From a62ecdb21225e143a75515423d815515c7e4ae18 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 25 Jan 2017 21:38:58 +0000 Subject: [PATCH 01/26] Custom Bridges and Per player world borders --- .../core/twofactor/TwoFactorAuth.java | 2 +- .../src/nautilus/game/arcade/Arcade.java | 8 +- .../game/games/bridge/BattleCryManager.java | 6 - .../game/arcade/game/games/bridge/Bridge.java | 336 +++++++++++++----- .../bridge/animation/BridgeAnimation.java | 45 +++ .../bridge/animation/BridgeAnimationType.java | 42 +++ .../animation/CustomBridgeAnimation.java | 153 ++++++++ .../bridge/animation/IceBridgeAnimation.java | 79 ++++ .../bridge/animation/LavaBridgeAnimation.java | 84 +++++ .../bridge/animation/WoodBridgeAnimation.java | 129 +++++++ .../game/arcade/game/modules/Module.java | 3 - .../game/modules/WorldBorderModule.java | 116 ++++++ 12 files changed, 898 insertions(+), 105 deletions(-) delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java index bc46f5218..59cab85bf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java @@ -176,7 +176,7 @@ public class TwoFactorAuth extends MiniClientPlugin player.sendMessage(F.main("2FA", "Setting up two-factor authentication.")); } - @EventHandler + //@EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 152a6b8d1..82fedec62 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -157,10 +157,10 @@ public class Arcade extends JavaPlugin Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); - SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); - ReportManager reportManager = new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1); - new SnapshotPlugin(this, snapshotManager, _clientManager); - new ReportPlugin(this, reportManager); +// SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); +// ReportManager reportManager = new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1); +// new SnapshotPlugin(this, snapshotManager, _clientManager); +// new ReportPlugin(this, reportManager); BlockRestore blockRestore = new BlockRestore(this); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java deleted file mode 100644 index 7c7e71ba0..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java +++ /dev/null @@ -1,6 +0,0 @@ -package nautilus.game.arcade.game.games.bridge; - -public class BattleCryManager -{ - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index a6d5d92f3..ac985ad84 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -1,9 +1,67 @@ package nautilus.game.arcade.game.games.bridge; -import com.google.common.collect.Lists; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; +import org.bukkit.entity.Chicken; +import org.bukkit.entity.Cow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Item; +import org.bukkit.entity.Pig; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.util.Vector; + import mineplex.core.common.Rank; -import mineplex.core.common.util.*; +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; +import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilWorld; import mineplex.core.explosion.ExplosionEvent; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.updater.UpdateType; @@ -17,35 +75,27 @@ import nautilus.game.arcade.events.PlayerDeathOutEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; -import nautilus.game.arcade.game.games.bridge.kits.*; +import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimation; +import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimationType; +import nautilus.game.arcade.game.games.bridge.animation.CustomBridgeAnimation; +import nautilus.game.arcade.game.games.bridge.kits.KitApple; +import nautilus.game.arcade.game.games.bridge.kits.KitArcher; +import nautilus.game.arcade.game.games.bridge.kits.KitBerserker; +import nautilus.game.arcade.game.games.bridge.kits.KitBomber; +import nautilus.game.arcade.game.games.bridge.kits.KitBrawler; +import nautilus.game.arcade.game.games.bridge.kits.KitDestructor; +import nautilus.game.arcade.game.games.bridge.kits.KitMammoth; +import nautilus.game.arcade.game.games.bridge.kits.KitMiner; +import nautilus.game.arcade.game.modules.WorldBorderModule; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.ore.OreHider; import nautilus.game.arcade.ore.OreObsfucation; -import nautilus.game.arcade.stats.*; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.Chest; -import org.bukkit.entity.*; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockFormEvent; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.inventory.PrepareItemCraftEvent; -import org.bukkit.event.player.*; -import org.bukkit.inventory.CraftingInventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.util.Vector; - -import java.util.*; +import nautilus.game.arcade.stats.BridgesSniperStatTracker; +import nautilus.game.arcade.stats.DeathBomberStatTracker; +import nautilus.game.arcade.stats.FoodForTheMassesStatTracker; +import nautilus.game.arcade.stats.KillFastStatTracker; +import nautilus.game.arcade.stats.TntMinerStatTracker; public class Bridge extends TeamGame implements OreObsfucation { @@ -54,10 +104,21 @@ public class Bridge extends TeamGame implements OreObsfucation */ private static final Material[] PLAYER_DROP_DELAY_MATERIALS = new Material[] { Material.LOG, Material.LOG_2, Material.IRON_ORE, Material.DIAMOND_ORE, Material.COAL_ORE, Material.GOLD_ORE, Material.WORKBENCH, Material.FURNACE }; - //Bridge Timer - private int _bridgeTime = 600000; + /** + * The number of milliseconds from the game start time til the bridges should be built. + */ + private static final long BRIDGE_TIME = TimeUnit.MINUTES.toMillis(10); + + /** + * The number of ticks after the prepare state that we wait before setting the world border for the players. Just to make sure they are in the correct world. + */ + private static final int WORLD_BORDER_PREPARE_TICKS = 20; + + //Bridge + private long _bridgeTime = BRIDGE_TIME; private boolean _bridgesDown = false; - + private BridgeAnimation _animation; + //Wood Bridge private ArrayList _woodBridge = new ArrayList(); private HashMap _woodBridgeBlocks = null; @@ -103,8 +164,8 @@ public class Bridge extends TeamGame implements OreObsfucation private boolean _tournament; private HashMap _tournamentKills = new HashMap(); private long _tournamentKillMessageTimer = 0; - + @SuppressWarnings("unchecked") public Bridge(ArcadeManager manager) { this(manager, GameType.Bridge); @@ -154,28 +215,6 @@ public class Bridge extends TeamGame implements OreObsfucation "The last team alive wins!" }); - List kits = Lists.newArrayList(GetKits()); - List finalKits = Lists.newArrayList(kits); - - boolean foundBrawler = false; - for(int i = 0; i < kits.size(); i++) - { - Kit kit = kits.get(i); - if(kit.GetName().equalsIgnoreCase("Brawler")) - { - if(!foundBrawler) - { - foundBrawler = true; - } - else - { - finalKits.remove(i); - } - } - } - - setKits(finalKits.toArray(new Kit[finalKits.size()])); - _ore = new OreHider(); // Flags @@ -183,7 +222,7 @@ public class Bridge extends TeamGame implements OreObsfucation Manager.GetExplosion().SetLiquidDamage(false); - this.StrictAntiHack = true; + StrictAntiHack = true; DamageSelf = true; @@ -206,10 +245,6 @@ public class Bridge extends TeamGame implements OreObsfucation WorldWaterDamage = 0; WorldBoundaryKill = false; - new CompassModule() - .setGiveCompassToAlive(true) - .register(this); - DeathDropItems = true; GemMultiplier = 2.5; @@ -229,18 +264,26 @@ public class Bridge extends TeamGame implements OreObsfucation "Killing yourself counts as -1 team kill.", "Team with the most kills wins!" }; + + _tournament = true; } - - _tournament = Manager.IsTournamentServer(); + new CompassModule() + .setGiveCompassToAlive(true) + .register(this); + + new WorldBorderModule().register(this); } + //TODO move this lower and use EntityDamage @EventHandler public void PlayerOut(final PlayerDeathOutEvent event) { if (_bridgesDown) + { return; - + } + Player player = event.GetPlayer(); if (!_usedLife.contains(player.getName())) @@ -253,11 +296,78 @@ public class Bridge extends TeamGame implements OreObsfucation } } + @EventHandler + public void prepare(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + { + return; + } + + //Delay this so that we are 100% sure people are in the world. + Manager.runSyncLater(() -> { + + WorldBorderModule borderModule = getModule(WorldBorderModule.class); + boolean oldWay = WorldData.GetCustomLocs("BORDER").isEmpty() || WorldData.GetCustomLocs("BORDER CENTER").isEmpty(); + +// if (!oldWay) +// { +// // Step 1 - Get the vector offset between the spectator location and the center of the border +// Location center = WorldData.GetCustomLocs("BORDER").get(0); +// +// Vector offset = center.subtract(SpectatorSpawn.toVector()).toVector(); +// } + + // Here we do some calculations for per player world borders + for (GameTeam team : GetTeamList()) + { + if (oldWay) + { + // If this is an old map or the builders haven't done it properly we can use this more of an estimate of the border size + // Step 1 - Get the average location of the spawns, we will assume this is the centre of the island + Location center = UtilAlg.getAverageLocation(team.GetSpawns()); + + // Step 2 - Calculate an estimate for the size of the border. We'll go with half but the setSize uses the radius so it works out the same to leave it like this + double distToCenter = UtilMath.offset2d(SpectatorSpawn, center); + + // Step 3 - Send the setCenter and setSize packets to the team members + for (Player player : team.GetPlayers(true)) + { + borderModule.setCenter(player, center); + borderModule.setSize(player, distToCenter); + } + } +// else +// { +// // Step 1 - Get the vector offset between the spectator location and the center of the border +// Location edge = WorldData.GetCustomLocs("BORDER").get(0); +// Location center = WorldData.GetCustomLocs("BORDER CENTER").get(0); +// +// Vector offset = center.subtract(SpectatorSpawn.toVector()).toVector(); +// +// // Step 2 - Calculate the distance between the the two border data points +// // Multiple by 2 because it is a radius +// double borderSize = UtilMath.offset2d(edge, center) * 2; +// +// // Step 3 - Send the setCenter and setSize packets to the team members +// for (Player player : team.GetPlayers(true)) +// { +// borderModule.setCenter(player, center); +// borderModule.setSize(player, borderSize); +// } +// } + } + + }, WORLD_BORDER_PREPARE_TICKS); + } + @EventHandler(priority = EventPriority.MONITOR) - public void GameStateChange(GameStateChangeEvent event) + public void live(GameStateChangeEvent event) { if (event.GetState() != GameState.Live) + { return; + } if (!WorldData.GetCustomLocs("WATER_DAMAGE").isEmpty()) { @@ -266,19 +376,47 @@ public class Bridge extends TeamGame implements OreObsfucation if (WorldWaterDamage > 0) { - if (WorldData.MapName.equals("Volcanic Islands")) + String name = WorldData.MapName; + + if (name.equals("Volcanic Islands")) + { UtilTextMiddle.display(C.cRed + "Warning", "Water is Boiling Hot", 10, 60, 20); + } else if (WorldData.MapName.equals("Icelands")) + { UtilTextMiddle.display(C.cRed + "Warning", "Water is Freezing Cold", 10, 60, 20); + } else + { UtilTextMiddle.display(C.cRed + "Warning", "Water is Deadly", 10, 60, 20); + } } } - //parse @Override public void ParseData() { + // Now we need to decide on what bridge animation. + typeLoop : for (BridgeAnimationType type : BridgeAnimationType.values()) + { + for (String colours : type.getColoursUsed()) + { + if (WorldData.GetDataLocs(colours).isEmpty()) + { + continue typeLoop; + } + } + + _animation = type.createInstance(this); + _animation.onParse(); + } + + if (_animation == null) + { + _animation = new CustomBridgeAnimation(this); + _animation.onParse(); + } + ParseLavaBridge(); ParseWoodBridge(); ParseIceBridge(); @@ -403,8 +541,6 @@ public class Bridge extends TeamGame implements OreObsfucation } } - - public void ParseOre(ArrayList teamOre) { int coal = (int) ((teamOre.size() / 32d) * _oreDensity); @@ -703,36 +839,49 @@ public class Bridge extends TeamGame implements OreObsfucation @EventHandler public void BridgeBuild(UpdateEvent event) { - if (!IsLive()) + if (!IsLive() || !UtilTime.elapsed(GetStateTime(), _bridgeTime)) + { return; - - if (event.getType() != UpdateType.FASTEST) + } + + if (_animation != null) + { + _animation.onUpdate(event.getType()); + } + + if (event.getType() != UpdateType.FAST) + { return; - - if (!UtilTime.elapsed(this.GetStateTime(), _bridgeTime)) - return; - + } + if (!_bridgesDown) { - Manager.GetExplosion().SetLiquidDamage(true); - this.Announce(C.cRed + C.Bold + "ALERT: " + ChatColor.RESET + C.Bold + "THE BRIDGES ARE SPAWNING!"); - } - - _bridgesDown = true; - - for (Kit kit : this.GetKits()) - { - if (kit instanceof KitDestructor) + _bridgesDown = true; + + WorldBorderModule borderModule = getModule(WorldBorderModule.class); + + for (Player player : GetPlayers(true)) { - ((KitDestructor)kit).SetEnabled(true); + borderModule.setSize(player, 1000); + } + + Manager.GetExplosion().SetLiquidDamage(true); + Announce(C.cRed + C.Bold + "ALERT: " + ChatColor.RESET + C.Bold + "THE BRIDGES ARE SPAWNING!"); + + for (Kit kit : GetKits()) + { + if (kit instanceof KitDestructor) + { + ((KitDestructor)kit).SetEnabled(true); + } } } - - BuildWood(); - BuildLava(); - BuildIce(); - BuildLillyPad(); - buildMushroom(); + +// BuildWood(); +// BuildLava(); +// BuildIce(); +// BuildLillyPad(); +// buildMushroom(); } protected void BuildLava() @@ -1515,7 +1664,7 @@ public class Bridge extends TeamGame implements OreObsfucation else { Scoreboard.write(C.cYellow + C.Bold + "Time Left"); - Scoreboard.write(UtilTime.MakeStr(5400000 - (System.currentTimeMillis() - this.GetStateTime()), 0)); + Scoreboard.write(UtilTime.MakeStr(GameTimeout - (System.currentTimeMillis() - GetStateTime()), 0)); } Scoreboard.draw(); @@ -1923,7 +2072,7 @@ public class Bridge extends TeamGame implements OreObsfucation _ore.ToggleVisibility(); if (Manager.GetClients().hasRank(event.getPlayer(), Rank.ADMIN) && event.getMessage().contains("/bridge")) - _bridgeTime = 30000; + _bridgeTime = 3000; } @EventHandler @@ -1961,6 +2110,11 @@ public class Bridge extends TeamGame implements OreObsfucation return _chestLoot; } + public HashSet getBridgeParts() + { + return _bridgeParts; + } + public boolean bridgesDown() { return _bridgesDown; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java new file mode 100644 index 000000000..8c3496f10 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java @@ -0,0 +1,45 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; +import nautilus.game.arcade.game.games.bridge.BridgePart; +import nautilus.game.arcade.world.WorldData; + +public abstract class BridgeAnimation +{ + + public static final int AVERAGE_BRIDGE_BLOCKS = 3000; + + protected final Bridge _bridge; + protected final WorldData _worldData; + + public BridgeAnimation(Bridge bridge) + { + _bridge = bridge; + _worldData = bridge.WorldData; + } + + public abstract void onParse(); + + public abstract void onUpdate(UpdateType type); + + public void registerBridgePart(BridgePart part) + { + _bridge.getBridgeParts().add(part); + } + + public boolean isAir(Location location) + { + return isAir(location.getBlock()); + } + + public boolean isAir(Block block) + { + return block.getType() == Material.AIR; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java new file mode 100644 index 000000000..bf2207187 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java @@ -0,0 +1,42 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import nautilus.game.arcade.game.games.bridge.Bridge; + +public enum BridgeAnimationType +{ + + WOOD(WoodBridgeAnimation.class, "BROWN", "GRAY"), + ICE(IceBridgeAnimation.class, "LIGHT_BLUE"), + LAVA(LavaBridgeAnimation.class, "BLACK", "RED", "ORANGE") + + ; + + private final Class _clazz; + private final String[] _coloursUsed; + + private BridgeAnimationType(Class clazz, String... coloursUsed) + { + _clazz = clazz; + _coloursUsed = coloursUsed; + } + + public BridgeAnimation createInstance(Bridge bridge) + { + try + { + return _clazz.cast(_clazz.getConstructor(Bridge.class).newInstance(bridge)); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } + + public String[] getColoursUsed() + { + return _coloursUsed; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java new file mode 100644 index 000000000..921676590 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java @@ -0,0 +1,153 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; + +import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class CustomBridgeAnimation extends BridgeAnimation +{ + + private static final String REGION_KEY = "BRIDGE"; + private static final String BRIDGE_DATA_KEY = "CUSTOM_BRIDGE"; + private static final double RATE = 0.5; + + private final BlockRestore _restore; + private final Map _bridgeBlocks; + + private int[] _blockIds; + + private double _maxDistance; + private double _minDistance; + + public CustomBridgeAnimation(Bridge bridge) + { + super(bridge); + + _restore = bridge.getArcadeManager().GetBlockRestore(); + _bridgeBlocks = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); + } + + @Override + public void onParse() + { + _maxDistance = 0; + + for (String key : _worldData.GetAllCustomLocs().keySet()) + { + if (!key.startsWith(BRIDGE_DATA_KEY)) + { + continue; + } + + String[] split = key.split(" "); + int[] blockIds = new int[split.length - 1]; + + for (int i = 1; i < split.length; i++) + { + try + { + blockIds[i - 1] = Integer.parseInt(split[i]); + } + catch (NumberFormatException e) + { + continue; + } + } + + _blockIds = blockIds; + } + + for (String key : _worldData.GetAllCustomLocs().keySet()) + { + if (!key.startsWith(REGION_KEY)) + { + continue; + } + + List locations = _worldData.GetCustomLocs(key); + + if (locations.size() < 2) + { + continue; + } + + for (Block block : UtilBlock.getInBoundingBox(locations.get(0), locations.get(1))) + { + boolean shouldAdd = false; + + for (int id : _blockIds) + { + if (block.getTypeId() == id) + { + shouldAdd = true; + break; + } + } + + if (!shouldAdd) + { + continue; + } + + double dist = UtilMath.offset2d(block.getLocation(), _bridge.GetSpectatorLocation()); + + if (dist > _maxDistance) + { + _maxDistance = dist; + } + + _restore.add(block, Material.AIR.getId(), (byte) 0, Integer.MAX_VALUE); + _bridgeBlocks.put(block.getLocation(), dist); + } + } + + _minDistance = _maxDistance; + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.FAST) + { + return; + } + + _minDistance -= RATE; + + Iterator iterator = _bridgeBlocks.keySet().iterator(); + + while (iterator.hasNext()) + { + Location location = iterator.next(); + double dist = _bridgeBlocks.get(location); + + if (dist > _minDistance) + { + Block block = location.getBlock(); + + _restore.restore(block); + UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, block.getLocation().add(0.5, 1.5, 0.5), 0.25F, 0.25F, 0.25F, 0.05F, 5, ViewDist.NORMAL); + + location.getWorld().playSound(location, Sound.ZOMBIE_UNFECT, 1.5F, 1); + + iterator.remove(); + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java new file mode 100644 index 000000000..6b555e861 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java @@ -0,0 +1,79 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class IceBridgeAnimation extends BridgeAnimation +{ + + private List _iceBridge; + + public IceBridgeAnimation(Bridge bridge) + { + super(bridge); + + _iceBridge = new ArrayList<>(AVERAGE_BRIDGE_BLOCKS); + } + + @Override + public void onParse() + { + _iceBridge = _worldData.GetDataLocs("LIGHT_BLUE"); + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.FASTEST || _iceBridge.isEmpty()) + { + return; + } + + int attempts = 0; + int done = 0; + + while (done < 5 && attempts < 400) + { + attempts++; + + // Random Block + Location loc = UtilAlg.Random(_iceBridge); + + Block block = loc.getBlock().getRelative(BlockFace.DOWN); + + if (!block.isLiquid()) + { + continue; + } + + if (block.getRelative(BlockFace.NORTH).isLiquid() && block.getRelative(BlockFace.EAST).isLiquid() && block.getRelative(BlockFace.SOUTH).isLiquid() && block.getRelative(BlockFace.WEST).isLiquid()) + { + continue; + } + + _iceBridge.remove(loc); + + if (Math.random() > 0.25) + { + MapUtil.QuickChangeBlockAt(block.getLocation(), Material.PACKED_ICE); + } + else + { + MapUtil.QuickChangeBlockAt(block.getLocation(), Material.ICE); + } + + done++; + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java new file mode 100644 index 000000000..2cf015470 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java @@ -0,0 +1,84 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.FallingBlock; + +import mineplex.core.common.util.UtilMath; +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; +import nautilus.game.arcade.game.games.bridge.BridgePart; + +public class LavaBridgeAnimation extends BridgeAnimation +{ + + private List _lavaSource; + private List _lavaBridge; + + public LavaBridgeAnimation(Bridge bridge) + { + super(bridge); + + _lavaSource = new ArrayList<>(); + _lavaBridge = new ArrayList<>(AVERAGE_BRIDGE_BLOCKS); + } + + @Override + public void onParse() + { + for (Location loc : _worldData.GetDataLocs("RED")) + { + _lavaBridge.add(loc.getBlock().getLocation()); + } + + for (Location loc : _worldData.GetDataLocs("ORANGE")) + { + _lavaBridge.add(loc.getBlock().getLocation()); + _lavaBridge.add(loc.getBlock().getRelative(BlockFace.UP).getLocation()); + } + + _lavaSource = _worldData.GetDataLocs("BLACK"); + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.FASTEST) + { + return; + } + + for (int i = 0; i < 3; i++) + { + if (!_lavaBridge.isEmpty() && !_lavaSource.isEmpty()) + { + // Random Block + Location bestLoc = _lavaBridge.get(UtilMath.r(_lavaBridge.size())); + + if (bestLoc.getBlock().getRelative(BlockFace.DOWN).isLiquid()) + { + continue; + } + + _lavaBridge.remove(bestLoc); + + Location source = _lavaSource.get(UtilMath.r(_lavaSource.size())); + + // Create Part + FallingBlock block = bestLoc.getWorld().spawnFallingBlock(source, Material.NETHERRACK, (byte) 0); + BridgePart part = new BridgePart(block, bestLoc, true); + + registerBridgePart(part); + + // Sound + source.getWorld().playSound(source, Sound.EXPLODE, 5f * (float) Math.random(), 0.5f + (float) Math.random()); + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java new file mode 100644 index 000000000..ecafe937b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java @@ -0,0 +1,129 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.FallingBlock; +import org.bukkit.util.Vector; + +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; +import nautilus.game.arcade.game.games.bridge.BridgePart; + +public class WoodBridgeAnimation extends BridgeAnimation +{ + + private static final BlockFace[] FACES = new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; + private static final int Y_MOD = 30; + + private final Map _woodBridge; + + public WoodBridgeAnimation(Bridge bridge) + { + super(bridge); + + _woodBridge = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); + } + + @Override + public void onParse() + { + onParse(_worldData.GetDataLocs("BROWN"), false); + onParse(_worldData.GetDataLocs("GRAY"), true); + } + + public void onParse(List locations, boolean aboveBelow) + { + for (Location location : locations) + { + if (aboveBelow) + { + _woodBridge.put(location.getBlock().getRelative(BlockFace.UP).getLocation(), Material.FENCE); + _woodBridge.put(location, Material.LOG); + } + else + { + _woodBridge.put(location, Material.WOOD_STEP); + } + } + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.FASTEST) + { + return; + } + + List toDo = new ArrayList<>(); + + for (Location location : _woodBridge.keySet()) + { + Material material = _woodBridge.get(location); + + if (material == Material.LOG) + { + int adjacent = 0; + + for (BlockFace face : FACES) + { + if (!isAir(location.getBlock().getRelative(face))) + { + adjacent++; + } + } + if (adjacent > 0) + { + toDo.add(location); + } + } + else if (material == Material.FENCE) + { + if (!isAir(location.getBlock().getRelative(BlockFace.DOWN))) + { + toDo.add(location); + } + } + else if (material == Material.WOOD_STEP) + { + int adjacent = 0; + + for (BlockFace face : FACES) + { + if (!isAir(location.getBlock().getRelative(face))) + { + adjacent++; + } + } + if (adjacent > 0) + { + toDo.add(location); + } + } + } + + if (toDo.size() == 0) + { + return; + } + + for (Location location : toDo) + { + Material material = _woodBridge.remove(location); + Location source = location.clone().add(0, Y_MOD, 0); + + // Create Part + FallingBlock block = location.getWorld().spawnFallingBlock(source, material, (byte) 0); + block.setVelocity(new Vector(0, -1, 0)); + BridgePart part = new BridgePart(block, location, false); + + registerBridgePart(part); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java index 2aed67d39..638d2620b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java @@ -1,10 +1,7 @@ package nautilus.game.arcade.game.modules; import com.google.gson.JsonElement; -import mineplex.core.Managers; -import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game; -import nautilus.game.arcade.game.TeamGame; import org.bukkit.event.Listener; /** diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java new file mode 100644 index 000000000..6a1f13bae --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java @@ -0,0 +1,116 @@ +package nautilus.game.arcade.game.modules; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import mineplex.core.common.Pair; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.packethandler.IPacketHandler; +import mineplex.core.packethandler.PacketHandler; +import mineplex.core.packethandler.PacketInfo; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; +import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder; +import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder.EnumWorldBorderAction; +import net.minecraft.server.v1_8_R3.WorldBorder; + +public class WorldBorderModule extends Module implements IPacketHandler +{ + + private PacketHandler _packetHandler; + private Map _sizeToSet; + private Map> _centerToSet; + + @Override + protected void setup() + { + _packetHandler = getGame().getArcadeManager().getPacketHandler(); + _sizeToSet = new HashMap<>(); + _centerToSet = new HashMap<>(); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void live(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + { + return; + } + + _packetHandler.addPacketHandler(this, PacketPlayOutWorldBorder.class); + } + + @Override + public void handle(PacketInfo packetInfo) + { + UUID player = packetInfo.getPlayer().getUniqueId(); + PacketPlayOutWorldBorder packet = (PacketPlayOutWorldBorder) packetInfo.getPacket(); + + try + { + Field actionField = packet.getClass().getDeclaredField("a"); + actionField.setAccessible(true); + EnumWorldBorderAction action = (EnumWorldBorderAction) actionField.get(packet); + + if (action == EnumWorldBorderAction.SET_SIZE) + { + Field sizeField = packet.getClass().getDeclaredField("e"); + sizeField.setAccessible(true); + double newSize = _sizeToSet.get(player); + + sizeField.set(packet, newSize); + } + else if (action == EnumWorldBorderAction.SET_CENTER) + { + Field xField = packet.getClass().getDeclaredField("c"); + Field zField = packet.getClass().getDeclaredField("d"); + + xField.setAccessible(true); + zField.setAccessible(true); + + Pair pair = _centerToSet.get(player); + + xField.set(packet, pair.getLeft()); + zField.set(packet, pair.getRight()); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + @Override + public void cleanup() + { + _packetHandler.removePacketHandler(this); + } + + public void setSize(Player player, double size) + { + _sizeToSet.put(player.getUniqueId(), size); + + sendPacket(player, EnumWorldBorderAction.SET_SIZE); + } + + public void setCenter(Player player, Location location) + { + _centerToSet.put(player.getUniqueId(), Pair.create(location.getX(), location.getZ())); + + sendPacket(player, EnumWorldBorderAction.SET_CENTER); + } + + private void sendPacket(Player player, EnumWorldBorderAction action) + { + WorldBorder border = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder(); + UtilPlayer.sendPacket(player, new PacketPlayOutWorldBorder(border, action)); + } +} From 13806a49d2a89b480acc172309e973133c655c22 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 3 Feb 2017 20:33:21 +0000 Subject: [PATCH 02/26] Bridges bug fixes --- .../game/arcade/game/games/bridge/Bridge.java | 581 ++++-------------- .../bridge/animation/BridgeAnimationType.java | 4 +- .../animation/LillyPadBridgeAnimation.java | 65 ++ .../animation/MushroomBridgeAnimation.java | 107 ++++ .../game/games/bridge/kits/KitDestructor.java | 2 +- .../games/bridge/modes/OverpoweredBridge.java | 36 +- .../game/arcade/kit/perks/PerkDestructor.java | 4 +- .../stats/FoodForTheMassesStatTracker.java | 6 + 8 files changed, 319 insertions(+), 486 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index ac985ad84..813f8349a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -13,14 +13,12 @@ import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; import org.bukkit.entity.Chicken; import org.bukkit.entity.Cow; import org.bukkit.entity.Entity; -import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Item; import org.bukkit.entity.Pig; import org.bukkit.entity.Player; @@ -31,9 +29,11 @@ import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; @@ -48,7 +48,6 @@ import org.bukkit.util.Vector; import mineplex.core.common.Rank; 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; @@ -71,7 +70,6 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; -import nautilus.game.arcade.events.PlayerDeathOutEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; @@ -89,6 +87,8 @@ import nautilus.game.arcade.game.games.bridge.kits.KitMiner; import nautilus.game.arcade.game.modules.WorldBorderModule; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.Perk; +import nautilus.game.arcade.kit.perks.PerkDestructor; import nautilus.game.arcade.ore.OreHider; import nautilus.game.arcade.ore.OreObsfucation; import nautilus.game.arcade.stats.BridgesSniperStatTracker; @@ -118,25 +118,6 @@ public class Bridge extends TeamGame implements OreObsfucation private long _bridgeTime = BRIDGE_TIME; private boolean _bridgesDown = false; private BridgeAnimation _animation; - - //Wood Bridge - private ArrayList _woodBridge = new ArrayList(); - private HashMap _woodBridgeBlocks = null; - - //Lava Bridge - private ArrayList _lavaBridge = new ArrayList(); - private ArrayList _lavaSource = new ArrayList(); - - //Lilly Pad Bridge - private NautHashMap _lillyPads = new NautHashMap(); - - //Mushrooms - private NautHashMap _mushroomStem = new NautHashMap(); - private NautHashMap _mushroomTop = new NautHashMap(); - private boolean _stemsGrown = false; - - //Ice - private ArrayList _iceBridge = new ArrayList(); private HashSet _bridgeParts = new HashSet(); @@ -273,26 +254,20 @@ public class Bridge extends TeamGame implements OreObsfucation .register(this); new WorldBorderModule().register(this); - } - - //TODO move this lower and use EntityDamage - @EventHandler - public void PlayerOut(final PlayerDeathOutEvent event) - { - if (_bridgesDown) - { - return; - } - Player player = event.GetPlayer(); - - if (!_usedLife.contains(player.getName())) + // So that we can be 110% sure + for (Kit kit : GetKits()) { - _usedLife.add(player.getName()); - - UtilPlayer.message(player, F.main("Game", "You used your " + F.elem(C.cAqua + "Early Game Revive") + ".")); - - event.setCancelled(true); + if (kit instanceof KitDestructor) + { + for (Perk perk : kit.GetPerks()) + { + ((PerkDestructor) perk).setEnabled(false); + break; + } + + break; + } } } @@ -308,54 +283,25 @@ public class Bridge extends TeamGame implements OreObsfucation Manager.runSyncLater(() -> { WorldBorderModule borderModule = getModule(WorldBorderModule.class); - boolean oldWay = WorldData.GetCustomLocs("BORDER").isEmpty() || WorldData.GetCustomLocs("BORDER CENTER").isEmpty(); - -// if (!oldWay) -// { -// // Step 1 - Get the vector offset between the spectator location and the center of the border -// Location center = WorldData.GetCustomLocs("BORDER").get(0); -// -// Vector offset = center.subtract(SpectatorSpawn.toVector()).toVector(); -// } // Here we do some calculations for per player world borders for (GameTeam team : GetTeamList()) { - if (oldWay) + // If this is an old map or the builders haven't done it properly we can use this more of an estimate of the border size + // Step 1 - Get the average location of the spawns, we will assume this is the centre of the island + Location center = UtilAlg.getAverageLocation(team.GetSpawns()); + center.add(UtilAlg.getTrajectory(SpectatorSpawn, center).multiply(20)); + + // Step 2 - Calculate an estimate for the size of the border. We'll go with half but the setSize uses the radius so it works out the same to leave it like this + double distToCenter = UtilMath.offset2d(SpectatorSpawn, center); + + // Step 3 - Send the setCenter and setSize packets to the team members + for (Player player : team.GetPlayers(true)) { - // If this is an old map or the builders haven't done it properly we can use this more of an estimate of the border size - // Step 1 - Get the average location of the spawns, we will assume this is the centre of the island - Location center = UtilAlg.getAverageLocation(team.GetSpawns()); - - // Step 2 - Calculate an estimate for the size of the border. We'll go with half but the setSize uses the radius so it works out the same to leave it like this - double distToCenter = UtilMath.offset2d(SpectatorSpawn, center); - - // Step 3 - Send the setCenter and setSize packets to the team members - for (Player player : team.GetPlayers(true)) - { - borderModule.setCenter(player, center); - borderModule.setSize(player, distToCenter); - } + borderModule.setCenter(player, center); + borderModule.setSize(player, distToCenter * 0.6); } -// else -// { -// // Step 1 - Get the vector offset between the spectator location and the center of the border -// Location edge = WorldData.GetCustomLocs("BORDER").get(0); -// Location center = WorldData.GetCustomLocs("BORDER CENTER").get(0); -// -// Vector offset = center.subtract(SpectatorSpawn.toVector()).toVector(); -// -// // Step 2 - Calculate the distance between the the two border data points -// // Multiple by 2 because it is a radius -// double borderSize = UtilMath.offset2d(edge, center) * 2; -// -// // Step 3 - Send the setCenter and setSize packets to the team members -// for (Player player : team.GetPlayers(true)) -// { -// borderModule.setCenter(player, center); -// borderModule.setSize(player, borderSize); -// } -// } + } }, WORLD_BORDER_PREPARE_TICKS); @@ -417,12 +363,6 @@ public class Bridge extends TeamGame implements OreObsfucation _animation.onParse(); } - ParseLavaBridge(); - ParseWoodBridge(); - ParseIceBridge(); - ParseLillyPad(); - ParseMushrooms(); - ParseChests(); ParseOre(WorldData.GetCustomLocs("73")); // Red @@ -761,81 +701,6 @@ public class Bridge extends TeamGame implements OreObsfucation } } - protected void ParseWoodBridge() { - _woodBridge = new ArrayList(); - - // Load Wood In - for (Location loc : WorldData.GetDataLocs("BROWN")) { - _woodBridge.add(loc.getBlock().getLocation()); - } - - for (Location loc : WorldData.GetDataLocs("GRAY")) { - _woodBridge.add(loc.getBlock().getLocation()); - _woodBridge.add(loc.getBlock().getRelative(BlockFace.UP) - .getLocation()); - } - - // Determine Wood Block - _woodBridgeBlocks = new HashMap(); - - for (Location loc : _woodBridge) { - if (_woodBridge.contains(loc.getBlock().getRelative(BlockFace.DOWN) - .getLocation())) { - _woodBridgeBlocks.put(loc, 85); - } - - if (_woodBridge.contains(loc.getBlock().getRelative(BlockFace.UP) - .getLocation())) { - _woodBridgeBlocks.put(loc, 17); - } - - if (!_woodBridgeBlocks.containsKey(loc)) { - _woodBridgeBlocks.put(loc, 126); - } - } - } - - protected void ParseLavaBridge() { - for (Location loc : WorldData.GetDataLocs("RED")) { - _lavaBridge.add(loc.getBlock().getLocation()); - } - - for (Location loc : WorldData.GetDataLocs("ORANGE")) { - _lavaBridge.add(loc.getBlock().getLocation()); - _lavaBridge.add(loc.getBlock().getRelative(BlockFace.UP) - .getLocation()); - } - - _lavaSource = WorldData.GetDataLocs("BLACK"); - } - - protected void ParseIceBridge() - { - _iceBridge = WorldData.GetDataLocs("LIGHT_BLUE"); - } - - protected void ParseMushrooms() - { - for (Location loc : WorldData.GetCustomLocs("21")) - { - _mushroomStem.put(loc, 0L); - loc.getBlock().setType(Material.AIR); - } - - for (Location loc : WorldData.GetDataLocs("PURPLE")) - { - _mushroomTop.put(loc, 0L); - } - } - - protected void ParseLillyPad() - { - for (Location loc : WorldData.GetDataLocs("LIME")) - { - _lillyPads.put(loc, 0L); - } - } - @EventHandler public void BridgeBuild(UpdateEvent event) { @@ -866,7 +731,8 @@ public class Bridge extends TeamGame implements OreObsfucation } Manager.GetExplosion().SetLiquidDamage(true); - Announce(C.cRed + C.Bold + "ALERT: " + ChatColor.RESET + C.Bold + "THE BRIDGES ARE SPAWNING!"); + Announce(C.cRedB + "ALERT: " + C.Reset + C.Bold + "THE BRIDGES ARE SPAWNING!"); + UtilTextMiddle.display(C.cRedB + "ALERT", "The BRIDGES ARE SPAWNING!"); for (Kit kit : GetKits()) { @@ -876,269 +742,43 @@ public class Bridge extends TeamGame implements OreObsfucation } } } - -// BuildWood(); -// BuildLava(); -// BuildIce(); -// BuildLillyPad(); -// buildMushroom(); } - protected void BuildLava() - { - for (int i = 0; i < 3; i++) - if (_lavaBridge != null && _lavaSource != null - && !_lavaBridge.isEmpty() && !_lavaSource.isEmpty()) { - // Random Block - Location bestLoc = _lavaBridge.get(UtilMath.r(_lavaBridge - .size())); - if (bestLoc.getBlock().getRelative(BlockFace.DOWN) - .isLiquid()) - continue; - - _lavaBridge.remove(bestLoc); - - Location source = _lavaSource.get(UtilMath.r(_lavaSource - .size())); - - // Create Part - FallingBlock block = bestLoc.getWorld().spawnFallingBlock( - source, 87, (byte) 0); - BridgePart part = new BridgePart(block, bestLoc, true); - _bridgeParts.add(part); - - // Sound - source.getWorld().playSound(source, Sound.EXPLODE, - 5f * (float) Math.random(), - 0.5f + (float) Math.random()); - } - } - - protected void BuildLillyPad() - { - for (int i = 0; i < 3; i++) - if (_lillyPads != null && !_lillyPads.isEmpty()) - { - // Random Block - Location loc = UtilAlg.Random(_lillyPads.keySet()); - - if (!UtilTime.elapsed(_lillyPads.get(loc), 8000)) - continue; - - if (!loc.getBlock().getRelative(BlockFace.DOWN).isLiquid()) - continue; - - _lillyPads.remove(loc); - - MapUtil.QuickChangeBlockAt(loc, Material.WATER_LILY); - - // Sound - loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 111); - } - } - - @EventHandler - public void breakLillyPad(BlockBreakEvent event) - { - if (event.getBlock().getType() != Material.WATER_LILY) - return; - - _lillyPads.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); - } +// @EventHandler +// public void breakLillyPad(BlockBreakEvent event) +// { +// if (event.getBlock().getType() != Material.WATER_LILY) +// return; +// +// _lillyPads.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); +// } - protected void buildMushroom() - { - if (_mushroomStem != null && !_mushroomStem.isEmpty()) - { - for (int i=0 ; i<4 && !_mushroomStem.isEmpty() ; i++) - { - double lowestY = 0; - Location lowestLoc = null; - - for (Location loc : _mushroomStem.keySet()) - { - if (!UtilTime.elapsed(_mushroomStem.get(loc), 6000)) - continue; - - if (lowestLoc == null || loc.getY() < lowestY) - { - lowestY = loc.getY(); - lowestLoc = loc; - } - } - - if (lowestLoc == null) - continue; - - _mushroomStem.remove(lowestLoc); - - MapUtil.QuickChangeBlockAt(lowestLoc, 100, (byte)15); - } - } - else - { - _stemsGrown = true; - } - - if (_stemsGrown && _mushroomTop != null && !_mushroomTop.isEmpty()) - { - int attempts = 0; - int done = 0; - while (done < 6 && attempts < 400) - { - attempts++; - - // Random Block - Location loc = UtilAlg.Random(_mushroomTop.keySet()); - - if (!UtilTime.elapsed(_mushroomTop.get(loc), 6000)) - continue; - - Block block = loc.getBlock(); - - if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR && - block.getRelative(BlockFace.NORTH).getType() == Material.AIR && - block.getRelative(BlockFace.EAST).getType() == Material.AIR && - block.getRelative(BlockFace.SOUTH).getType() == Material.AIR && - block.getRelative(BlockFace.WEST).getType() == Material.AIR) - continue; - - _mushroomTop.remove(loc); - - MapUtil.QuickChangeBlockAt(block.getLocation(), 99, (byte)14); - - done++; - } - } - } - - @EventHandler - public void breakMushroom(BlockBreakEvent event) - { - if (event.isCancelled()) - return; - - - if (event.getBlock().getTypeId() == 100 && - WorldData.GetCustomLocs("21").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) - { - event.setCancelled(true); - event.getBlock().setType(Material.AIR); - - _mushroomStem.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); - } - - if (event.getBlock().getTypeId() == 99 && - WorldData.GetDataLocs("PURPLE").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) - { - event.setCancelled(true); - event.getBlock().setType(Material.AIR); - - _mushroomTop.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); - } - } - - protected void BuildIce() - { - if (_iceBridge == null || _iceBridge.isEmpty() || UtilTime.elapsed(this.GetStateTime(), _bridgeTime + 120000)) - { - WorldData.World.setStorm(false); - return; - } - - WorldData.World.setStorm(true); - - int attempts = 0; - int done = 0; - while (done < 5 && attempts < 400) - { - attempts++; - - // Random Block - Location loc = _iceBridge.get(UtilMath.r(_iceBridge.size())); - - Block block = loc.getBlock().getRelative(BlockFace.DOWN); - - if (!block.isLiquid()) - continue; - - if (block.getRelative(BlockFace.NORTH).isLiquid() && - block.getRelative(BlockFace.EAST).isLiquid() && - block.getRelative(BlockFace.SOUTH).isLiquid() && - block.getRelative(BlockFace.WEST).isLiquid()) - continue; - - _iceBridge.remove(loc); - - if (Math.random() > 0.25) - MapUtil.QuickChangeBlockAt(block.getLocation(), Material.PACKED_ICE); - else - MapUtil.QuickChangeBlockAt(block.getLocation(), Material.ICE); - - done++; - } - } - - protected void BuildWood() - { - if (_woodBridgeBlocks != null && !_woodBridgeBlocks.isEmpty()) - { - ArrayList toDo = new ArrayList(); - - BlockFace[] faces = new BlockFace[] { BlockFace.NORTH, - BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; - - for (Location loc : _woodBridgeBlocks.keySet()) - { - if (_woodBridgeBlocks.get(loc) == 17) - { - int adjacent = 0; - - for (BlockFace face : faces) - if (loc.getBlock().getRelative(face).getTypeId() != 0) - adjacent++; - - if (adjacent > 0) - toDo.add(loc); - - } else if (_woodBridgeBlocks.get(loc) == 85) - { - if (loc.getBlock().getRelative(BlockFace.DOWN).getTypeId() == 0) - continue; - - toDo.add(loc); - } else if (_woodBridgeBlocks.get(loc) == 126) - { - int adjacent = 0; - - for (BlockFace face : faces) - if (loc.getBlock().getRelative(face).getTypeId() != 0) - adjacent++; - - if (adjacent > 0) - toDo.add(loc); - } - } - - if (toDo.size() == 0) - return; - - for (Location loc : toDo) - { - int id = _woodBridgeBlocks.remove(loc); - - Location source = loc.clone().add(0, 30, 0); - - // Create Part - FallingBlock block = loc.getWorld().spawnFallingBlock(source, - id, (byte) 0); - block.setVelocity(new Vector(0, -1, 0)); - BridgePart part = new BridgePart(block, loc, false); - _bridgeParts.add(part); - } - } - } +// @EventHandler +// public void breakMushroom(BlockBreakEvent event) +// { +// if (event.isCancelled()) +// return; +// +// +// if (event.getBlock().getTypeId() == 100 && +// WorldData.GetCustomLocs("21").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) +// { +// event.setCancelled(true); +// event.getBlock().setType(Material.AIR); +// +// _mushroomStem.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); +// } +// +// if (event.getBlock().getTypeId() == 99 && +// WorldData.GetDataLocs("PURPLE").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) +// { +// event.setCancelled(true); +// event.getBlock().setType(Material.AIR); +// +// _mushroomTop.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); +// } +// } @EventHandler public void BridgeUpdate(UpdateEvent event) @@ -1255,7 +895,7 @@ public class Bridge extends TeamGame implements OreObsfucation while (!UtilBlock.airFoliage(block)) { block = block.getRelative(BlockFace.UP); - + if (block.getY() >= 256) break; } @@ -1268,15 +908,15 @@ public class Bridge extends TeamGame implements OreObsfucation break; } - block = block.getRelative(BlockFace.UP); - - if (block.getTypeId() == 0) + if (block.getType() != Material.SNOW) { - if (Math.random() > 0.5) - block.setTypeId(39); - else - block.setTypeId(40); + block = block.getRelative(BlockFace.UP); } + + if (Math.random() > 0.5) + block.setTypeId(39); + else + block.setTypeId(40); } } @@ -2023,23 +1663,32 @@ public class Bridge extends TeamGame implements OreObsfucation } } - // @EventHandler - // public void liquidBlockDeny(BlockBreakEvent event) - // { - // if (_bridgesDown) - // return; - // - // if (!IsAlive(event.getPlayer())) - // return; - // - // if (event.getBlock().getRelative(BlockFace.UP).isLiquid() || event.getBlock().getRelative(BlockFace.UP).getRelative(BlockFace.UP).isLiquid()) - // { - // UtilPlayer.message(event.getPlayer(), F.main("Game", - // "Cannot tunnel under liquids.")); - // - // event.setCancelled(true); - // } - // } + @EventHandler(priority=EventPriority.LOWEST) + public void revivePlayer(EntityDamageEvent event) + { + if (_bridgesDown || !(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (player.getHealth() - event.getDamage() > 0) + { + return; + } + + if (!_usedLife.contains(player.getName())) + { + _usedLife.add(player.getName()); + + UtilPlayer.message(player, F.main("Game", "You used your " + F.elem(C.cAqua + "Early Game Revive") + ".")); + + GetTeam(player).SpawnTeleport(player); + player.setHealth(20); + event.setCancelled(true); + } + } @EventHandler public void vehicleDeny(PlayerInteractEvent event) @@ -2089,6 +1738,40 @@ public class Bridge extends TeamGame implements OreObsfucation UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot pickup liquids before the bridges have fallen.")); event.setCancelled(true); } + + @EventHandler + public void disableDoors(CraftItemEvent event) + { + if (_bridgesDown) + { + return; + } + + Material type = event.getRecipe().getResult().getType(); + + if (type == Material.WOOD_DOOR || type == Material.IRON_DOOR) + { + event.setResult(null); + event.setCancelled(true); + } + } + + @EventHandler + public void disableDoors(PlayerPickupItemEvent event) + { + if (_bridgesDown) + { + return; + } + + Material type = event.getItem().getItemStack().getType(); + + if (type == Material.WOOD_DOOR || type == Material.IRON_DOOR) + { + event.getItem().remove(); + event.setCancelled(true); + } + } public void setBridgeTime(int time) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java index bf2207187..a7a8aa739 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java @@ -7,7 +7,9 @@ public enum BridgeAnimationType WOOD(WoodBridgeAnimation.class, "BROWN", "GRAY"), ICE(IceBridgeAnimation.class, "LIGHT_BLUE"), - LAVA(LavaBridgeAnimation.class, "BLACK", "RED", "ORANGE") + LAVA(LavaBridgeAnimation.class, "BLACK", "RED", "ORANGE"), + LILLY(LillyPadBridgeAnimation.class, "LIME"), + MUSHROOM(MushroomBridgeAnimation.class, "PURPLE") ; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java new file mode 100644 index 000000000..839a9536e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java @@ -0,0 +1,65 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; + +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class LillyPadBridgeAnimation extends BridgeAnimation +{ + + private Map _lillyPads = new HashMap<>(); + + public LillyPadBridgeAnimation(Bridge bridge) + { + super(bridge); + } + + @Override + public void onParse() + { + for (Location loc : _worldData.GetDataLocs("LIME")) + { + _lillyPads.put(loc, 0L); + } + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.FASTEST) + return; + + for (int i = 0; i < 3; i++) + { + if (_lillyPads != null && !_lillyPads.isEmpty()) + { + // Random Block + Location loc = UtilAlg.Random(_lillyPads.keySet()); + + if (!UtilTime.elapsed(_lillyPads.get(loc), 8000)) + continue; + + if (!loc.getBlock().getRelative(BlockFace.DOWN).isLiquid()) + continue; + + _lillyPads.remove(loc); + + MapUtil.QuickChangeBlockAt(loc, Material.WATER_LILY); + + // Sound + loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 111); + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java new file mode 100644 index 000000000..dad3ecdb7 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java @@ -0,0 +1,107 @@ +package nautilus.game.arcade.game.games.bridge.animation; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class MushroomBridgeAnimation extends BridgeAnimation +{ + + private Map _mushroomStem = new HashMap<>(); + private Map _mushroomTop = new HashMap<>(); + private boolean _stemsGrown = false; + + public MushroomBridgeAnimation(Bridge bridge) + { + super(bridge); + } + + @Override + public void onParse() + { + for (Location loc : _worldData.GetCustomLocs("21")) + { + _mushroomStem.put(loc, 0L); + loc.getBlock().setType(Material.AIR); + } + + for (Location loc : _worldData.GetDataLocs("PURPLE")) + { + _mushroomTop.put(loc, 0L); + } + } + + @Override + public void onUpdate(UpdateType type) + { + if (_mushroomStem != null && !_mushroomStem.isEmpty()) + { + for (int i = 0; i < 4 && !_mushroomStem.isEmpty(); i++) + { + double lowestY = 0; + Location lowestLoc = null; + + for (Location loc : _mushroomStem.keySet()) + { + if (!UtilTime.elapsed(_mushroomStem.get(loc), 6000)) + continue; + + if (lowestLoc == null || loc.getY() < lowestY) + { + lowestY = loc.getY(); + lowestLoc = loc; + } + } + + if (lowestLoc == null) + continue; + + _mushroomStem.remove(lowestLoc); + + MapUtil.QuickChangeBlockAt(lowestLoc, 100, (byte) 15); + } + } + else + { + _stemsGrown = true; + } + + if (_stemsGrown && _mushroomTop != null && !_mushroomTop.isEmpty()) + { + int attempts = 0; + int done = 0; + while (done < 6 && attempts < 400) + { + attempts++; + + // Random Block + Location loc = UtilAlg.Random(_mushroomTop.keySet()); + + if (!UtilTime.elapsed(_mushroomTop.get(loc), 6000)) + continue; + + Block block = loc.getBlock(); + + if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR && block.getRelative(BlockFace.NORTH).getType() == Material.AIR && block.getRelative(BlockFace.EAST).getType() == Material.AIR && block.getRelative(BlockFace.SOUTH).getType() == Material.AIR && block.getRelative(BlockFace.WEST).getType() == Material.AIR) + continue; + + _mushroomTop.remove(loc); + + MapUtil.QuickChangeBlockAt(block.getLocation(), 99, (byte) 14); + + done++; + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java index b5710854f..178ae8ef1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java @@ -44,7 +44,7 @@ public class KitDestructor extends ProgressingKit { super(manager, "Destructor", "bridgedesctructor", KitAvailability.Achievement, 99999, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); - this.setAchievementRequirements(ACHIEVEMENTS); + setAchievementRequirements(ACHIEVEMENTS); } @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java index 17b6b5ce5..5935aaee0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java @@ -14,7 +14,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; @@ -29,7 +28,6 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.PlayerPrepareTeleportEvent; -import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.games.AbsorptionFix; import nautilus.game.arcade.game.games.bridge.Bridge; import net.md_5.bungee.api.ChatColor; @@ -72,38 +70,8 @@ public class OverpoweredBridge extends Bridge public void ParseData() { _starterChests = new HashMap<>(); - - ParseLavaBridge(); - ParseWoodBridge(); - ParseIceBridge(); - ParseLillyPad(); - ParseMushrooms(); - - ParseChests(); - - ParseOre(WorldData.GetCustomLocs("73")); // Red - ParseOre(WorldData.GetCustomLocs("14")); // Yellow - ParseOre(WorldData.GetCustomLocs("129")); // Green - ParseOre(WorldData.GetCustomLocs("56")); // Blue - - //Mass Teams - if (!WorldData.GetCustomLocs("152").isEmpty()) - ParseOre(WorldData.GetCustomLocs("152")); - if (!WorldData.GetCustomLocs("41").isEmpty()) - ParseOre(WorldData.GetCustomLocs("41")); - if (!WorldData.GetCustomLocs("133").isEmpty()) - ParseOre(WorldData.GetCustomLocs("133")); - if (!WorldData.GetCustomLocs("57").isEmpty()) - ParseOre(WorldData.GetCustomLocs("57")); - - if (!WorldData.GetCustomLocs("100").isEmpty()) - ParseOre(WorldData.GetCustomLocs("100")); - if (!WorldData.GetCustomLocs("86").isEmpty()) - ParseOre(WorldData.GetCustomLocs("86")); - if (!WorldData.GetCustomLocs("103").isEmpty()) - ParseOre(WorldData.GetCustomLocs("103")); - if (!WorldData.GetCustomLocs("22").isEmpty()) - ParseOre(WorldData.GetCustomLocs("22")); + + super.ParseData(); } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java index 5d63023a5..8c575627c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java @@ -294,7 +294,9 @@ public class PerkDestructor extends Perk if (lowest != null) { - if (lowest.getType() != Material.AIR && UtilBlock.airFoliage(lowest.getRelative(BlockFace.DOWN))) + Block down = lowest.getRelative(BlockFace.DOWN); + + if (lowest.getType() != Material.AIR && (UtilBlock.airFoliage(down) || down.isLiquid())) { lowest.getWorld().playEffect(lowest.getLocation(), Effect.STEP_SOUND, lowest.getType()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java index 5495e89a2..de127e6b2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.stats; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -40,6 +41,11 @@ public class FoodForTheMassesStatTracker extends StatTracker Player player = UtilPlayer.searchExact(event.GetLog().GetPlayer().GetName()); if (player == null) return; + + if (killer.getItemInHand().getType() != Material.APPLE) + { + return; + } if (event.GetLog().GetKiller().GetReason() != null && event.GetLog().GetKiller().GetReason().contains("Apple Thrower")) { From 36f318e4a0afaa8019835746c04454c35acbf984 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 6 Feb 2017 21:00:30 +0000 Subject: [PATCH 03/26] KP Upgrades (1) --- .../game/arcade/game/games/bridge/Bridge.java | 2 +- .../game/games/bridge/kits/KitApple.java | 74 ++++++++++++++- .../game/games/bridge/kits/KitBerserker.java | 93 +++++++++++++++---- .../game/games/skywars/kits/KitMetal.java | 4 + .../game/arcade/kit/ProgressingKit.java | 8 ++ 5 files changed, 158 insertions(+), 23 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index 813f8349a..eabc0b467 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -290,7 +290,7 @@ public class Bridge extends TeamGame implements OreObsfucation // If this is an old map or the builders haven't done it properly we can use this more of an estimate of the border size // Step 1 - Get the average location of the spawns, we will assume this is the centre of the island Location center = UtilAlg.getAverageLocation(team.GetSpawns()); - center.add(UtilAlg.getTrajectory(SpectatorSpawn, center).multiply(20)); + center.add(UtilAlg.getTrajectory(SpectatorSpawn, center).multiply(15)); // Step 2 - Calculate an estimate for the size of the border. We'll go with half but the setSize uses the radius so it works out the same to leave it like this double distToCenter = UtilMath.offset2d(SpectatorSpawn, center); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java index 78fc4acae..c3a40cdab 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java @@ -13,6 +13,9 @@ import org.bukkit.inventory.ItemStack; public class KitApple extends ProgressingKit { + private static final String PERK = "Apples"; + private static final String STARTING = "Starting amount"; + private static final String[] DESCRIPTION = { "Possess the rare skill of finding apples frequently!", "", @@ -20,20 +23,81 @@ public class KitApple extends ProgressingKit click(true, "the apple to throw it") }; - private static final Perk[] PERKS = { - new PerkApple(10000) - }; + private static final Perk[][] PERKS = + { + { + new PerkApple(17000) + }, + { + new PerkApple(15000) + }, + { + new PerkApple(15000) + }, + { + new PerkApple(13000) + }, + { + new PerkApple(13000) + }, + { + new PerkApple(11000) + }, + }; + + private static final String[][] UPGRADE_DETAILS = + { + { + reduceCooldown(COOLDOWN, 2) + }, + { + increaseNumber(PERK, STARTING, 3, PERK) + }, + { + reduceCooldown(COOLDOWN, 2) + }, + { + increaseNumber(PERK, STARTING, 3, PERK) + }, + { + reduceCooldown(COOLDOWN, 2) + }, + }; private static final ItemStack IN_HAND = new ItemStack(Material.APPLE); public KitApple(ArcadeManager manager) { - super(manager, "Apple", "bridgeapple", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); + super(manager, "Apple", "bridgeapple", KitAvailability.Free, DESCRIPTION, PERKS, UPGRADE_DETAILS, EntityType.ZOMBIE, IN_HAND); } @Override public void GiveItems(Player player) { - + int level = getUpgradeLevel(player.getUniqueId()); + int apples = 0; + + switch (level) + { + case 2: + case 3: + apples = 3; + break; + case 4: + case 5: + apples = 6; + default: + break; + } + + if (apples > 0) { + player.getInventory().addItem(new ItemStack(Material.APPLE, apples)); + } + } + + @Override + public boolean showUpgrades() + { + return true; } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java index 497017ee6..5d76bf540 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java @@ -1,17 +1,17 @@ package nautilus.game.arcade.game.games.bridge.kits; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + import mineplex.core.common.util.C; -import mineplex.core.itemstack.ItemStackFactory; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.ProgressingKit; import nautilus.game.arcade.kit.perks.PerkAxeman; import nautilus.game.arcade.kit.perks.PerkLeap; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; public class KitBerserker extends ProgressingKit { @@ -23,27 +23,86 @@ public class KitBerserker extends ProgressingKit "Deal " + C.cGreen + "+1" + C.cWhite + " damage using axes", click(false, " with your axe to use " + C.cGreen + "Berserker Leap") }; - - private static final Perk[] PERKS = { - new PerkLeap("Beserker Leap", 1.2, 1.2, 8000), - new PerkAxeman(), - }; - - private static final ItemStack[] PLAYER_ITEMS = { - ItemStackFactory.Instance.CreateStack(Material.STONE_AXE) - }; + + private static final Perk[][] PERKS = + { + { + new PerkLeap("Beserker Leap", 1.2, 1.2, 14000), + new PerkAxeman(), + }, + { + new PerkLeap("Beserker Leap", 1.2, 1.2, 13000), + new PerkAxeman(), + }, + { + new PerkLeap("Beserker Leap", 1.2, 1.2, 13000), + new PerkAxeman(), + }, + { + new PerkLeap("Beserker Leap", 1.2, 1.2, 12000), + new PerkAxeman(), + }, + { + new PerkLeap("Beserker Leap", 1.2, 1.2, 12000), + new PerkAxeman(), + }, + { + new PerkLeap("Beserker Leap", 1.2, 1.2, 11000), + new PerkAxeman(), + }, + }; + + private static final String[][] UPGRADE_DETAILS = + { + { + reduceCooldown(COOLDOWN, 1) + }, + { + receiveItem("Crafting Table", 1) + }, + { + reduceCooldown(COOLDOWN, 1) + }, + { + receiveItem("Iron Axe", 1) + }, + { + reduceCooldown(COOLDOWN, 1) + }, + }; private static final ItemStack IN_HAND = new ItemStack(Material.STONE_AXE); public KitBerserker(ArcadeManager manager) { - super(manager, "Berserker", "bridgeberserker", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); - + super(manager, "Berserker", "bridgeberserker", KitAvailability.Free, DESCRIPTION, PERKS, UPGRADE_DETAILS, EntityType.ZOMBIE, IN_HAND); } @Override public void GiveItems(Player player) { - player.getInventory().addItem(PLAYER_ITEMS); + int level = getUpgradeLevel(player.getUniqueId()); + + // Axe + if (level >= 4) + { + player.getInventory().addItem(new ItemStack(Material.IRON_AXE)); + } + else + { + player.getInventory().addItem(new ItemStack(Material.STONE_AXE)); + } + + //Crafting table + if (level >= 2) + { + player.getInventory().addItem(new ItemStack(Material.WORKBENCH)); + } + } + + @Override + public boolean showUpgrades() + { + return true; } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java index a5e4be83e..5d6cf5ff5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java @@ -90,6 +90,10 @@ public class KitMetal extends ProgressingKit @Override public void GiveItems(Player player) { + int level = getUpgradeLevel(player.getUniqueId()); + + + player.getInventory().addItem(PLAYER_ITEMS); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java index a93f7415e..eabe114f5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java @@ -30,6 +30,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilText; import mineplex.core.donation.Donor; import mineplex.core.menu.Menu; import mineplex.core.progression.ProgressiveKit; @@ -53,6 +54,8 @@ import net.minecraft.server.v1_8_R3.World; public abstract class ProgressingKit extends Kit implements ProgressiveKit { + public static final String COOLDOWN = "Cooldown"; + private static final FireworkEffect EFFECT = FireworkEffect.builder() .withColor(Color.AQUA) .with(Type.BALL) @@ -420,6 +423,11 @@ public abstract class ProgressingKit extends Kit implements ProgressiveKit return "Receive " + C.cGreen + amount + C.cWhite + " " + item + " every " + C.cGreen + time + C.cWhite + " second" + (time == 1 ? "" : "s") + (max > 0 ? ". Max " + C.cGreen + max : ""); } + + public static String receiveItem(String item, int amount) + { + return "Receive " + (amount == 1 ? (UtilText.startsWithVowel(item) ? "an" :" a") : C.cGreen + amount) + " " + item; + } public static String click(boolean left, String comp) { From 3018f264ccab79a3d7952eef46ea3de1f4c6a66d Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 6 Feb 2017 23:28:27 +0000 Subject: [PATCH 04/26] QA ready! --- .../src/nautilus/game/arcade/game/games/bridge/Bridge.java | 2 +- .../nautilus/game/arcade/game/games/bridge/kits/KitApple.java | 2 +- .../game/arcade/game/games/bridge/kits/KitBerserker.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index eabc0b467..c01dde25e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -299,7 +299,7 @@ public class Bridge extends TeamGame implements OreObsfucation for (Player player : team.GetPlayers(true)) { borderModule.setCenter(player, center); - borderModule.setSize(player, distToCenter * 0.6); + borderModule.setSize(player, distToCenter * 0.8); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java index c3a40cdab..e915f72b4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java @@ -98,6 +98,6 @@ public class KitApple extends ProgressingKit @Override public boolean showUpgrades() { - return true; + return false; } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java index 5d76bf540..70f3591a4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java @@ -103,6 +103,6 @@ public class KitBerserker extends ProgressingKit @Override public boolean showUpgrades() { - return true; + return false; } } From 2f9f55226a161e687920effaa8438510422dc73f Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 7 Feb 2017 00:05:10 +0000 Subject: [PATCH 05/26] Adjust world border distance --- .../src/nautilus/game/arcade/game/games/bridge/Bridge.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index c01dde25e..beaf472c5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -299,7 +299,7 @@ public class Bridge extends TeamGame implements OreObsfucation for (Player player : team.GetPlayers(true)) { borderModule.setCenter(player, center); - borderModule.setSize(player, distToCenter * 0.8); + borderModule.setSize(player, distToCenter * 0.9); } } From a49b19ee0cc51fd6df697ffe3226168efed9d112 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 14 Mar 2017 16:08:16 +0000 Subject: [PATCH 06/26] Removal of kit progression from bridges --- .../game/games/bridge/kits/KitApple.java | 76 ++------------- .../game/games/bridge/kits/KitArcher.java | 2 +- .../game/games/bridge/kits/KitBerserker.java | 95 ++++--------------- 3 files changed, 25 insertions(+), 148 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java index e915f72b4..021c06e83 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java @@ -13,9 +13,6 @@ import org.bukkit.inventory.ItemStack; public class KitApple extends ProgressingKit { - private static final String PERK = "Apples"; - private static final String STARTING = "Starting amount"; - private static final String[] DESCRIPTION = { "Possess the rare skill of finding apples frequently!", "", @@ -23,81 +20,20 @@ public class KitApple extends ProgressingKit click(true, "the apple to throw it") }; - private static final Perk[][] PERKS = - { - { - new PerkApple(17000) - }, - { - new PerkApple(15000) - }, - { - new PerkApple(15000) - }, - { - new PerkApple(13000) - }, - { - new PerkApple(13000) - }, - { - new PerkApple(11000) - }, - }; - - private static final String[][] UPGRADE_DETAILS = - { - { - reduceCooldown(COOLDOWN, 2) - }, - { - increaseNumber(PERK, STARTING, 3, PERK) - }, - { - reduceCooldown(COOLDOWN, 2) - }, - { - increaseNumber(PERK, STARTING, 3, PERK) - }, - { - reduceCooldown(COOLDOWN, 2) - }, - }; + private static final Perk[] PERKS = { + new PerkApple(10000) + }; private static final ItemStack IN_HAND = new ItemStack(Material.APPLE); public KitApple(ArcadeManager manager) { - super(manager, "Apple", "bridgeapple", KitAvailability.Free, DESCRIPTION, PERKS, UPGRADE_DETAILS, EntityType.ZOMBIE, IN_HAND); + super(manager, "Apple", "bridgeapple", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); } @Override public void GiveItems(Player player) { - int level = getUpgradeLevel(player.getUniqueId()); - int apples = 0; - - switch (level) - { - case 2: - case 3: - apples = 3; - break; - case 4: - case 5: - apples = 6; - default: - break; - } - - if (apples > 0) { - player.getInventory().addItem(new ItemStack(Material.APPLE, apples)); - } + } - - @Override - public boolean showUpgrades() - { - return false; - } -} +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java index a02a04427..87ee2d8dd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java @@ -53,6 +53,6 @@ public class KitArcher extends ProgressingKit Bridge bridge = (Bridge) Manager.GetGame(); if(!bridge.hasUsedRevive(player)) - player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW)); + player.getInventory().addItem(PLAYER_ITEMS); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java index 70f3591a4..9204c8d7a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java @@ -1,17 +1,17 @@ package nautilus.game.arcade.game.games.bridge.kits; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemStackFactory; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.ProgressingKit; import nautilus.game.arcade.kit.perks.PerkAxeman; import nautilus.game.arcade.kit.perks.PerkLeap; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; public class KitBerserker extends ProgressingKit { @@ -23,86 +23,27 @@ public class KitBerserker extends ProgressingKit "Deal " + C.cGreen + "+1" + C.cWhite + " damage using axes", click(false, " with your axe to use " + C.cGreen + "Berserker Leap") }; - - private static final Perk[][] PERKS = - { - { - new PerkLeap("Beserker Leap", 1.2, 1.2, 14000), - new PerkAxeman(), - }, - { - new PerkLeap("Beserker Leap", 1.2, 1.2, 13000), - new PerkAxeman(), - }, - { - new PerkLeap("Beserker Leap", 1.2, 1.2, 13000), - new PerkAxeman(), - }, - { - new PerkLeap("Beserker Leap", 1.2, 1.2, 12000), - new PerkAxeman(), - }, - { - new PerkLeap("Beserker Leap", 1.2, 1.2, 12000), - new PerkAxeman(), - }, - { - new PerkLeap("Beserker Leap", 1.2, 1.2, 11000), - new PerkAxeman(), - }, - }; - - private static final String[][] UPGRADE_DETAILS = - { - { - reduceCooldown(COOLDOWN, 1) - }, - { - receiveItem("Crafting Table", 1) - }, - { - reduceCooldown(COOLDOWN, 1) - }, - { - receiveItem("Iron Axe", 1) - }, - { - reduceCooldown(COOLDOWN, 1) - }, - }; + + private static final Perk[] PERKS = { + new PerkLeap("Beserker Leap", 1.2, 1.2, 8000), + new PerkAxeman(), + }; + + private static final ItemStack[] PLAYER_ITEMS = { + ItemStackFactory.Instance.CreateStack(Material.STONE_AXE) + }; private static final ItemStack IN_HAND = new ItemStack(Material.STONE_AXE); public KitBerserker(ArcadeManager manager) { - super(manager, "Berserker", "bridgeberserker", KitAvailability.Free, DESCRIPTION, PERKS, UPGRADE_DETAILS, EntityType.ZOMBIE, IN_HAND); + super(manager, "Berserker", "bridgeberserker", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); + } @Override public void GiveItems(Player player) { - int level = getUpgradeLevel(player.getUniqueId()); - - // Axe - if (level >= 4) - { - player.getInventory().addItem(new ItemStack(Material.IRON_AXE)); - } - else - { - player.getInventory().addItem(new ItemStack(Material.STONE_AXE)); - } - - //Crafting table - if (level >= 2) - { - player.getInventory().addItem(new ItemStack(Material.WORKBENCH)); - } + player.getInventory().addItem(PLAYER_ITEMS); } - - @Override - public boolean showUpgrades() - { - return false; - } -} +} \ No newline at end of file From c8a9cffcdf54ff67bd44c072db8937128227e2d3 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 14 Mar 2017 16:08:31 +0000 Subject: [PATCH 07/26] Edit the documentation for per player world borders --- .../nautilus/game/arcade/game/games/bridge/Bridge.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index beaf472c5..5995d93d3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -287,19 +287,19 @@ public class Bridge extends TeamGame implements OreObsfucation // Here we do some calculations for per player world borders for (GameTeam team : GetTeamList()) { - // If this is an old map or the builders haven't done it properly we can use this more of an estimate of the border size - // Step 1 - Get the average location of the spawns, we will assume this is the centre of the island + // Step 1 - Get the average location of the spawns, we assume this is generally in an OK position. Location center = UtilAlg.getAverageLocation(team.GetSpawns()); + // Step 1.5 - Move the location back a bit from the centre, this is usually because spawns are on the inside edge of the islands. center.add(UtilAlg.getTrajectory(SpectatorSpawn, center).multiply(15)); // Step 2 - Calculate an estimate for the size of the border. We'll go with half but the setSize uses the radius so it works out the same to leave it like this - double distToCenter = UtilMath.offset2d(SpectatorSpawn, center); + double distToCenter = UtilMath.offset2d(SpectatorSpawn, center) * 0.9; // Step 3 - Send the setCenter and setSize packets to the team members for (Player player : team.GetPlayers(true)) { borderModule.setCenter(player, center); - borderModule.setSize(player, distToCenter * 0.9); + borderModule.setSize(player, distToCenter); } } From b35a9582df77c332f543375cec5a69b864af1a07 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 14 Mar 2017 17:07:36 +0000 Subject: [PATCH 08/26] Optimise PlayParticle --- .../src/mineplex/core/common/util/UtilParticle.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java index 0945ad7fd..7b85b4971 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java @@ -372,11 +372,12 @@ public class UtilParticle int count, ViewDist dist, Player... players) { PacketPlayOutWorldParticles packet = getPacket(particle, location, offsetX, offsetY, offsetZ, speed, count, true); - + int distValue = dist.getDist() * dist.getDist(); + for (Player player : players) { // Out of range for player - if (UtilMath.offset(player.getLocation(), location) > dist.getDist()) + if (UtilMath.offsetSquared(player.getLocation(), location) > distValue) continue; UtilPlayer.sendPacket(player, packet); From 15d691370de59b3083898dad461f19a20ff59a52 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 14 Mar 2017 21:05:52 +0000 Subject: [PATCH 09/26] Configuration for bridges --- .../game/arcade/game/games/bridge/Bridge.java | 88 +++++-- .../animation/CustomBridgeAnimation.java | 153 ----------- .../bridge/animation/WoodBridgeAnimation.java | 2 +- .../custom/CustomBridgeAnimation.java | 246 ++++++++++++++++++ .../custom/RadiusCustomBridgeAnimation.java | 58 +++++ .../custom/RandomCustomBridgeAnimation.java | 44 ++++ 6 files changed, 420 insertions(+), 171 deletions(-) delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index 5995d93d3..3a0e97fc6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -37,7 +37,6 @@ import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.CraftingInventory; @@ -70,12 +69,15 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.DebugCommand; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimation; import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimationType; -import nautilus.game.arcade.game.games.bridge.animation.CustomBridgeAnimation; +import nautilus.game.arcade.game.games.bridge.animation.custom.CustomBridgeAnimation; +import nautilus.game.arcade.game.games.bridge.animation.custom.RadiusCustomBridgeAnimation; +import nautilus.game.arcade.game.games.bridge.animation.custom.RandomCustomBridgeAnimation; import nautilus.game.arcade.game.games.bridge.kits.KitApple; import nautilus.game.arcade.game.games.bridge.kits.KitArcher; import nautilus.game.arcade.game.games.bridge.kits.KitBerserker; @@ -114,11 +116,14 @@ public class Bridge extends TeamGame implements OreObsfucation */ private static final int WORLD_BORDER_PREPARE_TICKS = 20; + private static final String CUSTOM_BRIDGE_KEY = "TYPE"; + //Bridge private long _bridgeTime = BRIDGE_TIME; private boolean _bridgesDown = false; private BridgeAnimation _animation; - + private CustomBridgeAnimation[] _customAnimations; + private HashSet _bridgeParts = new HashSet(); //Animals @@ -249,6 +254,11 @@ public class Bridge extends TeamGame implements OreObsfucation _tournament = true; } + _customAnimations = new CustomBridgeAnimation[] { + new RandomCustomBridgeAnimation(this), + new RadiusCustomBridgeAnimation(this) + }; + new CompassModule() .setGiveCompassToAlive(true) .register(this); @@ -269,6 +279,34 @@ public class Bridge extends TeamGame implements OreObsfucation break; } } + + registerDebugCommand(new DebugCommand("bridge", Rank.ADMIN) + { + + @Override + public void Execute(Player caller, String[] args) + { + caller.sendMessage(F.main("Debug", "Spawning the bridges.")); + _bridgeTime = 3000; + } + }); + + registerDebugCommand(new DebugCommand("bridgeinfo", getArcadeManager().getGameCommandRank()) + { + + @Override + public void Execute(Player caller, String[] args) + { + if (_animation == null || !(_animation instanceof CustomBridgeAnimation)) + { + caller.sendMessage(F.main("Debug", "The bridge animation for this map isn't a custom one.")); + return; + } + + caller.sendMessage(F.main("Debug", "Bridge Info:")); + caller.sendMessage(_animation.toString()); + } + }); } @EventHandler @@ -354,15 +392,41 @@ public class Bridge extends TeamGame implements OreObsfucation } _animation = type.createInstance(this); - _animation.onParse(); + break; } + // If none of the premade ones are usable then we need a custom one! if (_animation == null) { - _animation = new CustomBridgeAnimation(this); - _animation.onParse(); + locationLoop : for (String key : WorldData.GetAllCustomLocs().keySet()) + { + if (!key.startsWith(CUSTOM_BRIDGE_KEY)) + { + continue; + } + + String[] split = key.split(" "); + + if (split.length < 2) + { + continue; + } + + String subKey = split[1]; + + for (CustomBridgeAnimation animation : _customAnimations) + { + if (animation.getTypeKey().equalsIgnoreCase(subKey)) + { + _animation = animation; + break locationLoop; + } + } + } } + _animation.onParse(); + ParseChests(); ParseOre(WorldData.GetCustomLocs("73")); // Red @@ -727,7 +791,7 @@ public class Bridge extends TeamGame implements OreObsfucation for (Player player : GetPlayers(true)) { - borderModule.setSize(player, 1000); + borderModule.setSize(player, 10000); } Manager.GetExplosion().SetLiquidDamage(true); @@ -1713,16 +1777,6 @@ public class Bridge extends TeamGame implements OreObsfucation else return 12; } - - @EventHandler - public void debug(PlayerCommandPreprocessEvent event) - { - if (Manager.GetClients().hasRank(event.getPlayer(), Rank.ADMIN) && event.getMessage().contains("/oretoggle")) - _ore.ToggleVisibility(); - - if (Manager.GetClients().hasRank(event.getPlayer(), Rank.ADMIN) && event.getMessage().contains("/bridge")) - _bridgeTime = 3000; - } @EventHandler public void disableIceForm(BlockFormEvent event) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java deleted file mode 100644 index 921676590..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/CustomBridgeAnimation.java +++ /dev/null @@ -1,153 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; - -import mineplex.core.blockrestore.BlockRestore; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilParticle.ParticleType; -import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; - -public class CustomBridgeAnimation extends BridgeAnimation -{ - - private static final String REGION_KEY = "BRIDGE"; - private static final String BRIDGE_DATA_KEY = "CUSTOM_BRIDGE"; - private static final double RATE = 0.5; - - private final BlockRestore _restore; - private final Map _bridgeBlocks; - - private int[] _blockIds; - - private double _maxDistance; - private double _minDistance; - - public CustomBridgeAnimation(Bridge bridge) - { - super(bridge); - - _restore = bridge.getArcadeManager().GetBlockRestore(); - _bridgeBlocks = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); - } - - @Override - public void onParse() - { - _maxDistance = 0; - - for (String key : _worldData.GetAllCustomLocs().keySet()) - { - if (!key.startsWith(BRIDGE_DATA_KEY)) - { - continue; - } - - String[] split = key.split(" "); - int[] blockIds = new int[split.length - 1]; - - for (int i = 1; i < split.length; i++) - { - try - { - blockIds[i - 1] = Integer.parseInt(split[i]); - } - catch (NumberFormatException e) - { - continue; - } - } - - _blockIds = blockIds; - } - - for (String key : _worldData.GetAllCustomLocs().keySet()) - { - if (!key.startsWith(REGION_KEY)) - { - continue; - } - - List locations = _worldData.GetCustomLocs(key); - - if (locations.size() < 2) - { - continue; - } - - for (Block block : UtilBlock.getInBoundingBox(locations.get(0), locations.get(1))) - { - boolean shouldAdd = false; - - for (int id : _blockIds) - { - if (block.getTypeId() == id) - { - shouldAdd = true; - break; - } - } - - if (!shouldAdd) - { - continue; - } - - double dist = UtilMath.offset2d(block.getLocation(), _bridge.GetSpectatorLocation()); - - if (dist > _maxDistance) - { - _maxDistance = dist; - } - - _restore.add(block, Material.AIR.getId(), (byte) 0, Integer.MAX_VALUE); - _bridgeBlocks.put(block.getLocation(), dist); - } - } - - _minDistance = _maxDistance; - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.FAST) - { - return; - } - - _minDistance -= RATE; - - Iterator iterator = _bridgeBlocks.keySet().iterator(); - - while (iterator.hasNext()) - { - Location location = iterator.next(); - double dist = _bridgeBlocks.get(location); - - if (dist > _minDistance) - { - Block block = location.getBlock(); - - _restore.restore(block); - UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, block.getLocation().add(0.5, 1.5, 0.5), 0.25F, 0.25F, 0.25F, 0.05F, 5, ViewDist.NORMAL); - - location.getWorld().playSound(location, Sound.ZOMBIE_UNFECT, 1.5F, 1); - - iterator.remove(); - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java index ecafe937b..e149f2bc3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java @@ -108,7 +108,7 @@ public class WoodBridgeAnimation extends BridgeAnimation } } - if (toDo.size() == 0) + if (toDo.isEmpty()) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java new file mode 100644 index 000000000..18f45bd3f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java @@ -0,0 +1,246 @@ +package nautilus.game.arcade.game.games.bridge.animation.custom; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.block.Block; + +import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import nautilus.game.arcade.game.games.bridge.Bridge; +import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimation; + +public abstract class CustomBridgeAnimation extends BridgeAnimation +{ + + private static final String BLOCK_IDS_KEY = "BLOCK_IDS"; + private static final String RATE_KEY = "RATE"; + private static final String PARTICLE_KEY = "PARTICLE"; + private static final String SOUND_KEY = "SOUND"; + private static final String REGION_KEY = "BRIDGE"; + + protected final BlockRestore _restore; + + private final String _typeKey; + protected final Map _bridgeBlocks; + + // Configuration + protected List _blockIds; + protected int _rate; + protected ParticleType _particle; + + // Sound + protected Sound _sound; + protected float _pitch; + + protected double _maxDistance; + + public CustomBridgeAnimation(Bridge bridge, String typeKey) + { + super(bridge); + + _restore = bridge.getArcadeManager().GetBlockRestore(); + + _typeKey = typeKey; + _bridgeBlocks = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); + + // Defaults + // Wood, Logs, Fences + _blockIds = Arrays.asList(5, 17, 85); + _rate = 1; + _particle = ParticleType.BLOCK_DUST; + } + + @Override + public void onParse() + { + List blockIds = new ArrayList<>(); + + for (String key : _worldData.GetAllCustomLocs().keySet()) + { + String[] split = key.split(" "); + String subKey = split[0]; + + if (split.length < 2) + { + continue; + } + + switch (subKey) + { + + case BLOCK_IDS_KEY: + // Set the block ids that the animation will use + + for (int i = 1; i < split.length; i++) + { + try + { + blockIds.add(Integer.parseInt(split[i])); + } + catch (NumberFormatException e) + { + continue; + } + } + + break; + + case RATE_KEY: + // Set the rate at which the animation will run at + + try + { + _rate = Integer.parseInt(split[1]); + } + catch (NumberFormatException e) + { + continue; + } + + break; + + case PARTICLE_KEY: + // Set which type of particle will be displayed when a block + // spawns + + try + { + _particle = ParticleType.valueOf(split[1]); + } + catch (IllegalArgumentException e) + { + continue; + } + + break; + + case SOUND_KEY: + // Set the sound and pitch that will be played when a block + // spawns + + if (split.length < 3) + { + continue; + } + + try + { + _sound = Sound.valueOf(split[1]); + } + catch (IllegalArgumentException e) + { + continue; + } + + try + { + _pitch = Float.parseFloat(split[2]); + } + catch (NumberFormatException e) + { + continue; + } + + break; + + default: + break; + } + } + + // Set configuration values + _blockIds = blockIds; + + // Save all blocks in a big map. + for (String key : _worldData.GetAllCustomLocs().keySet()) + { + if (!key.startsWith(REGION_KEY)) + { + continue; + } + + List locations = _worldData.GetCustomLocs(key); + + if (locations.size() < 2) + { + continue; + } + + for (Block block : UtilBlock.getInBoundingBox(locations.get(0), locations.get(1))) + { + if (!_blockIds.contains(block.getTypeId())) + { + continue; + } + + double dist = UtilMath.offset2d(block.getLocation(), _bridge.GetSpectatorLocation()); + + if (dist > _maxDistance) + { + _maxDistance = dist; + } + + _restore.add(block, Material.AIR.getId(), (byte) 0, Integer.MAX_VALUE); + _bridgeBlocks.put(block.getLocation(), dist); + } + } + } + + public void onBlockSet(Block block) + { + World world = _worldData.World; + Location location = block.getLocation().add(0.5, 0.5, 0.5); + + if (_particle != null) + { + if (_particle == ParticleType.BLOCK_DUST) + { + world.playEffect(location, Effect.STEP_SOUND, block.getType(), block.getData()); + } + else + { + UtilParticle.PlayParticleToAll(_particle, block.getLocation(), 0.5F, 0.5F, 0.5F, 0.5F, 5, ViewDist.NORMAL); + } + } + + if (_sound != null) + { + world.playSound(location, _sound, 1, _pitch); + } + } + + public final String getTypeKey() + { + return _typeKey; + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + + builder.append("Type: " + _typeKey).append("\n"); + builder.append("Bridge Blocks: " + _bridgeBlocks.size()).append("\n"); + builder.append("Block Ids: " + _blockIds).append("\n"); + builder.append("Rate: " + _rate).append("\n"); + builder.append("Particle: " + (_particle == null ? "Null" : _particle.getFriendlyName())).append("\n"); + builder.append("Sound: " + (_sound == null ? "Null" : _sound.toString() + " Pitch: " + _pitch)).append("\n"); + builder.append("Max Distance: " + _maxDistance).append("\n"); + + return builder.toString(); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java new file mode 100644 index 000000000..fe0779c7c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java @@ -0,0 +1,58 @@ +package nautilus.game.arcade.game.games.bridge.animation.custom; + +import java.util.Iterator; + +import org.bukkit.Location; +import org.bukkit.block.Block; + +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class RadiusCustomBridgeAnimation extends CustomBridgeAnimation +{ + + private double _minDistance; + + public RadiusCustomBridgeAnimation(Bridge bridge) + { + super(bridge, "RADIUS"); + } + + @Override + public void onParse() + { + super.onParse(); + + _minDistance = _maxDistance; + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.FAST) + { + return; + } + + _minDistance -= _rate; + + Iterator iterator = _bridgeBlocks.keySet().iterator(); + + while (iterator.hasNext()) + { + Location location = iterator.next(); + double dist = _bridgeBlocks.get(location); + + if (dist > _minDistance) + { + Block block = location.getBlock(); + + _restore.restore(block); + onBlockSet(block); + + iterator.remove(); + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java new file mode 100644 index 000000000..badf135bb --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java @@ -0,0 +1,44 @@ +package nautilus.game.arcade.game.games.bridge.animation.custom; + +import java.util.Iterator; + +import org.bukkit.Location; +import org.bukkit.block.Block; + +import mineplex.core.updater.UpdateType; +import nautilus.game.arcade.game.games.bridge.Bridge; + +public class RandomCustomBridgeAnimation extends CustomBridgeAnimation +{ + + public RandomCustomBridgeAnimation(Bridge bridge) + { + super(bridge, "RANDOM"); + } + + @Override + public void onUpdate(UpdateType type) + { + if (type != UpdateType.TICK) + { + return; + } + + Iterator iterator = _bridgeBlocks.keySet().iterator(); + int i = 0; + + while (iterator.hasNext() && i < _rate) + { + i++; + Location location = iterator.next(); + + Block block = location.getBlock(); + + _restore.restore(block); + onBlockSet(block); + + iterator.remove(); + } + } + +} From 8e5a5695d53add3216320974df973adee78443eb Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Mar 2017 17:03:53 +0000 Subject: [PATCH 10/26] Fix early game revive --- .../game/arcade/game/games/bridge/Bridge.java | 177 +++++------------- 1 file changed, 52 insertions(+), 125 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index 3a0e97fc6..bf646fa6e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -1,65 +1,8 @@ package nautilus.game.arcade.game.games.bridge; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.bukkit.ChatColor; -import org.bukkit.Effect; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.Chest; -import org.bukkit.entity.Chicken; -import org.bukkit.entity.Cow; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Item; -import org.bukkit.entity.Pig; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockFormEvent; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.inventory.CraftItemEvent; -import org.bukkit.event.inventory.PrepareItemCraftEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.inventory.CraftingInventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.util.Vector; - import mineplex.core.common.Rank; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.*; import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.common.util.UtilGear; -import mineplex.core.common.util.UtilInv; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; import mineplex.core.explosion.ExplosionEvent; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.updater.UpdateType; @@ -78,14 +21,7 @@ import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimationType; import nautilus.game.arcade.game.games.bridge.animation.custom.CustomBridgeAnimation; import nautilus.game.arcade.game.games.bridge.animation.custom.RadiusCustomBridgeAnimation; import nautilus.game.arcade.game.games.bridge.animation.custom.RandomCustomBridgeAnimation; -import nautilus.game.arcade.game.games.bridge.kits.KitApple; -import nautilus.game.arcade.game.games.bridge.kits.KitArcher; -import nautilus.game.arcade.game.games.bridge.kits.KitBerserker; -import nautilus.game.arcade.game.games.bridge.kits.KitBomber; -import nautilus.game.arcade.game.games.bridge.kits.KitBrawler; -import nautilus.game.arcade.game.games.bridge.kits.KitDestructor; -import nautilus.game.arcade.game.games.bridge.kits.KitMammoth; -import nautilus.game.arcade.game.games.bridge.kits.KitMiner; +import nautilus.game.arcade.game.games.bridge.kits.*; import nautilus.game.arcade.game.modules.WorldBorderModule; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; @@ -93,11 +29,38 @@ import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.perks.PerkDestructor; import nautilus.game.arcade.ore.OreHider; import nautilus.game.arcade.ore.OreObsfucation; -import nautilus.game.arcade.stats.BridgesSniperStatTracker; -import nautilus.game.arcade.stats.DeathBomberStatTracker; -import nautilus.game.arcade.stats.FoodForTheMassesStatTracker; -import nautilus.game.arcade.stats.KillFastStatTracker; -import nautilus.game.arcade.stats.TntMinerStatTracker; +import nautilus.game.arcade.stats.*; +import org.bukkit.Effect; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.util.Vector; + +import java.util.*; +import java.util.concurrent.TimeUnit; public class Bridge extends TeamGame implements OreObsfucation { @@ -144,7 +107,7 @@ public class Bridge extends TeamGame implements OreObsfucation private int _buildHeight = -1; //Player Respawn - private HashSet _usedLife = new HashSet(); + private Set _usedLife = new HashSet<>(); //Tourney Mode private boolean _tournament; @@ -204,7 +167,7 @@ public class Bridge extends TeamGame implements OreObsfucation _ore = new OreHider(); // Flags - GameTimeout = Manager.IsTournamentServer() ? 5400000 : 3600000; + GameTimeout = Manager.IsTournamentServer() ? TimeUnit.MINUTES.toMillis(90) : TimeUnit.MINUTES.toMillis(60); Manager.GetExplosion().SetLiquidDamage(false); @@ -766,84 +729,48 @@ public class Bridge extends TeamGame implements OreObsfucation } @EventHandler - public void BridgeBuild(UpdateEvent event) + public void BridgeBuild(UpdateEvent event) { if (!IsLive() || !UtilTime.elapsed(GetStateTime(), _bridgeTime)) { return; } - + if (_animation != null) { _animation.onUpdate(event.getType()); } - + if (event.getType() != UpdateType.FAST) { return; } - + if (!_bridgesDown) { _bridgesDown = true; - + WorldBorderModule borderModule = getModule(WorldBorderModule.class); - + for (Player player : GetPlayers(true)) { borderModule.setSize(player, 10000); } - + Manager.GetExplosion().SetLiquidDamage(true); Announce(C.cRedB + "ALERT: " + C.Reset + C.Bold + "THE BRIDGES ARE SPAWNING!"); UtilTextMiddle.display(C.cRedB + "ALERT", "The BRIDGES ARE SPAWNING!"); - + for (Kit kit : GetKits()) { if (kit instanceof KitDestructor) { - ((KitDestructor)kit).SetEnabled(true); + ((KitDestructor) kit).SetEnabled(true); } } } } - -// @EventHandler -// public void breakLillyPad(BlockBreakEvent event) -// { -// if (event.getBlock().getType() != Material.WATER_LILY) -// return; -// -// _lillyPads.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); -// } - -// @EventHandler -// public void breakMushroom(BlockBreakEvent event) -// { -// if (event.isCancelled()) -// return; -// -// -// if (event.getBlock().getTypeId() == 100 && -// WorldData.GetCustomLocs("21").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) -// { -// event.setCancelled(true); -// event.getBlock().setType(Material.AIR); -// -// _mushroomStem.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); -// } -// -// if (event.getBlock().getTypeId() == 99 && -// WorldData.GetDataLocs("PURPLE").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) -// { -// event.setCancelled(true); -// event.getBlock().setType(Material.AIR); -// -// _mushroomTop.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); -// } -// } - @EventHandler public void BridgeUpdate(UpdateEvent event) { @@ -1534,7 +1461,7 @@ public class Bridge extends TeamGame implements OreObsfucation { _tournamentKillMessageTimer = System.currentTimeMillis(); - this.Announce(C.cRed + C.Bold + "ALERT: " + ChatColor.RESET + C.Bold + "FIRST TEAM TO HAVE MOST KILLS WINS!"); + Announce(C.cRed + C.Bold + "ALERT: " + C.Reset + C.Bold + "FIRST TEAM TO HAVE MOST KILLS WINS!"); } } @@ -1728,16 +1655,16 @@ public class Bridge extends TeamGame implements OreObsfucation } @EventHandler(priority=EventPriority.LOWEST) - public void revivePlayer(EntityDamageEvent event) + public void revivePlayer(CustomDamageEvent event) { - if (_bridgesDown || !(event.getEntity() instanceof Player)) + if (_bridgesDown || !(event.GetDamageeEntity() instanceof Player)) { return; } - - Player player = (Player) event.getEntity(); - if (player.getHealth() - event.getDamage() > 0) + Player player = event.GetDamageePlayer(); + + if (player.getHealth() - event.GetDamage() > 0) { return; } @@ -1750,7 +1677,7 @@ public class Bridge extends TeamGame implements OreObsfucation GetTeam(player).SpawnTeleport(player); player.setHealth(20); - event.setCancelled(true); + event.SetCancelled("Early Game Revive"); } } From df8ed9013874456311fc5e1bfe9bac246a45d9e4 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Mar 2017 23:44:42 +0000 Subject: [PATCH 11/26] Ops, forgot to enable reports. Eclipse is bad --- .../src/nautilus/game/arcade/Arcade.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 9c10cf9c2..6478db304 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -159,10 +159,10 @@ public class Arcade extends JavaPlugin Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); -// SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); -// ReportManager reportManager = new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1); -// new SnapshotPlugin(this, snapshotManager, _clientManager); -// new ReportPlugin(this, reportManager); + SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); + ReportManager reportManager = new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1); + new SnapshotPlugin(this, snapshotManager, _clientManager); + new ReportPlugin(this, reportManager); BlockRestore blockRestore = require(BlockRestore.class); From 18538d918ceacee21add7a7d483848bc211620b4 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Mar 2017 23:51:13 +0000 Subject: [PATCH 12/26] And 2FA wow, this is why you skim read PRs --- .../src/mineplex/core/twofactor/TwoFactorAuth.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java index 02d2705e8..32107d3f6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java @@ -185,7 +185,7 @@ public class TwoFactorAuth extends MiniClientPlugin player.sendMessage(F.main("2FA", "Setting up two-factor authentication.")); } - //@EventHandler + @EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); From 05bd93cbdf06e0a7eb632e57c880341c98aedec4 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 19 Mar 2017 00:01:11 +0000 Subject: [PATCH 13/26] Fixed Death Bomber achievement exploit --- .../arcade/stats/DeathBomberStatTracker.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java index 90316be6e..61d4b8923 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java @@ -1,17 +1,16 @@ package nautilus.game.arcade.stats; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageEvent; - import mineplex.core.common.util.UtilPlayer; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import nautilus.game.arcade.game.Game; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; public class DeathBomberStatTracker extends StatTracker { @@ -52,6 +51,11 @@ public class DeathBomberStatTracker extends StatTracker if(killer.equals(killed)) return; + if (killer.getItemInHand().getType() != Material.TNT) + { + return; + } + if (event.GetLog().GetKiller() != null && event.GetLog().GetKiller().GetReason().contains("Throwing TNT")) { Integer count = _killCount.get(killer.getUniqueId()); From 95d919a654c72967b6105bb5c31569806ea43562 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 19 Mar 2017 00:07:23 +0000 Subject: [PATCH 14/26] Removed was werid disjointed code --- .../game/arcade/game/games/skywars/kits/KitMetal.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java index 5d6cf5ff5..a5e4be83e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/kits/KitMetal.java @@ -90,10 +90,6 @@ public class KitMetal extends ProgressingKit @Override public void GiveItems(Player player) { - int level = getUpgradeLevel(player.getUniqueId()); - - - player.getInventory().addItem(PLAYER_ITEMS); } From c4c7ebe1e6735a44f55e7f982f9ba69c66f95dcb Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 20 Mar 2017 22:10:20 +0000 Subject: [PATCH 15/26] Check for blocks already registering --- .../games/bridge/animation/custom/CustomBridgeAnimation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java index 18f45bd3f..fe5e6ed04 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java @@ -181,7 +181,7 @@ public abstract class CustomBridgeAnimation extends BridgeAnimation for (Block block : UtilBlock.getInBoundingBox(locations.get(0), locations.get(1))) { - if (!_blockIds.contains(block.getTypeId())) + if (!_blockIds.contains(block.getTypeId()) || _bridgeBlocks.containsKey(block)) { continue; } From 401276d70587bff6f042e779298d0ba2c6f2aa87 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 22 Mar 2017 23:04:50 +0000 Subject: [PATCH 16/26] Missing isLive check --- .../src/nautilus/game/arcade/game/games/bridge/Bridge.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index bf646fa6e..91bf17b99 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -1657,7 +1657,7 @@ public class Bridge extends TeamGame implements OreObsfucation @EventHandler(priority=EventPriority.LOWEST) public void revivePlayer(CustomDamageEvent event) { - if (_bridgesDown || !(event.GetDamageeEntity() instanceof Player)) + if (!IsLive() || _bridgesDown || !(event.GetDamageeEntity() instanceof Player)) { return; } From 222e4267d2f3eed163d10c9a7be97ab4eec2d68b Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 22 Mar 2017 22:36:53 -0500 Subject: [PATCH 17/26] Add UHC subtypes to server menu --- .../mineplex/hub/server/ui/ServerNpcShop.java | 3 + .../hub/server/ui/UHCServerTypePage.java | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java index 735066e80..107f9fb16 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java @@ -33,6 +33,9 @@ public class ServerNpcShop extends ShopBase case "MS": return new MinestrikeServerTypePage(getPlugin(), this, getClientManager(), getDonationManager(), player, _serverGroup); + case "UHC": + return new UHCServerTypePage(getPlugin(), this, getClientManager(), getDonationManager(), player); + default: return new ServerNpcPage(getPlugin(), this, getClientManager(), getDonationManager(), _serverGroup.getServerNpcName(), player, _serverGroup.getPrefix()); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java new file mode 100644 index 000000000..76cc3595b --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java @@ -0,0 +1,66 @@ +package mineplex.hub.server.ui; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.hub.server.ServerManager; + +public class UHCServerTypePage extends ShopPageBase + +{ + public UHCServerTypePage(ServerManager plugin, ServerNpcShop shop, CoreClientManager clientManager, + DonationManager donationManager, Player player) + { + super(plugin, shop, clientManager, donationManager, "Ultra Hardcore", player, 27); + + buildPage(); + } + + @Override + protected void buildPage() + { + setItem(10, new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3).setTitle(C.Reset + C.cYellow + "UHC Solo") + .addLore(new String[] + { + C.Reset + "", + C.Reset + C.cGreen + "Click to Play", + }).build()); + + setItem(12, new ItemBuilder(Material.SKULL_ITEM, 2, (byte) 3).setTitle(C.Reset + C.cYellow + "UHC Teams") + .addLore(new String[] + { + C.Reset + "", + C.Reset + C.cGreen + "Click to Play", + }).build()); + + setItem(14, new ItemBuilder(Material.SKULL_ITEM, 1, (byte) 3).setTitle(C.Reset + C.cYellow + "UHC Speed Solo") + .addLore(new String[] + { + C.Reset + "", + C.Reset + C.cGreen + "Click to Play" + }).build()); + + setItem(16, new ItemBuilder(Material.SKULL_ITEM, 2, (byte) 3).setTitle(C.Reset + C.cYellow + "UHC Speed Teams") + .addLore(new String[] + { + C.Reset + "", + C.Reset + C.cGreen + "Click to Play" + }).build()); + + getButtonMap().put(10, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC Solo", player, "UHC2"))); + getButtonMap().put(12, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC", player, "UHC"))); + getButtonMap().put(14, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC Speed Solo", player, "UHCS2"))); + getButtonMap().put(16, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC Speed", player, "UHCS"))); + } + + public void Update() + { + getButtonMap().clear(); + buildPage(); + } +} From 9c504064c1921afe5534642ca56670e5afae172b Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 22 Mar 2017 22:41:08 -0500 Subject: [PATCH 18/26] Force all players to reappear after win room --- .../src/mineplex/core/gadget/types/WinEffectGadget.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java index 403161cc9..06d6d9475 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java @@ -110,6 +110,7 @@ public abstract class WinEffectGadget extends Gadget } finally { + UtilServer.getPlayersCollection().forEach(UtilPlayer::showForAll); _player = null; _baseLocation = null; _team.clear(); From 5fa583109fdb7641464fe541e026069330e96581 Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 23 Mar 2017 15:04:04 -0500 Subject: [PATCH 19/26] Revert BungeeRotator US/EU merge This reverts commits e59d744074bc7ed517ec92b1f2b94af082336bab and b8ac877fa39e55dc8dbacaa50546679f7f7b3139 --- .../src/mineplex/bungee/BungeeRotator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java index a7d2e0462..12ff80b05 100644 --- a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java @@ -16,6 +16,7 @@ import java.util.logging.Logger; import mineplex.bungee.api.ApiDeleteCall; import mineplex.bungee.api.ApiGetCall; import mineplex.bungee.api.ApiPostCall; +import mineplex.bungee.api.HttpCallBase; import mineplex.bungee.api.token.ARecord; import mineplex.bungee.api.token.DnsRecord; import mineplex.bungee.api.token.DomainRecords; @@ -24,8 +25,8 @@ import mineplex.serverdata.data.BungeeServer; import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.servers.ConnectionData; -import mineplex.serverdata.servers.ConnectionData.ConnectionType; import mineplex.serverdata.servers.ServerManager; +import mineplex.serverdata.servers.ConnectionData.ConnectionType; public class BungeeRotator { @@ -96,8 +97,7 @@ public class BungeeRotator _repository = new RedisDataRepository(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL), Region.ALL, BungeeServer.class, "bungeeServers"); - // Temporarily reassigning to US Redis IP for EU player redirection testing. 10.81.1.156 -> 10.33.53.16 - _secondRepository = new RedisDataRepository(new ConnectionData("10.33.53.16", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionType.SLAVE, "ServerStatus"), + _secondRepository = new RedisDataRepository(new ConnectionData("10.81.1.156", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionType.SLAVE, "ServerStatus"), Region.ALL, BungeeServer.class, "bungeeServers"); //_ipRepository = new PlayerStatsRepository(); @@ -110,7 +110,7 @@ public class BungeeRotator try { List bungeeServers = new ArrayList(_repository.getElements()); - //bungeeServers.addAll(_secondRepository.getElements()); + bungeeServers.addAll(_secondRepository.getElements()); Collections.sort(bungeeServers, bungeeSorter); From e3c4d89d9af1909149a2b75fc7e1c14b2dc65b32 Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 23 Mar 2017 23:17:01 -0500 Subject: [PATCH 20/26] Disable 'Light em up' quest --- .../src/mineplex/gemhunters/quest/QuestModule.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index a48e843d7..342b1851c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; +import net.md_5.bungee.api.ChatColor; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -39,7 +41,6 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.quest.command.ResetQuestsCommand; import mineplex.gemhunters.quest.types.ChestOpenerQuest; -import mineplex.gemhunters.quest.types.CraftingQuest; import mineplex.gemhunters.quest.types.EnjoyTheViewQuest; import mineplex.gemhunters.quest.types.GiveItemQuest; import mineplex.gemhunters.quest.types.KillMostValuableQuest; @@ -49,7 +50,6 @@ import mineplex.gemhunters.quest.types.SamitoDQuest; import mineplex.gemhunters.quest.types.SpecificChestOpenerQuest; import mineplex.gemhunters.quest.types.WalkingQuest; import mineplex.gemhunters.world.WorldDataModule; -import net.md_5.bungee.api.ChatColor; @ReflectivelyCreateMiniPlugin public class QuestModule extends MiniClientPlugin @@ -89,7 +89,7 @@ public class QuestModule extends MiniClientPlugin new KillMostValuableQuest(17, "Equality", "Slay the most valuable player in the game.", 100, 1500), - new CraftingQuest(18, "Light em up", "Craft " + F.count("5 Torches"), 25, 250, Material.TORCH, 5) + //new CraftingQuest(18, "Light em up", "Craft " + F.count("5 Torches"), 25, 250, Material.TORCH, 5) }; private final EconomyModule _economy; From 3ebfb453c5d32bafd65e2747c56b3c546c45cb02 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Thu, 23 Feb 2017 17:16:02 -0500 Subject: [PATCH 21/26] Implement rank and powerplay linking to the website and give specific ranks an id corresponding to their respective forum tag --- .../src/mineplex/core/common/Rank.java | 60 +- .../core/account/CoreClientManager.java | 5 + .../core/account/event/RankSaveEvent.java | 42 ++ .../account/repository/AccountRepository.java | 3 + .../powerplayclub/PPCDataRequestEvent.java | 44 ++ .../PowerPlayClubRepository.java | 12 +- .../powerplayclub/SubscriptionAddEvent.java | 38 ++ .../mineplex/core/website/ForumUserData.java | 15 + .../mineplex/core/website/LinkCommand.java | 37 ++ .../core/website/MineplexAuthenticator.java | 28 + .../core/website/WebsiteLinkManager.java | 605 ++++++++++++++++++ .../mineplex/core/website/XenForoData.java | 13 + .../src/mineplex/clanshub/ClansHub.java | 2 + .../Mineplex.Hub/src/mineplex/hub/Hub.java | 6 +- .../src/nautilus/game/arcade/Arcade.java | 2 + 15 files changed, 883 insertions(+), 29 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/account/event/RankSaveEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PPCDataRequestEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/SubscriptionAddEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/website/ForumUserData.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/website/MineplexAuthenticator.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/website/XenForoData.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java index 2f3556b26..aef681107 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java @@ -10,58 +10,61 @@ import mineplex.core.common.util.UtilPlayer; public enum Rank { //Staff - LT("Leader", "lt", ChatColor.DARK_RED, "Leaders manage the operation of their respective team \nor projects. They usually operate on affairs within \nthe staff, development, or management team."), - OWNER("Owner", "owner", ChatColor.DARK_RED, "Owners are the founders of Mineplex. \nEach owner manages a different aspect of the \nserver and ensures its efficient operation."), - DEVELOPER("Dev", "dev", ChatColor.DARK_RED, "Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience."), - ADMIN("Admin", "adm", ChatColor.DARK_RED, "An Administrator’s role is to manage \ntheir respective Senior Moderator team \nand all moderators within it."), - JNR_DEV("Jr.Dev", "jrdev", ChatColor.GOLD, "Junior Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience."), - SUPPORT("Support", "spp", ChatColor.BLUE, "Support agents handle tickets and \nprovide customer service."), - CMOD("C.Mod", "cmod", ChatColor.GOLD, "Clans Moderators are members of the Clans Management Senior Mod team. \nTheir duties include moderation and support within the Clans servers. \n\nFor assistance, contact them using " + F.elem("/a ") + "."), - SNR_MODERATOR("Sr.Mod", "srmod", ChatColor.GOLD, "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a ") + "."), - MODERATOR("Mod", "mod", ChatColor.GOLD, "Moderators enforce rules and provide help to \nanyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a ") + "."), - HELPER("Trainee", "train", ChatColor.GOLD, "Trainees are moderators-in-training. \nTheir duties include enforcing the rules and \nproviding help to anyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a ") + "."), - MAPLEAD("MapLead", "mapl", ChatColor.BLUE, "Map Leaders are leaders of the Mineplex Build Team. \nThey oversee the creation of new maps and manage Builders."), - MAPDEV("Builder", "mapd", ChatColor.BLUE, "Builders are members of the Mineplex Build Team. \nThey create many of the maps used across Mineplex."), - MEDIA("Media", "media", ChatColor.BLUE, "The Media rank is given to talented artists who are\n endorsed to create content for Mineplex."), + LT("Leader", "lt", ChatColor.DARK_RED, "Leaders manage the operation of their respective team \nor projects. They usually operate on affairs within \nthe staff, development, or management team.", 11), + OWNER("Owner", "owner", ChatColor.DARK_RED, "Owners are the founders of Mineplex. \nEach owner manages a different aspect of the \nserver and ensures its efficient operation.", 55), + DEVELOPER("Dev", "dev", ChatColor.DARK_RED, "Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience.", 5), + ADMIN("Admin", "adm", ChatColor.DARK_RED, "An Administrator’s role is to manage \ntheir respective Senior Moderator team \nand all moderators within it.", 10), + JNR_DEV("Jr.Dev", "jrdev", ChatColor.GOLD, "Junior Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience.", -1), + SUPPORT("Support", "spp", ChatColor.BLUE, "Support agents handle tickets and \nprovide customer service.", 47), + CMOD("C.Mod", "cmod", ChatColor.GOLD, "Clans Moderators are members of the Clans Management Senior Mod team. \nTheir duties include moderation and support within the Clans servers. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 32), + SNR_MODERATOR("Sr.Mod", "srmod", ChatColor.GOLD, "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 44), + MODERATOR("Mod", "mod", ChatColor.GOLD, "Moderators enforce rules and provide help to \nanyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 32), + HELPER("Trainee", "train", ChatColor.GOLD, "Trainees are moderators-in-training. \nTheir duties include enforcing the rules and \nproviding help to anyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 24), + MAPLEAD("MapLead", "mapl", ChatColor.BLUE, "Map Leaders are leaders of the Mineplex Build Team. \nThey oversee the creation of new maps and manage Builders.", 25), + MAPDEV("Builder", "mapd", ChatColor.BLUE, "Builders are members of the Mineplex Build Team. \nThey create many of the maps used across Mineplex.", 26), + MEDIA("Media", "media", ChatColor.BLUE, "The Media rank is given to talented artists who are\n endorsed to create content for Mineplex.", -1), - EVENT("Event", "evnt", ChatColor.WHITE, "A member of the official Mineplex Events team!"), + EVENT("Event", "evnt", ChatColor.WHITE, "A member of the official Mineplex Events team!", -1), //Media - YOUTUBE("YouTube", "yt", ChatColor.RED, "A YouTuber who creates content for \nor related to Mineplex."), - YOUTUBE_SMALL("YT", "ytsm", ChatColor.DARK_PURPLE, "A YouTuber who creates content for \nor related to Mineplex. \n\nThey have fewer subscribers than full YouTubers."), - TWITCH("Twitch", "tw", ChatColor.DARK_PURPLE, "A Twitch streamer who often features \nMineplex in their streams."), + YOUTUBE("YouTube", "yt", ChatColor.RED, "A YouTuber who creates content for \nor related to Mineplex.", 22), + YOUTUBE_SMALL("YT", "ytsm", ChatColor.DARK_PURPLE, "A YouTuber who creates content for \nor related to Mineplex. \n\nThey have fewer subscribers than full YouTubers.", 20), + TWITCH("Twitch", "tw", ChatColor.DARK_PURPLE, "A Twitch streamer who often features \nMineplex in their streams.", 21), //Player - ETERNAL("Eternal", "et", ChatColor.DARK_AQUA, true, "Fantastic and magical, no one \nexcept the time lords truly understand \nthe power of this rank.\n\nThe fifth purchasable rank at Mineplex.com/shop"), - TITAN("Titan", "t", ChatColor.RED, true, "Ancient myths spoke of a gigantic being \nwith immense power... \n\nThe fourth purchasable rank at Mineplex.com/shop"), - LEGEND("Legend", "l", ChatColor.GREEN, true, "Years they have told stories of this rank, \nonly for the legends to be true. \n\nThe third purchasable rank at Mineplex.com/shop"), - HERO("Hero", "h", ChatColor.LIGHT_PURPLE, true, "There are many stories of a \nvaliant Hero who was brave enough to \ntame the most fearsome dragon in the land. \n\nThe second purchasable rank at Mineplex.com/shop"), - ULTRA("Ultra", "u", ChatColor.AQUA, true, "A first step into the stories of the mist. \nOnly those brave enough may enter. \n\nThe first purchasable rank at Mineplex.com/shop"), - ALL("", "", ChatColor.WHITE, null); + ETERNAL("Eternal", "et", ChatColor.DARK_AQUA, true, "Fantastic and magical, no one \nexcept the time lords truly understand \nthe power of this rank.\n\nThe fifth purchasable rank at Mineplex.com/shop", 18), + TITAN("Titan", "t", ChatColor.RED, true, "Ancient myths spoke of a gigantic being \nwith immense power... \n\nThe fourth purchasable rank at Mineplex.com/shop", 15), + LEGEND("Legend", "l", ChatColor.GREEN, true, "Years they have told stories of this rank, \nonly for the legends to be true. \n\nThe third purchasable rank at Mineplex.com/shop", 14), + HERO("Hero", "h", ChatColor.LIGHT_PURPLE, true, "There are many stories of a \nvaliant Hero who was brave enough to \ntame the most fearsome dragon in the land. \n\nThe second purchasable rank at Mineplex.com/shop", 13), + ULTRA("Ultra", "u", ChatColor.AQUA, true, "A first step into the stories of the mist. \nOnly those brave enough may enter. \n\nThe first purchasable rank at Mineplex.com/shop", 12), + ALL("", "", ChatColor.WHITE, null, -1); private ChatColor _color; private boolean _donor; private String _description; + private int _forumId; public String Name; public String ScoreboardTag; - Rank(String name, String scoreboardTag, ChatColor color, String description) + Rank(String name, String scoreboardTag, ChatColor color, String description, int forumId) { _color = color; Name = name; _donor = false; _description = description; ScoreboardTag = scoreboardTag; + _forumId = forumId; } - Rank(String name, String scoreboardTag, ChatColor color, boolean donor, String description) + Rank(String name, String scoreboardTag, ChatColor color, boolean donor, String description, int forumId) { _color = color; Name = name; _donor = donor; _description = description; ScoreboardTag = scoreboardTag; + _forumId = forumId; } public String getDescription() @@ -138,4 +141,9 @@ public enum Rank { return _donor; } -} + + public int getForumId() + { + return _forumId; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 37ca50942..a8bc40c04 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -36,6 +36,7 @@ import mineplex.core.account.command.TestRank; import mineplex.core.account.command.UpdateRank; import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientWebResponseEvent; +import mineplex.core.account.event.RankSaveEvent; import mineplex.core.account.repository.AccountRepository; import mineplex.core.account.repository.token.ClientToken; import mineplex.core.common.Rank; @@ -43,6 +44,7 @@ import mineplex.core.common.timing.TimingManager; import mineplex.core.common.util.Callback; import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTasks; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -552,6 +554,7 @@ public class CoreClientManager extends MiniPlugin client.SetRank(newRank, false); } + UtilServer.CallEvent(new RankSaveEvent(uuid, newRank)); } }, name, uuid, rank, perm); } @@ -571,6 +574,8 @@ public class CoreClientManager extends MiniPlugin if (callback != null) callback.run(newRank); + + UtilServer.CallEvent(new RankSaveEvent(uuid, newRank)); } }, name, uuid, rank, perm); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/event/RankSaveEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/account/event/RankSaveEvent.java new file mode 100644 index 000000000..8453ab6b7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/event/RankSaveEvent.java @@ -0,0 +1,42 @@ +package mineplex.core.account.event; + +import java.util.UUID; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.core.common.Rank; + +public class RankSaveEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private UUID _uuid; + private Rank _rank; + + public RankSaveEvent(UUID uuid, Rank rank) + { + _uuid = uuid; + _rank = rank; + } + + public UUID getUUID() + { + return _uuid; + } + + public Rank getRank() + { + return _rank; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 789914489..104365605 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -16,6 +16,7 @@ import com.google.gson.reflect.TypeToken; import mineplex.cache.player.PlayerCache; import mineplex.core.account.ILoginProcessor; +import mineplex.core.account.event.RankSaveEvent; import mineplex.core.account.repository.token.LoginToken; import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Rank; @@ -204,6 +205,8 @@ public class AccountRepository extends MinecraftRepository { if (callback != null) callback.run(response); + + UtilServer.CallEvent(new RankSaveEvent(uuid, rank)); }); }; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PPCDataRequestEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PPCDataRequestEvent.java new file mode 100644 index 000000000..51af9b3b9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PPCDataRequestEvent.java @@ -0,0 +1,44 @@ +package mineplex.core.powerplayclub; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PPCDataRequestEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private PowerPlayData _data; + + public PPCDataRequestEvent(Player player) + { + _player = player; + _data = null; + } + + public Player getPlayer() + { + return _player; + } + + public PowerPlayData getData() + { + return _data; + } + + public void setData(PowerPlayData data) + { + _data = data;; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRepository.java index e28b0509f..0e007abdb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRepository.java @@ -25,6 +25,7 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.account.ILoginProcessor; +import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; import mineplex.serverdata.database.DBPool; @@ -120,9 +121,17 @@ public class PowerPlayClubRepository implements Listener { _stageOneDataClaims.remove(event.getPlayer().getUniqueId()); // Just in case. _cachedPlayerData.remove(event.getPlayer().getUniqueId()); } + + @EventHandler + public void onDataRequested(PPCDataRequestEvent event) + { + event.setData(getCachedData(event.getPlayer())); + } public CompletableFuture addSubscription(int accountId, LocalDate date, String duration) { + UtilServer.CallEvent(new SubscriptionAddEvent(accountId, duration)); + return CompletableFuture.supplyAsync(() -> { try (Connection connection = DBPool.getAccount().getConnection()) @@ -133,7 +142,8 @@ public class PowerPlayClubRepository implements Listener { statement.setString(3, duration); statement.executeUpdate(); - } catch (SQLException e) + } + catch (SQLException e) { e.printStackTrace(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/SubscriptionAddEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/SubscriptionAddEvent.java new file mode 100644 index 000000000..50503de00 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/SubscriptionAddEvent.java @@ -0,0 +1,38 @@ +package mineplex.core.powerplayclub; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class SubscriptionAddEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private int _accountId; + private String _duration; + + public SubscriptionAddEvent(int accountId, String duration) + { + _accountId = accountId; + _duration = duration; + } + + public int getAccountId() + { + return _accountId; + } + + public String getDuration() + { + return _duration; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/ForumUserData.java b/Plugins/Mineplex.Core/src/mineplex/core/website/ForumUserData.java new file mode 100644 index 000000000..bd663e61b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/ForumUserData.java @@ -0,0 +1,15 @@ +package mineplex.core.website; + +public class ForumUserData +{ + public boolean Linked; + public int LinkedForumId; + public boolean LastSyncedPowerPlayStatus; + + public ForumUserData() + { + Linked = false; + LinkedForumId = -1; + LastSyncedPowerPlayStatus = false; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java new file mode 100644 index 000000000..2d754f9de --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java @@ -0,0 +1,37 @@ +package mineplex.core.website; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; + +public class LinkCommand extends CommandBase +{ + public LinkCommand(WebsiteLinkManager plugin) + { + super(plugin, Rank.ALL, "link"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args.length < 1) + { + UtilPlayer.message(caller, F.help("/" + _aliasUsed + " XXX-XXX-XXX", "Begins linking your Minecraft account with your website link code.", Rank.ALL, ChatColor.GREEN)); + } + else + { + if (Plugin.Get(caller).Linked) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), "Your account is already linked!")); + } + else + { + Plugin.startLink(caller, args[0]); + } + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/MineplexAuthenticator.java b/Plugins/Mineplex.Core/src/mineplex/core/website/MineplexAuthenticator.java new file mode 100644 index 000000000..5cd97df4d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/MineplexAuthenticator.java @@ -0,0 +1,28 @@ +package mineplex.core.website; + +import java.net.Authenticator; +import java.net.PasswordAuthentication; + +public class MineplexAuthenticator extends Authenticator +{ + private String _username, _password; + + public MineplexAuthenticator(String username, String password) + { + _username = username; + _password = password; + } + + @Override + public PasswordAuthentication getPasswordAuthentication() + { + System.out.println("-==Mineplex Authentication In Progress==-"); + System.out.println("Requesting Host: " + getRequestingHost()); + System.out.println("Requesting Port: " + getRequestingPort()); + System.out.println("Requesting Prompt: " + getRequestingPrompt()); + System.out.println("Requesting Protocol: " + getRequestingProtocol()); + System.out.println("Requesting Scheme: " + getRequestingScheme()); + System.out.println("Requesting Site: " + getRequestingSite()); + return new PasswordAuthentication(_username, _password.toCharArray()); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java new file mode 100644 index 000000000..3b50ff978 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java @@ -0,0 +1,605 @@ +package mineplex.core.website; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Authenticator; +import java.net.MalformedURLException; +import java.net.URL; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TimeZone; +import java.util.UUID; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; + +import mineplex.core.MiniDbClientPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.event.RankSaveEvent; +import mineplex.core.common.Pair; +import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.powerplayclub.PPCDataRequestEvent; +import mineplex.core.powerplayclub.PowerPlayData; +import mineplex.core.powerplayclub.SubscriptionAddEvent; +import mineplex.serverdata.database.DBPool; + +public class WebsiteLinkManager extends MiniDbClientPlugin +{ + private final JsonParser PARSER = new JsonParser(); + private final String API_URL = "https://xen.mineplex.com/api.php"; + private final String API_KEY = "dd412425-edb0-477c-abee-2d0b507c59ef"; + + public WebsiteLinkManager(JavaPlugin plugin, CoreClientManager clientManager) + { + super("Website Link", plugin, clientManager); + + addCommand(new LinkCommand(this)); + + Authenticator.setDefault(new MineplexAuthenticator("minexen", "c4cADuj&ChaQ")); + } + + public void startLink(Player player, String code) + { + final int forumId = getForumId(code); + final int accountId = getClientManager().getAccountId(player); + final Rank rank = getClientManager().Get(player).GetRank(true); + PowerPlayData d = UtilServer.CallEvent(new PPCDataRequestEvent(player)).getData(); + final boolean powerPlay = (d != null && d.isSubscribed()); + if (forumId == -1) + { + UtilPlayer.message(player, F.main(getName(), "That link code is invalid!")); + return; + } + runAsync(() -> + { + loadXenforoAccount(forumId, data -> + { + if (data == null) + { + UtilPlayer.message(player, F.main(getName(), "That link code is invalid!")); + return; + } + if (data.custom_fields.containsKey("mcAcctIdPC") && !data.custom_fields.get("mcAcctIdPC").isEmpty()) + { + UtilPlayer.message(player, F.main(getName(), "That link code is invalid!")); + return; + } + completeLink(player, data.username, data.user_id, accountId, rank, powerPlay); + }); + }); + } + + private void completeLink(Player player, String forumUser, int userId, int accountId, Rank rank, boolean powerPlay) + { + try (Connection c = DBPool.getAccount().getConnection()) + { + boolean success = c.prepareStatement("INSERT INTO forumLink (accountId, userId, powerPlayStatus) VALUES (" + accountId + ", " + userId + ", " + powerPlay + ");").executeUpdate() > 0; + if (success) + { + String call = "action=editUser&user=" + forumUser + "&custom_fields=mcAcctIdPC=" + accountId; + if (rank.getForumId() != -1) + { + call += ("&add_groups=" + rank.getForumId()); + } + if (powerPlay) + { + if (call.contains("&add_groups=")) + { + call += (",17"); + } + else + { + call += ("&add_groups=17"); + } + } + doAPICall(call, err -> + { + UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + }, () -> + { + UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + }, () -> + { + runSync(() -> + { + UtilPlayer.message(player, F.main(getName(), "You have successfully linked your account!")); + if (player.isOnline()) + { + Get(player).LinkedForumId = userId; + Get(player).LastSyncedPowerPlayStatus = powerPlay; + Get(player).Linked = true; + } + }); + }); + } + else + { + UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + } + } + catch (SQLException e) + { + UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + e.printStackTrace(); + } + } + + private void loadXenforoAccount(int userId, Callback callback) + { + try + { + StringBuilder result = new StringBuilder(); + URL call = new URL(API_URL + "?hash=" + API_KEY + "&action=getUser&value=" + userId); + BufferedReader br = new BufferedReader(new InputStreamReader(call.openStream())); + br.lines().forEach(line -> result.append(line)); + + String json = result.toString().trim(); + + JsonObject response = null; + try + { + response = PARSER.parse(json).getAsJsonObject(); + if (response.has("error")) + { + callback.run(null); + } + else + { + XenForoData data = new XenForoData(); + data.user_id = response.get("user_id").getAsInt(); + data.username = response.get("username").getAsString(); + data.email = response.get("email").getAsString(); + data.user_group_id = response.get("user_group_id").getAsInt(); + String groups = response.get("secondary_group_ids").getAsString(); + if (groups.isEmpty()) + { + data.secondary_group_ids = new int[] {}; + } + else + { + String[] groupIds = groups.split(","); + data.secondary_group_ids = new int[groupIds.length]; + for (int index = 0; index < groupIds.length; index++) + { + data.secondary_group_ids[index] = Integer.parseInt(groupIds[index]); + } + } + Map fields = new HashMap<>(); + if (response.get("custom_fields") instanceof JsonObject) + { + JsonObject cFields = (JsonObject) response.get("custom_fields"); + for (Entry entry : cFields.entrySet()) + { + fields.put(entry.getKey(), entry.getValue().getAsString()); + } + } + data.custom_fields = fields; + callback.run(data); + } + } + catch (JsonSyntaxException e) + { + callback.run(null); + e.printStackTrace(); + return; + } + } + catch (MalformedURLException e) + { + callback.run(null); + e.printStackTrace(); + } + catch (IOException e) + { + callback.run(null); + e.printStackTrace(); + } + } + + private void doAPICall(String call, Callback errorCallback, Runnable ioException, Runnable onComplete) + { + StringBuilder input = new StringBuilder(); + + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL + "?hash=" + API_KEY + "&" + call).openStream()))) + { + reader.lines().forEach(l -> input.append(l)); + } + catch (IOException e) + { + System.out.println("[XENFORO API] Could not connect to web server"); + e.printStackTrace(); + ioException.run(); + return; + } + + JsonObject response = null; + try + { + response = PARSER.parse(input.toString().trim()).getAsJsonObject(); + } + catch (JsonSyntaxException e) + { + System.out.println("[XENFORO API] Could not parse JSON response data"); + e.printStackTrace(); + return; + } + + if (response.has("error")) + { + if (response.get("error").getAsString().equals("7")) + { + if (response.has("user_error_id")) + { + String errorID = response.get("user_error_id").getAsString(); + + errorCallback.run(errorID); + System.out.println("[XENFORO API] An error was found in the JSON response (id: " + errorID + ") from REST call: " + call); + return; + } + else + { + System.out.println("[XENFORO API] An error was found in the JSON response, but no error code was found from REST call: " + call); + } + } + else + { + System.out.println("[XENFORO API] A non-user error was found in the JSON response (id: " + response.get("error").getAsString() + ") from REST call: " + call); + return; + } + } + else + { + onComplete.run(); + } + } + + private int getForumId(String linkCode) + { + String given = linkCode.replace("-", ""); + if (given.length() < 9) + { + return -1; + } + if (!StringUtils.isNumeric(given)) + { + return -1; + } + + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + int offset = 100000000; + StringBuilder sb = new StringBuilder((cal.get(Calendar.DAY_OF_YEAR) - 1) + ""); + while (sb.length() < 3) + { + sb.insert(0, "0"); + } + String reverse = sb.reverse().toString(); + Integer test = Integer.parseInt(reverse + reverse + reverse); + test += offset; + + Integer input = Integer.parseInt(given); + + return Math.abs(test - input); + } + + private Pair checkAccountOnline(int accountId) + { + for (Player player : Bukkit.getOnlinePlayers()) + { + if (getClientManager().getAccountId(player) == accountId) + { + return Pair.create(true, player.getUniqueId()); + } + } + + return Pair.create(false, null); + } + + @EventHandler + public void handleRankSave(RankSaveEvent event) + { + Callback dataCallback = new Callback() + { + public void run(XenForoData data) + { + List remove = new ArrayList<>(); + for (Rank rank : Rank.values()) + { + if (rank.getForumId() != -1 && rank != event.getRank()) + { + boolean found = false; + for (int groupId : data.secondary_group_ids) + { + if (groupId == rank.getForumId()) + { + found = true; + } + } + if (found) + { + remove.add(rank.getForumId()); + } + } + } + String callBase = "action=editUser&user=" + data.username; + if (!remove.isEmpty()) + { + String removal = "&remove_groups=" + remove.get(0).intValue(); + for (int i = 1; i < remove.size(); i++) + { + removal += ("," + remove.get(i)); + } + String call = callBase + removal; + doAPICall(call, error -> {}, () -> {}, () -> {}); + } + if (event.getRank().getForumId() != -1) + { + boolean found = false; + for (int groupId : data.secondary_group_ids) + { + if (groupId == event.getRank().getForumId()) + { + found = true; + } + } + if (!found) + { + String call = callBase + "&add_groups=" + event.getRank().getForumId(); + doAPICall(call, error -> {}, () -> {}, () -> {}); + } + } + } + }; + if (Bukkit.getPlayer(event.getUUID()) != null) + { + ForumUserData fd = Get(event.getUUID()); + if (fd.Linked) + { + final int userId = fd.LinkedForumId; + runAsync(() -> + { + loadXenforoAccount(userId, dataCallback); + }); + } + } + else + { + runAsync(() -> + { + getClientManager().getRepository().getAccountId(event.getUUID(), accountId -> + { + runAsync(() -> + { + try (Connection c = DBPool.getAccount().getConnection()) + { + ResultSet rs = c.prepareStatement("SELECT userId FROM forumLink WHERE accountId=" + accountId + ";").executeQuery(); + if (rs.next()) + { + Integer userId = rs.getInt(1); + loadXenforoAccount(userId, dataCallback); + } + } + catch (SQLException e) + { + e.printStackTrace(); + } + }); + }); + }); + } + } + + @EventHandler + public void handleSubscriptionAdd(SubscriptionAddEvent event) + { + Pair p = checkAccountOnline(event.getAccountId()); + if (p.getLeft()) + { + ForumUserData fd = Get(p.getRight()); + if (fd.Linked && !fd.LastSyncedPowerPlayStatus) + { + final int userId = fd.LinkedForumId; + runAsync(() -> + { + loadXenforoAccount(userId, data -> + { + boolean has = false; + for (int groupId : data.secondary_group_ids) + { + if (groupId == 17) + { + has = true; + } + } + if (!has) + { + doAPICall("action=editUser&user=" + data.username + "&add_groups=17", error -> {}, () -> {}, () -> + { + runSync(() -> + { + fd.LastSyncedPowerPlayStatus = true; + }); + try (Connection c = DBPool.getAccount().getConnection()) + { + c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + }); + } + }); + }); + } + } + else + { + runAsync(() -> + { + try (Connection c = DBPool.getAccount().getConnection()) + { + ResultSet rs = c.prepareStatement("SELECT userId FROM forumLink WHERE accountId=" + event.getAccountId() + ";").executeQuery(); + if (rs.next()) + { + Integer userId = rs.getInt(1); + loadXenforoAccount(userId, data -> + { + boolean has = false; + for (int groupId : data.secondary_group_ids) + { + if (groupId == 17) + { + has = true; + } + } + if (!has) + { + doAPICall("action=editUser&user=" + data.username + "&add_groups=17", error -> {}, () -> {}, () -> + { + try + { + c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + }); + } + }); + } + } + catch (SQLException e) + { + e.printStackTrace(); + } + }); + } + } + + @EventHandler + public void updatePPCTag(PlayerJoinEvent event) + { + runSyncLater(() -> + { + if (event.getPlayer().isOnline()) + { + boolean ppc = false; + PowerPlayData d = UtilServer.CallEvent(new PPCDataRequestEvent(event.getPlayer())).getData(); + if (d != null) + { + ppc = d.isSubscribed(); + final boolean powerPlay = ppc; + if (Get(event.getPlayer()).Linked && Get(event.getPlayer()).LastSyncedPowerPlayStatus != powerPlay) + { + final int userId = Get(event.getPlayer()).LinkedForumId; + final int accountId = getClientManager().getAccountId(event.getPlayer()); + runAsync(() -> + { + loadXenforoAccount(userId, data -> + { + String call = ""; + boolean change = false; + boolean has = false; + for (int groupId : data.secondary_group_ids) + { + if (groupId == 17) + { + has = true; + } + } + if (powerPlay) + { + if (!has) + { + call = "action=editUser&user=" + data.username + "&add_groups=17"; + change = true; + } + } + else + { + if (has) + { + call = "action=editUser&user=" + data.username + "&remove_groups=17"; + change = true; + } + } + if (change) + { + doAPICall(call, error -> {}, () -> {}, () -> + { + runSync(() -> + { + if (event.getPlayer().isOnline()) + { + Get(event.getPlayer()).LastSyncedPowerPlayStatus = powerPlay; + } + }); + try (Connection c = DBPool.getAccount().getConnection()) + { + c.prepareStatement("UPDATE forumLink SET powerPlayStatus=" + powerPlay + " WHERE accountId=" + accountId + ";").execute(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + }); + } + }); + }); + } + } + } + }, 40L); + } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT userId, powerPlayStatus FROM forumLink WHERE accountId=" + accountId + ";"; + } + + @Override + public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException + { + if (resultSet.next()) + { + ForumUserData data = new ForumUserData(); + data.Linked = true; + data.LinkedForumId = resultSet.getInt(1); + data.LastSyncedPowerPlayStatus = resultSet.getBoolean(2); + Set(uuid, data); + } + else + { + Set(uuid, new ForumUserData()); + } + } + + @Override + protected ForumUserData addPlayer(UUID uuid) + { + return new ForumUserData(); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/XenForoData.java b/Plugins/Mineplex.Core/src/mineplex/core/website/XenForoData.java new file mode 100644 index 000000000..cb5901982 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/XenForoData.java @@ -0,0 +1,13 @@ +package mineplex.core.website; + +import java.util.Map; + +public class XenForoData +{ + public int user_id; + public String username; + public String email; + public int user_group_id; + public int[] secondary_group_ids; + public Map custom_fields; +} \ No newline at end of file diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index e44061aad..7f10bdfca 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -60,6 +60,7 @@ import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; +import mineplex.core.website.WebsiteLinkManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.DamageManager; @@ -181,6 +182,7 @@ public class ClansHub extends JavaPlugin require(TrackManager.class); require(Titles.class); require(TwoFactorAuth.class); + new WebsiteLinkManager(this, clientManager); } @Override diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 763bbb153..1269d0ed9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -1,5 +1,7 @@ package mineplex.hub; +import static mineplex.core.Managers.require; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -74,6 +76,7 @@ import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; +import mineplex.core.website.WebsiteLinkManager; import mineplex.hub.modules.BillboardManager; import mineplex.hub.queue.QueueManager; import mineplex.hub.server.ServerManager; @@ -88,8 +91,6 @@ import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.fire.Fire; -import static mineplex.core.Managers.require; - public class Hub extends JavaPlugin implements IRelation { private NpcManager _npcManager; @@ -236,6 +237,7 @@ public class Hub extends JavaPlugin implements IRelation require(Titles.class); require(TwoFactorAuth.class); require(TeamspeakManager.class); + new WebsiteLinkManager(this, clientManager); } @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 6478db304..302603df5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -73,6 +73,7 @@ import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; +import mineplex.core.website.WebsiteLinkManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; @@ -199,6 +200,7 @@ public class Arcade extends JavaPlugin new FoodDupeFix(this); require(TwoFactorAuth.class); + new WebsiteLinkManager(this, _clientManager); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); From f6fdc1f8173950ac58bf84ec1697b71413ffec48 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Sat, 25 Feb 2017 12:52:34 -0500 Subject: [PATCH 22/26] Implement a method for administrators to remove the link between an in-game minecraft account and a forum account, and rewrite synchronization of tags to more effectively handle the intricacies of the API being utilized --- .../mineplex/core/website/UnlinkCommand.java | 30 + .../core/website/WebsiteLinkManager.java | 538 +++++++++++++----- 2 files changed, 411 insertions(+), 157 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java new file mode 100644 index 000000000..730d9b1fe --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java @@ -0,0 +1,30 @@ +package mineplex.core.website; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; + +public class UnlinkCommand extends CommandBase +{ + public UnlinkCommand(WebsiteLinkManager plugin) + { + super(plugin, Rank.ADMIN, "unlink"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args.length < 1) + { + UtilPlayer.message(caller, F.help("/" + _aliasUsed + " ", "Removes a link to a forum and in-game account.", Rank.ADMIN, ChatColor.RED)); + } + else + { + Plugin.unlink(caller, args[0]); + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java index 3b50ff978..b8bb6825e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java @@ -55,10 +55,120 @@ public class WebsiteLinkManager extends MiniDbClientPlugin super("Website Link", plugin, clientManager); addCommand(new LinkCommand(this)); + addCommand(new UnlinkCommand(this)); Authenticator.setDefault(new MineplexAuthenticator("minexen", "c4cADuj&ChaQ")); } + public void unlink(Player sender, String target) + { + getClientManager().getOrLoadClient(target, client -> + { + if (client != null) + { + Callback dataCallback = data -> + { + if (data == null) + { + UtilPlayer.message(sender, F.main(getName(), "Could not find " + F.name(target) + "!")); + } + else + { + if (!data.Linked) + { + UtilPlayer.message(sender, F.main(getName(), F.name(target) + " is not linked to a forum account!")); + } + else + { + runAsync(() -> + { + loadXenforoAccount(data.LinkedForumId, user -> + { + List remove = new ArrayList<>(); + remove.add(17); + remove.add(91); + for (Rank rank : Rank.values()) + { + if (rank.getForumId() != -1) + { + remove.add(rank.getForumId()); + } + } + String call = "action=editUser&user=" + user.username + "&custom_fields=mcAcctIdPC="; + doAPICall(call, err -> + { + runSync(() -> UtilPlayer.message(sender, F.main(getName(), F.name(target) + " was not able to be unlinked at this time!"))); + }, () -> + { + runSync(() -> UtilPlayer.message(sender, F.main(getName(), F.name(target) + " was not able to be unlinked at this time!"))); + }, () -> + { + refreshSiteTags(data.LinkedForumId, remove, new ArrayList<>(), false, () -> + { + try (Connection c = DBPool.getAccount().getConnection()) + { + c.prepareStatement("DELETE FROM forumLink WHERE accountId=" + client.getAccountId()).execute(); + runSync(() -> + { + UtilPlayer.message(sender, F.main(getName(), F.name(target) + " was successfully unlinked!")); + data.Linked = false; + data.LinkedForumId = -1; + data.LastSyncedPowerPlayStatus = false; + }); + } + catch (SQLException e) + { + e.printStackTrace(); + runSync(() -> UtilPlayer.message(sender, F.main(getName(), F.name(target) + " was not able to be unlinked at this time!"))); + } + }, false, () -> UtilPlayer.message(sender, F.main(getName(), F.name(target) + " was not able to be unlinked at this time!")), true); + }); + }); + }); + } + } + }; + if (Bukkit.getPlayer(client.getUniqueId()) != null) + { + dataCallback.run(Get(client.getUniqueId())); + } + else + { + runAsync(() -> + { + try (Connection c = DBPool.getAccount().getConnection()) + { + ResultSet rs = c.prepareStatement("SELECT userId, powerPlayStatus FROM forumLink WHERE accountId=" + client.getAccountId() + ";").executeQuery(); + if (rs.next()) + { + Integer userId = rs.getInt(1); + Boolean powerPlay = rs.getBoolean(2); + final ForumUserData data = new ForumUserData(); + data.Linked = true; + data.LinkedForumId = userId; + data.LastSyncedPowerPlayStatus = powerPlay; + runSync(() -> dataCallback.run(data)); + } + else + { + runSync(() -> dataCallback.run(new ForumUserData())); + } + } + catch (SQLException e) + { + e.printStackTrace(); + runSync(() -> dataCallback.run(new ForumUserData())); + } + }); + } + } + else + { + UtilPlayer.message(sender, F.main(getName(), "Could not find " + F.name(target) + "!")); + } + }); + } + public void startLink(Player player, String code) { final int forumId = getForumId(code); @@ -85,66 +195,248 @@ public class WebsiteLinkManager extends MiniDbClientPlugin UtilPlayer.message(player, F.main(getName(), "That link code is invalid!")); return; } - completeLink(player, data.username, data.user_id, accountId, rank, powerPlay); + completeLink(player, data, accountId, rank, powerPlay); }); }); } - private void completeLink(Player player, String forumUser, int userId, int accountId, Rank rank, boolean powerPlay) + private void completeLink(Player player, XenForoData data, int accountId, Rank rank, boolean powerPlay) { try (Connection c = DBPool.getAccount().getConnection()) { - boolean success = c.prepareStatement("INSERT INTO forumLink (accountId, userId, powerPlayStatus) VALUES (" + accountId + ", " + userId + ", " + powerPlay + ");").executeUpdate() > 0; + boolean success = c.prepareStatement("INSERT INTO forumLink (accountId, userId, powerPlayStatus) VALUES (" + accountId + ", " + data.user_id + ", " + powerPlay + ");").executeUpdate() > 0; if (success) { - String call = "action=editUser&user=" + forumUser + "&custom_fields=mcAcctIdPC=" + accountId; + String call = "action=editUser&user=" + data.username + "&custom_fields=mcAcctIdPC=" + accountId; + List adding = new ArrayList<>(); + adding.add(91); if (rank.getForumId() != -1) { - call += ("&add_groups=" + rank.getForumId()); + adding.add(rank.getForumId()); } if (powerPlay) { - if (call.contains("&add_groups=")) - { - call += (",17"); - } - else - { - call += ("&add_groups=17"); - } + adding.add(17); } doAPICall(call, err -> { - UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + runSync(() -> UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!"))); }, () -> { - UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + runSync(() -> UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!"))); }, () -> { - runSync(() -> + refreshSiteTags(data, new ArrayList<>(), adding, false, () -> { UtilPlayer.message(player, F.main(getName(), "You have successfully linked your account!")); if (player.isOnline()) { - Get(player).LinkedForumId = userId; + Get(player).LinkedForumId = data.user_id; Get(player).LastSyncedPowerPlayStatus = powerPlay; Get(player).Linked = true; } - }); + }, true, () -> UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")), true); }); } else { - UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + runSync(() -> UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!"))); } } catch (SQLException e) { - UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!")); + runSync(() -> UtilPlayer.message(player, F.main(getName(), "The link failed! Please try again!"))); e.printStackTrace(); } } + private void refreshSiteTags(int userId, List removing, List adding, boolean runAsync, Runnable after, boolean runAfterSync, Runnable onErr, boolean runErrSync) + { + Runnable r = () -> + { + loadXenforoAccount(userId, data -> + { + refreshSiteTags(data, removing, adding, false, after, runAfterSync, onErr, runErrSync); + }); + }; + + if (runAsync) + { + runAsync(r); + } + else + { + r.run(); + } + } + + private void refreshSiteTags(XenForoData data, List removing, List adding, boolean runAsync, Runnable after, boolean runAfterSync, Runnable onErr, boolean runErrSync) + { + Runnable r = () -> + { + if (data == null) + { + return; + } + String callBase = "action=editUser&user=" + data.username; + String groups = ""; + for (int groupId : data.secondary_group_ids) + { + if (!removing.contains(groupId) && !adding.contains(groupId)) + { + groups += ("," + groupId); + } + } + for (Integer groupId : adding) + { + groups += ("," + groupId); + } + if (!groups.isEmpty()) + { + groups = groups.substring(1); + } + final String addGroups = groups; + groups = ""; + for (int groupId : data.secondary_group_ids) + { + groups += ("," + groupId); + } + if (!groups.isEmpty()) + { + groups = groups.substring(1); + } + final String remGroups = groups; + if (!remGroups.isEmpty()) + { + doAPICall(callBase + "&remove_groups=" + remGroups, err -> + { + if (runErrSync) + { + runSync(onErr); + } + else + { + onErr.run(); + } + }, () -> + { + if (runErrSync) + { + runSync(onErr); + } + else + { + onErr.run(); + } + }, () -> + { + if (!addGroups.isEmpty()) + { + doAPICall(callBase + "&add_groups=" + addGroups, err -> + { + if (runErrSync) + { + runSync(onErr); + } + else + { + onErr.run(); + } + }, () -> + { + if (runErrSync) + { + runSync(onErr); + } + else + { + onErr.run(); + } + }, () -> + { + if (runAfterSync) + { + runSync(after); + } + else + { + after.run(); + } + }); + } + else + { + if (runAfterSync) + { + runSync(after); + } + else + { + after.run(); + } + } + }); + } + else + { + if (!addGroups.isEmpty()) + { + doAPICall(callBase + "&add_groups=" + addGroups, err -> + { + if (runErrSync) + { + runSync(onErr); + } + else + { + onErr.run(); + } + }, () -> + { + if (runErrSync) + { + runSync(onErr); + } + else + { + onErr.run(); + } + }, () -> + { + if (runAfterSync) + { + runSync(after); + } + else + { + after.run(); + } + }); + } + else + { + if (runAfterSync) + { + runSync(after); + } + else + { + after.run(); + } + } + } + }; + + if (runAsync) + { + runAsync(r); + } + else + { + r.run(); + } + } + private void loadXenforoAccount(int userId, Callback callback) { try @@ -288,7 +580,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); int offset = 100000000; - StringBuilder sb = new StringBuilder((cal.get(Calendar.DAY_OF_YEAR) - 1) + ""); + StringBuilder sb = new StringBuilder(cal.get(Calendar.DAY_OF_YEAR) + ""); while (sb.length() < 3) { sb.insert(0, "0"); @@ -299,7 +591,20 @@ public class WebsiteLinkManager extends MiniDbClientPlugin Integer input = Integer.parseInt(given); - return Math.abs(test - input); + Integer abs = Math.abs(test - input); + +// Bukkit.broadcastMessage("REVERSE: " + reverse); +// Bukkit.broadcastMessage("TEST: " + test); +// Bukkit.broadcastMessage("INPUT: " + input); +// Bukkit.broadcastMessage("ABS: " + abs); +// Bukkit.broadcastMessage("MODULUS: " + abs % 11); + + if (abs % 11 != 0) + { + return -1; + } + + return abs / 11; } private Pair checkAccountOnline(int accountId) @@ -318,57 +623,22 @@ public class WebsiteLinkManager extends MiniDbClientPlugin @EventHandler public void handleRankSave(RankSaveEvent event) { - Callback dataCallback = new Callback() + Callback dataCallback = id -> { - public void run(XenForoData data) + List remove = new ArrayList<>(); + List add = new ArrayList<>(); + for (Rank rank : Rank.values()) { - List remove = new ArrayList<>(); - for (Rank rank : Rank.values()) + if (rank.getForumId() != -1 && rank != event.getRank()) { - if (rank.getForumId() != -1 && rank != event.getRank()) - { - boolean found = false; - for (int groupId : data.secondary_group_ids) - { - if (groupId == rank.getForumId()) - { - found = true; - } - } - if (found) - { - remove.add(rank.getForumId()); - } - } - } - String callBase = "action=editUser&user=" + data.username; - if (!remove.isEmpty()) - { - String removal = "&remove_groups=" + remove.get(0).intValue(); - for (int i = 1; i < remove.size(); i++) - { - removal += ("," + remove.get(i)); - } - String call = callBase + removal; - doAPICall(call, error -> {}, () -> {}, () -> {}); - } - if (event.getRank().getForumId() != -1) - { - boolean found = false; - for (int groupId : data.secondary_group_ids) - { - if (groupId == event.getRank().getForumId()) - { - found = true; - } - } - if (!found) - { - String call = callBase + "&add_groups=" + event.getRank().getForumId(); - doAPICall(call, error -> {}, () -> {}, () -> {}); - } + remove.add(rank.getForumId()); } } + if (event.getRank().getForumId() != -1) + { + add.add(event.getRank().getForumId()); + } + refreshSiteTags(id, remove, add, false, () -> {}, false, () -> {}, false); }; if (Bukkit.getPlayer(event.getUUID()) != null) { @@ -378,7 +648,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin final int userId = fd.LinkedForumId; runAsync(() -> { - loadXenforoAccount(userId, dataCallback); + dataCallback.run(userId); }); } } @@ -396,7 +666,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin if (rs.next()) { Integer userId = rs.getInt(1); - loadXenforoAccount(userId, dataCallback); + dataCallback.run(userId); } } catch (SQLException e) @@ -421,35 +691,23 @@ public class WebsiteLinkManager extends MiniDbClientPlugin final int userId = fd.LinkedForumId; runAsync(() -> { - loadXenforoAccount(userId, data -> + List add = new ArrayList<>(); + add.add(17); + refreshSiteTags(userId, new ArrayList<>(), add, false, () -> { - boolean has = false; - for (int groupId : data.secondary_group_ids) + runSync(() -> { - if (groupId == 17) - { - has = true; - } - } - if (!has) + fd.LastSyncedPowerPlayStatus = true; + }); + try (Connection c = DBPool.getAccount().getConnection()) { - doAPICall("action=editUser&user=" + data.username + "&add_groups=17", error -> {}, () -> {}, () -> - { - runSync(() -> - { - fd.LastSyncedPowerPlayStatus = true; - }); - try (Connection c = DBPool.getAccount().getConnection()) - { - c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - }); + c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); } - }); + catch (SQLException e) + { + e.printStackTrace(); + } + }, false, () -> {}, false); }); } } @@ -463,31 +721,19 @@ public class WebsiteLinkManager extends MiniDbClientPlugin if (rs.next()) { Integer userId = rs.getInt(1); - loadXenforoAccount(userId, data -> + List add = new ArrayList<>(); + add.add(17); + refreshSiteTags(userId, new ArrayList<>(), add, false, () -> { - boolean has = false; - for (int groupId : data.secondary_group_ids) + try { - if (groupId == 17) - { - has = true; - } + c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); } - if (!has) + catch (SQLException e) { - doAPICall("action=editUser&user=" + data.username + "&add_groups=17", error -> {}, () -> {}, () -> - { - try - { - c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - }); + e.printStackTrace(); } - }); + }, false, () -> {}, false); } } catch (SQLException e) @@ -517,56 +763,34 @@ public class WebsiteLinkManager extends MiniDbClientPlugin final int accountId = getClientManager().getAccountId(event.getPlayer()); runAsync(() -> { - loadXenforoAccount(userId, data -> + List remove = new ArrayList<>(); + List add = new ArrayList<>(); + if (powerPlay) { - String call = ""; - boolean change = false; - boolean has = false; - for (int groupId : data.secondary_group_ids) + add.add(17); + } + else + { + remove.add(17); + } + refreshSiteTags(userId, remove, add, false, () -> + { + runSync(() -> { - if (groupId == 17) + if (event.getPlayer().isOnline()) { - has = true; + Get(event.getPlayer()).LastSyncedPowerPlayStatus = powerPlay; } - } - if (powerPlay) + }); + try (Connection c = DBPool.getAccount().getConnection()) { - if (!has) - { - call = "action=editUser&user=" + data.username + "&add_groups=17"; - change = true; - } + c.prepareStatement("UPDATE forumLink SET powerPlayStatus=" + powerPlay + " WHERE accountId=" + accountId + ";").execute(); } - else + catch (SQLException e) { - if (has) - { - call = "action=editUser&user=" + data.username + "&remove_groups=17"; - change = true; - } + e.printStackTrace(); } - if (change) - { - doAPICall(call, error -> {}, () -> {}, () -> - { - runSync(() -> - { - if (event.getPlayer().isOnline()) - { - Get(event.getPlayer()).LastSyncedPowerPlayStatus = powerPlay; - } - }); - try (Connection c = DBPool.getAccount().getConnection()) - { - c.prepareStatement("UPDATE forumLink SET powerPlayStatus=" + powerPlay + " WHERE accountId=" + accountId + ";").execute(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - }); - } - }); + }, false, () -> {}, false); }); } } From 1ff033de434df6e29897fb6d60eb1f2808521104 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Sat, 25 Feb 2017 19:44:55 -0500 Subject: [PATCH 23/26] Refactor website link to use consumers instead of callbacks --- .../core/website/WebsiteLinkManager.java | 129 +++++++++--------- 1 file changed, 66 insertions(+), 63 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java index b8bb6825e..f6787c514 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java @@ -17,6 +17,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TimeZone; import java.util.UUID; +import java.util.function.BiConsumer; +import java.util.function.Consumer; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -33,9 +35,7 @@ import com.google.gson.JsonSyntaxException; import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.account.event.RankSaveEvent; -import mineplex.core.common.Pair; import mineplex.core.common.Rank; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -66,7 +66,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin { if (client != null) { - Callback dataCallback = data -> + Consumer dataCallback = data -> { if (data == null) { @@ -130,7 +130,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin }; if (Bukkit.getPlayer(client.getUniqueId()) != null) { - dataCallback.run(Get(client.getUniqueId())); + dataCallback.accept(Get(client.getUniqueId())); } else { @@ -147,17 +147,17 @@ public class WebsiteLinkManager extends MiniDbClientPlugin data.Linked = true; data.LinkedForumId = userId; data.LastSyncedPowerPlayStatus = powerPlay; - runSync(() -> dataCallback.run(data)); + runSync(() -> dataCallback.accept(data)); } else { - runSync(() -> dataCallback.run(new ForumUserData())); + runSync(() -> dataCallback.accept(new ForumUserData())); } } catch (SQLException e) { e.printStackTrace(); - runSync(() -> dataCallback.run(new ForumUserData())); + runSync(() -> dataCallback.accept(new ForumUserData())); } }); } @@ -437,7 +437,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin } } - private void loadXenforoAccount(int userId, Callback callback) + private void loadXenforoAccount(int userId, Consumer callback) { try { @@ -454,7 +454,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin response = PARSER.parse(json).getAsJsonObject(); if (response.has("error")) { - callback.run(null); + callback.accept(null); } else { @@ -487,29 +487,29 @@ public class WebsiteLinkManager extends MiniDbClientPlugin } } data.custom_fields = fields; - callback.run(data); + callback.accept(data); } } catch (JsonSyntaxException e) { - callback.run(null); + callback.accept(null); e.printStackTrace(); return; } } catch (MalformedURLException e) { - callback.run(null); + callback.accept(null); e.printStackTrace(); } catch (IOException e) { - callback.run(null); + callback.accept(null); e.printStackTrace(); } } - private void doAPICall(String call, Callback errorCallback, Runnable ioException, Runnable onComplete) + private void doAPICall(String call, Consumer errorCallback, Runnable ioException, Runnable onComplete) { StringBuilder input = new StringBuilder(); @@ -545,7 +545,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin { String errorID = response.get("user_error_id").getAsString(); - errorCallback.run(errorID); + errorCallback.accept(errorID); System.out.println("[XENFORO API] An error was found in the JSON response (id: " + errorID + ") from REST call: " + call); return; } @@ -607,23 +607,24 @@ public class WebsiteLinkManager extends MiniDbClientPlugin return abs / 11; } - private Pair checkAccountOnline(int accountId) + private void checkAccountOnline(int accountId, BiConsumer consumer) { for (Player player : Bukkit.getOnlinePlayers()) { if (getClientManager().getAccountId(player) == accountId) { - return Pair.create(true, player.getUniqueId()); + consumer.accept(true, player.getUniqueId()); + return; } } - return Pair.create(false, null); + consumer.accept(false, null); } @EventHandler public void handleRankSave(RankSaveEvent event) { - Callback dataCallback = id -> + Consumer dataCallback = id -> { List remove = new ArrayList<>(); List add = new ArrayList<>(); @@ -648,7 +649,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin final int userId = fd.LinkedForumId; runAsync(() -> { - dataCallback.run(userId); + dataCallback.accept(userId); }); } } @@ -666,7 +667,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin if (rs.next()) { Integer userId = rs.getInt(1); - dataCallback.run(userId); + dataCallback.accept(userId); } } catch (SQLException e) @@ -682,50 +683,25 @@ public class WebsiteLinkManager extends MiniDbClientPlugin @EventHandler public void handleSubscriptionAdd(SubscriptionAddEvent event) { - Pair p = checkAccountOnline(event.getAccountId()); - if (p.getLeft()) + checkAccountOnline(event.getAccountId(), (online, uuid) -> { - ForumUserData fd = Get(p.getRight()); - if (fd.Linked && !fd.LastSyncedPowerPlayStatus) + if (online) { - final int userId = fd.LinkedForumId; - runAsync(() -> + ForumUserData fd = Get(uuid); + if (fd.Linked && !fd.LastSyncedPowerPlayStatus) { - List add = new ArrayList<>(); - add.add(17); - refreshSiteTags(userId, new ArrayList<>(), add, false, () -> + final int userId = fd.LinkedForumId; + runAsync(() -> { - runSync(() -> - { - fd.LastSyncedPowerPlayStatus = true; - }); - try (Connection c = DBPool.getAccount().getConnection()) - { - c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - }, false, () -> {}, false); - }); - } - } - else - { - runAsync(() -> - { - try (Connection c = DBPool.getAccount().getConnection()) - { - ResultSet rs = c.prepareStatement("SELECT userId FROM forumLink WHERE accountId=" + event.getAccountId() + ";").executeQuery(); - if (rs.next()) - { - Integer userId = rs.getInt(1); List add = new ArrayList<>(); add.add(17); refreshSiteTags(userId, new ArrayList<>(), add, false, () -> { - try + runSync(() -> + { + fd.LastSyncedPowerPlayStatus = true; + }); + try (Connection c = DBPool.getAccount().getConnection()) { c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); } @@ -734,14 +710,41 @@ public class WebsiteLinkManager extends MiniDbClientPlugin e.printStackTrace(); } }, false, () -> {}, false); - } + }); } - catch (SQLException e) + } + else + { + runAsync(() -> { - e.printStackTrace(); - } - }); - } + try (Connection c = DBPool.getAccount().getConnection()) + { + ResultSet rs = c.prepareStatement("SELECT userId FROM forumLink WHERE accountId=" + event.getAccountId() + ";").executeQuery(); + if (rs.next()) + { + Integer userId = rs.getInt(1); + List add = new ArrayList<>(); + add.add(17); + refreshSiteTags(userId, new ArrayList<>(), add, false, () -> + { + try + { + c.prepareStatement("UPDATE forumLink SET powerPlayStatus=true WHERE accountId=" + event.getAccountId() + ";").execute(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + }, false, () -> {}, false); + } + } + catch (SQLException e) + { + e.printStackTrace(); + } + }); + } + }); } @EventHandler From 3b2c50efa3cf043588e0d0c331a49240fd9b9916 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Wed, 1 Mar 2017 03:02:12 -0500 Subject: [PATCH 24/26] Remove magic values for PPC tag id and linked tag id --- .../mineplex/core/website/WebsiteLinkManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java index f6787c514..3ab0e1637 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/WebsiteLinkManager.java @@ -49,6 +49,8 @@ public class WebsiteLinkManager extends MiniDbClientPlugin private final JsonParser PARSER = new JsonParser(); private final String API_URL = "https://xen.mineplex.com/api.php"; private final String API_KEY = "dd412425-edb0-477c-abee-2d0b507c59ef"; + private final int POWER_PLAY_TAG_ID = 17; + private final int LINKED_TAG_ID = 91; public WebsiteLinkManager(JavaPlugin plugin, CoreClientManager clientManager) { @@ -85,8 +87,8 @@ public class WebsiteLinkManager extends MiniDbClientPlugin loadXenforoAccount(data.LinkedForumId, user -> { List remove = new ArrayList<>(); - remove.add(17); - remove.add(91); + remove.add(POWER_PLAY_TAG_ID); + remove.add(LINKED_TAG_ID); for (Rank rank : Rank.values()) { if (rank.getForumId() != -1) @@ -216,7 +218,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin } if (powerPlay) { - adding.add(17); + adding.add(POWER_PLAY_TAG_ID); } doAPICall(call, err -> { @@ -694,7 +696,7 @@ public class WebsiteLinkManager extends MiniDbClientPlugin runAsync(() -> { List add = new ArrayList<>(); - add.add(17); + add.add(POWER_PLAY_TAG_ID); refreshSiteTags(userId, new ArrayList<>(), add, false, () -> { runSync(() -> @@ -770,11 +772,11 @@ public class WebsiteLinkManager extends MiniDbClientPlugin List add = new ArrayList<>(); if (powerPlay) { - add.add(17); + add.add(POWER_PLAY_TAG_ID); } else { - remove.add(17); + remove.add(POWER_PLAY_TAG_ID); } refreshSiteTags(userId, remove, add, false, () -> { From d95ed8d7499fcc3fdf00cb10c19570eaff80ec86 Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 23 Mar 2017 23:22:33 -0500 Subject: [PATCH 25/26] Disable /link and /unlink help messages --- .../Mineplex.Core/src/mineplex/core/website/LinkCommand.java | 3 +-- .../src/mineplex/core/website/UnlinkCommand.java | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java index 2d754f9de..74dcbe768 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/LinkCommand.java @@ -1,6 +1,5 @@ package mineplex.core.website; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -20,7 +19,7 @@ public class LinkCommand extends CommandBase { if (args.length < 1) { - UtilPlayer.message(caller, F.help("/" + _aliasUsed + " XXX-XXX-XXX", "Begins linking your Minecraft account with your website link code.", Rank.ALL, ChatColor.GREEN)); + //UtilPlayer.message(caller, F.help("/" + _aliasUsed + " XXX-XXX-XXX", "Begins linking your Minecraft account with your website link code.", Rank.ALL, ChatColor.GREEN)); } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java index 730d9b1fe..b6060c863 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/website/UnlinkCommand.java @@ -1,12 +1,9 @@ package mineplex.core.website; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; public class UnlinkCommand extends CommandBase { @@ -20,7 +17,7 @@ public class UnlinkCommand extends CommandBase { if (args.length < 1) { - UtilPlayer.message(caller, F.help("/" + _aliasUsed + " ", "Removes a link to a forum and in-game account.", Rank.ADMIN, ChatColor.RED)); + //UtilPlayer.message(caller, F.help("/" + _aliasUsed + " ", "Removes a link to a forum and in-game account.", Rank.ADMIN, ChatColor.RED)); } else { From 0ad69ebefc3107a69d6eb6980a479437f800f371 Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 23 Mar 2017 23:24:00 -0500 Subject: [PATCH 26/26] Revert "Merge branch update/bridges into develop" This reverts commit 7e8f5b4939e9a095a2b3cb90b036629fce6b9fa3, reversing changes made to 222e4267d2f3eed163d10c9a7be97ab4eec2d68b. --- .../core/common/util/UtilParticle.java | 5 +- .../game/games/bridge/BattleCryManager.java | 6 + .../game/arcade/game/games/bridge/Bridge.java | 744 +++++++++++------- .../bridge/animation/BridgeAnimation.java | 45 -- .../bridge/animation/BridgeAnimationType.java | 44 -- .../bridge/animation/IceBridgeAnimation.java | 79 -- .../bridge/animation/LavaBridgeAnimation.java | 84 -- .../animation/LillyPadBridgeAnimation.java | 65 -- .../animation/MushroomBridgeAnimation.java | 107 --- .../bridge/animation/WoodBridgeAnimation.java | 129 --- .../custom/CustomBridgeAnimation.java | 246 ------ .../custom/RadiusCustomBridgeAnimation.java | 58 -- .../custom/RandomCustomBridgeAnimation.java | 44 -- .../game/games/bridge/kits/KitApple.java | 2 +- .../game/games/bridge/kits/KitArcher.java | 2 +- .../game/games/bridge/kits/KitBerserker.java | 2 +- .../game/games/bridge/kits/KitDestructor.java | 2 +- .../games/bridge/modes/OverpoweredBridge.java | 36 +- .../game/arcade/game/modules/Module.java | 3 + .../game/modules/WorldBorderModule.java | 116 --- .../game/arcade/kit/ProgressingKit.java | 8 - .../game/arcade/kit/perks/PerkDestructor.java | 4 +- .../arcade/stats/DeathBomberStatTracker.java | 22 +- .../stats/FoodForTheMassesStatTracker.java | 6 - 24 files changed, 522 insertions(+), 1337 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java delete mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java index 7b85b4971..0945ad7fd 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java @@ -372,12 +372,11 @@ public class UtilParticle int count, ViewDist dist, Player... players) { PacketPlayOutWorldParticles packet = getPacket(particle, location, offsetX, offsetY, offsetZ, speed, count, true); - int distValue = dist.getDist() * dist.getDist(); - + for (Player player : players) { // Out of range for player - if (UtilMath.offsetSquared(player.getLocation(), location) > distValue) + if (UtilMath.offset(player.getLocation(), location) > dist.getDist()) continue; UtilPlayer.sendPacket(player, packet); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java new file mode 100644 index 000000000..7c7e71ba0 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/BattleCryManager.java @@ -0,0 +1,6 @@ +package nautilus.game.arcade.game.games.bridge; + +public class BattleCryManager +{ + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java index 91bf17b99..a6d5d92f3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/Bridge.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.bridge; +import com.google.common.collect.Lists; import mineplex.core.common.Rank; import mineplex.core.common.util.*; import mineplex.core.common.util.UtilEvent.ActionType; @@ -12,28 +13,17 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; -import nautilus.game.arcade.game.DebugCommand; +import nautilus.game.arcade.events.PlayerDeathOutEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; -import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimation; -import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimationType; -import nautilus.game.arcade.game.games.bridge.animation.custom.CustomBridgeAnimation; -import nautilus.game.arcade.game.games.bridge.animation.custom.RadiusCustomBridgeAnimation; -import nautilus.game.arcade.game.games.bridge.animation.custom.RandomCustomBridgeAnimation; import nautilus.game.arcade.game.games.bridge.kits.*; -import nautilus.game.arcade.game.modules.WorldBorderModule; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; -import nautilus.game.arcade.kit.Perk; -import nautilus.game.arcade.kit.perks.PerkDestructor; import nautilus.game.arcade.ore.OreHider; import nautilus.game.arcade.ore.OreObsfucation; import nautilus.game.arcade.stats.*; -import org.bukkit.Effect; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; @@ -48,19 +38,14 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerBucketFillEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.*; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; import java.util.*; -import java.util.concurrent.TimeUnit; public class Bridge extends TeamGame implements OreObsfucation { @@ -69,24 +54,29 @@ public class Bridge extends TeamGame implements OreObsfucation */ private static final Material[] PLAYER_DROP_DELAY_MATERIALS = new Material[] { Material.LOG, Material.LOG_2, Material.IRON_ORE, Material.DIAMOND_ORE, Material.COAL_ORE, Material.GOLD_ORE, Material.WORKBENCH, Material.FURNACE }; - /** - * The number of milliseconds from the game start time til the bridges should be built. - */ - private static final long BRIDGE_TIME = TimeUnit.MINUTES.toMillis(10); - - /** - * The number of ticks after the prepare state that we wait before setting the world border for the players. Just to make sure they are in the correct world. - */ - private static final int WORLD_BORDER_PREPARE_TICKS = 20; - - private static final String CUSTOM_BRIDGE_KEY = "TYPE"; - - //Bridge - private long _bridgeTime = BRIDGE_TIME; + //Bridge Timer + private int _bridgeTime = 600000; private boolean _bridgesDown = false; - private BridgeAnimation _animation; - private CustomBridgeAnimation[] _customAnimations; + + //Wood Bridge + private ArrayList _woodBridge = new ArrayList(); + private HashMap _woodBridgeBlocks = null; + + //Lava Bridge + private ArrayList _lavaBridge = new ArrayList(); + private ArrayList _lavaSource = new ArrayList(); + + //Lilly Pad Bridge + private NautHashMap _lillyPads = new NautHashMap(); + //Mushrooms + private NautHashMap _mushroomStem = new NautHashMap(); + private NautHashMap _mushroomTop = new NautHashMap(); + private boolean _stemsGrown = false; + + //Ice + private ArrayList _iceBridge = new ArrayList(); + private HashSet _bridgeParts = new HashSet(); //Animals @@ -107,14 +97,14 @@ public class Bridge extends TeamGame implements OreObsfucation private int _buildHeight = -1; //Player Respawn - private Set _usedLife = new HashSet<>(); + private HashSet _usedLife = new HashSet(); //Tourney Mode private boolean _tournament; private HashMap _tournamentKills = new HashMap(); private long _tournamentKillMessageTimer = 0; + - @SuppressWarnings("unchecked") public Bridge(ArcadeManager manager) { this(manager, GameType.Bridge); @@ -164,14 +154,36 @@ public class Bridge extends TeamGame implements OreObsfucation "The last team alive wins!" }); + List kits = Lists.newArrayList(GetKits()); + List finalKits = Lists.newArrayList(kits); + + boolean foundBrawler = false; + for(int i = 0; i < kits.size(); i++) + { + Kit kit = kits.get(i); + if(kit.GetName().equalsIgnoreCase("Brawler")) + { + if(!foundBrawler) + { + foundBrawler = true; + } + else + { + finalKits.remove(i); + } + } + } + + setKits(finalKits.toArray(new Kit[finalKits.size()])); + _ore = new OreHider(); // Flags - GameTimeout = Manager.IsTournamentServer() ? TimeUnit.MINUTES.toMillis(90) : TimeUnit.MINUTES.toMillis(60); + GameTimeout = Manager.IsTournamentServer() ? 5400000 : 3600000; Manager.GetExplosion().SetLiquidDamage(false); - StrictAntiHack = true; + this.StrictAntiHack = true; DamageSelf = true; @@ -194,6 +206,10 @@ public class Bridge extends TeamGame implements OreObsfucation WorldWaterDamage = 0; WorldBoundaryKill = false; + new CompassModule() + .setGiveCompassToAlive(true) + .register(this); + DeathDropItems = true; GemMultiplier = 2.5; @@ -213,108 +229,35 @@ public class Bridge extends TeamGame implements OreObsfucation "Killing yourself counts as -1 team kill.", "Team with the most kills wins!" }; - - _tournament = true; } - _customAnimations = new CustomBridgeAnimation[] { - new RandomCustomBridgeAnimation(this), - new RadiusCustomBridgeAnimation(this) - }; - - new CompassModule() - .setGiveCompassToAlive(true) - .register(this); - - new WorldBorderModule().register(this); - - // So that we can be 110% sure - for (Kit kit : GetKits()) - { - if (kit instanceof KitDestructor) - { - for (Perk perk : kit.GetPerks()) - { - ((PerkDestructor) perk).setEnabled(false); - break; - } - - break; - } - } - - registerDebugCommand(new DebugCommand("bridge", Rank.ADMIN) - { - - @Override - public void Execute(Player caller, String[] args) - { - caller.sendMessage(F.main("Debug", "Spawning the bridges.")); - _bridgeTime = 3000; - } - }); - - registerDebugCommand(new DebugCommand("bridgeinfo", getArcadeManager().getGameCommandRank()) - { - - @Override - public void Execute(Player caller, String[] args) - { - if (_animation == null || !(_animation instanceof CustomBridgeAnimation)) - { - caller.sendMessage(F.main("Debug", "The bridge animation for this map isn't a custom one.")); - return; - } - - caller.sendMessage(F.main("Debug", "Bridge Info:")); - caller.sendMessage(_animation.toString()); - } - }); + + _tournament = Manager.IsTournamentServer(); } @EventHandler - public void prepare(GameStateChangeEvent event) + public void PlayerOut(final PlayerDeathOutEvent event) { - if (event.GetState() != GameState.Prepare) - { + if (_bridgesDown) return; + + Player player = event.GetPlayer(); + + if (!_usedLife.contains(player.getName())) + { + _usedLife.add(player.getName()); + + UtilPlayer.message(player, F.main("Game", "You used your " + F.elem(C.cAqua + "Early Game Revive") + ".")); + + event.setCancelled(true); } - - //Delay this so that we are 100% sure people are in the world. - Manager.runSyncLater(() -> { - - WorldBorderModule borderModule = getModule(WorldBorderModule.class); - - // Here we do some calculations for per player world borders - for (GameTeam team : GetTeamList()) - { - // Step 1 - Get the average location of the spawns, we assume this is generally in an OK position. - Location center = UtilAlg.getAverageLocation(team.GetSpawns()); - // Step 1.5 - Move the location back a bit from the centre, this is usually because spawns are on the inside edge of the islands. - center.add(UtilAlg.getTrajectory(SpectatorSpawn, center).multiply(15)); - - // Step 2 - Calculate an estimate for the size of the border. We'll go with half but the setSize uses the radius so it works out the same to leave it like this - double distToCenter = UtilMath.offset2d(SpectatorSpawn, center) * 0.9; - - // Step 3 - Send the setCenter and setSize packets to the team members - for (Player player : team.GetPlayers(true)) - { - borderModule.setCenter(player, center); - borderModule.setSize(player, distToCenter); - } - - } - - }, WORLD_BORDER_PREPARE_TICKS); } - + @EventHandler(priority = EventPriority.MONITOR) - public void live(GameStateChangeEvent event) + public void GameStateChange(GameStateChangeEvent event) { if (event.GetState() != GameState.Live) - { return; - } if (!WorldData.GetCustomLocs("WATER_DAMAGE").isEmpty()) { @@ -323,72 +266,24 @@ public class Bridge extends TeamGame implements OreObsfucation if (WorldWaterDamage > 0) { - String name = WorldData.MapName; - - if (name.equals("Volcanic Islands")) - { + if (WorldData.MapName.equals("Volcanic Islands")) UtilTextMiddle.display(C.cRed + "Warning", "Water is Boiling Hot", 10, 60, 20); - } else if (WorldData.MapName.equals("Icelands")) - { UtilTextMiddle.display(C.cRed + "Warning", "Water is Freezing Cold", 10, 60, 20); - } else - { UtilTextMiddle.display(C.cRed + "Warning", "Water is Deadly", 10, 60, 20); - } } } + //parse @Override public void ParseData() { - // Now we need to decide on what bridge animation. - typeLoop : for (BridgeAnimationType type : BridgeAnimationType.values()) - { - for (String colours : type.getColoursUsed()) - { - if (WorldData.GetDataLocs(colours).isEmpty()) - { - continue typeLoop; - } - } - - _animation = type.createInstance(this); - break; - } - - // If none of the premade ones are usable then we need a custom one! - if (_animation == null) - { - locationLoop : for (String key : WorldData.GetAllCustomLocs().keySet()) - { - if (!key.startsWith(CUSTOM_BRIDGE_KEY)) - { - continue; - } - - String[] split = key.split(" "); - - if (split.length < 2) - { - continue; - } - - String subKey = split[1]; - - for (CustomBridgeAnimation animation : _customAnimations) - { - if (animation.getTypeKey().equalsIgnoreCase(subKey)) - { - _animation = animation; - break locationLoop; - } - } - } - } - - _animation.onParse(); + ParseLavaBridge(); + ParseWoodBridge(); + ParseIceBridge(); + ParseLillyPad(); + ParseMushrooms(); ParseChests(); @@ -508,6 +403,8 @@ public class Bridge extends TeamGame implements OreObsfucation } } + + public void ParseOre(ArrayList teamOre) { int coal = (int) ((teamOre.size() / 32d) * _oreDensity); @@ -728,45 +625,368 @@ public class Bridge extends TeamGame implements OreObsfucation } } - @EventHandler - public void BridgeBuild(UpdateEvent event) + protected void ParseWoodBridge() { + _woodBridge = new ArrayList(); + + // Load Wood In + for (Location loc : WorldData.GetDataLocs("BROWN")) { + _woodBridge.add(loc.getBlock().getLocation()); + } + + for (Location loc : WorldData.GetDataLocs("GRAY")) { + _woodBridge.add(loc.getBlock().getLocation()); + _woodBridge.add(loc.getBlock().getRelative(BlockFace.UP) + .getLocation()); + } + + // Determine Wood Block + _woodBridgeBlocks = new HashMap(); + + for (Location loc : _woodBridge) { + if (_woodBridge.contains(loc.getBlock().getRelative(BlockFace.DOWN) + .getLocation())) { + _woodBridgeBlocks.put(loc, 85); + } + + if (_woodBridge.contains(loc.getBlock().getRelative(BlockFace.UP) + .getLocation())) { + _woodBridgeBlocks.put(loc, 17); + } + + if (!_woodBridgeBlocks.containsKey(loc)) { + _woodBridgeBlocks.put(loc, 126); + } + } + } + + protected void ParseLavaBridge() { + for (Location loc : WorldData.GetDataLocs("RED")) { + _lavaBridge.add(loc.getBlock().getLocation()); + } + + for (Location loc : WorldData.GetDataLocs("ORANGE")) { + _lavaBridge.add(loc.getBlock().getLocation()); + _lavaBridge.add(loc.getBlock().getRelative(BlockFace.UP) + .getLocation()); + } + + _lavaSource = WorldData.GetDataLocs("BLACK"); + } + + protected void ParseIceBridge() { - if (!IsLive() || !UtilTime.elapsed(GetStateTime(), _bridgeTime)) - { - return; - } + _iceBridge = WorldData.GetDataLocs("LIGHT_BLUE"); + } - if (_animation != null) + protected void ParseMushrooms() + { + for (Location loc : WorldData.GetCustomLocs("21")) { - _animation.onUpdate(event.getType()); + _mushroomStem.put(loc, 0L); + loc.getBlock().setType(Material.AIR); } + + for (Location loc : WorldData.GetDataLocs("PURPLE")) + { + _mushroomTop.put(loc, 0L); + } + } + + protected void ParseLillyPad() + { + for (Location loc : WorldData.GetDataLocs("LIME")) + { + _lillyPads.put(loc, 0L); + } + } - if (event.getType() != UpdateType.FAST) - { + @EventHandler + public void BridgeBuild(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() != UpdateType.FASTEST) + return; + + if (!UtilTime.elapsed(this.GetStateTime(), _bridgeTime)) return; - } if (!_bridgesDown) { - _bridgesDown = true; + Manager.GetExplosion().SetLiquidDamage(true); + this.Announce(C.cRed + C.Bold + "ALERT: " + ChatColor.RESET + C.Bold + "THE BRIDGES ARE SPAWNING!"); + } - WorldBorderModule borderModule = getModule(WorldBorderModule.class); + _bridgesDown = true; - for (Player player : GetPlayers(true)) + for (Kit kit : this.GetKits()) + { + if (kit instanceof KitDestructor) { - borderModule.setSize(player, 10000); + ((KitDestructor)kit).SetEnabled(true); + } + } + + BuildWood(); + BuildLava(); + BuildIce(); + BuildLillyPad(); + buildMushroom(); + } + + protected void BuildLava() + { + for (int i = 0; i < 3; i++) + if (_lavaBridge != null && _lavaSource != null + && !_lavaBridge.isEmpty() && !_lavaSource.isEmpty()) { + // Random Block + Location bestLoc = _lavaBridge.get(UtilMath.r(_lavaBridge + .size())); + + if (bestLoc.getBlock().getRelative(BlockFace.DOWN) + .isLiquid()) + continue; + + _lavaBridge.remove(bestLoc); + + Location source = _lavaSource.get(UtilMath.r(_lavaSource + .size())); + + // Create Part + FallingBlock block = bestLoc.getWorld().spawnFallingBlock( + source, 87, (byte) 0); + BridgePart part = new BridgePart(block, bestLoc, true); + _bridgeParts.add(part); + + // Sound + source.getWorld().playSound(source, Sound.EXPLODE, + 5f * (float) Math.random(), + 0.5f + (float) Math.random()); + } + } + + protected void BuildLillyPad() + { + for (int i = 0; i < 3; i++) + if (_lillyPads != null && !_lillyPads.isEmpty()) + { + // Random Block + Location loc = UtilAlg.Random(_lillyPads.keySet()); + + if (!UtilTime.elapsed(_lillyPads.get(loc), 8000)) + continue; + + if (!loc.getBlock().getRelative(BlockFace.DOWN).isLiquid()) + continue; + + _lillyPads.remove(loc); + + MapUtil.QuickChangeBlockAt(loc, Material.WATER_LILY); + + // Sound + loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 111); + } + } + + @EventHandler + public void breakLillyPad(BlockBreakEvent event) + { + if (event.getBlock().getType() != Material.WATER_LILY) + return; + + _lillyPads.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); + } + + protected void buildMushroom() + { + if (_mushroomStem != null && !_mushroomStem.isEmpty()) + { + for (int i=0 ; i<4 && !_mushroomStem.isEmpty() ; i++) + { + double lowestY = 0; + Location lowestLoc = null; + + for (Location loc : _mushroomStem.keySet()) + { + if (!UtilTime.elapsed(_mushroomStem.get(loc), 6000)) + continue; + + if (lowestLoc == null || loc.getY() < lowestY) + { + lowestY = loc.getY(); + lowestLoc = loc; + } + } + + if (lowestLoc == null) + continue; + + _mushroomStem.remove(lowestLoc); + + MapUtil.QuickChangeBlockAt(lowestLoc, 100, (byte)15); + } + } + else + { + _stemsGrown = true; + } + + if (_stemsGrown && _mushroomTop != null && !_mushroomTop.isEmpty()) + { + int attempts = 0; + int done = 0; + while (done < 6 && attempts < 400) + { + attempts++; + + // Random Block + Location loc = UtilAlg.Random(_mushroomTop.keySet()); + + if (!UtilTime.elapsed(_mushroomTop.get(loc), 6000)) + continue; + + Block block = loc.getBlock(); + + if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR && + block.getRelative(BlockFace.NORTH).getType() == Material.AIR && + block.getRelative(BlockFace.EAST).getType() == Material.AIR && + block.getRelative(BlockFace.SOUTH).getType() == Material.AIR && + block.getRelative(BlockFace.WEST).getType() == Material.AIR) + continue; + + _mushroomTop.remove(loc); + + MapUtil.QuickChangeBlockAt(block.getLocation(), 99, (byte)14); + + done++; + } + } + } + + @EventHandler + public void breakMushroom(BlockBreakEvent event) + { + if (event.isCancelled()) + return; + + + if (event.getBlock().getTypeId() == 100 && + WorldData.GetCustomLocs("21").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) + { + event.setCancelled(true); + event.getBlock().setType(Material.AIR); + + _mushroomStem.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); + } + + if (event.getBlock().getTypeId() == 99 && + WorldData.GetDataLocs("PURPLE").contains(event.getBlock().getLocation().add(0.5, 0, 0.5))) + { + event.setCancelled(true); + event.getBlock().setType(Material.AIR); + + _mushroomTop.put(event.getBlock().getLocation(), System.currentTimeMillis() + (long)(Math.random() * 12000)); + } + } + + protected void BuildIce() + { + if (_iceBridge == null || _iceBridge.isEmpty() || UtilTime.elapsed(this.GetStateTime(), _bridgeTime + 120000)) + { + WorldData.World.setStorm(false); + return; + } + + WorldData.World.setStorm(true); + + int attempts = 0; + int done = 0; + while (done < 5 && attempts < 400) + { + attempts++; + + // Random Block + Location loc = _iceBridge.get(UtilMath.r(_iceBridge.size())); + + Block block = loc.getBlock().getRelative(BlockFace.DOWN); + + if (!block.isLiquid()) + continue; + + if (block.getRelative(BlockFace.NORTH).isLiquid() && + block.getRelative(BlockFace.EAST).isLiquid() && + block.getRelative(BlockFace.SOUTH).isLiquid() && + block.getRelative(BlockFace.WEST).isLiquid()) + continue; + + _iceBridge.remove(loc); + + if (Math.random() > 0.25) + MapUtil.QuickChangeBlockAt(block.getLocation(), Material.PACKED_ICE); + else + MapUtil.QuickChangeBlockAt(block.getLocation(), Material.ICE); + + done++; + } + } + + protected void BuildWood() + { + if (_woodBridgeBlocks != null && !_woodBridgeBlocks.isEmpty()) + { + ArrayList toDo = new ArrayList(); + + BlockFace[] faces = new BlockFace[] { BlockFace.NORTH, + BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; + + for (Location loc : _woodBridgeBlocks.keySet()) + { + if (_woodBridgeBlocks.get(loc) == 17) + { + int adjacent = 0; + + for (BlockFace face : faces) + if (loc.getBlock().getRelative(face).getTypeId() != 0) + adjacent++; + + if (adjacent > 0) + toDo.add(loc); + + } else if (_woodBridgeBlocks.get(loc) == 85) + { + if (loc.getBlock().getRelative(BlockFace.DOWN).getTypeId() == 0) + continue; + + toDo.add(loc); + } else if (_woodBridgeBlocks.get(loc) == 126) + { + int adjacent = 0; + + for (BlockFace face : faces) + if (loc.getBlock().getRelative(face).getTypeId() != 0) + adjacent++; + + if (adjacent > 0) + toDo.add(loc); + } } - Manager.GetExplosion().SetLiquidDamage(true); - Announce(C.cRedB + "ALERT: " + C.Reset + C.Bold + "THE BRIDGES ARE SPAWNING!"); - UtilTextMiddle.display(C.cRedB + "ALERT", "The BRIDGES ARE SPAWNING!"); + if (toDo.size() == 0) + return; - for (Kit kit : GetKits()) + for (Location loc : toDo) { - if (kit instanceof KitDestructor) - { - ((KitDestructor) kit).SetEnabled(true); - } + int id = _woodBridgeBlocks.remove(loc); + + Location source = loc.clone().add(0, 30, 0); + + // Create Part + FallingBlock block = loc.getWorld().spawnFallingBlock(source, + id, (byte) 0); + block.setVelocity(new Vector(0, -1, 0)); + BridgePart part = new BridgePart(block, loc, false); + _bridgeParts.add(part); } } } @@ -886,7 +1106,7 @@ public class Bridge extends TeamGame implements OreObsfucation while (!UtilBlock.airFoliage(block)) { block = block.getRelative(BlockFace.UP); - + if (block.getY() >= 256) break; } @@ -899,15 +1119,15 @@ public class Bridge extends TeamGame implements OreObsfucation break; } - if (block.getType() != Material.SNOW) + block = block.getRelative(BlockFace.UP); + + if (block.getTypeId() == 0) { - block = block.getRelative(BlockFace.UP); + if (Math.random() > 0.5) + block.setTypeId(39); + else + block.setTypeId(40); } - - if (Math.random() > 0.5) - block.setTypeId(39); - else - block.setTypeId(40); } } @@ -1295,7 +1515,7 @@ public class Bridge extends TeamGame implements OreObsfucation else { Scoreboard.write(C.cYellow + C.Bold + "Time Left"); - Scoreboard.write(UtilTime.MakeStr(GameTimeout - (System.currentTimeMillis() - GetStateTime()), 0)); + Scoreboard.write(UtilTime.MakeStr(5400000 - (System.currentTimeMillis() - this.GetStateTime()), 0)); } Scoreboard.draw(); @@ -1461,7 +1681,7 @@ public class Bridge extends TeamGame implements OreObsfucation { _tournamentKillMessageTimer = System.currentTimeMillis(); - Announce(C.cRed + C.Bold + "ALERT: " + C.Reset + C.Bold + "FIRST TEAM TO HAVE MOST KILLS WINS!"); + this.Announce(C.cRed + C.Bold + "ALERT: " + ChatColor.RESET + C.Bold + "FIRST TEAM TO HAVE MOST KILLS WINS!"); } } @@ -1654,32 +1874,23 @@ public class Bridge extends TeamGame implements OreObsfucation } } - @EventHandler(priority=EventPriority.LOWEST) - public void revivePlayer(CustomDamageEvent event) - { - if (!IsLive() || _bridgesDown || !(event.GetDamageeEntity() instanceof Player)) - { - return; - } - - Player player = event.GetDamageePlayer(); - - if (player.getHealth() - event.GetDamage() > 0) - { - return; - } - - if (!_usedLife.contains(player.getName())) - { - _usedLife.add(player.getName()); - - UtilPlayer.message(player, F.main("Game", "You used your " + F.elem(C.cAqua + "Early Game Revive") + ".")); - - GetTeam(player).SpawnTeleport(player); - player.setHealth(20); - event.SetCancelled("Early Game Revive"); - } - } + // @EventHandler + // public void liquidBlockDeny(BlockBreakEvent event) + // { + // if (_bridgesDown) + // return; + // + // if (!IsAlive(event.getPlayer())) + // return; + // + // if (event.getBlock().getRelative(BlockFace.UP).isLiquid() || event.getBlock().getRelative(BlockFace.UP).getRelative(BlockFace.UP).isLiquid()) + // { + // UtilPlayer.message(event.getPlayer(), F.main("Game", + // "Cannot tunnel under liquids.")); + // + // event.setCancelled(true); + // } + // } @EventHandler public void vehicleDeny(PlayerInteractEvent event) @@ -1704,6 +1915,16 @@ public class Bridge extends TeamGame implements OreObsfucation else return 12; } + + @EventHandler + public void debug(PlayerCommandPreprocessEvent event) + { + if (Manager.GetClients().hasRank(event.getPlayer(), Rank.ADMIN) && event.getMessage().contains("/oretoggle")) + _ore.ToggleVisibility(); + + if (Manager.GetClients().hasRank(event.getPlayer(), Rank.ADMIN) && event.getMessage().contains("/bridge")) + _bridgeTime = 30000; + } @EventHandler public void disableIceForm(BlockFormEvent event) @@ -1719,40 +1940,6 @@ public class Bridge extends TeamGame implements OreObsfucation UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot pickup liquids before the bridges have fallen.")); event.setCancelled(true); } - - @EventHandler - public void disableDoors(CraftItemEvent event) - { - if (_bridgesDown) - { - return; - } - - Material type = event.getRecipe().getResult().getType(); - - if (type == Material.WOOD_DOOR || type == Material.IRON_DOOR) - { - event.setResult(null); - event.setCancelled(true); - } - } - - @EventHandler - public void disableDoors(PlayerPickupItemEvent event) - { - if (_bridgesDown) - { - return; - } - - Material type = event.getItem().getItemStack().getType(); - - if (type == Material.WOOD_DOOR || type == Material.IRON_DOOR) - { - event.getItem().remove(); - event.setCancelled(true); - } - } public void setBridgeTime(int time) { @@ -1774,11 +1961,6 @@ public class Bridge extends TeamGame implements OreObsfucation return _chestLoot; } - public HashSet getBridgeParts() - { - return _bridgeParts; - } - public boolean bridgesDown() { return _bridgesDown; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java deleted file mode 100644 index 8c3496f10..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimation.java +++ /dev/null @@ -1,45 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; - -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; -import nautilus.game.arcade.game.games.bridge.BridgePart; -import nautilus.game.arcade.world.WorldData; - -public abstract class BridgeAnimation -{ - - public static final int AVERAGE_BRIDGE_BLOCKS = 3000; - - protected final Bridge _bridge; - protected final WorldData _worldData; - - public BridgeAnimation(Bridge bridge) - { - _bridge = bridge; - _worldData = bridge.WorldData; - } - - public abstract void onParse(); - - public abstract void onUpdate(UpdateType type); - - public void registerBridgePart(BridgePart part) - { - _bridge.getBridgeParts().add(part); - } - - public boolean isAir(Location location) - { - return isAir(location.getBlock()); - } - - public boolean isAir(Block block) - { - return block.getType() == Material.AIR; - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java deleted file mode 100644 index a7a8aa739..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/BridgeAnimationType.java +++ /dev/null @@ -1,44 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import nautilus.game.arcade.game.games.bridge.Bridge; - -public enum BridgeAnimationType -{ - - WOOD(WoodBridgeAnimation.class, "BROWN", "GRAY"), - ICE(IceBridgeAnimation.class, "LIGHT_BLUE"), - LAVA(LavaBridgeAnimation.class, "BLACK", "RED", "ORANGE"), - LILLY(LillyPadBridgeAnimation.class, "LIME"), - MUSHROOM(MushroomBridgeAnimation.class, "PURPLE") - - ; - - private final Class _clazz; - private final String[] _coloursUsed; - - private BridgeAnimationType(Class clazz, String... coloursUsed) - { - _clazz = clazz; - _coloursUsed = coloursUsed; - } - - public BridgeAnimation createInstance(Bridge bridge) - { - try - { - return _clazz.cast(_clazz.getConstructor(Bridge.class).newInstance(bridge)); - } - catch (Exception e) - { - e.printStackTrace(); - } - - return null; - } - - public String[] getColoursUsed() - { - return _coloursUsed; - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java deleted file mode 100644 index 6b555e861..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/IceBridgeAnimation.java +++ /dev/null @@ -1,79 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; - -public class IceBridgeAnimation extends BridgeAnimation -{ - - private List _iceBridge; - - public IceBridgeAnimation(Bridge bridge) - { - super(bridge); - - _iceBridge = new ArrayList<>(AVERAGE_BRIDGE_BLOCKS); - } - - @Override - public void onParse() - { - _iceBridge = _worldData.GetDataLocs("LIGHT_BLUE"); - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.FASTEST || _iceBridge.isEmpty()) - { - return; - } - - int attempts = 0; - int done = 0; - - while (done < 5 && attempts < 400) - { - attempts++; - - // Random Block - Location loc = UtilAlg.Random(_iceBridge); - - Block block = loc.getBlock().getRelative(BlockFace.DOWN); - - if (!block.isLiquid()) - { - continue; - } - - if (block.getRelative(BlockFace.NORTH).isLiquid() && block.getRelative(BlockFace.EAST).isLiquid() && block.getRelative(BlockFace.SOUTH).isLiquid() && block.getRelative(BlockFace.WEST).isLiquid()) - { - continue; - } - - _iceBridge.remove(loc); - - if (Math.random() > 0.25) - { - MapUtil.QuickChangeBlockAt(block.getLocation(), Material.PACKED_ICE); - } - else - { - MapUtil.QuickChangeBlockAt(block.getLocation(), Material.ICE); - } - - done++; - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java deleted file mode 100644 index 2cf015470..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LavaBridgeAnimation.java +++ /dev/null @@ -1,84 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.FallingBlock; - -import mineplex.core.common.util.UtilMath; -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; -import nautilus.game.arcade.game.games.bridge.BridgePart; - -public class LavaBridgeAnimation extends BridgeAnimation -{ - - private List _lavaSource; - private List _lavaBridge; - - public LavaBridgeAnimation(Bridge bridge) - { - super(bridge); - - _lavaSource = new ArrayList<>(); - _lavaBridge = new ArrayList<>(AVERAGE_BRIDGE_BLOCKS); - } - - @Override - public void onParse() - { - for (Location loc : _worldData.GetDataLocs("RED")) - { - _lavaBridge.add(loc.getBlock().getLocation()); - } - - for (Location loc : _worldData.GetDataLocs("ORANGE")) - { - _lavaBridge.add(loc.getBlock().getLocation()); - _lavaBridge.add(loc.getBlock().getRelative(BlockFace.UP).getLocation()); - } - - _lavaSource = _worldData.GetDataLocs("BLACK"); - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.FASTEST) - { - return; - } - - for (int i = 0; i < 3; i++) - { - if (!_lavaBridge.isEmpty() && !_lavaSource.isEmpty()) - { - // Random Block - Location bestLoc = _lavaBridge.get(UtilMath.r(_lavaBridge.size())); - - if (bestLoc.getBlock().getRelative(BlockFace.DOWN).isLiquid()) - { - continue; - } - - _lavaBridge.remove(bestLoc); - - Location source = _lavaSource.get(UtilMath.r(_lavaSource.size())); - - // Create Part - FallingBlock block = bestLoc.getWorld().spawnFallingBlock(source, Material.NETHERRACK, (byte) 0); - BridgePart part = new BridgePart(block, bestLoc, true); - - registerBridgePart(part); - - // Sound - source.getWorld().playSound(source, Sound.EXPLODE, 5f * (float) Math.random(), 0.5f + (float) Math.random()); - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java deleted file mode 100644 index 839a9536e..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/LillyPadBridgeAnimation.java +++ /dev/null @@ -1,65 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.BlockFace; - -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilTime; -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; - -public class LillyPadBridgeAnimation extends BridgeAnimation -{ - - private Map _lillyPads = new HashMap<>(); - - public LillyPadBridgeAnimation(Bridge bridge) - { - super(bridge); - } - - @Override - public void onParse() - { - for (Location loc : _worldData.GetDataLocs("LIME")) - { - _lillyPads.put(loc, 0L); - } - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.FASTEST) - return; - - for (int i = 0; i < 3; i++) - { - if (_lillyPads != null && !_lillyPads.isEmpty()) - { - // Random Block - Location loc = UtilAlg.Random(_lillyPads.keySet()); - - if (!UtilTime.elapsed(_lillyPads.get(loc), 8000)) - continue; - - if (!loc.getBlock().getRelative(BlockFace.DOWN).isLiquid()) - continue; - - _lillyPads.remove(loc); - - MapUtil.QuickChangeBlockAt(loc, Material.WATER_LILY); - - // Sound - loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 111); - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java deleted file mode 100644 index dad3ecdb7..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/MushroomBridgeAnimation.java +++ /dev/null @@ -1,107 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilTime; -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; - -public class MushroomBridgeAnimation extends BridgeAnimation -{ - - private Map _mushroomStem = new HashMap<>(); - private Map _mushroomTop = new HashMap<>(); - private boolean _stemsGrown = false; - - public MushroomBridgeAnimation(Bridge bridge) - { - super(bridge); - } - - @Override - public void onParse() - { - for (Location loc : _worldData.GetCustomLocs("21")) - { - _mushroomStem.put(loc, 0L); - loc.getBlock().setType(Material.AIR); - } - - for (Location loc : _worldData.GetDataLocs("PURPLE")) - { - _mushroomTop.put(loc, 0L); - } - } - - @Override - public void onUpdate(UpdateType type) - { - if (_mushroomStem != null && !_mushroomStem.isEmpty()) - { - for (int i = 0; i < 4 && !_mushroomStem.isEmpty(); i++) - { - double lowestY = 0; - Location lowestLoc = null; - - for (Location loc : _mushroomStem.keySet()) - { - if (!UtilTime.elapsed(_mushroomStem.get(loc), 6000)) - continue; - - if (lowestLoc == null || loc.getY() < lowestY) - { - lowestY = loc.getY(); - lowestLoc = loc; - } - } - - if (lowestLoc == null) - continue; - - _mushroomStem.remove(lowestLoc); - - MapUtil.QuickChangeBlockAt(lowestLoc, 100, (byte) 15); - } - } - else - { - _stemsGrown = true; - } - - if (_stemsGrown && _mushroomTop != null && !_mushroomTop.isEmpty()) - { - int attempts = 0; - int done = 0; - while (done < 6 && attempts < 400) - { - attempts++; - - // Random Block - Location loc = UtilAlg.Random(_mushroomTop.keySet()); - - if (!UtilTime.elapsed(_mushroomTop.get(loc), 6000)) - continue; - - Block block = loc.getBlock(); - - if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR && block.getRelative(BlockFace.NORTH).getType() == Material.AIR && block.getRelative(BlockFace.EAST).getType() == Material.AIR && block.getRelative(BlockFace.SOUTH).getType() == Material.AIR && block.getRelative(BlockFace.WEST).getType() == Material.AIR) - continue; - - _mushroomTop.remove(loc); - - MapUtil.QuickChangeBlockAt(block.getLocation(), 99, (byte) 14); - - done++; - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java deleted file mode 100644 index e149f2bc3..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/WoodBridgeAnimation.java +++ /dev/null @@ -1,129 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.FallingBlock; -import org.bukkit.util.Vector; - -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; -import nautilus.game.arcade.game.games.bridge.BridgePart; - -public class WoodBridgeAnimation extends BridgeAnimation -{ - - private static final BlockFace[] FACES = new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; - private static final int Y_MOD = 30; - - private final Map _woodBridge; - - public WoodBridgeAnimation(Bridge bridge) - { - super(bridge); - - _woodBridge = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); - } - - @Override - public void onParse() - { - onParse(_worldData.GetDataLocs("BROWN"), false); - onParse(_worldData.GetDataLocs("GRAY"), true); - } - - public void onParse(List locations, boolean aboveBelow) - { - for (Location location : locations) - { - if (aboveBelow) - { - _woodBridge.put(location.getBlock().getRelative(BlockFace.UP).getLocation(), Material.FENCE); - _woodBridge.put(location, Material.LOG); - } - else - { - _woodBridge.put(location, Material.WOOD_STEP); - } - } - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.FASTEST) - { - return; - } - - List toDo = new ArrayList<>(); - - for (Location location : _woodBridge.keySet()) - { - Material material = _woodBridge.get(location); - - if (material == Material.LOG) - { - int adjacent = 0; - - for (BlockFace face : FACES) - { - if (!isAir(location.getBlock().getRelative(face))) - { - adjacent++; - } - } - if (adjacent > 0) - { - toDo.add(location); - } - } - else if (material == Material.FENCE) - { - if (!isAir(location.getBlock().getRelative(BlockFace.DOWN))) - { - toDo.add(location); - } - } - else if (material == Material.WOOD_STEP) - { - int adjacent = 0; - - for (BlockFace face : FACES) - { - if (!isAir(location.getBlock().getRelative(face))) - { - adjacent++; - } - } - if (adjacent > 0) - { - toDo.add(location); - } - } - } - - if (toDo.isEmpty()) - { - return; - } - - for (Location location : toDo) - { - Material material = _woodBridge.remove(location); - Location source = location.clone().add(0, Y_MOD, 0); - - // Create Part - FallingBlock block = location.getWorld().spawnFallingBlock(source, material, (byte) 0); - block.setVelocity(new Vector(0, -1, 0)); - BridgePart part = new BridgePart(block, location, false); - - registerBridgePart(part); - } - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java deleted file mode 100644 index fe5e6ed04..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/CustomBridgeAnimation.java +++ /dev/null @@ -1,246 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation.custom; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.block.Block; - -import mineplex.core.blockrestore.BlockRestore; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilParticle.ParticleType; -import mineplex.core.common.util.UtilParticle.ViewDist; -import nautilus.game.arcade.game.games.bridge.Bridge; -import nautilus.game.arcade.game.games.bridge.animation.BridgeAnimation; - -public abstract class CustomBridgeAnimation extends BridgeAnimation -{ - - private static final String BLOCK_IDS_KEY = "BLOCK_IDS"; - private static final String RATE_KEY = "RATE"; - private static final String PARTICLE_KEY = "PARTICLE"; - private static final String SOUND_KEY = "SOUND"; - private static final String REGION_KEY = "BRIDGE"; - - protected final BlockRestore _restore; - - private final String _typeKey; - protected final Map _bridgeBlocks; - - // Configuration - protected List _blockIds; - protected int _rate; - protected ParticleType _particle; - - // Sound - protected Sound _sound; - protected float _pitch; - - protected double _maxDistance; - - public CustomBridgeAnimation(Bridge bridge, String typeKey) - { - super(bridge); - - _restore = bridge.getArcadeManager().GetBlockRestore(); - - _typeKey = typeKey; - _bridgeBlocks = new HashMap<>(AVERAGE_BRIDGE_BLOCKS); - - // Defaults - // Wood, Logs, Fences - _blockIds = Arrays.asList(5, 17, 85); - _rate = 1; - _particle = ParticleType.BLOCK_DUST; - } - - @Override - public void onParse() - { - List blockIds = new ArrayList<>(); - - for (String key : _worldData.GetAllCustomLocs().keySet()) - { - String[] split = key.split(" "); - String subKey = split[0]; - - if (split.length < 2) - { - continue; - } - - switch (subKey) - { - - case BLOCK_IDS_KEY: - // Set the block ids that the animation will use - - for (int i = 1; i < split.length; i++) - { - try - { - blockIds.add(Integer.parseInt(split[i])); - } - catch (NumberFormatException e) - { - continue; - } - } - - break; - - case RATE_KEY: - // Set the rate at which the animation will run at - - try - { - _rate = Integer.parseInt(split[1]); - } - catch (NumberFormatException e) - { - continue; - } - - break; - - case PARTICLE_KEY: - // Set which type of particle will be displayed when a block - // spawns - - try - { - _particle = ParticleType.valueOf(split[1]); - } - catch (IllegalArgumentException e) - { - continue; - } - - break; - - case SOUND_KEY: - // Set the sound and pitch that will be played when a block - // spawns - - if (split.length < 3) - { - continue; - } - - try - { - _sound = Sound.valueOf(split[1]); - } - catch (IllegalArgumentException e) - { - continue; - } - - try - { - _pitch = Float.parseFloat(split[2]); - } - catch (NumberFormatException e) - { - continue; - } - - break; - - default: - break; - } - } - - // Set configuration values - _blockIds = blockIds; - - // Save all blocks in a big map. - for (String key : _worldData.GetAllCustomLocs().keySet()) - { - if (!key.startsWith(REGION_KEY)) - { - continue; - } - - List locations = _worldData.GetCustomLocs(key); - - if (locations.size() < 2) - { - continue; - } - - for (Block block : UtilBlock.getInBoundingBox(locations.get(0), locations.get(1))) - { - if (!_blockIds.contains(block.getTypeId()) || _bridgeBlocks.containsKey(block)) - { - continue; - } - - double dist = UtilMath.offset2d(block.getLocation(), _bridge.GetSpectatorLocation()); - - if (dist > _maxDistance) - { - _maxDistance = dist; - } - - _restore.add(block, Material.AIR.getId(), (byte) 0, Integer.MAX_VALUE); - _bridgeBlocks.put(block.getLocation(), dist); - } - } - } - - public void onBlockSet(Block block) - { - World world = _worldData.World; - Location location = block.getLocation().add(0.5, 0.5, 0.5); - - if (_particle != null) - { - if (_particle == ParticleType.BLOCK_DUST) - { - world.playEffect(location, Effect.STEP_SOUND, block.getType(), block.getData()); - } - else - { - UtilParticle.PlayParticleToAll(_particle, block.getLocation(), 0.5F, 0.5F, 0.5F, 0.5F, 5, ViewDist.NORMAL); - } - } - - if (_sound != null) - { - world.playSound(location, _sound, 1, _pitch); - } - } - - public final String getTypeKey() - { - return _typeKey; - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - - builder.append("Type: " + _typeKey).append("\n"); - builder.append("Bridge Blocks: " + _bridgeBlocks.size()).append("\n"); - builder.append("Block Ids: " + _blockIds).append("\n"); - builder.append("Rate: " + _rate).append("\n"); - builder.append("Particle: " + (_particle == null ? "Null" : _particle.getFriendlyName())).append("\n"); - builder.append("Sound: " + (_sound == null ? "Null" : _sound.toString() + " Pitch: " + _pitch)).append("\n"); - builder.append("Max Distance: " + _maxDistance).append("\n"); - - return builder.toString(); - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java deleted file mode 100644 index fe0779c7c..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RadiusCustomBridgeAnimation.java +++ /dev/null @@ -1,58 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation.custom; - -import java.util.Iterator; - -import org.bukkit.Location; -import org.bukkit.block.Block; - -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; - -public class RadiusCustomBridgeAnimation extends CustomBridgeAnimation -{ - - private double _minDistance; - - public RadiusCustomBridgeAnimation(Bridge bridge) - { - super(bridge, "RADIUS"); - } - - @Override - public void onParse() - { - super.onParse(); - - _minDistance = _maxDistance; - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.FAST) - { - return; - } - - _minDistance -= _rate; - - Iterator iterator = _bridgeBlocks.keySet().iterator(); - - while (iterator.hasNext()) - { - Location location = iterator.next(); - double dist = _bridgeBlocks.get(location); - - if (dist > _minDistance) - { - Block block = location.getBlock(); - - _restore.restore(block); - onBlockSet(block); - - iterator.remove(); - } - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java deleted file mode 100644 index badf135bb..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/animation/custom/RandomCustomBridgeAnimation.java +++ /dev/null @@ -1,44 +0,0 @@ -package nautilus.game.arcade.game.games.bridge.animation.custom; - -import java.util.Iterator; - -import org.bukkit.Location; -import org.bukkit.block.Block; - -import mineplex.core.updater.UpdateType; -import nautilus.game.arcade.game.games.bridge.Bridge; - -public class RandomCustomBridgeAnimation extends CustomBridgeAnimation -{ - - public RandomCustomBridgeAnimation(Bridge bridge) - { - super(bridge, "RANDOM"); - } - - @Override - public void onUpdate(UpdateType type) - { - if (type != UpdateType.TICK) - { - return; - } - - Iterator iterator = _bridgeBlocks.keySet().iterator(); - int i = 0; - - while (iterator.hasNext() && i < _rate) - { - i++; - Location location = iterator.next(); - - Block block = location.getBlock(); - - _restore.restore(block); - onBlockSet(block); - - iterator.remove(); - } - } - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java index 021c06e83..78fc4acae 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitApple.java @@ -36,4 +36,4 @@ public class KitApple extends ProgressingKit { } -} \ No newline at end of file +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java index 87ee2d8dd..a02a04427 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitArcher.java @@ -53,6 +53,6 @@ public class KitArcher extends ProgressingKit Bridge bridge = (Bridge) Manager.GetGame(); if(!bridge.hasUsedRevive(player)) - player.getInventory().addItem(PLAYER_ITEMS); + player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BOW)); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java index 9204c8d7a..497017ee6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitBerserker.java @@ -46,4 +46,4 @@ public class KitBerserker extends ProgressingKit { player.getInventory().addItem(PLAYER_ITEMS); } -} \ No newline at end of file +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java index 178ae8ef1..b5710854f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/kits/KitDestructor.java @@ -44,7 +44,7 @@ public class KitDestructor extends ProgressingKit { super(manager, "Destructor", "bridgedesctructor", KitAvailability.Achievement, 99999, DESCRIPTION, PERKS, EntityType.ZOMBIE, IN_HAND); - setAchievementRequirements(ACHIEVEMENTS); + this.setAchievementRequirements(ACHIEVEMENTS); } @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java index 5935aaee0..17b6b5ce5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/bridge/modes/OverpoweredBridge.java @@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; @@ -28,6 +29,7 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.PlayerPrepareTeleportEvent; +import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.games.AbsorptionFix; import nautilus.game.arcade.game.games.bridge.Bridge; import net.md_5.bungee.api.ChatColor; @@ -70,8 +72,38 @@ public class OverpoweredBridge extends Bridge public void ParseData() { _starterChests = new HashMap<>(); - - super.ParseData(); + + ParseLavaBridge(); + ParseWoodBridge(); + ParseIceBridge(); + ParseLillyPad(); + ParseMushrooms(); + + ParseChests(); + + ParseOre(WorldData.GetCustomLocs("73")); // Red + ParseOre(WorldData.GetCustomLocs("14")); // Yellow + ParseOre(WorldData.GetCustomLocs("129")); // Green + ParseOre(WorldData.GetCustomLocs("56")); // Blue + + //Mass Teams + if (!WorldData.GetCustomLocs("152").isEmpty()) + ParseOre(WorldData.GetCustomLocs("152")); + if (!WorldData.GetCustomLocs("41").isEmpty()) + ParseOre(WorldData.GetCustomLocs("41")); + if (!WorldData.GetCustomLocs("133").isEmpty()) + ParseOre(WorldData.GetCustomLocs("133")); + if (!WorldData.GetCustomLocs("57").isEmpty()) + ParseOre(WorldData.GetCustomLocs("57")); + + if (!WorldData.GetCustomLocs("100").isEmpty()) + ParseOre(WorldData.GetCustomLocs("100")); + if (!WorldData.GetCustomLocs("86").isEmpty()) + ParseOre(WorldData.GetCustomLocs("86")); + if (!WorldData.GetCustomLocs("103").isEmpty()) + ParseOre(WorldData.GetCustomLocs("103")); + if (!WorldData.GetCustomLocs("22").isEmpty()) + ParseOre(WorldData.GetCustomLocs("22")); } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java index 638d2620b..2aed67d39 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java @@ -1,7 +1,10 @@ package nautilus.game.arcade.game.modules; import com.google.gson.JsonElement; +import mineplex.core.Managers; +import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.TeamGame; import org.bukkit.event.Listener; /** diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java deleted file mode 100644 index 6a1f13bae..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/WorldBorderModule.java +++ /dev/null @@ -1,116 +0,0 @@ -package nautilus.game.arcade.game.modules; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import mineplex.core.common.Pair; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.packethandler.IPacketHandler; -import mineplex.core.packethandler.PacketHandler; -import mineplex.core.packethandler.PacketInfo; -import nautilus.game.arcade.events.GameStateChangeEvent; -import nautilus.game.arcade.game.Game.GameState; -import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder; -import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder.EnumWorldBorderAction; -import net.minecraft.server.v1_8_R3.WorldBorder; - -public class WorldBorderModule extends Module implements IPacketHandler -{ - - private PacketHandler _packetHandler; - private Map _sizeToSet; - private Map> _centerToSet; - - @Override - protected void setup() - { - _packetHandler = getGame().getArcadeManager().getPacketHandler(); - _sizeToSet = new HashMap<>(); - _centerToSet = new HashMap<>(); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void live(GameStateChangeEvent event) - { - if (event.GetState() != GameState.Prepare) - { - return; - } - - _packetHandler.addPacketHandler(this, PacketPlayOutWorldBorder.class); - } - - @Override - public void handle(PacketInfo packetInfo) - { - UUID player = packetInfo.getPlayer().getUniqueId(); - PacketPlayOutWorldBorder packet = (PacketPlayOutWorldBorder) packetInfo.getPacket(); - - try - { - Field actionField = packet.getClass().getDeclaredField("a"); - actionField.setAccessible(true); - EnumWorldBorderAction action = (EnumWorldBorderAction) actionField.get(packet); - - if (action == EnumWorldBorderAction.SET_SIZE) - { - Field sizeField = packet.getClass().getDeclaredField("e"); - sizeField.setAccessible(true); - double newSize = _sizeToSet.get(player); - - sizeField.set(packet, newSize); - } - else if (action == EnumWorldBorderAction.SET_CENTER) - { - Field xField = packet.getClass().getDeclaredField("c"); - Field zField = packet.getClass().getDeclaredField("d"); - - xField.setAccessible(true); - zField.setAccessible(true); - - Pair pair = _centerToSet.get(player); - - xField.set(packet, pair.getLeft()); - zField.set(packet, pair.getRight()); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void cleanup() - { - _packetHandler.removePacketHandler(this); - } - - public void setSize(Player player, double size) - { - _sizeToSet.put(player.getUniqueId(), size); - - sendPacket(player, EnumWorldBorderAction.SET_SIZE); - } - - public void setCenter(Player player, Location location) - { - _centerToSet.put(player.getUniqueId(), Pair.create(location.getX(), location.getZ())); - - sendPacket(player, EnumWorldBorderAction.SET_CENTER); - } - - private void sendPacket(Player player, EnumWorldBorderAction action) - { - WorldBorder border = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder(); - UtilPlayer.sendPacket(player, new PacketPlayOutWorldBorder(border, action)); - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java index eabe114f5..a93f7415e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/ProgressingKit.java @@ -30,7 +30,6 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilText; import mineplex.core.donation.Donor; import mineplex.core.menu.Menu; import mineplex.core.progression.ProgressiveKit; @@ -54,8 +53,6 @@ import net.minecraft.server.v1_8_R3.World; public abstract class ProgressingKit extends Kit implements ProgressiveKit { - public static final String COOLDOWN = "Cooldown"; - private static final FireworkEffect EFFECT = FireworkEffect.builder() .withColor(Color.AQUA) .with(Type.BALL) @@ -423,11 +420,6 @@ public abstract class ProgressingKit extends Kit implements ProgressiveKit return "Receive " + C.cGreen + amount + C.cWhite + " " + item + " every " + C.cGreen + time + C.cWhite + " second" + (time == 1 ? "" : "s") + (max > 0 ? ". Max " + C.cGreen + max : ""); } - - public static String receiveItem(String item, int amount) - { - return "Receive " + (amount == 1 ? (UtilText.startsWithVowel(item) ? "an" :" a") : C.cGreen + amount) + " " + item; - } public static String click(boolean left, String comp) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java index 8c575627c..5d63023a5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDestructor.java @@ -294,9 +294,7 @@ public class PerkDestructor extends Perk if (lowest != null) { - Block down = lowest.getRelative(BlockFace.DOWN); - - if (lowest.getType() != Material.AIR && (UtilBlock.airFoliage(down) || down.isLiquid())) + if (lowest.getType() != Material.AIR && UtilBlock.airFoliage(lowest.getRelative(BlockFace.DOWN))) { lowest.getWorld().playEffect(lowest.getLocation(), Effect.STEP_SOUND, lowest.getType()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java index 61d4b8923..90316be6e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java @@ -1,17 +1,18 @@ package nautilus.game.arcade.stats; -import mineplex.core.common.util.UtilPlayer; -import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; -import nautilus.game.arcade.game.Game; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import nautilus.game.arcade.game.Game; + public class DeathBomberStatTracker extends StatTracker { private int _required; @@ -51,11 +52,6 @@ public class DeathBomberStatTracker extends StatTracker if(killer.equals(killed)) return; - if (killer.getItemInHand().getType() != Material.TNT) - { - return; - } - if (event.GetLog().GetKiller() != null && event.GetLog().GetKiller().GetReason().contains("Throwing TNT")) { Integer count = _killCount.get(killer.getUniqueId()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java index de127e6b2..5495e89a2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/FoodForTheMassesStatTracker.java @@ -1,6 +1,5 @@ package nautilus.game.arcade.stats; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -41,11 +40,6 @@ public class FoodForTheMassesStatTracker extends StatTracker Player player = UtilPlayer.searchExact(event.GetLog().GetPlayer().GetName()); if (player == null) return; - - if (killer.getItemInHand().getType() != Material.APPLE) - { - return; - } if (event.GetLog().GetKiller().GetReason() != null && event.GetLog().GetKiller().GetReason().contains("Apple Thrower")) {