mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Properly register entity transform event depending on version (#2942)
Fixes the problem mentioned in #2931 which was introduced in #2836. This is caused as a result of EntityTransformEvent being a relatively new event introduced in Spigot [856adc3e6af](856adc3e6a
), which was after the update to 1.13.2 in Spigot [f311182396b](f311182396
). Closes #2931.
This commit is contained in:
parent
32ef61197f
commit
2e818ac709
@ -1,6 +1,7 @@
|
|||||||
package com.earth2me.essentials.protect;
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
import com.earth2me.essentials.metrics.Metrics;
|
import com.earth2me.essentials.metrics.Metrics;
|
||||||
|
import com.earth2me.essentials.utils.VersionUtil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -49,6 +50,11 @@ public class EssentialsProtect extends JavaPlugin implements IProtect {
|
|||||||
final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
|
final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
|
||||||
pm.registerEvents(entityListener, this);
|
pm.registerEvents(entityListener, this);
|
||||||
|
|
||||||
|
if (VersionUtil.getServerBukkitVersion().isHigherThan(VersionUtil.v1_13_2_R01)) {
|
||||||
|
final EssentialsProtectEntityListener1_13_2_R1 entityListener1_13_2_r1 = new EssentialsProtectEntityListener1_13_2_R1(this);
|
||||||
|
pm.registerEvents(entityListener1_13_2_r1, this);
|
||||||
|
}
|
||||||
|
|
||||||
final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
|
final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
|
||||||
pm.registerEvents(weatherListener, this);
|
pm.registerEvents(weatherListener, this);
|
||||||
}
|
}
|
||||||
|
@ -170,29 +170,6 @@ public class EssentialsProtectEntityListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onEntityTransform(final EntityTransformEvent event) {
|
|
||||||
final Entity entity = event.getEntity();
|
|
||||||
final EntityTransformEvent.TransformReason reason = event.getTransformReason();
|
|
||||||
if (reason == EntityTransformEvent.TransformReason.INFECTION && prot.getSettingBool(ProtectConfig.prevent_villager_infection)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else if (reason == EntityTransformEvent.TransformReason.CURED && prot.getSettingBool(ProtectConfig.prevent_villager_cure)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else if (reason == EntityTransformEvent.TransformReason.LIGHTNING) {
|
|
||||||
if (entity instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_to_witch)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else if (entity instanceof Pig && prot.getSettingBool(ProtectConfig.prevent_pig_transformation)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else if (entity instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_charge)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else if (entity instanceof MushroomCow && prot.getSettingBool(ProtectConfig.prevent_mooshroom_switching)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
} else if (reason == EntityTransformEvent.TransformReason.DROWNED && prot.getSettingBool(ProtectConfig.prevent_zombie_drowning)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onCreatureSpawn(final CreatureSpawnEvent event) {
|
public void onCreatureSpawn(final CreatureSpawnEvent event) {
|
||||||
if (event.getEntity() instanceof Player) {
|
if (event.getEntity() instanceof Player) {
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.earth2me.essentials.protect;
|
||||||
|
|
||||||
|
import net.ess3.api.IEssentials;
|
||||||
|
import org.bukkit.entity.Creeper;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.MushroomCow;
|
||||||
|
import org.bukkit.entity.Pig;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityTransformEvent;
|
||||||
|
|
||||||
|
public class EssentialsProtectEntityListener1_13_2_R1 implements Listener {
|
||||||
|
private final IProtect prot;
|
||||||
|
private final IEssentials ess;
|
||||||
|
|
||||||
|
EssentialsProtectEntityListener1_13_2_R1(final IProtect prot) {
|
||||||
|
this.prot = prot;
|
||||||
|
this.ess = prot.getEssentialsConnect().getEssentials();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onEntityTransform(final EntityTransformEvent event) {
|
||||||
|
final Entity entity = event.getEntity();
|
||||||
|
final EntityTransformEvent.TransformReason reason = event.getTransformReason();
|
||||||
|
if (reason == EntityTransformEvent.TransformReason.INFECTION && prot.getSettingBool(ProtectConfig.prevent_villager_infection)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (reason == EntityTransformEvent.TransformReason.CURED && prot.getSettingBool(ProtectConfig.prevent_villager_cure)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (reason == EntityTransformEvent.TransformReason.LIGHTNING) {
|
||||||
|
if (entity instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_to_witch)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (entity instanceof Pig && prot.getSettingBool(ProtectConfig.prevent_pig_transformation)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (entity instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_charge)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else if (entity instanceof MushroomCow && prot.getSettingBool(ProtectConfig.prevent_mooshroom_switching)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
} else if (reason == EntityTransformEvent.TransformReason.DROWNED && prot.getSettingBool(ProtectConfig.prevent_zombie_drowning)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user