diff --git a/World System.ipr b/World System.ipr index 0c9b267..7f467c7 100644 --- a/World System.ipr +++ b/World System.ipr @@ -1,79 +1,661 @@ - - - + + + + + + + + + + + + + + - + + + + + + - - + - + + + + + + + - - - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + @@ -83,7 +665,7 @@ @@ -94,11 +676,11 @@ - + - + - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index ed19fab..0868e20 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,9 @@ spigot { name = project.property("pluginName") authors = [project.property("author")] apiVersion = project.property("apiVersion") + depends = [project.property("Vault")] + + //Comands commands { @@ -152,6 +155,13 @@ repositories { url = 'http://maven.sk89q.com/repo/' } maven { url = "https://mvn.intellectualsites.com/content/repositories/releases/" } + + // Commons - IO + maven { url = "https://mvnrepository.com/artifact/commons-io/commons-io" } + + // WorldEdit + maven { url = "http://maven.enginehub.org/repo/" } + mavenCentral() } @@ -174,10 +184,10 @@ dependencies { compileOnly 'com.github.MilkBowl:VaultAPI:1.7' compileOnly 'com.mojang:authlib:1.5.25' compileOnly 'org.projectlombok:lombok:1.18.14' - compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT' - compileOnly 'com.sk89q.worldedit:worldedit-core:7.0.0-SNAPSHOT' - compile files('C:/Users/train/Desktop/Programing/Git/worldsystem/lib/commons-io-2.7.jar') - compile files('C:/Users/train/Desktop/Programing/Git/worldsystem/lib/FastAsyncWorldEdit.jar') + compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT' + compileOnly 'com.sk89q.worldedit:worldedit-core:7.2.0-SNAPSHOT' + compile group: 'commons-io', name: 'commons-io', version: '2.7' + compileOnly files('dependency/FastAsyncWorldEdit.jar') } shadowJar { diff --git a/gradle.properties b/gradle.properties index bd45738..146d8db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,8 @@ author = Trainerlord & Butzlabben mcVersion = 1.16.2 apiVersion = 1.15 version = 2.4.11 +Vault = Vault +WorldEdit = WorldEdit +FAWE = FAWE + diff --git a/src/main/java/de/butzlabben/world/WorldSystem.java b/src/main/java/de/butzlabben/world/WorldSystem.java index 3804e16..028dd14 100644 --- a/src/main/java/de/butzlabben/world/WorldSystem.java +++ b/src/main/java/de/butzlabben/world/WorldSystem.java @@ -2,15 +2,8 @@ package de.butzlabben.world; import de.butzlabben.world.autoupdater.AutoUpdater; import de.butzlabben.world.command.CommandRegistry; -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.SettingsConfig; -import de.butzlabben.world.listener.BlockListener; -import de.butzlabben.world.listener.CommandListener; -import de.butzlabben.world.listener.PlayerListener; -import de.butzlabben.world.listener.WorldEditListener; +import de.butzlabben.world.config.*; +import de.butzlabben.world.listener.*; import de.butzlabben.world.util.PapiExtension; import de.butzlabben.world.util.PlayerPositions; import de.butzlabben.world.util.VersionUtil; @@ -18,16 +11,16 @@ import de.butzlabben.world.util.database.DatabaseProvider; import de.butzlabben.world.wrapper.AsyncCreatorAdapter; import de.butzlabben.world.wrapper.CreatorAdapter; import de.butzlabben.world.wrapper.SystemWorld; -import java.io.File; -import java.io.IOException; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.World; - import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import java.io.File; +import java.io.IOException; + /** * @author Butzlabben * @author Jubeki @@ -38,6 +31,7 @@ public class WorldSystem extends JavaPlugin { private static boolean is1_13Plus = false; final private String version = this.getDescription().getVersion(); private CreatorAdapter creator; + public static void createConfigs() { File folder = getInstance().getDataFolder(); File dir = new File(folder + "/worldsources"); @@ -120,6 +114,7 @@ public class WorldSystem extends JavaPlugin { pm.registerEvents(new PlayerListener(), this); pm.registerEvents(new BlockListener(), this); pm.registerEvents(new CommandListener(), this); + pm.registerEvents(new WorldInitSkipSpawn(), this); if (pm.getPlugin("WorldEdit") != null) pm.registerEvents(new WorldEditListener(), this); @@ -132,6 +127,8 @@ public class WorldSystem extends JavaPlugin { 20 * PluginConfig.getGCPeriod()); } + + /* TODO better check this only on worldInitEvent Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { for (World w : Bukkit.getWorlds()) { SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); @@ -139,7 +136,7 @@ public class WorldSystem extends JavaPlugin { SettingsConfig.editWorld(w); } - }, 20, 20 * 10); + }, 20, 20 * 10);*/ Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { for (World w : Bukkit.getWorlds()) { @@ -159,11 +156,6 @@ public class WorldSystem extends JavaPlugin { //this.getCommand("ws fire").setExecutor(new WorldFire()); - - - - - System.setProperty("bstats.relocatecheck", "false"); Metrics m = new Metrics(this); m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID)); @@ -175,6 +167,7 @@ public class WorldSystem extends JavaPlugin { && Bukkit.getPluginManager().getPlugin("WorldEdit") != null && PluginConfig.loadWorldsASync() && !is1_13Plus) { + creator = new AsyncCreatorAdapter(); Bukkit.getConsoleSender() .sendMessage(PluginConfig.getPrefix() + "Found FAWE! Worlds now will be created asynchronously"); diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java index cc70601..afadd97 100644 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ b/src/main/java/de/butzlabben/world/command/CommandRegistry.java @@ -1,86 +1,104 @@ -package de.butzlabben.world.command; - -import de.butzlabben.world.command.commands.WSCommands; -import de.butzlabben.world.command.commands.WorldAdministrateCommand; -import de.butzlabben.world.command.commands.WorldSettingsCommands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import static de.butzlabben.world.command.commands.WSCommands.*; -import static de.butzlabben.world.command.commands.WorldAdministrateCommand.*; - -import java.util.List; - - -public class CommandRegistry implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - - if (args.length == 0) { - WSCommands ws = new WSCommands(); - return ws.mainCommand(sender, command, label, args); - } else { - WSCommands ws = new WSCommands(); - WorldAdministrateCommand admin = new WorldAdministrateCommand(); - WorldSettingsCommands settings = new WorldSettingsCommands(); - switch (args[0]) { - //WSCommands - case "get": - return ws.getCommand(sender, command, label, args); - case "gui": - return ws.guiCommand(sender, command, label, args); - case "confirm": - if (sender.hasPermission("ws.confirm")) { - return ws.confirmCommand(sender, command, label, args); - } else { - return false; - } - case "home": - return ws.homeCommand(sender, command, label, args); - case "info": - return ws.infoComannd(sender, command, label, args); - case "leave": - return ws.leaveCommand(sender, command, label, args); - case "tp": - return ws.tpCommand(sender, command, label, args); - //Admin Command - case "delmember": - return admin.delMemberCommand(sender, command, label, args); - case "delete": - if (sender.hasPermission("ws.delete")) { - return admin.deleteCommand(sender, command, label, args); - } else { - return false; - } - case "addmember": - return admin.addMemberCommand(sender, command, label, args); - case "toggletp": - return admin.toggleTeleportCommand(sender, command, label, args); - case "togglegm": - return admin.toggleGamemodeCommand(sender, command, label, args); - case "togglewe": - return admin.toggleWorldeditCommand(sender, command, label, args); - case "togglebuild": - return admin.toggleBuildCommand(sender, command, label, args); - //World Settings Command - case "reset": - return settings.resetCommand(sender, command, label, args); - case "sethome": - sender.sendMessage("Disabled For Major Error and Rework"); - /* - if (sender.hasPermission("ws.sethome")) { - return settings.setHomeCommand(sender, command, label, args); - } else { - return false; - }*/ - case "tnt": - return settings.tntCommand(sender, command, label, args); - case "fire": - return settings.fireCommand(sender, command, label, args); - default: - return false; - } - } - } -} +package de.butzlabben.world.command; + +import de.butzlabben.world.command.commands.WSCommands; +import de.butzlabben.world.command.commands.WorldAdministrateCommand; +import de.butzlabben.world.command.commands.WorldSettingsCommands; +import de.butzlabben.world.util.Worldutils; +import de.butzlabben.world.wrapper.WorldTemplateProvider; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + + +public class CommandRegistry implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (args.length == 0) { + WSCommands ws = new WSCommands(); + return ws.mainCommand(sender, command, label, args); + } else { + WSCommands ws = new WSCommands(); + WorldAdministrateCommand admin = new WorldAdministrateCommand(); + WorldSettingsCommands settings = new WorldSettingsCommands(); + switch (args[0]) { + //WSCommands + case "get": + return ws.getCommand(sender, command, label, args); + case "gui": + return ws.guiCommand(sender, command, label, args); + case "confirm": + if (sender.hasPermission("ws.confirm")) { + return ws.confirmCommand(sender, command, label, args); + } else { + return false; + } + case "home": + return ws.homeCommand(sender, command, label, args); + case "info": + return ws.infoComannd(sender, command, label, args); + case "leave": + return ws.leaveCommand(sender, command, label, args); + case "tp": + return ws.tpCommand(sender, command, label, args); + //Admin Command + case "day": + return admin.setTime(sender,0); + case "night": + return admin.setTime(sender,14000); + case "time": + return admin.setTime(sender, args[1]); + case "rain": + case "storm": + return admin.setStorm(sender,true); + case "sun": + return admin.setStorm(sender, false); + case "delmember": + return admin.delMemberCommand(sender, command, label, args); + case "delete": + if (sender.hasPermission("ws.delete")) { + return admin.deleteCommand(sender, command, label, args); + } else { + return false; + } + case "addmember": + return admin.addMemberCommand(sender, command, label, args); + case "toggletp": + return admin.toggleTeleportCommand(sender, command, label, args); + case "togglegm": + return admin.toggleGamemodeCommand(sender, command, label, args); + case "togglewe": + return admin.toggleWorldeditCommand(sender, command, label, args); + case "togglebuild": + return admin.toggleBuildCommand(sender, command, label, args); + //World Settings Command + case "reset": + return settings.resetCommand(sender, command, label, args); + case "sethome": + sender.sendMessage("Disabled For Major Error and Rework"); + return false; + /* + if (sender.hasPermission("ws.sethome")) { + return settings.setHomeCommand(sender, command, label, args); + } else { + return false; + }*/ + case "tnt": + return settings.tntCommand(sender, command, label, args); + case "fire": + return settings.fireCommand(sender, command, label, args); + case "reload": + if(!sender.isOp()){ + sender.sendMessage("Reloading Settings!"); + WorldTemplateProvider.getInstance().reload(); + Worldutils.reloadWorldSettings(); + return true; + } + default: + //default command is better than the other one + return ws.mainCommand(sender, command, label, args); + } + } + } +} diff --git a/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java b/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java index 0f31a28..fbeca3d 100644 --- a/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java +++ b/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java @@ -9,6 +9,7 @@ import de.butzlabben.world.event.WorldAddmemberEvent; import de.butzlabben.world.event.WorldDeleteEvent; import de.butzlabben.world.event.WorldRemovememberEvent; import de.butzlabben.world.util.PlayerPositions; +import de.butzlabben.world.util.PlayerWrapper; import de.butzlabben.world.wrapper.SystemWorld; import de.butzlabben.world.wrapper.WorldPlayer; import org.apache.commons.io.FileUtils; @@ -24,51 +25,116 @@ import java.io.IOException; public class WorldAdministrateCommand { + public boolean setTime(CommandSender sender, String ticks) { + switch (ticks) { + case "day": + return setTime(sender, 0); + case "night": + return setTime(sender, 14000); + case "dawn": + return setTime(sender, 23000); + default: + try { + return setTime(sender, Long.parseLong(ticks)); + } catch (NumberFormatException e) { + sender.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws time [day/night/dawn/0-24000]")); + return false; + } + + } + } + + public boolean setStorm(CommandSender sender, boolean storm) { + if (!(sender instanceof Player)) { + sender.sendMessage("Command has to be executed as a player!"); + return false; + } + + Player p = (Player) sender; + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNotOnWorld()); + return false; + } + + if (dc.getWorldname().equals(p.getWorld().getName())) { + p.getWorld().setStorm(storm); + return true; + } + + + p.sendMessage(MessageConfig.getNotOnWorld()); + return false; + } + + public boolean setTime(CommandSender sender, long ticks) { + if (!(sender instanceof Player)) { + sender.sendMessage("Command has to be executed as a player!"); + return false; + } + + Player p = (Player) sender; + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNotOnWorld()); + return false; + } + + if (dc.getWorldname().equals(p.getWorld().getName())) { + p.getWorld().setTime(ticks); + return true; + } + + + p.sendMessage(MessageConfig.getNotOnWorld()); + return false; + } + public boolean delMemberCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws delmember ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - - @SuppressWarnings("deprecation") - OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (a == null) { - p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1])); - return false; - } else if (!wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getNoMemberOwn()); - return false; - } - WorldRemovememberEvent event = new WorldRemovememberEvent(a.getUniqueId(), dc.getWorldname(), p); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - if (a.isOnline()) { - Player t = (Player) a; - if (t.getWorld().getName().equals(new DependenceConfig(p).getWorldname())) { - t.teleport(PluginConfig.getSpawn(t)); - t.setGameMode(PluginConfig.getSpawnGamemode()); + if (args.length < 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws delmember ")); + return false; } - } - wc.removeMember(a.getUniqueId()); - try { - wc.save(); - } catch (IOException e) { - p.sendMessage(MessageConfig.getUnknownError()); - e.printStackTrace(); - } - p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName())); + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return false; + } + + @SuppressWarnings("deprecation") + OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); + WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); + if (a == null) { + p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1])); + return false; + } else if (!wc.isMember(a.getUniqueId())) { + p.sendMessage(MessageConfig.getNoMemberOwn()); + return false; + } + WorldRemovememberEvent event = new WorldRemovememberEvent(a.getUniqueId(), dc.getWorldname(), p); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return false; + + if (a.isOnline()) { + Player t = (Player) a; + if (t.getWorld().getName().equals(new DependenceConfig(p).getWorldname())) { + t.teleport(PluginConfig.getSpawn(t)); + t.setGameMode(PluginConfig.getSpawnGamemode()); + } + } + + wc.removeMember(a.getUniqueId()); + try { + wc.save(); + } catch (IOException e) { + p.sendMessage(MessageConfig.getUnknownError()); + e.printStackTrace(); + } + p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName())); return true; } else { sender.sendMessage("No Console"); //TODO Get Config @@ -139,8 +205,11 @@ public class WorldAdministrateCommand { } public boolean addMemberCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; + if (!(sender instanceof Player)) { + sender.sendMessage("No Console"); //TODO Get Config + return false; + } + Player p = (Player) sender; if (args.length < 2) { p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws addmember ")); return false; @@ -152,7 +221,7 @@ public class WorldAdministrateCommand { return false; } @SuppressWarnings("deprecation") - OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); if (a == null) { p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1])); @@ -175,11 +244,8 @@ public class WorldAdministrateCommand { e.printStackTrace(); } p.sendMessage(MessageConfig.getMemberAdded().replaceAll("%player", a.getName())); - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } + return true; + } public boolean toggleTeleportCommand(CommandSender sender, Command command, String label, String[] args) { @@ -195,8 +261,7 @@ public class WorldAdministrateCommand { p.sendMessage(MessageConfig.getNoWorldOwn()); return false; } - @SuppressWarnings("deprecation") - OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); if (!wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); @@ -222,33 +287,33 @@ public class WorldAdministrateCommand { public boolean toggleGamemodeCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglegm ")); - return false; - } + if (args.length < 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglegm ")); + return false; + } - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - @SuppressWarnings("deprecation") - OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (!wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getNoMemberOwn()); - return false; - } - WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); - if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); - return false; - } - if (wp.toggleGamemode()) { - p.sendMessage(MessageConfig.getToggleGameModeEnabled().replaceAll("%player", a.getName())); - } else { - p.sendMessage(MessageConfig.getToggleGameModeDisabled().replaceAll("%player", a.getName())); - } + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return false; + } + @SuppressWarnings("deprecation") + OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); + WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); + if (!wc.isMember(a.getUniqueId())) { + p.sendMessage(MessageConfig.getNoMemberOwn()); + return false; + } + WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); + if (wp.isOwnerofWorld()) { + p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); + return false; + } + if (wp.toggleGamemode()) { + p.sendMessage(MessageConfig.getToggleGameModeEnabled().replaceAll("%player", a.getName())); + } else { + p.sendMessage(MessageConfig.getToggleGameModeDisabled().replaceAll("%player", a.getName())); + } return true; } else { sender.sendMessage("No Console"); //TODO Get Config @@ -270,7 +335,7 @@ public class WorldAdministrateCommand { return false; } @SuppressWarnings("deprecation") - OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); if (!wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); @@ -294,8 +359,8 @@ public class WorldAdministrateCommand { } public boolean toggleBuildCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; + if (sender instanceof Player) { + Player p = (Player) sender; if (args.length < 2) { p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglebuild ")); return false; @@ -307,7 +372,7 @@ public class WorldAdministrateCommand { return false; } @SuppressWarnings("deprecation") - OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); if (!wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); @@ -323,10 +388,10 @@ public class WorldAdministrateCommand { } else { p.sendMessage(MessageConfig.getToggleBuildDisabled().replaceAll("%player", a.getName())); } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } + return true; + } else { + sender.sendMessage("No Console"); //TODO Get Config + return false; } + } } diff --git a/src/main/java/de/butzlabben/world/config/DependenceConfig.java b/src/main/java/de/butzlabben/world/config/DependenceConfig.java index c948fa9..3244e6e 100644 --- a/src/main/java/de/butzlabben/world/config/DependenceConfig.java +++ b/src/main/java/de/butzlabben/world/config/DependenceConfig.java @@ -1,5 +1,6 @@ package de.butzlabben.world.config; +import de.butzlabben.world.util.PlayerWrapper; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.YamlConfiguration; @@ -17,15 +18,14 @@ public class DependenceConfig { setConfig(); } - @SuppressWarnings("deprecation") public DependenceConfig(String s) { OfflinePlayer op = null; try { - op = Bukkit.getOfflinePlayer(UUID.fromString(s)); + op = PlayerWrapper.getOfflinePlayer(UUID.fromString(s)); } catch (Exception ignored) { } if (op == null) { - op = Bukkit.getOfflinePlayer(s); + op = PlayerWrapper.getOfflinePlayer(s); } uuid = op.getUniqueId(); } @@ -85,7 +85,7 @@ public class DependenceConfig { File dconfig = new File("plugins//WorldSystem//dependence.yml"); YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); String uuid = this.uuid.toString(); - cfg.set("Dependences." + uuid + ".ActualName", Bukkit.getOfflinePlayer(this.uuid).getName()); + cfg.set("Dependences." + uuid + ".ActualName", PlayerWrapper.getOfflinePlayer(this.uuid).getName()); try { cfg.save(dconfig); } catch (IOException e) { @@ -102,7 +102,7 @@ public class DependenceConfig { id++; cfg.set("HighestID", id); cfg.set("Dependences." + uuid + ".ID", id); - cfg.set("Dependences." + uuid + ".ActualName", Bukkit.getOfflinePlayer(this.uuid).getName()); + cfg.set("Dependences." + uuid + ".ActualName", PlayerWrapper.getOfflinePlayer(this.uuid).getName()); try { cfg.save(dconfig); } catch (IOException e) { @@ -158,6 +158,6 @@ public class DependenceConfig { } public OfflinePlayer getOwner() { - return Bukkit.getOfflinePlayer(uuid); + return PlayerWrapper.getOfflinePlayer(uuid); } } diff --git a/src/main/java/de/butzlabben/world/config/PluginConfig.java b/src/main/java/de/butzlabben/world/config/PluginConfig.java index 99a6b46..e112f24 100644 --- a/src/main/java/de/butzlabben/world/config/PluginConfig.java +++ b/src/main/java/de/butzlabben/world/config/PluginConfig.java @@ -208,6 +208,12 @@ public class PluginConfig { return getConfig().getString("database.players_table_name"); } + public static String getUUIDTableName() { + return getConfig().getString("database.players_uuids"); + } + + + public static String getDatabaseType() { return getConfig().getString("database.type"); } diff --git a/src/main/java/de/butzlabben/world/config/SettingsConfig.java b/src/main/java/de/butzlabben/world/config/SettingsConfig.java index d428cdc..37f8dcd 100644 --- a/src/main/java/de/butzlabben/world/config/SettingsConfig.java +++ b/src/main/java/de/butzlabben/world/config/SettingsConfig.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; +//maybe just merge this config with the WorldConfig public class SettingsConfig { private static final HashMap borderSizes = new HashMap<>(); @@ -27,6 +28,8 @@ public class SettingsConfig { } @SuppressWarnings("deprecation") + // TODO rebuild this, as it's inperformant and not very beautiful code.. + // only load once, and then reload the things from the disk on command public static void editWorld(World w) { YamlConfiguration cfg = getConfig(); diff --git a/src/main/java/de/butzlabben/world/config/WorldConfig.java b/src/main/java/de/butzlabben/world/config/WorldConfig.java index e1fc7f9..42eec9b 100644 --- a/src/main/java/de/butzlabben/world/config/WorldConfig.java +++ b/src/main/java/de/butzlabben/world/config/WorldConfig.java @@ -3,6 +3,7 @@ package de.butzlabben.world.config; import com.google.common.collect.Sets; import com.mojang.authlib.GameProfile; import de.butzlabben.world.GameProfileBuilder; +import de.butzlabben.world.util.PlayerWrapper; import de.butzlabben.world.wrapper.WorldTemplate; import java.io.File; import java.io.IOException; @@ -94,7 +95,7 @@ public class WorldConfig { YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); cfg.set("Informations.ID", dc.getID()); cfg.set("Informations.Owner.PlayerUUID", uuid.toString()); - cfg.set("Informations.Owner.Actualname", Objects.requireNonNull(Bukkit.getOfflinePlayer(uuid)).getName()); + cfg.set("Informations.Owner.Actualname", Objects.requireNonNull(PlayerWrapper.getOfflinePlayer(uuid)).getName()); cfg.set("Informations.template_key", template.getName()); cfg.set("Settings.TNTDamage", false); cfg.set("Settings.Fire", false); @@ -370,7 +371,7 @@ public class WorldConfig { public HashMap getMembersWithNames() { HashMap map = new HashMap<>(); for (UUID uuid : permissions.keySet()) { - OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); + OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid); if (op == null || op.getName() == null) { if (PluginConfig.contactAuth()) { try { diff --git a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java b/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java index 228a67f..f5b9e55 100644 --- a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java +++ b/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java @@ -10,6 +10,7 @@ import de.butzlabben.world.gui.playeroption.BuildStatus; import de.butzlabben.world.gui.playeroption.GamemodeStatus; import de.butzlabben.world.gui.playeroption.TeleportStatus; import de.butzlabben.world.gui.playeroption.WorldEditStatus; +import de.butzlabben.world.util.PlayerWrapper; import de.butzlabben.world.wrapper.WorldPlayer; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -22,7 +23,7 @@ public class PlayerOptionsGUI extends OrcInventory { public PlayerOptionsGUI(Player loader, String otherPlayer, UUID other) { super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("options.player"), GuiConfig.isFill("options.player")); - WorldPlayer wp = new WorldPlayer(Bukkit.getOfflinePlayer(other), loader.getWorld().getName()); + WorldPlayer wp = new WorldPlayer(PlayerWrapper.getOfflinePlayer(other), loader.getWorld().getName()); loadItem("build", "/ws togglebuild " + otherPlayer, new BuildStatus(wp)); loadItem("gamemode", "/ws togglegm " + otherPlayer, new GamemodeStatus(wp)); loadItem("teleport", "/ws toggletp " + otherPlayer, new TeleportStatus(wp)); diff --git a/src/main/java/de/butzlabben/world/listener/PlayerListener.java b/src/main/java/de/butzlabben/world/listener/PlayerListener.java index 7f8c29a..b72ca99 100644 --- a/src/main/java/de/butzlabben/world/listener/PlayerListener.java +++ b/src/main/java/de/butzlabben/world/listener/PlayerListener.java @@ -4,6 +4,7 @@ import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.util.PlayerPositions; +import de.butzlabben.world.util.PlayerWrapper; import de.butzlabben.world.wrapper.SystemWorld; import de.butzlabben.world.wrapper.WorldPlayer; import java.util.HashMap; @@ -25,6 +26,7 @@ public class PlayerListener implements Listener { //#17 @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerJoinEvent e) { + PlayerWrapper.updateDatabase(e.getPlayer()); if (PluginConfig.spawnTeleportation()) { Player p = e.getPlayer(); DependenceConfig dc = new DependenceConfig(p); diff --git a/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java b/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java new file mode 100644 index 0000000..427fccb --- /dev/null +++ b/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java @@ -0,0 +1,23 @@ +package de.butzlabben.world.listener; + +import de.butzlabben.world.config.SettingsConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldInitEvent; + +public class WorldInitSkipSpawn implements Listener { + + @EventHandler + public void worldInit(WorldInitEvent e) { + World world = e.getWorld(); + SystemWorld sw = SystemWorld.getSystemWorld(world.getName()); + if(sw == null) + return; + + SettingsConfig.editWorld(world); + e.getWorld().setKeepSpawnInMemory(false); + } + +} diff --git a/src/main/java/de/butzlabben/world/util/MoneyUtil.java b/src/main/java/de/butzlabben/world/util/MoneyUtil.java index 0f23dfc..973c7f9 100644 --- a/src/main/java/de/butzlabben/world/util/MoneyUtil.java +++ b/src/main/java/de/butzlabben/world/util/MoneyUtil.java @@ -39,7 +39,7 @@ public class MoneyUtil { Preconditions.checkNotNull(uuid); Preconditions.checkNotNull(economy); Preconditions.checkArgument(money > 0, "Money must not be negative"); - OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); + OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid); Economy economy = (Economy) MoneyUtil.economy; EconomyResponse response = economy.withdrawPlayer(op, money); if (!response.transactionSuccess()) { @@ -52,7 +52,7 @@ public class MoneyUtil { Preconditions.checkNotNull(uuid); Preconditions.checkNotNull(economy); Preconditions.checkArgument(money > 0, "Money must not be negative"); - OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); + OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid); Economy economy = (Economy) MoneyUtil.economy; return economy.getBalance(op) >= money; } diff --git a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java new file mode 100644 index 0000000..10f1fec --- /dev/null +++ b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java @@ -0,0 +1,98 @@ +package de.butzlabben.world.util; + +import com.google.common.base.Preconditions; +import com.sk89q.worldedit.bukkit.BukkitPlayer; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.util.database.DatabaseProvider; +import de.butzlabben.world.util.database.DatabaseUtil; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; + +public class PlayerWrapper { + + + private static final DatabaseUtil util = DatabaseProvider.instance.util; + + static { + checkTables(); + } + + public static void checkTables() { + if (!util.isConnectionAvailable()) + return; + + String uuidTableName = PluginConfig.getUUIDTableName(); + try { + PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + uuidTableName + + " ( `uuid` VARCHAR(36) NOT NULL , `name` VARCHAR(36) NOT NULL , " + + " PRIMARY KEY (`name`))"); + + util.executeUpdate(ps); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void updateDatabase(Player player) { + if (!util.isConnectionAvailable()) + return; + + Preconditions.checkNotNull(player); + String uuidTableName = PluginConfig.getUUIDTableName(); + + try { + PreparedStatement ps = util.prepareStatement("REPLACE INTO " + uuidTableName + + " (uuid, name) VALUES (?, ?)"); + ps.setString(1, player.getUniqueId().toString()); + ps.setString(2, player.getName()); + + util.executeUpdate(ps); + } catch (SQLException e) { + e.printStackTrace(); + } + + } + + private static UUID getUUID(String name) { + String uuidTableName = PluginConfig.getUUIDTableName(); + + try { + PreparedStatement ps = util.prepareStatement("SELECT * FROM " + uuidTableName + " WHERE name=?"); + + ps.setString(1, name); + ResultSet rs = util.executeQuery(ps); + if (!rs.next()) + return null; + + return UUID.fromString(rs.getString("uuid")); + + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + public static OfflinePlayer getOfflinePlayer(String name) { + Player player = Bukkit.getPlayer(name); + if(player != null) + return Bukkit.getOfflinePlayer(player.getUniqueId()); + + UUID uuid = PlayerWrapper.getUUID(name); + if(uuid != null) + return Bukkit.getOfflinePlayer(uuid); + + return Bukkit.getOfflinePlayer(name); + } + + public static OfflinePlayer getOfflinePlayer(UUID uuid) { + return Bukkit.getOfflinePlayer(uuid); + } + + +} diff --git a/src/main/java/de/butzlabben/world/util/Worldutils.java b/src/main/java/de/butzlabben/world/util/Worldutils.java new file mode 100644 index 0000000..75ceefc --- /dev/null +++ b/src/main/java/de/butzlabben/world/util/Worldutils.java @@ -0,0 +1,18 @@ +package de.butzlabben.world.util; + +import de.butzlabben.world.config.SettingsConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import org.bukkit.Bukkit; +import org.bukkit.World; + +public class Worldutils { + + public static void reloadWorldSettings(){ + for (World w : Bukkit.getWorlds()) { + SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); + if (sw != null && sw.isLoaded()) + SettingsConfig.editWorld(w); + + } + } +} diff --git a/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java b/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java index 25300c9..f5332f0 100644 --- a/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java +++ b/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java @@ -18,6 +18,8 @@ public class AsyncCreatorAdapter implements CreatorAdapter { // Create worlds async to close #16 @Override public void create(WorldCreator creator, SystemWorld sw, Runnable r) { + + TaskManager.IMP.async(() -> { AsyncWorld world; if (Bukkit.getWorld(creator.name()) == null) diff --git a/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java b/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java index 7c14253..ca10a9d 100644 --- a/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java +++ b/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java @@ -8,6 +8,7 @@ import de.butzlabben.world.event.WorldLoadEvent; import de.butzlabben.world.event.WorldUnloadEvent; import de.butzlabben.world.util.PlayerPositions; + import de.butzlabben.world.util.PlayerWrapper; import de.butzlabben.world.util.VersionUtil; import org.apache.commons.io.FileUtils; import org.bukkit.*; @@ -361,7 +362,7 @@ public class SystemWorld { } }, 10L); - OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner()); + OfflinePlayer owner = PlayerWrapper.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner()); DependenceConfig dc = new DependenceConfig(owner); dc.setLastLoaded(); } @@ -422,7 +423,7 @@ public class SystemWorld { p.setGameMode(GameMode.CREATIVE); } - OfflinePlayer owner = Bukkit.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner()); + OfflinePlayer owner = PlayerWrapper.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner()); DependenceConfig dc = new DependenceConfig(owner); dc.setLastLoaded(); } diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java b/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java index 04080e0..7911281 100644 --- a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java +++ b/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java @@ -17,7 +17,14 @@ public class WorldTemplateProvider { private static final WorldTemplateProvider instance = new WorldTemplateProvider(); private final HashMap templates = new HashMap<>(); + private WorldTemplateProvider() { + reload(); + } + + public void reload(){ + templates.clear(); + ConfigurationSection section = PluginConfig.getConfig().getConfigurationSection("worldtemplates.templates"); for (String key : section.getKeys(false)) { String name = section.getString(key + ".name"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 02e0eb5..1761113 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -63,6 +63,9 @@ database: worlds_table_name: worlds_positions # How the table with the saved player positions on the normal worlds should be named players_table_name: player_positions + # how should the uuid cache be stored + players_uuids: players_uuids + # Configure here your mysql connection mysql_settings: host: 127.0.0.1