From 19877b2ff0e6ef3de6081e71faa81601657054a0 Mon Sep 17 00:00:00 2001 From: NotCoded <66999075+not-coded@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:42:20 +0200 Subject: [PATCH] chat, is this nexus listening? (probably untested?) --- .../com/nexia/core/games/util/LobbyUtil.java | 4 +- .../nexia/core/listeners/ListenerHelper.java | 5 +- .../listeners/nexus/PlayerDamageListener.java | 53 +++++++++++++++ .../listeners/nexus/PlayerDeathListener.java | 58 +++++++++++++++++ .../listeners/nexus/PlayerHungerListener.java | 33 ++++++++++ .../listeners/nexus/PlayerJoinListener.java | 65 ++++++++++--------- .../listeners/nexus/PlayerLeaveListener.java | 42 ++++-------- .../nexus/PlayerRespawnListener.java | 5 +- .../nexus/PlayerSwapHandItemsListener.java | 7 +- ...stener.java => PlayerUseItemListener.java} | 2 +- .../core/mixin/entity/LivingEntityMixin.java | 21 ------ .../core/mixin/item/ElytraItemMixin.java | 45 ------------- .../core/mixin/player/FoodDataMixin.java | 35 ---------- .../nexia/core/mixin/player/PlayerMixin.java | 43 +----------- .../core/mixin/player/ServerPlayerMixin.java | 12 +--- .../core/utilities/player/PlayerUtil.java | 14 +++- .../java/com/nexia/ffa/base/BaseFfaUtil.java | 11 ++-- .../nexia/ffa/sky/utilities/FfaSkyUtil.java | 2 +- .../games/bedwars/areas/BwAreas.java | 9 ++- .../games/bedwars/players/BwPlayerEvents.java | 12 +--- .../nexia/minigames/games/oitc/OitcGame.java | 16 +++-- .../minigames/games/skywars/SkywarsGame.java | 19 +++++- 22 files changed, 264 insertions(+), 249 deletions(-) create mode 100644 src/main/java/com/nexia/core/listeners/nexus/PlayerDamageListener.java create mode 100644 src/main/java/com/nexia/core/listeners/nexus/PlayerDeathListener.java create mode 100644 src/main/java/com/nexia/core/listeners/nexus/PlayerHungerListener.java rename src/main/java/com/nexia/core/listeners/nexus/{UseItemListener.java => PlayerUseItemListener.java} (98%) delete mode 100644 src/main/java/com/nexia/core/mixin/item/ElytraItemMixin.java diff --git a/src/main/java/com/nexia/core/games/util/LobbyUtil.java b/src/main/java/com/nexia/core/games/util/LobbyUtil.java index 21490be3..a4652fde 100644 --- a/src/main/java/com/nexia/core/games/util/LobbyUtil.java +++ b/src/main/java/com/nexia/core/games/util/LobbyUtil.java @@ -288,7 +288,7 @@ public static void sendGame(NexiaPlayer player, String game, boolean message, bo if(game.equalsIgnoreCase("oitc")){ player.addTag(OitcGame.OITC_TAG); ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode = PlayerGameMode.OITC; - OitcGame.death(player, player.unwrap().getLastDamageSource()); + OitcGame.death(player, null); ((OITCPlayerData)PlayerDataManager.getDataManager(NexiaCore.OITC_DATA_MANAGER).get(player)).gameMode = OitcGameMode.LOBBY; @@ -311,7 +311,7 @@ public static void sendGame(NexiaPlayer player, String game, boolean message, bo if(game.equalsIgnoreCase("skywars")){ player.addTag(PlayerGameMode.SKYWARS.tag); ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode = PlayerGameMode.SKYWARS; - SkywarsGame.death(player, player.unwrap().getLastDamageSource()); + SkywarsGame.death(player, null); ((SkywarsPlayerData)PlayerDataManager.getDataManager(NexiaCore.SKYWARS_DATA_MANAGER).get(player)).gameMode = SkywarsGameMode.LOBBY; diff --git a/src/main/java/com/nexia/core/listeners/ListenerHelper.java b/src/main/java/com/nexia/core/listeners/ListenerHelper.java index 31b092e3..19dcbe75 100644 --- a/src/main/java/com/nexia/core/listeners/ListenerHelper.java +++ b/src/main/java/com/nexia/core/listeners/ListenerHelper.java @@ -6,9 +6,12 @@ public class ListenerHelper { public static void registerListeners() { // Nexus Listeners new PlayerJoinListener().registerListener(); + new PlayerDamageListener().registerListener(); + new PlayerDeathListener().registerListener(); + new PlayerHungerListener().registerListener(); new PlayerLeaveListener().registerListener(); new PlayerSwapHandItemsListener().registerListener(); - new UseItemListener().registerListener(); + new PlayerUseItemListener().registerListener(); new PlayerDropItemListener().registerListener(); new PlayerRespawnListener().registerListener(); } diff --git a/src/main/java/com/nexia/core/listeners/nexus/PlayerDamageListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerDamageListener.java new file mode 100644 index 00000000..fba81be2 --- /dev/null +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerDamageListener.java @@ -0,0 +1,53 @@ +package com.nexia.core.listeners.nexus; + +import com.nexia.base.player.NexiaPlayer; +import com.nexia.core.games.util.LobbyUtil; +import com.nexia.core.games.util.PlayerGameMode; +import com.nexia.core.utilities.player.PlayerUtil; +import com.nexia.ffa.base.BaseFfaUtil; +import com.nexia.nexus.api.event.entity.LivingEntityDamageEvent; +import com.nexia.nexus.api.world.damage.DamageData; +import com.nexia.nexus.api.world.entity.player.Player; + +public class PlayerDamageListener { + public void registerListener() { + LivingEntityDamageEvent.BACKEND.register(livingEntityDamageEvent -> { + if(!(livingEntityDamageEvent.getLivingEntity() instanceof Player nexusPlayer)) return; + NexiaPlayer player = new NexiaPlayer(nexusPlayer); + DamageData damageData = livingEntityDamageEvent.getCause(); + + for (BaseFfaUtil util : BaseFfaUtil.ffaUtils) { + if (util.isFfaPlayer(player) && !util.beforeDamage(player, damageData)) { + livingEntityDamageEvent.setCancelled(true); + return; + } + } + + if(LobbyUtil.isLobbyWorld(player.getWorld()) && damageData.getType().equals(DamageData.Type.VOID)) { + LobbyUtil.lobbySpawn.teleportPlayer(LobbyUtil.nexusLobbyWorld, player); + player.teleport(LobbyUtil.nexusLobbyLocation); + livingEntityDamageEvent.setCancelled(true); + return; + } + + if (player.hasTag(LobbyUtil.NO_DAMAGE_TAG)) { + livingEntityDamageEvent.setCancelled(true); + return; + } + + Player attacker = PlayerUtil.getPlayerAttacker(damageData); + + if(attacker != null) { + if(attacker.hasTag(LobbyUtil.NO_DAMAGE_TAG)) { + livingEntityDamageEvent.setCancelled(true); + return; + } + } + + if(damageData.getType().equals(DamageData.Type.VOID) && (!player.isInGameMode(PlayerGameMode.LOBBY) || player.isInGameMode(PlayerGameMode.FFA))) { + livingEntityDamageEvent.setDamage(1000); + return; + } + }); + } +} diff --git a/src/main/java/com/nexia/core/listeners/nexus/PlayerDeathListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerDeathListener.java new file mode 100644 index 00000000..612d1b4f --- /dev/null +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerDeathListener.java @@ -0,0 +1,58 @@ +package com.nexia.core.listeners.nexus; + +import com.nexia.base.player.NexiaPlayer; +import com.nexia.base.player.PlayerDataManager; +import com.nexia.core.NexiaCore; +import com.nexia.core.games.util.PlayerGameMode; +import com.nexia.core.utilities.player.CorePlayerData; +import com.nexia.minigames.games.bedwars.areas.BwAreas; +import com.nexia.minigames.games.bedwars.players.BwPlayerEvents; +import com.nexia.minigames.games.duels.util.player.DuelsPlayerData; +import com.nexia.minigames.games.oitc.OitcGame; +import com.nexia.minigames.games.skywars.SkywarsGame; +import com.nexia.nexus.api.event.player.PlayerDeathEvent; + +public class PlayerDeathListener { + public void registerListener() { + PlayerDeathEvent.BACKEND.register(playerDeathEvent -> { + NexiaPlayer nexiaPlayer = new NexiaPlayer(playerDeathEvent.getPlayer()); + + PlayerGameMode gameMode = ((CorePlayerData) PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(nexiaPlayer)).gameMode; + DuelsPlayerData duelsData = (DuelsPlayerData) PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(nexiaPlayer); + + /* + if(FfaUtil.isFfaPlayer(nexiaPlayer)) { + FfaUtil.leaveOrDie(nexiaPlayer, playerDeathEvent, false); + } + */ + + if (BwAreas.isBedWarsWorld(nexiaPlayer.getWorld())) { + BwPlayerEvents.death(nexiaPlayer); + return; + } + + if(gameMode == PlayerGameMode.OITC){ + OitcGame.death(nexiaPlayer, playerDeathEvent); + return; + } + + if(gameMode == PlayerGameMode.SKYWARS) { + SkywarsGame.death(nexiaPlayer, playerDeathEvent); + return; + } + + /* + if(gameMode == PlayerGameMode.LOBBY && duelsData.gameOptions != null) { + if(duelsData.gameOptions.duelsGame != null) { + duelsData.gameOptions.duelsGame.death(nexiaPlayer, playerDeathEvent); + return; + } + if(duelsData.gameOptions.teamDuelsGame != null) { + duelsData.gameOptions.teamDuelsGame.death(nexiaPlayer, playerDeathEvent); + return; + } + } + */ + }); + } +} diff --git a/src/main/java/com/nexia/core/listeners/nexus/PlayerHungerListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerHungerListener.java new file mode 100644 index 00000000..e8723028 --- /dev/null +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerHungerListener.java @@ -0,0 +1,33 @@ +package com.nexia.core.listeners.nexus; + +import com.nexia.base.player.NexiaPlayer; +import com.nexia.base.player.PlayerDataManager; +import com.nexia.core.NexiaCore; +import com.nexia.core.games.util.PlayerGameMode; +import com.nexia.core.utilities.player.CorePlayerData; +import com.nexia.minigames.games.duels.DuelGameMode; +import com.nexia.minigames.games.duels.util.player.DuelsPlayerData; +import com.nexia.minigames.games.skywars.SkywarsGame; +import com.nexia.minigames.games.skywars.SkywarsGameMode; +import com.nexia.minigames.games.skywars.util.player.SkywarsPlayerData; +import com.nexia.nexus.api.event.player.PlayerFoodLevelsChangeEvent; + +public class PlayerHungerListener { + public void registerListener(){ + PlayerFoodLevelsChangeEvent.BACKEND.register(playerFoodLevelsChangeEvent -> { + NexiaPlayer player = new NexiaPlayer(playerFoodLevelsChangeEvent.getPlayer()); + + // SkyWars + SkywarsPlayerData playerData = (SkywarsPlayerData) PlayerDataManager.getDataManager(NexiaCore.SKYWARS_DATA_MANAGER).get(player); + if(SkywarsGame.isSkywarsPlayer(player) && playerData.gameMode.equals(SkywarsGameMode.PLAYING)) return; + + // Duels + DuelGameMode duelGameMode = ((DuelsPlayerData)PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(player)).gameMode; + PlayerGameMode gameMode = ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode; + if(gameMode.equals(PlayerGameMode.LOBBY) && (duelGameMode != null && !duelGameMode.hasSaturation)) return; + + playerFoodLevelsChangeEvent.setFoodLevel(20); + playerFoodLevelsChangeEvent.setCancelled(true); + }); + } +} diff --git a/src/main/java/com/nexia/core/listeners/nexus/PlayerJoinListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerJoinListener.java index 54a779f7..3ae497d2 100644 --- a/src/main/java/com/nexia/core/listeners/nexus/PlayerJoinListener.java +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerJoinListener.java @@ -11,12 +11,12 @@ import com.nexia.core.utilities.time.ServerTime; import com.nexia.discord.NexiaDiscord; import com.nexia.nexus.api.event.player.PlayerJoinEvent; -import com.nexia.nexus.api.world.entity.player.Player; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; +import net.minecraft.stats.Stats; import java.util.Objects; @@ -27,30 +27,42 @@ public void registerListener() { PlayerJoinEvent.BACKEND.register(playerJoinEvent -> { NexiaPlayer player = new NexiaPlayer(playerJoinEvent.getPlayer()); - processJoin(player); - - /* - if(minecraftPlayer.getStats().getValue(Stats.CUSTOM.get(Stats.LEAVE_GAME)) <= 1) { - playerJoinEvent.setJoinMessage( - Component.text("[").color(ChatFormat.lineColor) - .append(Component.text("!").color(TextColor.fromHexString("#ff9940"))) - .append(Component.text("] ").color(ChatFormat.lineColor)) - .append(Component.text(player.getRawName()).color(TextColor.fromHexString("#ff9940"))) - ); - } else { - playerJoinEvent.setJoinMessage( - Component.text("[").color(ChatFormat.lineColor) - .append(Component.text("+").color(ChatFormat.greenColor)) - .append(Component.text("] ").color(ChatFormat.lineColor)) - .append(Component.text(player.getRawName()).color(ChatFormat.greenColor)) - ); - } - */ + if(((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).clientType.equals(CorePlayerData.ClientType.VIAFABRICPLUS)) return; + + //setJoinMessage(player, playerJoinEvent); + + PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.addPlayerData(player)); + + LobbyUtil.returnToLobby(player, true); + checkBooster(player); + + ServerTime.scheduler.schedule(() -> { + sendJoinMessage(player); + }, 10); + + }); } + private static void setJoinMessage(NexiaPlayer player, PlayerJoinEvent playerJoinEvent) { + if(player.unwrap().getStats().getValue(Stats.CUSTOM.get(Stats.LEAVE_GAME)) < 1) { + playerJoinEvent.setJoinMessage( + net.kyori.adventure.text.Component.text("[").color(ChatFormat.lineColor) + .append(net.kyori.adventure.text.Component.text("!").color(ChatFormat.goldColor) + .append(net.kyori.adventure.text.Component.text("] ").color(ChatFormat.lineColor)) + .append(net.kyori.adventure.text.Component.text(player.getRawName()).color(ChatFormat.goldColor))) + ); + } else { + playerJoinEvent.setJoinMessage( + net.kyori.adventure.text.Component.text("[").color(ChatFormat.lineColor) + .append(net.kyori.adventure.text.Component.text("+").color(ChatFormat.greenColor)) + .append(net.kyori.adventure.text.Component.text("] ").color(ChatFormat.lineColor)) + .append(net.kyori.adventure.text.Component.text(player.getRawName()).color(ChatFormat.greenColor)) + ); + } + } - private static void sendJoinMessage(Player player){ + private static void sendJoinMessage(NexiaPlayer player){ player.sendMessage(ChatFormat.separatorLine("Welcome")); player.sendMessage( Component.text(" » ", ChatFormat.brandColor2) @@ -124,15 +136,4 @@ private static void checkBooster(NexiaPlayer player) { NexiaRank.setRank(NexiaRank.DEFAULT, player); } } - - private static void processJoin(NexiaPlayer player) { - if(((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).clientType.equals(CorePlayerData.ClientType.VIAFABRICPLUS)) return; - - PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.addPlayerData(player)); - - LobbyUtil.returnToLobby(player, true); - - checkBooster(player); - sendJoinMessage(player); - } } diff --git a/src/main/java/com/nexia/core/listeners/nexus/PlayerLeaveListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerLeaveListener.java index 797f3c1d..58276187 100644 --- a/src/main/java/com/nexia/core/listeners/nexus/PlayerLeaveListener.java +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerLeaveListener.java @@ -1,47 +1,31 @@ package com.nexia.core.listeners.nexus; -import com.nexia.base.player.PlayerDataManager; import com.nexia.base.player.NexiaPlayer; +import com.nexia.base.player.PlayerDataManager; +import com.nexia.core.utilities.chat.ChatFormat; import com.nexia.nexus.api.event.player.PlayerDisconnectEvent; +import net.kyori.adventure.text.Component; public class PlayerLeaveListener { public void registerListener() { PlayerDisconnectEvent.BACKEND.register(playerDisconnectEvent -> { - NexiaPlayer player = new NexiaPlayer(playerDisconnectEvent.getPlayer()); - processDisconnect(player); + player.leaveAllGames(); - /* - if(NexiaCore.config.events.statusMessages){ - playerDisconnectEvent.setLeaveMessage( - Component.text("[").color(ChatFormat.lineColor) - .append(Component.text("-", ChatFormat.failColor) - .append(Component.text("] ").color(ChatFormat.lineColor)) - .append(Component.text(player.getRawName(), ChatFormat.failColor))) - ); - } + //setLeaveMessage(player, playerDisconnectEvent); - */ + PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.removePlayerData(player)); }); } - private static void processDisconnect(NexiaPlayer player){ - /* - if (BwUtil.isInBedWars(player)) BwPlayerEvents.leaveInBedWars(player); - else if (FfaUtil.isFfaPlayer(player)) { - FfaUtil.leaveOrDie(player, player.getLastDamageSource(), true); - } - else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.LOBBY) DuelGameHandler.leave(player, true); - else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.SKYWARS) SkywarsGame.leave(player); - else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.OITC) OitcGame.leave(player); - else if (PlayerDataManager.get(player).gameMode == PlayerGameMode.FOOTBALL) FootballGame.leave(player); - else if (player.hasTag("duels")) DuelGameHandler.leave(player, true); - */ - - player.leaveAllGames(); - - PlayerDataManager.dataManagerMap.forEach((resourceLocation, playerDataManager) -> playerDataManager.removePlayerData(player)); + private static void setLeaveMessage(NexiaPlayer player, PlayerDisconnectEvent playerDisconnectEvent){ + playerDisconnectEvent.setLeaveMessage( + Component.text("[").color(ChatFormat.lineColor) + .append(Component.text("-", ChatFormat.failColor)) + .append(Component.text("] ").color(ChatFormat.lineColor)) + .append(Component.text(player.getRawName(), ChatFormat.failColor)) + ); } } diff --git a/src/main/java/com/nexia/core/listeners/nexus/PlayerRespawnListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerRespawnListener.java index 44bb4f71..74cc2d24 100644 --- a/src/main/java/com/nexia/core/listeners/nexus/PlayerRespawnListener.java +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerRespawnListener.java @@ -41,7 +41,10 @@ public void registerListener() { if (ffaUtil != null) { respawnEvent.setRespawnMode(ffaUtil.getMinecraftGameMode()); respawnEvent.setSpawnpoint(ffaUtil.getRespawnLocation()); - respawnEvent.runAfterwards(() -> ffaUtil.respawn(new NexiaPlayer(respawnEvent.getPlayer()))); + respawnEvent.runAfterwards(() -> { + ffaUtil.respawn(player.refreshPlayer()); + player.setInvulnerabilityTime(0); + }); } return; case "skywars": diff --git a/src/main/java/com/nexia/core/listeners/nexus/PlayerSwapHandItemsListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerSwapHandItemsListener.java index c07d0fa8..5b884b9e 100644 --- a/src/main/java/com/nexia/core/listeners/nexus/PlayerSwapHandItemsListener.java +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerSwapHandItemsListener.java @@ -6,12 +6,11 @@ public class PlayerSwapHandItemsListener { public void registerListener(){ - PlayerSwapHandItemsEvent.BACKEND.register(playerDropItemEvent -> { - - NexiaPlayer player = new NexiaPlayer(playerDropItemEvent.getPlayer()); + PlayerSwapHandItemsEvent.BACKEND.register(playerSwapHandItemsEvent -> { + NexiaPlayer player = new NexiaPlayer(playerSwapHandItemsEvent.getPlayer()); if(LobbyUtil.isLobbyWorld(player.getWorld())) { - playerDropItemEvent.setCancelled(true); + playerSwapHandItemsEvent.setCancelled(true); } }); } diff --git a/src/main/java/com/nexia/core/listeners/nexus/UseItemListener.java b/src/main/java/com/nexia/core/listeners/nexus/PlayerUseItemListener.java similarity index 98% rename from src/main/java/com/nexia/core/listeners/nexus/UseItemListener.java rename to src/main/java/com/nexia/core/listeners/nexus/PlayerUseItemListener.java index 72b48f60..c0aa40b2 100644 --- a/src/main/java/com/nexia/core/listeners/nexus/UseItemListener.java +++ b/src/main/java/com/nexia/core/listeners/nexus/PlayerUseItemListener.java @@ -9,7 +9,7 @@ import com.nexia.base.player.NexiaPlayer; import net.kyori.adventure.text.Component; -public class UseItemListener { +public class PlayerUseItemListener { public void registerListener() { PlayerUseItemEvent.BACKEND.register(playerUseItemEvent -> { diff --git a/src/main/java/com/nexia/core/mixin/entity/LivingEntityMixin.java b/src/main/java/com/nexia/core/mixin/entity/LivingEntityMixin.java index 3bdaf0c9..4a6d223a 100644 --- a/src/main/java/com/nexia/core/mixin/entity/LivingEntityMixin.java +++ b/src/main/java/com/nexia/core/mixin/entity/LivingEntityMixin.java @@ -1,16 +1,9 @@ package com.nexia.core.mixin.entity; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.nexia.base.player.PlayerDataManager; -import com.nexia.core.NexiaCore; -import com.nexia.core.games.util.PlayerGameMode; -import com.nexia.core.utilities.player.CorePlayerData; import com.nexia.minigames.games.bedwars.areas.BwAreas; import com.nexia.minigames.games.bedwars.util.BwUtil; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.CombatRules; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -39,20 +32,6 @@ public LivingEntityMixin(EntityType entityType, Level level) { @Shadow public abstract ItemStack getBlockingItem(); - @Shadow public abstract float getHealth(); - - // Make void death instant - @WrapOperation(method = "outOfWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) - protected boolean killInVoid(LivingEntity instance, DamageSource damageSource, float f, Operation original) { - if ((Object)this instanceof ServerPlayer serverPlayer) { - if (((CorePlayerData) PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(serverPlayer.getUUID())).gameMode == PlayerGameMode.LOBBY) { - return original.call(instance, damageSource, f); - } - } - return original.call(instance, damageSource, this.getHealth()); - } - - /** * @author NotCoded * @reason Fix Shield Knockback diff --git a/src/main/java/com/nexia/core/mixin/item/ElytraItemMixin.java b/src/main/java/com/nexia/core/mixin/item/ElytraItemMixin.java deleted file mode 100644 index 6afc5e84..00000000 --- a/src/main/java/com/nexia/core/mixin/item/ElytraItemMixin.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.nexia.core.mixin.item; - -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ElytraItem; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.level.Level; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ElytraItem.class) -public class ElytraItemMixin { - @Unique - public ItemStack copyAndEmpty(ItemStack itemStack) { - if (itemStack.isEmpty()) { - return ItemStack.EMPTY; - } - ItemStack itemStack1 = itemStack.copy(); - itemStack.setCount(0); - return itemStack1; - } - - @Inject(method = "use", at = @At("HEAD"), cancellable = true) - public void use(Level level, Player player, InteractionHand interactionHand, CallbackInfoReturnable> cir) { - ItemStack itemStack = player.getItemInHand(interactionHand); - EquipmentSlot equipmentSlot = Mob.getEquipmentSlotForItem(itemStack); - ItemStack itemStack2 = player.getItemBySlot(equipmentSlot); - if (EnchantmentHelper.hasBindingCurse(itemStack2) && !player.isCreative() || ItemStack.isSame(itemStack, itemStack2)) { - cir.setReturnValue(InteractionResultHolder.fail(itemStack)); - return; - } - - ItemStack itemStack3 = itemStack2.isEmpty() ? itemStack : copyAndEmpty(itemStack2); - ItemStack itemStack4 = copyAndEmpty(itemStack); - player.setItemSlot(equipmentSlot, itemStack4); - cir.setReturnValue(InteractionResultHolder.success(itemStack3)); - } -} diff --git a/src/main/java/com/nexia/core/mixin/player/FoodDataMixin.java b/src/main/java/com/nexia/core/mixin/player/FoodDataMixin.java index ad7d4282..9c85c242 100644 --- a/src/main/java/com/nexia/core/mixin/player/FoodDataMixin.java +++ b/src/main/java/com/nexia/core/mixin/player/FoodDataMixin.java @@ -1,20 +1,9 @@ package com.nexia.core.mixin.player; import com.nexia.base.player.NexiaPlayer; -import com.nexia.base.player.PlayerDataManager; -import com.nexia.core.NexiaCore; -import com.nexia.core.games.util.PlayerGameMode; -import com.nexia.core.utilities.player.CorePlayerData; import com.nexia.ffa.sky.utilities.FfaSkyUtil; import com.nexia.ffa.uhc.utilities.FfaUhcUtil; import com.nexia.minigames.games.bedwars.areas.BwAreas; -import com.nexia.minigames.games.bedwars.players.BwPlayerEvents; -import com.nexia.minigames.games.bedwars.util.BwUtil; -import com.nexia.minigames.games.duels.DuelGameMode; -import com.nexia.minigames.games.duels.util.player.DuelsPlayerData; -import com.nexia.minigames.games.skywars.SkywarsGame; -import com.nexia.minigames.games.skywars.SkywarsGameMode; -import com.nexia.minigames.games.skywars.util.player.SkywarsPlayerData; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.food.FoodData; @@ -51,28 +40,4 @@ private float heal(float par1) { return 1f; } - - @Inject(method = "tick", at = @At("TAIL")) - private void modifyHunger(Player player, CallbackInfo ci) { - if (!(player instanceof ServerPlayer serverPlayer)) return; - NexiaPlayer nexiaPlayer = new NexiaPlayer(serverPlayer); - - FoodData data = (FoodData)(Object)this; - - if (BwUtil.isInBedWars(nexiaPlayer)) { - BwPlayerEvents.afterHungerTick((FoodData)(Object)this); - BwPlayerEvents.afterHungerTick(data); - } - - SkywarsPlayerData playerData = (SkywarsPlayerData) PlayerDataManager.getDataManager(NexiaCore.SKYWARS_DATA_MANAGER).get(nexiaPlayer); - if(SkywarsGame.isSkywarsPlayer(nexiaPlayer) && playerData.gameMode.equals(SkywarsGameMode.PLAYING)) return; - - // Duels - DuelGameMode duelGameMode = ((DuelsPlayerData)PlayerDataManager.getDataManager(NexiaCore.DUELS_DATA_MANAGER).get(nexiaPlayer)).gameMode; - PlayerGameMode gameMode = ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(nexiaPlayer)).gameMode; - if(gameMode.equals(PlayerGameMode.LOBBY) && (duelGameMode != null && !duelGameMode.hasSaturation)) return; - - data.setFoodLevel(20); - } - } diff --git a/src/main/java/com/nexia/core/mixin/player/PlayerMixin.java b/src/main/java/com/nexia/core/mixin/player/PlayerMixin.java index 1e53d680..52b1aef2 100644 --- a/src/main/java/com/nexia/core/mixin/player/PlayerMixin.java +++ b/src/main/java/com/nexia/core/mixin/player/PlayerMixin.java @@ -3,14 +3,12 @@ import com.nexia.base.player.NexiaPlayer; import com.nexia.base.player.PlayerDataManager; import com.nexia.core.NexiaCore; -import com.nexia.core.games.util.LobbyUtil; import com.nexia.core.games.util.PlayerGameMode; import com.nexia.core.utilities.misc.EventUtil; import com.nexia.core.utilities.player.CorePlayerData; import com.nexia.core.utilities.player.CoreSavedPlayerData; import com.nexia.core.utilities.player.PlayerUtil; import com.nexia.core.utilities.pos.EntityPos; -import com.nexia.ffa.base.BaseFfaUtil; import com.nexia.ffa.sky.utilities.FfaSkyUtil; import com.nexia.ffa.uhc.utilities.FfaUhcUtil; import com.nexia.minigames.games.bedwars.players.BwPlayerEvents; @@ -87,45 +85,6 @@ private void preventFFAUsers(boolean bl, CallbackInfoReturnable cir) { } } - @Inject(method = "hurt", cancellable = true, at = @At("HEAD")) - private void beforeHurt(DamageSource damageSource, float damage, CallbackInfoReturnable cir) { - if (!((Object) this instanceof ServerPlayer player)) return; - NexiaPlayer nexiaPlayer = new NexiaPlayer(player); - - for (BaseFfaUtil util : BaseFfaUtil.ffaUtils) { - if (util.isFfaPlayer(nexiaPlayer) && !util.beforeDamage(nexiaPlayer, damageSource)) { - cir.setReturnValue(false); - return; - } - } - - if(player.getLevel().equals(LobbyUtil.lobbyWorld) && damageSource == DamageSource.OUT_OF_WORLD) { - LobbyUtil.lobbySpawn.teleportPlayer(LobbyUtil.lobbyWorld, player); - cir.setReturnValue(false); - return; - } - - ServerPlayer attacker = PlayerUtil.getPlayerAttacker(player, damageSource.getEntity()); - - if (player.getTags().contains(LobbyUtil.NO_DAMAGE_TAG)) { - cir.setReturnValue(false); - return; - } - - if(attacker != null) { - if(attacker.getTags().contains(LobbyUtil.NO_DAMAGE_TAG)) { - cir.setReturnValue(false); - } - - /* - DuelsTeam team = PlayerDataManager.get(player).duelOptions.duelsTeam; - if(team != null && team.all.contains(AccuratePlayer.create(attacker)) && PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player).gameMode == PlayerGameMode.LOBBY) { - cir.setReturnValue(false); - } - */ - } - } - // Make void death instant @Inject(method = "actuallyHurt", at = @At("TAIL")) private void afterHurt(DamageSource damageSource, float damage, CallbackInfo ci) { @@ -190,7 +149,7 @@ private void getAttackDelay(CallbackInfoReturnable cir) { @ModifyArg(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;setSprinting(Z)V")) public boolean setSprintFix(boolean par1) { - return ((CoreSavedPlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(new NexiaPlayer((ServerPlayer) (Object) this)).savedData).isSprintFix(); + return ((CoreSavedPlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(this.getUUID()).savedData).isSprintFix(); } @Inject(method = "hurt", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/com/nexia/core/mixin/player/ServerPlayerMixin.java b/src/main/java/com/nexia/core/mixin/player/ServerPlayerMixin.java index a56ef3b0..49b77f37 100644 --- a/src/main/java/com/nexia/core/mixin/player/ServerPlayerMixin.java +++ b/src/main/java/com/nexia/core/mixin/player/ServerPlayerMixin.java @@ -1,6 +1,7 @@ package com.nexia.core.mixin.player; import com.mojang.authlib.GameProfile; +import com.nexia.base.player.NexiaPlayer; import com.nexia.base.player.PlayerDataManager; import com.nexia.core.NexiaCore; import com.nexia.core.commands.staff.DetectCommand; @@ -9,7 +10,6 @@ import com.nexia.core.gui.duels.CustomDuelGUI; import com.nexia.core.gui.duels.DuelGUI; import com.nexia.core.utilities.player.CorePlayerData; -import com.nexia.base.player.NexiaPlayer; import com.nexia.ffa.FfaUtil; import com.nexia.minigames.games.bedwars.areas.BwAreas; import com.nexia.minigames.games.bedwars.players.BwPlayerEvents; @@ -17,7 +17,6 @@ import com.nexia.minigames.games.duels.util.player.DuelsPlayerData; import com.nexia.minigames.games.football.FootballGame; import com.nexia.minigames.games.oitc.OitcGame; -import com.nexia.minigames.games.skywars.SkywarsGame; import net.minecraft.core.BlockPos; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -120,19 +119,12 @@ private void die(DamageSource damageSource, CallbackInfo ci) { FfaUtil.leaveOrDie(nexiaPlayer, damageSource, false); } else if (BwAreas.isBedWarsWorld(getLevel())) { - BwPlayerEvents.death(nexiaPlayer ); - } - else if(gameMode == PlayerGameMode.OITC){ - OitcGame.death(nexiaPlayer, damageSource); - } - else if(gameMode == PlayerGameMode.SKYWARS) { - SkywarsGame.death(nexiaPlayer, damageSource); + BwPlayerEvents.death(nexiaPlayer); } else if(gameMode == PlayerGameMode.LOBBY && duelsData.gameOptions != null) { if(duelsData.gameOptions.duelsGame != null) duelsData.gameOptions.duelsGame.death(nexiaPlayer, damageSource); if(duelsData.gameOptions.teamDuelsGame != null) duelsData.gameOptions.teamDuelsGame.death(nexiaPlayer, damageSource); } - } @Redirect(method = "doCloseContainer", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/AbstractContainerMenu;removed(Lnet/minecraft/world/entity/player/Player;)V")) diff --git a/src/main/java/com/nexia/core/utilities/player/PlayerUtil.java b/src/main/java/com/nexia/core/utilities/player/PlayerUtil.java index c81927e7..962502f1 100644 --- a/src/main/java/com/nexia/core/utilities/player/PlayerUtil.java +++ b/src/main/java/com/nexia/core/utilities/player/PlayerUtil.java @@ -5,6 +5,8 @@ import com.nexia.core.utilities.time.ServerTime; import com.nexia.nexus.api.util.http.HttpAPI; import com.nexia.nexus.api.util.minecraft.MinecraftAPI; +import com.nexia.nexus.api.world.damage.DamageData; +import com.nexia.nexus.api.world.entity.player.Player; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.TextComponent; @@ -45,8 +47,6 @@ public static String getTextureID(@NotNull UUID uuid){ return null; } - - public static ItemStack getPlayerHead(@NotNull UUID playerUUID) { ItemStack playerHead = Items.PLAYER_HEAD.getDefaultInstance(); String textureID = getTextureID(playerUUID); @@ -147,6 +147,16 @@ public static ServerPlayer getPlayerAttacker(@NotNull ServerPlayer player, Entit return getPlayerAttacker(attackerEntity); } + public static Player getPlayerAttacker(@NotNull DamageData damageData) { + if (damageData.getDamagingEntity() instanceof Projectile projectile && projectile.getOwner() instanceof Player player) { + return player; + } else if (damageData.getDamagingEntity() instanceof Player player) { + return player; + } + + return null; + } + public static ServerPlayer getPlayerAttacker(@NotNull ServerPlayer player) { if(player.getKillCredit() instanceof ServerPlayer) { diff --git a/src/main/java/com/nexia/ffa/base/BaseFfaUtil.java b/src/main/java/com/nexia/ffa/base/BaseFfaUtil.java index ca422eed..60f16f75 100644 --- a/src/main/java/com/nexia/ffa/base/BaseFfaUtil.java +++ b/src/main/java/com/nexia/ffa/base/BaseFfaUtil.java @@ -16,6 +16,7 @@ import com.nexia.ffa.FfaGameMode; import com.nexia.ffa.FfaUtil; import com.nexia.nexus.api.world.World; +import com.nexia.nexus.api.world.damage.DamageData; import com.nexia.nexus.api.world.entity.player.Player; import com.nexia.nexus.api.world.types.Minecraft; import com.nexia.nexus.api.world.util.BoundingBox; @@ -172,8 +173,8 @@ public void killHeal(NexiaPlayer attacker) { public void doPreKill(NexiaPlayer attacker, NexiaPlayer player) { } - public void calculateDeath(NexiaPlayer player, boolean sendMessage){ - if (PlayerUtil.getPlayerAttacker(player.unwrap()).getTags().contains("bot")) return; + public void calculateDeath(NexiaPlayer player, @Nullable ServerPlayer attacker, boolean sendMessage){ + if(player.hasTag("bot") || (attacker != null && attacker.getTags().contains("bot"))) return; SavedPlayerData data = getDataManager().get(player).savedData; data.incrementInteger("deaths"); @@ -197,8 +198,8 @@ public void calculateDeath(NexiaPlayer player, boolean sendMessage){ data.set(Integer.class, "killstreak", 0); } - public boolean beforeDamage(NexiaPlayer player, DamageSource damageSource) { - if (damageSource == DamageSource.OUT_OF_WORLD) return true; + public boolean beforeDamage(NexiaPlayer player, DamageData damageData) { + if (damageData.getType().equals(DamageData.Type.VOID)) return true; return !isInFfaSpawn(player); } @@ -213,7 +214,7 @@ public AABB getFfaCorners() { public void setDeathMessage(@NotNull NexiaPlayer player, @Nullable ServerPlayer attacker, @Nullable DamageSource source) { - calculateDeath(player, true); + calculateDeath(player, attacker, true); Component msg = FfaUtil.returnDeathMessage(player, source); diff --git a/src/main/java/com/nexia/ffa/sky/utilities/FfaSkyUtil.java b/src/main/java/com/nexia/ffa/sky/utilities/FfaSkyUtil.java index 065a16e9..9eadd989 100644 --- a/src/main/java/com/nexia/ffa/sky/utilities/FfaSkyUtil.java +++ b/src/main/java/com/nexia/ffa/sky/utilities/FfaSkyUtil.java @@ -216,7 +216,7 @@ public boolean beforeBuild(NexiaPlayer player, BlockPos blockPos) { @Override public void setDeathMessage(@NotNull NexiaPlayer player, @Nullable ServerPlayer attacker, @Nullable DamageSource source) { - calculateDeath(player, false); + calculateDeath(player, attacker,false); if(attacker != null) { NexiaPlayer nexiaAttacker = new NexiaPlayer(attacker); diff --git a/src/main/java/com/nexia/minigames/games/bedwars/areas/BwAreas.java b/src/main/java/com/nexia/minigames/games/bedwars/areas/BwAreas.java index 42ed0f41..1a935343 100644 --- a/src/main/java/com/nexia/minigames/games/bedwars/areas/BwAreas.java +++ b/src/main/java/com/nexia/minigames/games/bedwars/areas/BwAreas.java @@ -1,12 +1,13 @@ package com.nexia.minigames.games.bedwars.areas; -import com.nexia.core.utilities.chat.ChatFormat; import com.nexia.base.player.NexiaPlayer; +import com.nexia.core.utilities.chat.ChatFormat; import com.nexia.core.utilities.pos.BlockVec3; import com.nexia.core.utilities.pos.EntityPos; import com.nexia.core.utilities.pos.ProtectionBlock; import com.nexia.core.utilities.pos.ProtectionMap; import com.nexia.minigames.games.bedwars.BwGame; +import com.nexia.nexus.api.world.World; import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; import net.minecraft.server.MinecraftServer; @@ -60,7 +61,11 @@ public static void createProtectionMap(ServerPlayer player) { // ------------------------------------------------------------ public static boolean isBedWarsWorld(Level level) { - return level.dimension().equals(BwDimension.LEVEL_KEY) || level.dimension().toString().contains(BwDimension.DIMENSION_ID + ":" + BwDimension.DIMENSION_NAME); + return level.dimension().equals(BwDimension.LEVEL_KEY) || level.dimension().location().toString().contains(BwDimension.DIMENSION_ID + ":" + BwDimension.DIMENSION_NAME); + } + + public static boolean isBedWarsWorld(World world) { + return world.getIdentifier().pure().equals(BwDimension.DIMENSION_ID + ":" + BwDimension.DIMENSION_NAME); } public static void setBedWarsWorld(MinecraftServer minecraftServer) { diff --git a/src/main/java/com/nexia/minigames/games/bedwars/players/BwPlayerEvents.java b/src/main/java/com/nexia/minigames/games/bedwars/players/BwPlayerEvents.java index d779c189..2afce395 100644 --- a/src/main/java/com/nexia/minigames/games/bedwars/players/BwPlayerEvents.java +++ b/src/main/java/com/nexia/minigames/games/bedwars/players/BwPlayerEvents.java @@ -1,14 +1,12 @@ package com.nexia.minigames.games.bedwars.players; +import com.nexia.base.player.NexiaPlayer; import com.nexia.base.player.PlayerDataManager; import com.nexia.core.NexiaCore; -import com.nexia.minigames.games.bedwars.util.player.BedwarsPlayerData; -import com.nexia.nexus.api.world.types.Minecraft; import com.nexia.core.games.util.LobbyUtil; import com.nexia.core.utilities.chat.ChatFormat; import com.nexia.core.utilities.item.BlockUtil; import com.nexia.core.utilities.item.ItemStackUtil; -import com.nexia.base.player.NexiaPlayer; import com.nexia.core.utilities.player.PlayerUtil; import com.nexia.core.utilities.pos.EntityPos; import com.nexia.core.utilities.time.ServerTime; @@ -22,6 +20,8 @@ import com.nexia.minigames.games.bedwars.upgrades.BwUpgradeShop; import com.nexia.minigames.games.bedwars.util.BwScoreboard; import com.nexia.minigames.games.bedwars.util.BwUtil; +import com.nexia.minigames.games.bedwars.util.player.BedwarsPlayerData; +import com.nexia.nexus.api.world.types.Minecraft; import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; @@ -41,7 +41,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.ThrownEgg; import net.minecraft.world.entity.projectile.ThrownTrident; -import net.minecraft.world.food.FoodData; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -293,9 +292,4 @@ public static boolean containerClick(NexiaPlayer player, ServerboundContainerCli return true; } - - public static void afterHungerTick(FoodData foodData) { - foodData.setFoodLevel(20); - } - } diff --git a/src/main/java/com/nexia/minigames/games/oitc/OitcGame.java b/src/main/java/com/nexia/minigames/games/oitc/OitcGame.java index 89ae9054..9e46405f 100644 --- a/src/main/java/com/nexia/minigames/games/oitc/OitcGame.java +++ b/src/main/java/com/nexia/minigames/games/oitc/OitcGame.java @@ -1,5 +1,6 @@ package com.nexia.minigames.games.oitc; +import com.nexia.base.player.NexiaPlayer; import com.nexia.base.player.PlayerDataManager; import com.nexia.core.NexiaCore; import com.nexia.core.games.util.LobbyUtil; @@ -8,7 +9,6 @@ import com.nexia.core.utilities.item.ItemDisplayUtil; import com.nexia.core.utilities.misc.RandomUtil; import com.nexia.core.utilities.player.CorePlayerData; -import com.nexia.base.player.NexiaPlayer; import com.nexia.core.utilities.player.PlayerUtil; import com.nexia.core.utilities.pos.EntityPos; import com.nexia.core.utilities.time.ServerTime; @@ -16,6 +16,7 @@ import com.nexia.core.utilities.world.WorldUtil; import com.nexia.minigames.games.duels.DuelGameHandler; import com.nexia.minigames.games.oitc.util.player.OITCPlayerData; +import com.nexia.nexus.api.event.player.PlayerDeathEvent; import com.nexia.nexus.api.world.types.Minecraft; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; @@ -27,7 +28,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.item.ItemEntity; @@ -36,6 +36,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.time.Duration; import java.util.ArrayList; @@ -77,7 +78,7 @@ public class OitcGame { public static void leave(NexiaPlayer player) { - OitcGame.death(player, player.unwrap().getLastDamageSource()); + OitcGame.death(player, null); OITCPlayerData data = (OITCPlayerData) PlayerDataManager.getDataManager(OITC_DATA_MANAGER).get(player); OitcGame.spectator.remove(player); @@ -336,8 +337,15 @@ public static boolean isOITCPlayer(NexiaPlayer player){ return ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode == PlayerGameMode.OITC || player.hasTag("oitc") || player.hasTag("in_oitc_game"); } - public static void death(NexiaPlayer victim, DamageSource source){ + public static void death(NexiaPlayer victim, @Nullable PlayerDeathEvent playerDeathEvent){ OITCPlayerData victimData = (OITCPlayerData) PlayerDataManager.getDataManager(OITC_DATA_MANAGER).get(victim); + + if(playerDeathEvent != null) { + playerDeathEvent.setDropEquipment(false); + playerDeathEvent.setDropExperience(false); + playerDeathEvent.setDropLoot(false); + } + if(OitcGame.isStarted && !OitcGame.deathPlayers.containsKey(victim) && victimData.gameMode == OitcGameMode.PLAYING) { ServerPlayer attacker = PlayerUtil.getPlayerAttacker(victim.unwrap()); if(attacker != null) { diff --git a/src/main/java/com/nexia/minigames/games/skywars/SkywarsGame.java b/src/main/java/com/nexia/minigames/games/skywars/SkywarsGame.java index 7175c997..33cee1cc 100644 --- a/src/main/java/com/nexia/minigames/games/skywars/SkywarsGame.java +++ b/src/main/java/com/nexia/minigames/games/skywars/SkywarsGame.java @@ -15,6 +15,7 @@ import com.nexia.ffa.FfaUtil; import com.nexia.minigames.games.duels.DuelGameHandler; import com.nexia.minigames.games.skywars.util.player.SkywarsPlayerData; +import com.nexia.nexus.api.event.player.PlayerDeathEvent; import com.nexia.nexus.api.world.types.Minecraft; import net.fabricmc.loader.impl.util.StringUtil; import net.kyori.adventure.text.Component; @@ -29,7 +30,6 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.Difficulty; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity; @@ -40,6 +40,7 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.nucleoid.fantasy.RuntimeWorldConfig; import java.time.Duration; @@ -102,7 +103,7 @@ public class SkywarsGame { public static HashMap blockEntities = null; public static void leave(NexiaPlayer player) { - if (player != winner) SkywarsGame.death(player, player.unwrap().getLastDamageSource()); + if (!player.equals(winner)) SkywarsGame.death(player, null); SkywarsPlayerData data = (SkywarsPlayerData) PlayerDataManager.getDataManager(SKYWARS_DATA_MANAGER).get(player); SkywarsGame.spectator.remove(player); @@ -427,7 +428,13 @@ public static boolean isSkywarsPlayer(NexiaPlayer player){ return ((CorePlayerData)PlayerDataManager.getDataManager(NexiaCore.CORE_DATA_MANAGER).get(player)).gameMode == PlayerGameMode.SKYWARS || player.hasTag("skywars"); } - public static void death(NexiaPlayer victim, DamageSource source){ + public static void death(NexiaPlayer victim, @Nullable PlayerDeathEvent playerDeathEvent) { + if(playerDeathEvent != null) { + playerDeathEvent.setDropEquipment(false); + playerDeathEvent.setDropExperience(false); + playerDeathEvent.setDropLoot(false); + } + if (SkywarsGame.winner != null) return; SkywarsPlayerData victimData = (SkywarsPlayerData) PlayerDataManager.getDataManager(SKYWARS_DATA_MANAGER).get(victim); if(SkywarsGame.isStarted && SkywarsGame.alive.contains(victim) && victimData.gameMode == SkywarsGameMode.PLAYING) { @@ -440,6 +447,12 @@ public static void death(NexiaPlayer victim, DamageSource source){ attackerData.savedData.incrementInteger("kills"); } + if(playerDeathEvent != null) { + playerDeathEvent.setDropLoot(true); + playerDeathEvent.setDropExperience(true); + playerDeathEvent.setDropLoot(true); + } + // TODO: re-implement these three ↑↑↑ into nexus, and remove ↓↓ these two victim.unwrap().destroyVanishingCursedItems(); victim.unwrap().inventory.dropAll();