mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
Fix /kill and /suicide on latest Spigot/Paper
This commit is contained in:
parent
63234d6b1d
commit
0cd47639c2
@ -60,6 +60,7 @@ import net.ess3.nms.refl.providers.ReflSpawnEggProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSpawnerBlockProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSyncCommandsProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
@ -83,10 +84,12 @@ import net.ess3.provider.providers.BukkitMaterialTagProvider;
|
||||
import net.ess3.provider.providers.BukkitSpawnerBlockProvider;
|
||||
import net.ess3.provider.providers.FixedHeightWorldInfoProvider;
|
||||
import net.ess3.provider.providers.FlatSpawnEggProvider;
|
||||
import net.ess3.provider.providers.LegacyDamageEventProvider;
|
||||
import net.ess3.provider.providers.LegacyItemUnbreakableProvider;
|
||||
import net.ess3.provider.providers.LegacyPlayerLocaleProvider;
|
||||
import net.ess3.provider.providers.LegacyPotionMetaProvider;
|
||||
import net.ess3.provider.providers.LegacySpawnEggProvider;
|
||||
import net.ess3.provider.providers.ModernDamageEventProvider;
|
||||
import net.ess3.provider.providers.ModernDataWorldInfoProvider;
|
||||
import net.ess3.provider.providers.ModernItemUnbreakableProvider;
|
||||
import net.ess3.provider.providers.ModernPersistentDataProvider;
|
||||
@ -193,6 +196,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private transient WorldInfoProvider worldInfoProvider;
|
||||
private transient PlayerLocaleProvider playerLocaleProvider;
|
||||
private transient SignDataProvider signDataProvider;
|
||||
private transient DamageEventProvider damageEventProvider;
|
||||
private transient Kits kits;
|
||||
private transient RandomTeleport randomTeleport;
|
||||
private transient UpdateChecker updateChecker;
|
||||
@ -475,6 +479,12 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
playerLocaleProvider = new LegacyPlayerLocaleProvider();
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_4_R01)) {
|
||||
damageEventProvider = new ModernDamageEventProvider();
|
||||
} else {
|
||||
damageEventProvider = new LegacyDamageEventProvider();
|
||||
}
|
||||
|
||||
execTimer.mark("Init(Providers)");
|
||||
reload();
|
||||
|
||||
@ -1405,6 +1415,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return playerLocaleProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageEventProvider getDamageEventProvider() {
|
||||
return damageEventProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignDataProvider getSignDataProvider() {
|
||||
return signDataProvider;
|
||||
|
@ -10,6 +10,7 @@ import com.earth2me.essentials.updatecheck.UpdateChecker;
|
||||
import com.earth2me.essentials.userstorage.IUserMap;
|
||||
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
@ -183,5 +184,7 @@ public interface IEssentials extends Plugin {
|
||||
|
||||
PlayerLocaleProvider getPlayerLocaleProvider();
|
||||
|
||||
DamageEventProvider getDamageEventProvider();
|
||||
|
||||
PluginCommand getPluginCommand(String cmd);
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ public class Commandkill extends EssentialsLoopCommand {
|
||||
if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
|
||||
throw new PlayerExemptException("killExempt", matchPlayer.getDisplayName());
|
||||
}
|
||||
final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Float.MAX_VALUE);
|
||||
server.getPluginManager().callEvent(ede);
|
||||
final EntityDamageEvent ede = ess.getDamageEventProvider().callDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Float.MAX_VALUE);
|
||||
if (ede.isCancelled() && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
|
||||
return;
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ public class Commandsuicide extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final EntityDamageEvent ede = new EntityDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Float.MAX_VALUE);
|
||||
server.getPluginManager().callEvent(ede);
|
||||
final EntityDamageEvent ede = ess.getDamageEventProvider().callDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Float.MAX_VALUE);
|
||||
ede.getEntity().setLastDamageCause(ede);
|
||||
user.getBase().setHealth(0);
|
||||
user.sendTl("suicideMessage");
|
||||
|
@ -0,0 +1,19 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class LegacyDamageEventProvider implements DamageEventProvider {
|
||||
@Override
|
||||
public EntityDamageEvent callDamageEvent(Player player, EntityDamageEvent.DamageCause cause, double damage) {
|
||||
final EntityDamageEvent ede = new EntityDamageEvent(player, cause, damage);
|
||||
player.getServer().getPluginManager().callEvent(ede);
|
||||
return ede;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Legacy Damage Event Provider";
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package net.ess3.provider;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public interface DamageEventProvider extends Provider {
|
||||
EntityDamageEvent callDamageEvent(Player player, EntityDamageEvent.DamageCause cause, double damage);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package net.ess3.provider.providers;
|
||||
|
||||
import net.ess3.provider.DamageEventProvider;
|
||||
import org.bukkit.damage.DamageSource;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ModernDamageEventProvider implements DamageEventProvider {
|
||||
private final DamageSource MAGIC_SOURCE = DamageSource.builder(DamageType.MAGIC).build();
|
||||
|
||||
@Override
|
||||
public EntityDamageEvent callDamageEvent(Player player, EntityDamageEvent.DamageCause cause, double damage) {
|
||||
final EntityDamageEvent ede = new EntityDamageEvent(player, cause, MAGIC_SOURCE, damage);
|
||||
player.getServer().getPluginManager().callEvent(ede);
|
||||
return ede;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "1.20.4+ Damage Event Provider";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user