From e4bc5de0b92c61c473d4678e838a1c9fd539df05 Mon Sep 17 00:00:00 2001 From: Peda Date: Sun, 27 Dec 2020 17:55:09 +0100 Subject: [PATCH 01/13] fixed gradle --- build.gradle | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index ed19fab..e9ec152 100644 --- a/build.gradle +++ b/build.gradle @@ -152,6 +152,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 +181,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 { From 6b38c3c37c7d42ff28b841cefddc06017bfb5515 Mon Sep 17 00:00:00 2001 From: Peda Date: Sun, 27 Dec 2020 19:45:13 +0100 Subject: [PATCH 02/13] added FAWE dependency --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index e9ec152..e183434 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("FAWE"), project.property("Vault")] + + //Comands commands { From 5b69c58bbb9f6238d5f728488512afb83c11b906 Mon Sep 17 00:00:00 2001 From: Peda Date: Sun, 27 Dec 2020 20:00:36 +0100 Subject: [PATCH 03/13] some fiddeling to make use of fawe worldgen --- World System.ipr | 670 ++++++++++++++++-- build.gradle | 2 +- gradle.properties | 4 + .../java/de/butzlabben/world/WorldSystem.java | 7 +- 4 files changed, 635 insertions(+), 48 deletions(-) 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 e183434..0949885 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ spigot { name = project.property("pluginName") authors = [project.property("author")] apiVersion = project.property("apiVersion") - depends = [ project.property("FAWE"), project.property("Vault")] + depends = [ project.property("WorldEdit"), project.property("Vault")] //Comands 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..c500da2 100644 --- a/src/main/java/de/butzlabben/world/WorldSystem.java +++ b/src/main/java/de/butzlabben/world/WorldSystem.java @@ -171,14 +171,15 @@ public class WorldSystem extends JavaPlugin { AutoUpdater.startAsync(); // Choose right creatoradapter for #16 - if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null + /*if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null && Bukkit.getPluginManager().getPlugin("WorldEdit") != null && PluginConfig.loadWorldsASync() - && !is1_13Plus) { + && !is1_13Plus) {*/ + try{ creator = new AsyncCreatorAdapter(); Bukkit.getConsoleSender() .sendMessage(PluginConfig.getPrefix() + "Found FAWE! Worlds now will be created asynchronously"); - } else { + }catch(Exception e) { creator = (c, sw, r) -> { Bukkit.getWorlds().add(c.createWorld()); if (sw != null) From 27b90b7343c9f0f0aff6508cea710b39719263d6 Mon Sep 17 00:00:00 2001 From: Peda Date: Sun, 27 Dec 2020 23:07:01 +0100 Subject: [PATCH 04/13] possible fix for getOfflinePlayer running in timeouts due to mojang --- .../commands/WorldAdministrateCommand.java | 13 +-- .../world/config/DependenceConfig.java | 10 +- .../butzlabben/world/config/PluginConfig.java | 6 ++ .../butzlabben/world/config/WorldConfig.java | 4 +- .../world/gui/PlayerOptionsGUI.java | 2 +- .../de/butzlabben/world/util/MoneyUtil.java | 4 +- .../butzlabben/world/util/PlayerWrapper.java | 97 +++++++++++++++++++ .../butzlabben/world/wrapper/SystemWorld.java | 5 +- 8 files changed, 123 insertions(+), 18 deletions(-) create mode 100644 src/main/java/de/butzlabben/world/util/PlayerWrapper.java 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..c2a32c8 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; @@ -39,7 +40,7 @@ public class WorldAdministrateCommand { } @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])); @@ -152,7 +153,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])); @@ -196,7 +197,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()); @@ -233,7 +234,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()); @@ -270,7 +271,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()); @@ -307,7 +308,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()); diff --git a/src/main/java/de/butzlabben/world/config/DependenceConfig.java b/src/main/java/de/butzlabben/world/config/DependenceConfig.java index c948fa9..9817924 100644 --- a/src/main/java/de/butzlabben/world/config/DependenceConfig.java +++ b/src/main/java/de/butzlabben/world/config/DependenceConfig.java @@ -21,11 +21,11 @@ public class DependenceConfig { 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/WorldConfig.java b/src/main/java/de/butzlabben/world/config/WorldConfig.java index e1fc7f9..42b222e 100644 --- a/src/main/java/de/butzlabben/world/config/WorldConfig.java +++ b/src/main/java/de/butzlabben/world/config/WorldConfig.java @@ -94,7 +94,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 +370,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..3c9fd4e 100644 --- a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java +++ b/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java @@ -22,7 +22,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/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..6ae2555 --- /dev/null +++ b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java @@ -0,0 +1,97 @@ +package de.butzlabben.world.util; + +import com.google.common.base.Preconditions; +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 (`uuid`))"); + + util.executeUpdate(ps); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void updateDatabase(Player player) { + if (!util.isConnectionAvailable()) + return; + + Preconditions.checkNotNull(player); + String playersTableName = PluginConfig.getPlayersTableName(); + + try { + PreparedStatement ps = util.prepareStatement("REPLACE INTO " + playersTableName + + " (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 player=?"); + + 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 PlayerWrapper.getOfflinePlayer(player.getUniqueId()); + + UUID uuid = PlayerWrapper.getUUID(name); + if(uuid != null) + return PlayerWrapper.getOfflinePlayer(uuid); + + return PlayerWrapper.getOfflinePlayer(name); + } + + public static OfflinePlayer getOfflinePlayer(UUID uuid) { + return PlayerWrapper.getOfflinePlayer(uuid); + } + + +} 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(); } From 0e180a0d5020f1c55a2a5764b24bf8671003864f Mon Sep 17 00:00:00 2001 From: Peda Date: Mon, 28 Dec 2020 01:30:59 +0100 Subject: [PATCH 05/13] + added player uuid caching + added extreme paper speedup on sync mode, by disabling the chunk loading --- .../java/de/butzlabben/world/WorldSystem.java | 32 ++-- .../world/command/CommandRegistry.java | 3 +- .../commands/WorldAdministrateCommand.java | 161 +++++++++--------- .../world/config/DependenceConfig.java | 2 +- .../butzlabben/world/config/WorldConfig.java | 1 + .../world/gui/PlayerOptionsGUI.java | 1 + .../world/listener/PlayerListener.java | 2 + .../world/listener/WorldInitSkipSpawn.java | 26 +++ .../butzlabben/world/util/PlayerWrapper.java | 9 +- .../world/wrapper/AsyncCreatorAdapter.java | 2 + src/main/resources/config.yml | 3 + 11 files changed, 134 insertions(+), 108 deletions(-) create mode 100644 src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java diff --git a/src/main/java/de/butzlabben/world/WorldSystem.java b/src/main/java/de/butzlabben/world/WorldSystem.java index c500da2..3f3ad97 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); @@ -159,11 +154,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)); @@ -171,15 +161,15 @@ public class WorldSystem extends JavaPlugin { AutoUpdater.startAsync(); // Choose right creatoradapter for #16 - /*if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null + if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null && Bukkit.getPluginManager().getPlugin("WorldEdit") != null && PluginConfig.loadWorldsASync() - && !is1_13Plus) {*/ - try{ + && !is1_13Plus) { + creator = new AsyncCreatorAdapter(); Bukkit.getConsoleSender() .sendMessage(PluginConfig.getPrefix() + "Found FAWE! Worlds now will be created asynchronously"); - }catch(Exception e) { + } else { creator = (c, sw, r) -> { Bukkit.getWorlds().add(c.createWorld()); if (sw != null) diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java index cc70601..133660f 100644 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ b/src/main/java/de/butzlabben/world/command/CommandRegistry.java @@ -79,7 +79,8 @@ public class CommandRegistry implements CommandExecutor { case "fire": return settings.fireCommand(sender, command, label, args); default: - return false; + //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 c2a32c8..79c23ba 100644 --- a/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java +++ b/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java @@ -28,48 +28,48 @@ public class WorldAdministrateCommand { 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 = 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()); + 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 @@ -140,8 +140,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; @@ -176,11 +179,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) { @@ -196,7 +196,6 @@ public class WorldAdministrateCommand { 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())) { @@ -223,33 +222,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 = 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())); - } + 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 @@ -295,8 +294,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; @@ -324,10 +323,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 9817924..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,7 +18,6 @@ public class DependenceConfig { setConfig(); } - @SuppressWarnings("deprecation") public DependenceConfig(String s) { OfflinePlayer op = null; try { diff --git a/src/main/java/de/butzlabben/world/config/WorldConfig.java b/src/main/java/de/butzlabben/world/config/WorldConfig.java index 42b222e..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; diff --git a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java b/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java index 3c9fd4e..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; 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..6f41ffc --- /dev/null +++ b/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java @@ -0,0 +1,26 @@ +package de.butzlabben.world.listener; + +import de.butzlabben.world.config.WorldConfig; +import de.butzlabben.world.wrapper.WorldPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.world.WorldInitEvent; + +import java.io.File; +import java.util.Objects; + +public class WorldInitSkipSpawn implements Listener { + + @EventHandler + public void worldInit(WorldInitEvent e) { + e.getWorld().setKeepSpawnInMemory(false); + } + +} diff --git a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java index 6ae2555..b9672aa 100644 --- a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java +++ b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java @@ -1,6 +1,7 @@ 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; @@ -80,17 +81,17 @@ public class PlayerWrapper { public static OfflinePlayer getOfflinePlayer(String name) { Player player = Bukkit.getPlayer(name); if(player != null) - return PlayerWrapper.getOfflinePlayer(player.getUniqueId()); + return Bukkit.getOfflinePlayer(player.getUniqueId()); UUID uuid = PlayerWrapper.getUUID(name); if(uuid != null) - return PlayerWrapper.getOfflinePlayer(uuid); + return Bukkit.getOfflinePlayer(uuid); - return PlayerWrapper.getOfflinePlayer(name); + return Bukkit.getOfflinePlayer(name); } public static OfflinePlayer getOfflinePlayer(UUID uuid) { - return PlayerWrapper.getOfflinePlayer(uuid); + return Bukkit.getOfflinePlayer(uuid); } 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/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 From bb589757ee540f497bd0543631a2b695220ce0f9 Mon Sep 17 00:00:00 2001 From: Peda Date: Mon, 28 Dec 2020 01:32:12 +0100 Subject: [PATCH 06/13] removed worldedit from dependency list --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0949885..0868e20 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ spigot { name = project.property("pluginName") authors = [project.property("author")] apiVersion = project.property("apiVersion") - depends = [ project.property("WorldEdit"), project.property("Vault")] + depends = [project.property("Vault")] //Comands From 52b9468b8f7b6443bef0ddbd7800420c4edcf533 Mon Sep 17 00:00:00 2001 From: Peda Date: Mon, 28 Dec 2020 03:33:08 +0100 Subject: [PATCH 07/13] + /wa reload zum Neuladen der Templates --- .../world/command/CommandRegistry.java | 180 +++++++++--------- .../world/wrapper/WorldTemplateProvider.java | 7 + 2 files changed, 100 insertions(+), 87 deletions(-) diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java index 133660f..de3001b 100644 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ b/src/main/java/de/butzlabben/world/command/CommandRegistry.java @@ -1,87 +1,93 @@ -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: - //default command is better than the other one - return ws.mainCommand(sender, command, label, args); - } - } - } -} +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); + case "reload": + if(!sender.isOp()){ + sender.sendMessage("Reloaded Templates!"); + WorldTemplateProvider.getInstance().reload(); + 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/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"); From 07d1e3803f7b6a6deb4350a3b4a291308678773d Mon Sep 17 00:00:00 2001 From: Peda Date: Mon, 28 Dec 2020 16:31:27 +0100 Subject: [PATCH 08/13] Changed some imports --- .../java/de/butzlabben/world/command/CommandRegistry.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java index de3001b..3a2f877 100644 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ b/src/main/java/de/butzlabben/world/command/CommandRegistry.java @@ -3,13 +3,10 @@ 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.wrapper.WorldTemplateProvider; 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 { From e97c827ddcd5f4bb5aeeb8ee7a0490aec1fb4dd7 Mon Sep 17 00:00:00 2001 From: Peda Date: Tue, 29 Dec 2020 11:51:35 +0100 Subject: [PATCH 09/13] fix -> tried to update on wrong table --- src/main/java/de/butzlabben/world/util/PlayerWrapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java index b9672aa..fdbb6be 100644 --- a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java +++ b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java @@ -44,10 +44,10 @@ public class PlayerWrapper { return; Preconditions.checkNotNull(player); - String playersTableName = PluginConfig.getPlayersTableName(); + String uuidTableName = PluginConfig.getUUIDTableName(); try { - PreparedStatement ps = util.prepareStatement("REPLACE INTO " + playersTableName + + PreparedStatement ps = util.prepareStatement("REPLACE INTO " + uuidTableName + " (uuid, name) VALUES (?, ?)"); ps.setString(1, player.getUniqueId().toString()); ps.setString(2, player.getName()); From 42c43c41b64608ec517c05678652d8159b40b7f8 Mon Sep 17 00:00:00 2001 From: Peda Date: Tue, 29 Dec 2020 12:44:04 +0100 Subject: [PATCH 10/13] World gamerules etc. are now only updated on world load --- .../java/de/butzlabben/world/WorldSystem.java | 4 +++- .../world/command/CommandRegistry.java | 4 +++- .../world/config/SettingsConfig.java | 3 +++ .../world/listener/WorldInitSkipSpawn.java | 21 ++++++++----------- .../de/butzlabben/world/util/Worldutils.java | 18 ++++++++++++++++ 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 src/main/java/de/butzlabben/world/util/Worldutils.java diff --git a/src/main/java/de/butzlabben/world/WorldSystem.java b/src/main/java/de/butzlabben/world/WorldSystem.java index 3f3ad97..028dd14 100644 --- a/src/main/java/de/butzlabben/world/WorldSystem.java +++ b/src/main/java/de/butzlabben/world/WorldSystem.java @@ -127,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()); @@ -134,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()) { diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java index 3a2f877..2a9b3e2 100644 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ b/src/main/java/de/butzlabben/world/command/CommandRegistry.java @@ -3,6 +3,7 @@ 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; @@ -77,8 +78,9 @@ public class CommandRegistry implements CommandExecutor { return settings.fireCommand(sender, command, label, args); case "reload": if(!sender.isOp()){ - sender.sendMessage("Reloaded Templates!"); + sender.sendMessage("Reloading Settings!"); WorldTemplateProvider.getInstance().reload(); + Worldutils.reloadWorldSettings(); return true; } default: 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/listener/WorldInitSkipSpawn.java b/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java index 6f41ffc..427fccb 100644 --- a/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java +++ b/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java @@ -1,25 +1,22 @@ package de.butzlabben.world.listener; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.entity.Player; +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.block.BlockBreakEvent; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.world.WorldInitEvent; -import java.io.File; -import java.util.Objects; - 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/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); + + } + } +} From 32f5619fe9adfb041c671df17265988573cf263b Mon Sep 17 00:00:00 2001 From: Peda Date: Tue, 29 Dec 2020 12:50:25 +0100 Subject: [PATCH 11/13] additional sql query fix --- src/main/java/de/butzlabben/world/util/PlayerWrapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java index fdbb6be..10f1fec 100644 --- a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java +++ b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java @@ -31,7 +31,7 @@ public class PlayerWrapper { try { PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + uuidTableName + " ( `uuid` VARCHAR(36) NOT NULL , `name` VARCHAR(36) NOT NULL , " + - " PRIMARY KEY (`uuid`))"); + " PRIMARY KEY (`name`))"); util.executeUpdate(ps); } catch (SQLException e) { @@ -63,7 +63,7 @@ public class PlayerWrapper { String uuidTableName = PluginConfig.getUUIDTableName(); try { - PreparedStatement ps = util.prepareStatement("SELECT * FROM " + uuidTableName + " WHERE player=?"); + PreparedStatement ps = util.prepareStatement("SELECT * FROM " + uuidTableName + " WHERE name=?"); ps.setString(1, name); ResultSet rs = util.executeQuery(ps); From cdda7436db823fa358139b375b9b61f81b499669 Mon Sep 17 00:00:00 2001 From: Peda Date: Tue, 29 Dec 2020 14:55:22 +0100 Subject: [PATCH 12/13] added day night time, storm, rain, sun commands --- .../world/command/CommandRegistry.java | 12 ++++ .../commands/WorldAdministrateCommand.java | 65 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java index 2a9b3e2..afadd97 100644 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ b/src/main/java/de/butzlabben/world/command/CommandRegistry.java @@ -43,6 +43,17 @@ public class CommandRegistry implements CommandExecutor { 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": @@ -66,6 +77,7 @@ public class CommandRegistry implements CommandExecutor { 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); 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 79c23ba..9363b41 100644 --- a/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java +++ b/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java @@ -25,6 +25,71 @@ 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.getNoWorldOwn()); + return false; + } + + if (dc.getWorldname().equals(p.getWorld().getName())) { + p.getWorld().setStorm(storm); + return true; + } + + + p.sendMessage(MessageConfig.getNoMemberOwn()); + 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.getNoWorldOwn()); + return false; + } + + if (dc.getWorldname().equals(p.getWorld().getName())) { + p.getWorld().setTime(ticks); + return true; + } + + + p.sendMessage(MessageConfig.getNoMemberOwn()); + return false; + } + public boolean delMemberCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { Player p = (Player) sender; From 1d454fea00612ca842e560a1e7f5e233f204082f Mon Sep 17 00:00:00 2001 From: Peda Date: Tue, 29 Dec 2020 15:08:48 +0100 Subject: [PATCH 13/13] fixed messages kinda? --- .../world/command/commands/WorldAdministrateCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 9363b41..fbeca3d 100644 --- a/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java +++ b/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java @@ -53,7 +53,7 @@ public class WorldAdministrateCommand { Player p = (Player) sender; DependenceConfig dc = new DependenceConfig(p); if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); + p.sendMessage(MessageConfig.getNotOnWorld()); return false; } @@ -63,7 +63,7 @@ public class WorldAdministrateCommand { } - p.sendMessage(MessageConfig.getNoMemberOwn()); + p.sendMessage(MessageConfig.getNotOnWorld()); return false; } @@ -76,7 +76,7 @@ public class WorldAdministrateCommand { Player p = (Player) sender; DependenceConfig dc = new DependenceConfig(p); if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); + p.sendMessage(MessageConfig.getNotOnWorld()); return false; } @@ -86,7 +86,7 @@ public class WorldAdministrateCommand { } - p.sendMessage(MessageConfig.getNoMemberOwn()); + p.sendMessage(MessageConfig.getNotOnWorld()); return false; }