From 31cc911a9a1e9bb4c6e2f6007a7c51eb6ad37147 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 20 Jun 2019 23:44:37 -0700 Subject: [PATCH] Add support for 1.14 --- README | 6 +-- pom.xml | 4 +- src/net/TheDgtl/Stargate/Blox.java | 12 ++++-- src/net/TheDgtl/Stargate/Portal.java | 51 +++++++++-------------- src/net/TheDgtl/Stargate/Stargate.java | 56 +++++++++++++++++--------- src/plugin.yml | 2 +- 6 files changed, 69 insertions(+), 62 deletions(-) diff --git a/README b/README index c0ec2c5..82c8957 100644 --- a/README +++ b/README @@ -162,7 +162,7 @@ handleVehicles - Whether or not to handle vehicles going through gates. Set to f sortLists - If true, network lists will be sorted alphabetically. protectEntrance - If true, will protect from users breaking gate entrance blocks (This is more resource intensive than the usual check, and should only be enabled for servers that use solid open/close blocks) signColor: This allows you to specify the color of the gate signs. Valid colors: -verifyPortals: Whether or not all the non-sign blocks are checked to match the gate layout when a stargate is loaded. +verifyPortals: Whether or not all the non-sign blocks are checked to match the gate layout when an old stargate is loaded. debug - Whether to show massive debug output permdebug - Whether to show massive permission debug output @@ -211,8 +211,8 @@ Stargates are stored under player names, not UUIDs. This will be changed in the Changes ============= [Version 0.8.0.0] PseudoKnight fork - - Update for 1.13 compatibility. This changes gate layouts to use new material names instead of numeric ids. You need to update your gate layout configs. - - Adds "verifyPortals" config option, which sets whether a stargate layout is verified when it is loaded. + - Update for 1.13/1.14 compatibility. This changes gate layouts to use new material names instead of numeric ids. You need to update your gate layout configs. + - Adds "verifyPortals" config option, which sets whether an old stargate's blocks are verified when loaded. [Version 0.7.9.11] PseudoKnight fork - Removed iConomy support. Updated Vault support. Changed setting from "useiconomy" to "useeconomy". - Updated to support Metrics for 1.7.10 diff --git a/pom.xml b/pom.xml index 835a721..0dbcb35 100644 --- a/pom.xml +++ b/pom.xml @@ -20,12 +20,12 @@ org.spigotmc spigot-api - 1.13.1-R0.1-SNAPSHOT + 1.14.2-R0.1-SNAPSHOT net.milkbowl.vault VaultAPI - 1.6 + 1.7 diff --git a/src/net/TheDgtl/Stargate/Blox.java b/src/net/TheDgtl/Stargate/Blox.java index 0fb1608..d94486d 100644 --- a/src/net/TheDgtl/Stargate/Blox.java +++ b/src/net/TheDgtl/Stargate/Blox.java @@ -5,6 +5,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Sign; import org.bukkit.block.data.type.WallSign; @@ -92,6 +93,10 @@ public class Blox { return world.getBlockAt(x, y, z); } + public Location getLocation() { + return new Location(world, x, y, z); + } + public int getX() { return x; } @@ -119,11 +124,12 @@ public class Blox { int offsetY = 0; int offsetZ = 0; - if (getBlock().getType() == Material.WALL_SIGN) { - BlockFace facing = ((WallSign) getBlock().getBlockData()).getFacing().getOppositeFace(); + BlockData blk = getBlock().getBlockData(); + if (blk instanceof WallSign) { + BlockFace facing = ((WallSign) blk).getFacing().getOppositeFace(); offsetX = facing.getModX(); offsetZ = facing.getModZ(); - } else if (getBlock().getType() == Material.SIGN) { + } else if (blk instanceof Sign) { offsetY = -1; } else { return; diff --git a/src/net/TheDgtl/Stargate/Portal.java b/src/net/TheDgtl/Stargate/Portal.java index 53fa120..853282e 100644 --- a/src/net/TheDgtl/Stargate/Portal.java +++ b/src/net/TheDgtl/Stargate/Portal.java @@ -26,10 +26,12 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Directional; import org.bukkit.block.data.Powerable; +import org.bukkit.block.data.type.WallSign; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.minecart.StorageMinecart; @@ -339,17 +341,16 @@ public class Portal { return frame; } - public Block getSign() { - return id.getBlock(); + public Blox getSign() { + return id; } public World getWorld() { return world; } - public Block getButton() { - if (button == null) return null; - return button.getBlock(); + public Blox getButton() { + return button; } public void setButton(Blox button) { @@ -373,8 +374,6 @@ public class Portal { if (isOpen() && !force) return false; - getWorld().loadChunk(getWorld().getChunkAt(topLeft.getBlock())); - Material openType = gate.getPortalBlockOpen(); Axis ax = openType == Material.NETHER_PORTAL ? rot : null; for (Blox inside : getEntrances()) { @@ -559,10 +558,6 @@ public class Portal { public boolean isChunkLoaded() { return getWorld().isChunkLoaded(topLeft.getBlock().getChunk()); } - - public void loadChunk() { - getWorld().loadChunk(topLeft.getBlock().getChunk()); - } public boolean isVerified() { verified = true; @@ -697,14 +692,14 @@ public class Portal { drawSign(); } - public final void drawSign() { - Material sMat = id.getBlock().getType(); - if (sMat != Material.SIGN && sMat != Material.WALL_SIGN) { + public final void drawSign() { + BlockState state = id.getBlock().getState(); + if (!(state instanceof Sign)) { Stargate.log.warning("[Stargate] Sign block is not a Sign object"); Stargate.debug("Portal::drawSign", "Block: " + id.getBlock().getType() + " @ " + id.getBlock().getLocation()); return; } - Sign sign = (Sign)id.getBlock().getState(); + Sign sign = (Sign) state; Stargate.setLine(sign, 0, "-" + name + "-"); int max = destinations.size() - 1; int done = 0; @@ -835,7 +830,7 @@ public class Portal { } } - if (id.getBlock().getType() == Material.WALL_SIGN && id.getBlock().getState() instanceof Sign) { + if (id.getBlock().getBlockData() instanceof WallSign) { Sign sign = (Sign)id.getBlock().getState(); sign.setLine(0, getName()); sign.setLine(1, ""); @@ -1249,6 +1244,9 @@ public class Portal { } public static void saveAllGates(World world) { + if(!Stargate.managedWorlds.contains(world.getName())) { + Stargate.managedWorlds.add(world.getName()); + } String loc = Stargate.getSaveLocation() + "/" + world.getName() + ".db"; try { @@ -1258,7 +1256,7 @@ public class Portal { String wName = portal.world.getName(); if (!wName.equalsIgnoreCase(world.getName())) continue; StringBuilder builder = new StringBuilder(); - Blox sign = new Blox(portal.id.getBlock()); + Blox sign = portal.id; Blox button = portal.button; builder.append(portal.name); @@ -1404,23 +1402,10 @@ public class Portal { portal.drawSign(); portalCount++; - if (!portal.isFixed()) continue; - - if (Stargate.enableBungee && portal.isBungee()) { - OpenCount++; + if (portal.isFixed() && (Stargate.enableBungee && portal.isBungee() + || portal.getDestination() != null && portal.isAlwaysOn())) { portal.open(true); - portal.drawSign(); - continue; - } - - Portal dest = portal.getDestination(); - if (dest != null) { - if (portal.isAlwaysOn()) { - portal.open(true); - OpenCount++; - } - portal.drawSign(); - dest.drawSign(); + OpenCount++; } } Stargate.log.info("[Stargate] {" + world.getName() + "} Loaded " + portalCount + " stargates with " + OpenCount + " set as always-on"); diff --git a/src/net/TheDgtl/Stargate/Stargate.java b/src/net/TheDgtl/Stargate/Stargate.java index 7272a48..9f3874b 100644 --- a/src/net/TheDgtl/Stargate/Stargate.java +++ b/src/net/TheDgtl/Stargate/Stargate.java @@ -5,6 +5,7 @@ import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; @@ -26,6 +27,7 @@ import org.bukkit.block.Block; import org.bukkit.block.EndGateway; import org.bukkit.block.Sign; import org.bukkit.block.data.Orientable; +import org.bukkit.block.data.type.WallSign; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -120,6 +122,8 @@ public class Stargate extends JavaPlugin { // HashMap of player names for Bungee support public static Map bungeeQueue = new HashMap<>(); + public static HashSet managedWorlds = new HashSet<>(); + public void onDisable() { Portal.closeAllGates(); Portal.clearGates(); @@ -162,14 +166,15 @@ public class Stargate extends JavaPlugin { lang = new LangLoader(langFolder, Stargate.langName); this.migrate(); - this.reloadGates(); + this.loadGates(); + this.loadAllPortals(); // Check to see if Economy is loaded yet. if (EconomyHandler.setupEconomy(pm)) { if (EconomyHandler.economy != null) log.info("[Stargate] Vault v" + EconomyHandler.vault.getDescription().getVersion() + " found"); } - + getServer().getScheduler().scheduleSyncRepeatingTask(this, new SGThread(), 0L, 100L); getServer().getScheduler().scheduleSyncRepeatingTask(this, new BlockPopulatorThread(), 0L, 1L); } @@ -217,16 +222,24 @@ public class Stargate extends JavaPlugin { this.saveConfig(); } - public void reloadGates() { + public void closeAllPortals() { // Close all gates prior to reloading for (Portal p : openList) { p.close(true); } - + } + + public void loadGates() { Gate.loadGates(gateFolder); log.info("[Stargate] Loaded " + Gate.getGateCount() + " gate layouts"); + } + + public void loadAllPortals() { for (World world : getServer().getWorlds()) { - Portal.loadAllGates(world); + if(!managedWorlds.contains(world.getName())) { + Portal.loadAllGates(world); + managedWorlds.add(world.getName()); + } } } @@ -829,7 +842,7 @@ public class Stargate extends JavaPlugin { // Right click if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - if (block.getType() == Material.WALL_SIGN) { + if (block.getBlockData() instanceof WallSign) { Portal portal = Portal.getByBlock(block); if (portal == null) return; // Cancel item use @@ -882,7 +895,7 @@ public class Stargate extends JavaPlugin { // Left click if (event.getAction() == Action.LEFT_CLICK_BLOCK) { // Check if we're scrolling a sign - if (block.getType() == Material.WALL_SIGN) { + if (block.getBlockData() instanceof WallSign) { Portal portal = Portal.getByBlock(block); if (portal == null) return; @@ -916,7 +929,7 @@ public class Stargate extends JavaPlugin { if (event.isCancelled()) return; Player player = event.getPlayer(); Block block = event.getBlock(); - if (block.getType() != Material.WALL_SIGN) return; + if (!(block.getBlockData() instanceof WallSign)) return; final Portal portal = Portal.createPortal(event, player); // Not creating a gate, just placing a sign @@ -1041,7 +1054,10 @@ public class Stargate extends JavaPlugin { private class wListener implements Listener { @EventHandler public void onWorldLoad(WorldLoadEvent event) { - Portal.loadAllGates(event.getWorld()); + if(!managedWorlds.contains(event.getWorld().getName())) { + Portal.loadAllGates(event.getWorld()); + managedWorlds.add(event.getWorld().getName()); + } } // We need to reload all gates on world unload, boo @@ -1049,13 +1065,13 @@ public class Stargate extends JavaPlugin { public void onWorldUnload(WorldUnloadEvent event) { Stargate.debug("onWorldUnload", "Reloading all Stargates"); World w = event.getWorld(); - String location = Stargate.getSaveLocation(); - File db = new File(location, w.getName() + ".db"); - if (db.exists()) { + if(managedWorlds.contains(w.getName())) { + managedWorlds.remove(w.getName()); Portal.clearGates(); - for (World world : server.getWorlds()) { - if (world.equals(w)) continue; - Portal.loadAllGates(world); + for(World world : server.getWorlds()) { + if(managedWorlds.contains(world.getName())) { + Portal.loadAllGates(world); + } } } } @@ -1101,7 +1117,7 @@ public class Stargate extends JavaPlugin { BloxPopulator b = Stargate.blockPopulatorQueue.poll(); if (b == null) return; Block blk = b.getBlox().getBlock(); - blk.setType(b.getMat(), false); + blk.setType(b.getMat()); if(b.getMat() == Material.END_GATEWAY && blk.getWorld().getEnvironment() == World.Environment.THE_END) { // force a location to prevent exit gateway generation EndGateway gateway = (EndGateway) blk.getState(); @@ -1167,12 +1183,11 @@ public class Stargate extends JavaPlugin { p.deactivate(); } // Close portals - for (Portal p : openList) { - p.close(true); - } + closeAllPortals(); // Clear all lists activeList.clear(); openList.clear(); + managedWorlds.clear(); Portal.clearGates(); Gate.clearGates(); @@ -1180,7 +1195,8 @@ public class Stargate extends JavaPlugin { boolean oldEnableBungee = enableBungee; // Reload data loadConfig(); - reloadGates(); + loadGates(); + loadAllPortals(); lang.setLang(langName); lang.reload(); diff --git a/src/plugin.yml b/src/plugin.yml index 3fc13e4..6821de4 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Stargate main: net.TheDgtl.Stargate.Stargate -version: 0.7.9.11 +version: 0.8.0.0-SNAPSHOT description: Stargate mod for Bukkit author: Drakia website: http://www.thedgtl.net