Implement MineplexWorld has a replacement for WorldData

This commit is contained in:
Sam 2018-07-26 16:36:08 +01:00 committed by Alexander Meech
parent d617744bcf
commit 9feecc32a1
17 changed files with 310 additions and 549 deletions

View File

@ -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<String, List<Location>> _ironLocations, _goldLocations, _spongeLocations;
public MineplexWorld(World world)
{
_world = world;
_ironLocations = new HashMap<>();
_goldLocations = new HashMap<>();
_spongeLocations = new HashMap<>();
}
public void loadWorldConfig()
{
try
{
List<String> lines = Files.readAllLines(new File(_world.getWorldFolder() + File.separator + "WorldConfig.dat").toPath());
List<Location> 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<Location> locations = getIronLocations(key);
return locations.isEmpty() ? null : locations.get(0);
}
public Location getGoldLocation(String key)
{
List<Location> locations = getGoldLocations(key);
return locations.isEmpty() ? null : locations.get(0);
}
public Location getSpongeLocation(String key)
{
List<Location> locations = getSpongeLocations(key);
return locations.isEmpty() ? null : locations.get(0);
}
public List<Location> getIronLocations(String key)
{
return _ironLocations.computeIfAbsent(key, k -> new ArrayList<>());
}
public List<Location> getGoldLocations(String key)
{
return _goldLocations.computeIfAbsent(key, k -> new ArrayList<>());
}
public List<Location> getSpongeLocations(String key)
{
return _spongeLocations.computeIfAbsent(key, k -> new ArrayList<>());
}
public Map<String, List<Location>> getIronLocations()
{
return Collections.unmodifiableMap(_ironLocations);
}
public Map<String, List<Location>> getGoldLocations()
{
return Collections.unmodifiableMap(_goldLocations);
}
public Map<String, List<Location>> getSpongeLocations()
{
return Collections.unmodifiableMap(_spongeLocations);
}
}

View File

@ -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<HubClient> implements IChatMess
private final HubPlugin _hubPlugin;
private final WorldDataModule _worldData;
private final MineplexWorld _worldData;
private final Location _spawn;
private final List<Location> _lookAt;
@ -164,9 +163,12 @@ public class HubManager extends MiniClientPlugin<HubClient> 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<HubClient> 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<HubClient> 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<HubClient> 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<HubClient> 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<HubClient> implements IChatMess
}
}
public MineplexWorld getWorldData()
{
return _worldData;
}
public List<Location> getLookAt()
{
return _lookAt;

View File

@ -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

View File

@ -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<>();

View File

@ -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<GameState> implements Listener
{
@ -25,7 +24,7 @@ public abstract class HubGame extends PhasedLifetime<GameState> implements Liste
private final HubGameType _type;
private final Map<Class<? extends HubGameComponent<?>>, HubGameComponent<?>> _components;
protected final WorldDataModule _worldData;
protected final MineplexWorld _worldData;
private final Location _spawn;
@ -35,8 +34,8 @@ public abstract class HubGame extends PhasedLifetime<GameState> 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);

View File

@ -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);

View File

@ -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<Location> corners = _worldData.getDataLocation("LIME");
List<Location> corners = _worldData.getIronLocations("LIME");
Location a = corners.get(0);
Location b = corners.get(1);

View File

@ -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<Location> corners = _worldData.getDataLocation("WHITE");
List<Location> corners = _worldData.getIronLocations("WHITE");
Location a = corners.get(0);
Location b = corners.get(1);

View File

@ -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<Location> 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);
}

View File

@ -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

View File

@ -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<Location> corners = worldData.getCustomLocation(key + " BORDER");
_checkpoints = worldData.getCustomLocation(key + " CHECK");
_reset = worldData.getCustomLocation(key + " RESET").get(0);
MineplexWorld worldData = manager.getHubManager().getWorldData();
List<Location> 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);

View File

@ -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<Player, ParkourAttempt> _attempts;
private final List<ParkourData> _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<Snake> snakes = new ArrayList<>();
List<Location> path = _worldData.getCustomLocation(String.valueOf(Material.QUARTZ_ORE.getId()));
List<Location> 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;
}
}

View File

@ -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(" ");

View File

@ -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<Set<Integer>>
@ -53,11 +54,11 @@ public class TreasureHuntManager extends MiniClientPlugin<Set<Integer>>
private void setupTreasureHunt()
{
WorldDataModule worldData = require(WorldDataModule.class);
MineplexWorld worldData = require(HubManager.class).getWorldData();
Map<Block, Integer> treasure = new HashMap<>();
_treasureHunt = new NewHubTreasureHunt(this, treasure);
worldData.getAllCustomLocations().forEach((key, locations) ->
worldData.getSpongeLocations().forEach((key, locations) ->
{
if (!key.startsWith("TH"))
{

View File

@ -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<GameCategory, List<String>> HOLOGRAMS = ImmutableMap.<GameCategory, List<String>>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<Location, Location> _portals;
private final Map<GameCategory, Hologram> _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<Location> portal = worldData.getCustomLocation(key);
List<Location> portalDestination = worldData.getCustomLocation(key + " DESTINATION");
List<Location> 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<String> content = HOLOGRAMS.get(category);
List<String> 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());
}
}
}

View File

@ -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();

View File

@ -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<String, List<Location>> SPAWN_LOCATIONS = new LinkedHashMap<>();
private final Map<String, List<Location>> DATA_LOCATIONS = new LinkedHashMap<>();
private final Map<String, List<Location>> 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<Location> currentTeam = null;
List<Location> 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<Location>());
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<Location>());
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<Location>());
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<Location> getSpawnLocation(String colour)
{
if (!SPAWN_LOCATIONS.containsKey(colour))
{
return new ArrayList<>();
}
return SPAWN_LOCATIONS.get(colour);
}
public List<Location> getDataLocation(String colour)
{
if (!DATA_LOCATIONS.containsKey(colour))
{
return new ArrayList<>();
}
return DATA_LOCATIONS.get(colour);
}
public List<Location> getCustomLocation(String id)
{
if (!CUSTOM_LOCATIONS.containsKey(id))
{
return new ArrayList<>();
}
return CUSTOM_LOCATIONS.get(id);
}
public Map<String, List<Location>> getAllSpawnLocations()
{
return SPAWN_LOCATIONS;
}
public Map<String, List<Location>> getAllCustomLocations()
{
return CUSTOM_LOCATIONS;
}
public Map<String, List<Location>> getAllDataLocations()
{
return DATA_LOCATIONS;
}
}