From 801ce6a4aac5ca5d9ce57f4fce9d4a34ab68e5e0 Mon Sep 17 00:00:00 2001 From: Alastair Date: Wed, 12 Jul 2017 13:27:22 +0100 Subject: [PATCH] Fixed issue from refactoring as well as other issues --- Resources/plugin.yml | 2 +- pom.xml | 2 +- .../AdvancedPortalsCommand.java | 16 +++-- .../AdvancedPortalsPlugin.java | 65 ++++++++++++++----- .../advancedportals/portals/Portal.java | 49 +++++++------- 5 files changed, 86 insertions(+), 48 deletions(-) diff --git a/Resources/plugin.yml b/Resources/plugin.yml index 7c36713e..dda033a3 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -1,6 +1,6 @@ main: com.sekwah.advancedportals.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.0.32 +version: 0.0.33 author: sekwah41 description: An advanced portals plugin for bukkit. commands: diff --git a/pom.xml b/pom.xml index ad7c2258..69220cdd 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - 0.0.32-snapshot + 0.0.33-snapshot UTF-8 1.7 diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 2a01e025..cbd3b225 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -44,6 +44,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); Player player = (Player) sender; PlayerInventory inventory = player.getInventory(); + if (sender.hasPermission("advancedportals.portal")) { if (args.length > 0) { switch (args[0].toLowerCase()) { case "wand": @@ -200,11 +201,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage(PluginMessages.customPrefix + "\u00A7e You have created a new portal with the following details:"); player.sendMessage("\u00A7aname: \u00A7e" + portalName); if (hasDestination) { - player.sendMessage("\u00A7adestination: \u00A7e" + destination); - } else if (destiPosX == null) { - player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)"); + if (destiPosX == null) { + player.sendMessage("\u00A7cdestination: \u00A7e" + destination + " (destination does not exist)"); + return true; + } + else{ + player.sendMessage("\u00A7adestination: \u00A7e" + destination); + } + } else { - player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not work)"); + player.sendMessage("\u00A7cdestination: \u00A7eN/A (will not teleport to a location)"); } if (isBungeePortal) { @@ -221,7 +227,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage("\u00A7acommand: \u00A7e" + portalCommand); } - Material triggerBlockMat = Material.getMaterial(0); + Material triggerBlockMat; if (hasTriggerBlock) { triggerBlockMat = Material.getMaterial(triggerBlock.toUpperCase()); if (triggerBlockMat != null) { diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index ebbe57db..dfe8db62 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -10,7 +10,7 @@ import com.sekwah.advancedportals.portals.Portal; import org.bukkit.Material; import org.bukkit.plugin.java.JavaPlugin; -import java.io.IOException; +import java.io.*; public class AdvancedPortalsPlugin extends JavaPlugin { @@ -37,9 +37,57 @@ public class AdvancedPortalsPlugin extends JavaPlugin { this.compat = new CraftBukkit(this, version); + + // This is a fix for my stupidity with the last version + File dataFolder = this.getDataFolder(); + File configFile = new File(dataFolder, "portals.yml"); + + InputStreamReader inr = null; + try { + inr = new InputStreamReader(new FileInputStream(configFile), "ASCII"); + BufferedReader br = new BufferedReader(inr); + StringBuffer sb = new StringBuffer(); + while (true) { + String line = br.readLine(); + if (line == null) + break; + sb.append(line); + sb.append("\n"); + } + br.close(); + inr.close(); + + String fileContents = sb.toString(); + + fileContents = fileContents.replaceAll(" getPos1\\(\\):", " pos1:"); + fileContents = fileContents.replaceAll(" getPos2\\(\\):", " pos2:"); + fileContents = fileContents.replaceAll(" getBungee\\(\\):", " bungee:"); + + try { + FileWriter fileWriter = new FileWriter(configFile); + + BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); + bufferedWriter.write(fileContents); + bufferedWriter.flush(); + bufferedWriter.close(); + fileWriter.close(); + } + catch(IOException e) { + e.printStackTrace(); + } + } catch (UnsupportedEncodingException e) { + this.getLogger().warning("Invalid Encoding"); + } catch (FileNotFoundException e) { + this.getLogger().info("File not found"); + } catch (IOException e) { + e.printStackTrace(); + } + + ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); portalConfig.saveDefaultConfig(); + ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); destinationConfig.saveDefaultConfig(); @@ -107,21 +155,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!"); } - private class MaterialPlotter extends Metrics.Plotter { - - private final int count; - - public MaterialPlotter(Material triggerBlock, int count){ - super(triggerBlock.toString()); - this.count = count; - } - - @Override - public int getValue() { - return this.count; - } - } - public Settings getSettings() { return settings; diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 4eabb8aa..dd27c8b0 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -96,8 +96,8 @@ public class Portal { String worldName = portalData.getConfig().getString(portal.toString() + ".world"); if(worldName != null) { World world = Bukkit.getWorld(worldName); - Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".getPos1().X"), portalData.getConfig().getInt(portal.toString() + ".getPos1().Y"), portalData.getConfig().getInt(portal.toString() + ".getPos1().Z")); - Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".getPos2().X"), portalData.getConfig().getInt(portal.toString() + ".getPos2().Y"), portalData.getConfig().getInt(portal.toString() + ".getPos2().Z")); + Location pos1 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos1.X"), portalData.getConfig().getInt(portal.toString() + ".pos1.Y"), portalData.getConfig().getInt(portal.toString() + ".pos1.Z")); + Location pos2 = new Location(world, portalData.getConfig().getInt(portal.toString() + ".pos2.X"), portalData.getConfig().getInt(portal.toString() + ".pos2.Y"), portalData.getConfig().getInt(portal.toString() + ".pos2.Z")); PortalArg[] portalArgs = new PortalArg[extraData.size()]; extraData.toArray(portalArgs); @@ -179,15 +179,15 @@ public class Portal { portalData.getConfig().set(name + ".destination", destination); - portalData.getConfig().set(name + ".getBungee()", serverName); + portalData.getConfig().set(name + ".bungee", serverName); - portalData.getConfig().set(name + ".getPos1().X", HighX); - portalData.getConfig().set(name + ".getPos1().Y", HighY); - portalData.getConfig().set(name + ".getPos1().Z", HighZ); + portalData.getConfig().set(name + ".pos1.X", HighX); + portalData.getConfig().set(name + ".pos1.Y", HighY); + portalData.getConfig().set(name + ".pos1.Z", HighZ); - portalData.getConfig().set(name + ".getPos2().X", LowX); - portalData.getConfig().set(name + ".getPos2().Y", LowY); - portalData.getConfig().set(name + ".getPos2().Z", LowZ); + portalData.getConfig().set(name + ".pos2.X", LowX); + portalData.getConfig().set(name + ".pos2.Y", LowY); + portalData.getConfig().set(name + ".pos2.Z", LowZ); for (PortalArg arg : portalArgs) { portalData.getConfig().set(name + ".portalArgs." + arg.argName, arg.value); @@ -289,13 +289,13 @@ public class Portal { public static void redefine(Location pos1, Location pos2, String name) { - portalData.getConfig().set(name + ".getPos1().X", pos1.getX()); - portalData.getConfig().set(name + ".getPos1().Y", pos1.getY()); - portalData.getConfig().set(name + ".getPos1().Z", pos1.getZ()); + portalData.getConfig().set(name + ".pos1.X", pos1.getX()); + portalData.getConfig().set(name + ".pos1.Y", pos1.getY()); + portalData.getConfig().set(name + ".pos1.Z", pos1.getZ()); - portalData.getConfig().set(name + ".getPos2().X", pos2.getX()); - portalData.getConfig().set(name + ".getPos2().Y", pos2.getY()); - portalData.getConfig().set(name + ".getPos2().Z", pos2.getZ()); + portalData.getConfig().set(name + ".pos2.X", pos2.getX()); + portalData.getConfig().set(name + ".pos2.Y", pos2.getY()); + portalData.getConfig().set(name + ".pos2.Z", pos2.getZ()); portalData.saveConfig(); @@ -331,15 +331,15 @@ public class Portal { portalData.getConfig().set(name + ".triggerblock", null); portalData.getConfig().set(name + ".destination", null); - portalData.getConfig().set(name + ".getPos1().X", null); - portalData.getConfig().set(name + ".getPos1().Y", null); - portalData.getConfig().set(name + ".getPos1().Z", null); + portalData.getConfig().set(name + ".pos1.X", null); + portalData.getConfig().set(name + ".pos1.Y", null); + portalData.getConfig().set(name + ".pos1.Z", null); - portalData.getConfig().set(name + ".getPos2().X", null); - portalData.getConfig().set(name + ".getPos2().Y", null); - portalData.getConfig().set(name + ".getPos2().Z", null); + portalData.getConfig().set(name + ".pos2.X", null); + portalData.getConfig().set(name + ".pos2.Y", null); + portalData.getConfig().set(name + ".pos2.Z", null); - portalData.getConfig().set(name + ".getPos1()", null); + portalData.getConfig().set(name + ".pos1", null); portalData.getConfig().set(name + ".getPos2()", null); portalData.getConfig().set(name, null);*/ @@ -351,7 +351,7 @@ public class Portal { public static boolean portalExists(String portalName) { - String posX = portalData.getConfig().getString(portalName + ".getPos1().X"); + String posX = portalData.getConfig().getString(portalName + ".pos1.X"); return posX != null; } @@ -507,8 +507,7 @@ public class Portal { ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); if (portalExists(portalName)) { int commandLine = 0; - while (config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null) - ; //Loops increasing commandLine till 1 is null + while (config.getConfig().getString(portalName + ".portalArgs.command." + ++commandLine) != null); //Loops increasing commandLine till 1 is null config.getConfig().set(portalName + ".portalArgs.command." + commandLine, portalCommand); config.saveConfig(); loadPortals();