diff --git a/src/main/java/me/lrxh/practice/Practice.java b/src/main/java/me/lrxh/practice/Practice.java index 54e7419..886f070 100644 --- a/src/main/java/me/lrxh/practice/Practice.java +++ b/src/main/java/me/lrxh/practice/Practice.java @@ -149,7 +149,6 @@ public void onEnable() { // Clear the droppedItems for each world getServer().getWorlds().forEach(world -> { world.setDifficulty(Difficulty.HARD); - clearEntities(world); }); for (World world : getInstance().getServer().getWorlds()) { @@ -183,13 +182,16 @@ public void onEnable() { System.gc(); } - public void clearEntities(World world) { - for (Entity entity : world.getEntities()) { - if (!(entity.getType() == EntityType.PLAYER)) { - continue; + public void clearEntities() { + for (World world : practice.getServer().getWorlds()) { + for (Entity entity : world.getEntities()) { + if (!(entity.getType() == EntityType.PLAYER)) { + continue; + } + if(entity.getType().equals(EntityType.DROPPED_ITEM)){ + entity.remove(); + } } - - entity.remove(); } } @@ -248,6 +250,7 @@ private void registerPermissions() { @Override public void onDisable() { + clearEntities(); Match.cleanup(); } diff --git a/src/main/java/me/lrxh/practice/arena/command/ArenaCommand.java b/src/main/java/me/lrxh/practice/arena/command/ArenaCommand.java index f5216f9..58d9f6c 100644 --- a/src/main/java/me/lrxh/practice/arena/command/ArenaCommand.java +++ b/src/main/java/me/lrxh/practice/arena/command/ArenaCommand.java @@ -275,7 +275,7 @@ public void tp(Player player, String arenaName) { if (arena == null) return; player.teleport(arena.getSpawnA()); - player.sendMessage(CC.GREEN + "Teleported to arena " + arena.getDisplayName()); + player.sendMessage(CC.GREEN + "Teleported to arena " + arena.getName()); } @Subcommand("generate") diff --git a/src/main/java/me/lrxh/practice/commands/admin/general/MainCommand.java b/src/main/java/me/lrxh/practice/commands/admin/general/MainCommand.java index ebf42e5..edc6360 100644 --- a/src/main/java/me/lrxh/practice/commands/admin/general/MainCommand.java +++ b/src/main/java/me/lrxh/practice/commands/admin/general/MainCommand.java @@ -24,6 +24,7 @@ public void help(Player player) { player.sendMessage(" "); player.sendMessage(CC.translate("&7* &c/practice setspawn &7- &fSet server spawn")); player.sendMessage(CC.translate("&7* &c/practice reload &7- &fReload all configs")); + player.sendMessage(CC.translate("&7* &c/practice clear &7- &fClear all items")); player.sendMessage(" "); player.sendMessage(CC.translate("&7&m-----------------------------------------")); } @@ -55,4 +56,9 @@ public void reload(Player player) { Practice.getInstance().loadConfigs(); player.sendMessage(CC.translate("&aSuccessfully reloaded configs!")); } + + @Subcommand("clear") + public void clear(Player player) { + Practice.getInstance().clearEntities(); + } } diff --git a/src/main/java/me/lrxh/practice/match/Match.java b/src/main/java/me/lrxh/practice/match/Match.java index 5b4aa4e..c7642d8 100644 --- a/src/main/java/me/lrxh/practice/match/Match.java +++ b/src/main/java/me/lrxh/practice/match/Match.java @@ -19,8 +19,10 @@ import me.lrxh.practice.queue.Queue; import me.lrxh.practice.util.*; import net.md_5.bungee.api.chat.BaseComponent; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; import org.bukkit.*; import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Firework; import org.bukkit.entity.Item; @@ -249,8 +251,8 @@ public void start() { public void end() { for (GameParticipant gameParticipant : getParticipants()) { for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) { + Player player = gamePlayer.getPlayer(); if (!gamePlayer.isDisconnected()) { - Player player = gamePlayer.getPlayer(); if (player != null) { player.setFireTicks(0); player.updateInventory(); @@ -261,7 +263,6 @@ public void end() { profile.setEnderpearlCooldown(new Cooldown(0)); } } else { - Player player = gamePlayer.getPlayer(); if (player != null) { player.setFireTicks(0); player.updateInventory(); @@ -294,9 +295,10 @@ public void end() { removeSpectator(player); } - droppedItems.forEach(Entity::remove); + if (kit.getGameRules().isBuild()) { arena.restoreSnapshot(); + arena.setActive(false); } @@ -500,11 +502,12 @@ public void onDisconnect(Player dead) { } public void onDeath(Player dead) { - PlayerUtil.animateDeath(dead); // Don't continue if the match is already ending if (!(state == MatchState.STARTING_ROUND || state == MatchState.PLAYING_ROUND)) { return; } + dead.getInventory().setContents(new ItemStack[36]); + PlayerUtil.animateDeath(dead); MatchGamePlayer deadGamePlayer = getGamePlayer(dead); Player killer = PlayerUtil.getLastAttacker(dead); diff --git a/src/main/java/me/lrxh/practice/match/MatchListener.java b/src/main/java/me/lrxh/practice/match/MatchListener.java index 6d8ede6..4f6ef79 100644 --- a/src/main/java/me/lrxh/practice/match/MatchListener.java +++ b/src/main/java/me/lrxh/practice/match/MatchListener.java @@ -12,10 +12,7 @@ import me.lrxh.practice.profile.hotbar.HotbarItem; import me.lrxh.practice.util.*; import org.apache.commons.lang.StringEscapeUtils; -import org.bukkit.Color; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; @@ -30,6 +27,7 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.ProjectileSource; +import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.Iterator; @@ -306,14 +304,16 @@ public void onPlayerPickUpEvent(PlayerPickupItemEvent event) { public void onPlayerDeathEvent(PlayerDeathEvent event) { Player player = event.getEntity(); event.setDeathMessage(null); - player.getInventory().setContents(new ItemStack[36]); Profile profile = Profile.getByUuid(event.getEntity().getUniqueId()); if (profile.getState() == ProfileState.FIGHTING) { + Match match = profile.getMatch(); + event.getDrops().clear(); + boolean aTeam = match.getParticipantA().containsPlayer(player.getUniqueId()); boolean bedGone = aTeam ? match.bedBBroken : match.bedABroken; @@ -328,16 +328,6 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) { return; } - List entities = new ArrayList<>(); - - event.getDrops().forEach(itemStack -> { - if (!(itemStack.getType() == Material.BOOK || itemStack.getType() == Material.ENCHANTED_BOOK)) { - entities.add(event.getEntity().getLocation().getWorld() - .dropItemNaturally(event.getEntity().getLocation(), itemStack)); - } - }); - - match.getDroppedItems().addAll(entities); match.onDeath(event.getEntity()); } }