Skip to content

Commit

Permalink
Merge pull request #174 from SpaceServerUniverse/dev/syoyu-fix-suicide
Browse files Browse the repository at this point in the history
/suでエラー履くやつ直し
  • Loading branch information
m1sk9 authored Oct 28, 2024
2 parents dd151ad + 5c1a586 commit 595523d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, Boolean> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
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)) {
return false;

}

SuicidePlayerData.getInstance().setChoke(player, true);
player.setHealth(0.0);
Bukkit.broadcast(getMessage(player));

Expand All @@ -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];
Expand Down

0 comments on commit 595523d

Please sign in to comment.