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 30f07f341..1d050b58e 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,6 +1,5 @@ package nautilus.game.arcade.game.games.survivalgames; -import java.lang.reflect.Field; import java.util.*; import java.util.Map.Entry; @@ -8,16 +7,8 @@ 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; @@ -36,27 +27,17 @@ 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.FireworkMeta; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; -import org.bukkit.scoreboard.TeamNameTagVisibility; +import org.bukkit.inventory.meta.ItemMeta; 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; @@ -73,11 +54,7 @@ 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.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.itemstack.ItemStackFactory; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -95,126 +72,96 @@ 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 -{ - // 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(); +{ + private HashSet _openedChest = new HashSet(); + private ArrayList _baseChestLoot = new ArrayList(); + private ArrayList _superChestLoot = new ArrayList(); - private HashMap> _hiddenNames = new HashMap>(); - private HashSet _lootedBlocks = new HashSet(); - - // Misc + //Misc private HashMap _tntMap = new HashMap(); private HashSet _placedBlocks = new HashSet(); private Location _spawn; - // Creep + //Creep private int _maxSpreadRate = 120; - private ArrayList _frostLocations = new ArrayList(); + private ArrayList _redLocations = new ArrayList(); private int _spreadType = 0; private String _spreadName = ""; private boolean _ignoreLiquids = true; private ArrayList> _spreadTypeBlocks; - private HashMap _frostOutTime = new HashMap(); + private HashMap _redOutTime = new HashMap(); - private HashMap>> _frostMap = new HashMap>>(); - private HashMap> _frostChunks = new HashMap>(); + private HashMap>> _redMap = new HashMap>>(); + private HashMap> _redChunks = new HashMap>(); - // Supply Drop + //Supply Drop private ArrayList _supplyLocations = new ArrayList(); private Location _supplyCurrent = null; private Location _supplyEffect = null; - private ArrayList _supplyCrates = new ArrayList(); - private HashSet _landedCrates = new HashSet(); + private ArrayList _supplyChests = new ArrayList(); - // Deathmatch + //Deathmatch private boolean _deathmatchCountdown = false; private boolean _deathmatchLive = false; private long _deathmatchTime = 0; - private int _chestRefillTime = 60 * 7; - - // Debug + //Debug private long totalTime = 0; - 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) + 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 KitArcher(manager), + new KitBrawler(manager), - new KitBrawler(manager), + new KitAssassin(manager), + new KitBeastmaster(manager), + new KitBomber(manager), + new KitNecromancer(manager), + + new KitHorseman(manager) + }, - new KitAssassin(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 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); + //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; @@ -224,51 +171,39 @@ public class SurvivalGames extends SoloGame this.ItemDrop = true; this.ItemPickup = true; - + this.InventoryClick = true; this.InventoryOpenBlock = true; this.InventoryOpenChest = true; - // Blocks - this.BlockBreakAllow.add(46); // TNT + this.CompassEnabled = false; //XXX + + //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 - 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); + //SPREAD + _spreadType = 1;//UtilMath.r(3); _spreadTypeBlocks = new ArrayList>(); @@ -300,179 +235,14 @@ 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"); - 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)); + registerStatTrackers( + new WinWithoutWearingArmorStatTracker(this), + new KillsWithinTimeLimitStatTracker(this, 3, 60, "Bloodlust"), + new FirstSupplyDropOpenStatTracker(this), + new SimultaneousSkeletonStatTracker(this, 5) + ); } @Override @@ -482,14 +252,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))); - setupChestsEnchantingCrafting(); + CreateChestCraftEnchant(); _supplyLocations = WorldData.GetDataLocs("WHITE"); for (Location loc : _supplyLocations) @@ -502,35 +272,35 @@ public class SurvivalGames extends SoloGame } } - private void setupChestsEnchantingCrafting() + private void CreateChestCraftEnchant() { 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++; @@ -566,174 +336,194 @@ 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(Material.CHEST.getId(), (byte) UtilMath.r(4), true); + block.setTypeIdAndData(54, (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 - public void OpenChest(PlayerInteractEvent event) + private void OpenChest(PlayerInteractEvent event) { if (event.isCancelled()) return; - Block block = event.getClickedBlock(); - - if (block == null) + if (event.getClickedBlock() == null) return; - if (!IsLive()) + if (!(event.getClickedBlock().getState() instanceof Chest)) return; - if (_lootedBlocks.contains(block.getLocation())) + if (GetState() != GameState.Live) return; - BlockState state = block.getState(); + if (_openedChest.contains(event.getClickedBlock().getLocation())) + return; - if (state instanceof DoubleChest) + _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) { - DoubleChest doubleChest = (DoubleChest) state; - - fillChest(event.getPlayer(), ((Chest) doubleChest.getLeftSide()).getBlock()); - fillChest(event.getPlayer(), ((Chest) doubleChest.getRightSide()).getBlock()); + count += UtilMath.r(3); } - else if (state instanceof Chest) + + if (_supplyChests.contains(event.getClickedBlock())) { - fillChest(event.getPlayer(), block); + count = 2; + if (Math.random() > 0.75) count++; + if (Math.random() > 0.95) count++; } - else if (state instanceof Furnace) + + for (int i = 0; i < count; i++) + chest.getBlockInventory().setItem(UtilMath.r(27), GetChestItem(_supplyChests.contains(event.getClickedBlock()))); + + if (_supplyChests.contains(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()); - } + Bukkit.getPluginManager().callEvent(new SupplyChestOpenEvent(event.getPlayer(), event.getClickedBlock())); } + + _supplyChests.remove(event.getClickedBlock()); } private ItemStack GetChestItem(boolean superChest) { - if (superChest) - return _superLoot.getLoot(); - - return _baseLoot.getLoot(); - } - - private String buildTime() - { - String s = ""; - - for (char c : ("" + System.nanoTime()).toCharArray()) + if (_baseChestLoot.isEmpty()) { - s += "§" + c; + //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) + "%"); + */ } - return s; - } + 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)); - private ItemStack buildCompass(int uses) - { - ItemBuilder item = new ItemBuilder(Material.COMPASS); - item.setTitle(C.cWhite + "Player Tracker" + buildTime()); + 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)); - 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!"); + 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)); + } - return item.build(); + + 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); } @EventHandler @@ -742,191 +532,15 @@ 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) { @@ -935,29 +549,10 @@ 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; @@ -966,54 +561,52 @@ public class SurvivalGames extends SoloGame } @EventHandler - // TODO - public void frostBorderStart(GameStateChangeEvent event) + public void RedBorderStart(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) - _frostLocations.add(block.getLocation()); + _redLocations.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) - _frostLocations.add(block.getLocation()); + _redLocations.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) - _frostLocations.add(block.getLocation()); + _redLocations.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) - _frostLocations.add(block.getLocation()); + _redLocations.add(block.getLocation()); } } - public int frostMax() + public int RedMax() { return _maxSpreadRate;// + (24 - GetPlayers(true).size())*2; } @EventHandler - // TODO - public void frostUpdate(UpdateEvent event) + public void RedUpdate(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; @@ -1023,56 +616,56 @@ public class SurvivalGames extends SoloGame long time = System.currentTimeMillis(); - if (_frostLocations.isEmpty()) + if (_redLocations.isEmpty()) return; - int max = Math.max(5, Math.min(frostMax(), _frostLocations.size() / 100)); + int max = Math.max(5, Math.min(RedMax(), _redLocations.size()/100)); - for (int i = 0; i < max; i++) + 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 - _frostLocations.add(block.getLocation()); + //Apply + _redLocations.add(block.getLocation()); return true; } - public void frostChangeBlock(Location loc, int id, byte data) + public void RedChangeBlock(Location loc, int id, byte data) { if (!IsLive()) return; MapUtil.ChunkBlockChange(loc, id, data, false); - // Old Style + //Old Style /* if (true) { @@ -1212,22 +803,20 @@ 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 (!_frostChunks.containsKey(player)) - _frostChunks.put(player, new ArrayList()); + if (!_redChunks.containsKey(player)) + _redChunks.put(player, new ArrayList()); boolean added = false; - for (ChunkChange change : _frostChunks.get(player)) + for (ChunkChange change : _redChunks.get(player)) { if (change.Chunk.equals(loc.getChunk()))// && change.DirtyCount < 63) { @@ -1237,13 +826,12 @@ public class SurvivalGames extends SoloGame } } if (!added) - _frostChunks.get(player).add(new ChunkChange(loc, id, data)); + _redChunks.get(player).add(new ChunkChange(loc, id, data)); } } @EventHandler - // TODO - public void frostChunkUpdate(UpdateEvent event) + public void RedChunkUpdate(UpdateEvent event) { if (event.getType() != UpdateType.FAST) return; @@ -1251,49 +839,47 @@ public class SurvivalGames extends SoloGame if (!IsLive()) return; - for (Player player : _frostChunks.keySet()) + for (Player player : _redChunks.keySet()) { - // Remove Far Away - Iterator chunkIterator = _frostChunks.get(player).iterator(); + //Remove Far Away + Iterator chunkIterator = _redChunks.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 (_frostChunks.get(player).isEmpty()) + if (_redChunks.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 < _frostChunks.get(player).size(); i++) + for (int i=0 ; i<_redChunks.get(player).size() ; i++) { - ChunkChange change = _frostChunks.get(player).get(i); + ChunkChange change = _redChunks.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) { @@ -1305,79 +891,70 @@ public class SurvivalGames extends SoloGame if (bestId == -1) continue; - // Send MultiBlock or Chunk Update for Fittest Chunk - ChunkChange change = _frostChunks.get(player).remove(bestId); + //Send MultiBlock or Chunk Update for Fittest Chunk + ChunkChange change = _redChunks.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 isFrost(Block block) + public boolean IsRed(Block block) { - if (!_frostMap.containsKey(block.getX())) + if (!_redMap.containsKey(block.getX())) return false; - if (!_frostMap.get(block.getX()).containsKey(block.getY())) + if (!_redMap.get(block.getX()).containsKey(block.getY())) return false; - return _frostMap.get(block.getX()).get(block.getY()).contains(block.getZ()); + return _redMap.get(block.getX()).get(block.getY()).contains(block.getZ()); } - public void setFrost(Location loc) + public void SetRed(Location loc) { - // Save Red - if (!_frostMap.containsKey(loc.getBlockX())) - _frostMap.put(loc.getBlockX(), new HashMap>()); + //Save Red + if (!_redMap.containsKey(loc.getBlockX())) + _redMap.put(loc.getBlockX(), new HashMap>()); - if (!_frostMap.get(loc.getBlockX()).containsKey(loc.getBlockY())) - _frostMap.get(loc.getBlockX()).put(loc.getBlockY(), new HashSet()); + if (!_redMap.get(loc.getBlockX()).containsKey(loc.getBlockY())) + _redMap.get(loc.getBlockX()).put(loc.getBlockY(), new HashSet()); - _frostMap.get(loc.getBlockX()).get(loc.getBlockY()).add(loc.getBlockZ()); + _redMap.get(loc.getBlockX()).get(loc.getBlockY()).add(loc.getBlockZ()); - // Red + //Red if (_spreadType == 0) { - frostChangeBlock(loc, 159, (byte) 14); + RedChangeBlock(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) - 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); + 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); } - // Nether - else + //Nether + else { - 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); + 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); else { double r = Math.random(); - if (r > 0.1) - frostChangeBlock(loc, 87, (byte) 0); - else - frostChangeBlock(loc, 153, (byte) 0); - } + if (r > 0.1) RedChangeBlock(loc, 87, (byte)0); + else RedChangeBlock(loc, 153, (byte)0); + } } } @EventHandler - // TODO - public void frostAttack(UpdateEvent event) + public void RedAttack(UpdateEvent event) { if (event.getType() != UpdateType.FASTER) return; @@ -1388,12 +965,12 @@ public class SurvivalGames extends SoloGame for (Block block : UtilBlock.getInRadius(player.getLocation(), 5d).keySet()) { - if (!isFrost(block)) + if (!IsRed(block)) continue; near = true; - // Red + //Red if (_spreadType == 0) { if (block.getRelative(BlockFace.UP).getType() == Material.AIR) @@ -1403,26 +980,23 @@ 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) @@ -1442,7 +1016,7 @@ public class SurvivalGames extends SoloGame while (!UtilBlock.solid(block) && block.getY() > 0) block = block.getRelative(BlockFace.DOWN); - if (isFrost(block) || block.getY() == 0) + if (IsRed(block) || block.getY() == 0) near = true; } } @@ -1457,111 +1031,29 @@ public class SurvivalGames extends SoloGame { player.getWorld().playSound(player.getLocation(), Sound.AMBIENCE_RAIN, 0.5f, 0f); - if (!_frostOutTime.containsKey(player)) + if (!_redOutTime.containsKey(player)) { - _frostOutTime.put(player, System.currentTimeMillis()); - } + _redOutTime.put(player, System.currentTimeMillis()); + } else { - if (UtilTime.elapsed(_frostOutTime.get(player), 5000)) - { - Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.VOID, 1, false, true, false, - "Hunger Games", _spreadName); + if (UtilTime.elapsed(_redOutTime.get(player), 5000)) + { + Manager.GetDamage().NewDamageEvent(player, null, null, + DamageCause.VOID, 1, false, true, false, + "Hunger Games", _spreadName); } } } else { - _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); - } - } + _redOutTime.remove(player); } } } @EventHandler - 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) + public void RedDamage(CustomDamageEvent event) { if (event.GetProjectile() == null) return; @@ -1574,6 +1066,29 @@ 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) { @@ -1594,19 +1109,18 @@ public class SurvivalGames extends SoloGame _supplyCurrent = _supplyLocations.remove(UtilMath.r(_supplyLocations.size())); - // Remove Prior - _supplyCrates.remove(_supplyCurrent.getBlock().getRelative(BlockFace.UP)); + //Remove Prior + _supplyChests.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 @@ -1619,25 +1133,23 @@ 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); - _supplyCrates.add(_supplyCurrent.getBlock().getRelative(BlockFace.UP)); - _lootedBlocks.remove(_supplyCurrent); + _supplyChests.add(_supplyCurrent.getBlock().getRelative(BlockFace.UP)); + _openedChest.remove(_supplyCurrent); - // Reset + //Reset _supplyEffect = null; _supplyCurrent = null; } @@ -1645,29 +1157,6 @@ 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) { @@ -1677,10 +1166,10 @@ public class SurvivalGames extends SoloGame if (event.getType() != UpdateType.TICK) return; - if (_supplyCrates.isEmpty()) + if (_supplyChests.isEmpty()) return; - Iterator chestIterator = _supplyCrates.iterator(); + Iterator chestIterator = _supplyChests.iterator(); while (chestIterator.hasNext()) { @@ -1696,22 +1185,6 @@ 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) { @@ -1745,18 +1218,18 @@ public class SurvivalGames extends SoloGame long timeLeft = 60000 - (System.currentTimeMillis() - _deathmatchTime); if (timeLeft <= 0) - { + { _deathmatchLive = true; - GetTeamList().get(0).SpawnTeleport(false); + GetTeamList().get(0).SpawnTeleport(); - _frostLocations.clear(); + _redLocations.clear(); for (Block block : UtilBlock.getInRadius(_spawn, 52d).keySet()) - frostSpread(block); + RedSpread(block); _deathmatchTime = 10; - } + } } else { @@ -1813,9 +1286,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.")); @@ -1857,175 +1330,91 @@ public class SurvivalGames extends SoloGame } @EventHandler - public void chestTickEvent(UpdateEvent event) + public void CompassUpdate(UpdateEvent event) { - if (event.getType() != UpdateType.SLOW) + if (event.getType() != UpdateType.SEC) return; - Iterator> itel = _openedChests.entrySet().iterator(); - - while (itel.hasNext()) - { - Entry entry = itel.next(); - // TODO Test this is removed properly when unloaded chunks - // TODO Load chests status when chunk loads packets - try - { - int key = (entry.getKey().x + entry.getKey().y + entry.getKey().z) % 200; - - int ticks = (_ticksField.getInt(entry.getKey()) + key) % 200; - - System.out.print(ticks + " - " + entry.getKey().o); - - if (ticks == entry.getValue()) - { - 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(); - } - } - } - - @EventHandler - public void chestCloseEvent(InventoryCloseEvent event) - { - InventoryHolder holder = event.getInventory().getHolder(); - - 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(); - } - } - } - } - - @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) + //Night Time > Drop Target + if (WorldData.World.getTime() > 14000 && WorldData.World.getTime() < 23000 && _supplyCurrent != null) { - uses--; - - Player closest = null; - double cDist = 0; - - for (Player p : GetPlayers(true)) + for (Player player : GetPlayers(true)) { - if (p != player) - { - double dist = p.getLocation().distance(player.getLocation()); + player.setCompassTarget(_supplyCurrent); - if (dist > 10 && (closest == null || dist < cDist)) + 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 + "Supply Drop Location: " + C.cYellow + UtilMath.trim(1, UtilMath.offset(player.getLocation(), _supplyCurrent))); + stack.setItemMeta(itemMeta); + + player.getInventory().setItem(i, stack); + } + } + } + //Player Target + else + { + for (Player player : GetPlayers(true)) + { + Player target = null; + double bestDist = 0; + + for (Player other : Manager.GetGame().GetPlayers(true)) + { + if (other.equals(player)) + continue; + + if (other.isSneaking()) + continue; + + double dist = UtilMath.offset(player, other); + + if (target == null || dist < bestDist) { - cDist = dist; - closest = p; + 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); } } } - - 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 DisallowBrewingStand(PlayerInteractEvent event) + public void DisallowBrewFurnace(PlayerInteractEvent event) { if (event.getClickedBlock() == null) return; - if (event.getClickedBlock().getType() == Material.BREWING_STAND) - { + if (event.getClickedBlock().getType() == Material.BREWING_STAND || + event.getClickedBlock().getType() == Material.FURNACE || + event.getClickedBlock().getType() == Material.BURNING_FURNACE) event.setCancelled(true); - } } @EventHandler @@ -2058,7 +1447,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); @@ -2071,16 +1460,15 @@ 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); @@ -2095,53 +1483,64 @@ 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 - // TODO - public void BlockPlaceOnFrost(BlockPlaceEvent event) - { - if (isFrost(event.getBlockAgainst())) + public void BlockPlace(BlockPlaceEvent event) + { + if (IsRed(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()); - - 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); - } - } - } + 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); + } + } + } + @EventHandler public void BlockBreak(BlockBreakEvent event) { @@ -2176,102 +1575,18 @@ 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; - 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); + 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); if (event.GetLog().GetKiller() == null) return; @@ -2280,7 +1595,7 @@ public class SurvivalGames extends SoloGame if (killer == null) return; - if (killer.equals(player)) + if (killer.equals(event.GetEvent().getEntity())) return; killer.giveExpLevels(1); @@ -2299,12 +1614,11 @@ public class SurvivalGames extends SoloGame } @EventHandler - // TODO public void FixClean(PlayerQuitEvent event) { - _frostChunks.remove(event.getPlayer()); + _redChunks.remove(event.getPlayer()); } - + @Override @EventHandler public void ScoreboardUpdate(UpdateEvent event) @@ -2318,7 +1632,7 @@ public class SurvivalGames extends SoloGame Scoreboard.Reset(); Scoreboard.WriteBlank(); - + GameTeam team = GetTeamList().get(0); if (team.GetPlayers(false).size() < 9) @@ -2351,18 +1665,19 @@ 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(); @@ -2378,12 +1693,13 @@ public class SurvivalGames extends SoloGame return true; } - + @EventHandler public void deathmatchBowShoot(EntityShootBowEvent event) { if (isDeathMatchAboutToStart()) event.getProjectile().remove(); } - + + }