From 0ffa67dfb8d7ee719a78f19ce062edce745a313a Mon Sep 17 00:00:00 2001 From: git Date: Thu, 3 Mar 2016 13:48:22 +1300 Subject: [PATCH 01/10] Ring game --- .../mineplex/core/common/util/UtilShapes.java | 75 ++++-- .../src/mineplex/core/game/GameDisplay.java | 1 + .../src/nautilus/game/arcade/Arcade.java | 2 +- .../nautilus/game/arcade/ArcadeManager.java | 1 + .../src/nautilus/game/arcade/GameType.java | 2 + .../arcade/game/games/rings/ElytraRings.java | 252 ++++++++++++++++++ .../game/arcade/game/games/rings/Ring.java | 73 +++++ 7 files changed, 383 insertions(+), 23 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/Ring.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java index dfff5bd5c..6013f85c3 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java @@ -11,38 +11,40 @@ public class UtilShapes { private final static BlockFace[] radial = { - BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST, BlockFace.NORTH, - BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST + BlockFace.SOUTH, + BlockFace.SOUTH_WEST, + BlockFace.WEST, + BlockFace.NORTH_WEST, + BlockFace.NORTH, + BlockFace.NORTH_EAST, + BlockFace.EAST, + BlockFace.SOUTH_EAST }; public static ArrayList getCircle(Location loc, boolean hollow, double radius) { - return getCircleBlocks(loc, radius, 0, hollow, false); + return getSphereBlocks(loc, radius, 0, hollow); } - public static ArrayList getSphereBlocks(Location loc, double radius, double height, boolean hollow) - { - return getCircleBlocks(loc, radius, height, hollow, true); - } - - private static ArrayList getCircleBlocks(Location loc, double radius, double height, boolean hollow, boolean sphere) + public static ArrayList getSphereBlocks(Location loc, double width, double height, boolean hollow) { ArrayList circleblocks = new ArrayList(); double cx = loc.getBlockX(); double cy = loc.getBlockY(); double cz = loc.getBlockZ(); - for (double y = (sphere ? cy - radius : cy); y < (sphere ? cy + radius : cy + height + 1); y++) + for (double y = height; y < height + 1; y++) { - for (double x = cx - radius; x <= cx + radius; x++) + for (double x = -width; x <= width; x++) { - for (double z = cz - radius; z <= cz + radius; z++) + for (double z = -width; z <= width; z++) { - double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (sphere ? (cy - y) * (cy - y) : 0); + double dist = (x * x) + (z * z) + (y * y); - if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1))) + if (dist < width * width + && !(hollow && Math.abs(x) - width < 1 && Math.abs(z) - width < 1 && Math.abs(y) - height < 1)) { - Location l = new Location(loc.getWorld(), x, y, z); + Location l = new Location(loc.getWorld(), x + cx, y + cy, z + cz); circleblocks.add(l); } } @@ -75,7 +77,8 @@ public class UtilShapes right = radial[high]; return new BlockFace[] { - left, right + left, + right }; } } @@ -87,13 +90,19 @@ public class UtilShapes BlockFace[] faces = getSideBlockFaces(facing); return new Block[] { - b.getRelative(faces[0]), b.getRelative(faces[1]) + b.getRelative(faces[0]), + b.getRelative(faces[1]) }; } public static BlockFace getFacing(float yaw) { - return radial[Math.round(yaw / 45f) & 0x7]; + return radial[Math.round(yaw / 45f) % 8]; + } + + public static float getFacing(BlockFace face) + { + return UtilAlg.GetYaw(new Vector(face.getModX(), face.getModY(), face.getModZ()).normalize()); } public static ArrayList getLinesDistancedPoints(Location startingPoint, Location endingPoint, @@ -133,6 +142,24 @@ public class UtilShapes return locs; } + /** + * Rotates the blocks around 0,0,0 + */ + public static ArrayList rotate(ArrayList locs, double degree) + { + ArrayList rotated = new ArrayList(); + + for (Location loc : locs) + { + double xRot = Math.cos(degree) * (loc.getX()) - Math.sin(degree) * (loc.getZ()); + double zRot = loc.getZ() + Math.sin(degree) * (loc.getX()) + Math.cos(degree) * (loc.getZ()); + + rotated.add(new Location(loc.getWorld(), xRot, loc.getY(), zRot)); + } + + return rotated; + } + public static ArrayList getDistancedCircle(Location center, double pointsDistance, double circleRadius) { return getPointsInCircle(center, (int) ((circleRadius * Math.PI * 2) / pointsDistance), circleRadius); @@ -157,12 +184,14 @@ public class UtilShapes new int[] { - allowDiagonal ? facing.getModX() : facing.getModZ(), allowDiagonal ? 0 : -facing.getModX() + allowDiagonal ? facing.getModX() : facing.getModZ(), + allowDiagonal ? 0 : -facing.getModX() }, new int[] { - allowDiagonal ? 0 : -facing.getModZ(), allowDiagonal ? facing.getModZ() : facing.getModX() + allowDiagonal ? 0 : -facing.getModZ(), + allowDiagonal ? facing.getModZ() : facing.getModX() } }; @@ -189,7 +218,8 @@ public class UtilShapes { faces = new BlockFace[] { - faces[1], faces[0] + faces[1], + faces[0] }; } @@ -228,7 +258,8 @@ public class UtilShapes return new Block[] { - b.getRelative(faces[0]), b.getRelative(faces[1]) + b.getRelative(faces[0]), + b.getRelative(faces[1]) }; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java index ac497cd48..d42a5b2a9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java @@ -21,6 +21,7 @@ public enum GameDisplay Dragons("Dragons", Material.ENDER_STONE, (byte)0, GameCategory.ARCADE, 13), DragonsTeams("Dragons Teams", Material.DRAGON_EGG, (byte)0, GameCategory.TEAM_VARIANT, 14), Draw("Draw My Thing", Material.BOOK_AND_QUILL, (byte)0, GameCategory.CLASSICS, 15), + ElytraRings("ElytraRings", Material.ELYTRA, (byte) 0, GameCategory.CLASSICS, 61), Evolution("Evolution", Material.EMERALD, (byte)0, GameCategory.ARCADE, 16), Gravity("Gravity", Material.ENDER_PORTAL_FRAME, (byte)0, GameCategory.EXTRA, 18), Halloween("Halloween Horror", Material.PUMPKIN, (byte)0, GameCategory.CLASSICS, 19), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 9bec8fee2..9dee1d16f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -216,7 +216,7 @@ public class Arcade extends JavaPlugin for (String gameName : _serverConfiguration.getServerGroup().getGames().split(",")) { try - { + {System.out.println(gameName); GameType type = GameType.valueOf(gameName); config.GameList.add(type); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 5ae8d2c00..3febcccc4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -105,6 +105,7 @@ import nautilus.game.arcade.managers.IdleManager; import nautilus.game.arcade.managers.MiscManager; import nautilus.game.arcade.player.ArcadePlayer; import nautilus.game.arcade.shop.ArcadeShop; +import net.minecraft.server.v1_8_R3.EntityLiving; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 252d24a03..08ae8fec4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -41,6 +41,7 @@ import nautilus.game.arcade.game.games.oldmineware.OldMineWare; import nautilus.game.arcade.game.games.paintball.Paintball; import nautilus.game.arcade.game.games.quiver.Quiver; import nautilus.game.arcade.game.games.quiver.QuiverTeams; +import nautilus.game.arcade.game.games.rings.ElytraRings; import nautilus.game.arcade.game.games.runner.Runner; import nautilus.game.arcade.game.games.searchanddestroy.SearchAndDestroy; import nautilus.game.arcade.game.games.sheep.SheepGame; @@ -89,6 +90,7 @@ public enum GameType Dragons(Dragons.class, GameDisplay.Dragons), DragonsTeams(DragonsTeams.class, GameDisplay.DragonsTeams), Draw(Draw.class, GameDisplay.Draw), + ElytraRings(ElytraRings.class, GameDisplay.ElytraRings), Evolution(Evolution.class, GameDisplay.Evolution), Gravity(Gravity.class, GameDisplay.Gravity), Halloween(Halloween.class, GameDisplay.Halloween, "http://file.mineplex.com/ResHalloween.zip", true), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java new file mode 100644 index 000000000..00920d3c2 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java @@ -0,0 +1,252 @@ +package nautilus.game.arcade.game.games.rings; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilShapes; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.events.PlayerGameRespawnEvent; +import nautilus.game.arcade.game.SoloGame; +import nautilus.game.arcade.game.games.uhc.KitUHC; +import nautilus.game.arcade.kit.Kit; + +public class ElytraRings extends SoloGame +{ + private HashMap _rings = new HashMap(); + private HashMap _goneThrough = new HashMap(); + private HashMap _lastLocation = new HashMap(); + + public ElytraRings(ArcadeManager manager) + { + super(manager, GameType.ElytraRings, new Kit[] + { + new KitUHC(manager) + }, new String[] + { + "Fly through the rings!" + }); + + DeathOut = false; + DeathMessages = false; + } + + public void RespawnPlayer(final Player player) + { + player.eject(); + + if (_goneThrough.containsKey(player.getUniqueId()) && _rings.containsKey(_goneThrough.get(player.getUniqueId()))) + { + Ring ring = _rings.get(_goneThrough.get(player.getUniqueId())); + + player.teleport(ring.getCenter()); + } + else if (_goneThrough.containsKey(player.getUniqueId()) && _rings.containsKey(_goneThrough.get(player.getUniqueId()) + 1)) + { + Ring ring = _rings.get(_goneThrough.get(player.getUniqueId()) + 1); + + player.teleport(ring.getCenter()); + } + else + { + player.teleport(GetTeam(player).GetSpawn()); + } + + Manager.Clear(player); + + // Event + PlayerGameRespawnEvent event = new PlayerGameRespawnEvent(this, player); + UtilServer.getServer().getPluginManager().callEvent(event); + + // Re-Give Kit + Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + { + public void run() + { + GetKit(player).ApplyKit(player); + } + }, 0); + } + + @Override + public void ParseData() + { + Location loc = UtilAlg.getAverageLocation(GetTeamList().get(0).GetSpawns()); + BlockFace currentDirection = BlockFace.values()[UtilMath.r(4)]; + + while (_rings.size() < 30) + { + int dist = UtilMath.r(40); + + loc = loc.getBlock().getRelative(currentDirection, 20).getLocation(); + + generateRing(loc, currentDirection, 2 + UtilMath.r(2) + UtilMath.r(2)); + } + + loc = loc.getBlock().getRelative(currentDirection, 20).getLocation(); + + Ring ring = generateRing(loc, currentDirection, 7); + + for (Block b : ring.getRing()) + { + b.setType(Material.GOLD_BLOCK); + } + } + + @EventHandler + public void onGameStart(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + return; + + for (Player player : this.GetPlayers(true)) + { + player.getInventory().setChestplate(new ItemStack(Material.ELYTRA)); + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event) + { + if (event.isCancelled()) + return; + + if (!IsAlive(event.getPlayer())) + return; + + Player player = event.getPlayer(); + int current = 1; + + if (_goneThrough.containsKey(player.getUniqueId())) + { + current = _goneThrough.get(player.getUniqueId()) + 1; + } + + if (!_rings.containsKey(current)) + { + return; + } + + Ring ring = _rings.get(current); + + if (!ring.isMoveThroughRing(event.getFrom(), event.getTo())) + { + return; + } + + _goneThrough.put(player.getUniqueId(), current + 1); + + Announce(player.getName() + " has gone through ring " + current + "!"); + } + + @EventHandler + public void onSpeedBoost(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + for (Player player : GetPlayers(true)) + { + float exp = player.getExp(); + + exp += 0.02; + + if (exp > 0.05 && _lastLocation.containsKey(player.getUniqueId())) + { + UtilAction.velocity(player, player.getLocation().getDirection()); + + if (!_goneThrough.containsKey(player.getUniqueId()) + || _rings.containsKey(_goneThrough.get(player.getUniqueId()) + 1)) + { + exp -= 0.05; + } + + for (Location loc : UtilShapes.getLinesDistancedPoints(_lastLocation.get(player.getUniqueId()), + player.getLocation(), 0.3)) + { + UtilParticle.PlayParticleToAll(ParticleType.CLOUD, loc, 0.2F, 0.2F, 0.2F, 0, 3, ViewDist.LONGER); + } + + _lastLocation.put(player.getUniqueId(), player.getLocation()); + } + + player.setExp(Math.min(exp, 1)); + } + } + + @EventHandler + public void onToggleSneak(PlayerToggleSneakEvent event) + { + if (!IsAlive(event.getPlayer())) + { + return; + } + + Player player = event.getPlayer(); + + if (event.isSneaking()) + { + _lastLocation.put(player.getUniqueId(), player.getLocation()); + } + else + { + _lastLocation.remove(player.getUniqueId()); + } + } + + private Ring generateRing(Location center, BlockFace direction, int size) + { + ArrayList blocks = new ArrayList(); + ArrayList hole = new ArrayList(); + + for (Location loc : UtilShapes.rotate(UtilShapes.getSphereBlocks(center, size, size, true), + UtilShapes.getFacing(direction))) + { + blocks.add(loc.getBlock()); + } + + size--; + + for (Location loc : UtilShapes.rotate(UtilShapes.getSphereBlocks(center, size, size, false), + UtilShapes.getFacing(direction))) + { + hole.add(loc.getBlock()); + } + + center.setDirection(new Vector(direction.getModX(), direction.getModY(), direction.getModZ())); + + Ring ring = new Ring(blocks, hole, center.clone()); + + for (Block b : ring.getRing()) + { + b.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 4, false); + } + + _rings.put(_rings.size() + 1, ring); + + return ring; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/Ring.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/Ring.java new file mode 100644 index 000000000..8004c3496 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/Ring.java @@ -0,0 +1,73 @@ +package nautilus.game.arcade.game.games.rings; + +import java.util.ArrayList; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; + +public class Ring +{ + private ArrayList _core = new ArrayList(); + private ArrayList _ring = new ArrayList(); + private Location _center; + + public Ring(ArrayList blocks, ArrayList inside, Location center) + { + _core = inside; + _ring = blocks; + _center = center; + } + + public Location getCenter() + { + return _center; + } + + public ArrayList getRing() + { + return _ring; + } + + public boolean isMoveThroughRing(Location from, Location to) + { + from = from.clone(); + to = to.clone(); + from.setX(from.getBlockX() + 0.5); + from.setY(from.getBlockY() + 0.5); + from.setZ(from.getBlockZ() + 0.5); + to.setX(to.getBlockX() + 0.5); + to.setY(to.getBlockY() + 0.5); + to.setZ(to.getBlockZ() + 0.5); + + Vector vec = UtilAlg.getTrajectory(from, to).multiply(0.5); + double dist = UtilMath.offset(from, to); + + while (dist > 0) + { + dist -= 0.5; + + Location loc = from.getBlock().getLocation().add(0.5, 0.5, 0.5); + + if (_core.contains(loc.getBlock())) + return true; + + if (_core.contains(loc.clone().add(loc.getX() == 0 ? 0 : loc.getX() > 0 ? 1 : -1, 0, 0))) + return true; + + if (_core.contains(loc.clone().add(0, loc.getY() == 0 ? 0 : loc.getY() > 0 ? 1 : -1, 0))) + return true; + + if (_core.contains(loc.clone().add(0, 0, loc.getZ() == 0 ? 0 : loc.getZ() > 0 ? 1 : -1))) + return true; + + from.add(vec); + } + + return false; + } + +} From 496983ee046ce753e3483b57fba6e3fb12a4d003 Mon Sep 17 00:00:00 2001 From: git Date: Mon, 7 Mar 2016 22:29:14 +1300 Subject: [PATCH 02/10] Untested bugfixes --- .../mineplex/core/common/util/UtilPlayer.java | 25 ++++++ .../src/mineplex/core/CustomTagFix.java | 33 +++---- .../src/mineplex/core/game/GameDisplay.java | 2 +- .../nautilus/game/arcade/ArcadeManager.java | 5 ++ .../arcade/game/games/hideseek/HideSeek.java | 63 ++++++-------- .../game/games/hideseek/forms/BlockForm.java | 86 ++++++++++--------- 6 files changed, 120 insertions(+), 94 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index 85c30066f..db6e9b2a4 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -789,4 +789,29 @@ public class UtilPlayer return null; } + + public static boolean isGliding(Player player) + { + return ((CraftPlayer) player).getHandle().isGliding(); + } + + public static void setGliding(Player player, boolean gliding) + { + ((CraftPlayer) player).getHandle().setGliding(gliding); + } + + public static void setAutoDeploy(Player player, boolean autoDeploy) + { + ((CraftPlayer) player).getHandle().setAutoWingsDeploy(autoDeploy); + } + + public static void setGlidableWithoutWings(Player player, boolean glidableWithoutWings) + { + ((CraftPlayer) player).getHandle().setGlidableWithoutWings(glidableWithoutWings); + } + + public static void setAutoDeployDistance(Player player, float distance) + { + ((CraftPlayer) player).getHandle().setWingsDeployAt(distance); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java index c71f85960..4f8199ed7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java @@ -71,8 +71,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class, PacketPlayOutNamedEntitySpawn.class, PacketPlayInUseEntity.class, PacketPlayOutAttachEntity.class); -// NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this); -// NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this); + // NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this); + // NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this); NCPHookManager.addHook(CheckType.ALL, this); } @@ -256,15 +256,16 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook return; } - int newId = UtilEnt.getNewEntityId(); + Integer[] ids = new Integer[] + { + UtilEnt.getNewEntityId(), + UtilEnt.getNewEntityId() + }; _entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName); - _entityMap.get(owner.getName()).put(spawnPacket.a, new Integer[] - { - newId - }); + _entityMap.get(owner.getName()).put(spawnPacket.a, ids); - sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier, true, -1); + sendProtocolPackets(owner, spawnPacket.a, ids[1], entityName, verifier, true, ids[0]); break; } } @@ -331,13 +332,13 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } String newName = currentName; - boolean newDisplay = isDisplaying; + boolean displayName = isDisplaying; for (WatchableObject watchable : (List) metaPacket.b) { if (watchable.a() == 3 && watchable.b() instanceof Byte) { - newDisplay = ((Byte) watchable.b()) == 1; + displayName = ((Byte) watchable.b()) == 1; } if (watchable.a() == 2 && watchable.b() instanceof String) @@ -347,10 +348,10 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } // If the name has changed and the name should be showing, or the name display status has changed. - if ((!newName.equals(currentName) && newDisplay) || newDisplay != isDisplaying) + if ((!newName.equals(currentName) && displayName) || displayName != isDisplaying) { // If name is still being displayed - if (newDisplay) + if (displayName) { Integer[] newId; @@ -363,6 +364,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook { newId = new Integer[] { + UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId() }; @@ -370,7 +372,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } _entityNameMap.get(owner.getName()).put(metaPacket.a, newName); - sendProtocolPackets(owner, metaPacket.a, newId[0], newName, verifier, !isDisplaying, -1); + sendProtocolPackets(owner, metaPacket.a, newId[1], newName, verifier, !isDisplaying, + !isDisplaying ? newId[0] : -1); } else { // Lets delete it @@ -483,8 +486,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook _entityRiding.get(owner.getName()).remove(attachPacket.b); - sendProtocolPackets(owner, vehicleId, ids[ids.length - 1], _entityNameMap.get(owner.getName()).get(vehicleId), - verifier, true, ids.length > 1 ? ids[0] : -1); + sendProtocolPackets(owner, vehicleId, ids[1], _entityNameMap.get(owner.getName()).get(vehicleId), verifier, + true, ids[0]); } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java index d42a5b2a9..d14d5c35b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java @@ -21,7 +21,7 @@ public enum GameDisplay Dragons("Dragons", Material.ENDER_STONE, (byte)0, GameCategory.ARCADE, 13), DragonsTeams("Dragons Teams", Material.DRAGON_EGG, (byte)0, GameCategory.TEAM_VARIANT, 14), Draw("Draw My Thing", Material.BOOK_AND_QUILL, (byte)0, GameCategory.CLASSICS, 15), - ElytraRings("ElytraRings", Material.ELYTRA, (byte) 0, GameCategory.CLASSICS, 61), + ElytraRings("Elytra Rings", Material.ELYTRA, (byte) 0, GameCategory.CLASSICS, 61), Evolution("Evolution", Material.EMERALD, (byte)0, GameCategory.ARCADE, 16), Gravity("Gravity", Material.ENDER_PORTAL_FRAME, (byte)0, GameCategory.EXTRA, 18), Halloween("Halloween Horror", Material.PUMPKIN, (byte)0, GameCategory.CLASSICS, 19), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 3febcccc4..1767c67d6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -871,6 +871,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation UtilInv.Clear(player); + UtilPlayer.setAutoDeploy(player, false); + UtilPlayer.setGlidableWithoutWings(player, false); + UtilPlayer.setGliding(player, false); + UtilPlayer.setAutoDeployDistance(player, 1.15F); + ((CraftEntity) player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0), EntityLiving.META_ENTITYDATA, (byte) 0); player.setCustomName(""); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java index 3b6d29694..5488f3d77 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/HideSeek.java @@ -240,54 +240,45 @@ public class HideSeek extends TeamGame for (Entry entry : _forms.entrySet()) { - if (entry.getValue() instanceof BlockForm) + if (!(entry.getValue() instanceof BlockForm)) + continue; + + final BlockForm blockForm = (BlockForm) entry.getValue(); + + if (blockForm.Player.getEntityId() != id || blockForm.Player == packetInfo.getPlayer()) + continue; + + final Player player = packetInfo.getPlayer(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() { - final BlockForm blockForm = (BlockForm) entry - .getValue(); - - if (blockForm.Player.getEntityId() == id - && blockForm.Player != packetInfo.getPlayer()) + public void run() { - final Player player = packetInfo.getPlayer(); - - Bukkit.getScheduler().scheduleSyncDelayedTask( - Manager.getPlugin(), new Runnable() - { - public void run() - { - UtilPlayer - .sendPacket( - player, - blockForm - .getBlockPackets(UtilPlayer.is1_9(player))); - } - }); - break; + UtilPlayer.sendPacket(player, blockForm.getBlockPackets(UtilPlayer.is1_9(player))); } - } + }); + + break; } } else if (packetInfo.getPacket() instanceof PacketPlayOutEntityDestroy) { - for (int i : ((PacketPlayOutEntityDestroy) packetInfo - .getPacket()).a) + for (int i : ((PacketPlayOutEntityDestroy) packetInfo.getPacket()).a) { for (Entry entry : _forms.entrySet()) { - if (entry.getValue() instanceof BlockForm) - { - BlockForm blockForm = (BlockForm) entry.getValue(); + if (!(entry.getValue() instanceof BlockForm)) + continue; - if (blockForm.Player.getEntityId() == i) + BlockForm blockForm = (BlockForm) entry.getValue(); + + if (blockForm.Player.getEntityId() != i) + continue; + + UtilPlayer.sendPacket(packetInfo.getPlayer(), new PacketPlayOutEntityDestroy(new int[] { - UtilPlayer.sendPacket(packetInfo.getPlayer(), - new PacketPlayOutEntityDestroy( - new int[] - { - blockForm.getBlockId() - })); - } - } + blockForm.getBlockId() + })); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java index 99b52c0ab..f0a2973f4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/hideseek/forms/BlockForm.java @@ -54,8 +54,8 @@ public class BlockForm extends Form private int _entityId; private Location _loc; - private int _selfEntityId1; - private int _selfEntityId2; + private int _fakeSilverfishId; + private int _fakeBlockId; private Vector _lastSaw; private Vector _sawDiff = new Vector(); private int _blockId = UtilEnt.getNewEntityId(); @@ -66,8 +66,8 @@ public class BlockForm extends Form _mat = mat; _loc = player.getLocation(); - _selfEntityId1 = UtilEnt.getNewEntityId(); - _selfEntityId2 = UtilEnt.getNewEntityId(); + _fakeSilverfishId = UtilEnt.getNewEntityId(); + _fakeBlockId = UtilEnt.getNewEntityId(); System.out.println("Block Form: " + _mat + " " + _mat.getId()); } @@ -100,7 +100,7 @@ public class BlockForm extends Form Packet[] packets = new Packet[3]; PacketPlayOutSpawnEntityLiving packet1 = new PacketPlayOutSpawnEntityLiving(); - packet1.a = _selfEntityId1; + packet1.a = _fakeSilverfishId; packet1.b = EntityType.SILVERFISH.getTypeId(); packet1.c = (int) Math.floor(_lastSaw.getX() * 32); packet1.d = (int) Math.floor(_lastSaw.getY() * 32); @@ -114,9 +114,9 @@ public class BlockForm extends Form if (UtilPlayer.is1_9(Player)) { - packets[2] = new PacketPlayOutNewAttachEntity(_selfEntityId1, new int[] + packets[2] = new PacketPlayOutNewAttachEntity(_fakeSilverfishId, new int[] { - _selfEntityId2 + _fakeBlockId }); } @@ -124,14 +124,14 @@ public class BlockForm extends Form { PacketPlayOutAttachEntity packet3 = new PacketPlayOutAttachEntity(); - packet3.b = _selfEntityId2; - packet3.c = _selfEntityId1; + packet3.b = _fakeBlockId; + packet3.c = _fakeSilverfishId; packets[2] = packet3; } PacketPlayOutSpawnEntity packet2 = new PacketPlayOutSpawnEntity(player, 70, _mat.getId()); - packet2.a = _selfEntityId2; + packet2.a = _fakeBlockId; packet2.uuid = UUID.randomUUID(); packets[1] = packet2; @@ -140,16 +140,11 @@ public class BlockForm extends Form // Inform String blockName = F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false)); if (!blockName.contains("Block")) - UtilPlayer.message( - Player, - F.main("Game", - C.cWhite + "You are now a " - + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false) + " Block") + "!")); + UtilPlayer.message(Player, F.main("Game", C.cWhite + "You are now a " + + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false) + " Block") + "!")); else - UtilPlayer.message( - Player, - F.main("Game", C.cWhite + "You are now a " + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false)) - + "!")); + UtilPlayer.message(Player, F.main("Game", + C.cWhite + "You are now a " + F.elem(ItemStackFactory.Instance.GetName(_mat, (byte) 0, false)) + "!")); // Give Item Player.getInventory().setItem(8, new ItemStack(Host.GetItemEquivilent(_mat))); @@ -171,11 +166,11 @@ public class BlockForm extends Form if (is19) { - packets[2] = new PacketPlayOutNewAttachEntity(_blockId, new int[] + packets[1] = new PacketPlayOutNewAttachEntity(Player.getEntityId(), new int[] { - Player.getEntityId() - }); + _blockId + }); } else { @@ -203,8 +198,8 @@ public class BlockForm extends Form UtilPlayer.sendPacket(Player, new PacketPlayOutEntityDestroy(new int[] { - _selfEntityId1, - _selfEntityId2, + _fakeSilverfishId, + _fakeBlockId, _blockId })); @@ -214,8 +209,8 @@ public class BlockForm extends Form public void SolidifyUpdate() { if (!Player.isSprinting()) - ((CraftEntity) Player).getHandle().getDataWatcher() - .watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA, (byte) 32); + ((CraftEntity) Player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 32), Entity.META_ENTITYDATA, + (byte) 32); // Not a Block if (_block == null) @@ -273,26 +268,26 @@ public class BlockForm extends Form _sawDiff.add(blockLoc.clone().subtract(_lastSaw)); - Packet packet = this.getPacket(_sawDiff, blockLoc); + Packet[] packet = this.getPacket(_sawDiff, blockLoc); _lastSaw = Player.getLocation().toVector().subtract(new Vector(0, 0.15625, 0)); _sawDiff = _lastSaw.clone().subtract(blockLoc); if (packet != null) { - if (packet instanceof PacketPlayOutEntityTeleport) + if (packet[0] instanceof PacketPlayOutEntityTeleport) { _sawDiff = new Vector(); } - ((CraftPlayer) Player).getHandle().playerConnection.sendPacket(packet); + UtilPlayer.sendPacket(Player, packet[UtilPlayer.is1_9(Player) ? 1 : 0]); } for (Player player : UtilServer.getPlayers()) { UtilPlayer.sendPacket(player, new PacketPlayOutEntityDestroy(new int[] { - getBlockId() + getBlockId() })); } } @@ -321,8 +316,8 @@ public class BlockForm extends Form MapUtil.QuickChangeBlockAt(_block.getLocation(), 0, (byte) 0); _block = null; - EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) Player).getHandle().world).tracker.trackedEntities - .get(Player.getEntityId()); + EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) Player) + .getHandle().world).tracker.trackedEntities.get(Player.getEntityId()); if (tracker != null) { @@ -374,13 +369,13 @@ public class BlockForm extends Form _lastSaw = Player.getLocation().subtract(0, 0.15625, 0).toVector(); - Packet packet = this.getPacket(_sawDiff, _lastSaw); + Packet[] packet = this.getPacket(_sawDiff, _lastSaw); if (packet != null) { - if (packet instanceof PacketPlayOutRelEntityMove) + if (!UtilPlayer.is1_9(Player) && packet[0] instanceof PacketPlayOutRelEntityMove) { - PacketPlayOutRelEntityMove relPacket = (PacketPlayOutRelEntityMove) packet; + PacketPlayOutRelEntityMove relPacket = (PacketPlayOutRelEntityMove) packet[0]; _sawDiff.subtract(new Vector(relPacket.b / 32D, relPacket.c / 32D, relPacket.d / 32D)); } else @@ -388,12 +383,12 @@ public class BlockForm extends Form _sawDiff = new Vector(); } - UtilPlayer.sendPacket(Player, packet); + UtilPlayer.sendPacket(Player, packet[UtilPlayer.is1_9(Player) ? 1 : 0]); } } } - private Packet getPacket(Vector blocksFromNewPosition, Vector newPosition) + private Packet[] getPacket(Vector blocksFromNewPosition, Vector newPosition) { int x = (int) Math.floor(blocksFromNewPosition.getX() * 32); int y = (int) Math.floor(blocksFromNewPosition.getY() * 32); @@ -401,26 +396,33 @@ public class BlockForm extends Form if (x != 0 || y != 0 || z != 0) { + Packet[] packets = new Packet[2]; + if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127) { PacketPlayOutRelEntityMove relMove = new PacketPlayOutRelEntityMove(); - relMove.a = this._selfEntityId1; + relMove.a = this._fakeSilverfishId; relMove.b = (byte) x; relMove.c = (byte) y; relMove.d = (byte) z; - return relMove; + packets[0] = relMove; } - else + { PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(); - teleportPacket.a = _selfEntityId1; + teleportPacket.a = _fakeSilverfishId; teleportPacket.b = (int) Math.floor(32 * newPosition.getX()); teleportPacket.c = (int) Math.floor(32 * newPosition.getY()); teleportPacket.d = (int) Math.floor(32 * newPosition.getZ()); - return teleportPacket; + if (packets[0] == null) + packets[0] = teleportPacket; + + packets[1] = teleportPacket; } + + return packets; } return null; From 280d03daa754d59f5a7c5335af4cc1ffc2b099a1 Mon Sep 17 00:00:00 2001 From: git Date: Tue, 8 Mar 2016 09:52:30 +1300 Subject: [PATCH 03/10] Fix names --- .../src/mineplex/core/CustomTagFix.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java index 4f8199ed7..6f14c0810 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java @@ -265,7 +265,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook _entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName); _entityMap.get(owner.getName()).put(spawnPacket.a, ids); - sendProtocolPackets(owner, spawnPacket.a, ids[1], entityName, verifier, true, ids[0]); + sendProtocolPackets(owner, spawnPacket.a, entityName, verifier, true, ids); break; } } @@ -302,17 +302,16 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook return; } - int newId = UtilEnt.getNewEntityId(); - int newId2 = UtilEnt.getNewEntityId(); + Integer[] ids = new Integer[] + { + UtilEnt.getNewEntityId(), + UtilEnt.getNewEntityId() + }; _entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName); - _entityMap.get(owner.getName()).put(spawnPacket.a, new Integer[] - { - newId, - newId2 - }); + _entityMap.get(owner.getName()).put(spawnPacket.a, ids); - sendProtocolPackets(owner, spawnPacket.a, newId2, entityName, verifier, true, newId); + sendProtocolPackets(owner, spawnPacket.a, entityName, verifier, true, ids); break; } } @@ -372,8 +371,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } _entityNameMap.get(owner.getName()).put(metaPacket.a, newName); - sendProtocolPackets(owner, metaPacket.a, newId[1], newName, verifier, !isDisplaying, - !isDisplaying ? newId[0] : -1); + sendProtocolPackets(owner, metaPacket.a, newName, verifier, !isDisplaying, newId); } else { // Lets delete it @@ -486,14 +484,14 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook _entityRiding.get(owner.getName()).remove(attachPacket.b); - sendProtocolPackets(owner, vehicleId, ids[1], _entityNameMap.get(owner.getName()).get(vehicleId), verifier, - true, ids[0]); + sendProtocolPackets(owner, vehicleId, _entityNameMap.get(owner.getName()).get(vehicleId), verifier, true, + ids); } else { Integer[] ids = _entityMap.get(owner.getName()).get(attachPacket.c); - if (ids != null && ids[0] != attachPacket.b) + if (ids != null && ids[1] != attachPacket.b) { _entityRiding.get(owner.getName()).put(attachPacket.b, attachPacket.c); @@ -511,8 +509,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } } - private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, String entityName, - final PacketVerifier packetList, final boolean newPacket, final int squidId) + private void sendProtocolPackets(final Player owner, final int entityId, String entityName, final PacketVerifier packetList, + final boolean newPacket, final Integer[] entityIds) { CustomTagEvent event = new CustomTagEvent(owner, entityId, entityName); _plugin.getServer().getPluginManager().callEvent(event); @@ -532,7 +530,6 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook if (newPacket) { - if (squidId >= 0) { watcher.watch(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16); @@ -540,7 +537,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook squidWatcher.a(0, (byte) (0 | 1 << 5), Entity.META_ENTITYDATA, (byte) (0 | 1 << 5)); PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving(); - spawnPacket.a = squidId; + spawnPacket.a = entityIds[1]; spawnPacket.b = (byte) EntityType.SQUID.getTypeId(); spawnPacket.c = 1000000; @@ -558,7 +555,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving(); - spawnPacket.a = newEntityId; + spawnPacket.a = entityIds[0]; spawnPacket.b = (byte) 30; spawnPacket.c = 1000000; @@ -569,15 +566,15 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity(); vehiclePacket.a = 0; - vehiclePacket.b = spawnPacket.a; - vehiclePacket.c = squidId >= 0 ? squidId : entityId; + vehiclePacket.b = entityIds[0]; + vehiclePacket.c = entityIds[1]; UtilPlayer.sendPacket(owner, vehiclePacket); } else { PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(); - entityMetadata.a = newEntityId; + entityMetadata.a = entityIds[0]; entityMetadata.b = watcher.c(); packetList.bypassProcess(entityMetadata); From 0f752fb7e3ea53df4a8dbd3f1115b58434190724 Mon Sep 17 00:00:00 2001 From: git Date: Tue, 8 Mar 2016 16:11:12 +1300 Subject: [PATCH 04/10] Fix custom names in 1.9 --- .../src/mineplex/core/CustomTagFix.java | 97 +++++++++++++------ .../mineplex/core/bonuses/BonusManager.java | 2 +- 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java index 6f14c0810..a4285980f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java @@ -28,6 +28,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutAttachEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn; +import net.minecraft.server.v1_8_R3.PacketPlayOutNewAttachEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; @@ -67,9 +68,9 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook { super("Custom Tag Fix", plugin); - packetHandler.addPacketHandler(this, true, PacketPlayOutAttachEntity.class, PacketPlayOutEntityDestroy.class, - PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class, - PacketPlayOutNamedEntitySpawn.class, PacketPlayInUseEntity.class, PacketPlayOutAttachEntity.class); + packetHandler.addPacketHandler(this, true, PacketPlayOutEntityDestroy.class, PacketPlayOutEntityMetadata.class, + PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class, PacketPlayOutNamedEntitySpawn.class, + PacketPlayInUseEntity.class, PacketPlayOutAttachEntity.class, PacketPlayOutNewAttachEntity.class); // NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this); // NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this); @@ -452,9 +453,25 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } } } - else if (packet instanceof PacketPlayOutAttachEntity) + else if (packet instanceof PacketPlayOutAttachEntity || packet instanceof PacketPlayOutNewAttachEntity) { - PacketPlayOutAttachEntity attachPacket = (PacketPlayOutAttachEntity) packet; + int vech = -1; + int rider = -1; + + if (packet instanceof PacketPlayOutAttachEntity) + { + PacketPlayOutAttachEntity attachPacket = (PacketPlayOutAttachEntity) packet; + vech = attachPacket.b; + rider = attachPacket.c; + } + else if (packet instanceof PacketPlayOutNewAttachEntity) + { + PacketPlayOutNewAttachEntity attachPacket = (PacketPlayOutNewAttachEntity) packet; + vech = attachPacket.a; + + if (attachPacket.b.length > 0) + rider = attachPacket.b[0]; + } // c = rider, b = ridden // When detaching, c is sent, b is -1 @@ -473,27 +490,27 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook int vehicleId = -1; - if (_entityRiding.get(owner.getName()).containsKey(attachPacket.b)) + if (_entityRiding.get(owner.getName()).containsKey(vech)) { - vehicleId = _entityRiding.get(owner.getName()).get(attachPacket.b); + vehicleId = _entityRiding.get(owner.getName()).get(vech); } - if (attachPacket.c == -1 && _entityMap.get(owner.getName()).containsKey(vehicleId)) + if (rider == -1 && _entityMap.get(owner.getName()).containsKey(vehicleId)) { Integer[] ids = _entityMap.get(owner.getName()).get(vehicleId); - _entityRiding.get(owner.getName()).remove(attachPacket.b); + _entityRiding.get(owner.getName()).remove(vech); sendProtocolPackets(owner, vehicleId, _entityNameMap.get(owner.getName()).get(vehicleId), verifier, true, ids); } else { - Integer[] ids = _entityMap.get(owner.getName()).get(attachPacket.c); + Integer[] ids = _entityMap.get(owner.getName()).get(rider); - if (ids != null && ids[1] != attachPacket.b) + if (ids != null && ids[1] != vech) { - _entityRiding.get(owner.getName()).put(attachPacket.b, attachPacket.c); + _entityRiding.get(owner.getName()).put(vech, rider); int[] newIds = new int[ids.length]; @@ -522,54 +539,76 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook { DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle())); - watcher.a(0, (byte) (0 | 1 << 5), Entity.META_ENTITYDATA, (byte) (0 | 1 << 5)); // Invisible + watcher.a(0, (byte) 32, Entity.META_ENTITYDATA, (byte) 32); // Invisible watcher.a(1, Short.valueOf((short) 300), Entity.META_AIR, 0); watcher.a(2, finalEntityName, Entity.META_CUSTOMNAME, finalEntityName); watcher.a(3, (byte) 1, Entity.META_CUSTOMNAME_VISIBLE, true); - watcher.a(10, (byte) (0 | 0x1), EntityArmorStand.META_ARMOR_OPTION, (byte) (0 | 0x1)); // Small + watcher.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16); // Small if (newPacket) { { - watcher.watch(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16); - DataWatcher squidWatcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle())); - squidWatcher.a(0, (byte) (0 | 1 << 5), Entity.META_ENTITYDATA, (byte) (0 | 1 << 5)); + squidWatcher.a(0, (byte) 32, Entity.META_ENTITYDATA, (byte) 32); PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving(); spawnPacket.a = entityIds[1]; spawnPacket.b = (byte) EntityType.SQUID.getTypeId(); - spawnPacket.c = 1000000; + spawnPacket.c = owner.getLocation().getBlockX() * 32; + spawnPacket.d = -150; + spawnPacket.e = owner.getLocation().getBlockZ() * 32; spawnPacket.l = squidWatcher; spawnPacket.uuid = UUID.randomUUID(); UtilPlayer.sendPacket(owner, spawnPacket); - PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity(); - vehiclePacket.a = 0; - vehiclePacket.b = spawnPacket.a; - vehiclePacket.c = entityId; + if (UtilPlayer.is1_9(owner)) + { + UtilPlayer.sendPacket(owner, new PacketPlayOutNewAttachEntity(entityId, new int[] + { + entityIds[1] + })); + } + else + { + PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity(); + vehiclePacket.a = 0; + vehiclePacket.b = spawnPacket.a; + vehiclePacket.c = entityId; - UtilPlayer.sendPacket(owner, vehiclePacket); + UtilPlayer.sendPacket(owner, vehiclePacket); + } } PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving(); spawnPacket.a = entityIds[0]; spawnPacket.b = (byte) 30; - spawnPacket.c = 1000000; + spawnPacket.c = owner.getLocation().getBlockX() * 32; + spawnPacket.d = -150; + spawnPacket.e = owner.getLocation().getBlockZ() * 32; spawnPacket.l = watcher; spawnPacket.uuid = UUID.randomUUID(); UtilPlayer.sendPacket(owner, spawnPacket); - PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity(); - vehiclePacket.a = 0; - vehiclePacket.b = entityIds[0]; - vehiclePacket.c = entityIds[1]; + if (UtilPlayer.is1_9(owner)) + { + UtilPlayer.sendPacket(owner, new PacketPlayOutNewAttachEntity(entityIds[1], new int[] + { + entityIds[0] + })); + } + else + { + PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity(); + vehiclePacket.a = 0; + vehiclePacket.b = entityIds[0]; + vehiclePacket.c = entityIds[1]; - UtilPlayer.sendPacket(owner, vehiclePacket); + UtilPlayer.sendPacket(owner, vehiclePacket); + } } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index be8ddbe84..9410fb7a3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -917,7 +917,7 @@ public class BonusManager extends MiniClientPlugin implements I if (client.getHologram() == null) { - double yAdd = 2.18; + double yAdd = 2.3; hologram = new Hologram(_hologramManager, _carlNpc.getLocation().clone().add(0, yAdd, 0), ""); hologram.setHologramTarget(Hologram.HologramTarget.WHITELIST); hologram.addPlayer(player); From 557b0bf978b98abbdd8142c739410470c1d111e1 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 11 Mar 2016 01:55:49 +1300 Subject: [PATCH 05/10] Fix Wither disguise --- .../mineplex/core/disguise/disguises/DisguiseWither.java | 3 +++ .../nautilus/game/arcade/game/games/rings/ElytraRings.java | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseWither.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseWither.java index 884123ee8..333d283bd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseWither.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseWither.java @@ -5,6 +5,8 @@ import net.minecraft.server.v1_8_R3.EntityWither; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; +import mineplex.core.common.util.UtilMath; + public class DisguiseWither extends DisguiseMonster { public DisguiseWither(org.bukkit.entity.Entity entity) @@ -24,6 +26,7 @@ public class DisguiseWither extends DisguiseMonster public void setInvulTime(int i) { + DataWatcher.watch(17, Integer.valueOf(i), EntityWither.META_INVUL_TIME, i); DataWatcher.watch(20, Integer.valueOf(i), EntityWither.META_INVUL_TIME, i); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java index 00920d3c2..127c8aa16 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java @@ -19,6 +19,7 @@ import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; @@ -43,7 +44,7 @@ public class ElytraRings extends SoloGame { super(manager, GameType.ElytraRings, new Kit[] { - new KitUHC(manager) + new KitElytraRings(manager) }, new String[] { "Fly through the rings!" @@ -175,7 +176,7 @@ public class ElytraRings extends SoloGame if (exp > 0.05 && _lastLocation.containsKey(player.getUniqueId())) { - UtilAction.velocity(player, player.getLocation().getDirection()); + UtilAction.velocity(player, player.getLocation().getDirection().multiply(0.3)); if (!_goneThrough.containsKey(player.getUniqueId()) || _rings.containsKey(_goneThrough.get(player.getUniqueId()) + 1)) @@ -206,7 +207,7 @@ public class ElytraRings extends SoloGame Player player = event.getPlayer(); - if (event.isSneaking()) + if (event.isSneaking() && UtilPlayer.isGliding(player)) { _lastLocation.put(player.getUniqueId(), player.getLocation()); } From a107c38f286fdc33f0a40dc1e6d2565f9303698e Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 23 Mar 2016 10:18:22 +1100 Subject: [PATCH 06/10] Comment out missing ring game kit so we can compile --- .../src/nautilus/game/arcade/game/games/rings/ElytraRings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java index 127c8aa16..0849aa965 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/rings/ElytraRings.java @@ -44,7 +44,7 @@ public class ElytraRings extends SoloGame { super(manager, GameType.ElytraRings, new Kit[] { - new KitElytraRings(manager) +// new KitElytraRings(manager) }, new String[] { "Fly through the rings!" From 309b5464f28b83d223d92b909b9a32abd2dbfe56 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 23 Mar 2016 10:21:02 +1100 Subject: [PATCH 07/10] Clean up Account Repository, attempt to load account ID from cache --- .../mineplex/cache/player/PlayerCache.java | 18 ++- .../core/account/CoreClientManager.java | 36 ++--- .../account/repository/AccountRepository.java | 128 +++++++----------- 3 files changed, 71 insertions(+), 111 deletions(-) diff --git a/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java b/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java index 4ab7fbbc6..da02123eb 100644 --- a/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java +++ b/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java @@ -48,13 +48,6 @@ public class PlayerCache try { PlayerInfo playerInfo = _repository.getElement(uuid.toString()); - System.out.println("Got playerInfo: " + playerInfo); - if (playerInfo != null) - { - System.out.println("account id: " + playerInfo.getAccountId()); - System.out.println("name: " + playerInfo.getName()); - } - return playerInfo; } catch (Exception exception) @@ -65,6 +58,17 @@ public class PlayerCache return null; } + + /** + * Attempts to grab a player's account ID from the cache + * @param uuid Minecraft Account UUID + * @return The account id of the player, or -1 if the player is not in the cache + */ + public int getAccountId(UUID uuid) + { + PlayerInfo info = getPlayer(uuid); + return info == null ? -1 : info.getAccountId(); + } public void clean() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 1f2dc672d..c0d7386e6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -1,8 +1,8 @@ package mineplex.core.account; +import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; import java.util.UUID; @@ -49,9 +49,8 @@ public class CoreClientManager extends MiniPlugin private NautHashMap _clientList; private HashSet _duplicateLoginGlitchPreventionList; - private NautHashMap _loginProcessors = new NautHashMap(); - private LinkedList _querylessLoginProcessors = new LinkedList(); - + private List _loginProcessors = new ArrayList<>(); + private Object _clientLock = new Object(); private static AtomicInteger _clientsConnecting = new AtomicInteger(0); @@ -260,7 +259,7 @@ public class CoreClientManager extends MiniPlugin CoreClient client = Add(playerName); client.SetRank(Rank.valueOf(token.Rank), false); - client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName())); + client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName())); // JSON sql response Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); @@ -332,7 +331,7 @@ public class CoreClientManager extends MiniPlugin CoreClient client = Add(playerName); client.SetRank(Rank.valueOf(token.Rank), false); - client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName())); + client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName())); // JSON sql response Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); @@ -373,12 +372,12 @@ public class CoreClientManager extends MiniPlugin _clientLoginLock.put(client.GetPlayerName(), new Object()); ClientToken token = null; Gson gson = new Gson(); - + runAsync(new Runnable() { public void run() { - client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName())); + client.setAccountId(_repository.login(_loginProcessors, uuid, client.GetPlayerName())); _clientLoginLock.remove(client.GetPlayerName()); } }); @@ -386,7 +385,8 @@ public class CoreClientManager extends MiniPlugin TimingManager.start(client.GetPlayerName() + " GetClient."); String response = _repository.GetClient(client.GetPlayerName(), uuid, ipAddress); TimingManager.stop(client.GetPlayerName() + " GetClient."); - + + TimingManager.start(client.GetPlayerName() + " Event."); token = gson.fromJson(response, ClientToken.class); client.SetRank(Rank.valueOf(token.Rank), false); @@ -395,7 +395,9 @@ public class CoreClientManager extends MiniPlugin // JSON sql response Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); - + TimingManager.stop(client.GetPlayerName() + " Event."); + + TimingManager.start(client.GetPlayerName() + " While Loop."); while (_clientLoginLock.containsKey(client.GetPlayerName()) && System.currentTimeMillis() - timeStart < 15000) { try @@ -407,6 +409,7 @@ public class CoreClientManager extends MiniPlugin e.printStackTrace(); } } + TimingManager.stop(client.GetPlayerName() + " While Loop."); if (_clientLoginLock.containsKey(client.GetPlayerName())) { @@ -646,14 +649,9 @@ public class CoreClientManager extends MiniPlugin public void addStoredProcedureLoginProcessor(ILoginProcessor processor) { - _loginProcessors.put(processor.getName(), processor); + _loginProcessors.add(processor); } - public void addStoredProcedureLoginProcessor(IQuerylessLoginProcessor processor) - { - _querylessLoginProcessors.add(processor); - } - public boolean hasRank(Player player, Rank rank) { CoreClient client = Get(player); @@ -662,10 +660,4 @@ public class CoreClientManager extends MiniPlugin return client.GetRank().has(rank); } - - public int getCachedClientAccountId(UUID uuid) - { - PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid); - return playerInfo == null ? -1 : playerInfo.getAccountId(); - } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 746b3cf6b..8ec8ecb31 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -6,30 +6,28 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; -import mineplex.core.database.MinecraftRepository; import org.bukkit.Bukkit; import com.google.gson.reflect.TypeToken; import org.bukkit.plugin.java.JavaPlugin; +import mineplex.cache.player.PlayerCache; import mineplex.core.account.ILoginProcessor; -import mineplex.core.account.IQuerylessLoginProcessor; import mineplex.core.account.repository.token.LoginToken; import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; -import mineplex.core.common.util.NautHashMap; +import mineplex.core.database.MinecraftRepository; +import mineplex.core.server.remotecall.JsonWebCall; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.DatabaseRunnable; -import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.column.ColumnBoolean; import mineplex.serverdata.database.column.ColumnTimestamp; import mineplex.serverdata.database.column.ColumnVarChar; -import mineplex.core.server.remotecall.JsonWebCall; public class AccountRepository extends MinecraftRepository { @@ -59,100 +57,66 @@ public class AccountRepository extends MinecraftRepository //executeUpdate(CREATE_ACCOUNT_TABLE); } - public int login(NautHashMap loginProcessors, LinkedList querylessLoginProcessors, String uuid, String name) + public int login(final List loginProcessors, final UUID uuid, final String name) { + // First we try to grab the account id from cache - this saves an extra trip to database int accountId = -1; - try ( - Connection connection = getConnection(); - Statement statement = connection.createStatement() - ) + + try (Connection connection = getConnection(); Statement statement = connection.createStatement()) { - statement.execute("SELECT id FROM accounts WHERE accounts.uuid = '" + uuid + "' LIMIT 1;"); - ResultSet resultSet = statement.getResultSet(); - - while (resultSet.next()) + int cachedId = PlayerCache.getInstance().getAccountId(uuid); + if (cachedId > 0) { - accountId = resultSet.getInt(1); + accountId = cachedId; + System.out.println("Loaded Account ID From Cache [" + name + " - " + accountId + "]"); } - - if (accountId == -1) + else { - final List tempList = new ArrayList(1); - - executeInsert(ACCOUNT_LOGIN_NEW, new ResultSetCallable() - { - @Override - public void processResultSet(ResultSet resultSet) throws SQLException - { - while (resultSet.next()) - { - tempList.add(resultSet.getInt(1)); - } - } - },new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 100, name)); - - accountId = tempList.get(0); - } - - /* - boolean statementStatus = statement.execute( - "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';" - + "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;" - + "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = '" + uuid + "';" - + "SELECT benefit FROM rankBenefits WHERE rankBenefits.uuid = '" + uuid + "';" - + "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = '" + uuid + "';" - + "SELECT tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = '" + uuid + "';" - + "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';" - ); -*/ + // Player was not found in cache, we need to grab the account id from database + statement.execute("SELECT id FROM accounts WHERE accounts.uuid = '" + uuid + "' LIMIT 1;"); + ResultSet resultSet = statement.getResultSet(); - String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE id = '" + accountId + "';"; - - for (ILoginProcessor loginProcessor : loginProcessors.values()) - { - loginString += loginProcessor.getQuery(accountId, uuid, name); - } - - statement.execute(loginString); - - /* - while (true) - { - if (statementStatus) + if (resultSet.next()) { - System.out.println("ResultSet : " + statement.getResultSet().getMetaData().getColumnCount() + " columns:"); - - for (int i = 0; i < statement.getResultSet().getMetaData().getColumnCount(); i++) - { - System.out.println(statement.getResultSet().getMetaData().getColumnName(i + 1)); - } + accountId = resultSet.getInt(1); } else { - if (statement.getUpdateCount() == -1) - break; + // Player doesn't exist in our database, add them to the accounts table + final List tempList = new ArrayList(1); - System.out.println("Update statement : " + statement.getUpdateCount() + " rows affected."); + executeInsert(ACCOUNT_LOGIN_NEW, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + tempList.add(resultSet.getInt(1)); + } + } + }, new ColumnVarChar("uuid", 100, uuid.toString()), new ColumnVarChar("name", 100, name)); + + accountId = tempList.get(0); } - - statementStatus = statement.getMoreResults(); } - - System.out.println("Done"); - */ - + + final int finalId = accountId; + final String uuidString = uuid.toString(); + + String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE id = '" + accountId + "';"; + // We can use a parallel stream because they will be in the correct order when we collect + loginString += loginProcessors.parallelStream().map(processor -> processor.getQuery(finalId, uuidString, name)).collect(Collectors.joining()); + + statement.execute(loginString); + statement.getUpdateCount(); statement.getMoreResults(); - - for (ILoginProcessor loginProcessor : loginProcessors.values()) - { - loginProcessor.processLoginResultSet(name, accountId, statement.getResultSet()); - statement.getMoreResults(); - } - for (IQuerylessLoginProcessor loginProcessor : querylessLoginProcessors) + for (ILoginProcessor loginProcessor : loginProcessors) { - loginProcessor.processLogin(name, accountId); + loginProcessor.processLoginResultSet(name, finalId, statement.getResultSet()); + statement.getMoreResults(); } } catch (Exception exception) From da9a642a6d54b1179f94c1cce7c68e0ef022fb64 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 23 Mar 2016 10:21:36 +1100 Subject: [PATCH 08/10] Process item for treasure before opening --- .../core/treasure/TreasureLocation.java | 96 +++++++++++-------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java index 2c48bea27..d74defe01 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java @@ -4,6 +4,7 @@ import java.util.List; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; @@ -101,12 +102,6 @@ public class TreasureLocation implements Listener return; } - if (!chargeAccount(player, treasureType)) - { - player.sendMessage(F.main("Treasure", "You dont have any chests to open!")); - return; - } - TreasureStartEvent event = new TreasureStartEvent(player); Bukkit.getPluginManager().callEvent(event); @@ -115,48 +110,73 @@ public class TreasureLocation implements Listener return; } - // Treasure is now being opened - setHoloChestVisible(false); - - if (treasureType == TreasureType.ANCIENT) - Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening an " + treasureType.getName())); - - if (treasureType == TreasureType.MYTHICAL) - Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName())); - - if (treasureType == TreasureType.CHRISTMAS) - Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName())); - - Reward[] rewards = _treasureManager.getRewards(player, treasureType.getRewardPool(), treasureType.getRewardType()); - Treasure treasure = new Treasure(player, rewards, treasureType.getRewardType(), _chestBlock, _chestSpawns, treasureType, _treasureManager.getBlockRestore(), _hologramManager, _statusManager); - _currentTreasure = treasure; - - UtilTextMiddle.display(treasureType.getName(), "Choose 4 Chests To Open", 20, 180, 20, player); - UtilPlayer.message(player, F.main("Treasure", "Choose 4 Chests To Open")); - - Location teleportLocation = treasure.getCenterBlock().getLocation().add(0.5, 0, 0.5); - teleportLocation.setPitch(player.getLocation().getPitch()); - teleportLocation.setYaw(player.getLocation().getYaw()); - - for (Entity entity : player.getNearbyEntities(3, 3, 3)) + chargeAccount(player, treasureType, new Callback() { - UtilAction.velocity(entity, UtilAlg.getTrajectory(entity.getLocation(), treasure.getCenterBlock().getLocation()).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); - } + @Override + public void run(Boolean success) + { + if (!success) + { + player.sendMessage(F.main("Treasure", "You dont have any chests to open!")); + } + else + { + if (isTreasureInProgress()) + { + // Need to check again because of callback. Add item back + player.sendMessage(F.main("Treasure", "Please wait for the current chest to be opened")); + _inventoryManager.addItemToInventory(player, treasureType.getItemName(), 1); + return; + } - player.teleport(teleportLocation); + // Treasure is now being opened + setHoloChestVisible(false); - _treasureManager.addOpenStat(player, treasureType); + if (treasureType == TreasureType.ANCIENT) + Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening an " + treasureType.getName())); + + if (treasureType == TreasureType.MYTHICAL) + Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName())); + + if (treasureType == TreasureType.CHRISTMAS) + Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName())); + + Reward[] rewards = _treasureManager.getRewards(player, treasureType.getRewardPool(), treasureType.getRewardType()); + Treasure treasure = new Treasure(player, rewards, treasureType.getRewardType(), _chestBlock, _chestSpawns, treasureType, _treasureManager.getBlockRestore(), _hologramManager, _statusManager); + _currentTreasure = treasure; + + UtilTextMiddle.display(treasureType.getName(), "Choose 4 Chests To Open", 20, 180, 20, player); + UtilPlayer.message(player, F.main("Treasure", "Choose 4 Chests To Open")); + + Location teleportLocation = treasure.getCenterBlock().getLocation().add(0.5, 0, 0.5); + teleportLocation.setPitch(player.getLocation().getPitch()); + teleportLocation.setYaw(player.getLocation().getYaw()); + + for (Entity entity : player.getNearbyEntities(3, 3, 3)) + { + UtilAction.velocity(entity, UtilAlg.getTrajectory(entity.getLocation(), treasure.getCenterBlock().getLocation()).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); + } + + player.teleport(teleportLocation); + + _treasureManager.addOpenStat(player, treasureType); + } + } + }); } - private boolean chargeAccount(Player player, TreasureType treasureType) + private void chargeAccount(Player player, TreasureType treasureType, Callback callback) { int itemCount = _inventoryManager.Get(player).getItemCount(treasureType.getItemName()); if (itemCount > 0) { - _inventoryManager.addItemToInventory(player, treasureType.getItemName(), -1); - return true; + // Should always handle the callback for us + _inventoryManager.addItemToInventory(callback, player, treasureType.getItemName(), -1); + } + else + { + callback.run(false); } - return false; } private void setHoloChestVisible(boolean visible) From 656780d027bab2573ffb5f1e6d2b2148efeb90ac Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 23 Mar 2016 10:22:40 +1100 Subject: [PATCH 09/10] Change runAsync in MiniPlugin to use our own thread pool This allows the tasks to run immediately. Using Bukkit's scheduler the async task wont start until the next server tick --- .../Mineplex.Core/src/mineplex/core/MiniPlugin.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java index 732c13816..dbad6fbdb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java @@ -1,11 +1,15 @@ package mineplex.core; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import mineplex.core.command.CommandCenter; import mineplex.core.command.ICommand; import mineplex.core.common.util.F; @@ -15,6 +19,9 @@ import mineplex.core.common.util.UtilTime.TimeUnit; public abstract class MiniPlugin implements Listener { + private static final ExecutorService threadPool = Executors.newCachedThreadPool( + new ThreadFactoryBuilder().setNameFormat("MiniPlugin Async %1$d").build()); + protected String _moduleName = "Default"; protected JavaPlugin _plugin; protected NautHashMap _commands; @@ -105,7 +112,8 @@ public abstract class MiniPlugin implements Listener public void runAsync(Runnable runnable) { - _plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, runnable); + // Instead of using + threadPool.execute(runnable); } public void runAsync(Runnable runnable, long time) From 1e73adf2af4fc92b7dd2bc15a707336b81ba0349 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 23 Mar 2016 10:23:04 +1100 Subject: [PATCH 10/10] Increase ram and cpu for event server --- .../mineplex/core/personalServer/PersonalServerManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java index 8f8e68dc9..ee40a0e6f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java @@ -131,7 +131,11 @@ public class PersonalServerManager extends MiniPlugin } if (eventServer) + { + ram = 4096; + cpu = 8; createGroup(player, "EVENT", ram, cpu, 40, 80, "Event", eventServer); + } else createGroup(player, serverName, ram, cpu, 40, 80, "Smash", eventServer); }