diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/data/SuicidePlayerData.java b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/data/SuicidePlayerData.java new file mode 100644 index 00000000..96eac14f --- /dev/null +++ b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/data/SuicidePlayerData.java @@ -0,0 +1,37 @@ +package space.yurisi.universecorev2.subplugins.changemessages.data; + +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public class SuicidePlayerData { + + private static SuicidePlayerData instance; + private Map map; + + public SuicidePlayerData(){ + instance = this; + map = new HashMap<>(); + } + + public static SuicidePlayerData getInstance(){ + return instance; + } + + public void register(Player player){ + map.put(player.getUniqueId().toString(), false); + } + + public void unregister(Player player){ + map.remove(player.getUniqueId().toString()); + } + + public void setChoke(Player player, boolean bool){ + map.put(player.getUniqueId().toString(), bool); + } + + public boolean isSuicide(Player player){ + return map.get(player.getUniqueId().toString()); + } +} diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/DeathEvent.java b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/DeathEvent.java index 5ee2d9ef..a19d0f5c 100755 --- a/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/DeathEvent.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/DeathEvent.java @@ -6,6 +6,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import space.yurisi.universecorev2.subplugins.changemessages.data.SuicidePlayerData; import space.yurisi.universecorev2.subplugins.changemessages.message.event.player_death.*; import javax.annotation.Nullable; @@ -16,6 +17,11 @@ public class DeathEvent implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onDeath(PlayerDeathEvent event) { Player player = event.getPlayer(); + if(SuicidePlayerData.getInstance().isSuicide(player)) { + SuicidePlayerData.getInstance().setChoke(player, false); + event.deathMessage(null); + return; + } Player killer = event.getEntity().getKiller(); EntityDamageEvent.DamageCause cause = Optional.ofNullable(event.getEntity().getLastDamageCause()) .map(EntityDamageEvent::getCause) diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/JoinEvent.java b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/JoinEvent.java index 12eaa1fe..0113754a 100755 --- a/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/JoinEvent.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/JoinEvent.java @@ -8,6 +8,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import space.yurisi.universecorev2.UniverseCoreV2; +import space.yurisi.universecorev2.subplugins.changemessages.data.SuicidePlayerData; import space.yurisi.universecorev2.subplugins.changemessages.file.Config; import java.util.List; @@ -26,6 +27,7 @@ public JoinEvent(Config config, Plugin plugin) { @EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + SuicidePlayerData.getInstance().register(player); player.sendTitle("§eWelcome to SpaceServer", "- Universe -"); if (!player.hasPlayedBefore()) { event.joinMessage(getFirstJoinMessage(player)); diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/QuitEvent.java b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/QuitEvent.java index 7bc2b347..775854e0 100755 --- a/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/QuitEvent.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/changemessages/event/player/QuitEvent.java @@ -5,12 +5,14 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; +import space.yurisi.universecorev2.subplugins.changemessages.data.SuicidePlayerData; public final class QuitEvent implements Listener { @EventHandler public void onQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); + SuicidePlayerData.getInstance().unregister(player); PlayerQuitEvent.QuitReason reason = event.getReason(); event.quitMessage(getComponent(player, reason)); } diff --git a/src/main/java/space/yurisi/universecorev2/subplugins/universeutilcommand/suicide/suCommand.java b/src/main/java/space/yurisi/universecorev2/subplugins/universeutilcommand/suicide/suCommand.java index ffcf59eb..8613d61e 100644 --- a/src/main/java/space/yurisi/universecorev2/subplugins/universeutilcommand/suicide/suCommand.java +++ b/src/main/java/space/yurisi/universecorev2/subplugins/universeutilcommand/suicide/suCommand.java @@ -7,11 +7,16 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import space.yurisi.universecorev2.subplugins.changemessages.data.SuicidePlayerData; import java.util.Random; public class suCommand implements CommandExecutor{ + public suCommand(){ + new SuicidePlayerData(); + } + @Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { if (!(commandSender instanceof Player player)) { @@ -19,6 +24,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command } + SuicidePlayerData.getInstance().setChoke(player, true); player.setHealth(0.0); Bukkit.broadcast(getMessage(player)); @@ -32,10 +38,10 @@ private int getRandom(Component[] components){ private Component getMessage(Player player) { Component[] messages = new Component[]{ - Component.text("§a §l[死亡管理AI]§b " + player.getName() + "§a は消滅した"), - Component.text("§a §l[死亡管理AI]§b " + player.getName() + "§a は存在がなくなった"), - Component.text("§a §l[死亡管理AI]§b " + player.getName() + "§a はちりになった"), - Component.text("§a §l[死亡管理AI]§b " + player.getName() + "§a は星になった") + Component.text("§a§l[死亡管理AI]§b " + player.getName() + "§a は消滅した"), + Component.text("§a§l[死亡管理AI]§b " + player.getName() + "§a は存在がなくなった"), + Component.text("§a§l[死亡管理AI]§b " + player.getName() + "§a はちりになった"), + Component.text("§a§l[死亡管理AI]§b " + player.getName() + "§a は星になった") }; int i = this.getRandom(messages); return messages[i];