From 96dc86a4814081e3772bfe7a026cb095f8b98eec Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 15 Aug 2015 07:34:04 +0200 Subject: [PATCH 1/7] Fixing map rotation. --- .../src/nautilus/game/arcade/world/WorldData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java index 1bb5955e0..e584708fc 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/world/WorldData.java @@ -151,7 +151,7 @@ public class WorldData File = Host.GetFiles().get(game).get(map); //Don't allow repeat maps. - if (Host.GetFiles().size() > 1) + if (Host.GetFiles().get(game).size() > 1) { while (File.equals(Host.Manager.GetGameCreationManager().GetLastMap())) { From 6e926b431c25daa5b0a82084293080eb9d18c70a Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 19 Aug 2015 16:00:36 +0200 Subject: [PATCH 2/7] Fixing snowballs and eggs in Solo Skywars. --- .../game/arcade/game/games/skywars/Skywars.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java index 91a1f9c19..6feb9d7d7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java @@ -964,8 +964,13 @@ public abstract class Skywars extends Game if (event.GetDamage() >= 1) return; - if(GetTeam(event.GetDamagerPlayer(true)) == GetTeam(event.GetDamageePlayer())) - return; + if(this instanceof TeamSkywars) + { + if(GetTeam(event.GetDamagerPlayer(true)) == GetTeam(event.GetDamageePlayer())) + { + return; + } + } if (event.GetProjectile() instanceof Egg || event.GetProjectile() instanceof Snowball) { @@ -998,6 +1003,10 @@ public abstract class Skywars extends Game { if(event.getEntity() instanceof Player) { + + if(this instanceof SoloSkywars) + return; + if(GetTeam((Player) prj.getShooter()) == GetTeam((Player) event.getEntity())) { event.setCancelled(true); From 15c873392a94b1319fd0d2af96ac90a801683e39 Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Thu, 20 Aug 2015 20:38:07 +0200 Subject: [PATCH 3/7] updated give to allow naming of items. --- .../mineplex/core/common/util/UtilItem.java | 35 ++++++++++++------- .../src/mineplex/core/give/Give.java | 19 ++++++---- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java index cdd967e05..1c874c58b 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java @@ -4,22 +4,24 @@ import java.util.AbstractMap; import java.util.LinkedList; import java.util.Map.Entry; +import mineplex.core.common.structs.ItemContainer; + import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class UtilItem { - public static LinkedList> matchItem(Player caller, String items, boolean inform) + public static LinkedList matchItem(Player caller, String items, boolean inform) { - LinkedList> matchList = new LinkedList>(); + LinkedList matchList = new LinkedList(); String failList = ""; //Mass Search for (String cur : items.split(",")) { - Entry match = searchItem(caller, cur, inform); + ItemContainer match = searchItem(caller, cur, inform); if (match != null) matchList.add(match); @@ -40,21 +42,27 @@ public class UtilItem return matchList; } - public static Entry searchItem(Player caller, String args, boolean inform) + public static ItemContainer searchItem(Player caller, String args, boolean inform) { - LinkedList> matchList = new LinkedList>(); + LinkedList matchList = new LinkedList(); for (Material cur : Material.values()) { + String[] arg = args.split(":"); + + //Get Selected Name + String name = null; + if (arg.length > 2) + name = arg[2].replaceAll("_", " "); + //By Name if (cur.toString().equalsIgnoreCase(args)) - return new AbstractMap.SimpleEntry(cur, (byte)0); + return new ItemContainer(cur, (byte)0, name); if (cur.toString().toLowerCase().contains(args.toLowerCase())) - matchList.add(new AbstractMap.SimpleEntry(cur, (byte)0)); + matchList.add(new ItemContainer(cur, (byte)0, name)); - //By ID:Data - String[] arg = args.split(":"); + //By ID:Data:Name //ID int id = 0; @@ -82,8 +90,8 @@ public class UtilItem { continue; } - - return new AbstractMap.SimpleEntry(cur, data); + + return new ItemContainer(cur, data, name); } //No / Non-Unique @@ -102,8 +110,9 @@ public class UtilItem if (matchList.size() > 0) { String matchString = ""; - for (Entry cur : matchList) - matchString += F.elem(cur.getKey().toString()) + ", "; + for (ItemContainer cur : matchList) + matchString += F.elem(cur.Type.toString()) + ", "; + if (matchString.length() > 1) matchString = matchString.substring(0 , matchString.length() - 2); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java b/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java index 458ad6400..21234daa6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.common.structs.ItemContainer; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilItem; @@ -65,7 +66,7 @@ public class Give extends MiniPlugin public void give(Player player, String target, String itemNames, String amount, String enchants) { //Item - LinkedList> itemList = new LinkedList>(); + LinkedList itemList = new LinkedList(); itemList = UtilItem.matchItem(player, itemNames, true); if (itemList.isEmpty()) return; @@ -128,11 +129,15 @@ public class Give extends MiniPlugin if (givenList.length() > 0) givenList = givenList.substring(0, givenList.length()-1); - for (Entry curItem : itemList) + for (ItemContainer curItem : itemList) { for (Player cur : giveList) { - ItemStack stack = ItemStackFactory.Instance.CreateStack(curItem.getKey(), curItem.getValue(), count); + ItemStack stack; + if (curItem.Name == null) + stack = ItemStackFactory.Instance.CreateStack(curItem.Type, curItem.Data, count); + else + stack = ItemStackFactory.Instance.CreateStack(curItem.Type, curItem.Data, count, curItem.Name); //Enchants stack.addUnsafeEnchantments(enchs); @@ -142,18 +147,18 @@ public class Give extends MiniPlugin { //Inform if (!cur.equals(player)) - UtilPlayer.message(cur, F.main("Give", "You received " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " from " + F.elem(player.getName()) + ".")); + UtilPlayer.message(cur, F.main("Give", "You received " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " from " + F.elem(player.getName()) + ".")); } } if (target.equalsIgnoreCase("all")) - UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " to " + F.elem("ALL")) + "."); + UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " to " + F.elem("ALL")) + "."); else if (giveList.size() > 1) - UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " to " + F.elem(givenList) + ".")); + UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " to " + F.elem(givenList) + ".")); else - UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " to " + F.elem(giveList.getFirst().getName()) + ".")); + UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " to " + F.elem(giveList.getFirst().getName()) + ".")); } } } From 63107b0c26848dc53c117af2a81d1a8c6d593713 Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Thu, 20 Aug 2015 20:39:20 +0200 Subject: [PATCH 4/7] missing file --- .../core/common/structs/ItemContainer.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/structs/ItemContainer.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/structs/ItemContainer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/structs/ItemContainer.java new file mode 100644 index 000000000..64871529b --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/structs/ItemContainer.java @@ -0,0 +1,24 @@ +package mineplex.core.common.structs; + +import org.bukkit.Material; + +public class ItemContainer +{ + public Material Type; + public byte Data; + public String Name; + + public ItemContainer(Material type, byte data, String name) + { + Type = type; + Data = data; + Name = name; + } + + public ItemContainer(int id, byte data, String name) + { + Type = Material.getMaterial(id); + Data = data; + Name = name; + } +} From c41328d7264705a543c3285b6fc494f8aa639246 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 21 Aug 2015 20:40:09 +1200 Subject: [PATCH 5/7] Dead bodies: Change to Item from disguised arrow, fix body positioning, move to Game.java to enable in all games --- .../core/disguise/DisguiseManager.java | 8 +- .../src/nautilus/game/arcade/game/Game.java | 334 +++++++++++++++++- .../games/survivalgames/SurvivalGames.java | 171 +-------- 3 files changed, 337 insertions(+), 176 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java index 86a78df78..6aa48ef1a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java @@ -442,7 +442,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler return new PacketPlayOutMapChunk(_bedChunk, true, 0, UtilPlayer.is1_8(player) ? 48 : 0); } - private Packet[] getBedPackets(Location recieving, DisguisePlayer playerDisguise) + private Packet[] getBedPackets(Location recieving, DisguisePlayer playerDisguise, boolean is18) { try { @@ -458,7 +458,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(playerDisguise.GetEntity()); - teleportPacket.c += (int) (0.35D * 32); + teleportPacket.c += (int) ((is18 ? 0.1D : 0.3D) * 32); return new Packet[] { @@ -502,7 +502,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler && ((DisguisePlayer) entry.getKey()).getSleepingDirection() != null) { - packets.addAll(Arrays.asList(getBedPackets(newLoc, (DisguisePlayer) entry.getKey()))); + packets.addAll(Arrays.asList(getBedPackets(newLoc, (DisguisePlayer) entry.getKey(), UtilPlayer.is1_8(player)))); } } } @@ -853,7 +853,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler if (pDisguise.getSleepingDirection() != null) { - for (Packet packet : getBedPackets(player.getLocation(), pDisguise)) + for (Packet packet : getBedPackets(player.getLocation(), pDisguise, UtilPlayer.is1_8(player))) { handlePacket(packet, packetVerifier); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 075c2afdb..781bfbc1b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -5,30 +5,44 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Map.Entry; import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftItem; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; import org.bukkit.entity.Entity; import org.bukkit.entity.Hanging; +import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; +import org.bukkit.scoreboard.TeamNameTagVisibility; import org.bukkit.util.Vector; import mineplex.core.common.util.C; @@ -40,10 +54,15 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTabTitle; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.disguise.disguises.DisguisePlayer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.packethandler.IPacketHandler; +import mineplex.core.packethandler.PacketInfo; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.classcombat.event.ClassCombatCreatureAllowSpawnEvent; import mineplex.minecraft.game.core.combat.DeathMessageType; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import nautilus.game.arcade.ArcadeFormat; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; @@ -58,7 +77,11 @@ import nautilus.game.arcade.managers.GameLobbyManager; import nautilus.game.arcade.scoreboard.GameScoreboard; import nautilus.game.arcade.stats.*; import nautilus.game.arcade.world.WorldData; -import net.minecraft.server.v1_7_R4.EntityHuman; +import net.minecraft.server.v1_7_R4.EntityItem; +import net.minecraft.server.v1_7_R4.PacketPlayInUseEntity; +import net.minecraft.server.v1_7_R4.PacketPlayOutScoreboardTeam; +import net.minecraft.server.v1_7_R4.ScoreboardTeam; +import net.minecraft.server.v1_7_R4.WorldServer; import net.minecraft.util.com.mojang.authlib.GameProfile; public abstract class Game implements Listener @@ -271,6 +294,18 @@ public abstract class Game implements Listener public boolean VersionRequire1_8 = false; + public boolean DeadBodies = false; + public boolean DeadBodiesQuit = true; + public boolean DeadBodiesDeath = true; + public int DeadBodiesExpire = -1; + + private IPacketHandler _useEntityPacketHandler; + protected Field NameTagVisibility; + protected Field PacketTeam; + private int _deadBodyCount; + private NautHashMap _deadBodies = new NautHashMap(); + private NautHashMap _deadBodiesExpire = new NautHashMap(); + public ArrayList GemBoosters = new ArrayList(); private final Set> _statTrackers = new HashSet<>(); @@ -346,6 +381,41 @@ public abstract class Game implements Listener Manager.setResourcePack(gameType.getResourcePackUrl(), gameType.isEnforceResourcePack()); + try + { + PacketTeam = Class.forName( + "org.bukkit.craftbukkit.v1_7_R4.scoreboard.CraftTeam") + .getDeclaredField("team"); + PacketTeam.setAccessible(true); + + NameTagVisibility = PacketPlayOutScoreboardTeam.class + .getDeclaredField("_nameTagVisibility"); + NameTagVisibility.setAccessible(true); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + _useEntityPacketHandler = new IPacketHandler() + { + @Override + public void handle(PacketInfo packetInfo) + { + if (packetInfo.getPacket() instanceof PacketPlayInUseEntity) + { + net.minecraft.server.v1_7_R4.Entity entity = ((PacketPlayInUseEntity) packetInfo + .getPacket()).a(((CraftWorld) packetInfo + .getPlayer().getWorld()).getHandle()); + + if (entity instanceof EntityItem) + { + packetInfo.setCancelled(true); + } + } + } + }; + System.out.println("Loading " + GetName() + "..."); } @@ -1449,5 +1519,263 @@ public abstract class Game implements Listener //End SetState(GameState.End); } - + + @EventHandler + public void handleEntityPacket(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Live) + { + getArcadeManager().getPacketHandler().addPacketHandler( + _useEntityPacketHandler); + } + else if (event.GetState() == GameState.Dead) + { + getArcadeManager().getPacketHandler().removePacketHandler( + _useEntityPacketHandler); + } + } + + @EventHandler + public void DeadBodyPlayerJoin(PlayerJoinEvent event) + { + for (int i = 0; i < _deadBodyCount; i++) + { + String name = ""; + + for (char c : ("" + i).toCharArray()) + { + name += "§" + c; + } + + try + { + Team team = Scoreboard.GetScoreboard().registerNewTeam(name); + + team.setNameTagVisibility(TeamNameTagVisibility.NEVER); + team.addEntry(name); + + PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam( + (ScoreboardTeam) PacketTeam.get(team), 2); + + UtilPlayer.sendPacket(event.getPlayer(), packet); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + + @EventHandler + public void SpawnPlayerBodyDeath(CombatDeathEvent event) + { + if (!IsLive()) + { + return; + } + + if (!(event.GetEvent().getEntity() instanceof Player)) + return; + + if (!DeadBodiesDeath) + { + return; + } + + spawnDeadBody((Player) event.GetEvent().getEntity()); + } + + @EventHandler(priority = EventPriority.LOW) + public void SpawnBodyQuit(PlayerQuitEvent event) + { + if (!IsLive()) + { + return; + } + + if (!IsAlive(event.getPlayer())) + { + return; + } + + if (!DeadBodiesQuit) + { + return; + } + + spawnDeadBody(event.getPlayer()); + } + + private void spawnDeadBody(Player player) + { + if (!DeadBodies) + { + return; + } + + String name = ""; + + for (char c : ("" + _deadBodyCount++).toCharArray()) + { + name += "§" + c; + } + + try + { + Team team = Scoreboard.GetScoreboard().registerNewTeam(name); + + team.setNameTagVisibility(TeamNameTagVisibility.NEVER); + team.addEntry(name); + + PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam( + (ScoreboardTeam) PacketTeam.get(team), 2); + + for (Player alive : GetPlayers(false)) + { + UtilPlayer.sendPacket(alive, packet); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + GameProfile newProfile = new GameProfile(UUID.randomUUID(), name); + + newProfile.getProperties() + .putAll(((CraftPlayer) player).getHandle().getProfile() + .getProperties()); + + DisguisePlayer disguise = new DisguisePlayer(null, newProfile); + + disguise.setSleeping(getSleepingFace(player.getLocation())); + + getArcadeManager().GetDisguise().addFutureDisguise(disguise); + + Location loc = player.getLocation(); + WorldServer world = ((CraftWorld) loc.getWorld()).getHandle(); + + EntityItem nmsItem = new EntityItem(world, loc.getX(), + loc.getY() + 0.5, loc.getZ(), + CraftItemStack.asNMSCopy(new ItemBuilder(Material.STONE) + .setTitle(System.currentTimeMillis() + "").build())); + + nmsItem.motX = 0; + nmsItem.motY = 0; + nmsItem.motZ = 0; + nmsItem.yaw = 0; + + world.addEntity(nmsItem); + + Item entity = new CraftItem(world.getServer(), nmsItem); + + entity.setPickupDelay(Integer.MAX_VALUE); + + _deadBodies.put(player.getName(), entity); + + if (DeadBodiesExpire > 0) + { + _deadBodiesExpire.put(player.getName(), System.currentTimeMillis() + + (DeadBodiesExpire * 1000)); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onSpawn(ItemSpawnEvent event) + { + if (_deadBodies.containsValue(event.getEntity())) + { + event.setCancelled(false); + + ((CraftEntity) event.getEntity()).getHandle().dead = false; + } + } + + public NautHashMap getDeadBodies() + { + return _deadBodies; + } + + public void cleanDeadBodies() + { + for (Entity entity : _deadBodies.values()) + { + entity.remove(); + } + + _deadBodies.clear(); + _deadBodiesExpire.clear(); + _deadBodyCount = 0; + } + + private BlockFace getSleepingFace(Location loc) + { + Block block = loc.getBlock(); + + while (block.getY() > 0 + && !UtilBlock.fullSolid(block.getRelative(BlockFace.DOWN)) + && !UtilBlock.solid(block.getRelative(BlockFace.DOWN))) + { + block = block.getRelative(BlockFace.DOWN); + } + + BlockFace proper = BlockFace.values()[Math.round(loc.getYaw() / 90F) & 0x3] + .getOppositeFace(); + + // A complicated way to get the face the dead body should be towards. + for (HashSet validBlocks : new HashSet[] + { + UtilBlock.blockAirFoliageSet, UtilBlock.blockPassSet + }) + { + + if (validBlocks.contains((byte) block.getRelative(proper) + .getTypeId())) + { + return proper; + } + + for (BlockFace face : new BlockFace[] + { + BlockFace.EAST, BlockFace.SOUTH, BlockFace.NORTH, + BlockFace.WEST + }) + { + if (validBlocks.contains((byte) block.getRelative(face) + .getTypeId())) + { + return face; + } + } + } + + return proper; + } + + @EventHandler + public void onDeadBodiesExpireUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + Iterator> itel = _deadBodiesExpire.entrySet() + .iterator(); + + while (itel.hasNext()) + { + Entry entry = itel.next(); + + if (entry.getValue() < System.currentTimeMillis()) + { + if (_deadBodies.containsKey(entry.getKey())) + { + _deadBodies.remove(entry.getKey()).remove(); + } + + itel.remove(); + } + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java index a46a085de..a7699db24 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java @@ -13,9 +13,7 @@ import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; import org.bukkit.block.Furnace; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftArrow; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftLargeFireball; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Boat; import org.bukkit.entity.Egg; import org.bukkit.entity.Entity; @@ -56,7 +54,6 @@ import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -import org.bukkit.scoreboard.TeamNameTagVisibility; import org.bukkit.util.Vector; import mineplex.core.common.util.C; @@ -74,16 +71,11 @@ import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; -import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.loot.*; -import mineplex.core.packethandler.IPacketHandler; -import mineplex.core.packethandler.PacketInfo; import mineplex.core.packethandler.PacketPlayOutWorldBorder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; @@ -97,22 +89,18 @@ import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.games.survivalgames.kit.*; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.stats.FirstSupplyDropOpenStatTracker; import nautilus.game.arcade.stats.KillsWithinTimeLimitStatTracker; import nautilus.game.arcade.stats.SimultaneousSkeletonStatTracker; import nautilus.game.arcade.stats.WinWithoutWearingArmorStatTracker; -import net.minecraft.server.v1_7_R4.EntityArrow; import net.minecraft.server.v1_7_R4.EntityLargeFireball; -import net.minecraft.server.v1_7_R4.PacketPlayInUseEntity; import net.minecraft.server.v1_7_R4.PacketPlayOutScoreboardTeam; import net.minecraft.server.v1_7_R4.ScoreboardTeam; import net.minecraft.server.v1_7_R4.TileEntity; import net.minecraft.server.v1_7_R4.TileEntityChest; import net.minecraft.server.v1_7_R4.WorldServer; -import net.minecraft.util.com.mojang.authlib.GameProfile; public abstract class SurvivalGames extends Game { @@ -156,8 +144,6 @@ public abstract class SurvivalGames extends Game private Field _nameTagVisibility; private Field _packetTeam; - private IPacketHandler _useEntityPacketHandler; - private int _deadBodyCount; private int _chestRefillTime = 60 * 7; private NautHashMap _openedChests = new NautHashMap(); @@ -239,6 +225,7 @@ public abstract class SurvivalGames extends Game PrepareTime = 15000; VersionRequire1_8 = true; + DeadBodies = true; BlockBreakAllow.add(Material.WEB.getId()); // Web BlockPlaceAllow.add(Material.WEB.getId()); @@ -285,24 +272,6 @@ public abstract class SurvivalGames extends Game ex.printStackTrace(); } - _useEntityPacketHandler = new IPacketHandler() - { - @Override - public void handle(PacketInfo packetInfo) - { - if (packetInfo.getPacket() instanceof PacketPlayInUseEntity) - { - net.minecraft.server.v1_7_R4.Entity entity = ((PacketPlayInUseEntity) packetInfo.getPacket()) - .a(((CraftWorld) packetInfo.getPlayer().getWorld()).getHandle()); - - if (entity instanceof EntityArrow) - { - packetInfo.setCancelled(true); - } - } - } - }; - registerStatTrackers(new WinWithoutWearingArmorStatTracker(this), new KillsWithinTimeLimitStatTracker(this, 3, 60, "Bloodlust"), new FirstSupplyDropOpenStatTracker(this), new SimultaneousSkeletonStatTracker(this, 5)); } @@ -788,126 +757,6 @@ public abstract class SurvivalGames extends Game } } - private BlockFace getFace(Location loc) - { - Block block = loc.getBlock(); - - while (block.getY() > 0 && !UtilBlock.fullSolid(block.getRelative(BlockFace.DOWN)) - && !UtilBlock.solid(block.getRelative(BlockFace.DOWN))) - { - block = block.getRelative(BlockFace.DOWN); - } - - BlockFace proper = BlockFace.values()[Math.round(loc.getYaw() / 90F) & 0x3].getOppositeFace(); - - // A complicated way to get the face the dead body should be towards. - for (HashSet validBlocks : new HashSet[] - { - UtilBlock.blockAirFoliageSet, UtilBlock.blockPassSet - }) - { - - if (validBlocks.contains((byte) block.getRelative(proper).getTypeId())) - { - return proper; - } - - for (BlockFace face : new BlockFace[] - { - BlockFace.EAST, BlockFace.SOUTH, BlockFace.NORTH, BlockFace.WEST - }) - { - if (validBlocks.contains((byte) block.getRelative(face).getTypeId())) - { - return face; - } - } - } - - return proper; - } - - private void deathOrQuit(Player player) - { - String name = ""; - - for (char c : ("" + _deadBodyCount++).toCharArray()) - { - name += "§" + c; - } - - try - { - - Team team = Scoreboard.GetScoreboard().registerNewTeam(name); - - if (!_hiddenNames.get(player).isEmpty()) - { - ScoreboardTeam nmsTeam = (ScoreboardTeam) _packetTeam.get(team); - - PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam(nmsTeam, 2); - - Field teamName = PacketPlayOutScoreboardTeam.class.getDeclaredField("a"); - teamName.setAccessible(true); - Field displayName = PacketPlayOutScoreboardTeam.class.getDeclaredField("b"); - displayName.setAccessible(true); - - for (Player alive : GetPlayers(true)) - { - if (_hiddenNames.get(player).contains(alive.getName())) - { - teamName.set(packet, alive.getName()); - displayName.set(packet, alive.getName()); - - UtilPlayer.sendPacket(player, packet); - } - } - } - - _hiddenNames.remove(player); - - team.setNameTagVisibility(TeamNameTagVisibility.NEVER); - team.addEntry(name); - - PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam((ScoreboardTeam) _packetTeam.get(team), 2); - - for (Player alive : GetPlayers(false)) - { - UtilPlayer.sendPacket(alive, packet); - } - - } - catch (Exception ex) - { - ex.printStackTrace(); - } - - GameProfile newProfile = new GameProfile(UUID.randomUUID(), name); - - newProfile.getProperties().putAll(((CraftPlayer) player).getHandle().getProfile().getProperties()); - - DisguisePlayer disguise = new DisguisePlayer(null, newProfile); - - disguise.setSleeping(getFace(player.getLocation())); - - getArcadeManager().GetDisguise().addFutureDisguise(disguise); - - Entity entity = player.getWorld().spawnEntity(player.getLocation(), EntityType.ARROW); - - try - { - EntityArrow entityArrow = ((CraftArrow) entity).getHandle(); - - Field at = EntityArrow.class.getDeclaredField("at"); - at.setAccessible(true); - at.set(entityArrow, Integer.MIN_VALUE); // Despawn time - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - @EventHandler public void DisableDamageLevel(CustomDamageEvent event) { @@ -1028,19 +877,6 @@ public abstract class SurvivalGames extends Game return 12; } - @EventHandler - public void handleEntityPacket(GameStateChangeEvent event) - { - if (event.GetState() == GameState.Live) - { - getArcadeManager().getPacketHandler().addPacketHandler(_useEntityPacketHandler); - } - else if (event.GetState() == GameState.Dead) - { - getArcadeManager().getPacketHandler().removePacketHandler(_useEntityPacketHandler); - } - } - // If an item spawns and no one is there to see it, does it really spawn? No. @EventHandler public void ItemSpawn(ItemSpawnEvent event) @@ -1543,8 +1379,6 @@ public abstract class SurvivalGames extends Game Player player = (Player) event.GetEvent().getEntity(); - deathOrQuit(player); - FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.RED).with(Type.BALL_LARGE).trail(false) .build(); for (int i = 0; i < 3; i++) @@ -1673,8 +1507,7 @@ public abstract class SurvivalGames extends Game return; } - deathOrQuit(event.getPlayer()); - + _hiddenNames.remove(event.getPlayer()); } private void setBorder() From bad339cf04ead2e63800b0bb41870b9df73ab4de Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 21 Aug 2015 20:52:57 +1200 Subject: [PATCH 6/7] Tweak dead bodies more --- .../core/disguise/DisguiseManager.java | 2 +- .../src/nautilus/game/arcade/game/Game.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java index 6aa48ef1a..0e1a9c9d5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java @@ -458,7 +458,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(playerDisguise.GetEntity()); - teleportPacket.c += (int) ((is18 ? 0.1D : 0.3D) * 32); + teleportPacket.c += (int) ((is18 ? 0.07D : 0.25D) * 32); return new Packet[] { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 781bfbc1b..4fa5ee78e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -1521,7 +1521,7 @@ public abstract class Game implements Listener } @EventHandler - public void handleEntityPacket(GameStateChangeEvent event) + public void handleInteractEntityPacket(GameStateChangeEvent event) { if (event.GetState() == GameState.Live) { @@ -1536,7 +1536,7 @@ public abstract class Game implements Listener } @EventHandler - public void DeadBodyPlayerJoin(PlayerJoinEvent event) + public void onDeadBodyJoin(PlayerJoinEvent event) { for (int i = 0; i < _deadBodyCount; i++) { @@ -1549,10 +1549,12 @@ public abstract class Game implements Listener try { - Team team = Scoreboard.GetScoreboard().registerNewTeam(name); + Team team = Scoreboard.GetScoreboard().getTeam(name); - team.setNameTagVisibility(TeamNameTagVisibility.NEVER); - team.addEntry(name); + if (team == null) + { + continue; + } PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam( (ScoreboardTeam) PacketTeam.get(team), 2); @@ -1567,7 +1569,7 @@ public abstract class Game implements Listener } @EventHandler - public void SpawnPlayerBodyDeath(CombatDeathEvent event) + public void onDeadBodyDeath(CombatDeathEvent event) { if (!IsLive()) { @@ -1586,7 +1588,7 @@ public abstract class Game implements Listener } @EventHandler(priority = EventPriority.LOW) - public void SpawnBodyQuit(PlayerQuitEvent event) + public void onDeadBodyQuit(PlayerQuitEvent event) { if (!IsLive()) { @@ -1681,7 +1683,7 @@ public abstract class Game implements Listener } @EventHandler(priority = EventPriority.HIGHEST) - public void onSpawn(ItemSpawnEvent event) + public void onDeadBodyItemSpawn(ItemSpawnEvent event) { if (_deadBodies.containsValue(event.getEntity())) { @@ -1753,7 +1755,7 @@ public abstract class Game implements Listener } @EventHandler - public void onDeadBodiesExpireUpdate(UpdateEvent event) + public void onDeadBodiesExpire(UpdateEvent event) { if (event.getType() != UpdateType.SEC) { From 7841b17d0343e930f5047b0ceaa7675326a823c7 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 22 Aug 2015 00:38:37 +1200 Subject: [PATCH 7/7] Add PacketPlayOutCamera for locking view to entity --- .../core/packethandler/PacketHandler.java | 3 +- .../packethandler/PacketPlayOutCamera.java | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java index 008aa8f1f..056b75877 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java @@ -50,7 +50,8 @@ public class PacketHandler extends MiniPlugin Method method = ProtocolInjector.class.getDeclaredMethod("addPacket", EnumProtocol.class,boolean.class, int.class, Class.class); method.setAccessible(true); - + + method.invoke(null, EnumProtocol.PLAY, true, 67, PacketPlayOutCamera.class); method.invoke(null, EnumProtocol.PLAY, true, 68, PacketPlayOutWorldBorder.class); // EnumProtocol.PLAY.b().put(68, PacketPlayOutWorldBorder.class); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java new file mode 100644 index 000000000..11dd54051 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketPlayOutCamera.java @@ -0,0 +1,44 @@ +package mineplex.core.packethandler; + +import org.bukkit.entity.Entity; + +import net.minecraft.server.v1_7_R4.Packet; +import net.minecraft.server.v1_7_R4.PacketDataSerializer; +import net.minecraft.server.v1_7_R4.PacketListener; + +public class PacketPlayOutCamera extends Packet +{ + public int a; + + public PacketPlayOutCamera() + { + } + + public PacketPlayOutCamera(int id) + { + a = id; + } + + public PacketPlayOutCamera(Entity paramEntity) + { + this.a = paramEntity.getEntityId(); + } + + public void a(PacketDataSerializer paramPacketDataSerializer) + { + } + + public void b(PacketDataSerializer paramPacketDataSerializer) + { + paramPacketDataSerializer.b(this.a); + } + + public void a(PacketListener paramPacketListenerPlayOut) + { + } + + @Override + public void handle(PacketListener arg0) + { + } +} \ No newline at end of file