From e4981c74913f2c58be11042a4f8145a02f9da50c Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 14 Nov 2015 20:30:37 +0000 Subject: [PATCH] Undead camp finishing stuff --- .../game/clans/clans/ClansManager.java | 2 +- .../clans/worldevent/EventTerrainFinder.java | 216 ++++++++---------- .../clans/worldevent/WorldEventManager.java | 50 ++-- .../clans/worldevent/WorldEventType.java | 26 +-- .../worldevent/command/ClearCommand.java | 4 +- .../worldevent/command/StartCommand.java | 2 +- .../minecraft/game/core/boss/WorldEvent.java | 12 +- 7 files changed, 145 insertions(+), 167 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 7b3c33084..3f5fb4ba2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -198,7 +198,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat _npcManager = new NpcManager(plugin, creature); _condition = new SkillConditionManager(plugin); DamageManager damageManager = new DamageManager(plugin, _combatManager, _npcManager, _disguiseManager, _condition); - _worldEvent = new WorldEventManager(plugin, this, damageManager, _lootManager, blockRestore); + _worldEvent = new WorldEventManager(plugin, this, damageManager, _lootManager, blockRestore, _clanRegions); TaskManager taskManager = new TaskManager(plugin, _clientManager, webServerAddress); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/EventTerrainFinder.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/EventTerrainFinder.java index 0f20cb4bd..0bfdc2f1a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/EventTerrainFinder.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/EventTerrainFinder.java @@ -1,179 +1,161 @@ package mineplex.game.clans.clans.worldevent; -import java.util.HashMap; -import java.util.HashSet; +import java.util.ArrayList; +import java.util.List; import java.util.Set; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; -import mineplex.game.clans.clans.ClansManager; - -import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.regions.ClansRegions; + public class EventTerrainFinder { private WorldEventManager _eventManager; private ClansManager _clansManager; - - public EventTerrainFinder(WorldEventManager eventManager, ClansManager clansManager) + private ClansRegions _clansRegions; + + public EventTerrainFinder(WorldEventManager eventManager, ClansManager clansManager, ClansRegions clansRegions) { _eventManager = eventManager; _clansManager = clansManager; + _clansRegions = clansRegions; } - + public double posNeg() { - if (Math.random() > 0.5) - return -1; + if (Math.random() > 0.5) return -1; return 1; } - - public Location findArea(World world, int size, int vert) + + public Location findAreaInBorderlands(World world, int size, int vert) { - for (int i=0 ; i<20 ; i++) + System.out.println("Starting finding area..."); + int borderlandsDist = 31; + int borderlandsWidth = 47 - borderlandsDist; + + for (int i = 0; i < 20; i++) { int x = 0; int z = 0; - - //X Side - if (Math.random() > 0.5) + + x = (borderlandsDist * 16) + (UtilMath.clamp(UtilMath.random.nextInt(borderlandsWidth), 2, borderlandsWidth - 2) * 16); + z = (borderlandsDist * 16) + (UtilMath.clamp(UtilMath.random.nextInt(borderlandsWidth), 2, borderlandsWidth - 2) * 16); + + if (UtilMath.random.nextBoolean()) { - x = (int) (posNeg() * ((400 + size) + UtilMath.r(200 - (size*2)))); - z = (int) (posNeg() * UtilMath.r(600 - size)); + x = -x; + z = -z; } - //Z Side - else - { - z = (int) (posNeg() * ((400 + size) + UtilMath.r(200 - (size*2)))); - x = (int) (posNeg() * UtilMath.r(600 - size)); - } - + Location loc = UtilBlock.getHighest(world, x, z).getLocation(); - - int total = ((size*2)+1)*((size*2)+1); - - int liquid = 0; - HashMap heights = new HashMap(); - - HashSet chunks = new HashSet(); - boolean wilderness = true; - - //Gather Data - for (x=-size ; x<=size && wilderness ; x++) - for (z=-size ; z<=size && wilderness ; z++) - { - Block block = UtilBlock.getHighest(world, loc.getBlockX()+x, loc.getBlockZ()+z); - - if (!chunks.contains(block.getChunk())) - if (_clansManager.getClanUtility().isClaimed(block.getLocation())) - { - chunks.add(block.getChunk()); - wilderness = false; - break; - } - - //Liquid - if (block.getRelative(BlockFace.DOWN).isLiquid() || block.isLiquid()) - liquid++; - - //Height - int heightDiff = block.getY() - loc.getBlockY(); - if (!heights.containsKey(heightDiff)) heights.put(heightDiff, 1); - else heights.put(heightDiff, heights.get(heightDiff) + 1); - } - - if (!wilderness) - continue; - - //Too Watery - if ((double)liquid/(double)total > 0.25) - continue; - - //Too Height Variable - int withinHeight = 0; - for (int h=-vert ; h<=vert ; h++) + + int blocks = ((size * 2) + 1) * ((size * 2) + 1); + + boolean suitable = true; + + int liquids = 0; + for (x = -size; x < size; x++) { - if (!heights.containsKey(h)) - continue; - - withinHeight += heights.get(h); + for (z = -size; z < size; z++) + { + Block topBlock = loc.getWorld().getBlockAt(loc.getBlockX() + x, loc.getWorld().getHighestBlockYAt(loc.getBlockX() + x, loc.getBlockZ() + z), loc.getBlockZ()); + + if (255 - topBlock.getY() < size) + { + suitable = false; + continue; + } + + if (topBlock.isLiquid()) + { + liquids++; + } + } } - - if ((double)withinHeight/(double)total < 0.9) + + if (liquids > 1 && (((double) blocks)) / ((double) liquids) > 0.25) + { + System.out.println("water bad"); + suitable = false; + } + + // If this region is not suitable, try again. + if (!suitable) + { continue; - - //Success + } + + System.out.println("Done finding area... [success]"); + + // Success return loc; } - + + System.out.println("Done finding area..."); + return null; } - + public Location locateSpace(Location areaSource, int areaRadius, int xArea, int yArea, int zArea, boolean replaceBlocks, boolean aboveOther, Set otherBlock) { - for (int i=0 ; i<20 ; i++) + for (int i = 0; i < 20; i++) { - int x = UtilMath.r(areaRadius*2) - areaRadius + areaSource.getBlockX(); - int z = UtilMath.r(areaRadius*2) - areaRadius + areaSource.getBlockZ(); - + int x = UtilMath.r(areaRadius * 2) - areaRadius + areaSource.getBlockX(); + int z = UtilMath.r(areaRadius * 2) - areaRadius + areaSource.getBlockZ(); + Block block = UtilBlock.getHighest(areaSource.getWorld(), x, z); - - if (!aboveOther) - if (otherBlock.contains(block.getRelative(BlockFace.DOWN))) - continue; - + + if (!aboveOther) if (otherBlock.contains(block.getRelative(BlockFace.DOWN))) continue; + boolean valid = true; - + int overlaps = 0; - - //Previous - for (x=-xArea ; x<=xArea ; x++) + + // Previous + for (x = -xArea; x <= xArea; x++) { - for (z=-zArea ; z<=zArea ; z++) + for (z = -zArea; z <= zArea; z++) { - for (int y=0 ; y<=yArea ; y++) + for (int y = 0; y <= yArea; y++) { - //Check Blocks - Block cur = areaSource.getWorld().getBlockAt(block.getX()+x, block.getY()+y, block.getZ()+z); - + // Check Blocks + Block cur = areaSource.getWorld().getBlockAt(block.getX() + x, block.getY() + y, block.getZ() + z); + if (cur.getRelative(BlockFace.DOWN).isLiquid()) { valid = false; break; } - + if (otherBlock.contains(cur)) { valid = false; break; } - - //Check Area - if (!UtilBlock.airFoliage(cur)) - overlaps += 1; + + // Check Area + if (!UtilBlock.airFoliage(cur)) overlaps += 1; } - - if (!valid) - break; + + if (!valid) break; } - - if (!valid) - break; + + if (!valid) break; } - - if (!replaceBlocks && overlaps > 0) - continue; - - if (!valid) - continue; - + + if (!replaceBlocks && overlaps > 0) continue; + + if (!valid) continue; + return block.getLocation(); } - + return null; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index 69d62e1fd..67c41636e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -27,6 +27,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.loot.LootManager; +import mineplex.game.clans.clans.regions.ClansRegions; import mineplex.game.clans.clans.worldevent.command.WorldEventCommand; import mineplex.minecraft.game.core.boss.EventState; import mineplex.minecraft.game.core.boss.WorldEvent; @@ -43,24 +44,28 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement private LootManager _lootManager; private BlockRestore _blockRestore; - private long _lastEventEnd; private long _nextEventStart; - public WorldEventManager(JavaPlugin plugin, ClansManager clansManager, DamageManager damageManager, LootManager lootManager, BlockRestore blockRestore) + public WorldEventManager(JavaPlugin plugin, ClansManager clansManager, DamageManager damageManager, LootManager lootManager, BlockRestore blockRestore, ClansRegions clansRegions) { super("World Event", plugin); _random = new Random(); - _terrainFinder = new EventTerrainFinder(this, clansManager); + _terrainFinder = new EventTerrainFinder(this, clansManager, clansRegions); _clansManager = clansManager; _damageManager = damageManager; _lootManager = lootManager; _blockRestore = blockRestore; _runningEvents = new LinkedList(); - _lastEventEnd = System.currentTimeMillis(); updateNextEventTime(); } + public void addCommands() + { + addCommand(new WorldEventCommand(this)); + } + + // PS: This never gets called @Override public void disable() { @@ -71,9 +76,12 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement } @EventHandler - public void removeEvent(UpdateEvent event) + public void cleanupEvent(UpdateEvent event) { - if (event.getType() != UpdateType.SEC) return; + if (event.getType() != UpdateType.SEC) + { + return; + } boolean removed = false; @@ -86,14 +94,13 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement HandlerList.unregisterAll(worldEvent); iterator.remove(); - // If the event was cancelled, we don't need to run a cleanup + // If the event was cancelled, cleanup was already done. if (worldEvent.getState() == EventState.COMPLETE) { worldEvent.cleanup(); } removed = true; - _lastEventEnd = System.currentTimeMillis(); } } @@ -101,18 +108,13 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement { updateNextEventTime(); } - } - - @EventHandler - public void startEvent(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) return; - if (_runningEvents.size() == 0 && System.currentTimeMillis() > _nextEventStart) + + if (_runningEvents.size() == 0 && System.currentTimeMillis() >= _nextEventStart) { if (UtilServer.getPlayers().length > 0) { - startRandomEvent(); + tryStartEvent(); } else { @@ -121,11 +123,11 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement } } - private void startRandomEvent() + private void tryStartEvent() { WorldEventType[] types = WorldEventType.values(); WorldEventType type = types[_random.nextInt(types.length)]; - Location location = _terrainFinder.findArea(Bukkit.getWorlds().get(0), type.getAreaNeeded(), type.getAreaNeeded()); + Location location = _terrainFinder.findAreaInBorderlands(Bukkit.getWorlds().get(0), type.getAreaNeeded(), type.getAreaNeeded()); if (location != null) { initializeEvent(type.createInstance(this, location)); @@ -133,7 +135,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement else { // Try again in 5 minutes - _nextEventStart = System.currentTimeMillis() + 300000; + _nextEventStart = System.currentTimeMillis() + 25000;//300000; } } @@ -194,16 +196,10 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement return _terrainFinder; } - @Override - public void addCommands() - { - addCommand(new WorldEventCommand(this)); - } - private void updateNextEventTime() { - // 45 Minutes + 0 - 15 Minutes - long waitTime = 2700000L + _random.nextInt(900000); + // 45 Minutes + (0 - 15 Minutes) + long waitTime = 25000;//2700000L + _random.nextInt(900000); _nextEventStart = System.currentTimeMillis() + waitTime; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java index e1598e018..35a7cdacb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java @@ -12,48 +12,48 @@ import org.bukkit.Location; public enum WorldEventType { - SLIME_KING("Slime King", SlimeBoss.class, 30), KING_OF_THE_HILL("King of The Hill", KingHill.class, 30), UNDEAD_CAMP( - "Undead Camp", UndeadCamp.class, 30), Golem("Iron Wizard", GolemBoss.class, 30); - + SLIME_KING("Slime King", SlimeBoss.class, 30), + KING_OF_THE_HILL("King of The Hill", KingHill.class, 30), + UNDEAD_CAMP("Undead Camp", UndeadCamp.class, 30), + Golem("Iron Wizard", GolemBoss.class, 30); + private String _name; private Class _clazz; private int _areaNeeded; - + WorldEventType(String name, Class clazz, int areaNeeded) { _name = name; _clazz = clazz; _areaNeeded = areaNeeded; } - + public int getAreaNeeded() { return _areaNeeded; } - + public WorldEvent createInstance(WorldEventManager eventManager, Location centerLocation) { WorldEvent worldEvent = null; - + try { for (Constructor con : _clazz.getConstructors()) { Class[] classes = con.getParameterTypes(); - + if (classes[0] == WorldEventManager.class) { worldEvent = (WorldEvent) con.newInstance(eventManager, centerLocation); } else if (classes.length == 4) { - worldEvent = (WorldEvent) con.newInstance(eventManager.getDamage(), eventManager.getBlockRestore(), - eventManager.getClans().getCondition(), centerLocation); + worldEvent = (WorldEvent) con.newInstance(eventManager.getDamage(), eventManager.getBlockRestore(), eventManager.getClans().getCondition(), centerLocation); } else { - worldEvent = (WorldEvent) con.newInstance(eventManager.getDamage(), eventManager.getBlockRestore(), - eventManager.getClans().getCondition(), eventManager.getClans().getProjectile(), centerLocation); + worldEvent = (WorldEvent) con.newInstance(eventManager.getDamage(), eventManager.getBlockRestore(), eventManager.getClans().getCondition(), eventManager.getClans().getProjectile(), centerLocation); } } } @@ -61,7 +61,7 @@ public enum WorldEventType { e.printStackTrace(); } - + return worldEvent; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/ClearCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/ClearCommand.java index e01ddb587..6a74d6475 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/ClearCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/ClearCommand.java @@ -18,9 +18,9 @@ public class ClearCommand extends CommandBase { public ClearCommand(WorldEventManager plugin) { - super(plugin, Rank.DEVELOPER, "clear"); + super(plugin, Rank.DEVELOPER, new Rank[] { Rank.JNR_DEV }, "clear"); } - + @Override public void Execute(Player caller, String[] args) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java index 7027980c5..a0e9eded1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java @@ -13,7 +13,7 @@ public class StartCommand extends CommandBase { public StartCommand(WorldEventManager plugin) { - super(plugin, Rank.DEVELOPER, "start", "create"); + super(plugin, Rank.DEVELOPER, new Rank[] { Rank.JNR_DEV }, "start", "create"); } @Override diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java index 4c10fef3b..789bd95ff 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java @@ -54,7 +54,7 @@ public abstract class WorldEvent implements Listener private Schematic _schematic; // Creatures - private List _creatures; + private List> _creatures; // Block Restore private BlockRestoreMap _blocks; private boolean _isArcade; @@ -81,7 +81,7 @@ public abstract class WorldEvent implements Listener _random = new Random(); _ticks = 0; - _creatures = new ArrayList(); + _creatures = new ArrayList<>(); _blocks = blockRestore.createMap(); _lastActive = System.currentTimeMillis(); @@ -240,18 +240,18 @@ public abstract class WorldEvent implements Listener return _map == null ? _cornerLocation : _map.getCenterLocation(); } - public List getCreatures() + public List> getCreatures() { return _creatures; } - public void registerCreature(EventCreature creature) + public void registerCreature(EventCreature creature) { UtilServer.getServer().getPluginManager().registerEvents(creature, _damageManager.getPlugin()); _creatures.add(creature); } - public void removeCreature(EventCreature creature) + public void removeCreature(EventCreature creature) { HandlerList.unregisterAll(creature); _creatures.remove(creature); @@ -267,7 +267,7 @@ public abstract class WorldEvent implements Listener public void clearCreatures() { - for (EventCreature creature : _creatures) + for (EventCreature creature : _creatures) { creature.remove(false); HandlerList.unregisterAll(creature);