From c22c9b78db32294f200e226abe5e6dfb407d5c12 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 14 May 2018 22:10:26 +0200 Subject: [PATCH] Added in config contact_auth option. WorldPlayer is now on WorldConfig --- WorldSystem/bin/config.yml | 5 + WorldSystem/src/config.yml | 5 + .../world/command/WSToggleBuildCommand.java | 5 +- .../world/command/WSToggleGMCommand.java | 13 +- .../world/command/WSToggleTPCommand.java | 5 +- .../butzlabben/world/config/PluginConfig.java | 5 +- .../butzlabben/world/config/WorldConfig.java | 1 - .../butzlabben/world/wrapper/SystemWorld.java | 3 +- .../butzlabben/world/wrapper/WorldPlayer.java | 123 +++++------------- 9 files changed, 64 insertions(+), 101 deletions(-) diff --git a/WorldSystem/bin/config.yml b/WorldSystem/bin/config.yml index 69df7fd..c1a07ad 100644 --- a/WorldSystem/bin/config.yml +++ b/WorldSystem/bin/config.yml @@ -34,6 +34,11 @@ language: en # Prefix which will be shown before each message prefix: '&8[&3WorldSystem&8] &6' +# Whether WorldSystem should contact the Mojang authserver +# If not, some unknown playernames will not be displayed +# eg. in the gui or in /ws info +contact_authserver: true + # Options for the LagSystem: # period_in_seconds - how often will be checked for entities in seconds # entities_per_world - maximal allowed entities per world diff --git a/WorldSystem/src/config.yml b/WorldSystem/src/config.yml index 69df7fd..c1a07ad 100644 --- a/WorldSystem/src/config.yml +++ b/WorldSystem/src/config.yml @@ -34,6 +34,11 @@ language: en # Prefix which will be shown before each message prefix: '&8[&3WorldSystem&8] &6' +# Whether WorldSystem should contact the Mojang authserver +# If not, some unknown playernames will not be displayed +# eg. in the gui or in /ws info +contact_authserver: true + # Options for the LagSystem: # period_in_seconds - how often will be checked for entities in seconds # entities_per_world - maximal allowed entities per world diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java index e5130f6..affebad 100644 --- a/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; import de.butzlabben.world.WorldSystem; import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.WorldConfig2; +import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.wrapper.WorldPlayer; public class WSToggleBuildCommand implements CommandExecutor { @@ -32,7 +32,8 @@ public class WSToggleBuildCommand implements CommandExecutor { } @SuppressWarnings("deprecation") OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); - if (!WorldConfig2.isMember(a, dc.getWorldname())) { + WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); + if (wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); return true; } diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java index e59ed17..ea02f3d 100644 --- a/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; import de.butzlabben.world.WorldSystem; import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.WorldConfig2; +import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.wrapper.WorldPlayer; public class WSToggleGMCommand implements CommandExecutor { @@ -20,9 +20,10 @@ public class WSToggleGMCommand implements CommandExecutor { if (!(cs instanceof Player)) return true; Player p = (Player) cs; - if(args.length != 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", WorldSystem.getInstance().getCommand("ws togglegm").getUsage())); - return true; + if (args.length != 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", + WorldSystem.getInstance().getCommand("ws togglegm").getUsage())); + return true; } DependenceConfig dc = new DependenceConfig(p); if (!dc.hasWorld()) { @@ -31,7 +32,8 @@ public class WSToggleGMCommand implements CommandExecutor { } @SuppressWarnings("deprecation") OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); - if (!WorldConfig2.isMember(a, dc.getWorldname())) { + WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); + if (wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); return true; } @@ -44,4 +46,3 @@ public class WSToggleGMCommand implements CommandExecutor { return true; } } - diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java index 9ddc8a4..aee4ada 100644 --- a/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; import de.butzlabben.world.WorldSystem; import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.WorldConfig2; +import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.wrapper.WorldPlayer; public class WSToggleTPCommand implements CommandExecutor { @@ -32,7 +32,8 @@ public class WSToggleTPCommand implements CommandExecutor { } @SuppressWarnings("deprecation") OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); - if (!WorldConfig2.isMember(a, dc.getWorldname())) { + WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); + if (wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); return true; } diff --git a/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java b/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java index a305210..f912663 100644 --- a/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java +++ b/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java @@ -33,7 +33,7 @@ public class PluginConfig { YamlConfiguration cfg = getConfig(); if (false == (cfg.isString("worldfolder") && cfg.isString("worldsource") && cfg.isInt("unloadingtime") && cfg.isBoolean("survival") && cfg.isString("language") && cfg.isString("prefix") - && cfg.isInt("request_expires") && cfg.isBoolean("need_confirm") && + && cfg.isInt("request_expires") && cfg.isBoolean("need_confirm") && cfg.isBoolean("contact_authserver") && cfg.isInt("lagsystem.period_in_seconds") && cfg.isInt("lagsystem.entities_per_world") && cfg.isBoolean("lagsystem.garbagecollector.use") @@ -196,4 +196,7 @@ public class PluginConfig { return getConfig().getBoolean("need_confirm", true); } + public static boolean contact_auth() { + return getConfig().getBoolean("contact_authserver", true); + } } diff --git a/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java index 4a91be4..a900d9a 100644 --- a/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java +++ b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java @@ -400,7 +400,6 @@ public class WorldConfig { fire = cfg.getBoolean("Settings.Fire", true); if (membersOldFormatted(cfg)) { - System.out.println("sfdjkl"); for (String s : cfg.getConfigurationSection("Members").getKeys(false)) { HashSet perms = new HashSet<>(); perms.add(WorldPerm.MEMBER); diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java index 4ae7db4..820cbde 100644 --- a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java +++ b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java @@ -3,6 +3,7 @@ package de.butzlabben.world.wrapper; import java.io.File; import java.io.IOException; import java.util.HashMap; + import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -12,6 +13,7 @@ import org.bukkit.World.Environment; import org.bukkit.WorldCreator; import org.bukkit.WorldType; import org.bukkit.entity.Player; + import com.google.common.base.Preconditions; import de.butzlabben.event.WorldCreateEvent; @@ -22,7 +24,6 @@ import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.config.WorldConfig2; /** * This class represents a systemworld, loaded or not diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java b/WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java index 9483534..e393b79 100644 --- a/WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java +++ b/WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; import com.google.common.base.Preconditions; -import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.config.WorldConfig; public class WorldPlayer { @@ -30,24 +30,20 @@ public class WorldPlayer { */ public boolean toggleBuild() { Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - if (!file.exists()) { - file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); - } - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - if (cfg.getString("Members." + uuid + ".PlayerUUID") == null) + + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + if (!wc.isMember(p.getUniqueId())) return false; - boolean teleport = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); - teleport = !teleport; - cfg.set("Members." + uuid + ".Permissions.CanBuild", teleport); + boolean build = wc.canBuild(p.getUniqueId()); + build = !build; + wc.setBuild(p.getUniqueId(), build); try { - cfg.save(file); + wc.save(); } catch (IOException e) { e.printStackTrace(); } - return teleport; + return build; } /** @@ -55,11 +51,8 @@ public class WorldPlayer { */ public boolean canBuild() { Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); - return b; + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + return wc.canBuild(p.getUniqueId()); } /** @@ -68,20 +61,16 @@ public class WorldPlayer { */ public boolean toggleTeleport() { Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - if (!file.exists()) { - file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); - } - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - if (cfg.getString("Members." + uuid + ".PlayerUUID") == null) + + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + if (!wc.isMember(p.getUniqueId())) return false; - boolean teleport = cfg.getBoolean("Members." + uuid + ".Permissions.CanTP"); + boolean teleport = wc.canTeleport(p.getUniqueId()); teleport = !teleport; - cfg.set("Members." + uuid + ".Permissions.CanTP", teleport); + wc.setTeleport(p.getUniqueId(), teleport); try { - cfg.save(file); + wc.save(); } catch (IOException e) { e.printStackTrace(); } @@ -93,11 +82,8 @@ public class WorldPlayer { */ public boolean canTeleport() { Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanTP"); - return b; + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + return wc.canTeleport(p.getUniqueId()); } /** @@ -106,20 +92,17 @@ public class WorldPlayer { */ public boolean toggleGamemode() { Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - if (!file.exists()) { - file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); - } - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - if (cfg.getString("Members." + uuid + ".PlayerUUID") == null) + + + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + if (!wc.isMember(p.getUniqueId())) return false; - boolean changeGamemode = cfg.getBoolean("Members." + uuid + ".Permissions.ChangeGM"); + boolean changeGamemode = wc.canGamemode(p.getUniqueId()); changeGamemode = !changeGamemode; - cfg.set("Members." + uuid + ".Permissions.ChangeGM", changeGamemode); + wc.setGamemode(p.getUniqueId(), changeGamemode); try { - cfg.save(file); + wc.save(); } catch (IOException e) { e.printStackTrace(); } @@ -131,11 +114,8 @@ public class WorldPlayer { */ public boolean canChangeGamemode() { Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.ChangeGM"); - return b; + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + return wc.canGamemode(p.getUniqueId()); } /** @@ -143,22 +123,9 @@ public class WorldPlayer { */ public boolean isMember() { Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - if (!worldconfig.exists()) { - worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); - } - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); - String uuid = p.getUniqueId().toString(); - if (uuid.equals(cfg.getString("Members." + uuid + ".PlayerUUID"))) { - cfg.set("Members." + uuid + ".Actualname", p.getName()); - try { - cfg.save(worldconfig); - } catch (IOException e) { - e.printStackTrace(); - } - return true; - } - return false; + + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + return wc.isMember(p.getUniqueId()); } public WorldPlayer(OfflinePlayer p, String worldname) { @@ -197,20 +164,8 @@ public class WorldPlayer { * @return if he ist the owner */ public boolean isOwnerofWorld() { - File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); - if (p.getUniqueId().toString().equals(cfg.getString("Informations.Owner.PlayerUUID"))) { - String playerName = p.getName(); - cfg.set("Informations.Owner.Actualname", playerName); - try { - cfg.save(worldconfig); - } catch (IOException e) { - e.printStackTrace(); - } - return true; - } else { - return false; - } + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + return wc.getOwner().equals(p.getUniqueId()); } /** @@ -218,16 +173,8 @@ public class WorldPlayer { * @return worldname if he is the owner of the specified world */ public boolean isMemberofWorld(String worldname) { - File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - if (!worldconfig.exists()) { - worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); - } - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); - String uuid = p.getUniqueId().toString(); - if (uuid.equals(cfg.getString("Members." + uuid + ".PlayerUUID"))) { - return true; - } - return false; + WorldConfig wc = WorldConfig.getWorldConfig(worldname); + return wc.isMember(p.getUniqueId()); } }