From ac4b4953017c168c7195c5c37a799ad9c6dbbbfa Mon Sep 17 00:00:00 2001 From: Tim Ziankoski Date: Sat, 7 Mar 2015 20:50:47 -0500 Subject: [PATCH 1/4] Created internationalization helper class and began i18n process --- .../artifacts/Nautilus_Game_Arcade_jar.xml | 2 +- .../artifacts/Nautilus_Game_Arcade_test.xml | 1 + Plugins/.idea/copyright/profiles_settings.xml | 3 + .../Mineplex.Core.Common.iml | 4 +- .../core/common/lang/mineplex_de.properties | 1 + .../core/common/lang/mineplex_en.properties | 4 + .../src/mineplex/core/common/lang/Lang.java | 115 ++++++++++++++++++ .../arcade/managers/GameLobbyManager.java | 12 +- 8 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 Plugins/.idea/copyright/profiles_settings.xml create mode 100644 Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties create mode 100644 Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java diff --git a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml index cd4447b88..3f5cae6e4 100644 --- a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml +++ b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml @@ -17,7 +17,7 @@ - + \ No newline at end of file diff --git a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml index 8b3142e4c..73139df16 100644 --- a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml +++ b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml @@ -3,6 +3,7 @@ $PROJECT_DIR$/../Testing/Arcade/plugins + \ No newline at end of file diff --git a/Plugins/.idea/copyright/profiles_settings.xml b/Plugins/.idea/copyright/profiles_settings.xml new file mode 100644 index 000000000..e7bedf337 --- /dev/null +++ b/Plugins/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml b/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml index b59695f8a..c145ccad3 100644 --- a/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml +++ b/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml @@ -4,10 +4,10 @@ + - - + \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties b/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties new file mode 100644 index 000000000..cb380f81e --- /dev/null +++ b/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties @@ -0,0 +1 @@ +waiting.for.players=Warten auf Spieler diff --git a/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties b/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties new file mode 100644 index 000000000..d99ecb4b3 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties @@ -0,0 +1,4 @@ +waiting.for.players=Waiting for Players +lobby=Lobby +starting.in.0.seconds=Starting in {0} Seconds +starting.in.0.seconds.singular=Starting in {0} Second diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java new file mode 100644 index 000000000..cb6e3fa89 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java @@ -0,0 +1,115 @@ +package mineplex.core.common.lang; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.MissingResourceException; +import java.util.ResourceBundle; +import java.util.WeakHashMap; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public final class Lang +{ + private static final String RESOURCE_BUNDLE_PATH = "mineplex/core/common/lang/mineplex"; + + private static final Map _playerLocales = new WeakHashMap<>(); + private static final ResourceBundle _defaultResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH); + private static final Map _localeResourceBundles = Collections.synchronizedMap(new HashMap()); + + private Lang() + { + + } + + public static void setPlayerLocale(Player player, Locale locale) + { + _playerLocales.put(player, locale); + } + + public static ResourceBundle getDefaultResourceBundle() + { + return _defaultResourceBundle; + } + + public static ResourceBundle getResourceBundle(Locale locale) + { + ResourceBundle bundle = getDefaultResourceBundle(); + + synchronized (_localeResourceBundles) + { + if (_localeResourceBundles.containsKey(locale)) + { + ResourceBundle b = _localeResourceBundles.get(locale); + if (b != null) + bundle = b; + } + else + { + try + { + bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH, locale); + _localeResourceBundles.put(locale, bundle); + } + catch (MissingResourceException e) + { + _localeResourceBundles.put(locale, null); + + Bukkit.getLogger().warning(e.getMessage()); + } + } + } + + return bundle; + } + + public static String getString(String key, int count) + { + return getString(key, (Locale) null, count); + } + + public static String getString(String key, Locale locale, int count) + { + if (key == null) + return null; + else + { + ResourceBundle bundle; + if (locale == null) + bundle = getDefaultResourceBundle(); + else + bundle = getResourceBundle(locale); + + if (count == 1) + { + String singularKey = key + ".singular"; + if (bundle.containsKey(singularKey)) + return bundle.getString(singularKey); + } + + return bundle.getString(key); + } + } + + public static String getString(String key, Player player, int count) + { + return getString(key, _playerLocales.get(player), count); + } + + public static String getString(String key) + { + return getString(key, 0); + } + + public static String getString(String key, Locale locale) + { + return getString(key, locale, 0); + } + + public static String getString(String key, Player player) + { + return getString(key, player, 0); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java index fe3a858b4..688eaa4b8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java @@ -1,10 +1,11 @@ package nautilus.game.arcade.managers; -import java.util.ArrayList; +import java.text.MessageFormat;import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map.Entry; import org.bukkit.Bukkit; @@ -41,6 +42,7 @@ import net.minecraft.server.v1_7_R4.WatchableObject; import mineplex.core.account.CoreClient; import mineplex.core.common.Rank; +import mineplex.core.common.lang.Lang; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; @@ -948,18 +950,18 @@ public class GameLobbyManager implements Listener, IPacketHandler for (Entry entry : _scoreboardMap.entrySet()) { - Objective objective = entry.getValue().getObjective("§l" + "Lobby"); - + Objective objective = entry.getValue().getObjective(C.Bold + Lang.getString("lobby", entry.getKey())); + if (Manager.GetGame() != null && Manager.GetGame().GetCountdown() >= 0) { if (Manager.GetGame().GetCountdown() > 0) - objective.setDisplayName(C.Bold + "§lStarting in " + C.cGreen + "§l" + Manager.GetGame().GetCountdown() + (Manager.GetGame().GetCountdown() == 1 ? " Second" : " Seconds")); + objective.setDisplayName(MessageFormat.format(C.Bold + Lang.getString("starting.in.0.seconds", entry.getKey(), Manager.GetGame().GetCountdown()), C.cGreen + C.Bold + Manager.GetGame().GetCountdown())); else if (Manager.GetGame().GetCountdown() == 0) objective.setDisplayName(ChatColor.WHITE + "§lIn Progress..."); } else { - objective.setDisplayName(ChatColor.GREEN + "§l" + "Waiting for Players"); + objective.setDisplayName(C.cGreen + C.Bold + Lang.getString("waiting.for.players", entry.getKey())); } int line = 15; From dbeea5bf690c0e3013aa2a3814c8b4efa9bfb001 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 9 Mar 2015 05:17:04 +1300 Subject: [PATCH 2/4] Pre-Frost changes --- .../games/survivalgames/SurvivalGames.java | 1758 ++++++++++++----- 1 file changed, 1221 insertions(+), 537 deletions(-) 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 1d050b58e..30f07f341 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 @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.survivalgames; +import java.lang.reflect.Field; import java.util.*; import java.util.Map.Entry; @@ -7,8 +8,16 @@ import org.bukkit.*; import org.bukkit.FireworkEffect.Type; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; 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.CraftPlayer; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.entity.Snowball; @@ -27,17 +36,27 @@ import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.FurnaceInventory; +import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; +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; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; @@ -54,7 +73,11 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilWorld; -import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.disguise.disguises.DisguisePlayer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.loot.*; +import mineplex.core.packethandler.IPacketHandler; +import mineplex.core.packethandler.PacketInfo; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -72,96 +95,126 @@ 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.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.util.com.mojang.authlib.GameProfile; public class SurvivalGames extends SoloGame -{ - private HashSet _openedChest = new HashSet(); - private ArrayList _baseChestLoot = new ArrayList(); - private ArrayList _superChestLoot = new ArrayList(); +{ + // Lootables + private ChestLoot _baseLoot = new ChestLoot(); + private ChestLoot _spawnLoot = new ChestLoot(); + private ChestLoot _superLoot = new ChestLoot(); + private ChestLoot _cookedFurnace = new ChestLoot(); + private ChestLoot _rawFurnace = new ChestLoot(); - //Misc + private HashMap> _hiddenNames = new HashMap>(); + private HashSet _lootedBlocks = new HashSet(); + + // Misc private HashMap _tntMap = new HashMap(); private HashSet _placedBlocks = new HashSet(); private Location _spawn; - //Creep + // Creep private int _maxSpreadRate = 120; - private ArrayList _redLocations = new ArrayList(); + private ArrayList _frostLocations = new ArrayList(); private int _spreadType = 0; private String _spreadName = ""; private boolean _ignoreLiquids = true; private ArrayList> _spreadTypeBlocks; - private HashMap _redOutTime = new HashMap(); + private HashMap _frostOutTime = new HashMap(); - private HashMap>> _redMap = new HashMap>>(); - private HashMap> _redChunks = new HashMap>(); + private HashMap>> _frostMap = new HashMap>>(); + private HashMap> _frostChunks = new HashMap>(); - //Supply Drop + // Supply Drop private ArrayList _supplyLocations = new ArrayList(); private Location _supplyCurrent = null; private Location _supplyEffect = null; - private ArrayList _supplyChests = new ArrayList(); + private ArrayList _supplyCrates = new ArrayList(); + private HashSet _landedCrates = new HashSet(); - //Deathmatch + // Deathmatch private boolean _deathmatchCountdown = false; private boolean _deathmatchLive = false; private long _deathmatchTime = 0; - //Debug + private int _chestRefillTime = 60 * 7; + + // Debug private long totalTime = 0; - public SurvivalGames(ArcadeManager manager) + private Field _nameTagVisibility; + private Field _packetTeam; + private IPacketHandler _useEntityPacketHandler; + private int _deadBodyCount; + + private NautHashMap _openedChests = new NautHashMap(); + /** + * @The field is originally set to 1, if the next tick finds it at 1, then its set to 10. If the next tick finds it at 10 then + * it removes. + * @Else the ticks set it to 50 + */ + private Field _ticksField; + + public SurvivalGames(ArcadeManager manager) { super(manager, GameType.SurvivalGames, - new Kit[] - { - new KitAxeman(manager), - //new KitLooter(manager), - new KitKnight(manager), + new Kit[] + { + new KitAxeman(manager), + // new KitLooter(manager), + new KitKnight(manager), - new KitArcher(manager), - new KitBrawler(manager), + new KitArcher(manager), - new KitAssassin(manager), - new KitBeastmaster(manager), - new KitBomber(manager), - new KitNecromancer(manager), - - new KitHorseman(manager) - }, + new KitBrawler(manager), - new String[] - { - "Search for chests to find loot", - "Slaughter your opponents", - "Stay away from the Deep Freeze!", - "Last tribute alive wins!" - }); - - _help = new String[] - { - C.cGreen + "Use a Compass to find and kill enemies!", - C.cAqua + "Crouch to become invisible to Compass tracking!", - C.cGreen + "Avoid the Deep Freeze at all costs!", - C.cAqua + "Use TNT & Tripwires to make traps!", - C.cGreen + "You lose Speed 2 at start of game if you attack.", - C.cAqua + "Avoid enemies who have better gear than you!", - C.cGreen + "Compass finds Supply Drops during night time.", - C.cAqua + "Compass finds Players during day time.", - }; + new KitAssassin(manager), - //Manager.GetAntiStack().SetEnabled(false); + new KitBeastmaster(manager), + + new KitBomber(manager), + + new KitNecromancer(manager), + + new KitHorseman(manager) + }, + + new String[] + { + "Search for chests to find loot", "Slaughter your opponents", "Stay away from the Deep Freeze!", + "Last tribute alive wins!" + }); + + _help = new String[] + { + C.cGreen + "Use a Compass to find and kill enemies!", + + C.cGreen + "Avoid the Deep Freeze at all costs!", + + C.cGreen + "You lose Speed 2 at start of game if you attack.", + + C.cAqua + "Avoid enemies who have better gear than you!" + }; + + // Manager.GetAntiStack().SetEnabled(false); this.StrictAntiHack = true; - + this.GameTimeout = 9600000; - + this.QuitDropItems = true; - + this.WorldTimeSet = 0; - this.WorldBoundaryKill = false; - + this.WorldBoundaryKill = false; + this.SpawnDistanceRequirement = 48; this.DamageSelf = true; @@ -171,39 +224,51 @@ public class SurvivalGames extends SoloGame this.ItemDrop = true; this.ItemPickup = true; - + this.InventoryClick = true; this.InventoryOpenBlock = true; this.InventoryOpenChest = true; - this.CompassEnabled = false; //XXX - - //Blocks - this.BlockBreakAllow.add(46); //TNT + // Blocks + this.BlockBreakAllow.add(46); // TNT this.BlockPlaceAllow.add(46); - this.BlockBreakAllow.add(30); //Web + this.BlockBreakAllow.add(30); // Web this.BlockPlaceAllow.add(30); - this.BlockBreakAllow.add(132); //Tripwire + this.BlockBreakAllow.add(132); // Tripwire this.BlockPlaceAllow.add(132); - this.BlockBreakAllow.add(131); //Wire Hook + this.BlockBreakAllow.add(131); // Wire Hook this.BlockPlaceAllow.add(131); - this.BlockBreakAllow.add(55); //Redstone Dust + this.BlockBreakAllow.add(55); // Redstone Dust this.BlockPlaceAllow.add(55); - this.BlockBreakAllow.add(72); //Wood Pressure Plate + this.BlockBreakAllow.add(72); // Wood Pressure Plate this.BlockPlaceAllow.add(72); - this.BlockBreakAllow.add(69); //Lever + this.BlockBreakAllow.add(69); // Lever this.BlockPlaceAllow.add(69); - this.BlockBreakAllow.add(18); //Leaves + this.BlockBreakAllow.add(18); // Leaves - //SPREAD - _spreadType = 1;//UtilMath.r(3); + BlockBreakAllow.add(Material.LONG_GRASS.getId()); + BlockBreakAllow.add(Material.RED_ROSE.getId()); + BlockBreakAllow.add(Material.YELLOW_FLOWER.getId()); + BlockBreakAllow.add(Material.BROWN_MUSHROOM.getId()); + BlockBreakAllow.add(Material.RED_MUSHROOM.getId()); + BlockBreakAllow.add(Material.DEAD_BUSH.getId()); + BlockBreakAllow.add(Material.CARROT.getId()); + BlockBreakAllow.add(Material.POTATO.getId()); + BlockBreakAllow.add(Material.DOUBLE_PLANT.getId()); + BlockBreakAllow.add(Material.CROPS.getId()); + BlockBreakAllow.add(Material.SAPLING.getId()); + BlockBreakAllow.add(Material.VINE.getId()); + BlockBreakAllow.add(Material.WATER_LILY.getId()); + + // SPREAD + _spreadType = 1;// UtilMath.r(3); _spreadTypeBlocks = new ArrayList>(); @@ -235,14 +300,179 @@ public class SurvivalGames extends SoloGame System.out.println("==================="); System.out.println("CREEP TYPE: " + _spreadName); System.out.println("==================="); - //Manager.GetStatsManager().addTable(GetName(), "kills", "deaths", "chestsOpened"); + // Manager.GetStatsManager().addTable(GetName(), "kills", "deaths", "chestsOpened"); - registerStatTrackers( - new WinWithoutWearingArmorStatTracker(this), - new KillsWithinTimeLimitStatTracker(this, 3, 60, "Bloodlust"), - new FirstSupplyDropOpenStatTracker(this), - new SimultaneousSkeletonStatTracker(this, 5) - ); + setupLoot(); + + 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); + + _ticksField = TileEntityChest.class.getDeclaredField("ticks"); + _ticksField.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 EntityArrow) + { + packetInfo.setCancelled(true); + } + } + } + }; + + registerStatTrackers(new WinWithoutWearingArmorStatTracker(this), new KillsWithinTimeLimitStatTracker(this, 3, 60, + "Bloodlust"), new FirstSupplyDropOpenStatTracker(this), new SimultaneousSkeletonStatTracker(this, 5)); + } + + @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); + } + } + + @Override + public boolean isPlaySoundGameStart() + { + return false; + } + + private void setupLoot() + { + // Food + _baseLoot.registerLoot(new RandomItem(Material.RAW_FISH, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.RAW_BEEF, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.RAW_CHICKEN, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.POTATO_ITEM, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.CARROT_ITEM, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.RED_MUSHROOM, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.BROWN_MUSHROOM, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.WHEAT, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.APPLE, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.PORK, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(new ItemStack(Material.INK_SACK, 1, (short) 3), 30, 1, 2)); // Cocoa beans + _baseLoot.registerLoot(new RandomItem(Material.ROTTEN_FLESH, 30, 1, 2)); + + // Weapons + _baseLoot.registerLoot(new RandomItem(Material.WOOD_AXE, 30)); + _baseLoot.registerLoot(new RandomItem(Material.WOOD_SWORD, 30)); + _baseLoot.registerLoot(new RandomItem(Material.STONE_AXE, 30)); + + // Leather armor + _baseLoot.registerLoot(new RandomItem(Material.LEATHER_BOOTS, 30)); + _baseLoot.registerLoot(new RandomItem(Material.LEATHER_CHESTPLATE, 30)); + _baseLoot.registerLoot(new RandomItem(Material.LEATHER_HELMET, 30)); + _baseLoot.registerLoot(new RandomItem(Material.LEATHER_LEGGINGS, 30)); + + // Chain armor + _baseLoot.registerLoot(new RandomItem(Material.CHAINMAIL_BOOTS, 30)); + _baseLoot.registerLoot(new RandomItem(Material.CHAINMAIL_CHESTPLATE, 30)); + _baseLoot.registerLoot(new RandomItem(Material.CHAINMAIL_HELMET, 30)); + _baseLoot.registerLoot(new RandomItem(Material.CHAINMAIL_LEGGINGS, 30)); + + // Throwable + _baseLoot.registerLoot(new RandomItem(Material.FISHING_ROD, 30)); + _baseLoot.registerLoot(new RandomItem(Material.BOW, 30)); + _baseLoot.registerLoot(new RandomItem(Material.ARROW, 30, 1, 5)); + _baseLoot.registerLoot(new RandomItem(Material.SNOW_BALL, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.EGG, 30, 1, 2)); + + // Misc + _baseLoot.registerLoot(new RandomItem(Material.EXP_BOTTLE, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.FLINT_AND_STEEL, 1)); + _baseLoot.registerLoot(new RandomItem(Material.COMPASS, 50)); + _baseLoot.registerLoot(new RandomItem(Material.STICK, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.BOAT, 30)); + _baseLoot.registerLoot(new RandomItem(Material.FLINT, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.FEATHER, 30, 1, 2)); + _baseLoot.registerLoot(new RandomItem(Material.GOLD_INGOT, 30, 1, 2)); + + _spawnLoot.cloneLoot(_baseLoot); + + // Food + _spawnLoot.registerLoot(new RandomItem(Material.BAKED_POTATO, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.CAKE, 30)); + _spawnLoot.registerLoot(new RandomItem(Material.COOKED_BEEF, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.COOKED_CHICKEN, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.COOKED_FISH, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.GRILLED_PORK, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.COOKIE, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.PUMPKIN_PIE, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.APPLE, 30, 1, 2)); + + // Loot for chests in spawn + // Random bowl + _spawnLoot.registerLoot(new RandomItem(Material.BOWL, 30, 1, 2)); + + // Weaponry and ores + _spawnLoot.registerLoot(new RandomItem(Material.STONE_SWORD, 30)); + _spawnLoot.registerLoot(new RandomItem(Material.IRON_INGOT, 30, 1, 2)); + _spawnLoot.registerLoot(new RandomItem(Material.DIAMOND, 30)); + + // Iron gear + _spawnLoot.registerLoot(new RandomItem(Material.IRON_BOOTS, 30)); + _spawnLoot.registerLoot(new RandomItem(Material.IRON_CHESTPLATE, 30)); + _spawnLoot.registerLoot(new RandomItem(Material.IRON_HELMET, 30)); + _spawnLoot.registerLoot(new RandomItem(Material.IRON_LEGGINGS, 30)); + + // Supply crate loot + // Diamond gear + _superLoot.registerLoot(new RandomItem(Material.DIAMOND_HELMET, 3)); + _superLoot.registerLoot(new RandomItem(Material.DIAMOND_CHESTPLATE, 1)); + _superLoot.registerLoot(new RandomItem(Material.DIAMOND_LEGGINGS, 2)); + _superLoot.registerLoot(new RandomItem(Material.DIAMOND_BOOTS, 3)); + + // Iron gear + _superLoot.registerLoot(new RandomItem(Material.IRON_HELMET, 30)); + _superLoot.registerLoot(new RandomItem(Material.IRON_CHESTPLATE, 24)); + _superLoot.registerLoot(new RandomItem(Material.IRON_LEGGINGS, 27)); + _superLoot.registerLoot(new RandomItem(Material.IRON_BOOTS, 30)); + + // Weapons + _superLoot.registerLoot(new RandomItem(Material.IRON_SWORD, 24)); + _superLoot.registerLoot(new RandomItem(Material.DIAMOND_SWORD, 8)); + _superLoot.registerLoot(new RandomItem(Material.DIAMOND_AXE, 16)); + + // Cooked furnace + _cookedFurnace.registerLoot(new RandomItem(Material.COOKED_BEEF, 3, 1, 2)); + _cookedFurnace.registerLoot(new RandomItem(Material.COOKED_CHICKEN, 3, 1, 2)); + _cookedFurnace.registerLoot(new RandomItem(Material.COOKED_FISH, 3, 1, 2)); + _cookedFurnace.registerLoot(new RandomItem(Material.GRILLED_PORK, 3, 1, 2)); + _cookedFurnace.registerLoot(new RandomItem(Material.IRON_INGOT, 1, 1, 1)); + _cookedFurnace.registerLoot(new RandomItem(Material.BAKED_POTATO, 3, 1, 1)); + _cookedFurnace.registerLoot(new RandomItem(Material.PUMPKIN_PIE, 3, 1, 1)); + + // Raw furnace + _rawFurnace.registerLoot(new RandomItem(Material.RAW_BEEF, 1, 1, 2)); + _rawFurnace.registerLoot(new RandomItem(Material.RAW_CHICKEN, 1, 1, 2)); + _rawFurnace.registerLoot(new RandomItem(Material.RAW_FISH, 1, 1, 2)); + _rawFurnace.registerLoot(new RandomItem(Material.PORK, 1, 1, 2)); + _rawFurnace.registerLoot(new RandomItem(Material.POTATO_ITEM, 1, 1, 2)); } @Override @@ -252,14 +482,14 @@ public class SurvivalGames extends SoloGame } @Override - public void ParseData() + public void ParseData() { _spawn = UtilWorld.averageLocation(this.GetTeamList().get(0).GetSpawns()); for (Location loc : this.GetTeamList().get(0).GetSpawns()) loc.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(loc, _spawn))); - CreateChestCraftEnchant(); + setupChestsEnchantingCrafting(); _supplyLocations = WorldData.GetDataLocs("WHITE"); for (Location loc : _supplyLocations) @@ -272,35 +502,35 @@ public class SurvivalGames extends SoloGame } } - private void CreateChestCraftEnchant() + private void setupChestsEnchantingCrafting() { ArrayList chests = WorldData.GetCustomLocs("54"); System.out.println("Map Chest Locations: " + chests.size()); - //Enchants + // Enchants System.out.println("Enchanting Tables: " + Math.min(5, chests.size())); - for (int i=0 ; i<5 && !chests.isEmpty() ; i++) + for (int i = 0; i < 5 && !chests.isEmpty(); i++) { - Location loc = chests.remove(UtilMath.r(chests.size())); + Location loc = chests.remove(UtilMath.r(chests.size())); loc.getBlock().setType(Material.ENCHANTMENT_TABLE); } - //Crafting + // Crafting System.out.println("Crafting Benches: " + Math.min(10, chests.size())); - for (int i=0 ; i<10 && !chests.isEmpty() ; i++) + for (int i = 0; i < 10 && !chests.isEmpty(); i++) { - Location loc = chests.remove(UtilMath.r(chests.size())); + Location loc = chests.remove(UtilMath.r(chests.size())); loc.getBlock().setType(Material.WORKBENCH); } int spawn = 0; - //Chests + // Chests System.out.println("Chests: " + Math.min(250, chests.size())); - for (int i=0 ; i<250 && !chests.isEmpty() ; i++) + for (int i = 0; i < 250 && !chests.isEmpty(); i++) { - Location loc = chests.remove(UtilMath.r(chests.size())); + Location loc = chests.remove(UtilMath.r(chests.size())); if (UtilMath.offset2d(loc, _spawn) < 8) spawn++; @@ -336,194 +566,174 @@ public class SurvivalGames extends SoloGame while (done < 40) { - Block block = UtilBlock.getHighest(WorldData.World, WorldData.MinX + UtilMath.r(xDiff), WorldData.MinZ + UtilMath.r(zDiff), ignore); + Block block = UtilBlock.getHighest(WorldData.World, WorldData.MinX + UtilMath.r(xDiff), + WorldData.MinZ + UtilMath.r(zDiff), ignore); if (!UtilBlock.airFoliage(block) || !UtilBlock.solid(block.getRelative(BlockFace.DOWN))) continue; - block.setTypeIdAndData(54, (byte)UtilMath.r(4), true); + block.setTypeIdAndData(Material.CHEST.getId(), (byte) UtilMath.r(4), true); done++; } } + private void fillChest(Player looter, Block block) + { + _lootedBlocks.add(block.getLocation()); + + Chest chest = (Chest) block.getState(); + + chest.getBlockInventory().clear(); + + int items = 2; + if (Math.random() > 0.50) + items++; + if (Math.random() > 0.65) + items++; + if (Math.random() > 0.80) + items++; + if (Math.random() > 0.95) + items++; + + boolean spawnChest = UtilMath.offset(chest.getLocation(), _spawn) < 8; + if (spawnChest) + items += 3; + + if (GetKit(looter) instanceof KitLooter) + { + items += UtilMath.r(3); + } + + if (_supplyCrates.contains(block)) + { + items = 2; + if (Math.random() > 0.75) + items++; + if (Math.random() > 0.95) + items++; + } + + for (int i = 0; i < items; i++) + { + ItemStack item; + + if (spawnChest) + { + item = _spawnLoot.getLoot(); + } + else + { + item = GetChestItem(_supplyCrates.contains(block)); + } + + if (item.getType() == Material.COMPASS) + { + item = buildCompass(5); + } + + chest.getBlockInventory().setItem(UtilMath.r(27), item); + } + + if (_supplyCrates.contains(block)) + { + Bukkit.getPluginManager().callEvent(new SupplyChestOpenEvent(looter, block)); + } + + _supplyCrates.remove(block); + _landedCrates.add(block.getLocation()); + } + @EventHandler - private void OpenChest(PlayerInteractEvent event) + public void OpenChest(PlayerInteractEvent event) { if (event.isCancelled()) return; - if (event.getClickedBlock() == null) + Block block = event.getClickedBlock(); + + if (block == null) return; - if (!(event.getClickedBlock().getState() instanceof Chest)) + if (!IsLive()) return; - if (GetState() != GameState.Live) + if (_lootedBlocks.contains(block.getLocation())) return; - if (_openedChest.contains(event.getClickedBlock().getLocation())) - return; + BlockState state = block.getState(); - _openedChest.add(event.getClickedBlock().getLocation()); - - Chest chest = (Chest)event.getClickedBlock().getState(); - - chest.getBlockInventory().clear(); - - int count = 2; - if (Math.random() > 0.50) count++; - if (Math.random() > 0.65) count++; - if (Math.random() > 0.80) count++; - if (Math.random() > 0.95) count++; - - if (UtilMath.offset(chest.getLocation(), _spawn) < 8) - count += 3; - - if (GetKit(event.getPlayer()) instanceof KitLooter) + if (state instanceof DoubleChest) { - count += UtilMath.r(3); - } + DoubleChest doubleChest = (DoubleChest) state; - if (_supplyChests.contains(event.getClickedBlock())) + fillChest(event.getPlayer(), ((Chest) doubleChest.getLeftSide()).getBlock()); + fillChest(event.getPlayer(), ((Chest) doubleChest.getRightSide()).getBlock()); + } + else if (state instanceof Chest) { - count = 2; - if (Math.random() > 0.75) count++; - if (Math.random() > 0.95) count++; + fillChest(event.getPlayer(), block); } - - for (int i = 0; i < count; i++) - chest.getBlockInventory().setItem(UtilMath.r(27), GetChestItem(_supplyChests.contains(event.getClickedBlock()))); - - if (_supplyChests.contains(event.getClickedBlock())) + else if (state instanceof Furnace) { - Bukkit.getPluginManager().callEvent(new SupplyChestOpenEvent(event.getPlayer(), event.getClickedBlock())); + Furnace furnace = (Furnace) state; + + if (furnace.getCookTime() == 0) + { + FurnaceInventory inv = furnace.getInventory(); + + if (UtilMath.r(3) == 0) + { + int random = UtilMath.r(9); + + if (random == 0) + { + inv.setFuel(new ItemStack(Material.STICK, new Random().nextInt(2) + 1)); + } + else if (random <= 3) + { + inv.setSmelting(_rawFurnace.getLoot()); + } + else + { + inv.setResult(_cookedFurnace.getLoot()); + } + } + + _lootedBlocks.add(block.getLocation()); + } } - - _supplyChests.remove(event.getClickedBlock()); } private ItemStack GetChestItem(boolean superChest) { - if (_baseChestLoot.isEmpty()) + if (superChest) + return _superLoot.getLoot(); + + return _baseLoot.getLoot(); + } + + private String buildTime() + { + String s = ""; + + for (char c : ("" + System.nanoTime()).toCharArray()) { - //Armor - for (int i = 0; i < 10; i++) _baseChestLoot.add(new ItemStack(Material.IRON_HELMET)); - for (int i = 0; i < 3; i++) _baseChestLoot.add(new ItemStack(Material.IRON_CHESTPLATE)); - for (int i = 0; i < 5; i++) _baseChestLoot.add(new ItemStack(Material.IRON_LEGGINGS)); - for (int i = 0; i < 10; i++) _baseChestLoot.add(new ItemStack(Material.IRON_BOOTS)); - - for (int i = 0; i < 30; i++) _baseChestLoot.add(new ItemStack(Material.CHAINMAIL_HELMET)); - for (int i = 0; i < 20; i++) _baseChestLoot.add(new ItemStack(Material.CHAINMAIL_CHESTPLATE)); - for (int i = 0; i < 25; i++) _baseChestLoot.add(new ItemStack(Material.CHAINMAIL_LEGGINGS)); - for (int i = 0; i < 30; i++) _baseChestLoot.add(new ItemStack(Material.CHAINMAIL_BOOTS)); - - for (int i = 0; i < 40; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_HELMET)); - for (int i = 0; i < 30; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_CHESTPLATE)); - for (int i = 0; i < 35; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_LEGGINGS)); - for (int i = 0; i < 40; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_BOOTS)); - - for (int i = 0; i < 100; i++) _baseChestLoot.add(new ItemStack(Material.LEATHER_HELMET)); - for (int i = 0; i < 90; i++) _baseChestLoot.add(new ItemStack(Material.LEATHER_CHESTPLATE)); - for (int i = 0; i < 85; i++) _baseChestLoot.add(new ItemStack(Material.LEATHER_LEGGINGS)); - for (int i = 0; i < 100; i++) _baseChestLoot.add(new ItemStack(Material.LEATHER_BOOTS)); - - //Weapons - for (int i = 0; i < 70; i++) _baseChestLoot.add(new ItemStack(Material.WOOD_AXE)); - for (int i = 0; i < 45; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_AXE)); - for (int i = 0; i < 35; i++) _baseChestLoot.add(new ItemStack(Material.STONE_AXE)); - for (int i = 0; i < 15; i++) _baseChestLoot.add(new ItemStack(Material.IRON_AXE)); - - for (int i = 0; i < 60; i++) _baseChestLoot.add(new ItemStack(Material.WOOD_SWORD)); - for (int i = 0; i < 35; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_SWORD)); - for (int i = 0; i < 25; i++) _baseChestLoot.add(new ItemStack(Material.STONE_SWORD)); - for (int i = 0; i < 8; i++) _baseChestLoot.add(new ItemStack(Material.IRON_SWORD)); - - for (int i = 0; i < 45; i++) _baseChestLoot.add(new ItemStack(Material.BOW)); - for (int i = 0; i < 55; i++) _baseChestLoot.add(new ItemStack(Material.ARROW, 4)); - - for (int i = 0; i < 15; i++) _baseChestLoot.add(new ItemStack(Material.TNT, 1)); - for (int i = 0; i < 30; i++) _baseChestLoot.add(new ItemStack(Material.WEB, 2)); - - //Food - for (int i = 0; i < 40; i++) _baseChestLoot.add(new ItemStack(Material.MUSHROOM_SOUP)); - for (int i = 0; i < 50; i++) _baseChestLoot.add(new ItemStack(Material.COOKED_CHICKEN, 4)); - for (int i = 0; i < 80; i++) _baseChestLoot.add(new ItemStack(Material.RAW_BEEF, 6)); - for (int i = 0; i < 50; i++) _baseChestLoot.add(new ItemStack(Material.GRILLED_PORK, 4)); - for (int i = 0; i < 160; i++) _baseChestLoot.add(new ItemStack(Material.BREAD, 5)); - for (int i = 0; i < 40; i++) _baseChestLoot.add(new ItemStack(Material.PUMPKIN_PIE, 3)); - for (int i = 0; i < 80; i++) _baseChestLoot.add(new ItemStack(Material.COOKIE, 7)); - for (int i = 0; i < 90; i++) _baseChestLoot.add(new ItemStack(Material.ROTTEN_FLESH, 4)); - - for (int i = 0; i < 80; i++) _baseChestLoot.add(new ItemStack(Material.WHEAT, 6)); - - //Misc - for (int i = 0; i < 50; i++) _baseChestLoot.add(new ItemStack(Material.COMPASS, 1)); - for (int i = 0; i < 25; i++) _baseChestLoot.add(new ItemStack(Material.EXP_BOTTLE, 1)); - for (int i = 0; i < 50; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_INGOT, 2)); - for (int i = 0; i < 30; i++) _baseChestLoot.add(new ItemStack(Material.IRON_INGOT)); - for (int i = 0; i < 5; i++) _baseChestLoot.add(new ItemStack(Material.DIAMOND)); - for (int i = 0; i < 60; i++) _baseChestLoot.add(new ItemStack(Material.STICK, 4)); - for (int i = 0; i < 80; i++) _baseChestLoot.add(new ItemStack(Material.FLINT, 6)); - for (int i = 0; i < 80; i++) _baseChestLoot.add(new ItemStack(Material.FEATHER, 6)); - for (int i = 0; i < 40; i++) _baseChestLoot.add(new ItemStack(Material.BOAT)); - for (int i = 0; i < 70; i++) _baseChestLoot.add(new ItemStack(Material.FISHING_ROD)); - - //Building Supplies - for (int i = 0; i < 45; i++) _baseChestLoot.add(new ItemStack(Material.PISTON_BASE, 4)); - - /* - String material = _baseChestLoot.get(0).getType().toString(); - double count = 0; - - for (int i = 0; i < _baseChestLoot.size(); i++) - { - if (!_baseChestLoot.get(i).getType().toString().equalsIgnoreCase(material)) - { - System.out.println(material + " - " + count + " - " + (count / _baseChestLoot.size() * 100) + "%"); - material = _baseChestLoot.get(i).getType().toString(); - count = 1; - } - else - { - count++; - } - } - - System.out.println(material + " " + (count / _baseChestLoot.size() * 100) + "%"); - */ + s += "§" + c; } - if (_superChestLoot.isEmpty()) - { - for (int i = 0; i < 3; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_HELMET)); - for (int i = 0; i < 1; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_CHESTPLATE)); - for (int i = 0; i < 2; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_LEGGINGS)); - for (int i = 0; i < 3; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_BOOTS)); + return s; + } - for (int i = 0; i < 30; i++) _superChestLoot.add(new ItemStack(Material.IRON_HELMET)); - for (int i = 0; i < 24; i++) _superChestLoot.add(new ItemStack(Material.IRON_CHESTPLATE)); - for (int i = 0; i < 27; i++) _superChestLoot.add(new ItemStack(Material.IRON_LEGGINGS)); - for (int i = 0; i < 30; i++) _superChestLoot.add(new ItemStack(Material.IRON_BOOTS)); + private ItemStack buildCompass(int uses) + { + ItemBuilder item = new ItemBuilder(Material.COMPASS); + item.setTitle(C.cWhite + "Player Tracker" + buildTime()); - for (int i = 0; i < 24; i++) _superChestLoot.add(new ItemStack(Material.IRON_SWORD)); - for (int i = 0; i < 8; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_SWORD)); - for (int i = 0; i < 16; i++) _superChestLoot.add(new ItemStack(Material.DIAMOND_AXE)); - } + item.addLore(C.cBlue + "Uses remaining: " + C.cWhite + uses); + item.addLore(C.cGray + "Use this to find the location and"); + item.addLore(C.cGray + "distance of the nearest player!"); - - ItemStack stack = _baseChestLoot.get(UtilMath.r(_baseChestLoot.size())); - if (superChest) - stack = _superChestLoot.get(UtilMath.r(_superChestLoot.size())); - - int amount = 1; - - if (stack.getType().getMaxStackSize() > 1) - amount = Math.max(1, UtilMath.r(stack.getAmount())); - - if (stack.getTypeId() == 33) - return ItemStackFactory.Instance.CreateStack(stack.getTypeId(), (byte)0, amount, "Barricade"); - - return ItemStackFactory.Instance.CreateStack(stack.getTypeId(), amount); + return item.build(); } @EventHandler @@ -532,15 +742,191 @@ public class SurvivalGames extends SoloGame if (event.GetState() != GameState.Live) return; + Scoreboard board = GetScoreboard().GetScoreboard(); + for (Player player : GetPlayers(true)) { + player.playSound(player.getLocation(), Sound.DONKEY_DEATH, 0.8F, 0); + Manager.GetCondition().Factory().Speed("Start Speed", player, player, 30, 1, false, false, false); Manager.GetCondition().Factory().HealthBoost("Start Health", player, player, 30, 1, false, false, false); player.setHealth(player.getMaxHealth()); + + Team team = board.registerNewTeam(player.getName()); + + team.setPrefix(board.getPlayerTeam(player).getPrefix()); + + team.addPlayer(player); } } + @EventHandler + public void joinMessage(PlayerJoinEvent event) + { + if (!UtilPlayer.is1_8(event.getPlayer())) + returnToHub(event.getPlayer()); + } + + @EventHandler + public void outdatedVersion(GameStateChangeEvent event) + { + for (Player player : UtilServer.getPlayers()) + { + if (!UtilPlayer.is1_8(player)) + returnToHub(player); + } + } + + public void returnToHub(Player player) + { + UtilPlayer.message(player, " "); + UtilPlayer.message(player, C.cGold + C.Bold + "SurvivalGames requires you to be using Minecraft 1.8!"); + UtilPlayer.message(player, " "); + + player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f); + Manager.GetPortal().sendPlayerToServer(player, "Lobby"); + } + + @EventHandler + public void UpdateNametagVisibility(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + if (!IsLive()) + return; + + ArrayList alivePlayers = GetPlayers(true); + HashMap> checkedPlayers = new HashMap>(); + + for (Player target : alivePlayers) + { + + PacketPlayOutScoreboardTeam packet = null; + + try + { + ScoreboardTeam nmsTeam = (ScoreboardTeam) _packetTeam.get(target.getScoreboard().getTeam(target.getName())); + + packet = new PacketPlayOutScoreboardTeam(nmsTeam, 2); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + for (Player player : alivePlayers) + { + if (target != player) + { + boolean hideName = false; + + if (!checkedPlayers.containsKey(target) || !checkedPlayers.get(target).containsKey(player)) + { + if (target.getLocation().distance(player.getLocation()) > 16) + { + hideName = true; + } + else if (!target.hasLineOfSight(player)) + { + // no los + hideName = true; + } + + Player[] players = new Player[] + { + target, player + }; + + for (int i = 0; i <= 1; i++) + { + Player p1 = players[i]; + Player p2 = players[1 - i]; + + if (!checkedPlayers.containsKey(p1)) + { + checkedPlayers.put(p1, new HashMap()); + } + + checkedPlayers.get(p1).put(p2, hideName); + } + } + else + { + hideName = checkedPlayers.get(target).get(player); + } + + // If hiddenNames conta + if (hideName != (_hiddenNames.containsKey(player) && _hiddenNames.get(player).contains(target.getName()))) + { + if (!hideName) + { + _hiddenNames.get(player).remove(target.getName()); + } + else + { + if (!_hiddenNames.containsKey(player)) + { + _hiddenNames.put(player, new HashSet()); + } + + _hiddenNames.get(player).add(target.getName()); + } + + try + { + _nameTagVisibility.set(packet, hideName ? "never" : "always"); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + UtilPlayer.sendPacket(player, packet); + } + } + } + } + } + + @EventHandler + public void RemoveNametagInfo(PlayerQuitEvent event) + { + _hiddenNames.remove(event.getPlayer()); + deathOrQuit(event.getPlayer()); + } + + @EventHandler + public void onGameEnd(GameStateChangeEvent event) + { + if (event.GetState() != GameState.End) + return; + + new BukkitRunnable() + { + public void run() + { + if (GetState() != GameState.End) + { + cancel(); + return; + } + + for (Location loc : GetTeamList().get(0).GetSpawns()) + { + Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); + + FireworkMeta meta = firework.getFireworkMeta(); + + meta.addEffect(FireworkEffect.builder().withColor(Color.AQUA).with(Type.BALL).withTrail().build()); + + firework.setFireworkMeta(meta); + } + } + }.runTaskTimer(getArcadeManager().getPlugin(), 0, 60); + } + @EventHandler public void SpeedRemove(CustomDamageEvent event) { @@ -549,10 +935,29 @@ public class SurvivalGames extends SoloGame Manager.GetCondition().EndCondition(damager, null, "Start Speed"); } - //If an item spawns and no one is there to see it, does it really spawn? No. + // If an item spawns and no one is there to see it, does it really spawn? No. @EventHandler public void ItemSpawn(ItemSpawnEvent event) { + Material mat = event.getEntity().getItemStack().getType(); + + switch (mat) + { + case SEEDS: + case SAPLING: + case VINE: + case LEAVES: + case LONG_GRASS: + case RED_ROSE: + case YELLOW_FLOWER: + case DEAD_BUSH: + case WATER_LILY: + event.setCancelled(true); + return; + default: + break; + } + for (Player player : GetPlayers(true)) if (UtilMath.offset(player, event.getEntity()) < 6) return; @@ -561,52 +966,54 @@ public class SurvivalGames extends SoloGame } @EventHandler - public void RedBorderStart(GameStateChangeEvent event) + // TODO + public void frostBorderStart(GameStateChangeEvent event) { if (event.GetState() != GameState.Prepare) return; - //Start Red + // Start Red Block block; - for (int x=WorldData.MinX ; x<=WorldData.MaxX ; x++) + for (int x = WorldData.MinX; x <= WorldData.MaxX; x++) { block = WorldData.World.getHighestBlockAt(x, WorldData.MinZ); while (!UtilBlock.solid(block) && !block.isLiquid() && block.getY() > 0) block = block.getRelative(BlockFace.DOWN); if (block.getY() > 0) - _redLocations.add(block.getLocation()); + _frostLocations.add(block.getLocation()); block = WorldData.World.getHighestBlockAt(x, WorldData.MaxZ); while (!UtilBlock.solid(block) && !block.isLiquid() && block.getY() > 0) block = block.getRelative(BlockFace.DOWN); if (block.getY() > 0) - _redLocations.add(block.getLocation()); + _frostLocations.add(block.getLocation()); } - for (int z=WorldData.MinZ ; z<=WorldData.MaxZ ; z++) + for (int z = WorldData.MinZ; z <= WorldData.MaxZ; z++) { block = WorldData.World.getHighestBlockAt(WorldData.MinX, z); while (!UtilBlock.solid(block) && !block.isLiquid() && block.getY() > 0) block = block.getRelative(BlockFace.DOWN); if (block.getY() > 0) - _redLocations.add(block.getLocation()); + _frostLocations.add(block.getLocation()); block = WorldData.World.getHighestBlockAt(WorldData.MaxX, z); while (!UtilBlock.solid(block) && !block.isLiquid() && block.getY() > 0) block = block.getRelative(BlockFace.DOWN); if (block.getY() > 0) - _redLocations.add(block.getLocation()); + _frostLocations.add(block.getLocation()); } } - public int RedMax() + public int frostMax() { return _maxSpreadRate;// + (24 - GetPlayers(true).size())*2; } @EventHandler - public void RedUpdate(UpdateEvent event) + // TODO + public void frostUpdate(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; @@ -616,56 +1023,56 @@ public class SurvivalGames extends SoloGame long time = System.currentTimeMillis(); - if (_redLocations.isEmpty()) + if (_frostLocations.isEmpty()) return; - int max = Math.max(5, Math.min(RedMax(), _redLocations.size()/100)); + int max = Math.max(5, Math.min(frostMax(), _frostLocations.size() / 100)); - for (int i=0 ; i WorldData.MaxX || block.getZ() < WorldData.MinZ || block.getZ() > WorldData.MaxZ) + // Outside Boundaries + if (block.getX() < WorldData.MinX || block.getX() > WorldData.MaxX || block.getZ() < WorldData.MinZ + || block.getZ() > WorldData.MaxZ) return false; - //Not Visible + // Not Visible if (!UtilBlock.isVisible(block)) return false; - //Apply - _redLocations.add(block.getLocation()); + // Apply + _frostLocations.add(block.getLocation()); return true; } - public void RedChangeBlock(Location loc, int id, byte data) + public void frostChangeBlock(Location loc, int id, byte data) { if (!IsLive()) return; MapUtil.ChunkBlockChange(loc, id, data, false); - //Old Style + // Old Style /* if (true) { @@ -803,20 +1212,22 @@ public class SurvivalGames extends SoloGame } */ - //Non-Queue + // Non-Queue for (Player player : UtilServer.getPlayers()) { - if (Math.abs(player.getLocation().getChunk().getX() - loc.getChunk().getX()) > UtilServer.getServer().getViewDistance()) + if (Math.abs(player.getLocation().getChunk().getX() - loc.getChunk().getX()) > UtilServer.getServer() + .getViewDistance()) continue; - if (Math.abs(player.getLocation().getChunk().getZ() - loc.getChunk().getZ()) > UtilServer.getServer().getViewDistance()) + if (Math.abs(player.getLocation().getChunk().getZ() - loc.getChunk().getZ()) > UtilServer.getServer() + .getViewDistance()) continue; - if (!_redChunks.containsKey(player)) - _redChunks.put(player, new ArrayList()); + if (!_frostChunks.containsKey(player)) + _frostChunks.put(player, new ArrayList()); boolean added = false; - for (ChunkChange change : _redChunks.get(player)) + for (ChunkChange change : _frostChunks.get(player)) { if (change.Chunk.equals(loc.getChunk()))// && change.DirtyCount < 63) { @@ -826,12 +1237,13 @@ public class SurvivalGames extends SoloGame } } if (!added) - _redChunks.get(player).add(new ChunkChange(loc, id, data)); + _frostChunks.get(player).add(new ChunkChange(loc, id, data)); } } @EventHandler - public void RedChunkUpdate(UpdateEvent event) + // TODO + public void frostChunkUpdate(UpdateEvent event) { if (event.getType() != UpdateType.FAST) return; @@ -839,47 +1251,49 @@ public class SurvivalGames extends SoloGame if (!IsLive()) return; - for (Player player : _redChunks.keySet()) + for (Player player : _frostChunks.keySet()) { - //Remove Far Away - Iterator chunkIterator = _redChunks.get(player).iterator(); + // Remove Far Away + Iterator chunkIterator = _frostChunks.get(player).iterator(); while (chunkIterator.hasNext()) { ChunkChange change = chunkIterator.next(); - if (Math.abs(player.getLocation().getChunk().getX() - change.Chunk.getX()) > UtilServer.getServer().getViewDistance() || - Math.abs(player.getLocation().getChunk().getZ() - change.Chunk.getZ()) > UtilServer.getServer().getViewDistance()) + if (Math.abs(player.getLocation().getChunk().getX() - change.Chunk.getX()) > UtilServer.getServer() + .getViewDistance() + || Math.abs(player.getLocation().getChunk().getZ() - change.Chunk.getZ()) > UtilServer.getServer() + .getViewDistance()) { chunkIterator.remove(); } } - if (_redChunks.get(player).isEmpty()) + if (_frostChunks.get(player).isEmpty()) continue; - //Get Fittest Chunk to Update + // Get Fittest Chunk to Update int bestId = -1; double bestScore = 0; - for (int i=0 ; i<_redChunks.get(player).size() ; i++) + for (int i = 0; i < _frostChunks.get(player).size(); i++) { - ChunkChange change = _redChunks.get(player).get(i); + ChunkChange change = _frostChunks.get(player).get(i); - //Base Score, 1 per block + // Base Score, 1 per block double score = change.Changes.size(); - //Time Score, multiply block score by 1 + 0.5 per second - score = score * (1 + (System.currentTimeMillis() - change.Time)/200d); + // Time Score, multiply block score by 1 + 0.5 per second + score = score * (1 + (System.currentTimeMillis() - change.Time) / 200d); - //Distance Divisor + // Distance Divisor double dist = 0.5; if (!player.getLocation().getChunk().equals(change.Chunk)) { int x = Math.abs(player.getLocation().getChunk().getX() - change.Chunk.getX()); int z = Math.abs(player.getLocation().getChunk().getZ() - change.Chunk.getZ()); - dist = Math.sqrt(x*x + z*z); + dist = Math.sqrt(x * x + z * z); } - score = score/(dist*dist); + score = score / (dist * dist); if (bestId == -1 || score > bestScore) { @@ -891,70 +1305,79 @@ public class SurvivalGames extends SoloGame if (bestId == -1) continue; - //Send MultiBlock or Chunk Update for Fittest Chunk - ChunkChange change = _redChunks.get(player).remove(bestId); + // Send MultiBlock or Chunk Update for Fittest Chunk + ChunkChange change = _frostChunks.get(player).remove(bestId); if (change.DirtyCount > 63) MapUtil.SendChunkForPlayer(change.Chunk.getX(), change.Chunk.getZ(), player); else - MapUtil.SendMultiBlockForPlayer(change.Chunk.getX(), change.Chunk.getZ(), change.DirtyBlocks, change.DirtyCount, change.Chunk.getWorld(), player); + MapUtil.SendMultiBlockForPlayer(change.Chunk.getX(), change.Chunk.getZ(), change.DirtyBlocks, change.DirtyCount, + change.Chunk.getWorld(), player); } } - public boolean IsRed(Block block) + public boolean isFrost(Block block) { - if (!_redMap.containsKey(block.getX())) + if (!_frostMap.containsKey(block.getX())) return false; - if (!_redMap.get(block.getX()).containsKey(block.getY())) + if (!_frostMap.get(block.getX()).containsKey(block.getY())) return false; - return _redMap.get(block.getX()).get(block.getY()).contains(block.getZ()); + return _frostMap.get(block.getX()).get(block.getY()).contains(block.getZ()); } - public void SetRed(Location loc) + public void setFrost(Location loc) { - //Save Red - if (!_redMap.containsKey(loc.getBlockX())) - _redMap.put(loc.getBlockX(), new HashMap>()); + // Save Red + if (!_frostMap.containsKey(loc.getBlockX())) + _frostMap.put(loc.getBlockX(), new HashMap>()); - if (!_redMap.get(loc.getBlockX()).containsKey(loc.getBlockY())) - _redMap.get(loc.getBlockX()).put(loc.getBlockY(), new HashSet()); + if (!_frostMap.get(loc.getBlockX()).containsKey(loc.getBlockY())) + _frostMap.get(loc.getBlockX()).put(loc.getBlockY(), new HashSet()); - _redMap.get(loc.getBlockX()).get(loc.getBlockY()).add(loc.getBlockZ()); + _frostMap.get(loc.getBlockX()).get(loc.getBlockY()).add(loc.getBlockZ()); - //Red + // Red if (_spreadType == 0) { - RedChangeBlock(loc, 159, (byte)14); + frostChangeBlock(loc, 159, (byte) 14); } - //Snow + // Snow else if (_spreadType == 1) { - if (loc.getBlock().getType() == Material.LEAVES) //RedChangeBlock(loc, 79, (byte)0); + if (loc.getBlock().getType() == Material.LEAVES) // RedChangeBlock(loc, 79, (byte)0); { } - else if (loc.getBlock().getTypeId() == 8 || loc.getBlock().getTypeId() == 9) RedChangeBlock(loc, 79, (byte)0); - else if (loc.getBlock().getTypeId() == 10 || loc.getBlock().getTypeId() == 11) RedChangeBlock(loc, 49, (byte)0); - else RedChangeBlock(loc, 80, (byte)0); + else if (loc.getBlock().getTypeId() == 8 || loc.getBlock().getTypeId() == 9) + frostChangeBlock(loc, 79, (byte) 0); + else if (loc.getBlock().getTypeId() == 10 || loc.getBlock().getTypeId() == 11) + frostChangeBlock(loc, 49, (byte) 0); + else + frostChangeBlock(loc, 80, (byte) 0); } - //Nether - else + // Nether + else { - if (loc.getBlock().getType() == Material.LEAVES) RedChangeBlock(loc, 88, (byte)0); - else if (loc.getBlock().getTypeId() == 8 || loc.getBlock().getTypeId() == 9) RedChangeBlock(loc, 49, (byte)0); + if (loc.getBlock().getType() == Material.LEAVES) + frostChangeBlock(loc, 88, (byte) 0); + else if (loc.getBlock().getTypeId() == 8 || loc.getBlock().getTypeId() == 9) + frostChangeBlock(loc, 49, (byte) 0); else { double r = Math.random(); - if (r > 0.1) RedChangeBlock(loc, 87, (byte)0); - else RedChangeBlock(loc, 153, (byte)0); - } + if (r > 0.1) + frostChangeBlock(loc, 87, (byte) 0); + else + frostChangeBlock(loc, 153, (byte) 0); + } } } @EventHandler - public void RedAttack(UpdateEvent event) + // TODO + public void frostAttack(UpdateEvent event) { if (event.getType() != UpdateType.FASTER) return; @@ -965,12 +1388,12 @@ public class SurvivalGames extends SoloGame for (Block block : UtilBlock.getInRadius(player.getLocation(), 5d).keySet()) { - if (!IsRed(block)) + if (!isFrost(block)) continue; near = true; - //Red + // Red if (_spreadType == 0) { if (block.getRelative(BlockFace.UP).getType() == Material.AIR) @@ -980,23 +1403,26 @@ public class SurvivalGames extends SoloGame } } - //Snow + // Snow else if (_spreadType == 1) { if (Math.random() > 0.95) player.playEffect(block.getLocation().add(0, 1, 0), Effect.STEP_SOUND, Material.SNOW_BLOCK); if (Math.random() > 0.8) - { + { Vector traj = UtilAlg.getTrajectory(block.getLocation().add(0.5, 1.5, 0.5), player.getLocation()); - Snowball ball = player.getWorld().spawn(block.getLocation().add(0.5, 1.5, 0.5).subtract(traj.clone().multiply(8 + UtilMath.r(8))), Snowball.class); + Snowball ball = player.getWorld().spawn( + block.getLocation().add(0.5, 1.5, 0.5).subtract(traj.clone().multiply(8 + UtilMath.r(8))), + Snowball.class); - ball.setVelocity(UtilAlg.getTrajectory(ball.getLocation(), player.getEyeLocation().add(0, 3, 0)).add(new Vector(Math.random()-0.5, Math.random()-0.5, Math.random()-0.5).multiply(0.1))); - } + ball.setVelocity(UtilAlg.getTrajectory(ball.getLocation(), player.getEyeLocation().add(0, 3, 0)).add( + new Vector(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).multiply(0.1))); + } } - //Nether + // Nether if (_spreadType == 2) { if (block.getRelative(BlockFace.UP).getType() == Material.AIR) @@ -1016,7 +1442,7 @@ public class SurvivalGames extends SoloGame while (!UtilBlock.solid(block) && block.getY() > 0) block = block.getRelative(BlockFace.DOWN); - if (IsRed(block) || block.getY() == 0) + if (isFrost(block) || block.getY() == 0) near = true; } } @@ -1031,29 +1457,111 @@ public class SurvivalGames extends SoloGame { player.getWorld().playSound(player.getLocation(), Sound.AMBIENCE_RAIN, 0.5f, 0f); - if (!_redOutTime.containsKey(player)) + if (!_frostOutTime.containsKey(player)) { - _redOutTime.put(player, System.currentTimeMillis()); - } + _frostOutTime.put(player, System.currentTimeMillis()); + } else { - if (UtilTime.elapsed(_redOutTime.get(player), 5000)) - { - Manager.GetDamage().NewDamageEvent(player, null, null, - DamageCause.VOID, 1, false, true, false, - "Hunger Games", _spreadName); + if (UtilTime.elapsed(_frostOutTime.get(player), 5000)) + { + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.VOID, 1, false, true, false, + "Hunger Games", _spreadName); } } } else { - _redOutTime.remove(player); + _frostOutTime.remove(player); + } + } + } + + public void refillChests() + { + ArrayList list = new ArrayList(_lootedBlocks); + + _lootedBlocks.clear(); + + for (Location loc : list) + { + if (loc.getChunk().isLoaded()) + { + Block block = loc.getBlock(); + + if (_landedCrates.contains(loc)) + continue; + + if (block.getState() instanceof InventoryHolder) + { + InventoryHolder holder = (InventoryHolder) block.getState(); + + if (!holder.getInventory().getViewers().isEmpty()) + { + fillChest((Player) holder.getInventory().getViewers().get(0), block); + } + } } } } @EventHandler - public void RedDamage(CustomDamageEvent event) + public void chestRefill(UpdateEvent event) + { + if (!IsLive() || event.getType() != UpdateType.SEC) + return; + + if (_deathmatchCountdown || _deathmatchLive) + return; + + if (_chestRefillTime > 0) + { + _chestRefillTime--; + switch (_chestRefillTime) + { + case 0: + + Bukkit.broadcastMessage(ChatColor.GOLD + "➽" + ChatColor.GREEN + " The chests has been refilled!"); + + for (Player player : Bukkit.getOnlinePlayers()) + { + player.playSound(player.getEyeLocation(), Sound.IRONGOLEM_DEATH, 1000, 0); + } + + refillChests(); + break; + case 1: + case 2: + case 3: + case 4: + case 5: + case 10: + case 15: + case 30: + case 60: + case 120: + case 180: + case 300: + + String time; + + if (_chestRefillTime >= 60) + time = (_chestRefillTime / 60) + " minute" + (_chestRefillTime > 60 ? "s" : ""); + else + time = _chestRefillTime + " second" + (_chestRefillTime != 1 ? "s" : ""); + + Bukkit.broadcastMessage(ChatColor.GOLD + "➽" + ChatColor.GREEN + " The chests will be refilled in " + time); + + break; + default: + break; + } + } + } + + @EventHandler + // TODO + public void frostDamage(CustomDamageEvent event) { if (event.GetProjectile() == null) return; @@ -1066,29 +1574,6 @@ public class SurvivalGames extends SoloGame event.AddKnockback("Snowball", 4); } - @EventHandler - public void DayNightCycle(UpdateEvent event) - { - if (!IsLive()) - return; - - if (event.getType() != UpdateType.TICK) - return; - - long time = WorldData.World.getTime(); - - if (time > 22000 || time < 14000) - { - WorldTimeSet = (WorldTimeSet + 4)%24000; - } - else - { - WorldTimeSet = (WorldTimeSet + 16)%24000; - } - - WorldData.World.setTime(WorldTimeSet); - } - @EventHandler public void SupplyDrop(UpdateEvent event) { @@ -1109,18 +1594,19 @@ public class SurvivalGames extends SoloGame _supplyCurrent = _supplyLocations.remove(UtilMath.r(_supplyLocations.size())); - //Remove Prior - _supplyChests.remove(_supplyCurrent.getBlock().getRelative(BlockFace.UP)); + // Remove Prior + _supplyCrates.remove(_supplyCurrent.getBlock().getRelative(BlockFace.UP)); _supplyCurrent.getBlock().getRelative(BlockFace.UP).setType(Material.AIR); - //Create New + // Create New _supplyCurrent.getBlock().setType(Material.BEACON); - for (int x=-1 ; x<=1 ; x++) - for (int z=-1 ; z<=1 ; z++) + for (int x = -1; x <= 1; x++) + for (int z = -1; z <= 1; z++) _supplyCurrent.getBlock().getRelative(x, -1, z).setType(Material.IRON_BLOCK); - //Announce - this.Announce(C.cYellow + C.Bold + "Supply Drop Incoming (" + ChatColor.RESET + UtilWorld.locToStrClean(_supplyCurrent) + C.cYellow + C.Bold + ")"); + // Announce + this.Announce(C.cYellow + C.Bold + "Supply Drop Incoming (" + ChatColor.RESET + + UtilWorld.locToStrClean(_supplyCurrent) + C.cYellow + C.Bold + ")"); } } else @@ -1133,23 +1619,25 @@ public class SurvivalGames extends SoloGame _supplyEffect.setY(250); } - FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).with(Type.BURST).trail(false).build(); + FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).with(Type.BURST) + .trail(false).build(); UtilFirework.playFirework(_supplyEffect, effect); - _supplyEffect.setY(_supplyEffect.getY()-2); + _supplyEffect.setY(_supplyEffect.getY() - 2); if (UtilMath.offset(_supplyEffect, _supplyCurrent) < 2) { - effect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).with(Type.BALL_LARGE).trail(true).build(); + effect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).with(Type.BALL_LARGE).trail(true) + .build(); UtilFirework.playFirework(_supplyEffect, effect); - //Create Chest + // Create Chest _supplyCurrent.getBlock().setType(Material.GLASS); _supplyCurrent.getBlock().getRelative(BlockFace.UP).setType(Material.CHEST); - _supplyChests.add(_supplyCurrent.getBlock().getRelative(BlockFace.UP)); - _openedChest.remove(_supplyCurrent); + _supplyCrates.add(_supplyCurrent.getBlock().getRelative(BlockFace.UP)); + _lootedBlocks.remove(_supplyCurrent); - //Reset + // Reset _supplyEffect = null; _supplyCurrent = null; } @@ -1157,6 +1645,29 @@ public class SurvivalGames extends SoloGame } } + @EventHandler + public void DayNightCycle(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + return; + + long time = WorldData.World.getTime(); + + if (time > 22000 || time < 14000) + { + WorldTimeSet = (WorldTimeSet + 4) % 24000; + } + else + { + WorldTimeSet = (WorldTimeSet + 16) % 24000; + } + + WorldData.World.setTime(WorldTimeSet); + } + @EventHandler public void SupplyGlow(UpdateEvent event) { @@ -1166,10 +1677,10 @@ public class SurvivalGames extends SoloGame if (event.getType() != UpdateType.TICK) return; - if (_supplyChests.isEmpty()) + if (_supplyCrates.isEmpty()) return; - Iterator chestIterator = _supplyChests.iterator(); + Iterator chestIterator = _supplyCrates.iterator(); while (chestIterator.hasNext()) { @@ -1185,6 +1696,22 @@ public class SurvivalGames extends SoloGame } } + @EventHandler + public void preventBucketCraft(PrepareItemCraftEvent event) + { + ItemStack result = event.getInventory().getResult(); + + if (result != null) + { + Material type = result.getType(); + + if (type == Material.BUCKET) + { + event.getInventory().setResult(new ItemStack(Material.AIR)); + } + } + } + @EventHandler public void DeathmatchUpdate(UpdateEvent event) { @@ -1218,18 +1745,18 @@ public class SurvivalGames extends SoloGame long timeLeft = 60000 - (System.currentTimeMillis() - _deathmatchTime); if (timeLeft <= 0) - { + { _deathmatchLive = true; - GetTeamList().get(0).SpawnTeleport(); + GetTeamList().get(0).SpawnTeleport(false); - _redLocations.clear(); + _frostLocations.clear(); for (Block block : UtilBlock.getInRadius(_spawn, 52d).keySet()) - RedSpread(block); + frostSpread(block); _deathmatchTime = 10; - } + } } else { @@ -1286,9 +1813,9 @@ public class SurvivalGames extends SoloGame { if (!event.getMessage().equalsIgnoreCase("/dm")) return; - + event.setCancelled(true); - + if (!IsAlive(event.getPlayer())) { UtilPlayer.message(event.getPlayer(), F.main("Game", "You are not in the game.")); @@ -1330,91 +1857,175 @@ public class SurvivalGames extends SoloGame } @EventHandler - public void CompassUpdate(UpdateEvent event) + public void chestTickEvent(UpdateEvent event) { - if (event.getType() != UpdateType.SEC) + if (event.getType() != UpdateType.SLOW) return; - if (!IsLive()) - return; + Iterator> itel = _openedChests.entrySet().iterator(); - //Night Time > Drop Target - if (WorldData.World.getTime() > 14000 && WorldData.World.getTime() < 23000 && _supplyCurrent != null) + while (itel.hasNext()) { - for (Player player : GetPlayers(true)) + Entry entry = itel.next(); + // TODO Test this is removed properly when unloaded chunks + // TODO Load chests status when chunk loads packets + try { - player.setCompassTarget(_supplyCurrent); + int key = (entry.getKey().x + entry.getKey().y + entry.getKey().z) % 200; - for (int i : player.getInventory().all(Material.COMPASS).keySet()) + int ticks = (_ticksField.getInt(entry.getKey()) + key) % 200; + + System.out.print(ticks + " - " + entry.getKey().o); + + if (ticks == entry.getValue()) { - ItemStack stack = player.getInventory().getItem(i); + if (ticks == 1) + { + System.out.print("Removed"); + itel.remove(); + } + else + { + _ticksField.setInt(entry.getKey(), (200 - key) + ticks - 1); + _openedChests.put(entry.getKey(), ticks - 1); + } + } + else + { + _ticksField.setInt(entry.getKey(), (200 - key) + 10); + System.out.print((_ticksField.getInt(entry.getKey()) + key)); + _openedChests.put(entry.getKey(), 10); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } - ItemMeta itemMeta = stack.getItemMeta(); - itemMeta.setDisplayName( - C.cWhite + C.Bold + "Supply Drop Location: " + C.cYellow + UtilMath.trim(1, UtilMath.offset(player.getLocation(), _supplyCurrent))); - stack.setItemMeta(itemMeta); + @EventHandler + public void chestCloseEvent(InventoryCloseEvent event) + { + InventoryHolder holder = event.getInventory().getHolder(); - player.getInventory().setItem(i, stack); + if (holder instanceof DoubleChest) + { + holder = (Chest) ((DoubleChest) holder).getLeftSide(); + } + + if (holder instanceof Chest) + { + Block block = ((Chest) holder).getBlock(); + + TileEntity tileEntity = ((CraftWorld) block.getWorld()).getTileEntityAt(block.getX(), block.getY(), block.getZ()); + + if (tileEntity instanceof TileEntityChest) + { + TileEntityChest chest = (TileEntityChest) tileEntity; + + try + { + chest.o = 10; + + int key = (chest.x + chest.y + chest.z) % 200; + + _ticksField.setInt(chest, (200 - key) + 10); + + _openedChests.put(chest, 10); + } + catch (Exception ex) + { + ex.printStackTrace(); } } } - //Player Target - else + } + + @EventHandler + public void onUse(PlayerInteractEvent event) + { + if (!IsLive()) + return; + + Player player = event.getPlayer(); + + if (!IsAlive(player)) + return; + + if (!event.getAction().name().contains("RIGHT")) + return; + + ItemStack item = event.getItem(); + + if (item == null || item.getType() != Material.COMPASS) + return; + + int uses = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replaceAll("\\D+", "")); + + if (uses > 0) { - for (Player player : GetPlayers(true)) - { - Player target = null; - double bestDist = 0; + uses--; - for (Player other : Manager.GetGame().GetPlayers(true)) + Player closest = null; + double cDist = 0; + + for (Player p : GetPlayers(true)) + { + if (p != player) { - if (other.equals(player)) - continue; + double dist = p.getLocation().distance(player.getLocation()); - if (other.isSneaking()) - continue; - - double dist = UtilMath.offset(player, other); - - if (target == null || dist < bestDist) + if (dist > 10 && (closest == null || dist < cDist)) { - target = other; - bestDist = dist; - } - } - - if (target != null) - { - player.setCompassTarget(target.getLocation()); - - for (int i : player.getInventory().all(Material.COMPASS).keySet()) - { - ItemStack stack = player.getInventory().getItem(i); - - - ItemMeta itemMeta = stack.getItemMeta(); - itemMeta.setDisplayName( - " " + C.cWhite + C.Bold + "Nearest Player: " + C.cYellow + target.getName() + - " " + C.cWhite + C.Bold + "Distance: " + C.cYellow + UtilMath.trim(1, bestDist)); - stack.setItemMeta(itemMeta); - - player.getInventory().setItem(i, stack); + cDist = dist; + closest = p; } } } - } - } + + if (closest != null) + { + player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 0); + closest.playSound(closest.getLocation(), Sound.ORB_PICKUP, 1, 0); + + player.setCompassTarget(closest.getLocation()); + player.setItemInHand(buildCompass(uses)); + + closest.sendMessage(F.main("Compass", player.getName() + " used a compass on you!")); + + player.sendMessage(F.main("Compass", "Located " + closest.getName() + " " + (int) cDist + " blocks away")); + + if (uses >= 1) + { + player.sendMessage(F.main("Compass", uses + " use" + (uses > 1 ? "s" : "") + " of the compass remaining.")); + } + else + { + player.sendMessage(F.main("Compass", "No remaining uses! Next use will break it!")); + } + } + } + else + { + player.sendMessage(F.main("Compass", "The compass breaks! No remaining uses!")); + + player.getWorld().playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 5); + + player.setItemInHand(new ItemStack(Material.AIR)); + } + } @EventHandler - public void DisallowBrewFurnace(PlayerInteractEvent event) + public void DisallowBrewingStand(PlayerInteractEvent event) { if (event.getClickedBlock() == null) return; - if (event.getClickedBlock().getType() == Material.BREWING_STAND || - event.getClickedBlock().getType() == Material.FURNACE || - event.getClickedBlock().getType() == Material.BURNING_FURNACE) + if (event.getClickedBlock().getType() == Material.BREWING_STAND) + { event.setCancelled(true); + } } @EventHandler @@ -1447,7 +2058,7 @@ public class SurvivalGames extends SoloGame Player player = event.getPlayer(); - if (!UtilInv.IsItem(player.getItemInHand(), Material.TNT, (byte)0)) + if (!UtilInv.IsItem(player.getItemInHand(), Material.TNT, (byte) 0)) return; event.setCancelled(true); @@ -1460,15 +2071,16 @@ public class SurvivalGames extends SoloGame if (!Manager.GetGame().CanThrowTNT(player.getLocation())) { - //Inform + // Inform UtilPlayer.message(event.getPlayer(), F.main(GetName(), "You cannot use " + F.item("Throw TNT") + " here.")); return; } - UtilInv.remove(player, Material.TNT, (byte)0, 1); + UtilInv.remove(player, Material.TNT, (byte) 0, 1); UtilInv.Update(player); - TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class); + TNTPrimed tnt = player.getWorld() + .spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class); UtilAction.velocity(tnt, player.getLocation().getDirection(), 0.5, false, 0, 0.1, 10, false); @@ -1483,64 +2095,53 @@ public class SurvivalGames extends SoloGame Player player = _tntMap.remove(event.getEntity()); + /*CustomExplosion explosion = new CustomExplosion(this.getArcadeManager().GetDamage(), event.getEntity().getLocation(), + ((TNTPrimed) event.getEntity()).getYield(), "Throwing TNT"); + + explosion.setPlayer(player, true);*/ + for (Player other : UtilPlayer.getNearby(event.getEntity().getLocation(), 14)) Manager.GetCondition().Factory().Explosion("Throwing TNT", other, player, 50, 0.1, false, false); } @EventHandler - public void BlockPlace(BlockPlaceEvent event) - { - if (IsRed(event.getBlockAgainst())) + // TODO + public void BlockPlaceOnFrost(BlockPlaceEvent event) + { + if (isFrost(event.getBlockAgainst())) { event.setCancelled(true); return; } - - if (event.getItemInHand().getType() == Material.PISTON_BASE) - { - _placedBlocks.add(event.getBlock().getLocation()); - event.setCancelled(false); - - final Block block = event.getBlock(); - - UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() - { - public void run() - { - block.setType(Material.PISTON_BASE); - block.setData((byte) 6); - } - }, 0); - } } @EventHandler - public void TourneyKills(CombatDeathEvent event) - { - if (!(event.GetEvent().getEntity() instanceof Player)) - return; - - Player killed = (Player)event.GetEvent().getEntity(); - - if (event.GetLog().GetKiller() != null) - { - Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); + public void TourneyKills(CombatDeathEvent event) + { + if (!(event.GetEvent().getEntity() instanceof Player)) + return; + + Player killed = (Player) event.GetEvent().getEntity(); + + if (event.GetLog().GetKiller() != null) + { + Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); + + if (killer != null && !killer.equals(killed)) + { + // Manager.GetStatsManager().addStat(killer, GetName(), "kills", 1); + } + } + + if (event.GetLog().GetPlayer() != null) + { + if (killed != null) + { + // Manager.GetStatsManager().addStat(killed, GetName(), "deaths", 1); + } + } + } - if (killer != null && !killer.equals(killed)) - { - //Manager.GetStatsManager().addStat(killer, GetName(), "kills", 1); - } - } - - if (event.GetLog().GetPlayer() != null) - { - if (killed != null) - { - //Manager.GetStatsManager().addStat(killed, GetName(), "deaths", 1); - } - } - } - @EventHandler public void BlockBreak(BlockBreakEvent event) { @@ -1575,18 +2176,102 @@ public class SurvivalGames extends SoloGame event.setCancelled(true); } + private void deathOrQuit(Player player) + { + if (!IsLive()) + return; + + String name = ""; + + for (char c : ("" + _deadBodyCount++).toCharArray()) + { + name += "§" + c; + } + + try + { + + Team team = player.getScoreboard().registerNewTeam(name); + + if (_hiddenNames.containsKey(player) && !_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); + + for (Player alive : GetPlayers(true)) + { + if (_hiddenNames.get(player).contains(alive.getName())) + { + teamName.set(packet, alive.getName()); + UtilPlayer.sendPacket(player, packet); + } + } + } + + 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(BlockFace.values()[Math.round(player.getLocation().getYaw() / 90F) & 0x3].getOppositeFace()); + + 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(); + } + + _hiddenNames.remove(player); + } + @EventHandler public void PlayerKillAward(CombatDeathEvent event) { Game game = Manager.GetGame(); - if (game == null) return; + if (game == null) + return; if (!(event.GetEvent().getEntity() instanceof Player)) return; - FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.RED).with(Type.BALL_LARGE).trail(false).build(); - for (int i=0 ; i<3 ; i++) - UtilFirework.launchFirework(event.GetEvent().getEntity().getLocation(), effect, null, 3); + 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++) + UtilFirework.launchFirework(player.getLocation(), effect, null, 3); if (event.GetLog().GetKiller() == null) return; @@ -1595,7 +2280,7 @@ public class SurvivalGames extends SoloGame if (killer == null) return; - if (killer.equals(event.GetEvent().getEntity())) + if (killer.equals(player)) return; killer.giveExpLevels(1); @@ -1614,11 +2299,12 @@ public class SurvivalGames extends SoloGame } @EventHandler + // TODO public void FixClean(PlayerQuitEvent event) { - _redChunks.remove(event.getPlayer()); + _frostChunks.remove(event.getPlayer()); } - + @Override @EventHandler public void ScoreboardUpdate(UpdateEvent event) @@ -1632,7 +2318,7 @@ public class SurvivalGames extends SoloGame Scoreboard.Reset(); Scoreboard.WriteBlank(); - + GameTeam team = GetTeamList().get(0); if (team.GetPlayers(false).size() < 9) @@ -1665,19 +2351,18 @@ public class SurvivalGames extends SoloGame Scoreboard.Write(C.cRed + "Players Dead"); Scoreboard.Write("" + (team.GetPlayers(false).size() - team.GetPlayers(true).size())); } - - + if (_deathmatchCountdown) { if (event.getType() != UpdateType.TICK) return; long timeLeft = 60000 - (System.currentTimeMillis() - _deathmatchTime); - + Scoreboard.WriteBlank(); Scoreboard.Write(C.cYellow + C.Bold + "Deathmatch"); Scoreboard.Write(UtilTime.MakeStr(Math.max(0, timeLeft), 0)); - + } Scoreboard.Draw(); @@ -1693,13 +2378,12 @@ public class SurvivalGames extends SoloGame return true; } - + @EventHandler public void deathmatchBowShoot(EntityShootBowEvent event) { if (isDeathMatchAboutToStart()) event.getProjectile().remove(); } - - + } From 759db08679e84ca18f5085e55cca0f2b8a06c9b7 Mon Sep 17 00:00:00 2001 From: Tim Ziankoski Date: Mon, 9 Mar 2015 17:24:01 -0400 Subject: [PATCH 3/4] Revert "Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex" This reverts commit 2e06a272b499147ab1b612529ebf4edc5411a67f, reversing changes made to e443b41e15fd475bba06ac63cc39751f02939bb7. --- .../artifacts/Nautilus_Game_Arcade_jar.xml | 2 +- .../artifacts/Nautilus_Game_Arcade_test.xml | 1 - Plugins/.idea/copyright/profiles_settings.xml | 3 - .../Mineplex.Core.Common.iml | 4 +- .../core/common/lang/mineplex_de.properties | 1 - .../core/common/lang/mineplex_en.properties | 4 - .../src/mineplex/core/common/lang/Lang.java | 115 ------------------ .../arcade/managers/GameLobbyManager.java | 12 +- 8 files changed, 8 insertions(+), 134 deletions(-) delete mode 100644 Plugins/.idea/copyright/profiles_settings.xml delete mode 100644 Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties delete mode 100644 Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java diff --git a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml index 3f5cae6e4..cd4447b88 100644 --- a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml +++ b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_jar.xml @@ -17,7 +17,7 @@ - + \ No newline at end of file diff --git a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml index 73139df16..8b3142e4c 100644 --- a/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml +++ b/Plugins/.idea/artifacts/Nautilus_Game_Arcade_test.xml @@ -3,7 +3,6 @@ $PROJECT_DIR$/../Testing/Arcade/plugins - \ No newline at end of file diff --git a/Plugins/.idea/copyright/profiles_settings.xml b/Plugins/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf337..000000000 --- a/Plugins/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml b/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml index c145ccad3..b59695f8a 100644 --- a/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml +++ b/Plugins/Mineplex.Core.Common/Mineplex.Core.Common.iml @@ -4,10 +4,10 @@ - - \ No newline at end of file + + diff --git a/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties b/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties deleted file mode 100644 index cb380f81e..000000000 --- a/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_de.properties +++ /dev/null @@ -1 +0,0 @@ -waiting.for.players=Warten auf Spieler diff --git a/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties b/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties deleted file mode 100644 index d99ecb4b3..000000000 --- a/Plugins/Mineplex.Core.Common/resources/mineplex/core/common/lang/mineplex_en.properties +++ /dev/null @@ -1,4 +0,0 @@ -waiting.for.players=Waiting for Players -lobby=Lobby -starting.in.0.seconds=Starting in {0} Seconds -starting.in.0.seconds.singular=Starting in {0} Second diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java deleted file mode 100644 index cb6e3fa89..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java +++ /dev/null @@ -1,115 +0,0 @@ -package mineplex.core.common.lang; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.WeakHashMap; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public final class Lang -{ - private static final String RESOURCE_BUNDLE_PATH = "mineplex/core/common/lang/mineplex"; - - private static final Map _playerLocales = new WeakHashMap<>(); - private static final ResourceBundle _defaultResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH); - private static final Map _localeResourceBundles = Collections.synchronizedMap(new HashMap()); - - private Lang() - { - - } - - public static void setPlayerLocale(Player player, Locale locale) - { - _playerLocales.put(player, locale); - } - - public static ResourceBundle getDefaultResourceBundle() - { - return _defaultResourceBundle; - } - - public static ResourceBundle getResourceBundle(Locale locale) - { - ResourceBundle bundle = getDefaultResourceBundle(); - - synchronized (_localeResourceBundles) - { - if (_localeResourceBundles.containsKey(locale)) - { - ResourceBundle b = _localeResourceBundles.get(locale); - if (b != null) - bundle = b; - } - else - { - try - { - bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_PATH, locale); - _localeResourceBundles.put(locale, bundle); - } - catch (MissingResourceException e) - { - _localeResourceBundles.put(locale, null); - - Bukkit.getLogger().warning(e.getMessage()); - } - } - } - - return bundle; - } - - public static String getString(String key, int count) - { - return getString(key, (Locale) null, count); - } - - public static String getString(String key, Locale locale, int count) - { - if (key == null) - return null; - else - { - ResourceBundle bundle; - if (locale == null) - bundle = getDefaultResourceBundle(); - else - bundle = getResourceBundle(locale); - - if (count == 1) - { - String singularKey = key + ".singular"; - if (bundle.containsKey(singularKey)) - return bundle.getString(singularKey); - } - - return bundle.getString(key); - } - } - - public static String getString(String key, Player player, int count) - { - return getString(key, _playerLocales.get(player), count); - } - - public static String getString(String key) - { - return getString(key, 0); - } - - public static String getString(String key, Locale locale) - { - return getString(key, locale, 0); - } - - public static String getString(String key, Player player) - { - return getString(key, player, 0); - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java index 688eaa4b8..fe3a858b4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java @@ -1,11 +1,10 @@ package nautilus.game.arcade.managers; -import java.text.MessageFormat;import java.util.ArrayList; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map.Entry; import org.bukkit.Bukkit; @@ -42,7 +41,6 @@ import net.minecraft.server.v1_7_R4.WatchableObject; import mineplex.core.account.CoreClient; import mineplex.core.common.Rank; -import mineplex.core.common.lang.Lang; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; @@ -950,18 +948,18 @@ public class GameLobbyManager implements Listener, IPacketHandler for (Entry entry : _scoreboardMap.entrySet()) { - Objective objective = entry.getValue().getObjective(C.Bold + Lang.getString("lobby", entry.getKey())); - + Objective objective = entry.getValue().getObjective("§l" + "Lobby"); + if (Manager.GetGame() != null && Manager.GetGame().GetCountdown() >= 0) { if (Manager.GetGame().GetCountdown() > 0) - objective.setDisplayName(MessageFormat.format(C.Bold + Lang.getString("starting.in.0.seconds", entry.getKey(), Manager.GetGame().GetCountdown()), C.cGreen + C.Bold + Manager.GetGame().GetCountdown())); + objective.setDisplayName(C.Bold + "§lStarting in " + C.cGreen + "§l" + Manager.GetGame().GetCountdown() + (Manager.GetGame().GetCountdown() == 1 ? " Second" : " Seconds")); else if (Manager.GetGame().GetCountdown() == 0) objective.setDisplayName(ChatColor.WHITE + "§lIn Progress..."); } else { - objective.setDisplayName(C.cGreen + C.Bold + Lang.getString("waiting.for.players", entry.getKey())); + objective.setDisplayName(ChatColor.GREEN + "§l" + "Waiting for Players"); } int line = 15; From f47447134e982921e33699db9abb2576d2222b4b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 11 Mar 2015 13:16:00 +1300 Subject: [PATCH 4/4] Cleanup hologram class, remove witherskull option for 1.8 and fix duplicate nametags and non-invisibility on armorstands --- .../src/mineplex/core/CustomTagFix.java | 5 + .../src/mineplex/core/hologram/Hologram.java | 1213 +++++++++-------- .../game/games/searchanddestroy/TeamBomb.java | 3 +- 3 files changed, 630 insertions(+), 591 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java index 130995fde..bc4a9381f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java @@ -192,6 +192,11 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook // Ignore Armor stand packets if (spawnPacket.b == 30 || spawnPacket.l == null || spawnPacket.l.c() == null || spawnPacket.a == 777777) { + if (spawnPacket.b == 30) + { + _ignoreSkulls.add(spawnPacket.a); + } + return; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index 1c454ae01..7b470f779 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -29,628 +29,663 @@ import mineplex.core.common.util.UtilPlayer; public class Hologram { - public enum HologramTarget - { - BLACKLIST, WHITELIST; - } + public enum HologramTarget + { + BLACKLIST, WHITELIST; + } - private Packet _destroy1_7; - private Packet _destroy1_8; - private boolean _destroyPackets = true; - /** - * 1.7 packets uses both EntityIDs while 1.8 uses only the first. - */ - private ArrayList> _entityIds = new ArrayList>(); - private Entity _followEntity; - private HologramManager _hologramManager; - private boolean _isWitherSkull; - /** - * Keeps track of the holograms movements. This fixes offset that occasionally happens when moving a hologram around. - */ - private Vector _lastMovement; - private Location _location; - private boolean _makePackets = true; - private Packet[] _packets1_7; - private Packet[] _packets1_8; - private HashSet _playersInList = new HashSet(); - private ArrayList _playersTracking = new ArrayList(); - private HologramTarget _target = HologramTarget.BLACKLIST; - private String[] _text = new String[0]; - private int _viewDistance = 70; - protected Vector relativeToEntity; - private boolean _removeEntityDeath; + private Packet _destroy1_7; + private Packet _destroy1_8; + /** + * 1.7 packets uses both EntityIDs while 1.8 uses only the first. + */ + private ArrayList> _entityIds = new ArrayList>(); + private Entity _followEntity; + private HologramManager _hologramManager; + private String[] _hologramText = new String[0]; + /** + * Keeps track of the holograms movements. This fixes offset that occasionally happens when moving a hologram around. + */ + private Vector _lastMovement; + private Location _location; + private boolean _makeDestroyPackets = true; + private boolean _makeSpawnPackets = true; + private Packet[] _packets1_7; + private Packet[] _packets1_8; + private HashSet _playersInList = new HashSet(); + private ArrayList _playersTracking = new ArrayList(); + private boolean _removeEntityDeath; + private HologramTarget _target = HologramTarget.BLACKLIST; + private int _viewDistance = 70; + protected Vector relativeToEntity; - public Hologram(HologramManager hologramManager, Location location, String... text) - { - _hologramManager = hologramManager; - _location = location.clone(); - setText(text); - } - - public boolean isRemoveOnEntityDeath() { - return _removeEntityDeath; - } - - public Hologram setRemoveOnEntityDeath() { - _removeEntityDeath = true; - return this; - } + public Hologram(HologramManager hologramManager, Location location, String... text) + { + _hologramManager = hologramManager; + _location = location.clone(); + setText(text); + } - /** - * Adds the player to the Hologram to be effected by Whitelist or Blacklist - */ - public Hologram addPlayer(Player player) - { - return addPlayer(player.getName()); - } + /** + * Adds the player to the Hologram to be effected by Whitelist or Blacklist + */ + public Hologram addPlayer(Player player) + { + return addPlayer(player.getName()); + } - /** - * Adds the player to the Hologram to be effected by Whitelist or Blacklist - */ - public Hologram addPlayer(String player) - { - _playersInList.add(player); - return this; - } + /** + * Adds the player to the Hologram to be effected by Whitelist or Blacklist + */ + public Hologram addPlayer(String player) + { + _playersInList.add(player); + return this; + } - /** - * Is there a player entry in the hologram for Whitelist and Blacklist - */ - public boolean containsPlayer(Player player) - { - return _playersInList.contains(player.getName()); - } + /** + * Is there a player entry in the hologram for Whitelist and Blacklist + */ + public boolean containsPlayer(Player player) + { + return _playersInList.contains(player.getName()); + } - /** - * Is there a player entry in the hologram for Whitelist and Blacklist - */ - public boolean containsPlayer(String player) - { - return _playersInList.contains(player); - } + /** + * Is there a player entry in the hologram for Whitelist and Blacklist + */ + public boolean containsPlayer(String player) + { + return _playersInList.contains(player); + } - protected Packet getDestroyPacket(Player player) - { - if (_destroyPackets) - { - makeDestroyPacket(); - _destroyPackets = false; - } - return UtilPlayer.is1_8(player) ? _destroy1_8 : _destroy1_7; - } + protected Packet getDestroyPacket(Player player) + { + if (_makeDestroyPackets) + { + makeDestroyPacket(); + _makeDestroyPackets = false; + } - public Entity getEntityFollowing() - { - return _followEntity; - } + return UtilPlayer.is1_8(player) ? _destroy1_8 : _destroy1_7; + } - /** - * Get who can see the hologram - * - * @Whitelist = Only people added can see the hologram - * @Blacklist = Anyone but people added can see the hologram - */ - public HologramTarget getHologramTarget() - { - return _target; - } + public Entity getEntityFollowing() + { + return _followEntity; + } - /** - * Get the hologram location - */ - public Location getLocation() - { - return _location.clone(); - } + /** + * Get who can see the hologram + * + * @Whitelist = Only people added can see the hologram + * @Blacklist = Anyone but people added can see the hologram + */ + public HologramTarget getHologramTarget() + { + return _target; + } - protected ArrayList getNearbyPlayers() - { - ArrayList nearbyPlayers = new ArrayList(); - for (Player player : getLocation().getWorld().getPlayers()) - { - if (isVisible(player)) - { - nearbyPlayers.add(player); - } - } - return nearbyPlayers; - } + /** + * Get the hologram location + */ + public Location getLocation() + { + return _location.clone(); + } - protected ArrayList getPlayersTracking() - { - return _playersTracking; - } + protected ArrayList getNearbyPlayers() + { + ArrayList nearbyPlayers = new ArrayList(); - protected Packet[] getSpawnPackets(Player player) - { - if (_makePackets) - { - makeSpawnPackets(); - _makePackets = false; - } - return UtilPlayer.is1_8(player) ? _packets1_8 : _packets1_7; - } + for (Player player : getLocation().getWorld().getPlayers()) + { + if (isVisible(player)) + { + nearbyPlayers.add(player); + } + } + return nearbyPlayers; + } - /** - * Get the text in the hologram - */ - public String[] getText() - { - // We reverse it again as the hologram would otherwise display the text from the bottom row to the top row - String[] reversed = new String[_text.length]; - for (int i = 0; i < reversed.length; i++) - { - reversed[i] = _text[reversed.length - (i + 1)]; - } - return reversed; - } + protected ArrayList getPlayersTracking() + { + return _playersTracking; + } - /** - * Get the view distance the hologram is viewable from. Default is 70 - */ - public int getViewDistance() - { - return _viewDistance; - } + protected Packet[] getSpawnPackets(Player player) + { + if (_makeSpawnPackets) + { + makeSpawnPackets(); + _makeSpawnPackets = false; + } - /** - * Is the hologram holograming? - */ - public boolean isInUse() - { - return _lastMovement != null; - } + return UtilPlayer.is1_8(player) ? _packets1_8 : _packets1_7; + } - /** - * Does the hologram use the wither skull for 1.8 clients? - */ - public boolean isUsingWitherSkull() - { - return _isWitherSkull; - } + /** + * Get the text in the hologram + */ + public String[] getText() + { + // We reverse it again as the hologram would otherwise display the text from the bottom row to the top row + String[] reversed = new String[_hologramText.length]; - public boolean isVisible(Player player) - { - if (getLocation().getWorld() == player.getWorld()) - { - if ((getHologramTarget() == HologramTarget.WHITELIST) == containsPlayer(player)) - { - if (getLocation().distance(player.getLocation()) < getViewDistance()) - { - return true; - } - } - } - return false; - } + for (int i = 0; i < reversed.length; i++) + { + reversed[i] = _hologramText[reversed.length - (i + 1)]; + } - private void makeDestroyPacket() - { - int[] entityIds1_7 = new int[_entityIds.size() * 2]; - int[] entityIds1_8 = new int[_entityIds.size()]; - for (int i = 0; i < _entityIds.size(); i++) - { - Entry entry = _entityIds.get(i); - entityIds1_7[i * 2] = entry.getKey(); - entityIds1_7[(i * 2) + 1] = entry.getValue(); - entityIds1_8[i] = entry.getKey(); - } - _destroy1_7 = new PacketPlayOutEntityDestroy(entityIds1_7); - _destroy1_8 = new PacketPlayOutEntityDestroy(entityIds1_8); - } + return reversed; + } - private void makeSpawnPackets() - { - _packets1_7 = new Packet[_text.length * 3]; - _packets1_8 = new Packet[_text.length * (isUsingWitherSkull() ? 2 : 1)]; - if (_entityIds.size() < _text.length) - { - _destroyPackets = true; - for (int i = _entityIds.size(); i < _text.length; i++) - { - _entityIds.add(new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId())); - } - } - else - { - _destroyPackets = true; - while (_entityIds.size() > _text.length) - { - _entityIds.remove(_text.length); - } - } - for (int textRow = 0; textRow < _text.length; textRow++) - { - Entry entityIds = this._entityIds.get(textRow); - Packet[] packets1_7 = makeSpawnPackets1_7(textRow, entityIds.getKey(), entityIds.getValue(), _text[textRow]); - for (int i = 0; i < packets1_7.length; i++) - { - _packets1_7[(textRow * 3) + i] = packets1_7[i]; - } + /** + * Get the view distance the hologram is viewable from. Default is 70 + */ + public int getViewDistance() + { + return _viewDistance; + } - Packet[] packets1_8 = makeSpawnPackets1_8(textRow, entityIds.getKey(), _text[textRow]); - for (int i = 0; i < packets1_8.length; i++) - { - _packets1_8[(textRow * (isUsingWitherSkull() ? 2 : 1)) + i] = packets1_8[i]; - } - } - } + /** + * Is the hologram holograming? + */ + public boolean isInUse() + { + return _lastMovement != null; + } - private Packet[] makeSpawnPackets1_7(int height, int witherId, int horseId, String horseName) - { - // Spawn wither skull - PacketPlayOutSpawnEntity spawnWitherSkull = new PacketPlayOutSpawnEntity(); - spawnWitherSkull.a = witherId; - spawnWitherSkull.b = (int) (getLocation().getX() * 32); - spawnWitherSkull.c = (int) ((getLocation().getY() + 54.6 + ((double) height * 0.285D)) * 32); - spawnWitherSkull.d = (int) (getLocation().getZ() * 32); - spawnWitherSkull.j = 66; - // Spawn horse - PacketPlayOutSpawnEntityLiving spawnHorse = new PacketPlayOutSpawnEntityLiving(); - spawnHorse.a = horseId; - spawnHorse.b = 100; - spawnHorse.c = (int) (getLocation().getX() * 32); - spawnHorse.d = (int) ((getLocation().getY() + 54.83 + ((double) height * 0.285D) + 0.23D) * 32); - spawnHorse.e = (int) (getLocation().getZ() * 32); - // Setup datawatcher - DataWatcher watcher = new DataWatcher(null); - watcher.a(0, (byte) 0); - watcher.a(1, (short) 300); - watcher.a(10, horseName); - watcher.a(11, (byte) 1); - watcher.a(12, -1700000); - spawnHorse.l = watcher; - // Make horse ride wither - PacketPlayOutAttachEntity attachEntity = new PacketPlayOutAttachEntity(); - attachEntity.b = horseId; - attachEntity.c = witherId; - return new Packet[] - { - spawnWitherSkull, spawnHorse, attachEntity - }; - } + public boolean isRemoveOnEntityDeath() + { + return _removeEntityDeath; + } - private Packet[] makeSpawnPackets1_8(int textRow, int entityId, String lineOfText) - { - if (this.isUsingWitherSkull()) - { - PacketPlayOutSpawnEntity spawnPacket = new PacketPlayOutSpawnEntity(); - spawnPacket.a = entityId; - spawnPacket.b = (int) (getLocation().getX() * 32); - spawnPacket.c = (int) ((getLocation().getY() + -0.55 + ((double) textRow * 0.285)) * 32); - spawnPacket.d = (int) (getLocation().getZ() * 32); - spawnPacket.j = 66; - // Setup datawatcher for wither skull - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(); - metadataPacket.a = entityId; - DataWatcher watcher = new DataWatcher(null); - watcher.a(0, (byte) 0); - watcher.a(2, lineOfText); - watcher.a(3, (byte) 1); - metadataPacket.b = watcher.c(); - return new Packet[] - { - spawnPacket, metadataPacket - }; - } - else - { - PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(); - packet.a = entityId; - packet.b = 30; - packet.c = (int) (getLocation().getX() * 32); - packet.d = (int) ((getLocation().getY() + -2.1 + ((double) textRow * 0.285)) * 32); - packet.e = (int) (getLocation().getZ() * 32); - // Setup datawatcher for armor stand - DataWatcher watcher = new DataWatcher(null); - watcher.a(0, (byte) 32); - watcher.a(2, lineOfText); - watcher.a(3, (byte) 1); - // watcher.a(10, (byte) 10); TODO Uncomment after a new MC version is released (1.8.2?) - // It uses the marker value which mojang indicates will be usable to hide the bounding box. - // Currently it hides the bounding box and the entity itself.. - packet.l = watcher; - return new Packet[] - { - packet - }; - } - } + public boolean isVisible(Player player) + { + if (getLocation().getWorld() == player.getWorld()) + { + if ((getHologramTarget() == HologramTarget.WHITELIST) == containsPlayer(player)) + { + if (getLocation().distance(player.getLocation()) < getViewDistance()) + { + return true; + } + } + } - /** - * Removes the player from the Hologram so they are no longer effected by Whitelist or Blacklist - */ - public Hologram removePlayer(Player player) - { - return addPlayer(player.getName()); - } + return false; + } - /** - * Removes the player from the Hologram so they are no longer effected by Whitelist or Blacklist - */ - public Hologram removePlayer(String player) - { - _playersInList.remove(player); - return this; - } + private void makeDestroyPacket() + { + int[] entityIds1_7 = new int[_entityIds.size() * 2]; + int[] entityIds1_8 = new int[_entityIds.size()]; - /** - * If the entity moves, the hologram will update its position to appear relative to the movement. - * - * @Please note the hologram updates every tick. - */ - public Hologram setFollowEntity(Entity entityToFollow) - { - _followEntity = entityToFollow; - relativeToEntity = entityToFollow == null ? null : this._location.clone().subtract(entityToFollow.getLocation()) - .toVector(); - return this; - } + for (int i = 0; i < _entityIds.size(); i++) + { + Entry entry = _entityIds.get(i); - /** - * Set who can see the hologram - * - * @Whitelist = Only people added can see the hologram - * @Blacklist = Anyone but people added can see the hologram - */ - public Hologram setHologramTarget(HologramTarget newTarget) - { - this._target = newTarget; - return this; - } + entityIds1_7[i * 2] = entry.getKey(); + entityIds1_7[(i * 2) + 1] = entry.getValue(); - /** - * Sets the hologram to appear at this location - */ - public Hologram setLocation(Location newLocation) - { - _makePackets = true; - Location oldLocation = getLocation(); - _location = newLocation.clone(); - if (getEntityFollowing() != null) - { - relativeToEntity = _location.clone().subtract(getEntityFollowing().getLocation()).toVector(); - } - if (isInUse()) - { - ArrayList canSee = getNearbyPlayers(); - Iterator itel = _playersTracking.iterator(); - while (itel.hasNext()) - { - Player player = itel.next(); - if (!canSee.contains(player)) - { - itel.remove(); - if (player.getWorld() == getLocation().getWorld()) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); - } - } - } - itel = canSee.iterator(); - while (itel.hasNext()) - { - Player player = itel.next(); - if (!_playersTracking.contains(player)) - { - _playersTracking.add(player); - itel.remove(); - for (Packet packet : getSpawnPackets(player)) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - } - } - if (!canSee.isEmpty()) - { - _lastMovement.add(new Vector(newLocation.getX() - oldLocation.getX(), newLocation.getY() - oldLocation.getY(), - newLocation.getZ() - oldLocation.getZ())); - int x = (int) Math.floor(32 * _lastMovement.getX()); - int y = (int) Math.floor(32 * _lastMovement.getY()); - int z = (int) Math.floor(32 * _lastMovement.getZ()); - Packet[] packets1_7 = new Packet[_text.length]; - Packet[] packets1_8 = new Packet[_text.length]; - int i = 0; - if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127) - { - _lastMovement.subtract(new Vector(x / 32D, y / 32D, z / 32D)); - for (Entry entityId : this._entityIds) - { - PacketPlayOutRelEntityMove relMove = new PacketPlayOutRelEntityMove(); - relMove.a = entityId.getKey(); - relMove.b = (byte) x; - relMove.c = (byte) y; - relMove.d = (byte) z; - packets1_7[i] = relMove; - packets1_8[i] = relMove; - i++; - } - } - else - { - x = (int) Math.floor(32 * newLocation.getX()); - z = (int) Math.floor(32 * newLocation.getZ()); - _lastMovement = new Vector(newLocation.getX() - (x / 32D), 0, newLocation.getZ() - (z / 32D)); - for (Entry entityId : this._entityIds) - { - for (int b = 0; b < 2; b++) - { - PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(); - teleportPacket.a = entityId.getKey(); - teleportPacket.b = x; - teleportPacket.c = (int) Math.floor((oldLocation.getY() - + (b == 0 ? 54.6 : isUsingWitherSkull() ? -0.55 : -2.1) + ((double) i * 0.285)) * 32); - teleportPacket.d = z; - if (b == 0) - { - packets1_7[i] = teleportPacket; - } - else - { - packets1_8[i] = teleportPacket; - } - } - i++; - } - } - for (Player player : canSee) - { - for (Packet packet : UtilPlayer.is1_8(player) ? packets1_8 : packets1_7) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - } - } - } - return this; - } + entityIds1_8[i] = entry.getKey(); + } - /** - * Set the hologram text - */ - public Hologram setText(String... newText) - { - String[] reversed = new String[newText.length]; - for (int i = 0; i < reversed.length; i++) - { - reversed[i] = newText[reversed.length - (i + 1)]; - } - if (reversed.equals(_text)) - return this; - _makePackets = true; - if (isInUse()) - { - ArrayList packets1_7 = new ArrayList(); - int[] destroy1_7 = new int[0]; - int[] destroy1_8 = new int[0]; - ArrayList packets1_8 = new ArrayList(); - if (_text.length != reversed.length) - { - _destroyPackets = true; - } - for (int textRow = 0; textRow < Math.max(_text.length, reversed.length); textRow++) - { - // You can safely assume that _entityIds here is containing _text.length amount as this code is inside isInUse - if (textRow >= _text.length) - { - // Add entity id and send spawn packets - // You add a entity id because the new hologram needs - Entry entry = new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId()); - _entityIds.add(entry); - packets1_7.addAll(Arrays.asList(makeSpawnPackets1_7(textRow, entry.getKey(), entry.getValue(), - reversed[textRow]))); - packets1_8.addAll(Arrays.asList(makeSpawnPackets1_8(textRow, entry.getKey(), reversed[textRow]))); - } - else if (textRow >= reversed.length) - { - // Remove entity id and send destroy packets - Entry entry = _entityIds.remove(reversed.length); - destroy1_7 = Arrays.copyOf(destroy1_7, destroy1_7.length + 2); - destroy1_7[destroy1_7.length - 2] = entry.getKey(); - destroy1_7[destroy1_7.length - 1] = entry.getValue(); - destroy1_8 = Arrays.copyOf(destroy1_8, destroy1_8.length + 1); - destroy1_8[destroy1_8.length - 1] = entry.getKey(); - } - else if (!reversed[textRow].equals(_text[textRow])) - { - // Send update metadata packets - Entry entry = _entityIds.get(textRow); - PacketPlayOutEntityMetadata metadata1_7 = new PacketPlayOutEntityMetadata(); - metadata1_7.a = entry.getValue(); - DataWatcher watcher1_7 = new DataWatcher(null); - watcher1_7.a(0, (byte) 0); - watcher1_7.a(1, (short) 300); - watcher1_7.a(10, reversed[textRow]); - watcher1_7.a(11, (byte) 1); - watcher1_7.a(12, -1700000); - metadata1_7.b = watcher1_7.c(); - packets1_7.add(metadata1_7); + _destroy1_7 = new PacketPlayOutEntityDestroy(entityIds1_7); + _destroy1_8 = new PacketPlayOutEntityDestroy(entityIds1_8); + } - PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata(); - metadata1_8.a = entry.getKey(); - DataWatcher watcher1_8 = new DataWatcher(null); - watcher1_8.a(0, (byte) 0); - watcher1_8.a(2, reversed[textRow]); - watcher1_8.a(3, (byte) 1); - metadata1_8.b = watcher1_8.c(); - packets1_8.add(metadata1_8); - } - } - if (destroy1_7.length > 0) - { - packets1_7.add(new PacketPlayOutEntityDestroy(destroy1_7)); - } - if (destroy1_8.length > 0) - { - packets1_8.add(new PacketPlayOutEntityDestroy(destroy1_8)); - } - for (Player player : _playersTracking) - { - for (Packet packet : UtilPlayer.is1_8(player) ? packets1_8 : packets1_7) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - } - } - _text = reversed; - return this; - } + private void makeSpawnPackets() + { + _packets1_7 = new Packet[_hologramText.length * 3]; + _packets1_8 = new Packet[_hologramText.length * 1]; - /** - * Tells the hologram to use the wither skull instead of armorstand for 1.8 clients - */ - public Hologram setUsesWitherSkull() - { - _isWitherSkull = true; - return this; - } + if (_entityIds.size() < _hologramText.length) + { + _makeDestroyPackets = true; - /** - * Set the distance the hologram is viewable from. Default is 70 - */ - public Hologram setViewDistance(int newDistance) - { - this._viewDistance = newDistance; - return setLocation(getLocation()); - } + for (int i = _entityIds.size(); i < _hologramText.length; i++) + { + _entityIds.add(new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId())); + } + } + else + { + _makeDestroyPackets = true; - /** - * Start the hologram - */ - public Hologram start() - { - if (!isInUse()) - { - _hologramManager.addHologram(this); - _playersTracking.addAll(getNearbyPlayers()); - for (Player player : _playersTracking) - { - for (Packet packet : getSpawnPackets(player)) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - } - _lastMovement = new Vector(); - } - return this; - } + while (_entityIds.size() > _hologramText.length) + { + _entityIds.remove(_hologramText.length); + } + } + for (int textRow = 0; textRow < _hologramText.length; textRow++) + { + Entry entityIds = this._entityIds.get(textRow); - /** - * Stop the hologram - */ - public Hologram stop() - { - if (isInUse()) - { - _hologramManager.removeHologram(this); - for (Player player : _playersTracking) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); - } - _playersTracking.clear(); - _lastMovement = null; - } - return this; - } + Packet[] packets1_7 = makeSpawnPackets1_7(textRow, entityIds.getKey(), entityIds.getValue(), _hologramText[textRow]); + + for (int i = 0; i < packets1_7.length; i++) + { + _packets1_7[(textRow * 3) + i] = packets1_7[i]; + } + + Packet[] packets1_8 = makeSpawnPackets1_8(textRow, entityIds.getKey(), _hologramText[textRow]); + + for (int i = 0; i < packets1_8.length; i++) + { + _packets1_8[textRow + i] = packets1_8[i]; + } + } + } + + private Packet[] makeSpawnPackets1_7(int height, int witherId, int horseId, String horseName) + { + // Spawn wither skull + PacketPlayOutSpawnEntity spawnWitherSkull = new PacketPlayOutSpawnEntity(); + + spawnWitherSkull.a = witherId; + spawnWitherSkull.b = (int) (getLocation().getX() * 32); + spawnWitherSkull.c = (int) ((getLocation().getY() + 54.6 + ((double) height * 0.285D)) * 32); + spawnWitherSkull.d = (int) (getLocation().getZ() * 32); + spawnWitherSkull.j = 66; + + // Spawn horse + PacketPlayOutSpawnEntityLiving spawnHorse = new PacketPlayOutSpawnEntityLiving(); + DataWatcher watcher = new DataWatcher(null); + + spawnHorse.a = horseId; + spawnHorse.b = 100; + spawnHorse.c = (int) (getLocation().getX() * 32); + spawnHorse.d = (int) ((getLocation().getY() + 54.83 + ((double) height * 0.285D) + 0.23D) * 32); + spawnHorse.e = (int) (getLocation().getZ() * 32); + spawnHorse.l = watcher; + + // Setup datawatcher + watcher.a(0, (byte) 0); + watcher.a(1, (short) 300); + watcher.a(10, horseName); + watcher.a(11, (byte) 1); + watcher.a(12, -1700000); + + // Make horse ride wither + PacketPlayOutAttachEntity attachEntity = new PacketPlayOutAttachEntity(); + + attachEntity.b = horseId; + attachEntity.c = witherId; + + return new Packet[] + { + spawnWitherSkull, spawnHorse, attachEntity + }; + } + + private Packet[] makeSpawnPackets1_8(int textRow, int entityId, String lineOfText) + { + PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(); + DataWatcher watcher = new DataWatcher(null); + + packet.a = entityId; + packet.b = 30; + packet.c = (int) (getLocation().getX() * 32); + packet.d = (int) ((getLocation().getY() + -2.1 + ((double) textRow * 0.285)) * 32); + packet.e = (int) (getLocation().getZ() * 32); + packet.l = watcher; + + // Setup datawatcher for armor stand + watcher.a(0, (byte) 32); + watcher.a(2, lineOfText); + watcher.a(3, (byte) 1); + // watcher.a(10, (byte) 16); // TODO Uncomment after we can enforce 1.8.3 + // Also correct hologram positioning + + return new Packet[] + { + packet + }; + } + + /** + * Removes the player from the Hologram so they are no longer effected by Whitelist or Blacklist + */ + public Hologram removePlayer(Player player) + { + return addPlayer(player.getName()); + } + + /** + * Removes the player from the Hologram so they are no longer effected by Whitelist or Blacklist + */ + public Hologram removePlayer(String player) + { + _playersInList.remove(player); + return this; + } + + /** + * If the entity moves, the hologram will update its position to appear relative to the movement. + * + * @Please note the hologram updates every tick. + */ + public Hologram setFollowEntity(Entity entityToFollow) + { + _followEntity = entityToFollow; + relativeToEntity = entityToFollow == null ? null : this._location.clone().subtract(entityToFollow.getLocation()) + .toVector(); + + return this; + } + + /** + * Set who can see the hologram + * + * @Whitelist = Only people added can see the hologram + * @Blacklist = Anyone but people added can see the hologram + */ + public Hologram setHologramTarget(HologramTarget newTarget) + { + this._target = newTarget; + return this; + } + + /** + * Sets the hologram to appear at this location + */ + public Hologram setLocation(Location newLocation) + { + _makeSpawnPackets = true; + + Location oldLocation = getLocation(); + _location = newLocation.clone(); + + if (getEntityFollowing() != null) + { + relativeToEntity = _location.clone().subtract(getEntityFollowing().getLocation()).toVector(); + } + if (isInUse()) + { + ArrayList canSee = getNearbyPlayers(); + Iterator itel = _playersTracking.iterator(); + + while (itel.hasNext()) + { + Player player = itel.next(); + if (!canSee.contains(player)) + { + itel.remove(); + + if (player.getWorld() == getLocation().getWorld()) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); + } + } + } + itel = canSee.iterator(); + while (itel.hasNext()) + { + Player player = itel.next(); + + if (!_playersTracking.contains(player)) + { + _playersTracking.add(player); + itel.remove(); + + for (Packet packet : getSpawnPackets(player)) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + if (!canSee.isEmpty()) + { + _lastMovement.add(new Vector(newLocation.getX() - oldLocation.getX(), newLocation.getY() - oldLocation.getY(), + newLocation.getZ() - oldLocation.getZ())); + + int x = (int) Math.floor(32 * _lastMovement.getX()); + int y = (int) Math.floor(32 * _lastMovement.getY()); + int z = (int) Math.floor(32 * _lastMovement.getZ()); + + Packet[] packets1_7 = new Packet[_hologramText.length]; + Packet[] packets1_8 = new Packet[_hologramText.length]; + + int i = 0; + + if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127) + { + _lastMovement.subtract(new Vector(x / 32D, y / 32D, z / 32D)); + for (Entry entityId : this._entityIds) + { + PacketPlayOutRelEntityMove relMove = new PacketPlayOutRelEntityMove(); + + relMove.a = entityId.getKey(); + relMove.b = (byte) x; + relMove.c = (byte) y; + relMove.d = (byte) z; + + packets1_7[i] = relMove; + packets1_8[i] = relMove; + i++; + } + } + else + { + x = (int) Math.floor(32 * newLocation.getX()); + z = (int) Math.floor(32 * newLocation.getZ()); + + _lastMovement = new Vector(newLocation.getX() - (x / 32D), 0, newLocation.getZ() - (z / 32D)); + + for (Entry entityId : this._entityIds) + { + for (int b = 0; b < 2; b++) + { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(); + teleportPacket.a = entityId.getKey(); + teleportPacket.b = x; + teleportPacket.c = (int) Math + .floor((oldLocation.getY() + (b == 0 ? 54.6 : -2.1) + ((double) i * 0.285)) * 32); + teleportPacket.d = z; + + if (b == 0) + { + packets1_7[i] = teleportPacket; + } + else + { + packets1_8[i] = teleportPacket; + } + } + + i++; + } + } + + for (Player player : canSee) + { + for (Packet packet : UtilPlayer.is1_8(player) ? packets1_8 : packets1_7) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + } + return this; + } + + public Hologram setRemoveOnEntityDeath() + { + _removeEntityDeath = true; + return this; + } + + /** + * Set the hologram text + */ + public Hologram setText(String... newLines) + { + String[] newText = new String[newLines.length]; + + for (int i = 0; i < newText.length; i++) + { + newText[i] = newLines[newText.length - (i + 1)]; + } + + if (newText.equals(_hologramText)) + return this; + + _makeSpawnPackets = true; + + if (isInUse()) + { + int[] destroy1_7 = new int[0]; + int[] destroy1_8 = new int[0]; + + ArrayList packets1_7 = new ArrayList(); + ArrayList packets1_8 = new ArrayList(); + + if (_hologramText.length != newText.length) + { + _makeDestroyPackets = true; + } + + for (int i = 0; i < Math.max(_hologramText.length, newText.length); i++) + { + // If more lines than previously + if (i >= _hologramText.length) + { + // Add entity id and send spawn packets + // You add a entity id because the new hologram needs + Entry entry = new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId()); + _entityIds.add(entry); + + packets1_7.addAll(Arrays.asList(makeSpawnPackets1_7(i, entry.getKey(), entry.getValue(), newText[i]))); + + packets1_8.addAll(Arrays.asList(makeSpawnPackets1_8(i, entry.getKey(), newText[i]))); + } + // If less lines than previously + else if (i >= newText.length) + { + // Remove entity id and send destroy packets + Entry entry = _entityIds.remove(newText.length); + + destroy1_7 = Arrays.copyOf(destroy1_7, destroy1_7.length + 2); + + destroy1_7[destroy1_7.length - 2] = entry.getKey(); + destroy1_7[destroy1_7.length - 1] = entry.getValue(); + + destroy1_8 = Arrays.copyOf(destroy1_8, destroy1_8.length + 1); + destroy1_8[destroy1_8.length - 1] = entry.getKey(); + } + else if (!newText[i].equals(_hologramText[i])) + { + // Send update metadata packets + Entry entry = _entityIds.get(i); + PacketPlayOutEntityMetadata metadata1_7 = new PacketPlayOutEntityMetadata(); + + metadata1_7.a = entry.getValue(); + + DataWatcher watcher1_7 = new DataWatcher(null); + + watcher1_7.a(0, (byte) 0); + watcher1_7.a(1, (short) 300); + watcher1_7.a(10, newText[i]); + watcher1_7.a(11, (byte) 1); + watcher1_7.a(12, -1700000); + + metadata1_7.b = watcher1_7.c(); + + packets1_7.add(metadata1_7); + + PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata(); + + metadata1_8.a = entry.getKey(); + + DataWatcher watcher1_8 = new DataWatcher(null); + + watcher1_8.a(0, (byte) 32); + watcher1_8.a(2, newText[i]); + watcher1_8.a(3, (byte) 1); + // watcher1_8.a(10, (byte) 16);// TODO Uncomment after we can enforce 1.8.3 + // Also correct hologram positioning + metadata1_8.b = watcher1_8.c(); + + packets1_8.add(metadata1_8); + } + } + + if (destroy1_7.length > 0) + { + packets1_7.add(new PacketPlayOutEntityDestroy(destroy1_7)); + } + + if (destroy1_8.length > 0) + { + packets1_8.add(new PacketPlayOutEntityDestroy(destroy1_8)); + } + + for (Player player : _playersTracking) + { + for (Packet packet : UtilPlayer.is1_8(player) ? packets1_8 : packets1_7) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + + _hologramText = newText; + + return this; + } + + /** + * Set the distance the hologram is viewable from. Default is 70 + */ + public Hologram setViewDistance(int newDistance) + { + this._viewDistance = newDistance; + return setLocation(getLocation()); + } + + /** + * Start the hologram + */ + public Hologram start() + { + if (!isInUse()) + { + _hologramManager.addHologram(this); + _playersTracking.addAll(getNearbyPlayers()); + + for (Player player : _playersTracking) + { + for (Packet packet : getSpawnPackets(player)) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + + _lastMovement = new Vector(); + } + return this; + } + + /** + * Stop the hologram + */ + public Hologram stop() + { + if (isInUse()) + { + _hologramManager.removeHologram(this); + + for (Player player : _playersTracking) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); + } + + _playersTracking.clear(); + _lastMovement = null; + } + return this; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java index 9c045890f..50dfd8594 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java @@ -315,8 +315,7 @@ class TeamBomb implements Comparable public void setupHologram() { - _hologram = new Hologram(this._game.getArcadeManager().getHologramManager(), getBlockLocation().clone().add(0, 1, 0)) - .setUsesWitherSkull(); + _hologram = new Hologram(this._game.getArcadeManager().getHologramManager(), getBlockLocation().clone().add(0, 1, 0)); _hologram.setText(getTeam().GetColor() + C.Bold + getTeam().GetName() + " Team's Bomb"); _hologram.start(); }