From 9feecc32a143df4540d752ac3dda1201c5e3a224 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 26 Jul 2018 16:36:08 +0100 Subject: [PATCH] Implement MineplexWorld has a replacement for WorldData --- .../mineplex/core/world/MineplexWorld.java | 245 ++++++++++++++ .../src/mineplex/hub/HubManager.java | 26 +- .../mineplex/hub/gimmicks/SecretAreas.java | 13 +- .../hub/gimmicks/staffbuild/StaffBuild.java | 5 +- .../src/mineplex/hub/hubgame/HubGame.java | 9 +- .../mineplex/hub/hubgame/HubGameManager.java | 4 +- .../src/mineplex/hub/hubgame/duel/Duels.java | 4 +- .../src/mineplex/hub/hubgame/tron/Tron.java | 4 +- .../src/mineplex/hub/kit/HubKitManager.java | 11 +- .../mineplex/hub/news/SalesBoardManager.java | 4 - .../src/mineplex/hub/parkour/ParkourData.java | 12 +- .../mineplex/hub/parkour/ParkourManager.java | 15 +- .../mineplex/hub/server/ServerManager.java | 3 +- .../hub/treasurehunt/TreasureHuntManager.java | 7 +- .../mineplex/hub/world/HubPortalManager.java | 174 ---------- .../mineplex/hub/world/HubWorldManager.java | 19 +- .../mineplex/hub/world/WorldDataModule.java | 304 ------------------ 17 files changed, 310 insertions(+), 549 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/world/MineplexWorld.java delete mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/world/HubPortalManager.java delete mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/world/WorldDataModule.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/world/MineplexWorld.java b/Plugins/Mineplex.Core/src/mineplex/core/world/MineplexWorld.java new file mode 100644 index 000000000..8d23342b3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/world/MineplexWorld.java @@ -0,0 +1,245 @@ +package mineplex.core.world; + +import java.io.File; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.World; + +public class MineplexWorld +{ + + private final World _world; + + private Location _min, _max; + private String _mapName, _mapAuthor; + + private final Map> _ironLocations, _goldLocations, _spongeLocations; + + public MineplexWorld(World world) + { + _world = world; + _ironLocations = new HashMap<>(); + _goldLocations = new HashMap<>(); + _spongeLocations = new HashMap<>(); + } + + public void loadWorldConfig() + { + try + { + List lines = Files.readAllLines(new File(_world.getWorldFolder() + File.separator + "WorldConfig.dat").toPath()); + List current = null; + int minX = 0, minY = 0, minZ = 0, maxX = 0, maxY = 0, maxZ = 0; + + for (String line : lines) + { + String[] tokens = line.split(":"); + + if (tokens.length < 2 || tokens[0].isEmpty()) + { + continue; + } + + String key = tokens[0], value = tokens[1]; + + //Name & Author + if (key.equalsIgnoreCase("MAP_NAME")) + { + _mapName = value; + } + else if (key.equalsIgnoreCase("MAP_AUTHOR")) + { + _mapAuthor = value; + } + + //Spawn Locations + else if (key.equalsIgnoreCase("TEAM_NAME")) + { + current = getGoldLocations(value); + } + else if (key.equalsIgnoreCase("TEAM_SPAWNS")) + { + for (int i = 1; i < tokens.length; i++) + { + Location location = fromString(tokens[i]); + + if (location == null) + { + continue; + } + + current.add(location); + } + } + + //Data Locations + else if (key.equalsIgnoreCase("DATA_NAME")) + { + current = getIronLocations(value); + } + else if (key.equalsIgnoreCase("DATA_LOCS")) + { + for (int i = 1; i < tokens.length; i++) + { + Location location = fromString(tokens[i]); + + if (location == null) + { + continue; + } + + current.add(location); + } + } + + //Custom Locations + else if (key.equalsIgnoreCase("CUSTOM_NAME")) + { + current = getSpongeLocations(value); + } + else if (key.equalsIgnoreCase("CUSTOM_LOCS")) + { + for (int i = 1; i < tokens.length; i++) + { + Location location = fromString(tokens[i]); + + if (location == null) + { + continue; + } + + current.add(location); + } + } + + //Map Bounds + else if (key.equalsIgnoreCase("MIN_X")) + { + minX = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("MAX_X")) + { + maxX = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("MIN_Z")) + { + minZ = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("MAX_Z")) + { + maxZ = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("MIN_Y")) + { + minY = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("MAX_Y")) + { + maxY = Integer.parseInt(value); + } + } + + _min = new Location(_world, minX, minY, minZ); + _max = new Location(_world, maxX, maxY, maxZ); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + private Location fromString(String location) + { + String[] cords = location.split(","); + + try + { + return new Location(_world, Integer.valueOf(cords[0]) + 0.5, Integer.valueOf(cords[1]), Integer.valueOf(cords[2]) + 0.5); + } + catch (Exception e) + { + System.err.println("World Data Read Error: Invalid Location String [" + location + "]"); + } + + return null; + } + + public World getWorld() + { + return _world; + } + + public Location getMin() + { + return _min; + } + + public Location getMax() + { + return _max; + } + + public String getMapName() + { + return _mapName; + } + + public String getMapAuthor() + { + return _mapAuthor; + } + + public Location getIronLocation(String key) + { + List locations = getIronLocations(key); + return locations.isEmpty() ? null : locations.get(0); + } + + public Location getGoldLocation(String key) + { + List locations = getGoldLocations(key); + return locations.isEmpty() ? null : locations.get(0); + } + + public Location getSpongeLocation(String key) + { + List locations = getSpongeLocations(key); + return locations.isEmpty() ? null : locations.get(0); + } + + public List getIronLocations(String key) + { + return _ironLocations.computeIfAbsent(key, k -> new ArrayList<>()); + } + + public List getGoldLocations(String key) + { + return _goldLocations.computeIfAbsent(key, k -> new ArrayList<>()); + } + + public List getSpongeLocations(String key) + { + return _spongeLocations.computeIfAbsent(key, k -> new ArrayList<>()); + } + + public Map> getIronLocations() + { + return Collections.unmodifiableMap(_ironLocations); + } + + public Map> getGoldLocations() + { + return Collections.unmodifiableMap(_goldLocations); + } + + public Map> getSpongeLocations() + { + return Collections.unmodifiableMap(_spongeLocations); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 4684f9a95..d75fa57d8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -91,6 +91,7 @@ import mineplex.core.treasure.TreasureManager; import mineplex.core.twofactor.TwoFactorAuth; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.world.MineplexWorld; import mineplex.core.youtube.YoutubeManager; import mineplex.hub.commands.GadgetToggle; import mineplex.hub.commands.ListCommand; @@ -109,9 +110,7 @@ import mineplex.hub.player.CreativeManager; import mineplex.hub.player.HubPlayerManager; import mineplex.hub.plugin.HubPlugin; import mineplex.hub.scoreboard.HubScoreboard; -import mineplex.hub.world.HubPortalManager; import mineplex.hub.world.HubWorldManager; -import mineplex.hub.world.WorldDataModule; import mineplex.minecraft.game.core.combat.DeathMessageType; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; @@ -148,7 +147,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess private final HubPlugin _hubPlugin; - private final WorldDataModule _worldData; + private final MineplexWorld _worldData; private final Location _spawn; private final List _lookAt; @@ -164,9 +163,12 @@ public class HubManager extends MiniClientPlugin implements IChatMess _portal = portal; - _worldData = require(WorldDataModule.class); - _spawn = _worldData.getCustomLocation("SPAWN").get(0); - _lookAt = _worldData.getCustomLocation("LOOK_AT"); + World world = Bukkit.getWorld("world"); + + _worldData = new MineplexWorld(world); + _worldData.loadWorldConfig(); + _spawn = _worldData.getSpongeLocation("SPAWN"); + _lookAt = _worldData.getSpongeLocations("LOOK_AT"); // Disable item merging WorldServer nmsWorld = ((CraftWorld) _spawn.getWorld()).getHandle(); @@ -188,7 +190,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess TreasureManager treasureManager = require(TreasureManager.class); new CosmeticManager(_plugin, clientManager, donationManager, inventoryManager, _gadgetManager, petManager, treasureManager, boosterManager, punish); - for (Location location : _worldData.getCustomLocation("TREASURE CHEST")) + for (Location location : _worldData.getSpongeLocations("TREASURE CHEST")) { treasureManager.addTreasureLocation(location); } @@ -211,7 +213,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess _achievementManager = achievementManager; _missionManager = require(MissionManager.class); - Location location = _worldData.getCustomLocation("MISSIONS").get(0); + Location location = _worldData.getSpongeLocation("MISSIONS"); location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, GetSpawn()))); _missionManager.createNPC(location); @@ -244,7 +246,6 @@ public class HubManager extends MiniClientPlugin implements IChatMess require(AdminPunch.class); require(StaffBuild.class); require(SecretAreas.class); - require(HubPortalManager.class); // require(TreasureHuntManager.class); _parkourManager = require(ParkourManager.class); @@ -612,7 +613,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess return; } - for (Entity entity : _worldData.World.getEntities()) + for (Entity entity : _worldData.getWorld().getEntities()) { if (entity instanceof EntityInsentient) { @@ -629,6 +630,11 @@ public class HubManager extends MiniClientPlugin implements IChatMess } } + public MineplexWorld getWorldData() + { + return _worldData; + } + public List getLookAt() { return _lookAt; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/SecretAreas.java b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/SecretAreas.java index ee59ba78c..dc0d2d985 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/SecretAreas.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/SecretAreas.java @@ -33,7 +33,8 @@ import mineplex.core.noteblock.NotePlayer; import mineplex.core.noteblock.NoteSong; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.hub.world.WorldDataModule; +import mineplex.core.world.MineplexWorld; +import mineplex.hub.HubManager; @ReflectivelyCreateMiniPlugin public class SecretAreas extends MiniPlugin @@ -58,9 +59,9 @@ public class SecretAreas extends MiniPlugin _restore = require(BlockRestore.class); - WorldDataModule worldData = require(WorldDataModule.class); - _konamiLocation = worldData.getCustomLocation("KONAMI").get(0).getBlock(); - _tankLocation = worldData.getCustomLocation("TANK").get(0).getBlock().getRelative(BlockFace.DOWN); + MineplexWorld worldData = require(HubManager.class).getWorldData(); + _konamiLocation = worldData.getSpongeLocation("KONAMI").getBlock(); + _tankLocation = worldData.getSpongeLocation("TANK").getBlock().getRelative(BlockFace.DOWN); try { @@ -70,8 +71,8 @@ public class SecretAreas extends MiniPlugin { } - _cannonBall = worldData.getCustomLocation("CANNON BALL").get(0); - _cannons = worldData.getCustomLocation("CANNON"); + _cannonBall = worldData.getSpongeLocation("CANNON BALL"); + _cannons = worldData.getSpongeLocations("CANNON"); } @EventHandler diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/staffbuild/StaffBuild.java b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/staffbuild/StaffBuild.java index b89593154..a1b337733 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/staffbuild/StaffBuild.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/gimmicks/staffbuild/StaffBuild.java @@ -25,14 +25,13 @@ import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilItem; -import mineplex.core.common.util.UtilItem.ItemCategory; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.HubManager; import mineplex.hub.player.CreativeManager; import mineplex.hub.player.HubPlayerManager; -import mineplex.hub.world.WorldDataModule; @ReflectivelyCreateMiniPlugin public class StaffBuild extends MiniPlugin @@ -60,7 +59,7 @@ public class StaffBuild extends MiniPlugin _clientManager = require(CoreClientManager.class); _creativeManager = require(CreativeManager.class); _playerManager = require(HubPlayerManager.class); - _buildLocations = require(WorldDataModule.class).getCustomLocation(String.valueOf(Material.RED_SANDSTONE.getId())); + _buildLocations = require(HubManager.class).getWorldData().getSpongeLocations(String.valueOf(Material.RED_SANDSTONE.getId())); _buildLocations.forEach(location -> location.getBlock().setType(Material.AIR)); _buildHistory = new HashMap<>(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGame.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGame.java index 8f739e712..56646dcd4 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGame.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGame.java @@ -8,15 +8,14 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Listener; -import mineplex.core.Managers; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilServer; import mineplex.core.lifetimes.PhasedLifetime; import mineplex.core.newnpc.NPC; +import mineplex.core.world.MineplexWorld; import mineplex.hub.hubgame.CycledGame.GameState; import mineplex.hub.hubgame.common.HubGameComponent; -import mineplex.hub.world.WorldDataModule; public abstract class HubGame extends PhasedLifetime implements Listener { @@ -25,7 +24,7 @@ public abstract class HubGame extends PhasedLifetime implements Liste private final HubGameType _type; private final Map>, HubGameComponent> _components; - protected final WorldDataModule _worldData; + protected final MineplexWorld _worldData; private final Location _spawn; @@ -35,8 +34,8 @@ public abstract class HubGame extends PhasedLifetime implements Liste _type = type; _components = new HashMap<>(); - _worldData = Managers.require(WorldDataModule.class); - _spawn = _worldData.getCustomLocation(type.name() + " SPAWN").get(0); + _worldData = manager.getHubManager().getWorldData(); + _spawn = _worldData.getSpongeLocation(type.name() + " SPAWN"); start(GameState.Waiting); UtilServer.RegisterEvents(this); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java index 9d39112e8..4f605dbb1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/HubGameManager.java @@ -36,7 +36,6 @@ import mineplex.hub.hubgame.CycledGame.GameState; import mineplex.hub.hubgame.event.HubGamePlayerDeathEvent; import mineplex.hub.hubgame.ui.HubGameShop; import mineplex.hub.player.HubPlayerManager; -import mineplex.hub.world.WorldDataModule; @ReflectivelyCreateMiniPlugin public class HubGameManager extends MiniPlugin @@ -73,11 +72,10 @@ public class HubGameManager extends MiniPlugin _hubManager = require(HubManager.class); _hotbarManager = require(HubPlayerManager.class); _npcManager = require(NewNPCManager.class); - WorldDataModule worldData = require(WorldDataModule.class); _shop = new HubGameShop(this, _clientManager, _donationManager); _games = new ArrayList<>(); - _teleport = worldData.getCustomLocation("TELEPORT " + _moduleName).get(0); + _teleport = _hubManager.getWorldData().getSpongeLocation("TELEPORT " + _moduleName); UtilAlg.lookAtNearest(_teleport, _hubManager.getLookAt()); runSyncLater(this::spawnNPCs, 50); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java index 653e67e5f..bdbb5c6ea 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java @@ -98,7 +98,7 @@ public class Duels extends CycledGame return null; })); - registerComponent(new TeleportIntoMapComponent(this, _worldData.getDataLocation("YELLOW"))); + registerComponent(new TeleportIntoMapComponent(this, _worldData.getIronLocations("YELLOW"))); registerComponent(new PrepareFreezeComponent(this)); registerComponent(new InventoryEditComponent(this)); registerComponent(new DoubleJumpComponent(this)); @@ -107,7 +107,7 @@ public class Duels extends CycledGame registerComponent(new PlayerGameModeComponent(this, GameMode.SURVIVAL)); registerComponent(new MissionsComponent(this)); - List corners = _worldData.getDataLocation("LIME"); + List corners = _worldData.getIronLocations("LIME"); Location a = corners.get(0); Location b = corners.get(1); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/Tron.java b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/Tron.java index 0d9ba5329..9d86f4044 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/Tron.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/tron/Tron.java @@ -44,13 +44,13 @@ public class Tron extends CycledGame super(manager, HubGameType.TRON); _bikes = new HashMap<>(); - registerComponent(new TeleportIntoMapComponent(this, _worldData.getDataLocation("RED"))); + registerComponent(new TeleportIntoMapComponent(this, _worldData.getIronLocations("RED"))); registerComponent(new GameDescriptionComponent(this)); registerComponent(new GameTimeoutComponent(this, TimeUnit.MINUTES.toMillis(3))); registerComponent(new PlacesComponent(this)); registerComponent(new MissionsComponent(this)); - List corners = _worldData.getDataLocation("WHITE"); + List corners = _worldData.getIronLocations("WHITE"); Location a = corners.get(0); Location b = corners.get(1); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/kit/HubKitManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/kit/HubKitManager.java index 251ec9097..38d1c5a3e 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/kit/HubKitManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/kit/HubKitManager.java @@ -1,15 +1,13 @@ package mineplex.hub.kit; -import java.util.List; - import org.bukkit.Location; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; import mineplex.core.game.MineplexGameManager; +import mineplex.core.world.MineplexWorld; import mineplex.hub.HubManager; -import mineplex.hub.world.WorldDataModule; @ReflectivelyCreateMiniPlugin public class HubKitManager extends MiniPlugin @@ -20,16 +18,15 @@ public class HubKitManager extends MiniPlugin super("Hub Kit"); MineplexGameManager gameManager = require(MineplexGameManager.class); - WorldDataModule worldData = require(WorldDataModule.class); + MineplexWorld worldData = require(HubManager.class).getWorldData(); HubManager manager = require(HubManager.class); gameManager.getKits().forEach(kit -> { - List locations = worldData.getCustomLocation("KIT " + kit.getId()); + Location location = worldData.getSpongeLocation("KIT " + kit.getId()); - if (!locations.isEmpty()) + if (location != null) { - Location location = locations.get(0); UtilAlg.lookAtNearest(location, manager.getLookAt()); kit.createNPC(location); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/news/SalesBoardManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/news/SalesBoardManager.java index 3bd28d5a3..6e37a06e8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/news/SalesBoardManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/news/SalesBoardManager.java @@ -1,7 +1,5 @@ package mineplex.hub.news; -import org.bukkit.Location; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; @@ -11,8 +9,6 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.imagemap.ImageMapManager; -import mineplex.core.imagemap.objects.PlayerMapBoard; -import mineplex.hub.world.WorldDataModule; @ReflectivelyCreateMiniPlugin public class SalesBoardManager extends MiniPlugin diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourData.java b/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourData.java index 13fe1a749..90e16729d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourData.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourData.java @@ -13,7 +13,7 @@ import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.hub.world.WorldDataModule; +import mineplex.core.world.MineplexWorld; public class ParkourData implements Listener { @@ -42,12 +42,12 @@ public class ParkourData implements Listener _description = description; _difficulty = difficulty; - WorldDataModule worldData = manager.getWorldData(); - List corners = worldData.getCustomLocation(key + " BORDER"); - _checkpoints = worldData.getCustomLocation(key + " CHECK"); - _reset = worldData.getCustomLocation(key + " RESET").get(0); + MineplexWorld worldData = manager.getHubManager().getWorldData(); + List corners = worldData.getSpongeLocations(key + " BORDER"); + _checkpoints = worldData.getSpongeLocations(key + " CHECK"); + _reset = worldData.getSpongeLocation(key + " RESET"); UtilAlg.lookAtNearest(_reset, manager.getHubManager().getLookAt()); - _teleport = worldData.getCustomLocation(key + " TELEPORT").get(0); + _teleport = worldData.getSpongeLocation(key + " TELEPORT"); UtilAlg.lookAtNearest(_teleport, manager.getHubManager().getLookAt()); _cornerA = corners.get(0); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourManager.java index a5e60655f..e669a6b73 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/parkour/ParkourManager.java @@ -39,13 +39,13 @@ import mineplex.core.recharge.Recharge; import mineplex.core.teleport.event.MineplexTeleportEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.world.MineplexWorld; import mineplex.hub.HubManager; import mineplex.hub.doublejump.DoubleJumpPrepareEvent; import mineplex.hub.parkour.data.Snake; import mineplex.hub.parkour.data.SnakeParkourData; import mineplex.hub.parkour.data.SprintingParkourData; import mineplex.hub.player.HubPlayerManager; -import mineplex.hub.world.WorldDataModule; @ReflectivelyCreateMiniPlugin public class ParkourManager extends MiniPlugin @@ -62,7 +62,7 @@ public class ParkourManager extends MiniPlugin private final HubManager _hubManager; private final HubPlayerManager _hubPlayerManager; private final GadgetManager _gadgetManager; - private final WorldDataModule _worldData; + private final MineplexWorld _worldData; private final Map _attempts; private final List _parkours; @@ -74,7 +74,7 @@ public class ParkourManager extends MiniPlugin _hubManager = require(HubManager.class); _hubPlayerManager = require(HubPlayerManager.class); _gadgetManager = require(GadgetManager.class); - _worldData = require(WorldDataModule.class); + _worldData = _hubManager.getWorldData(); _attempts = new HashMap<>(); _parkours = new ArrayList<>(); @@ -87,9 +87,9 @@ public class ParkourManager extends MiniPlugin }, DIFFICULTY_EASY)); List snakes = new ArrayList<>(); - List path = _worldData.getCustomLocation(String.valueOf(Material.QUARTZ_ORE.getId())); + List path = _worldData.getSpongeLocations(String.valueOf(Material.QUARTZ_ORE.getId())); - for (Location head : _worldData.getDataLocation("LIGHT_BLUE")) + for (Location head : _worldData.getIronLocations("LIGHT_BLUE")) { snakes.add(new Snake(head, path)); } @@ -361,9 +361,4 @@ public class ParkourManager extends MiniPlugin { return _hubManager; } - - public WorldDataModule getWorldData() - { - return _worldData; - } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index 6942336d9..e8c1239e8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -65,7 +65,6 @@ import mineplex.hub.HubManager; import mineplex.hub.server.ui.LobbyShop; import mineplex.hub.server.ui.QuickShop; import mineplex.hub.server.ui.ServerNpcShop; -import mineplex.hub.world.WorldDataModule; import mineplex.serverdata.Region; import mineplex.serverdata.data.MinecraftServer; import mineplex.serverdata.data.ServerGroup; @@ -152,7 +151,7 @@ public class ServerManager extends MiniPlugin _titles = require(Titles.class); _serverNPCTeleport = HashBiMap.create(); - require(WorldDataModule.class).getAllCustomLocations().forEach((key, locations) -> + _hubManager.getWorldData().getSpongeLocations().forEach((key, locations) -> { String[] split = key.split(" "); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/treasurehunt/TreasureHuntManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/treasurehunt/TreasureHuntManager.java index 40aae6bb3..6e9cfd595 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/treasurehunt/TreasureHuntManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/treasurehunt/TreasureHuntManager.java @@ -22,8 +22,9 @@ import mineplex.core.common.util.F; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.titles.tracks.TrackManager; +import mineplex.core.world.MineplexWorld; +import mineplex.hub.HubManager; import mineplex.hub.treasurehunt.types.NewHubTreasureHunt; -import mineplex.hub.world.WorldDataModule; @ReflectivelyCreateMiniPlugin public class TreasureHuntManager extends MiniClientPlugin> @@ -53,11 +54,11 @@ public class TreasureHuntManager extends MiniClientPlugin> private void setupTreasureHunt() { - WorldDataModule worldData = require(WorldDataModule.class); + MineplexWorld worldData = require(HubManager.class).getWorldData(); Map treasure = new HashMap<>(); _treasureHunt = new NewHubTreasureHunt(this, treasure); - worldData.getAllCustomLocations().forEach((key, locations) -> + worldData.getSpongeLocations().forEach((key, locations) -> { if (!key.startsWith("TH")) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/world/HubPortalManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/world/HubPortalManager.java deleted file mode 100644 index 66e5e7286..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/world/HubPortalManager.java +++ /dev/null @@ -1,174 +0,0 @@ -package mineplex.hub.world; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - -import com.google.common.collect.ImmutableMap; - -import mineplex.core.MiniPlugin; -import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilServer; -import mineplex.core.game.GameCategory; -import mineplex.core.hologram.Hologram; -import mineplex.core.hologram.HologramManager; -import mineplex.core.newnpc.NewNPCManager; -import mineplex.core.newnpc.event.NPCInteractEvent; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.hub.HubManager; - -@ReflectivelyCreateMiniPlugin -public class HubPortalManager extends MiniPlugin -{ - - private static final int PORTAL_RANGE_SQUARED = 36; - private static final String GO_BACK_METADATA = "GO_BACK"; - private static final Map> HOLOGRAMS = ImmutableMap.>builder() - .put(GameCategory.CASUAL, Arrays.asList - ( - "Mixed Arcade", - "Micro Battles", - "Turf Wars", - "Draw My Thing", - "Master Builders" - )) - .put(GameCategory.INTERMEDIATE, Arrays.asList - ( - "Survival Games", - "Speed Builders", - "Block Hunt", - "Cake Wars", - "Skywars" - )) - .put(GameCategory.HARDCORE, Arrays.asList - ( - "The Bridges", - "Mine-Strike", - "Super Smash Mobs", - "Champions", - "Clans" - )) - .build(); - - private final HubManager _manager; - private final Map _portals; - private final Map _holograms; - - private int _lineIndex; - - private HubPortalManager() - { - super("Hub Portal"); - - _manager = require(HubManager.class); - WorldDataModule worldData = require(WorldDataModule.class); - - _portals = new HashMap<>(); - _holograms = new HashMap<>(); - - HologramManager hologramManager = require(HologramManager.class); - - for (GameCategory category : GameCategory.values()) - { - String key = "PORTAL " + category.name(); - List portal = worldData.getCustomLocation(key); - List portalDestination = worldData.getCustomLocation(key + " DESTINATION"); - List hologram = worldData.getCustomLocation("HOLOGRAM " + category.name()); - - if (!portal.isEmpty() && !portalDestination.isEmpty()) - { - Location destinationLocation = portalDestination.get(0); - UtilAlg.lookAtNearest(destinationLocation, _manager.getLookAt()); - _portals.put(portal.get(0), destinationLocation); - } - if (!hologram.isEmpty()) - { - _holograms.put(category, new Hologram(hologramManager, hologram.get(0), "") - .setViewDistance(36) - .start()); - } - } - - worldData.getCustomLocation(String.valueOf(Material.LAPIS_ORE.getId())).forEach(location -> location.getBlock().setType(Material.WATER)); - - NewNPCManager npcManager = require(NewNPCManager.class); - npcManager.spawnNPCs("HUB", null); - npcManager.spawnNPCs("GO_BACK", null); - } - - @EventHandler - public void updatePortals(UpdateEvent event) - { - if (event.getType() != UpdateType.FASTEST) - { - return; - } - - for (Player player : UtilServer.getPlayersCollection()) - { - if (!UtilEnt.isInWater(player)) - { - continue; - } - - Location location = player.getLocation(); - - _portals.forEach((portal, destination) -> - { - if (UtilMath.offset2dSquared(portal, location) < PORTAL_RANGE_SQUARED) - { - player.teleport(destination); - } - }); - } - } - - @EventHandler - public void updateHolograms(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) - { - return; - } - - _holograms.forEach((category, hologram) -> - { - List content = HOLOGRAMS.get(category); - List text = new ArrayList<>(content.size() + 2); - int lineIndex = _lineIndex % content.size(); - - text.add(category.getChatColor() + C.Bold + category.getName()); - text.add(C.cBlack); - - for (int i = 0; i < content.size(); i++) - { - text.add((lineIndex == i ? C.cYellowB : C.cGold) + content.get(i)); - } - - hologram.setText(text.toArray(new String[0])); - }); - - _lineIndex++; - } - - @EventHandler - public void npcInteract(NPCInteractEvent event) - { - if (event.getNpc().getMetadata().equals(GO_BACK_METADATA)) - { - event.getPlayer().teleport(_manager.GetSpawn()); - } - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/world/HubWorldManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/world/HubWorldManager.java index 09c63593d..d589328da 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/world/HubWorldManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/world/HubWorldManager.java @@ -1,7 +1,7 @@ package mineplex.hub.world; +import org.bukkit.Difficulty; import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Boat; @@ -56,6 +56,7 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.world.MineplexWorld; import mineplex.hub.HubManager; import mineplex.minecraft.game.core.damage.CustomDamageEvent; @@ -71,7 +72,7 @@ public class HubWorldManager extends MiniPlugin private final HubManager _manager; private final BlockRestore _blockRestore; - private final WorldDataModule _worldData; + private final MineplexWorld _worldData; private HubWorldManager() { @@ -79,9 +80,13 @@ public class HubWorldManager extends MiniPlugin _manager = require(HubManager.class); _blockRestore = require(BlockRestore.class); - _worldData = require(WorldDataModule.class); + _worldData = _manager.getWorldData(); - _manager.GetSpawn().getWorld().setGameRuleValue("doDayNightCycle", "false"); + World world = _worldData.getWorld(); + + world.setGameRuleValue("showDeathMessages", "false"); + world.setGameRuleValue("doDayNightCycle", "false"); + world.setDifficulty(Difficulty.EASY); } /** @@ -321,13 +326,11 @@ public class HubWorldManager extends MiniPlugin return; } - World world= _manager.GetSpawn().getWorld(); - Location a = new Location(world, _worldData.MinX, 0, _worldData.MinZ); - Location b = new Location(world, _worldData.MaxX, 256, _worldData.MaxZ); + World world = _manager.GetSpawn().getWorld(); for (Player player : world.getPlayers()) { - if (!UtilAlg.inBoundingBox(player.getLocation(), a, b)) + if (!UtilAlg.inBoundingBox(player.getLocation(), _worldData.getMin(), _worldData.getMax())) { player.eject(); player.leaveVehicle(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/world/WorldDataModule.java b/Plugins/Mineplex.Hub/src/mineplex/hub/world/WorldDataModule.java deleted file mode 100644 index 300ebc7a8..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/world/WorldDataModule.java +++ /dev/null @@ -1,304 +0,0 @@ -package mineplex.hub.world; - -import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.Difficulty; -import org.bukkit.Location; -import org.bukkit.World; - -import mineplex.core.MiniPlugin; -import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.common.timing.TimingManager; - -// TODO remove this and standardise world data. somehow... -@ReflectivelyCreateMiniPlugin -public class WorldDataModule extends MiniPlugin -{ - public World World; - public int MinX = 0; - public int MinZ = 0; - public int MaxX = 0; - public int MaxZ = 0; - - public int MinY = -1; - public int MaxY = 256; - - private final Map> SPAWN_LOCATIONS = new LinkedHashMap<>(); - private final Map> DATA_LOCATIONS = new LinkedHashMap<>(); - private final Map> CUSTOM_LOCATIONS = new LinkedHashMap<>(); - - private WorldDataModule() - { - super("World Data"); - - initialize(); - } - - public void initialize() - { - final WorldDataModule worldData = this; - - World = Bukkit.getWorld("world"); - - World.setDifficulty(Difficulty.EASY); - World.setGameRuleValue("showDeathMessages", "false"); - - TimingManager.start("WorldData loading WorldConfig."); - worldData.loadWorldConfig(); - TimingManager.stop("WorldData loading WorldConfig."); - } - - public String getFolder() - { - return "world"; - } - - public void loadWorldConfig() - { - // Load Track Data - String line = null; - - try - { - FileInputStream fstream = new FileInputStream(getFolder() + File.separator + "WorldConfig.dat"); - DataInputStream in = new DataInputStream(fstream); - BufferedReader br = new BufferedReader(new InputStreamReader(in)); - - List currentTeam = null; - List currentData = null; - - int currentDirection = 0; - - while ((line = br.readLine()) != null) - { - String[] tokens = line.split(":"); - - if (tokens.length < 2) - { - continue; - } - - String key = tokens[0]; - String value = tokens[1]; - - if (key.length() == 0) - { - continue; - } - - // Spawn Locations - if (key.equalsIgnoreCase("TEAM_NAME")) - { - SPAWN_LOCATIONS.put(value, new ArrayList()); - currentTeam = SPAWN_LOCATIONS.get(value); - currentDirection = 0; - } - else if (key.equalsIgnoreCase("TEAM_DIRECTION")) - { - currentDirection = Integer.parseInt(value); - } - else if (key.equalsIgnoreCase("TEAM_SPAWNS")) - { - for (int i = 1; i < tokens.length; i++) - { - Location loc = stringToLocation(tokens[i]); - if (loc == null) - { - continue; - } - - loc.setYaw(currentDirection); - - currentTeam.add(loc); - } - } - - // Data Locations - else if (key.equalsIgnoreCase("DATA_NAME")) - { - DATA_LOCATIONS.put(value, new ArrayList()); - currentData = DATA_LOCATIONS.get(value); - } - else if (key.equalsIgnoreCase("DATA_LOCS")) - { - for (int i = 1; i < tokens.length; i++) - { - Location loc = stringToLocation(tokens[i]); - if (loc == null) - { - continue; - } - - currentData.add(loc); - } - } - - // Custom Locations - else if (key.equalsIgnoreCase("CUSTOM_NAME")) - { - CUSTOM_LOCATIONS.put(value, new ArrayList()); - currentData = CUSTOM_LOCATIONS.get(value); - } - else if (key.equalsIgnoreCase("CUSTOM_LOCS")) - { - for (int i = 1; i < tokens.length; i++) - { - Location loc = stringToLocation(tokens[i]); - if (loc == null) - { - continue; - } - - currentData.add(loc); - } - } - - // Map Bounds - else if (key.equalsIgnoreCase("MIN_X")) - { - try - { - MinX = Integer.parseInt(value); - } - catch (Exception e) - { - System.out.println("World Data Read Error: Invalid MinX [" + value + "]"); - } - - } - else if (key.equalsIgnoreCase("MAX_X")) - { - try - { - MaxX = Integer.parseInt(value); - } - catch (Exception e) - { - System.out.println("World Data Read Error: Invalid MaxX [" + value + "]"); - } - } - else if (key.equalsIgnoreCase("MIN_Z")) - { - try - { - MinZ = Integer.parseInt(value); - } - catch (Exception e) - { - System.out.println("World Data Read Error: Invalid MinZ [" + value + "]"); - } - } - else if (key.equalsIgnoreCase("MAX_Z")) - { - try - { - MaxZ = Integer.parseInt(value); - } - catch (Exception e) - { - System.out.println("World Data Read Error: Invalid MaxZ [" + value + "]"); - } - } - else if (key.equalsIgnoreCase("MIN_Y")) - { - try - { - MinY = Integer.parseInt(value); - } - catch (Exception e) - { - System.out.println("World Data Read Error: Invalid MinY [" + value + "]"); - } - } - else if (key.equalsIgnoreCase("MAX_Y")) - { - try - { - MaxY = Integer.parseInt(value); - } - catch (Exception e) - { - System.out.println("World Data Read Error: Invalid MaxY [" + value + "]"); - } - } - } - - in.close(); - } - catch (Exception e) - { - e.printStackTrace(); - System.err.println("Line: " + line); - } - } - - private Location stringToLocation(String loc) - { - String[] coords = loc.split(","); - - try - { - return new Location(World, Integer.valueOf(coords[0]) + 0.5, Integer.valueOf(coords[1]), Integer.valueOf(coords[2]) + 0.5); - } - catch (Exception e) - { - System.out.println("World Data Read Error: Invalid Location String [" + loc + "]"); - } - - return null; - } - - public List getSpawnLocation(String colour) - { - if (!SPAWN_LOCATIONS.containsKey(colour)) - { - return new ArrayList<>(); - } - - return SPAWN_LOCATIONS.get(colour); - } - - public List getDataLocation(String colour) - { - if (!DATA_LOCATIONS.containsKey(colour)) - { - return new ArrayList<>(); - } - - return DATA_LOCATIONS.get(colour); - } - - public List getCustomLocation(String id) - { - if (!CUSTOM_LOCATIONS.containsKey(id)) - { - return new ArrayList<>(); - } - - return CUSTOM_LOCATIONS.get(id); - } - - public Map> getAllSpawnLocations() - { - return SPAWN_LOCATIONS; - } - - public Map> getAllCustomLocations() - { - return CUSTOM_LOCATIONS; - } - - public Map> getAllDataLocations() - { - return DATA_LOCATIONS; - } -} \ No newline at end of file