Skip to content

Commit

Permalink
Update to 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed May 24, 2024
1 parent d1e5671 commit c10bda9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.event.player.PlayerSpawnLocationEvent;

Expand All @@ -37,6 +38,9 @@
import net.goldtreeservers.worldguardextraflags.wg.handlers.FlyFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.GiveEffectsFlagHandler;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
public class PlayerListener implements Listener
{
Expand Down Expand Up @@ -125,9 +129,17 @@ public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
Player player = event.getPlayer();

ItemMeta itemMeta = event.getItem().getItemMeta();
if (itemMeta instanceof PotionMeta)
if (itemMeta instanceof PotionMeta potionMeta)
{
this.sessionManager.get(this.worldGuardPlugin.wrapPlayer(player)).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
List<PotionEffect> effects = new ArrayList<>();
if (potionMeta.getBasePotionType() != null)
{
effects.addAll(potionMeta.getBasePotionType().getPotionEffects());
}

effects.addAll(potionMeta.getCustomEffects());

this.sessionManager.get(this.worldGuardPlugin.wrapPlayer(player)).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, effects);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion WG/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.goldtreeservers.worldguardextraflags.flags.helpers;

import org.bukkit.Registry;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

Expand All @@ -23,7 +24,7 @@ public PotionEffectFlag(String name)
@Override
public Object marshal(PotionEffect o)
{
return o.getType().getName() + " " + o.getAmplifier() + " " + o.hasParticles();
return o.getType().getKey().toString() + " " + o.getAmplifier() + " " + o.hasParticles();
}

@Override
Expand All @@ -34,11 +35,16 @@ public PotionEffect parseInput(FlagContext context) throws InvalidFlagFormat
{
throw new InvalidFlagFormat("Please use the following format: <effect name> [effect amplifier] [show particles]");
}
PotionEffectType potionEffect = PotionEffectType.getByName(split[0]);

PotionEffectType potionEffect = Registry.EFFECT.match(split[0]);
if (potionEffect == null)
{
throw new InvalidFlagFormat("Unable to find the potion effect type! Please refer to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html");
potionEffect = PotionEffectType.getByName(split[0]);
}

if (potionEffect == null)
{
throw new InvalidFlagFormat("Unable to find the potion effect type! Input valid namespaced ids.");
}

return this.buildPotionEffect(split);
Expand All @@ -54,7 +60,11 @@ public PotionEffect unmarshal(Object o)

private PotionEffect buildPotionEffect(String[] split)
{
PotionEffectType potionEffect = PotionEffectType.getByName(split[0]);
PotionEffectType potionEffect = Registry.EFFECT.match(split[0]);
if (potionEffect == null)
{
potionEffect = PotionEffectType.getByName(split[0]);
}

int amplifier = 0;
if (split.length >= 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.goldtreeservers.worldguardextraflags.flags.helpers;

import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.potion.PotionEffectType;

import com.sk89q.worldguard.protection.flags.Flag;
Expand All @@ -16,26 +18,29 @@ public PotionEffectTypeFlag(String name)
@Override
public Object marshal(PotionEffectType o)
{
return o.getName();
return o.getKey().toString();
}

@Override
public PotionEffectType parseInput(FlagContext context) throws InvalidFlagFormat
{
PotionEffectType potionEffect = PotionEffectType.getByName(context.getUserInput().trim());
if (potionEffect != null)
PotionEffectType potionEffect = Registry.EFFECT.match(context.getUserInput().trim());
if (potionEffect == null)
{
return potionEffect;
potionEffect = PotionEffectType.getByName(context.getUserInput().trim());
}
else

if (potionEffect != null)
{
throw new InvalidFlagFormat("Unable to find the potion effect type! Please refer to https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html");
return potionEffect;
}

throw new InvalidFlagFormat("Unable to find the potion effect type! Input valid namespaced ids.");
}

@Override
public PotionEffectType unmarshal(Object o)
{
return PotionEffectType.getByName(o.toString());
return Registry.EFFECT.get(NamespacedKey.fromString(o.toString()));
}
}
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -26,7 +26,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit c10bda9

Please sign in to comment.