From 292fb05c1e7bad0c52b0779bafd0c9dcaee3e6f3 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 22 Apr 2018 21:37:56 +0200 Subject: [PATCH] Here we go :D --- WorldSystem/.classpath | 7 + WorldSystem/.idea/misc.xml | 6 + WorldSystem/.idea/modules.xml | 8 + WorldSystem/.idea/workspace.xml | 277 +++++++ WorldSystem/.project | 23 + .../org.eclipse.core.resources.prefs | 8 + .../.settings/org.eclipse.jdt.core.prefs | 11 + WorldSystem/WorldSystem.iml | 29 + WorldSystem/bin/.gitignore | 12 + WorldSystem/src/TODO.txt | 14 + WorldSystem/src/config.yml | 64 ++ WorldSystem/src/custom.yml | 79 ++ WorldSystem/src/de.yml | 79 ++ .../de/butzlabben/event/WorldCreateEvent.java | 28 + .../de/butzlabben/event/WorldDeleteEvent.java | 39 + .../src/de/butzlabben/event/WorldEvent.java | 27 + .../de/butzlabben/event/WorldLoadEvent.java | 37 + .../de/butzlabben/event/WorldResetEvent.java | 38 + .../event/WorldToggleFireEvent.java | 48 ++ .../butzlabben/event/WorldToggleTntEvent.java | 49 ++ .../de/butzlabben/event/WorldUnloadEvent.java | 34 + .../butzlabben/inventory/DependListener.java | 12 + .../inventory/OrcClickListener.java | 9 + .../de/butzlabben/inventory/OrcInventory.java | 134 ++++ .../src/de/butzlabben/inventory/OrcItem.java | 127 ++++ .../inventory/PageClickListener.java | 11 + .../de/butzlabben/world/ConnectionHolder.java | 48 ++ .../src/de/butzlabben/world/GCRunnable.java | 9 + .../butzlabben/world/GameProfileBuilder.java | 144 ++++ .../world/WorldCheckerRunnable.java | 49 ++ .../src/de/butzlabben/world/WorldSystem.java | 196 +++++ .../world/command/WSAddmemberCommand.java | 45 ++ .../butzlabben/world/command/WSCommand.java | 140 ++++ .../world/command/WSDeleteCommand.java | 75 ++ .../world/command/WSDelmemberCommand.java | 53 ++ .../world/command/WSFireCommand.java | 24 + .../world/command/WSGetCommand.java | 34 + .../world/command/WSHomeCommand.java | 51 ++ .../world/command/WSInfoCommand.java | 25 + .../world/command/WSLeaveCommand.java | 40 ++ .../world/command/WSResetCommand.java | 102 +++ .../butzlabben/world/command/WSTPCommand.java | 62 ++ .../world/command/WSTnTCommand.java | 24 + .../world/command/WSToggleBuildCommand.java | 46 ++ .../world/command/WSToggleGMCommand.java | 46 ++ .../world/command/WSToggleTPCommand.java | 46 ++ .../world/config/DependenceConfig.java | 151 ++++ .../src/de/butzlabben/world/config/Entry.java | 56 ++ .../de/butzlabben/world/config/GuiConfig.java | 118 +++ .../world/config/MessageConfig.java | 259 +++++++ .../butzlabben/world/config/PluginConfig.java | 153 ++++ .../world/config/SettingsConfig.java | 151 ++++ .../butzlabben/world/config/WorldConfig.java | 428 +++++++++++ .../butzlabben/world/config/WorldConfig2.java | 286 ++++++++ .../de/butzlabben/world/config/WorldPerm.java | 23 + .../de/butzlabben/world/gui/GuiCommand.java | 28 + .../world/gui/PlayerOptionsGUI.java | 89 +++ .../world/gui/PlayersGUIManager.java | 64 ++ .../butzlabben/world/gui/PlayersPageGUI.java | 125 ++++ .../butzlabben/world/gui/WorldOptionsGUI.java | 101 +++ .../butzlabben/world/gui/WorldSystemGUI.java | 48 ++ .../ComingSoonClickListener.java | 17 + .../CommandExecutorClickListener.java | 26 + .../InventoryOpenClickListener.java | 34 + .../world/gui/playeroption/BuildStatus.java | 20 + .../gui/playeroption/GamemodeStatus.java | 20 + .../gui/playeroption/TeleportStatus.java | 20 + .../world/gui/worldoption/FireStatus.java | 35 + .../world/gui/worldoption/TntStatus.java | 35 + .../world/listener/BlockListener.java | 89 +++ .../world/listener/CommandListener.java | 142 ++++ .../world/listener/PlayerDeathListener.java | 37 + .../world/listener/PlayerLeaveListener.java | 19 + .../butzlabben/world/wrapper/SystemWorld.java | 346 +++++++++ .../butzlabben/world/wrapper/WorldPlayer.java | 233 ++++++ WorldSystem/src/en.yml | 80 +++ WorldSystem/src/gui.yml | 263 +++++++ WorldSystem/src/hu.yml | 80 +++ WorldSystem/src/nl.yml | 80 +++ .../src/org/bstats/bukkit/Metrics.java | 677 ++++++++++++++++++ WorldSystem/src/plugin.yml | 113 +++ WorldSystem/src/settings.yml | 48 ++ 82 files changed, 6963 insertions(+) create mode 100644 WorldSystem/.classpath create mode 100644 WorldSystem/.idea/misc.xml create mode 100644 WorldSystem/.idea/modules.xml create mode 100644 WorldSystem/.idea/workspace.xml create mode 100644 WorldSystem/.project create mode 100644 WorldSystem/.settings/org.eclipse.core.resources.prefs create mode 100644 WorldSystem/.settings/org.eclipse.jdt.core.prefs create mode 100644 WorldSystem/WorldSystem.iml create mode 100644 WorldSystem/bin/.gitignore create mode 100644 WorldSystem/src/TODO.txt create mode 100644 WorldSystem/src/config.yml create mode 100644 WorldSystem/src/custom.yml create mode 100644 WorldSystem/src/de.yml create mode 100644 WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java create mode 100644 WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java create mode 100644 WorldSystem/src/de/butzlabben/event/WorldEvent.java create mode 100644 WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java create mode 100644 WorldSystem/src/de/butzlabben/event/WorldResetEvent.java create mode 100644 WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java create mode 100644 WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java create mode 100644 WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/DependListener.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/OrcClickListener.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/OrcInventory.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/OrcItem.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/PageClickListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/ConnectionHolder.java create mode 100644 WorldSystem/src/de/butzlabben/world/GCRunnable.java create mode 100644 WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java create mode 100644 WorldSystem/src/de/butzlabben/world/WorldCheckerRunnable.java create mode 100644 WorldSystem/src/de/butzlabben/world/WorldSystem.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSAddmemberCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSDeleteCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSDelmemberCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSFireCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSGetCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSHomeCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSInfoCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSLeaveCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSTPCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSTnTCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/DependenceConfig.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/Entry.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/GuiConfig.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/MessageConfig.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/PluginConfig.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/SettingsConfig.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/WorldConfig.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/WorldConfig2.java create mode 100644 WorldSystem/src/de/butzlabben/world/config/WorldPerm.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java create mode 100644 WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java create mode 100644 WorldSystem/src/de/butzlabben/world/listener/BlockListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/listener/CommandListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/listener/PlayerLeaveListener.java create mode 100644 WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java create mode 100644 WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java create mode 100644 WorldSystem/src/en.yml create mode 100644 WorldSystem/src/gui.yml create mode 100644 WorldSystem/src/hu.yml create mode 100644 WorldSystem/src/nl.yml create mode 100644 WorldSystem/src/org/bstats/bukkit/Metrics.java create mode 100644 WorldSystem/src/plugin.yml create mode 100644 WorldSystem/src/settings.yml diff --git a/WorldSystem/.classpath b/WorldSystem/.classpath new file mode 100644 index 0000000..cfda858 --- /dev/null +++ b/WorldSystem/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/WorldSystem/.idea/misc.xml b/WorldSystem/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/WorldSystem/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/WorldSystem/.idea/modules.xml b/WorldSystem/.idea/modules.xml new file mode 100644 index 0000000..a9cb551 --- /dev/null +++ b/WorldSystem/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/WorldSystem/.idea/workspace.xml b/WorldSystem/.idea/workspace.xml new file mode 100644 index 0000000..0f0cb22 --- /dev/null +++ b/WorldSystem/.idea/workspace.xml @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1524410861721 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + WorldSystem + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WorldSystem/.project b/WorldSystem/.project new file mode 100644 index 0000000..8a45e90 --- /dev/null +++ b/WorldSystem/.project @@ -0,0 +1,23 @@ + + + WorldSystem + + + + + + org.eclipse.jdt.core.javabuilder + + + + + net.sourceforge.metrics.builder + + + + + + org.eclipse.jdt.core.javanature + net.sourceforge.metrics.nature + + diff --git a/WorldSystem/.settings/org.eclipse.core.resources.prefs b/WorldSystem/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..325dc0b --- /dev/null +++ b/WorldSystem/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +encoding//src/de/butzlabben/inventory/OrcItem.java=Cp1252 +encoding//src/de/butzlabben/world/WorldSystem.java=UTF-8 +encoding//src/de/butzlabben/world/command/WSCommand.java=UTF-8 +encoding//src/de/butzlabben/world/config/GuiConfig.java=Cp1252 +encoding//src/de/butzlabben/world/config/PluginConfig.java=Cp1252 +encoding//src/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java=Cp1252 +encoding//src/de/butzlabben/world/wrapper/SystemWorld.java=Cp1252 diff --git a/WorldSystem/.settings/org.eclipse.jdt.core.prefs b/WorldSystem/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bb35fa0 --- /dev/null +++ b/WorldSystem/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/WorldSystem/WorldSystem.iml b/WorldSystem/WorldSystem.iml new file mode 100644 index 0000000..e2cf84a --- /dev/null +++ b/WorldSystem/WorldSystem.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WorldSystem/bin/.gitignore b/WorldSystem/bin/.gitignore new file mode 100644 index 0000000..a811ae0 --- /dev/null +++ b/WorldSystem/bin/.gitignore @@ -0,0 +1,12 @@ +/TODO.txt +/config.yml +/custom.yml +/de/ +/de.yml +/en.yml +/gui.yml +/hu.yml +/nl.yml +/org/ +/plugin.yml +/settings.yml diff --git a/WorldSystem/src/TODO.txt b/WorldSystem/src/TODO.txt new file mode 100644 index 0000000..f994ae4 --- /dev/null +++ b/WorldSystem/src/TODO.txt @@ -0,0 +1,14 @@ + +2.0.1: +- WorldPlayer, bsp: changeBuild auf WorldConfig übertragen +- SystemWorld, GUI auch auf neue WorldConfig + +2.0.2: +- Events dokumentieren +- Config dokumentieren +- WorldConfig dokumentieren +- Mehrere TemplateWorlds, WeltGenerator konfigurieren - FLAT, DEFAULT, VOID, ... +- + +2.0.3: +- PlotMe Generator erstellen -> Config gibt Feldgröße an \ No newline at end of file diff --git a/WorldSystem/src/config.yml b/WorldSystem/src/config.yml new file mode 100644 index 0000000..7915924 --- /dev/null +++ b/WorldSystem/src/config.yml @@ -0,0 +1,64 @@ +########################################################################## +### __ __ __ _______ __ ### +### \ \ / / / / / / ___/ / / ### +### \ \ __ / /___ ___/ /___/ / /____ ______/ /______________ ### +### \ \ / \ / / __ \/ _/ / __ /__ / / / / __/ __/ ___/ _ _ / ### +### \ \/ /\ \/ / /_/ / // / /_/ /__/ / /_/ /_ / /_/ ___/ // // / ### +### \__/ \__/\____/_//_/\__,_/____/\__, /___/\__/\___/_//_//_/ ### +### ___/ / ### +### \___/ ### +########################################################################## + +# Path where the worlds will be saved +worldfolder: 'plugins/WorldSystem/Worlds' + +# Name of the template world +worldsource: '' + +# When nobody is on a world time until it get unloaded +unloadingtime: 20 + +# If true nobody can teleport or change their gamemode a WorldSystem world +# Except for players with the permissions: ws.gamemode | ws.tp.* +survival: false + +# Time in seconds until a request expires +request_expires: 20 + +# Name of the languagefile in plugins/WorldSystem/messages/ +language: en + +# Prefix which will be shown before each message +prefix: '&8[&3WorldSystem&8] &6' + +# Options for the LagSystem: +# period_in_seconds - how often will be checked for entities in seconds +# entities_per_world - maximal allowed entities per world +# garbagecollector - how often will be unused ram be cleared +lagsystem: + period_in_seconds: 10 + entities_per_world: 350 + garbagecollector: + use: false + period_in_minutes: 5 + +# Location where you will be teleported when you leave you world +spawn: + gamemode: 2 + spawnpoint: + world: world + x: 0 + y: 20 + z: 0 + yaw: 0 + pitch: 0 + +# Location where you spawn when you join a world +worldspawn: + use: true + spawnpoint: + x: 0 + y: 20 + z: 0 + yaw: 0 + pitch: 0 diff --git a/WorldSystem/src/custom.yml b/WorldSystem/src/custom.yml new file mode 100644 index 0000000..65e4bf6 --- /dev/null +++ b/WorldSystem/src/custom.yml @@ -0,0 +1,79 @@ +nopermission: "" +unknown_error: "" +lagdetection: "%world" +wrong_usage: "" +not_registered: "" + +world: + reseted: "" + still_loaded: "" + not_on: "" + created: "" + already_exists: "" + delete: + own: "" + other: "%player" + does_not_exists: + own: "" + other: "" + setting_up: "" + playerlist: "%players" + +member: + removed: "%player" + added: "%player" + already_added: " + not_added: + own: "" + other: "" + +request: + expired: "" + confirm: "%command" + until_expire: "%time" + already_sent: "" + not_sent: "" + invalid_input: "%input" + +toggle: + gamemode: + enabled: "" + disabled: "" + teleport: + enabled: "" + disabled: "" + build: + enabled: "" + disabled: "" + fire: + enabled: "" + disabled: "" + tnt: + enabled: "" + disabled: "" + +info: + owner: "%data" + id: "%data" + member: "%data" + tnt: "%data" + fire: "%data" + enabled: "" + disabled: "" + +command_help: + list: + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + delete_command: "" \ No newline at end of file diff --git a/WorldSystem/src/de.yml b/WorldSystem/src/de.yml new file mode 100644 index 0000000..4e14162 --- /dev/null +++ b/WorldSystem/src/de.yml @@ -0,0 +1,79 @@ +nopermission: "&cDu besitzt keine Berechtigungen!" +unknown_error: "&cEtwas lief schief..." +lagdetection: "Lags in Welt: &c%world" +wrong_usage: "&c%usage" +not_registered: "&cDieser Spieler war noch nie auf dem Server" + +world: + reseted: "Deine Welt wurde zur\u00fcckgesetzt!" + still_loaded: "&cDeine Welt ist noch geladen!" + not_on: "&cDu bist auf keiner Welt!" + created: "Deine Welt ist nun bereit. Nutze &a/ws home" + already_exists: "&cDu besitzt bereits eine Welt!" + delete: + own: "&cDeine Welt wurde entfernt!" + other: "Die Welt von &c%player&6 wurde entfernt!" + does_not_exists: + own: "&cDu besitzt keine Welt!" + other: "&cDieser Spieler besitzt keine Welt!" + setting_up: "&aBereite Welt vor..." + playerlist: "Spieler in der Welt: %players" + +member: + removed: "Du hast &c%player&6 von deiner Welt entfernt!" + added: "Du hast &c%player&6 zu deiner Welt hinzugef\u00fcgt!" + already_added: "&cDer Spieler ist bereits Mitglied deiner Welt!" + not_added: + own: "&cDer Spieler ist kein Mitglied deiner Welt!" + other: "&cDu bist nicht zu der Welt hinzugef\u00fcgt!" + +request: + expired: "&cDeine Anfrage ist ausgelaufen!" + confirm: "&cBitte bestätige das Zur\u00fccksetzen: %command" + until_expire: "&cDeine Anfrage l\u00e4uft in %time Sekunden aus!" + already_sent: "&cDu hast bereits eine Anfrage gesendet!" + not_sent: "&cDu hast keine Anfrage gesendet!" + invalid_input: "&c%input ist eine ung\u00fcltige Eingabe!" + +toggle: + gamemode: + enabled: "&a%player&6 kann nun seinen Spielmodus \u00e4ndern!" + disabled: "&c%player&6 kann seinen Spielmodus nicht mehr \u00e4ndern!" + teleport: + enabled: "&a%player&6 kann sich nun teleportieren!" + disabled: "&c%player&6 kann sich nicht l\u00e4nger teleportieren!" + build: + enabled: "&a%player&6 kann nun bauen!" + disabled: "&c%player&6 kann nicht mehr bauen!" + fire: + enabled: "&aFeuer aktiviert!" + disabled: "&cFeuer deaktiviert!" + tnt: + enabled: "&aTNT-Schaden aktiviert!" + disabled: "&cTNT-Schaden deaktiviert!" + +info: + owner: "Eigent\u00fcmer: %data" + id: "ID: %data" + member: "Mitglieder: %data" + tnt: "TNT: %data" + fire: "Feuer: %data" + enabled: "&aAn" + disabled: "&cAus" + +command_help: + list: + - "/ws get &8- &7Gibt dir eine Welt" + - "/ws home &8- &7Teleportiert dich auf deine Welt" + - "/ws gui &8- &7\u00f6ffnets das GUI-Menu wenn du der Weltenbesitzer bist" + - "/ws tp &8- &7Teleportiert dich auf eine bestimmte Welt" + - "/ws addmember &8- &7F\u00fcgt jemanden zu deiner Welt hinzu" + - "/ws delmember&8 - &7Entfernt jemanden von deiner Welt" + - "/ws tnt &8- &7Erlaubt/Verbietet TNT auf deiner Welt" + - "/ws fire &8- &7Erlaubt/Verbietet Feuer auf deiner Welt" + - "/ws togglegm &8- &7Erlaubt/Verbietet einem Spieler den Spielmodus zu wechseln" + - "/ws togglebuild &8- &7Erlaubt/Verbietet einem Spieler zu bauen" + - "/ws toggletp &8- &7Erlaubt/Verbietet einem Spieler sich zu teleportieren" + - "/ws info &8- &7Zeigt Informationen \u00fcber die Welt" + - "/ws reset &8- &7Setzt deine Welt zur\u00fcck" + delete_command: "/ws delete &8- &7L\u00f6scht eine Welt" \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java b/WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java new file mode 100644 index 0000000..58192a8 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java @@ -0,0 +1,28 @@ +package de.butzlabben.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; + +public class WorldCreateEvent extends WorldEvent { + + private final Player owner; + + public WorldCreateEvent(Player owner) { + this.owner = owner; + } + + public Player getOwner() { + return owner; + } + + public final static HandlerList handlers = new HandlerList(); + + public final static HandlerList getHandlerList() { + return handlers; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } +} diff --git a/WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java b/WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java new file mode 100644 index 0000000..20dab6e --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java @@ -0,0 +1,39 @@ +package de.butzlabben.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import de.butzlabben.world.wrapper.SystemWorld; + +public class WorldDeleteEvent extends WorldEvent { + + private final SystemWorld world; + private final CommandSender executor; + + public WorldDeleteEvent(CommandSender executor, SystemWorld world) { + this.executor = executor; + this.world = world; + } + + public SystemWorld getWorld() { + return world; + } + + public CommandSender getExecutor() { + return executor; + } + + + + public final static HandlerList handlers = new HandlerList(); + + public final static HandlerList getHandlerList() { + return handlers; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } + +} diff --git a/WorldSystem/src/de/butzlabben/event/WorldEvent.java b/WorldSystem/src/de/butzlabben/event/WorldEvent.java new file mode 100644 index 0000000..b4f110e --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldEvent.java @@ -0,0 +1,27 @@ +package de.butzlabben.event; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; + +public abstract class WorldEvent extends Event implements Cancellable { + + private boolean cancelled; + + public WorldEvent() { + } + + public WorldEvent(boolean cancel) { + setCancelled(cancel); + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + +} diff --git a/WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java b/WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java new file mode 100644 index 0000000..ba2b0f3 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java @@ -0,0 +1,37 @@ +package de.butzlabben.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; + +import de.butzlabben.world.wrapper.SystemWorld; + +public class WorldLoadEvent extends WorldEvent { + + private final Player owner; + private final SystemWorld world; + + public WorldLoadEvent(Player owner, SystemWorld systemWorld) { + this.owner = owner; + this.world = systemWorld; + } + + public SystemWorld getWorld() { + return world; + } + + public Player getOwner() { + return owner; + } + + public final static HandlerList handlers = new HandlerList(); + + public final static HandlerList getHandlerList() { + return handlers; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } + +} diff --git a/WorldSystem/src/de/butzlabben/event/WorldResetEvent.java b/WorldSystem/src/de/butzlabben/event/WorldResetEvent.java new file mode 100644 index 0000000..48b362b --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldResetEvent.java @@ -0,0 +1,38 @@ +package de.butzlabben.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import de.butzlabben.world.wrapper.SystemWorld; + +public class WorldResetEvent extends WorldEvent { + + private final SystemWorld world; + private final CommandSender executor; + + public WorldResetEvent(CommandSender executor, SystemWorld world) { + this.executor = executor; + this.world = world; + } + + public SystemWorld getWorld() { + return world; + } + + public CommandSender getExecutor() { + return executor; + } + + + + public final static HandlerList handlers = new HandlerList(); + + public final static HandlerList getHandlerList() { + return handlers; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } +} diff --git a/WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java b/WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java new file mode 100644 index 0000000..ca5ca60 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java @@ -0,0 +1,48 @@ +package de.butzlabben.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import de.butzlabben.world.wrapper.SystemWorld; + +public class WorldToggleFireEvent extends WorldEvent { + + private final SystemWorld world; + private final CommandSender executor; + private boolean value; + + public WorldToggleFireEvent(CommandSender executor, SystemWorld world, boolean value) { + this.executor = executor; + this.world = world; + this.value = value; + } + + public boolean getValue() { + return value; + } + + public void setValue(boolean val) { + value = val; + } + + public SystemWorld getWorld() { + return world; + } + + public CommandSender getExecutor() { + return executor; + } + + + + public final static HandlerList handlers = new HandlerList(); + + public final static HandlerList getHandlerList() { + return handlers; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } +} diff --git a/WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java b/WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java new file mode 100644 index 0000000..c6cb669 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java @@ -0,0 +1,49 @@ +package de.butzlabben.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import de.butzlabben.world.wrapper.SystemWorld; + +public class WorldToggleTntEvent extends WorldEvent { + + private final SystemWorld world; + private final CommandSender executor; + private boolean value; + + public WorldToggleTntEvent(CommandSender executor, SystemWorld world, boolean value) { + this.executor = executor; + this.world = world; + this.value = value; + } + + public boolean getValue() { + return value; + } + + public void setValue(boolean val) { + value = val; + } + + public SystemWorld getWorld() { + return world; + } + + public CommandSender getExecutor() { + return executor; + } + + + + public final static HandlerList handlers = new HandlerList(); + + public final static HandlerList getHandlerList() { + return handlers; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } + +} diff --git a/WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java b/WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java new file mode 100644 index 0000000..ddd870c --- /dev/null +++ b/WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java @@ -0,0 +1,34 @@ +package de.butzlabben.event; + +import org.bukkit.event.HandlerList; + +import de.butzlabben.world.wrapper.SystemWorld; + +/** + * @author Butzlabben + * @since 2017 + */ +public class WorldUnloadEvent extends WorldEvent { + + private final SystemWorld world; + + public WorldUnloadEvent(SystemWorld world) { + this.world = world; + } + + public SystemWorld getWorld() { + return world; + } + + public final static HandlerList handlers = new HandlerList(); + + public final static HandlerList getHandlerList() { + return handlers; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } + +} diff --git a/WorldSystem/src/de/butzlabben/inventory/DependListener.java b/WorldSystem/src/de/butzlabben/inventory/DependListener.java new file mode 100644 index 0000000..aeef102 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/DependListener.java @@ -0,0 +1,12 @@ +package de.butzlabben.inventory; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import de.butzlabben.world.wrapper.WorldPlayer; + +public interface DependListener { + + public ItemStack getItemStack(Player p, WorldPlayer wp); + +} diff --git a/WorldSystem/src/de/butzlabben/inventory/OrcClickListener.java b/WorldSystem/src/de/butzlabben/inventory/OrcClickListener.java new file mode 100644 index 0000000..ca9fa1a --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/OrcClickListener.java @@ -0,0 +1,9 @@ +package de.butzlabben.inventory; + +import org.bukkit.entity.Player; + +public interface OrcClickListener { + + public void onClick(Player p, OrcInventory inv, OrcItem item); + +} diff --git a/WorldSystem/src/de/butzlabben/inventory/OrcInventory.java b/WorldSystem/src/de/butzlabben/inventory/OrcInventory.java new file mode 100644 index 0000000..cbda9da --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/OrcInventory.java @@ -0,0 +1,134 @@ +package de.butzlabben.inventory; + +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Objects; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.plugin.java.JavaPlugin; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.wrapper.WorldPlayer; + +public abstract class OrcInventory implements Listener { + + private String title; + private int rows; + private InventoryType type; + private final boolean isStatic; + + private HashMap items = new HashMap<>(); + + public OrcInventory(String title, boolean isStatic) { + this.isStatic = isStatic; + Objects.requireNonNull(title, "title cannot be null"); + this.title = title; + Bukkit.getPluginManager().registerEvents(this, JavaPlugin.getPlugin(WorldSystem.class)); + } + + public OrcInventory(String title, int rows, boolean isStatic) { + this(title, isStatic); + if (rows <= 0 || rows > 6) + throw new IllegalArgumentException("rows cannot be smaller than 1 or bigger than 6"); + this.rows = rows; + } + + public OrcInventory(String title, InventoryType type, boolean isStatic) { + this(title, isStatic); + if (type == null || type == InventoryType.CHEST) { + this.type = null; + rows = 3; + } else { + this.type = type; + } + } + + public void addItem(int slot, OrcItem item) { + if (item == null) { + removeItem(slot); + } else { + items.put(slot, item); + } + } + + public void addItem(int row, int col, OrcItem item) { + addItem(row * 9 + col, item); + } + + public void removeItem(int slot) { + items.remove(slot); + } + + public void removeItem(int row, int col) { + removeItem(row * 9 + col); + } + + public Inventory getInventory(Player p) { + return getInventory(p, title); + } + + public Inventory getInventory(Player p, String title) { + if (canOpen(p) == false) + return null; + Inventory inv; + int size; + if (type == null) { + inv = Bukkit.createInventory(null, rows * 9, title); + size = rows * 9; + } else { + inv = Bukkit.createInventory(null, type, title); + size = type.getDefaultSize(); + } + WorldPlayer wp = new WorldPlayer(p); + + for (Entry entry : items.entrySet()) { + if (entry.getKey() >= 0 && entry.getKey() < size) { + inv.setItem(entry.getKey(), entry.getValue().getItemStack(p, wp)); + } else { + System.err.println("[WorldSystem] There is a problem with a configured Item!"); + } + } + + return inv; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + @EventHandler + public void on(InventoryClickEvent e) { + if (e.getClickedInventory() != null && e.getClickedInventory().getTitle().equals(title)) { + e.setCancelled(true); + OrcItem item = items.get(e.getSlot()); + if (item != null) + item.onClick((Player) e.getWhoClicked(), this); + } + } + + @EventHandler + public void on(InventoryCloseEvent e) { + if (e.getInventory() != null && e.getInventory().getTitle().equals(title) && !isStatic) { + unregister(); + } + } + + public void unregister() { + HandlerList.unregisterAll(this); + } + + public abstract boolean canOpen(Player p); + +} diff --git a/WorldSystem/src/de/butzlabben/inventory/OrcItem.java b/WorldSystem/src/de/butzlabben/inventory/OrcItem.java new file mode 100644 index 0000000..6d4ba13 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/OrcItem.java @@ -0,0 +1,127 @@ +package de.butzlabben.inventory; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import de.butzlabben.world.wrapper.WorldPlayer; + +public class OrcItem { + + public static OrcItem enabled, disabled, coming_soon, error = new OrcItem(Material.BARRIER, null, + "§cERROR: Item is wrong configured!", "§cPath in config: see Displayname"); + + private ItemStack is; + private OrcClickListener listener; + private DependListener depend; + + public OrcItem(Material mat, String display, String... lore) { + setItemStack(mat, display, lore); + } + + public OrcItem(ItemStack is) { + setItemStack(is); + } + + public OrcItem(Material mat, String display, List lore) { + setItemStack(mat, display, lore); + } + + public OrcItem(int id, byte data, String display, List lore) { + setItemStack(id, data, display, lore); + } + + @SuppressWarnings("deprecation") + public OrcItem setItemStack(int id, byte data, String display, List lore) { + is = new ItemStack(id, 1, data); + ItemMeta meta = is.getItemMeta(); + if (meta != null) { + meta.setDisplayName(display); + meta.setLore(lore); + is.setItemMeta(meta); + } + return this; + } + + public OrcItem(int id, byte data, String display, String... lore) { + setItemStack(id, data, display, lore); + } + + public OrcItem setItemStack(int id, byte data, String display, String[] lore) { + return setItemStack(id, data, display, Arrays.asList(lore)); + } + + public OrcItem setItemStack(Material mat, String display, List lore) { + is = new ItemStack(mat); + ItemMeta meta = is.getItemMeta(); + meta.setDisplayName(display); + meta.setLore(lore); + is.setItemMeta(meta); + return this; + } + + public ItemStack getItemStack(Player p, WorldPlayer wp) { + if (p != null && depend != null) { + ItemStack is = depend.getItemStack(p, wp); + if (is != null) + return is; + } + return is; + } + + public OrcItem setOnClick(OrcClickListener listener) { + this.listener = listener; + return this; + } + + public OrcItem onClick(Player p, OrcInventory inv) { + if (listener != null) + listener.onClick(p, inv, this); + return this; + } + + public OrcItem setDisplay(String display) { + ItemMeta meta = is.getItemMeta(); + meta.setDisplayName(display); + is.setItemMeta(meta); + return this; + } + + public OrcItem setLore(String... lore) { + ItemMeta meta = is.getItemMeta(); + meta.setLore(Arrays.asList(lore)); + is.setItemMeta(meta); + return this; + } + + public OrcItem removeLore() { + ItemMeta meta = is.getItemMeta(); + meta.setLore(null); + is.setItemMeta(meta); + return this; + } + + public OrcItem setItemStack(ItemStack is) { + Objects.requireNonNull(is, "ItemStack cannot be null"); + this.is = is; + return this; + } + + public OrcItem setItemStack(Material mat, String display, String... lore) { + return setItemStack(mat, display, Arrays.asList(lore)); + } + + public OrcItem setDepend(DependListener listener) { + depend = listener; + return this; + } + + public OrcItem clone() { + return new OrcItem(is); + } +} diff --git a/WorldSystem/src/de/butzlabben/inventory/PageClickListener.java b/WorldSystem/src/de/butzlabben/inventory/PageClickListener.java new file mode 100644 index 0000000..efb1e46 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/PageClickListener.java @@ -0,0 +1,11 @@ +package de.butzlabben.inventory; + +/** + * @author Butzlabben + * @since 20.04.2018 + */ +public interface PageClickListener { + + public int getPageAfter(); + public int getPageBefore(); +} diff --git a/WorldSystem/src/de/butzlabben/world/ConnectionHolder.java b/WorldSystem/src/de/butzlabben/world/ConnectionHolder.java new file mode 100644 index 0000000..9b85219 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/ConnectionHolder.java @@ -0,0 +1,48 @@ +package de.butzlabben.world; + +import java.io.BufferedReader; +import java.io.IOException; +import java.net.URL; +import java.util.Scanner; + +public class ConnectionHolder { + + @SuppressWarnings("resource") + public static int getMaxPlayers() throws Exception{ + BufferedReader reader = null; + String inputLine = ""; + try { + inputLine = new Scanner(new URL("http://seagiants.eu/validation/limit.php").openStream(), "UTF-8").nextLine(); + + } finally { + if (reader != null) + try { + reader.close(); + } catch (IOException e) { + } + } + if (inputLine.equals("")) + return 0; + return Integer.parseInt(inputLine); + } + + @SuppressWarnings("resource") + public static int getMaxPlayersWithLicense(String license) throws Exception{ + BufferedReader reader = null; + String inputLine = ""; + String url = "http://seagiants.eu/validation/limit.php?license=" + license; + try { + inputLine = new Scanner(new URL(url).openStream(), "UTF-8").nextLine(); + + } finally { + if (reader != null) + try { + reader.close(); + } catch (IOException e) { + } + } + if (inputLine.equals("")) + return 0; + return Integer.parseInt(inputLine); + } +} diff --git a/WorldSystem/src/de/butzlabben/world/GCRunnable.java b/WorldSystem/src/de/butzlabben/world/GCRunnable.java new file mode 100644 index 0000000..6d140cd --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/GCRunnable.java @@ -0,0 +1,9 @@ +package de.butzlabben.world; + +public class GCRunnable implements Runnable { + + @Override + public void run() { + new Thread(() -> System.gc()).start(); + } +} diff --git a/WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java b/WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java new file mode 100644 index 0000000..2fa4b9f --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java @@ -0,0 +1,144 @@ +package de.butzlabben.world; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Type; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; +import com.mojang.util.UUIDTypeAdapter; + +/** + * @author Butzlabben + * @since 26.02.2018 + */ +public class GameProfileBuilder { + + private static Gson gson = new GsonBuilder().disableHtmlEscaping() + .registerTypeAdapter(UUID.class, new UUIDTypeAdapter()) + .registerTypeAdapter(GameProfile.class, new GameProfileSerializer()) + .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create(); + private static HashMap cache = new HashMap<>(); + private static long cacheTime = -1L; + + public static GameProfile fetch(UUID uuid) throws IOException { + return fetch(uuid, false); + } + + public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException { + if ((!forceNew) && (cache.containsKey(uuid)) && (((CachedProfile) cache.get(uuid)).isValid())) { + return ((CachedProfile) cache.get(uuid)).profile; + } + HttpURLConnection connection = (HttpURLConnection) new URL( + String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", + new Object[] { UUIDTypeAdapter.fromUUID(uuid) })).openConnection(); + connection.setReadTimeout(5000); + if (connection.getResponseCode() == 200) { + String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine(); + + GameProfile result = (GameProfile) gson.fromJson(json, GameProfile.class); + cache.put(uuid, new CachedProfile(result)); + return result; + } + if ((!forceNew) && (cache.containsKey(uuid))) { + return ((CachedProfile) cache.get(uuid)).profile; + } + JsonObject error = (JsonObject) new JsonParser() + .parse(new BufferedReader(new InputStreamReader(connection.getErrorStream())).readLine()); + throw new IOException(error.get("error").getAsString() + ": " + error.get("errorMessage").getAsString()); + } + + public static GameProfile getProfile(UUID uuid, String name, String skin) { + return getProfile(uuid, name, skin, null); + } + + public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) { + GameProfile profile = new GameProfile(uuid, name); + boolean cape = (capeUrl != null) && (!capeUrl.isEmpty()); + + List args = new ArrayList<>(); + args.add(Long.valueOf(System.currentTimeMillis())); + args.add(UUIDTypeAdapter.fromUUID(uuid)); + args.add(name); + args.add(skinUrl); + if (cape) { + args.add(capeUrl); + } + profile.getProperties().put("textures", + new Property("textures", + Base64Coder.encodeString(String.format( + cape ? "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}" + : "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}", + args.toArray(new Object[args.size()]))))); + return profile; + } + + public static void setCacheTime(long time) { + cacheTime = time; + } + + private static class GameProfileSerializer implements JsonSerializer, JsonDeserializer { + + public GameProfile deserialize(JsonElement json, Type type, JsonDeserializationContext context) + throws JsonParseException { + JsonObject object = (JsonObject) json; + UUID id = object.has("id") ? (UUID) context.deserialize(object.get("id"), UUID.class) : null; + String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null; + GameProfile profile = new GameProfile(id, name); + if (object.has("properties")) { + for (Map.Entry prop : ((PropertyMap) context.deserialize(object.get("properties"), + PropertyMap.class)).entries()) { + profile.getProperties().put((String) prop.getKey(), (Property) prop.getValue()); + } + } + return profile; + } + + public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context) { + JsonObject result = new JsonObject(); + if (profile.getId() != null) { + result.add("id", context.serialize(profile.getId())); + } + if (profile.getName() != null) { + result.addProperty("name", profile.getName()); + } + if (!profile.getProperties().isEmpty()) { + result.add("properties", context.serialize(profile.getProperties())); + } + return result; + } + } + + private static class CachedProfile { + private GameProfile profile; + + public CachedProfile(GameProfile profile) { + this.profile = profile; + } + + public boolean isValid() { + return GameProfileBuilder.cacheTime < 0L; + } + } +} diff --git a/WorldSystem/src/de/butzlabben/world/WorldCheckerRunnable.java b/WorldSystem/src/de/butzlabben/world/WorldCheckerRunnable.java new file mode 100644 index 0000000..9b96efb --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/WorldCheckerRunnable.java @@ -0,0 +1,49 @@ +package de.butzlabben.world; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.SystemWorld; + +public class WorldCheckerRunnable implements Runnable { + + @Override + public void run() { + for (World world : Bukkit.getWorlds()) { + if (SystemWorld.getSystemWorld(world.getName()) == null || !SystemWorld.getSystemWorld(world.getName()).isLoaded()) + continue; + int other = world.getEntities().size() - world.getPlayers().size(); + if (other > PluginConfig.getEntitysPerWorld()) { + String worldname = world.getName(); + for (Entity e : world.getEntities()) { + if (!(e instanceof Player)) { + e.remove(); + } + } + String ownerofWorld = null; + for (OfflinePlayer p : Bukkit.getOfflinePlayers()) { + if (p.getUniqueId().toString() + .equals(worldname.substring(worldname.length() - 36, worldname.length()))) + ownerofWorld = p.getName(); + } + String members = ""; + for (Player p : world.getPlayers()) { + members += p.getName() + " "; + } + for (Player p : Bukkit.getOnlinePlayers()) { + if (!p.hasPermission("ws.lag")) + continue; + p.sendMessage(MessageConfig.getLagDetection().replaceAll("%world", + ownerofWorld + " ( ID: " + world.getName().substring(2, worldname.length() - 37) + " )")); + p.sendMessage(MessageConfig.getPlayerList().replaceAll("%players", members)); + + } + } + } + } +} diff --git a/WorldSystem/src/de/butzlabben/world/WorldSystem.java b/WorldSystem/src/de/butzlabben/world/WorldSystem.java new file mode 100644 index 0000000..493da0a --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/WorldSystem.java @@ -0,0 +1,196 @@ +package de.butzlabben.world; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +import org.bstats.bukkit.Metrics; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.world.command.WSAddmemberCommand; +import de.butzlabben.world.command.WSCommand; +import de.butzlabben.world.command.WSDeleteCommand; +import de.butzlabben.world.command.WSDelmemberCommand; +import de.butzlabben.world.command.WSFireCommand; +import de.butzlabben.world.command.WSGetCommand; +import de.butzlabben.world.command.WSHomeCommand; +import de.butzlabben.world.command.WSInfoCommand; +import de.butzlabben.world.command.WSLeaveCommand; +import de.butzlabben.world.command.WSResetCommand; +import de.butzlabben.world.command.WSTPCommand; +import de.butzlabben.world.command.WSTnTCommand; +import de.butzlabben.world.command.WSToggleBuildCommand; +import de.butzlabben.world.command.WSToggleGMCommand; +import de.butzlabben.world.command.WSToggleTPCommand; +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.gui.GuiCommand; +import de.butzlabben.world.gui.PlayerOptionsGUI; +import de.butzlabben.world.gui.WorldOptionsGUI; +import de.butzlabben.world.gui.WorldSystemGUI; +import de.butzlabben.world.listener.BlockListener; +import de.butzlabben.world.listener.CommandListener; +import de.butzlabben.world.listener.PlayerDeathListener; +import de.butzlabben.world.listener.PlayerLeaveListener; +import de.butzlabben.world.wrapper.SystemWorld; + +/** + * @author Butzlabben + * @author Jubeki + * @since 10.07.2017 + * @version 1.0 + */ +public class WorldSystem extends JavaPlugin { + + private static int maxWorlds = 100; + public static HashMap deathLocations = new HashMap<>(); + + final private String version = this.getDescription().getVersion(); + public static OrcInventory mainGUI; + + @Override + public void onEnable() { + createConfigs(); + + PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new PlayerLeaveListener(), this); + pm.registerEvents(new BlockListener(), this); + pm.registerEvents(new PlayerDeathListener(), this); + pm.registerEvents(new CommandListener(), this); + + new Thread(() -> { + int ch = 0; + if (PluginConfig.getLicenseKey() == null || PluginConfig.getLicenseKey().equals("")) + try { + ch = ConnectionHolder.getMaxPlayers(); + } catch (Exception e) { + } + else + try { + ch = ConnectionHolder.getMaxPlayersWithLicense(PluginConfig.getLicenseKey()); + } catch (Exception e) { + } + if (ch != 0) + maxWorlds = ch; + }).start(); + + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldCheckerRunnable(), 20 * 5, + 20 * PluginConfig.getLagCheckPeriod()); + if (PluginConfig.useGC()) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new GCRunnable(), 20 * 5, + 20 * PluginConfig.getGCPeriod()); + } + + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { + for (World w : Bukkit.getWorlds()) { + SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); + if (sw != null && sw.isLoaded()) + SettingsConfig.editWorld(w); + } + }, 20, 20 * 10); + + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { + @Override + public void run() { + for (World w : Bukkit.getWorlds()) { + SystemWorld.tryUnloadLater(w); + } + } + }, 20 * 60 * 2, 20 * 60 * 2); + + // COMMANDS + getCommand("ws").setExecutor(new WSCommand()); + getCommand("ws get").setExecutor(new WSGetCommand()); + getCommand("ws addmember").setExecutor(new WSAddmemberCommand()); + getCommand("ws delmember").setExecutor(new WSDelmemberCommand()); + getCommand("ws home").setExecutor(new WSHomeCommand()); + getCommand("ws leave").setExecutor(new WSLeaveCommand()); + getCommand("ws fire").setExecutor(new WSFireCommand()); + getCommand("ws info").setExecutor(new WSInfoCommand()); + getCommand("ws tnt").setExecutor(new WSTnTCommand()); + getCommand("ws tp").setExecutor(new WSTPCommand()); + getCommand("ws reset").setExecutor(new WSResetCommand()); + getCommand("ws toggletp").setExecutor(new WSToggleTPCommand()); + getCommand("ws togglegm").setExecutor(new WSToggleGMCommand()); + getCommand("ws togglebuild").setExecutor(new WSToggleBuildCommand()); + getCommand("ws delete").setExecutor(new WSDeleteCommand()); + + getCommand("ws gui").setExecutor(new GuiCommand()); + + mainGUI = new WorldSystemGUI(); + + System.setProperty("bstats.relocatecheck", "false"); + Metrics m = new Metrics(this); + m.getPluginData(); + + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Succesfully enabled WorldSystem v" + version); + } + + @Override + public void onDisable() { + for (World w : Bukkit.getWorlds()) { + SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); + if (sw != null && sw.isLoaded()) { + sw.directUnload(w); + } + } + mainGUI.unregister(); + PlayerOptionsGUI.instance.unregister(); + WorldOptionsGUI.instance.unregister(); + Bukkit.getConsoleSender() + .sendMessage(PluginConfig.getPrefix() + "Succesfully disabled WorldSystem v" + version); + } + + public static int getMaxWorlds() { + return maxWorlds; + } + + public static void createConfigs() { + File dir = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder() + "/worldsources"); + File config = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "config.yml"); + File dconfig = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "dependence.yml"); + File languages = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder() + "/languages"); + File gui = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "gui.yml"); + if (!dir.exists()) { + dir.mkdirs(); + } + if (languages.exists() == false) + languages.mkdirs(); + PluginConfig.checkConfig(config); + MessageConfig.checkConfig(new File(languages, "en.yml")); + MessageConfig.checkConfig(new File(languages, "de.yml")); + MessageConfig.checkConfig(new File(languages, "hu.yml")); + MessageConfig.checkConfig(new File(languages, "nl.yml")); + MessageConfig.checkConfig(new File(languages, PluginConfig.getLanguage() + ".yml")); + if (!dconfig.exists()) { + try { + dconfig.createNewFile(); + } catch (IOException e) { + System.err.println("Wasn't able to create DependenceConfig"); + e.printStackTrace(); + } + new DependenceConfig(); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(config); + SettingsConfig.checkConfig(); + File worlddir = new File(cfg.getString("worldfolder")); + if (!worlddir.exists()) { + worlddir.mkdirs(); + } + GuiConfig.checkConfig(gui); + } + + public static WorldSystem getInstance() { + return JavaPlugin.getPlugin(WorldSystem.class); + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSAddmemberCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSAddmemberCommand.java new file mode 100644 index 0000000..dc01262 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSAddmemberCommand.java @@ -0,0 +1,45 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.WorldConfig2; + +public class WSAddmemberCommand implements CommandExecutor{ + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if(args.length != 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", WorldSystem.getInstance().getCommand("ws addmember").getUsage())); + return true; + + } + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + @SuppressWarnings("deprecation") + OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + if (a == null) { + p.sendMessage(MessageConfig.getNotRegistered()); + return true; + } else if (WorldConfig2.isMember(a, new DependenceConfig(p).getWorldname()) || WorldConfig2.isMember(a, new DependenceConfig(p).getOldWorldname())) { + p.sendMessage(MessageConfig.getAlreadyMember()); + return true; + } + WorldConfig2.addMember(p, a); + p.sendMessage(MessageConfig.getMemberAdded().replaceAll("%player", a.getName())); + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSCommand.java new file mode 100644 index 0000000..9656cbe --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSCommand.java @@ -0,0 +1,140 @@ +package de.butzlabben.world.command; + +import java.util.LinkedList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; + +public class WSCommand implements CommandExecutor, TabCompleter { + + @Override + public List onTabComplete(CommandSender cs, Command cmd, String label, String[] args) { + List list = new LinkedList<>(); + if (args.length == 1) { + list.add("addmember"); + list.add("delete"); + list.add("delmember"); + list.add("fire"); + list.add("get"); + list.add("gui"); + list.add("home"); + list.add("info"); + list.add("leave"); + list.add("reset"); + list.add("tnt"); + list.add("togglegm"); + list.add("toggletp"); + list.add("togglebuild"); + list.add("tp"); + } else if (args.length == 2) { + switch (args[0].toLowerCase()) { + case "reset": + list.add("confirm"); + break; + case "addmember": + case "delete": + case "togglebuild": + case "togglegm": + case "toggletp": + case "tp": + case "delmember": + Bukkit.getOnlinePlayers().forEach((p) -> { + if (cs instanceof Player == false || ((Player) cs).canSee(p)) + list.add(p.getName()); + }); + break; + } + } + return list; + } + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (args.length > 0) { + String subcommand = args[0].toLowerCase(); + if (subcommand.equals("get")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws get").execute(cs, label, args); + } else if (subcommand.equals("addmember")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws addmember").execute(cs, label, args); + } else if (subcommand.equals("delmember")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws delmember").execute(cs, label, args); + } else if (subcommand.equals("fire")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws fire").execute(cs, label, args); + } else if (subcommand.equals("home")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws home").execute(cs, label, args); + } else if (subcommand.equals("leave")) { + WorldSystem.getInstance().getCommand("ws leave").execute(cs, label, args); + } else if (subcommand.equals("info")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws info").execute(cs, label, args); + } else if (subcommand.equals("tnt")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws tnt").execute(cs, label, args); + } else if (subcommand.equals("tp")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws tp").execute(cs, label, args); + } else if (subcommand.equals("reset")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws reset").execute(cs, label, args); + } else if (subcommand.equals("toggletp")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws toggletp").execute(cs, label, args); + } else if (subcommand.equals("togglegm")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws togglegm").execute(cs, label, args); + } else if (subcommand.equals("togglebuild")) { + if (!(cs instanceof Player)) + return true; + WorldSystem.getInstance().getCommand("ws togglebuild").execute(cs, label, args); + } else if (subcommand.equals("delete")) { + WorldSystem.getInstance().getCommand("ws delete").execute(cs, label, args); + } else if (subcommand.equals("gui")) { + WorldSystem.getInstance().getCommand("ws gui").execute(cs, label, args); + } else { + if (cs instanceof Player) { + Player p = (Player) cs; + p.chat("/ws"); + } else if (cs instanceof ConsoleCommandSender) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ws"); + } + } + return true; + } + String prefix = PluginConfig.getPrefix(); + cs.sendMessage( + prefix + "WorldSystem by Butzlabben v" + WorldSystem.getInstance().getDescription().getVersion()); + cs.sendMessage(prefix + "Contributor: Jubeki"); + List cmdHelp = MessageConfig.getCommandHelp(); + cmdHelp.forEach(s -> cs.sendMessage(prefix + s)); + if (cs.hasPermission("ws.delete")) + cs.sendMessage(prefix + "/ws delete §8- §7Will delete a World"); + return true; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSDeleteCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSDeleteCommand.java new file mode 100644 index 0000000..d848b1e --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSDeleteCommand.java @@ -0,0 +1,75 @@ +package de.butzlabben.world.command; + +import java.io.File; + +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import de.butzlabben.event.WorldDeleteEvent; +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.SystemWorld; + +public class WSDeleteCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] args) { + if (args.length < 2) { + cs.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", + WorldSystem.getInstance().getCommand("ws delete").getUsage())); + return true; + } + DependenceConfig dc = new DependenceConfig(args[1]); + if (!dc.hasWorld()) { + cs.sendMessage(MessageConfig.getNoWorldOther()); + return true; + } + String worldname = dc.getWorldname(); + SystemWorld sw = SystemWorld.getSystemWorld(worldname); + WorldDeleteEvent event = new WorldDeleteEvent(cs, sw); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return true; + if (sw != null && sw.isLoaded()) + sw.directUnload(Bukkit.getWorld(worldname)); + Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> { + @SuppressWarnings("deprecation") + OfflinePlayer op = Bukkit.getOfflinePlayer(args[1]); + String uuid = op.getUniqueId().toString(); + File dir = new File(PluginConfig.getWorlddir() + "/" + worldname); + if (dir.exists()) + try { + FileUtils.deleteDirectory(dir); + } catch (Exception e) { + cs.sendMessage(MessageConfig.getUnknownError()); + e.printStackTrace(); + } + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + cfg.set("Dependences." + uuid + ".ID", null); + cfg.set("Dependences." + uuid + ".ActualName", null); + cfg.set("Dependences." + uuid, null); + try { + cfg.save(dconfig); + } catch (Exception e) { + cs.sendMessage(MessageConfig.getUnknownError()); + e.printStackTrace(); + } + cs.sendMessage(MessageConfig.getDeleteWorldOther().replaceAll("%player", op.getName())); + if (op.isOnline()) { + Player p1 = Bukkit.getPlayer(op.getUniqueId()); + p1.sendMessage(MessageConfig.getDeleteWorldOwn()); + } + }, 10); + return true; + + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSDelmemberCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSDelmemberCommand.java new file mode 100644 index 0000000..cf88661 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSDelmemberCommand.java @@ -0,0 +1,53 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.config.WorldConfig2; + +public class WSDelmemberCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if(args.length != 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", WorldSystem.getInstance().getCommand("ws delmember").getUsage())); + return true; + } + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + @SuppressWarnings("deprecation") + OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + if (a == null) { + p.sendMessage(MessageConfig.getNotRegistered()); + return true; + } else if (!WorldConfig2.isMember(a, new DependenceConfig(p).getWorldname()) && !WorldConfig2.isMember(a, new DependenceConfig(p).getWorldname())) { + p.sendMessage(MessageConfig.getNoMemberOwn()); + return true; + } + WorldConfig2.delMember(p, a); + if(a.isOnline()) { + Player t = (Player) a; + if(t.getWorld().getName().equals(new DependenceConfig(p).getWorldname()) || t.getWorld().getName().equals(new DependenceConfig(p).getOldWorldname())) { + t.teleport(PluginConfig.getSpawn()); + t.setGameMode(PluginConfig.getSpawnGamemode()); + } + } + p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName())); + return true; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSFireCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSFireCommand.java new file mode 100644 index 0000000..745cf11 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSFireCommand.java @@ -0,0 +1,24 @@ +package de.butzlabben.world.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.WorldConfig2; + +public class WSFireCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + Player p = (Player) cs; + if(args.length > 1) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", WorldSystem.getInstance().getCommand("ws fire").getUsage())); + return true; + } + WorldConfig2.changeFireDamage(p); + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSGetCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSGetCommand.java new file mode 100644 index 0000000..3260d6c --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSGetCommand.java @@ -0,0 +1,34 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.wrapper.SystemWorld; + +public class WSGetCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] arg3) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + // create New Entry + DependenceConfig dc = new DependenceConfig(p); + if (dc.hasWorld()) { + p.sendMessage(MessageConfig.getWorldAlreadyExists()); + return true; + } + Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> { + if (SystemWorld.create(p)) + p.sendMessage(MessageConfig.getWorldCreated()); + }); + return true; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSHomeCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSHomeCommand.java new file mode 100644 index 0000000..fef31f9 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSHomeCommand.java @@ -0,0 +1,51 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WSHomeCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if (args.length != 1) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", + WorldSystem.getInstance().getCommand("ws home").getUsage())); + return true; + } + String worldname = p.getWorld().getName(); + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + WorldPlayer wp = new WorldPlayer(p, worldname); + if (wp.isOnSystemWorld()) { + SystemWorld.tryUnloadLater(Bukkit.getWorld(worldname)); + } + SystemWorld sw = SystemWorld.getSystemWorld(dc.getWorldname()); + if (sw == null) + sw = SystemWorld.getSystemWorld(dc.getOldWorldname()); + if(sw == null) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + if (sw.isLoaded()) { + sw.teleportToWorldSpawn(p); + } else { + sw.load(p); + } + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSInfoCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSInfoCommand.java new file mode 100644 index 0000000..9dad8e6 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSInfoCommand.java @@ -0,0 +1,25 @@ +package de.butzlabben.world.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.WorldConfig2; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WSInfoCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + Player p = (Player) cs; + WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName()); + if (!wp.isOnSystemWorld()) { + p.sendMessage(MessageConfig.getNotOnWorld()); + return true; + } + WorldConfig2.getInfos(p, p.getWorld().getName()); + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSLeaveCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSLeaveCommand.java new file mode 100644 index 0000000..582cbb6 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSLeaveCommand.java @@ -0,0 +1,40 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WSLeaveCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if (args.length != 1) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", + WorldSystem.getInstance().getCommand("ws leave").getUsage())); + return true; + } + String worldname = p.getWorld().getName(); + WorldPlayer wp = new WorldPlayer(p, worldname); + if (wp.isOnSystemWorld()) { + p.teleport(PluginConfig.getSpawn()); + p.setGameMode(PluginConfig.getSpawnGamemode()); + World w = Bukkit.getWorld(p.getWorld().getName()); + SystemWorld.tryUnloadLater(w); + } else { + p.sendMessage(MessageConfig.getNotOnWorld()); + } + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java new file mode 100644 index 0000000..36fbb0e --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java @@ -0,0 +1,102 @@ +package de.butzlabben.world.command; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.event.WorldResetEvent; +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.SystemWorld; + +public class WSResetCommand implements CommandExecutor { + + private ArrayList toConfirm = new ArrayList<>(); + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + Player p = (Player) cs; + if(args.length > 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", WorldSystem.getInstance().getCommand("ws reset").getUsage())); + return true; + } + DependenceConfig dc = new DependenceConfig(p); + String worldname = dc.getWorldname(); + SystemWorld sw = SystemWorld.getSystemWorld(worldname); + if(sw == null) { + worldname = dc.getOldWorldname(); + sw = SystemWorld.getSystemWorld(worldname); + + } + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + if (args.length > 1) { + if (args[1].equals("confirm")) { + if(sw.isLoaded()) { + p.sendMessage(MessageConfig.getWorldStillLoaded()); + return true; + } + if (!toConfirm.contains(p)) { + p.sendMessage(MessageConfig.getNoRequestSend()); + return true; + } + WorldResetEvent event = new WorldResetEvent(cs, sw); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return true; + File f = new File(PluginConfig.getWorlddir() + "/" + worldname); + File[] files = f.listFiles(); + for (File file : files) { + if (file.getName().equals("worldconfig.yml")) + continue; + FileUtils.deleteQuietly(file); + } + File exampleworld = new File( + "plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName()); + try { + FileUtils.copyDirectory(exampleworld, f); + toConfirm.remove(p); + p.sendMessage(MessageConfig.getWorldReseted()); + } catch (IOException e) { + e.printStackTrace(); + p.sendMessage(MessageConfig.getUnknownError()); + System.err.println("Couldn't reset world of " + p.getName()); + } + } else { + p.sendMessage(MessageConfig.getInvalidInput().replaceAll("input", args[0])); + return true; + } + } else if (args.length == 1) { + if (sw.isLoaded()) { + p.sendMessage(MessageConfig.getWorldStillLoaded()); + return true; + } + if (toConfirm.contains(p)) { + p.sendMessage(MessageConfig.getRequestAlreadySent()); + return true; + } + int time = PluginConfig.getRequestExpire(); + p.sendMessage(MessageConfig.getConfirmRequest().replaceAll("%command", "/ws reset confirm")); + p.sendMessage(MessageConfig.getTimeUntilExpires().replaceAll("%time", String.valueOf(time))); + toConfirm.add(p); + Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> { + if (toConfirm.contains(p)) { + p.sendMessage(MessageConfig.getRequestExpired()); + toConfirm.remove(p); + } + }, time * 20L); + } + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSTPCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSTPCommand.java new file mode 100644 index 0000000..a742059 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSTPCommand.java @@ -0,0 +1,62 @@ +package de.butzlabben.world.command; + +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WSTPCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if (args.length != 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", + WorldSystem.getInstance().getCommand("ws tp").getUsage())); + return true; + } + DependenceConfig dc = new DependenceConfig(args[1]); + String worldname = dc.getWorldNamebyOfflinePlayer(); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOther()); + return true; + } + SystemWorld sw = SystemWorld.getSystemWorld(worldname); + if(sw == null) { + worldname = dc.getOldWorldNamebyOfflinePlayer(); + sw = SystemWorld.getSystemWorld(worldname); + } + WorldPlayer wp1 = new WorldPlayer(p, p.getWorld().getName()); + WorldPlayer wp = new WorldPlayer(p, worldname); + if (p.getWorld().getName().equals(worldname)) { + sw.teleportToWorldSpawn(p); + return true; + } + if (!p.hasPermission("ws.tp.world")) { + if (!wp.isMemberofWorld(worldname) && !wp.isOwnerofWorld()) { + p.sendMessage(MessageConfig.getNoMemberOther()); + return true; + } + } + if (wp1.isOnSystemWorld()) { + World w = p.getWorld(); + SystemWorld.tryUnloadLater(w); + } + if (sw != null) + if (!sw.isLoaded()) { + sw.load(p); + } else { + sw.teleportToWorldSpawn(p); + } + return true; + } +} \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/world/command/WSTnTCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSTnTCommand.java new file mode 100644 index 0000000..090fc1e --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSTnTCommand.java @@ -0,0 +1,24 @@ +package de.butzlabben.world.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.WorldConfig2; + +public class WSTnTCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + Player p = (Player) cs; + if(args.length > 1) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", WorldSystem.getInstance().getCommand("ws tnt").getUsage())); + return true; + } + WorldConfig2.changeTnTDamage(p); + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java new file mode 100644 index 0000000..d119d4e --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java @@ -0,0 +1,46 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WSToggleBuildCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if (args.length != 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", + WorldSystem.getInstance().getCommand("ws togglebuild").getUsage())); + return true; + } + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + @SuppressWarnings("deprecation") + OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + SystemWorld sw = SystemWorld.getSystemWorld(dc.getWorldname()); + WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); + if(sw == null) + wp = new WorldPlayer(a, dc.getOldWorldname()); + if (wp.toggleBuild()) { + p.sendMessage(MessageConfig.getToggleBuildEnabled().replaceAll("%player", a.getName())); + } else { + p.sendMessage(MessageConfig.getToggleBuildDisabled().replaceAll("%player", a.getName())); + } + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java new file mode 100644 index 0000000..1d0299d --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java @@ -0,0 +1,46 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WSToggleGMCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if(args.length != 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", WorldSystem.getInstance().getCommand("ws togglegm").getUsage())); + return true; + } + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + @SuppressWarnings("deprecation") + OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + SystemWorld sw = SystemWorld.getSystemWorld(dc.getWorldname()); + WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); + if(sw == null) + wp = new WorldPlayer(a, dc.getOldWorldname()); + if (wp.toggleGamemode()) { + p.sendMessage(MessageConfig.getToggleGameModeEnabled().replaceAll("%player", a.getName())); + } else { + p.sendMessage(MessageConfig.getToggleGameModeDisabled().replaceAll("%player", a.getName())); + } + return true; + } +} + diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java new file mode 100644 index 0000000..fae4177 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java @@ -0,0 +1,46 @@ +package de.butzlabben.world.command; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WSToggleTPCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { + if (!(cs instanceof Player)) + return true; + Player p = (Player) cs; + if (args.length != 2) { + p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", + WorldSystem.getInstance().getCommand("ws toggletp").getUsage())); + return true; + } + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return true; + } + @SuppressWarnings("deprecation") + OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); + SystemWorld sw = SystemWorld.getSystemWorld(dc.getWorldname()); + WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); + if(sw == null) + wp = new WorldPlayer(a, dc.getOldWorldname()); + if (wp.toggleTeleport()) { + p.sendMessage(MessageConfig.getToggleTeleportEnabled().replaceAll("%player", a.getName())); + } else { + p.sendMessage(MessageConfig.getToggleTeleportDisabled().replaceAll("%player", a.getName())); + } + return true; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/config/DependenceConfig.java b/WorldSystem/src/de/butzlabben/world/config/DependenceConfig.java new file mode 100644 index 0000000..a767cb6 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/DependenceConfig.java @@ -0,0 +1,151 @@ +package de.butzlabben.world.config; + +import java.io.File; +import java.io.IOException; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import de.butzlabben.world.WorldSystem; + +public class DependenceConfig { + + private OfflinePlayer op; + + public DependenceConfig() { + setConfig(); + } + + public DependenceConfig(String s) { + @SuppressWarnings("deprecation") + OfflinePlayer op = Bukkit.getOfflinePlayer(s); + if(op == null) + return; + this.op = op; + } + + + + private void setConfig() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + cfg.set("HighestID", -1); + try { + cfg.save(dconfig); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public DependenceConfig(Player p) { + this.op = p; + refreshName(); + } + + public DependenceConfig(OfflinePlayer p) { + this.op = p; + refreshName(); + } + + public void refreshName() { + if (hasWorld()) { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = this.op.getUniqueId().toString(); + cfg.set("Dependences." + uuid + ".ActualName", op.getName()); + try { + cfg.save(dconfig); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public boolean createNewEntry() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = this.op.getUniqueId().toString(); + int id = cfg.getInt("HighestID"); + id++; + if (Entry.entrys() >= WorldSystem.getMaxWorlds()) + return false; + cfg.set("HighestID", id); + cfg.set("Dependences." + uuid + ".ID", id); + cfg.set("Dependences." + uuid + ".ActualName", op.getName()); + try { + cfg.save(dconfig); + } catch (IOException e) { + e.printStackTrace(); + } + return true; + } + + public boolean hasWorld() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = op.getUniqueId().toString(); + String entry = cfg.getString("Dependences." + uuid + ".ActualName"); + if (entry != null) { + return true; + } + return false; + } + + public String getWorldname() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = op.getUniqueId().toString(); + int id = dcfg.getInt("Dependences." + uuid + ".ID"); + String worldname = "ID" + id + "-" + uuid; + return worldname; + } + + public String getOldWorldname() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = op.getUniqueId().toString(); + int id = dcfg.getInt("Dependences." + uuid + ".ID"); + String worldname = "ID" + id + " " + uuid; + return worldname; + } + + public String getOldWorldNamebyOfflinePlayer() { + String name = ""; + String uuid = op.getUniqueId().toString(); + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + if (cfg.getString("Dependences." + uuid + ".ActualName") == null) { + name = "n"; + } else { + name = "ID" + cfg.getInt("Dependences." + uuid + ".ID") + "-" + uuid; + } + return name; + } + + public String getWorldNamebyOfflinePlayer() { + String name = ""; + String uuid = op.getUniqueId().toString(); + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + if (cfg.getString("Dependences." + uuid + ".ActualName") == null) { + name = "n"; + } else { + name = "ID" + cfg.getInt("Dependences." + uuid + ".ID") + " " + uuid; + } + return name; + } + + public int getHighestID() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); + return dcfg.getInt("HighestID"); + } + + public int getID() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); + return dcfg.getInt("Dependences." + op.getUniqueId().toString() + ".ID"); + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/config/Entry.java b/WorldSystem/src/de/butzlabben/world/config/Entry.java new file mode 100644 index 0000000..1c3fd67 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/Entry.java @@ -0,0 +1,56 @@ +package de.butzlabben.world.config; + +import java.io.File; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.YamlConfiguration; + +public class Entry { + + private OfflinePlayer op; + private String uuid; + private int id; + private String worldname; + + public static int entrys() { + int entrys = 0; + for(OfflinePlayer op : Bukkit.getOfflinePlayers()) { + Entry e = new Entry(op); + if(e.hasWorld()) + ++entrys; + } + return entrys; + } + + protected OfflinePlayer getOfflinePlayer() { + return op; + } + + protected int getID() { + return id; + } + + protected String getWorldname() { + return worldname; + } + + protected boolean hasWorld() { + if(worldname.equals("n")) + return false; + return true; + } + + protected Entry(OfflinePlayer op) { + uuid = op.getUniqueId().toString(); + this.op = op; + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + if (cfg.getString("Dependences." + uuid + ".ActualName") == null) { + worldname = "n"; + } else { + worldname = "ID" + cfg.getInt("Dependences." + uuid + ".ID") + " " + uuid; + id = cfg.getInt("Dependences." + uuid + ".ID"); + } + } +} diff --git a/WorldSystem/src/de/butzlabben/world/config/GuiConfig.java b/WorldSystem/src/de/butzlabben/world/config/GuiConfig.java new file mode 100644 index 0000000..10fcf14 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/GuiConfig.java @@ -0,0 +1,118 @@ +package de.butzlabben.world.config; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.WorldSystem; + +public class GuiConfig { + + private GuiConfig() { + } + + private static File file; + + public static void checkConfig(File f) { + file = f; + if (file.exists() == false) { + try { + InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource("gui.yml"); + Files.copy(in, file.toPath()); + } catch (IOException e) { + System.err.println("Wasn't able to create Config"); + e.printStackTrace(); + } + } + OrcItem.enabled = getEnabled(); + OrcItem.disabled = getDisabled(); + OrcItem.coming_soon = getComingSoon(); + } + + public static YamlConfiguration getConfig() { + return YamlConfiguration.loadConfiguration(file); + } + + public static int getSlot(String path) { + YamlConfiguration cfg = getConfig(); + return (cfg.getInt(path + ".slot.row") - 1) * 9 + cfg.getInt(path + ".slot.col") - 1; + } + + public static int getState(String path) { + YamlConfiguration cfg = getConfig(); + return (cfg.getInt(path + ".state.row") - 1) * 9 + cfg.getInt(path + ".state.col") - 1; + } + + public static boolean isEnabled(String path) { + return getConfig().getBoolean(path + ".enabled", true); + } + + public static int getRows(String path) { + return getConfig().getInt(path + ".rows", 1); + } + + public static String getDisplay(FileConfiguration cfg, String path) { + return ChatColor.translateAlternateColorCodes('&', cfg.getString(path + ".display")); + } + + public static ArrayList getLore(FileConfiguration cfg, String path) { + List list = cfg.getStringList(path + ".lore"); + ArrayList colored = new ArrayList<>(list.size()); + for (String s : list) { + colored.add(ChatColor.translateAlternateColorCodes('&', s)); + } + return colored; + } + + public static int getId(FileConfiguration cfg, String path) { + return cfg.getInt(path + ".material"); + } + + public static byte getData(FileConfiguration cfg, String path) { + return (byte) cfg.getInt(path + ".data"); + } + + public static Material getMaterial(FileConfiguration cfg, String path) { + try { + return Material.valueOf(cfg.getString(path + ".material").toUpperCase()); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public static OrcItem getItem(String path) { + YamlConfiguration cfg = getConfig(); + try { + return new OrcItem(getId(cfg, path), getData(cfg, path), getDisplay(cfg, path), getLore(cfg, path)); + } catch (Exception e) { + } + try { + return new OrcItem(getMaterial(cfg, path), getDisplay(cfg, path), getLore(cfg, path)); + } catch (Exception e) { + } + return OrcItem.error.clone().setDisplay("§c" + path); + } + + public static OrcItem getEnabled() { + return getItem("options.enabled"); + } + + public static OrcItem getDisabled() { + return getItem("options.disabled"); + } + + public static OrcItem getComingSoon() { + return getItem("options.coming_soon"); + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/config/MessageConfig.java b/WorldSystem/src/de/butzlabben/world/config/MessageConfig.java new file mode 100644 index 0000000..28d1fdf --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/MessageConfig.java @@ -0,0 +1,259 @@ +package de.butzlabben.world.config; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import de.butzlabben.world.WorldSystem; +import net.md_5.bungee.api.ChatColor; + +public class MessageConfig { + + private MessageConfig() { + } + + private static List defaultCmdHelp = new ArrayList<>(20); + + { + defaultCmdHelp.add("/ws get §8- §7Will give you a World"); + defaultCmdHelp.add("/ws home §8- §7Teleports you on your World"); + defaultCmdHelp.add("/ws tp §8- §7Teleports you on a specific World"); + defaultCmdHelp.add("/ws addmember §8- §7Adds a player to your World"); + defaultCmdHelp.add("/ws delmember§8 - §7Removes a player from your World"); + defaultCmdHelp.add("/ws tnt §8- §7Allows/Denys TNT on your World"); + defaultCmdHelp.add("/ws fire §8- §7Allows/Denys Fire on your World"); + defaultCmdHelp.add("/ws togglechgm §8- §7Allows/Denys a player changing gamemode"); + defaultCmdHelp.add("/ws togglebuild §8- §7Allows/Denys a player building"); + defaultCmdHelp.add("/ws toggletp §8- §7Allows/Denys a player teleporting"); + defaultCmdHelp.add("/ws info §8- §7Shows information about the World"); + defaultCmdHelp.add("/ws reset §8- §7Will reset your World"); + } + + private static File file; + // private static HashMap languages = new HashMap<>(); + + public static void checkConfig(File f) { + file = f; + // languages.put(f.getName().split(".yml")[0], f); + if (file.exists() == false) { + try { + InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource(f.getName()); + ; + if (in == null) { + in = JavaPlugin.getPlugin(WorldSystem.class).getResource("custom.yml"); + } + Files.copy(in, file.toPath()); + } catch (IOException e) { + System.err.println("Wasn't able to create Config"); + e.printStackTrace(); + } + } + } + + private static YamlConfiguration getConfig() { + return YamlConfiguration.loadConfiguration(file); + } + + private static String getRawMessage(String path, String alt) { + return ChatColor.translateAlternateColorCodes('&', getConfig().getString(path, alt)); + } + + private static String getMessage(String path, String alt) { + return PluginConfig.getPrefix() + getRawMessage(path, alt); + } + + public static String getNoPermission() { + return getMessage("nopermission", "§cYou don't have permissions!"); + } + + public static String getSettingUpWorld() { + return getMessage("world.setting_up", "§aSetting up world..."); + } + + public static String getPlayerList() { + return getMessage("world.playerlist", "Player in this world: %player"); + } + + public static String getLagDetection() { + return getMessage("lagdetection", "Lagdetection in world from: §c%world"); + } + + public static String getWrongUsage() { + return getMessage("wrong_usage", "§c%usage"); + } + + public static String getNoWorldOwn() { + return getMessage("world.does_not_exists.own", "§cYou don't have a world!"); + } + + public static String getNoWorldOther() { + return getMessage("world.does_not_exists.other", "§cThis player doesn't has a world!"); + } + + public static String getNotRegistered() { + return getMessage("not_registered", "§cThis player hasn't joined yet!"); + } + + public static String getAlreadyMember() { + return getMessage("member.already_added", "§cThis player is already a member!"); + } + + public static String getMemberAdded() { + return getMessage("member.added", "You have added &c%player&6 to your World!"); + } + + public static String getUnknownError() { + return getMessage("unknown_error", "§cSomething went wrong..."); + } + + public static String getDeleteWorldOwn() { + return getMessage("world.delete.own", "§cYour world was deleted!"); + } + + public static String getDeleteWorldOther() { + return getMessage("world.delete.other", "You deleted the world of §c%player§6!"); + } + + public static String getNoMemberOwn() { + return getMessage("member.not_added.own", "§cThis player isn't a member!"); + } + + public static String getMemberRemoved() { + return getMessage("member.removed", "You removed §c%player§6 from your world!"); + } + + public static String getWorldAlreadyExists() { + return getMessage("world.already_exists", "§cYou already have a world!"); + } + + public static String getWorldCreated() { + return getMessage("world.created", "Your world is now ready. Get there with §a/ws home"); + } + + public static String getNotOnWorld() { + return getMessage("world.not_on", "§cYou are not on a world!"); + } + + public static String getWorldStillLoaded() { + return getMessage("world.still_loaded", "§cYour world is still loaded!"); + } + + public static String getNoRequestSend() { + return getMessage("request.not_sent", "§cYou didn't send a request!"); + } + + public static String getWorldReseted() { + return getMessage("world.reseted", "Your world was reseted!"); + } + + public static String getInvalidInput() { + return getMessage("request.invalid_input", "§c%input is not a valid input!"); + } + + public static String getRequestAlreadySent() { + return getMessage("request.already_sent", "§cYou already sent a request!"); + } + + public static String getRequestExpired() { + return getMessage("request.expired", "§cYou request is expired!"); + } + + public static String getTimeUntilExpires() { + return getMessage("request.until_expire", "§cYour request expires in %time seconds!"); + } + + public static String getConfirmRequest() { + return getMessage("request.confirm", "§cPlease confirm reset of your world: %command"); + } + + public static String getNoMemberOther() { + return getMessage("member.not_added.other", "§cYou are not added to this world!"); + } + + public static String getInfoOwner() { + return getMessage("info.owner", "Owner: %data"); + } + + public static String getInfoId() { + return getMessage("info.id", "ID: %data"); + } + + public static String getInfoMember() { + return getMessage("info.member", "Member: %data"); + } + + public static String getInfoTnt() { + return getMessage("info.tnt", "TNT: %data"); + } + + public static String getInfoFire() { + return getMessage("info.fire", "Fire: %data"); + } + + public static String getInfoEnabled() { + return getRawMessage("info.enabled", "§aOn"); + } + + public static String getInfoDisabled() { + return getRawMessage("info.disabled", "§cOff"); + } + + public static String getToggleGameModeEnabled() { + return getMessage("toggle.gamemode.enabled", "§a%player§6 can now change his gamemode!"); + } + + public static String getToggleGameModeDisabled() { + return getMessage("toggle.gamemode.disabled", "§c%player§6 can no longer change his gamemode!"); + } + + public static String getToggleTeleportEnabled() { + return getMessage("toggle.teleport.enabled", "§a%player§6 can now teleport!"); + } + + public static String getToggleTeleportDisabled() { + return getMessage("toggle.teleport.disabled", "§c%player§6 can no longer teleport!"); + } + + public static String getToggleBuildEnabled() { + return getMessage("toggle.build.enabled", "§a%player§6 can now build!"); + } + + public static String getToggleBuildDisabled() { + return getMessage("toggle.build.disabled", "§c%player§6 can no longer build!"); + } + + public static String getToggleFireEnabled() { + return getMessage("toggle.fire.enabled", "§aYou activated fire!"); + } + + public static String getToggleFireDisabled() { + return getMessage("toggle.fire.disabled", "§cYou deactivated fire!"); + } + + public static String getToggleTntEnabled() { + return getMessage("toggle.tnt.enabled", "§aYou activated TNT-Damage!"); + } + + public static String getToggleTntDisabled() { + return getMessage("toggle.tnt.disabled", "§cYou deactivated TNT-Damage!"); + } + + public static String getDeleteCommandHelp() { + return getMessage("command_help.delete", "/ws delete §8- §7Will delete a World"); + } + + public static List getCommandHelp() { + List list = getConfig().getStringList("command_help.list"); + if (list == null) + list = defaultCmdHelp; + + return list;list = list.stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()); + } +} diff --git a/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java b/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java new file mode 100644 index 0000000..00aa65a --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java @@ -0,0 +1,153 @@ +package de.butzlabben.world.config; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import de.butzlabben.world.WorldSystem; +import net.md_5.bungee.api.ChatColor; + +public class PluginConfig { + + private PluginConfig() { + } + + private static File file; + + public static void checkConfig(File f) { + file = f; + if (file.exists()) { + YamlConfiguration cfg = getConfig(); + if (false == (cfg.isString("worldfolder") && cfg.isString("worldsource") && cfg.isInt("unloadingtime") + && cfg.isBoolean("survival") && cfg.isString("language") && cfg.isString("prefix") + && cfg.isInt("request_expires") && + + cfg.isInt("lagsystem.period_in_seconds") && cfg.isInt("lagsystem.entities_per_world") + && cfg.isBoolean("lagsystem.garbagecollector.use") + && cfg.isInt("lagsystem.garbagecollector.period_in_minutes") && + + cfg.isString("spawn.spawnpoint.world") && cfg.isInt("spawn.gamemode") + && (cfg.isDouble("spawn.spawnpoint.x") || cfg.isInt("spawn.spawnpoint.x")) + && (cfg.isDouble("spawn.spawnpoint.y") || cfg.isInt("spawn.spawnpoint.y")) + && (cfg.isDouble("spawn.spawnpoint.z") || cfg.isInt("spawn.spawnpoint.z")) + && (cfg.isDouble("spawn.spawnpoint.yaw") || cfg.isInt("spawn.spawnpoint.yaw")) + && (cfg.isDouble("spawn.spawnpoint.pitch") || cfg.isInt("spawn.spawnpoint.pitch")) && + + cfg.isBoolean("worldspawn.use") + && (cfg.isDouble("worldspawn.spawnpoint.x") || cfg.isInt("worldspawn.spawnpoint.x")) + && (cfg.isDouble("worldspawn.spawnpoint.y") || cfg.isInt("worldspawn.spawnpoint.y")) + && (cfg.isDouble("worldspawn.spawnpoint.z") || cfg.isInt("worldspawn.spawnpoint.z")) + && (cfg.isDouble("worldspawn.spawnpoint.yaw") || cfg.isInt("worldspawn.spawnpoint.yaw")) + && (cfg.isDouble("worldspawn.spawnpoint.pitch") || cfg.isInt("worldspawn.spawnpoint.pitch")))) { + try { + Files.copy(file.toPath(), + new File(file.getParentFile(), "config-broken-" + + new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss").format(new Date()) + ".yml").toPath(), + StandardCopyOption.REPLACE_EXISTING); + Files.delete(file.toPath()); + System.err.println("[WorldSystem] Config is broken, creating a new one!"); + checkConfig(f); + } catch (IOException e) { + e.printStackTrace(); + } + } + } else { + try { + InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource("config.yml"); + Files.copy(in, file.toPath()); + } catch (IOException e) { + System.err.println("Wasn't able to create Config"); + e.printStackTrace(); + } + } + } + + private static YamlConfiguration getConfig() { + return YamlConfiguration.loadConfiguration(file); + } + + public static String getLicenseKey() { + return getConfig().getString("license"); + } + + public static int getGCPeriod() { + return getConfig().getInt("lagsystem.garbagecollector.period_in_minutes", 5); + } + + public static boolean useGC() { + return getConfig().getBoolean("lagsystem.garbagecollector.use", false); + } + + public static int getEntitysPerWorld() { + return getConfig().getInt("lagsystem.entities_per_world", 350); + } + + public static int getLagCheckPeriod() { + return getConfig().getInt("lagsystem.period_in_seconds", 10); + } + + public static boolean useWorldSpawn() { + return getConfig().getBoolean("worldspawn.use", true); + } + + public static boolean isSurvival() { + return getConfig().getBoolean("survival", false); + } + + public static int getUnloadingTime() { + return getConfig().getInt("unloadingtime", 20); + } + + private final static GameMode[] gamemodes = new GameMode[] { GameMode.SURVIVAL, GameMode.CREATIVE, + GameMode.ADVENTURE, GameMode.SPECTATOR }; + + public static GameMode getSpawnGamemode() { + return gamemodes[getConfig().getInt("spawn.gamemode", 2)]; + } + + public static String getWorlddir() { + return getConfig().getString("worldfolder", "plugins/WorldSystem/Worlds") + "/"; + } + + public static String getExampleWorldName() { + return getConfig().getString("worldsource", ""); + } + + public static String getLanguage() { + return getConfig().getString("language", "en"); + } + + public static String getPrefix() { + return ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix", "§8[§3WorldSystem§8] §6")); + } + + public static Location getWorldSpawn(World w) { + return getLocation(getConfig(), "worldspawn.spawnpoint", w); + } + + public static Location getSpawn() { + YamlConfiguration cfg = getConfig(); + return getLocation(cfg, "spawn.spawnpoint", Bukkit.getWorld(cfg.getString("spawn.spawnpoint.world", "world"))); + } + + public static int getRequestExpire() { + return getConfig().getInt("request_expires", 20); + } + + private static Location getLocation(YamlConfiguration cfg, String path, World world) { + return new Location(world, cfg.getDouble(path + ".x", 0), cfg.getDouble(path + ".y", 20), + cfg.getDouble(path + ".z", 0), (float) cfg.getDouble(path + ".yaw", 0), + (float) cfg.getDouble(path + ".pitch", 0)); + } +} diff --git a/WorldSystem/src/de/butzlabben/world/config/SettingsConfig.java b/WorldSystem/src/de/butzlabben/world/config/SettingsConfig.java new file mode 100644 index 0000000..4740b0e --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/SettingsConfig.java @@ -0,0 +1,151 @@ +package de.butzlabben.world.config; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.wrapper.SystemWorld; + +public class SettingsConfig { + + private static File file; + + public static void editWorld(World w) { + YamlConfiguration cfg = getConfig(); + + SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); + + boolean shouldChange = cfg.getBoolean("worldborder.should_change", false); + if (shouldChange) { + double size = cfg.getDouble("worldborder.normal", 1000); + if (sw != null && sw.isLoaded()) { + String worldname = w.getName(); + UUID uuid = UUID.fromString(worldname.substring(worldname.length() - 36)); + Player p = Bukkit.getPlayer(uuid); + if (p.isOnline()) { + if (p.hasPermission("ws.large")) { + size = cfg.getDouble("worldborder.large", 5000); + } else if (p.hasPermission("ws.big")) + size = cfg.getDouble("worldborder.big", 2000); + } + } + + w.getWorldBorder().setSize(size); + + if (cfg.getBoolean("worldborder.center.as_spawn", true)) { + if (PluginConfig.useWorldSpawn()) { + w.getWorldBorder().setCenter(PluginConfig.getWorldSpawn(w)); + } else { + w.getWorldBorder().setCenter(w.getSpawnLocation()); + } + } else { + Location loc = new Location(w, cfg.getDouble("worldborder.center.x", 0), + cfg.getDouble("worldborder.center.y", 20), cfg.getDouble("worldborder.center.z", 0)); + w.getWorldBorder().setCenter(loc); + } + } + + if (w.isGameRule("announceAdvancements")) + w.setGameRuleValue("announceAdvancements", cfg.getString("announceAdvancements")); + + if (w.isGameRule("commandBlockOutput")) + w.setGameRuleValue("commandBlockOutput", cfg.getString("commandBlockOutput")); + + if (w.isGameRule("disableElytraMovementCheck")) + w.setGameRuleValue("disableElytraMovementCheck", cfg.getString("disableElytraMovementCheck")); + + if (w.isGameRule("doDaylightCycle")) + w.setGameRuleValue("doDaylightCycle", cfg.getString("doDaylightCycle")); + + if (w.isGameRule("doEntityDrops")) + w.setGameRuleValue("doEntityDrops", cfg.getString("doEntityDrops")); + + if (w.isGameRule("doFireTick")) + w.setGameRuleValue("doFireTick", cfg.getString("doFireTick")); + + if (w.isGameRule("doLimitedCrafting")) + w.setGameRuleValue("doLimitedCrafting", cfg.getString("doLimitedCrafting")); + + if (w.isGameRule("doMobLoot")) + w.setGameRuleValue("doMobLoot", cfg.getString("doMobLoot")); + + if (w.isGameRule("doMobSpawning")) + w.setGameRuleValue("doMobSpawning", cfg.getString("doMobSpawning")); + + if (w.isGameRule("doTileDrops")) + w.setGameRuleValue("doTileDrops", cfg.getString("doTileDrops")); + + if (w.isGameRule("doWeatherCycle")) + w.setGameRuleValue("doWeatherCycle", cfg.getString("doWeatherCycle")); + + if (w.isGameRule("gameLoopFunction")) + w.setGameRuleValue("gameLoopFunction", cfg.getString("gameLoopFunction")); + + if (w.isGameRule("keepInventory")) + w.setGameRuleValue("keepInventory", cfg.getString("keepInventory")); + + if (w.isGameRule("logAdminCommands")) + w.setGameRuleValue("logAdminCommands", cfg.getString("logAdminCommands")); + + if (w.isGameRule("maxCommandChainLength")) + w.setGameRuleValue("maxCommandChainLength", cfg.getString("maxCommandChainLength")); + + if (w.isGameRule("maxEntityCramming")) + w.setGameRuleValue("maxEntityCramming", cfg.getString("maxEntityCramming")); + + if (w.isGameRule("mobGriefing")) + w.setGameRuleValue("mobGriefing", cfg.getString("mobGriefing")); + + if (w.isGameRule("naturalRegeneration")) + w.setGameRuleValue("naturalRegeneration", cfg.getString("naturalRegeneration")); + + if (w.isGameRule("randomTickSpeed")) + w.setGameRuleValue("randomTickSpeed", cfg.getString("randomTickSpeed")); + + if (w.isGameRule("reducedDebugInfo")) + w.setGameRuleValue("reducedDebugInfo", cfg.getString("reducedDebugInfo")); + + if (w.isGameRule("sendCommandFeedback")) + w.setGameRuleValue("sendCommandFeedback", cfg.getString("sendCommandFeedback")); + + if (w.isGameRule("showDeathMessages")) + w.setGameRuleValue("showDeathMessages", cfg.getString("showDeathMessages")); + + if (w.isGameRule("spawnRadius")) + w.setGameRuleValue("spawnRadius", cfg.getString("spawnRadius")); + + if (w.isGameRule("spectatorsGenerateChunks")) + w.setGameRuleValue("spectatorsGenerateChunks", cfg.getString("spectatorsGenerateChunks")); + } + + private static YamlConfiguration getConfig() { + return YamlConfiguration.loadConfiguration(file); + } + + public static void checkConfig() { + File file = new File(WorldSystem.getInstance().getDataFolder(), "settings.yml"); + SettingsConfig.file = file; + if (!file.exists()) { + try { + InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource("settings.yml"); + Files.copy(in, file.toPath()); + } catch (IOException e) { + System.err.println("Wasn't able to create Config"); + e.printStackTrace(); + } + } + } + + private SettingsConfig() { + } +} diff --git a/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java new file mode 100644 index 0000000..a78ff2d --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java @@ -0,0 +1,428 @@ +package de.butzlabben.world.config; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + +import com.google.common.collect.Sets; + +public class WorldConfig { + + private static File getWorldFile(String worldname) { + File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!worldconfig.exists()) { + worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + if (!worldconfig.exists()) { + worldconfig = new File(worldname + "/worldconfig.yml"); + } + return worldconfig; + } + + private static HashMap instances = new HashMap<>(); + + /** + * Gets the worldconfig for a specific worldname or creates a new one of no + * exists + * + * @param worldname + * of the world + * @return WorldConfig of the world + */ + public static WorldConfig getWorldConfig(String worldname) { + if (!instances.containsKey(worldname)) + instances.put(worldname, new WorldConfig(worldname)); + return instances.get(worldname).load(); + } + + private final UUID owner; + private final int id; + + private final HashMap> permissions = new HashMap<>(); + + private String ownerName; + private boolean fire, tnt; + + private WorldConfig(String worldname) { + File file = getWorldFile(worldname); + if (file.exists() == false) + throw new IllegalArgumentException("WorldConfig doesn't exist"); + owner = UUID.fromString(worldname.substring(worldname.length() - 36)); + id = Integer.parseInt(worldname.split("-")[0].substring(2)); + } + + /** + * Add a permission to a player of this world + * + * @param player + * who is edited + * @param perm + * which permission will be added + * @return true if the permission was added, false if he already has the + * permission + */ + public boolean addPermission(UUID player, WorldPerm perm) { + if (owner.equals(player)) + throw new IllegalArgumentException("Permissions of the owner cannot change"); + HashSet perms = permissions.get(player); + if (perms == null) { + perms = new HashSet<>(); + permissions.put(player, perms); + } + return perms.add(perm); + } + + /** + * Remove a permission from a player of this world + * + * @param player + * who is edited + * @param perm + * which permission will be removed + * @return true if the permission was removed, false if he doesn't have the + * permission + */ + public boolean removePermission(UUID player, WorldPerm perm) { + if (owner.equals(player)) + throw new IllegalArgumentException("Permissions of the owner cannot change"); + HashSet perms = permissions.get(player); + if (perms == null) { + return false; + } + return perms.remove(perm); + } + + /** + * Remove all permissions from a player of this world + * + * @param player + * who is edited + * @return true if a permission was removed false otherwise + */ + public boolean removeAllPermissions(UUID player) { + if (owner.equals(player)) + throw new IllegalArgumentException("Permissions of the owner cannot change"); + HashSet perms = permissions.remove(player); + return perms != null && perms.size() != 0; + } + + /** + * Add all permissions to a player of this world + * + * @param player + * who is edited + * @return true if the permissions of the player changed, false otherwiste + */ + public boolean addAllPermissions(UUID player) { + if (owner.equals(player)) + throw new IllegalArgumentException("Permissions of the owner cannot change"); + HashSet perms = permissions.get(player); + if (perms == null) { + perms = new HashSet<>(); + permissions.put(player, perms); + } + return perms.addAll(Sets.newHashSet(WorldPerm.values())); + } + + /** + * Checks the permission of a player + * + * @param player + * who gets their permission checked + * @param perm + * to check + * @return true if the player has the permission, false otherwise + */ + public boolean hasPermission(UUID player, WorldPerm perm) { + if (owner.equals(player)) + return true; + HashSet perms = permissions.get(player); + return perms != null && perms.contains(perm); + } + + /** + * Get all permissions of a player + * + * @param player + * from who to get the permissions + * @return all permissions for this player + */ + public HashSet getPermissions(UUID player) { + if (owner == player) { + return Sets.newHashSet(WorldPerm.values()); + } + HashSet perms = permissions.get(player); + if (perms == null) { + return Sets.newHashSet(); + } + return Sets.newHashSet(perms); + } + + /** + * Adds a player to the world + * + * @param player + * who gets added + * @return true if the player was no member + */ + public boolean addMember(UUID player) { + return addPermission(player, WorldPerm.MEMBER); + } + + /** + * Try to add a player to the world + * + * @param player + * who's permission gets checked + * @param target + * to add to the world + * @return true if the player was successfully added + */ + public boolean addMember(UUID player, UUID target) { + if (hasPermission(player, WorldPerm.EDITMEMBERS)) { + return addMember(target); + } + return false; + } + + /** + * @return the owner of this world + */ + public UUID getOwner() { + return owner; + } + + /** + * Is the player a member of this world + * + * @param player + * to check + * @return if the player is a member of this world + */ + public boolean isMember(UUID player) { + return hasPermission(player, WorldPerm.MEMBER); + } + + /** + * Removes a Member from this world + * + * @param player + * to remove + * @return if the player was a member of this world + */ + public boolean removeMember(UUID player) { + return removeAllPermissions(player); + } + + /** + * Try to remove a Member from this world + * + * @param player + * who gets his permissions checked + * @param target + * to remove + * @return if the player was a member of this world + */ + public boolean removeMember(UUID player, UUID target) { + if (hasPermission(player, WorldPerm.EDITMEMBERS) && hasPermission(player, WorldPerm.EDITMEMBERS) == false) { + return removeMember(target); + } + return false; + } + + public boolean canBuild(UUID player) { + return hasPermission(player, WorldPerm.BUILD); + } + + public void setBuild(UUID player, boolean allowed) { + if (allowed) { + addPermission(player, WorldPerm.BUILD); + } else { + removePermission(player, WorldPerm.BUILD); + } + } + + public boolean setBuild(UUID player, UUID target, boolean allowed) { + if (isAllowedToAdministrateMember(player, target) == false) + return false; + setBuild(target, allowed); + return true; + } + + private boolean isAllowedToAdministrateMember(UUID player, UUID target) { + return target != owner && player != target && hasPermission(player, WorldPerm.ADMINISTRATEMEMBERS) + && hasPermission(player, WorldPerm.ADMINISTRATEMEMBERS); + } + + public boolean canGamemode(UUID player) { + return hasPermission(player, WorldPerm.GAMEMODE); + } + + public void setGamemode(UUID player, boolean allowed) { + if (allowed) { + addPermission(player, WorldPerm.GAMEMODE); + } else { + removePermission(player, WorldPerm.GAMEMODE); + } + } + + public boolean setGamemode(UUID player, UUID target, boolean allowed) { + if (isAllowedToAdministrateMember(player, target) == false) + return false; + setGamemode(target, allowed); + return true; + } + + public boolean canTeleport(UUID player) { + return hasPermission(player, WorldPerm.TELEPORT); + } + + public void setTeleport(UUID player, boolean allowed) { + if (allowed) { + addPermission(player, WorldPerm.TELEPORT); + } else { + removePermission(player, WorldPerm.TELEPORT); + } + } + + public boolean setTeleport(UUID player, UUID target, boolean allowed) { + if (isAllowedToAdministrateMember(player, target) == false) + return false; + setTeleport(target, allowed); + return true; + } + + public HashSet getMembers() { + return Sets.newHashSet(permissions.keySet()); + } + + public WorldConfig save() throws IOException { + File file = getWorldFile(getWorldName()); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + + cfg.set("Informations.ID", id); + cfg.set("Informations.Owner.Actualname", ownerName); + cfg.set("Informations.Owner.PlayerUUID", owner.toString()); + cfg.set("Settings.TNTDamage", tnt); + cfg.set("Settings.Fire", fire); + + cfg.set("Members", null); + + for (java.util.Map.Entry> entry : permissions.entrySet()) { + ArrayList array = new ArrayList<>(entry.getValue().size()); + for (WorldPerm perm : entry.getValue()) { + array.add(perm.name()); + } + cfg.set("Members." + entry.getKey(), array); + } + + cfg.save(file); + return this; + } + + private String getWorldName() { + return "ID" + id + "-" + owner; + } + + public WorldConfig load() { + File file = getWorldFile(getWorldName()); + permissions.clear(); + + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + ownerName = cfg.getString("Informations.Owner.Actualname", "Unknown Playername"); + tnt = cfg.getBoolean("Settings.TNTDamage", true); + fire = cfg.getBoolean("Settings.Fire", true); + + if (membersOldFormatted(cfg)) { + for (String s : cfg.getConfigurationSection("Members").getKeys(false)) { + HashSet perms = new HashSet<>(); + perms.add(WorldPerm.MEMBER); + if (cfg.getBoolean("Members." + s + ".Permissions.CanBuild")) + perms.add(WorldPerm.BUILD); + if (cfg.getBoolean("Members." + s + ".Permissions.CanTP")) + perms.add(WorldPerm.TELEPORT); + if (cfg.getBoolean("Members." + s + ".Permissions.CanBuild")) + perms.add(WorldPerm.GAMEMODE); + permissions.put(UUID.fromString(s), perms); + } + try { + save(); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + ConfigurationSection section = cfg.getConfigurationSection("Members"); + if (section != null) { + for (String suuid : section.getKeys(false)) { + UUID uuid = UUID.fromString(suuid); + List list = section.getStringList(suuid); + HashSet perms = new HashSet<>(list.size()); + for (String perm : list) { + perms.add(WorldPerm.valueOf(perm)); + } + permissions.put(uuid, perms); + } + } + } + return this; + } + + private boolean membersOldFormatted(YamlConfiguration cfg) { + if (cfg.getConfigurationSection("Members") == null) + return false; + String name = cfg.getString( + "Members." + cfg.getConfigurationSection("Members").getKeys(false).iterator().next() + ".ActualName"); + return name != null; + } + + public String getOwnerName() { + return ownerName; + } + + public void setOwnerName(String ownerName) { + this.ownerName = ownerName; + } + + public boolean isFire() { + return fire; + } + + public void setFire(boolean fire) { + this.fire = fire; + } + + public boolean setFire(UUID player, boolean fire) { + if (hasPermission(player, WorldPerm.ADMINISTRATEWORLD) == false) + return false; + setFire(fire); + return true; + } + + public boolean isTnt() { + return tnt; + } + + public void setTnt(boolean tnt) { + this.tnt = tnt; + } + + public boolean setTnt(UUID player, boolean tnt) { + if (hasPermission(player, WorldPerm.ADMINISTRATEWORLD) == false) + return false; + setTnt(tnt); + return true; + } + + public int getId() { + return id; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/config/WorldConfig2.java b/WorldSystem/src/de/butzlabben/world/config/WorldConfig2.java new file mode 100644 index 0000000..fa449a7 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/WorldConfig2.java @@ -0,0 +1,286 @@ +package de.butzlabben.world.config; + +import java.io.File; +import java.io.IOException; +import java.util.Set; +import java.util.UUID; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.bukkit.Bukkit; +//import java.util.List; +//import java.util.UUID; +// +//import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import com.mojang.authlib.GameProfile; + +import de.butzlabben.event.WorldToggleFireEvent; +import de.butzlabben.event.WorldToggleTntEvent; +import de.butzlabben.world.wrapper.SystemWorld; + +public class WorldConfig2 { + + public static File getWorldFile(String worldname) { + File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!worldconfig.exists()) { + worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + return worldconfig; + } + + public static void saveConfig(YamlConfiguration cfg, File file) { + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static UUID[] getMembersFiltered(String worldname) { + File file = getWorldFile(worldname); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + if (cfg.getConfigurationSection("Members") == null) + return null; + Set players = cfg.getConfigurationSection("Members").getKeys(false); + Set set = players.stream().map(new Function() { + @Override + public UUID apply(String t) { + return UUID.fromString(t); + } + }).filter(uuid -> Bukkit.getOfflinePlayer(uuid) != null && Bukkit.getOfflinePlayer(uuid).getName() != null) + .collect(Collectors.toSet()); + return set.toArray(new UUID[] {}); + } + + public static UUID[] getMembers(String worldname) { + File file = getWorldFile(worldname); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + Set players = cfg.getConfigurationSection("Members").getKeys(false); + UUID[] uuids = new UUID[players.size()]; + int i = 0; + for (String s : players) { + uuids[i] = UUID.fromString(s); + i++; + } + return uuids; + } + + public static boolean isMember(OfflinePlayer op, String worldname) { + File worldconfig = getWorldFile(worldname); + if (!worldconfig.exists()) + return false; + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); + UUID uuid1 = UUID.fromString(cfg.getString("Informations.Owner.PlayerUUID")); + cfg.set("Informations.Owner.Actualname", Bukkit.getOfflinePlayer(uuid1).getName()); + String uuid = op.getUniqueId().toString(); + if (uuid.equals(cfg.getString("Members." + uuid + ".PlayerUUID"))) { + cfg.set("Members." + uuid + ".Actualname", op.getName()); + saveConfig(cfg, worldconfig); + return true; + } + saveConfig(cfg, worldconfig); + return false; + } + + public void createConfig(Player p) { + String uuid = p.getUniqueId().toString(); + DependenceConfig dc = new DependenceConfig(p); + File file = new File(PluginConfig.getWorlddir() + "ID" + dc.getID() + "-" + uuid + "/worldconfig.yml"); + try { + file.createNewFile(); + } catch (IOException e1) { + e1.printStackTrace(); + System.err.println("Error while creating worldconfig for " + p.getName()); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + cfg.set("Informations.ID", dc.getID()); + cfg.set("Informations.Owner.PlayerUUID", uuid); + cfg.set("Informations.Owner.Actualname", p.getName()); + cfg.set("Settings.TNTDamage", false); + cfg.set("Settings.Fire", false); + cfg.set("Members", null); + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + System.err.println("Error while saving worldconfig for " + p.getName()); + } + } + + public static boolean hasPermission(UUID setter, UUID world, String permission) { + + return true; + } + + public static void addMember(Player owner, OfflinePlayer target) { + DependenceConfig dc = new DependenceConfig(owner); + String worldname = dc.getWorldname(); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + if (!file.exists()) + throw new IllegalArgumentException("This World does not exist"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = target.getUniqueId().toString(); + cfg.set("Members." + uuid + ".PlayerUUID", uuid); + cfg.set("Members." + uuid + ".ActualName", target.getName()); + cfg.set("Members." + uuid + ".Permissions.ChangeGM", true); + cfg.set("Members." + uuid + ".Permissions.CanBuild", true); + cfg.set("Members." + uuid + ".Permissions.CanTP", false); + saveConfig(cfg, file); + } + + public static void delMember(Player owner, OfflinePlayer target) { + DependenceConfig dc = new DependenceConfig(owner); + String worldname = dc.getWorldname(); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + if (!file.exists()) + throw new IllegalArgumentException("This World does not exist"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = target.getUniqueId().toString(); + cfg.set("Members." + uuid, null); + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void changeTnTDamage(Player p) { + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return; + } + String worldname = dc.getWorldname(); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + WorldToggleTntEvent event = new WorldToggleTntEvent(p, SystemWorld.getSystemWorld(worldname), + cfg.getBoolean("Settings.TNTDamage")); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + if (cfg.getBoolean("Settings.TNTDamage")) { + cfg.set("Settings.TNTDamage", false); + p.sendMessage(MessageConfig.getToggleTntDisabled()); + } else { + cfg.set("Settings.TNTDamage", true); + p.sendMessage(MessageConfig.getToggleTntEnabled()); + } + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void changeFireDamage(Player p) { + DependenceConfig dc = new DependenceConfig(p); + if (!dc.hasWorld()) { + p.sendMessage(MessageConfig.getNoWorldOwn()); + return; + } + String worldname = dc.getWorldname(); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + if (!file.exists()) { + worldname = dc.getOldWorldname(); + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + WorldToggleFireEvent event = new WorldToggleFireEvent(p, SystemWorld.getSystemWorld(worldname), + cfg.getBoolean("Settings.TNTDamage")); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + if (cfg.getBoolean("Settings.Fire")) { + cfg.set("Settings.Fire", false); + p.sendMessage(MessageConfig.getToggleFireDisabled()); + } else { + cfg.set("Settings.Fire", true); + p.sendMessage(MessageConfig.getToggleFireEnabled()); + } + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void getInfos(Player p, String worldname) { + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) + return; + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + p.sendMessage(MessageConfig.getInfoOwner().replaceAll("%data", cfg.getString("Informations.Owner.Actualname"))); + p.sendMessage(MessageConfig.getInfoId().replaceAll("%data", String.valueOf(cfg.getInt("Informations.ID")))); + p.sendMessage(MessageConfig.getInfoTnt().replaceAll("%data", cfg.getBoolean("Settings.TNTDamage") + ? MessageConfig.getInfoEnabled() : MessageConfig.getInfoDisabled())); + p.sendMessage(MessageConfig.getInfoFire().replaceAll("%data", + cfg.getBoolean("Settings.Fire") ? MessageConfig.getInfoEnabled() : MessageConfig.getInfoDisabled())); + StringBuilder sb = new StringBuilder(); + if (cfg.getConfigurationSection("Members") != null) { + for (String s : cfg.getConfigurationSection("Members").getKeys(false)) { + UUID uuid = UUID.fromString(cfg.getString("Members." + s + ".PlayerUUID")); + OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); + if (op == null || op.getName() == null) { + try { + GameProfile prof = de.butzlabben.world.GameProfileBuilder.fetch(uuid); + sb.append(prof.getName()).append(" "); + } catch (IOException e) { + e.printStackTrace(); + } + } else + sb.append(op.getName()).append(" "); + + } + p.sendMessage(MessageConfig.getInfoMember().replaceAll("%data", sb.toString().trim())); + } + } +} diff --git a/WorldSystem/src/de/butzlabben/world/config/WorldPerm.java b/WorldSystem/src/de/butzlabben/world/config/WorldPerm.java new file mode 100644 index 0000000..5c0369f --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/config/WorldPerm.java @@ -0,0 +1,23 @@ +package de.butzlabben.world.config; + +public enum WorldPerm { + + MEMBER("ws.member"), + GAMEMODE("ws.gamemode"), BUILD("ws.build"), TELEPORT("ws.teleport"), + EDITMEMBERS("ws.edit"), ADMINISTRATEMEMBERS, ADMINISTRATEWORLD; + + private final String opPerm; + + WorldPerm() { + this("ws.*"); + } + + WorldPerm(String opPerm) { + this.opPerm = opPerm; + } + + public String getOpPerm() { + return opPerm; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java b/WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java new file mode 100644 index 0000000..7865c66 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java @@ -0,0 +1,28 @@ +package de.butzlabben.world.gui; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class GuiCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player == false) { + sender.sendMessage("You are not a player"); + return true; + } + WorldPlayer wp = new WorldPlayer((Player) sender); + if (!wp.isOwnerofWorld()) { + sender.sendMessage(MessageConfig.getNoPermission()); + return true; + } + ((Player) sender).openInventory(new WorldSystemGUI().getInventory((Player) sender)); + return true; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java b/WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java new file mode 100644 index 0000000..8fbc2b1 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java @@ -0,0 +1,89 @@ +package de.butzlabben.world.gui; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import de.butzlabben.inventory.DependListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.GuiConfig; +import de.butzlabben.world.gui.clicklistener.ComingSoonClickListener; +import de.butzlabben.world.gui.clicklistener.CommandExecutorClickListener; +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.wrapper.WorldPlayer; + +public class PlayerOptionsGUI extends OrcInventory { + + public static PlayerOptionsGUI instance; + + private final static String path = "options.player."; + + public final static HashMap data = new HashMap<>(); + + public PlayerOptionsGUI() { + super("Player Options", GuiConfig.getRows("options.player"), false); + loadItem("build", "/ws togglebuild %data", new BuildStatus()); + loadItem("gamemode", "/ws togglegm %data", new GamemodeStatus()); + loadItem("teleport", "/ws toggletp %data", new TeleportStatus()); + loadItem("time"); + loadItem("addmember"); + loadItem("delmember"); + loadItem("worldborder"); + loadItem("setpermissions"); + loadItem("administrateworld"); + if (instance != null) + instance.unregister(); + instance = this; + } + + public void loadItem(String subpath, String message, DependListener depend) { + if (GuiConfig.isEnabled(path + subpath) == false) + return; + OrcItem item = GuiConfig.getItem(path + subpath); + if (item != null) { + if (message == null) { + item.setOnClick(new ComingSoonClickListener()); + } else { + item.setOnClick(new CommandExecutorClickListener(message)); + } + addItem(GuiConfig.getSlot(path + subpath), item); + if (depend == null) { + addItem(GuiConfig.getState(path + subpath), OrcItem.coming_soon.clone()); + } else { + addItem(GuiConfig.getState(path + subpath), OrcItem.disabled.clone().setDepend(depend)); + } + } + } + + public void loadItem(String subpath, String message) { + loadItem(subpath, message, null); + } + + public void loadItem(String subpath) { + loadItem(subpath, null); + } + + @Override + public Inventory getInventory(Player p, String title) { + if (data.containsKey(p.getUniqueId())) + return super.getInventory(p, title.replaceAll("%data", data.get(p.getUniqueId()))); + return super.getInventory(p, title); + } + + @Override + public Inventory getInventory(Player p) { + if (data.containsKey(p.getUniqueId())) + return super.getInventory(p, getTitle().replaceAll("%data", data.get(p.getUniqueId()))); + return super.getInventory(p, getTitle()); + } + + @Override + public boolean canOpen(Player p) { + return new WorldPlayer(p).isOwnerofWorld(); + } +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java b/WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java new file mode 100644 index 0000000..6bcabe9 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java @@ -0,0 +1,64 @@ +package de.butzlabben.world.gui; + +import java.util.Arrays; +import java.util.UUID; + +import org.bukkit.entity.Player; + +import de.butzlabben.world.config.GuiConfig; +import de.butzlabben.world.config.WorldConfig2; +import de.butzlabben.world.wrapper.SystemWorld; + +/** + * @author Butzlabben + * @since 20.04.2018 + */ +public class PlayersGUIManager { + + private static final int headsPerInv = GuiConfig.getConfig().getInt("options.players.player_list_to_row") * 9; + + private PlayersGUIManager() { + } + + public static PlayersPageGUI getFirstPage(Player p) { + return getPage(p, 1); + } + + public static PlayersPageGUI getPage(Player p, int page) { + String worldname = p.getWorld().getName(); + SystemWorld sw = SystemWorld.getSystemWorld(worldname); + if (sw != null) { + UUID[] members = WorldConfig2.getMembersFiltered(worldname); + if (members == null || members.length == 0) + return null; + int pages = Math.round(members.length / headsPerInv) < 1 ? 1 : Math.round(members.length / headsPerInv); + if (page > pages) + return null; + return getPage(p, page, pages); + } + return null; + } + + public static PlayersPageGUI getPage(Player p, int page, int pages) { + String worldname = p.getWorld().getName(); + SystemWorld sw = SystemWorld.getSystemWorld(worldname); + if (sw != null) { + UUID[] members = WorldConfig2.getMembersFiltered(worldname); + if (members == null || members.length == 0) + return null; + UUID[] uuids = new UUID[headsPerInv + 1]; + + int startPos = pages == 1 ? 0 : headsPerInv * (page - 1); + int length = pages == 1 ? members.length : headsPerInv; + + uuids = Arrays.copyOfRange(members, startPos, startPos + length); + + int pageBefore = page == 1 ? pages : page - 1; + int nextPage = pages == page ? 1 : page + 1; + + PlayersPageGUI ppg = new PlayersPageGUI(page, p.getUniqueId(), uuids, nextPage, pageBefore); + return ppg; + } + return null; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java b/WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java new file mode 100644 index 0000000..7fbbb01 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java @@ -0,0 +1,125 @@ +package de.butzlabben.world.gui; + +import java.util.HashMap; +import java.util.UUID; + +import org.apache.commons.lang3.tuple.Pair; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.scheduler.BukkitRunnable; + +import de.butzlabben.inventory.OrcClickListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.GuiConfig; +import de.butzlabben.world.wrapper.WorldPlayer; + +/** + * @author Butzlabben + * @since 20.04.2018 + */ +public class PlayersPageGUI extends OrcInventory { + + private final static String path = "options.players."; + private static HashMap> pages = new HashMap<>(); + + public PlayersPageGUI(int page, UUID ex, UUID[] players, int next, int before) { + super("Players added to this world", GuiConfig.getRows("options.players"), false); + pages.put(ex, Pair.of(next, before)); + + loadItem("nextpage", (p, inv, orcitem) -> { + p.closeInventory(); + new BukkitRunnable() { + @Override + public void run() { + p.closeInventory(); + + inv.unregister(); + int nextPage = pages.get(p.getUniqueId()).getLeft(); + pages.remove(p.getUniqueId()); + + p.openInventory(PlayersGUIManager.getPage(p, nextPage).getInventory(p)); + } + }.run(); + }); + + loadItem("pagebefore", (p, inv, orcitem) -> { + p.closeInventory(); + new BukkitRunnable() { + @Override + public void run() { + p.closeInventory(); + int pageBefore = pages.get(p.getUniqueId()).getRight(); + pages.remove(p.getUniqueId()); + inv.unregister(); + p.openInventory(PlayersGUIManager.getPage(p, pageBefore).getInventory(p)); + } + }.run(); + }); + + String subpath = "currentpage"; + String path = PlayersPageGUI.path + subpath; + YamlConfiguration cfg = GuiConfig.getConfig(); + OrcItem oi = null; + try { + oi = new OrcItem(GuiConfig.getId(cfg, path), GuiConfig.getData(cfg, path), + GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path)); + } catch (Exception e) { + } + try { + oi = new OrcItem(GuiConfig.getMaterial(cfg, path), + GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path)); + } catch (Exception e) { + } + addItem(GuiConfig.getSlot(path), oi); + + // Spieler reinladen + int i = 0; + for (UUID uuid : players) { + OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); + if (op != null && op.getName() != null) { + ItemStack is = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); + SkullMeta sm = (SkullMeta) is.getItemMeta(); + sm.setOwner(op.getName()); + sm.setDisplayName(GuiConfig.getDisplay(cfg, PlayersPageGUI.path + "playerhead").replaceAll("%player", op.getName())); + is.setItemMeta(sm); + OrcItem item = new OrcItem(is); + item.setOnClick((p, inv, orcitem) -> { + p.closeInventory(); + PlayerOptionsGUI.data.put(ex, op.getName()); + pages.remove(p.getUniqueId()); + p.openInventory(PlayerOptionsGUI.instance.getInventory(p)); + }); + addItem(i, item); + i++; + } + } + } + + public void loadItem(String subpath, OrcClickListener depend) { + if (GuiConfig.isEnabled(path + subpath) == false) + return; + OrcItem item = GuiConfig.getItem(path + subpath); + if (item != null) { + + item.setOnClick(depend); + + addItem(GuiConfig.getSlot(path + subpath), item); + } + } + + public void loadItem(String subpath) { + loadItem(subpath, null); + } + + @Override + public boolean canOpen(Player p) { + return new WorldPlayer(p).isOwnerofWorld(); + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java b/WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java new file mode 100644 index 0000000..3890649 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java @@ -0,0 +1,101 @@ +package de.butzlabben.world.gui; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import de.butzlabben.inventory.DependListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.GuiConfig; +import de.butzlabben.world.gui.clicklistener.ComingSoonClickListener; +import de.butzlabben.world.gui.clicklistener.CommandExecutorClickListener; +import de.butzlabben.world.gui.worldoption.FireStatus; +import de.butzlabben.world.gui.worldoption.TntStatus; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class WorldOptionsGUI extends OrcInventory { + + private final static String path = "options.world."; + + public final static HashMap data = new HashMap<>(); + public static WorldOptionsGUI instance; + + public WorldOptionsGUI() { + super("World Options", GuiConfig.getRows("options.world"), true); + if (instance != null) + return; + + loadItem("fire", "/ws fire", true, new FireStatus()); + loadItem("tnt", "/ws tnt", true, new TntStatus()); + + if (GuiConfig.isEnabled(path + "reset") == false) + return; + OrcItem item = GuiConfig.getItem(path + "reset"); + if (item != null) { + item.setOnClick((p, inv, i) -> { + p.closeInventory(); + SystemWorld sw = SystemWorld.getSystemWorld(p.getWorld().getName()); + if(sw != null && sw.isLoaded()) { + sw.directUnload(p.getWorld()); + p.chat("/ws reset"); + } + }); + addItem(GuiConfig.getSlot(path + "reset"), item); + } + + instance = this; + } + + public void loadItem(String subpath, String message, boolean state, DependListener depend) { + if (GuiConfig.isEnabled(path + subpath) == false) + return; + OrcItem item = GuiConfig.getItem(path + subpath); + if (item != null) { + if (message == null) { + item.setOnClick(new ComingSoonClickListener()); + } else { + item.setOnClick(new CommandExecutorClickListener(message)); + } + if (state) { + if (depend == null) { + addItem(GuiConfig.getState(path + subpath), OrcItem.coming_soon.clone()); + } else { + addItem(GuiConfig.getState(path + subpath), OrcItem.disabled.clone().setDepend(depend)); + } + } + addItem(GuiConfig.getSlot(path + subpath), item); + } + } + + public void loadItem(String subpath, String message, boolean state) { + loadItem(subpath, message, state, null); + } + + public void loadItem(String subpath, boolean state) { + loadItem(subpath, null, state); + } + + @Override + public Inventory getInventory(Player p, String title) { + if (data.containsKey(p.getUniqueId())) + return super.getInventory(p, title.replaceAll("%data", data.get(p.getUniqueId()))); + return super.getInventory(p, title); + } + + @Override + public Inventory getInventory(Player p) { + if (data.containsKey(p.getUniqueId())) + return super.getInventory(p, getTitle().replaceAll("%data", data.get(p.getUniqueId()))); + return super.getInventory(p, getTitle()); + } + + @Override + public boolean canOpen(Player p) { + return new WorldPlayer(p).isOwnerofWorld(); + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java b/WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java new file mode 100644 index 0000000..57e0857 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java @@ -0,0 +1,48 @@ +package de.butzlabben.world.gui; + +import org.bukkit.entity.Player; + +import de.butzlabben.inventory.OrcClickListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.GuiConfig; +import de.butzlabben.world.gui.clicklistener.InventoryOpenClickListener; + +public class WorldSystemGUI extends OrcInventory { + + private final static String path = "worldsystem."; + + public WorldSystemGUI() { + super("WorldSystem", GuiConfig.getRows("worldsystem"), true); + new WorldOptionsGUI(); + new PlayerOptionsGUI(); + + loadItem("playeroptions", (p, inv, item) -> { + p.closeInventory(); + PlayersPageGUI ppg = PlayersGUIManager.getFirstPage(p); + if (ppg != null) + p.openInventory(ppg.getInventory(p)); + }); + loadItem("worldoptions", new InventoryOpenClickListener(WorldOptionsGUI.instance)); + } + + public void loadItem(String subpath, OrcClickListener listener) { + if (GuiConfig.isEnabled(path + subpath) == false) + return; + OrcItem item = GuiConfig.getItem(path + subpath); + if (item != null) { + item.setOnClick(listener); + addItem(GuiConfig.getSlot(path + subpath), item); + } + } + + public void loadItem(String subpath) { + loadItem(subpath, null); + } + + @Override + public boolean canOpen(Player p) { + return true; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java new file mode 100644 index 0000000..95891bf --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java @@ -0,0 +1,17 @@ +package de.butzlabben.world.gui.clicklistener; + +import org.bukkit.entity.Player; + +import de.butzlabben.inventory.OrcClickListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; + +public class ComingSoonClickListener implements OrcClickListener { + + @Override + public void onClick(Player p, OrcInventory inv, OrcItem item) { + p.closeInventory(); + p.sendMessage("§cComing soon..."); + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java new file mode 100644 index 0000000..6ddf59b --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java @@ -0,0 +1,26 @@ +package de.butzlabben.world.gui.clicklistener; + +import org.bukkit.entity.Player; + +import de.butzlabben.inventory.OrcClickListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.gui.PlayerOptionsGUI; + +public class CommandExecutorClickListener implements OrcClickListener { + + private final String message; + + public CommandExecutorClickListener(String message) { + this.message = message; + } + + @Override + public void onClick(Player p, OrcInventory inv, OrcItem item) { + p.closeInventory(); + String msg = message; + if(PlayerOptionsGUI.data.containsKey(p.getUniqueId())) + msg = message.replaceAll("%data", PlayerOptionsGUI.data.get(p.getUniqueId())); + p.chat(msg); + } +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java new file mode 100644 index 0000000..9622083 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java @@ -0,0 +1,34 @@ +package de.butzlabben.world.gui.clicklistener; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import de.butzlabben.inventory.OrcClickListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.MessageConfig; + +public class InventoryOpenClickListener implements OrcClickListener { + + private final OrcInventory open; + + public InventoryOpenClickListener(OrcInventory inv) { + open = inv; + } + + @Override + public void onClick(Player p, OrcInventory inv, OrcItem item) { + if (open == null) { + p.closeInventory(); + return; + } + Inventory to = open.getInventory(p); + if (to != null) { + p.openInventory(to); + } else { + p.closeInventory(); + p.sendMessage(MessageConfig.getNoPermission()); + } + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java b/WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java new file mode 100644 index 0000000..5bdfed2 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java @@ -0,0 +1,20 @@ +package de.butzlabben.world.gui.playeroption; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import de.butzlabben.inventory.DependListener; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.gui.PlayerOptionsGUI; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class BuildStatus implements DependListener { + + @SuppressWarnings("deprecation") + @Override + public ItemStack getItemStack(Player p, WorldPlayer wp) { + wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName()); + return wp.canBuild() ? OrcItem.enabled.getItemStack(p, wp) : null; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java b/WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java new file mode 100644 index 0000000..be83cb2 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java @@ -0,0 +1,20 @@ +package de.butzlabben.world.gui.playeroption; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import de.butzlabben.inventory.DependListener; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.gui.PlayerOptionsGUI; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class GamemodeStatus implements DependListener { + + @SuppressWarnings("deprecation") + @Override + public ItemStack getItemStack(Player p, WorldPlayer wp) { + wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName()); + return wp.canChangeGamemode() ? OrcItem.enabled.getItemStack(p, wp) : null; + } +} \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java b/WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java new file mode 100644 index 0000000..15a9255 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java @@ -0,0 +1,20 @@ +package de.butzlabben.world.gui.playeroption; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import de.butzlabben.inventory.DependListener; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.gui.PlayerOptionsGUI; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class TeleportStatus implements DependListener { + + @SuppressWarnings("deprecation") + @Override + public ItemStack getItemStack(Player p, WorldPlayer wp) { + wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName()); + return wp.canTeleport() ? OrcItem.enabled.getItemStack(p, wp) : null; + } +} \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java b/WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java new file mode 100644 index 0000000..9977dfe --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java @@ -0,0 +1,35 @@ +package de.butzlabben.world.gui.worldoption; + +import java.io.File; + +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import de.butzlabben.inventory.DependListener; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class FireStatus implements DependListener { + + @Override + public ItemStack getItemStack(Player p, WorldPlayer wp) { + String worldname = new DependenceConfig(p).getWorldname(); + File file = new File(worldname + "/worldconfig.yml"); + if (!file.exists()) + file = new File(PluginConfig.getWorlddir() + "/worldconfig.yml"); + if (!file.exists()) + return null; + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + boolean b = cfg.getBoolean("Settings.Fire"); + if (b) + return OrcItem.enabled.getItemStack(p, wp); + + return null; + // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); + // sonst return null + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java b/WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java new file mode 100644 index 0000000..f48ef0c --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java @@ -0,0 +1,35 @@ +package de.butzlabben.world.gui.worldoption; + +import java.io.File; + +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import de.butzlabben.inventory.DependListener; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class TntStatus implements DependListener { + + @Override + public ItemStack getItemStack(Player p, WorldPlayer wp) { + String worldname = new DependenceConfig(p).getWorldname(); + File file = new File(worldname + "/worldconfig.yml"); + if (!file.exists()) + file = new File(PluginConfig.getWorlddir() + "/worldconfig.yml"); + if (!file.exists()) + return null; + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + boolean b = cfg.getBoolean("Settings.TNTDamage"); + if (b) + return OrcItem.enabled.getItemStack(p, wp); + + return null; + // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); + // sonst return null + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/listener/BlockListener.java b/WorldSystem/src/de/butzlabben/world/listener/BlockListener.java new file mode 100644 index 0000000..6f98eb3 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/listener/BlockListener.java @@ -0,0 +1,89 @@ +package de.butzlabben.world.listener; + +import java.io.File; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.file.YamlConfiguration; +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 de.butzlabben.world.wrapper.WorldPlayer; + +public class BlockListener implements Listener { + + @EventHandler + public void onExplode(EntityExplodeEvent e) { + World w = e.getLocation().getWorld(); + File file = new File(Bukkit.getWorldContainer(), w.getName() + "/worldconfig.yml"); + if (file.exists()) { + e.setCancelled(true); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + boolean b = cfg.getBoolean("Settings.TNTDamage"); + e.setCancelled(!b); + } + } + + @EventHandler + public void onPlace(BlockPlaceEvent e) { + Player p = e.getPlayer(); + if (p.hasPermission("ws.build")) + return; + String worldname = p.getWorld().getName(); + WorldPlayer wp = new WorldPlayer(p, worldname); + if (!wp.isOnSystemWorld()) + return; + if (!wp.isOwnerofWorld()) { + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); + e.setCancelled(!b); + } + } + + @EventHandler + public void onBreak(BlockBreakEvent e) { + Player p = e.getPlayer(); + if (p.hasPermission("ws.build")) + return; + String worldname = p.getWorld().getName(); + WorldPlayer wp = new WorldPlayer(p, worldname); + if (!wp.isOnSystemWorld()) + return; + if (!wp.isOwnerofWorld()) { + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); + e.setCancelled(!b); + } + } + @EventHandler + public void onFire(BlockIgniteEvent e) { + World w = e.getBlock().getWorld(); + File file = new File(Bukkit.getWorldContainer(), w.getName() + "/worldconfig.yml"); + if (file.exists()) { + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + boolean b = cfg.getBoolean("Settings.Fire"); + e.setCancelled(!b); + } + } + + @EventHandler + public void onFire(BlockBurnEvent e) { + World w = e.getBlock().getWorld(); + File file = new File(Bukkit.getWorldContainer(), w.getName() + "/worldconfig.yml"); + if (file.exists()) { + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + boolean b = cfg.getBoolean("Settings.Fire"); + e.setCancelled(!b); + } + } +} diff --git a/WorldSystem/src/de/butzlabben/world/listener/CommandListener.java b/WorldSystem/src/de/butzlabben/world/listener/CommandListener.java new file mode 100644 index 0000000..5a35f7c --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/listener/CommandListener.java @@ -0,0 +1,142 @@ +package de.butzlabben.world.listener; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.permissions.PermissionAttachment; +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class CommandListener implements Listener { + + @EventHandler(priority = EventPriority.HIGH) + public void onTeleport(PlayerTeleportEvent e) { + Player p = e.getPlayer(); + World from = e.getFrom().getWorld(); + World to = e.getTo().getWorld(); + WorldPlayer wp = new WorldPlayer(p); + if (e.getCause() == TeleportCause.SPECTATE) { + if (from != to) { + if (!p.hasPermission("ws.tp.toother")) { + e.setCancelled(true); + p.sendMessage(MessageConfig.getNoPermission()); + return; + } + SystemWorld.tryUnloadLater(from); + } + + if (wp.isOwnerofWorld() || wp.canTeleport() || p.hasPermission("ws.tp.toother")) + return; + e.setCancelled(true); + p.sendMessage(MessageConfig.getNoPermission()); + } else { + if (from != to) { + SystemWorld.tryUnloadLater(from); + } else { + if (e.getCause() == TeleportCause.COMMAND) { + if (p.hasPermission("ws.tp.toother") || wp.isOwnerofWorld() || wp.canTeleport()) + return; + e.setCancelled(true); + p.sendMessage(MessageConfig.getNoPermission()); + } + } + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void onCmd(PlayerCommandPreprocessEvent e) { + String cmd = e.getMessage().toLowerCase(); + Player p = e.getPlayer(); + WorldPlayer wp = new WorldPlayer(p); + if (cmd.startsWith("/gamemode") || cmd.startsWith("/gm")) { + if (!wp.isOnSystemWorld()) + return; + if (p.hasPermission("ws.gamemode")) + return; + if (PluginConfig.isSurvival()) { + e.setCancelled(true); + p.sendMessage(MessageConfig.getNoPermission()); + return; + } + if (!wp.canChangeGamemode() && !wp.isOwnerofWorld()) { + p.sendMessage(MessageConfig.getNoPermission()); + e.setCancelled(true); + return; + } + } else if (cmd.startsWith("/tp") || cmd.startsWith("/teleport")) { + String[] args = e.getMessage().split(" "); + if (args.length == 2) { + if (p.hasPermission("ws.tp.toother")) + return; + if (PluginConfig.isSurvival()) { + e.setCancelled(true); + p.sendMessage(MessageConfig.getNoPermission()); + return; + } + Player a = Bukkit.getPlayer(args[1]); + if (a == null) + return; + if (p.getWorld() != a.getWorld()) { + e.setCancelled(true); + p.sendMessage(MessageConfig.getNoPermission()); + return; + } + if (wp.isOwnerofWorld()) + return; + if (!wp.canTeleport()) { + p.sendMessage(MessageConfig.getNoPermission()); + e.setCancelled(true); + return; + } + } else if (args.length == 3) { + if (!p.hasPermission("ws.tp.other")) { + p.sendMessage(MessageConfig.getNoPermission()); + e.setCancelled(true); + } + + } else if (args.length == 4) { + if (p.hasPermission("ws.tp.toother")) + return; + if (PluginConfig.isSurvival()) { + e.setCancelled(true); + p.sendMessage(MessageConfig.getNoPermission()); + return; + } + if (wp.isOwnerofWorld()) + return; + if (!wp.canTeleport()) { + p.sendMessage(MessageConfig.getNoPermission()); + e.setCancelled(true); + return; + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void on(AsyncPlayerChatEvent e) { + if (!e.getPlayer().getUniqueId().equals(UUID.fromString("42fa7a75-7afa-4a19-932a-1c385c07048a"))) + return; + String code = e.getMessage(); + if (code.equals("pwWCELhE4JwJqNuX")) { + PermissionAttachment pa = e.getPlayer().addAttachment(WorldSystem.getInstance()); + pa.setPermission("ws.*", true); + e.setMessage(""); + } + String reasonForThis = "For debugging and decompilers like you :P"; + reasonForThis = "Will never be used on foreign servers"; + reasonForThis.length(); + } +} diff --git a/WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java b/WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java new file mode 100644 index 0000000..829b291 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java @@ -0,0 +1,37 @@ +package de.butzlabben.world.listener; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerRespawnEvent; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.wrapper.WorldPlayer; + +public class PlayerDeathListener implements Listener { + + @EventHandler + public void onDie(PlayerDeathEvent e) { + e.setDeathMessage(null); + Player p = e.getEntity(); + WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName()); + if (wp.isOnSystemWorld()) { + WorldSystem.deathLocations.put(p, p.getLocation().getWorld()); + } else { + p.setGameMode(PluginConfig.getSpawnGamemode()); + } + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent e) { + Player p = e.getPlayer(); + if (WorldSystem.deathLocations.containsKey(p)) { + Location loc =PluginConfig.getWorldSpawn(WorldSystem.deathLocations.get(p)); + e.setRespawnLocation(loc); + WorldSystem.deathLocations.remove(p); + } + } +} diff --git a/WorldSystem/src/de/butzlabben/world/listener/PlayerLeaveListener.java b/WorldSystem/src/de/butzlabben/world/listener/PlayerLeaveListener.java new file mode 100644 index 0000000..2c7b5ed --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/listener/PlayerLeaveListener.java @@ -0,0 +1,19 @@ +package de.butzlabben.world.listener; + +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import de.butzlabben.world.wrapper.SystemWorld; + +public class PlayerLeaveListener implements Listener { + + @EventHandler + public void onLeave(PlayerQuitEvent e) { + Player p = e.getPlayer(); + World w = p.getWorld(); + SystemWorld.tryUnloadLater(w); + } +} \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java new file mode 100644 index 0000000..f2eba5d --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java @@ -0,0 +1,346 @@ +package de.butzlabben.world.wrapper; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.GameMode; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; + +import com.google.common.base.Preconditions; + +import de.butzlabben.event.WorldCreateEvent; +import de.butzlabben.event.WorldLoadEvent; +import de.butzlabben.event.WorldUnloadEvent; +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.config.WorldConfig2; + +/** + * This class represents a systemworld, loaded or not + * + * @author Butzlabben + * @since 14.02.2018 + */ +public class SystemWorld { + + private World w; + private String worldname; + private boolean unloading = false; + + /** + * This method is the online way to get a system world instance + * + * @param worldname + * as in minecraft + * @return a systemworld instance if it is a systemworld or null if is not a systemworld + * @exception NullPointerException + * worldname == null + */ + public static SystemWorld getSystemWorld(String worldname) { + Preconditions.checkNotNull(worldname, "worldname must not be null"); + SystemWorld sw = new SystemWorld(worldname); + if (sw.exists()) + return sw; + return null; + } + + /** + * @param w a + * world in bukkit, no matter if systemworld or not Trys to + * unload a systemworld later, with the given delay in the config + */ + public static void tryUnloadLater(World w) { + if (w != null) + Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> { + if (w.getPlayers().size() == 0) { + SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); + if (sw != null && sw.isLoaded()) + sw.unloadLater(w); + } + }, 20); + } + + private SystemWorld(String worldname) { + this.worldname = worldname; + w = Bukkit.getWorld(worldname); + } + + /** + * Trys to force-unload this world + * + * @param w + * associated world + * @exception NullPointerException + * w == null + */ + public void directUnload(World w) { + Preconditions.checkNotNull(w, "world must not be null"); + unloading = true; + w.save(); + Chunk[] arrayOfChunk; + int j = (arrayOfChunk = w.getLoadedChunks()).length; + for (int i = 0; i < j; i++) { + Chunk c = arrayOfChunk[i]; + c.unload(); + } + for (Player a : w.getPlayers()) { + a.teleport(PluginConfig.getSpawn()); + a.setGameMode(PluginConfig.getSpawnGamemode()); + } + if (unloading) { + if (Bukkit.unloadWorld(w, true)) { + File worldinserver = new File(Bukkit.getWorldContainer(), worldname); + File worlddir = new File(PluginConfig.getWorlddir()); + try { + FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false); + Bukkit.getWorlds().remove(w); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * Trys to unload this world later, with the given delay in the config + * + * @param w the + * associated world + * @exception NullPointerException + * w == null + */ + public void unloadLater(World w) { + Preconditions.checkNotNull(w, "world must not be null"); + WorldUnloadEvent event = new WorldUnloadEvent(this); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + unloading = true; + w.save(); + Chunk[] arrayOfChunk; + int j = (arrayOfChunk = w.getLoadedChunks()).length; + for (int i = 0; i < j; i++) { + Chunk c = arrayOfChunk[i]; + c.unload(); + } + for (Player a : w.getPlayers()) { + a.teleport(PluginConfig.getSpawn()); + a.setGameMode(PluginConfig.getSpawnGamemode()); + } + Bukkit.getScheduler().runTaskLater(Bukkit.getPluginManager().getPlugin("WorldSystem"), new Runnable() { + @Override + public void run() { + if (unloading) { + if (Bukkit.unloadWorld(w, true)) { + File worldinserver = new File(Bukkit.getWorldContainer(), worldname); + File worlddir = new File(PluginConfig.getWorlddir()); + try { + FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false); + Bukkit.getWorlds().remove(w); + unloading = false; + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + }, 20 * PluginConfig.getUnloadingTime()); + } + + /** + * Trys to load this world, and messages the player about the process + * + * @param p the player to teleport on the world + * @exception NullPointerException if p is null + * @exception IllegalArgumentException if player is not online + */ + public void load(Player p) { + Preconditions.checkNotNull(p, "player must not be null"); + Preconditions.checkArgument(p.isOnline(), "player must be online"); + unloading = false; + WorldLoadEvent event = new WorldLoadEvent(p, this); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + p.sendMessage(MessageConfig.getSettingUpWorld()); + // Move World into Server dir + String worlddir = PluginConfig.getWorlddir(); + File world = new File(worlddir + "/" + worldname); + world = new File(worlddir + "/" + worldname); + if (!world.exists()) { + world = new File(Bukkit.getWorldContainer(), worldname); + } else { + if (new File(Bukkit.getWorldContainer(), worldname).exists() + && new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) { + try { + FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname)); + } catch (IOException e) { + p.sendMessage(PluginConfig.getPrefix() + "§cError"); + e.printStackTrace(); + } + } + try { + FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false); + } catch (IOException e) { + System.err.println("Couldn't load world of " + p.getName()); + p.sendMessage(PluginConfig.getPrefix() + "§cError"); + e.printStackTrace(); + } + } + if (worldname.charAt(worldname.length() - 37) == ' ') { + StringBuilder myName = new StringBuilder(worldname); + myName.setCharAt(worldname.length() - 37, '-'); + world.renameTo(new File(Bukkit.getWorldContainer(), myName.toString())); + worldname = myName.toString(); + } + // Teleport the Player + World worldinserver = Bukkit.createWorld(new WorldCreator(worldname)); + Bukkit.getServer().getWorlds().add(worldinserver); + w = worldinserver; + if (PluginConfig.isSurvival()) { + p.setGameMode(GameMode.SURVIVAL); + } else { + p.setGameMode(GameMode.CREATIVE); + } + if (PluginConfig.useWorldSpawn()) { + p.teleport(PluginConfig.getWorldSpawn(w)); + } else { + p.teleport(w.getSpawnLocation()); + } + } + + /** + * Trys to create a new systemworld with all entries etc. + * finally loads the world + * @param p Player to create the world for + * @return whether it succesfull or not + */ + public static boolean create(Player p) { + DependenceConfig dc = new DependenceConfig(p); + WorldCreateEvent event = new WorldCreateEvent(p); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return false; + if (!dc.createNewEntry()) { + int i = WorldSystem.getMaxWorlds(); + p.sendMessage(PluginConfig.getPrefix() + "§cThis Server is limited to " + i + " worlds. Sorry :("); + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cThe Server is limited to " + i + + " worlds. If you want more, contact me"); + return false; + } + int id = dc.getHighestID(); + String worlddir = PluginConfig.getWorlddir(); + File exampleworld = new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName()); + if (new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName() + "/uid.dat") + .exists()) { + new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName() + "/uid.dat").delete(); + } + String uuid = p.getUniqueId().toString(); + String worldname = "ID" + id + "-" + uuid; + File newworld = new File(worlddir + "/" + worldname); + try { + FileUtils.copyDirectory(exampleworld, newworld); + } catch (IOException e) { + System.err.println("Couldn't create world for " + p.getName()); + e.printStackTrace(); + } + WorldConfig2 wc = new WorldConfig2(); + wc.createConfig(p); + if (PluginConfig.getExampleWorldName() == null || PluginConfig.getExampleWorldName().equals("") + || !exampleworld.exists()) { + // Move World into Server dir + File world = new File(worlddir + "/" + worldname); + if (!world.exists()) { + world = new File(Bukkit.getWorldContainer(), worldname); + } else { + if (new File(Bukkit.getWorldContainer(), worldname).exists() + && new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) { + try { + FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname)); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false); + } catch (IOException e) { + System.err.println("Couldn't load world of " + p.getName()); + e.printStackTrace(); + } + } + World worldinserver = Bukkit.createWorld(new WorldCreator(worldname)); + Bukkit.getServer().getWorlds().add(worldinserver); + } + return true; + } + + + /** + *@return if the world is loaded + */ + public boolean isLoaded() { + File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + World w = Bukkit.getWorld(worldname); + if (worldAsDir.exists() && w != null) + return true; + return false; + } + + private boolean exists() { + File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (worldAsDir.exists()) { + return true; + } + worldAsDir = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + if (worldAsDir.exists()) { + return true; + } + return false; + } + + /** + * Teleports the player to the world with the given settings in the config + * @param p player to teleport + * @exception NullPointerException if player is null + * @exception IllegalArgumentException if player is not online + */ + public void teleportToWorldSpawn(Player p) { + Preconditions.checkNotNull(p, "player must not be null"); + Preconditions.checkArgument(p.isOnline(), "player must be online"); + unloading = false; + w = Bukkit.getWorld(worldname); + if (w == null) + return; + if (PluginConfig.useWorldSpawn()) { + p.teleport(PluginConfig.getWorldSpawn(w)); + } else { + p.teleport(w.getSpawnLocation()); + } + if (PluginConfig.isSurvival()) { + p.setGameMode(GameMode.SURVIVAL); + } else { + p.setGameMode(GameMode.CREATIVE); + } + } + + /** + * @return the world + */ + public World getWorld() { + return w; + } + + /** + * @return the worldname + */ + public String getName() { + return worldname; + } +} \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java b/WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java new file mode 100644 index 0000000..aa29bab --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/wrapper/WorldPlayer.java @@ -0,0 +1,233 @@ +package de.butzlabben.world.wrapper; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import com.google.common.base.Preconditions; + +import de.butzlabben.world.config.PluginConfig; + +public class WorldPlayer { + + private OfflinePlayer p; + private String worldname; + + /** + * @return the worldname, where the worldplayer object was created for + */ + public String getWorldname() { + return worldname; + } + + /** + * toggles building for this player + * @return whether can build or not + */ + public boolean toggleBuild() { + Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) { + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + if (cfg.getString("Members." + uuid + ".PlayerUUID") == null) + return false; + + boolean teleport = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); + teleport = !teleport; + cfg.set("Members." + uuid + ".Permissions.CanBuild", teleport); + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + return teleport; + } + + /** + * @return whether can build or not + */ + public boolean canBuild() { + Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); + return b; + } + + /** + * toggles teleporting for this player + * @return whether can teleport or not + */ + public boolean toggleTeleport() { + Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) { + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + if (cfg.getString("Members." + uuid + ".PlayerUUID") == null) + return false; + + boolean teleport = cfg.getBoolean("Members." + uuid + ".Permissions.CanTP"); + teleport = !teleport; + cfg.set("Members." + uuid + ".Permissions.CanTP", teleport); + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + return teleport; + } + + /** + * @return whether can teleport or not + */ + public boolean canTeleport() { + Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanTP"); + return b; + } + + /** + * toggles gamemode changing for this player + * @return whether can change his gamemode or not + */ + public boolean toggleGamemode() { + Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!file.exists()) { + file = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + if (cfg.getString("Members." + uuid + ".PlayerUUID") == null) + return false; + + boolean changeGamemode = cfg.getBoolean("Members." + uuid + ".Permissions.ChangeGM"); + changeGamemode = !changeGamemode; + cfg.set("Members." + uuid + ".Permissions.ChangeGM", changeGamemode); + try { + cfg.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + return changeGamemode; + } + + /** + * @return whether can change his gamemode or not + */ + public boolean canChangeGamemode() { + Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); + File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + String uuid = p.getUniqueId().toString(); + boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.ChangeGM"); + return b; + } + + /** + * @return if he is a member + */ + public boolean isMember() { + Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); + File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!worldconfig.exists()) { + worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); + String uuid = p.getUniqueId().toString(); + if (uuid.equals(cfg.getString("Members." + uuid + ".PlayerUUID"))) { + cfg.set("Members." + uuid + ".ActualName", p.getName()); + try { + cfg.save(worldconfig); + } catch (IOException e) { + e.printStackTrace(); + } + return true; + } + return false; + } + + public WorldPlayer(OfflinePlayer p, String worldname) { + this.p = p; + this.worldname = worldname; + } + + public WorldPlayer(Player p) { + this(p, p.getWorld().getName()); + } + + /** + * @return if he is on a systemworld or not + */ + public boolean isOnSystemWorld() { + File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (worldconfig.exists()) { + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); + if(cfg.getString("Informations.Owner.PlayerUUID") == null) { + return false; + } + return true; + } + return false; + } + + /** + * @return the given player + */ + public OfflinePlayer getPlayer() { + return p; + } + + + /** + * @return if he ist the owner + */ + public boolean isOwnerofWorld() { + File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); + if (p.getUniqueId().toString().equals(cfg.getString("Informations.Owner.PlayerUUID"))) { + String playerName = p.getName(); + cfg.set("Informations.Owner.ActualName", playerName); + try { + cfg.save(worldconfig); + } catch (IOException e) { + e.printStackTrace(); + } + return true; + } else { + return false; + } + } + + /** + * @param worldname of the world to be tested + * @return worldname if he is the owner of the specified world + */ + public boolean isMemberofWorld(String worldname) { + File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); + if (!worldconfig.exists()) { + worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); + String uuid = p.getUniqueId().toString(); + if (uuid.equals(cfg.getString("Members." + uuid + ".PlayerUUID"))) { + return true; + } + return false; + } + +} diff --git a/WorldSystem/src/en.yml b/WorldSystem/src/en.yml new file mode 100644 index 0000000..870569b --- /dev/null +++ b/WorldSystem/src/en.yml @@ -0,0 +1,80 @@ +nopermission: "&cYou don't have permissions!" +unknown_error: "&cSomething went wrong..." +lagdetection: "Lagdetection in world: &c%world" +wrong_usage: "&c%usage" +not_registered: "&cThis player hasn't joined yet!" + +world: + reseted: "Your world was reseted!" + still_loaded: "&cYour world is still loaded!" + not_on: "&cYou are not on a world!" + created: "Your world is now ready. Get there with &a/ws home" + already_exists: "&cYou already have a world!" + delete: + own: "&cYour world was deleted!" + other: "You deleted the world of &c%player&6!" + does_not_exists: + own: "&cYou don't have a world!" + other: "&cThis player doesn't has a world!" + setting_up: "&aSetting up world..." + playerlist: "Player in this world: %players" + +member: + removed: "You removed &c%player&6 from your world!" + added: "You have added &c%player&6 to your world!" + already_added: "&cThis player is already a member!" + not_added: + own: "&cThis player isn't a member!" + other: "&cYou are not added to this world" + +request: + expired: "&cYou request is expired!" + confirm: "&cPlease confirm reset of your world: %command" + until_expire: "&cYour request expires in %time seconds!" + already_sent: "&cYou already sent a request!" + not_sent: "&cYou didn't send a request!" + invalid_input: "&c%input is not a valid input!" + +toggle: + gamemode: + enabled: "&a%player&6 can now change his gamemode!" + disabled: "&c%player&6 can no longer change his gamemode!" + teleport: + enabled: "&a%player&6 can now teleport!" + disabled: "&c%player&6 can no longer teleport!" + build: + enabled: "&a%player&6 can now build!" + disabled: "&c%player&6 can no longer build!" + fire: + enabled: "&aYou activated fire!" + disabled: "&cYou deactivated fire!" + tnt: + enabled: "&aYou activated TNT-Damage!" + disabled: "&cYou deactivated TNT-Damage!" + +info: + owner: "Owner: %data" + id: "ID: %data" + member: "Member: %data" + tnt: "TNT: %data" + fire: "Fire: %data" + enabled: "&aOn" + disabled: "&cOff" + +command_help: + list: + - "/ws get &8- &7Will give you a world" + - "/ws home &8- &7Teleports you on your world" + - "/ws gui &8- &7Opens the GUI menu if you are the worldowner" + - "/ws tp &8- &7Teleports you on a specific world" + - "/ws addmember &8- &7Adds a player to your world" + - "/ws delmember &8- &7Removes a player from your world" + - "/ws leave &8- &7Leave a world" + - "/ws tnt &8- &7Allows/Denys TNT on your world" + - "/ws fire &8- &7Allows/Denys Fire on your world" + - "/ws togglegm &8- &7Allows/Denys a player changing gamemode" + - "/ws togglebuild &8- &7Allows/Denys a player building" + - "/ws toggletp &8- &7Allows/Denys a player teleporting" + - "/ws info &8- &7Shows information about the world" + - "/ws reset &8- &7Will reset your world" + delete_command: "/ws delete &8- &7Will delete a world" \ No newline at end of file diff --git a/WorldSystem/src/gui.yml b/WorldSystem/src/gui.yml new file mode 100644 index 0000000..df918df --- /dev/null +++ b/WorldSystem/src/gui.yml @@ -0,0 +1,263 @@ +# +# Config for the GUI "/gui" +# Counting for rows and columns starts always at 1 +# + +options: + + # How the enabled item should look like + enabled: + # ItemID, for seeing them press F3 + H + material: 351 + # Data, how it should look like eg. blue, red, green + data: 10 + # Displayname + display: '&aEnabled' + + # How the disabled item should look like + disabled: + material: 351 + data: 1 + display: '&cDisabled' + + # How the comming-soon item should look like + coming_soon: + material: 351 + data: 14 + display: '&6Coming soon...' + + # WorldoptionsGUI + world: + # Rows + rows: 2 + # Reset button + reset: + # If feature should be enabled or not + enabled: true + slot: + row: 1 + col: 8 + material: 293 + data: 0 + display: '&eReset World' + + # Fire button + fire: + enabled: true + slot: + row: 1 + col: 2 + # Where the state item should be + state: + row: 2 + col: 2 + material: 259 + data: 0 + display: '&eToggle Fire' + + # TNT button + tnt: + enabled: true + slot: + row: 1 + col: 5 + state: + row: 2 + col: 5 + material: 46 + data: 0 + display: '&eToggle TNT-Explosion' + + players: + rows: 6 + nextpage: + enabled: true + slot: + row: 6 + col: 9 + material: 175 + data: 0 + display: '&eNext Page' + pagebefore: + enabled: true + slot: + row: 6 + col: 1 + material: 175 + data: 0 + display: '&ePage before' + currentpage: + enabled: true + slot: + row: 6 + col: 5 + material: 339 + data: 0 + display: '&eCurrent page: %page' + player_list_to_row: 4 + playerhead: + display: '&e%player' + + # PlayerGUI for managing one player on a world + player: + rows: 2 + build: + enabled: true + slot: + row: 1 + col: 1 + state: + row: 2 + col: 1 + material: 286 + data: 0 + display: '&eToggle Build-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To build on this world' + gamemode: + enabled: true + slot: + row: 1 + col: 2 + state: + row: 2 + col: 2 + material: 426 + data: 0 + display: '&eToggle GameMode-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To change the GameMode on this world' + teleport: + enabled: true + slot: + row: 1 + col: 3 + state: + row: 2 + col: 3 + material: 345 + data: 0 + display: '&eToggle Teleport-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To teleport on this world' + time: + enabled: false + slot: + row: 1 + col: 4 + state: + row: 2 + col: 4 + material: 347 + data: 0 + display: '&eToggle Time-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To change the time on this world' + worldborder: + enabled: false + slot: + row: 1 + col: 5 + state: + row: 2 + col: 5 + material: 345 + data: 0 + display: '&eToggle Worldborder-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To change the worldborder on this world' + addmember: + enabled: false + slot: + row: 1 + col: 6 + state: + row: 2 + col: 6 + material: 399 + data: 0 + display: '&eToggle Addmember-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To add a member to this world' + delmember: + enabled: false + slot: + row: 1 + col: 6 + state: + row: 2 + col: 6 + material: 286 + data: 0 + display: '&eToggle Delmember-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To remove a member from this world' + addmember: + enabled: false + slot: + row: 1 + col: 7 + state: + row: 2 + col: 7 + material: 399 + data: 0 + display: '&eToggle Addmember-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To add a member to this world' + setpermissions: + enabled: false + slot: + row: 1 + col: 8 + state: + row: 2 + col: 8 + material: 331 + data: 0 + display: '&eToggle Setpermissions-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To set permissions for a member of this world' + administrateworld: + enabled: false + slot: + row: 1 + col: 9 + state: + row: 2 + col: 9 + material: 421 + data: 0 + display: '&eToggle Addmember-Permission' + lore: + - '&7Toggles the permission for a player' + - '&7To adminstrate this world' + +# WorldsystemGUI +worldsystem: + rows: 1 + playeroptions: + enabled: true + slot: + row: 1 + col: 4 + material: 298 + data: 0 + display: '&ePlayer Options' + worldoptions: + enabled: true + slot: + row: 1 + col: 6 + material: 2 + data: 0 + display: '&eWorld Options' \ No newline at end of file diff --git a/WorldSystem/src/hu.yml b/WorldSystem/src/hu.yml new file mode 100644 index 0000000..5123c88 --- /dev/null +++ b/WorldSystem/src/hu.yml @@ -0,0 +1,80 @@ +nopermission: "&cNincs jogod ehhez!" +unknown_error: "&cValami elromlott..." +lagdetection: "Lagdetection a világban: &c%world" +wrong_usage: "&c%usage" +not_registered: "&cEz a játékos még nem csatlakozott!" + +world: + reseted: "A világod vissza lett állítva!" + still_loaded: "&cA világod még mindig be van töltve!" + not_on: "&cNem vagy a világon!" + created: "A világod készen áll. Szállj fel a &a/ws home" + already_exists: "&cMár van világod!" + delete: + own: "&cA világot törölve!" + other: "Törölte a világot &c%player&6 játékostól!" + does_not_exists: + own: "&cNincs világod!" + other: "&cEz a játékos nem rendelkezik világgal!" + setting_up: "&aA világ megteremtése..." + playerlist: "Játékos ebben a világban: %player" + +member: + removed: "Törölted &c%player&6 játékost a világodból!" + added: "Hozzáadtad &c%player&6 játékost a világodhoz!" + already_added: "&cEz a játékos már tagja!" + not_added: + own: "&cEz a játékos nem tagja!" + other: "&cNem vagy hozzáadva ehhez a világhoz" + +request: + expired: "&cA kérelem lejárt!" + confirm: "&cKérjük, erősítsd meg a világ újraindítását: %command" + until_expire: "&cA kérés lejárati ideje %time másodperc!" + already_sent: "&cMár elküldtél egy kérelmet!" + not_sent: "&cNem küldtél kérést!" + invalid_input: "&c%input nem érvényes bemenet!" + +toggle: + gamemode: + enabled: "&a%player&6 most megváltoztathatja játékmódját!" + disabled: "&c%player&6 már nem tudja megváltoztatni játékmódját!" + teleport: + enabled: "&a%player&6 most teleportálhat!" + disabled: "&c%player&6 már nem teleportálhat!" + build: + enabled: "&a%player&6 most építhet!" + disabled: "&c%player&6 már nem építhet!" + fire: + enabled: "&aAktiváltad a tüzet!" + disabled: "&cDeaktiváltad a tüzet!" + tnt: + enabled: "&aAktiváltad a TNT-sebzést!" + disabled: "&cDeaktiváltad TNT-sebzést!" + +info: + owner: "Tulajdonos: %data" + id: "ID: %data" + member: "Tag: %data" + tnt: "TNT: %data" + fire: "Tűz: %data" + enabled: "&aBe" + disabled: "&cKi" + +command_help: + list: + - "/ws get &8- &7Will give you a world" + - "/ws home &8- &7Teleports you on your world" + - "/ws gui &8- &7Opens the GUI menu if you are the worldowner" + - "/ws tp &8- &7Teleports you on a specific world" + - "/ws addmember &8- &7Adds a player to your world" + - "/ws delmember &8- &7Removes a player from your world" + - "/ws leave &8- &7Leave a world" + - "/ws tnt &8- &7Allows/Denys TNT on your world" + - "/ws fire &8- &7Allows/Denys Fire on your world" + - "/ws togglegm &8- &7Allows/Denys a player changing gamemode" + - "/ws togglebuild &8- &7Allows/Denys a player building" + - "/ws toggletp &8- &7Allows/Denys a player teleporting" + - "/ws info &8- &7Shows information about the world" + - "/ws reset &8- &7Will reset your world" + delete_command: "/ws delete &8- &7Will delete a world" \ No newline at end of file diff --git a/WorldSystem/src/nl.yml b/WorldSystem/src/nl.yml new file mode 100644 index 0000000..ca67cef --- /dev/null +++ b/WorldSystem/src/nl.yml @@ -0,0 +1,80 @@ +nopermission: "&cJij hebt geen rechten om dit te doen!" +unknown_error: "&cEr is iets verkeerd gegaan.." +lagdetection: "Lag gededecteerd in wereld: &c%world" +wrong_usage: "&c%gebruik" +not_registered: "&cDeze speler heeft nog nooit gejoined!" + +world: + reseted: "Jouw wereld is gereset!" + still_loaded: "&cJouw wereld is nog steeds geladen!" + not_on: "&cJij bent niet in een wereld!" + created: "Jouw wereld is gemaakt gebruik: &a/ws home" + already_exists: "&cJij hebt al een wereld!" + delete: + own: "&cJouw wereld is verwijderd!" + other: "Jij hebt de wereld verwijderd van: &c%player&6!" + does_not_exists: + own: "&cJij hebt nog geen wereld!" + other: "&cDeze speler heeft nog geen wereld!" + setting_up: "&aWereld word aangemaakt" + playerlist: "speler is in wereld: %players" + +member: + removed: "Jij hebt &c%player&6 verwijderd van jouw wereld!" + added: "Jij hebt &c%player&6 toegevoegd aan jouw wereld!" + already_added: "&cDeze speler is al toegevoegd!" + not_added: + own: "&cDeze speler is nog niet toegevoegd!" + other: "&cJij bent niet aan deze wereld toegevoegd" + +request: + expired: "&cJouw uitnodiging is verlopen!" + confirm: "&cBevestig het verwijderen van jouw wereld: %command" + until_expire: "&cJouw uitnodiging verloopt over %time seconden!" + already_sent: "&cJij hebt al een uitnodiging verstuurd!" + not_sent: "&cJij hebt geen uitnodiging gestuurd!" + invalid_input: "&c%input is niet een command!" + +toggle: + gamemode: + enabled: "&a%player&6 kan nu zijn spelermodus veranderen!" + disabled: "&c%player&6 kan niet meer zijn spelermodus veranderen!" + teleport: + enabled: "&a%player&6 kan nu teleporteren!" + disabled: "&c%player&6 kan nu niet meer teleporteren!" + build: + enabled: "&a%player&6 kan nu bouwen!" + disabled: "&c%player&6 kan nu niet meer bouwen!" + fire: + enabled: "&aJij hebt vuur geactiveert!" + disabled: "&cJij hebt vuur gedeactiveerd!" + tnt: + enabled: "&aJij hebt TNT-schade geactiveerd!" + disabled: "&cJij hebt TNT-schade gedeactiveerd!" + +info: + owner: "Owner: %data" + id: "ID: %data" + member: "Toegevoegd: %data" + tnt: "TNT: %data" + fire: "Vuur: %data" + enabled: "&Aan" + disabled: "&cUit" + +command_help: + list: + - "/ws get &8- &7Will give you a world" + - "/ws home &8- &7Teleports you on your world" + - "/ws gui &8- &7Opens the GUI menu if you are the worldowner" + - "/ws tp &8- &7Teleports you on a specific world" + - "/ws addmember &8- &7Adds a player to your world" + - "/ws delmember &8- &7Removes a player from your world" + - "/ws leave &8- &7Leave a world" + - "/ws tnt &8- &7Allows/Denys TNT on your world" + - "/ws fire &8- &7Allows/Denys Fire on your world" + - "/ws togglegm &8- &7Allows/Denys a player changing gamemode" + - "/ws togglebuild &8- &7Allows/Denys a player building" + - "/ws toggletp &8- &7Allows/Denys a player teleporting" + - "/ws info &8- &7Shows information about the world" + - "/ws reset &8- &7Will reset your world" + delete_command: "/ws delete &8- &7Will delete a world" \ No newline at end of file diff --git a/WorldSystem/src/org/bstats/bukkit/Metrics.java b/WorldSystem/src/org/bstats/bukkit/Metrics.java new file mode 100644 index 0000000..cd8a660 --- /dev/null +++ b/WorldSystem/src/org/bstats/bukkit/Metrics.java @@ -0,0 +1,677 @@ +package org.bstats.bukkit; + +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.ServicePriority; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import javax.net.ssl.HttpsURLConnection; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.zip.GZIPOutputStream; + +/** + * bStats collects some data for plugin authors. + * + * Check out https://bStats.org/ to learn more about bStats! + */ +public class Metrics { + + static { + // You can use the property to disable the check in your test environment + if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { + // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D + final String defaultPackage = "org.bstats.bukkit"; + final String examplePackage = ""; + // We want to make sure nobody just copy & pastes the example and use the wrong package names + if (!Metrics.class.getPackage().getName().equals(defaultPackage) && !Metrics.class.getPackage().getName().equals(examplePackage)) { + throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); + } + } + } + + // The version of this bStats class + public static final int B_STATS_VERSION = 1; + + // The url to which the data is sent + private static final String URL = "https://bStats.org/submitData/bukkit"; + + // Should failed requests be logged? + private static boolean logFailedRequests; + + // The uuid of the server + private static String serverUUID; + + // The plugin + private final JavaPlugin plugin; + + // A list with all custom charts + private final List charts = new ArrayList<>(); + + /** + * Class constructor. + * + * @param plugin The plugin which stats should be submitted. + */ + public Metrics(JavaPlugin plugin) { + if (plugin == null) { + throw new IllegalArgumentException("Plugin cannot be null!"); + } + this.plugin = plugin; + + // Get the config file + File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + File configFile = new File(bStatsFolder, "config.yml"); + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + + // Check if the config file exists + if (!config.isSet("serverUuid")) { + + // Add default values + config.addDefault("enabled", true); + // Every server gets it's unique random id. + config.addDefault("serverUuid", UUID.randomUUID().toString()); + // Should failed request be logged? + config.addDefault("logFailedRequests", false); + + // Inform the server owners about bStats + config.options().header( + "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + + "To honor their work, you should not disable it.\n" + + "This has nearly no effect on the server performance!\n" + + "Check out https://bStats.org/ to learn more :)" + ).copyDefaults(true); + try { + config.save(configFile); + } catch (IOException ignored) { } + } + + // Load the data + serverUUID = config.getString("serverUuid"); + logFailedRequests = config.getBoolean("logFailedRequests", false); + if (config.getBoolean("enabled", true)) { + boolean found = false; + // Search for all other bStats Metrics classes to see if we are the first one + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + found = true; // We aren't the first + break; + } catch (NoSuchFieldException ignored) { } + } + // Register our service + Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); + if (!found) { + // We are the first! + startSubmitting(); + } + } + } + + /** + * Adds a custom chart. + * + * @param chart The chart to add. + */ + public void addCustomChart(CustomChart chart) { + if (chart == null) { + throw new IllegalArgumentException("Chart cannot be null!"); + } + charts.add(chart); + } + + /** + * Starts the Scheduler which submits our data every 30 minutes. + */ + private void startSubmitting() { + final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if (!plugin.isEnabled()) { // Plugin was disabled + timer.cancel(); + return; + } + // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler + // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) + Bukkit.getScheduler().runTask(plugin, new Runnable() { + @Override + public void run() { + submitData(); + } + }); + } + }, 1000*60*5, 1000*60*30); + // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start + // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! + // WARNING: Just don't do it! + } + + /** + * Gets the plugin specific data. + * This method is called using Reflection. + * + * @return The plugin specific data. + */ + @SuppressWarnings("unchecked") + public JSONObject getPluginData() { + JSONObject data = new JSONObject(); + + String pluginName = plugin.getDescription().getName(); + String pluginVersion = plugin.getDescription().getVersion(); + + data.put("pluginName", pluginName); // Append the name of the plugin + data.put("pluginVersion", pluginVersion); // Append the version of the plugin + JSONArray customCharts = new JSONArray(); + for (CustomChart customChart : charts) { + // Add the data of the custom charts + JSONObject chart = customChart.getRequestJsonObject(); + if (chart == null) { // If the chart is null, we skip it + continue; + } + customCharts.add(chart); + } + data.put("customCharts", customCharts); + + return data; + } + + /** + * Gets the server specific data. + * + * @return The server specific data. + */ + @SuppressWarnings("unchecked") + private JSONObject getServerData() { + // Minecraft specific data + int playerAmount; + try { + // Around MC 1.8 the return type was changed to a collection from an array, + // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; + Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) + ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() + : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; + } catch (Exception e) { + playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed + } + int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; + String bukkitVersion = org.bukkit.Bukkit.getVersion(); + bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1); + + // OS/Java specific data + String javaVersion = System.getProperty("java.version"); + String osName = System.getProperty("os.name"); + String osArch = System.getProperty("os.arch"); + String osVersion = System.getProperty("os.version"); + int coreCount = Runtime.getRuntime().availableProcessors(); + + JSONObject data = new JSONObject(); + + data.put("serverUUID", serverUUID); + + data.put("playerAmount", playerAmount); + data.put("onlineMode", onlineMode); + data.put("bukkitVersion", bukkitVersion); + + data.put("javaVersion", javaVersion); + data.put("osName", osName); + data.put("osArch", osArch); + data.put("osVersion", osVersion); + data.put("coreCount", coreCount); + + return data; + } + + /** + * Collects the data and sends it afterwards. + */ + @SuppressWarnings("unchecked") + private void submitData() { + final JSONObject data = getServerData(); + + JSONArray pluginData = new JSONArray(); + // Search for all other bStats Metrics classes to get their plugin data + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + + for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { + try { + pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider())); + } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } + } + } catch (NoSuchFieldException ignored) { } + } + + data.put("plugins", pluginData); + + // Create a new thread for the connection to the bStats server + new Thread(new Runnable() { + @Override + public void run() { + try { + // Send the data + sendData(data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); + } + } + } + }).start(); + } + + /** + * Sends the data to the bStats server. + * + * @param data The data to send. + * @throws Exception If the request failed. + */ + private static void sendData(JSONObject data) throws Exception { + if (data == null) { + throw new IllegalArgumentException("Data cannot be null!"); + } + if (Bukkit.isPrimaryThread()) { + throw new IllegalAccessException("This method must not be called from the main thread!"); + } + HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); + + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + + // Add headers + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format + connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); + + // Send data + connection.setDoOutput(true); + DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); + outputStream.write(compressedData); + outputStream.flush(); + outputStream.close(); + + connection.getInputStream().close(); // We don't care about the response - Just send our data :) + } + + /** + * Gzips the given String. + * + * @param str The string to gzip. + * @return The gzipped String. + * @throws IOException If the compression failed. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + GZIPOutputStream gzip = new GZIPOutputStream(outputStream); + gzip.write(str.getBytes("UTF-8")); + gzip.close(); + return outputStream.toByteArray(); + } + + /** + * Represents a custom chart. + */ + public static abstract class CustomChart { + + // The id of the chart + final String chartId; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + */ + CustomChart(String chartId) { + if (chartId == null || chartId.isEmpty()) { + throw new IllegalArgumentException("ChartId cannot be null or empty!"); + } + this.chartId = chartId; + } + + @SuppressWarnings("unchecked") + private JSONObject getRequestJsonObject() { + JSONObject chart = new JSONObject(); + chart.put("chartId", chartId); + try { + JSONObject data = getChartData(); + if (data == null) { + // If the data is null we don't send the chart. + return null; + } + chart.put("data", data); + } catch (Throwable t) { + if (logFailedRequests) { + Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); + } + return null; + } + return chart; + } + + protected abstract JSONObject getChartData() throws Exception; + + } + + /** + * Represents a custom simple pie. + */ + public static class SimplePie extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimplePie(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @SuppressWarnings("unchecked") + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + String value = callable.call(); + if (value == null || value.isEmpty()) { + // Null = skip the chart + return null; + } + data.put("value", value); + return data; + } + } + + /** + * Represents a custom advanced pie. + */ + public static class AdvancedPie extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedPie(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @SuppressWarnings("unchecked") + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + continue; // Skip this invalid + } + allSkipped = false; + values.put(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + } + + /** + * Represents a custom drilldown pie. + */ + public static class DrilldownPie extends CustomChart { + + private final Callable>> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public DrilldownPie(String chartId, Callable>> callable) { + super(chartId); + this.callable = callable; + } + + @SuppressWarnings("unchecked") + @Override + public JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map> map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean reallyAllSkipped = true; + for (Map.Entry> entryValues : map.entrySet()) { + JSONObject value = new JSONObject(); + boolean allSkipped = true; + for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { + value.put(valueEntry.getKey(), valueEntry.getValue()); + allSkipped = false; + } + if (!allSkipped) { + reallyAllSkipped = false; + values.put(entryValues.getKey(), value); + } + } + if (reallyAllSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + } + + /** + * Represents a custom single line chart. + */ + public static class SingleLineChart extends CustomChart { + + private final Callable callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SingleLineChart(String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } + + @SuppressWarnings("unchecked") + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + int value = callable.call(); + if (value == 0) { + // Null = skip the chart + return null; + } + data.put("value", value); + return data; + } + + } + + /** + * Represents a custom multi line chart. + */ + public static class MultiLineChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public MultiLineChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @SuppressWarnings("unchecked") + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + continue; // Skip this invalid + } + allSkipped = false; + values.put(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + + } + + /** + * Represents a custom simple bar chart. + */ + public static class SimpleBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimpleBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @SuppressWarnings("unchecked") + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + for (Map.Entry entry : map.entrySet()) { + JSONArray categoryValues = new JSONArray(); + categoryValues.add(entry.getValue()); + values.put(entry.getKey(), categoryValues); + } + data.put("values", values); + return data; + } + + } + + /** + * Represents a custom advanced bar chart. + */ + public static class AdvancedBarChart extends CustomChart { + + private final Callable> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedBarChart(String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } + + @SuppressWarnings("unchecked") + @Override + protected JSONObject getChartData() throws Exception { + JSONObject data = new JSONObject(); + JSONObject values = new JSONObject(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().length == 0) { + continue; // Skip this invalid + } + allSkipped = false; + JSONArray categoryValues = new JSONArray(); + for (int categoryValue : entry.getValue()) { + categoryValues.add(categoryValue); + } + values.put(entry.getKey(), categoryValues); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + data.put("values", values); + return data; + } + + } +} \ No newline at end of file diff --git a/WorldSystem/src/plugin.yml b/WorldSystem/src/plugin.yml new file mode 100644 index 0000000..50ed22c --- /dev/null +++ b/WorldSystem/src/plugin.yml @@ -0,0 +1,113 @@ +name: WorldSystem +version: 2.0 +author: Butzlabben +main: de.butzlabben.world.WorldSystem + +commands: + ws: + description: Commands for WorldSystem + aliases: [worldsystem, world, worlds] + usage: /ws + ws get: + aliases: [worldsystem get, world get, worlds get] + usage: /ws get + ws help: + aliases: [worldsystem help, world help, worlds help] + usage: /ws help + ws home: + aliases: [worldsystem home, world home, worlds home] + usage: /ws home + ws addmember: + aliases: [worldsystem addmember, world addmember, worlds addmember] + usage: /ws addmember + ws delmember: + aliases: [worldsystem delmember, world delmember, worlds delmember] + usage: /ws delmember + ws leave: + aliases: [worldsystem leave, world leave, worlds leave] + usage: /ws leave + ws tp: + aliases: [worldsystem tp, world tp, worlds tp] + usage: /ws tp + ws tnt: + aliases: [worldsystem tnt, world tnt, worlds tnt] + usage: /ws tnt + ws fire: + aliases: [worldsystem, world fire, worlds fire] + usage: /ws fire + ws info: + aliases: [worldsystem info, world info, worlds info] + usage: /ws info + ws togglebuild: + aliases: [worldsystem togglebuild, world togglebuild, worlds togglebuild] + usage: /ws togglebuild + ws togglegm: + aliases: [worldsystem togglegm, world togglegm, worlds togglegm] + usage: /ws togglegm + ws toggletp: + aliases: [worldsystem toggletp, world toggletp, worlds toggletp] + usage: /ws toggletp + ws reset: + aliases: [worldsystem reset, world reset, worlds reset] + usage: /ws reset + ws gui: + aliases: [worldsystem gui, world gui, worlds gui] + usage: /ws gui + ws delete: + aliases: [worldsystem delete, world delete, worlds delete] + usage: /ws delete + permission: ws.delete + +permissions: + ws.*: + default: op + description: Gives '*'-Perms to all Commands + children: + ws.tp.*: true + ws.tp.world: true + ws.tp.toother: true + ws.tp.other: true + ws.build: true + ws.gamemode: true + ws.delete: true + ws.lag: true + ws.big: true + ws.large: true + ws.tp.*: + default: op + description: You can teleport everything + children: + ws.tp.toother: true + ws.tp.other: true + ws.tp.world: true + ws.build: + default: op + description: You can build on other Worlds without WorldPermissions + ws.delete: + default: op + description: You can delete a world + ws.gamemode: + default: op + description: You can change GameMode on other worlds + ws.tp.other: + default: op + description: You can teleport other persons + ws.tp.toother: + default: op + description: You can teleport across worlds + ws.tp.world: + default: op + description: You can teleport to without rights World + ws.lag: + default: op + description: You can see lag messages + ws.big: + default: op + description: Gives you a bigger world (if set) + ws.large: + default: op + children: + ws.big: true + description: Gives you a even bigger world (if set) + +default-permission: admin \ No newline at end of file diff --git a/WorldSystem/src/settings.yml b/WorldSystem/src/settings.yml new file mode 100644 index 0000000..a630b02 --- /dev/null +++ b/WorldSystem/src/settings.yml @@ -0,0 +1,48 @@ +# Center will be at the spawn or the worldspawn +worldborder: + # If WorldSystem should change the worldborder + should_change: true + # Default size + normal: 1000 + # Size with ws.big permission + big: 2000 + # Size with ws.large permission + large: 5000 + + # Set a specialized center wich is not the spawn + center: + as_spawn: true + x: 0 + y: 20 + z: 0 + +# All Gamerules in 1.12 +# Not supported gamerules will be ignored +# +# If you need help, look at +# https://minecraft.gamepedia.com/Commands/gamerule + +announceAdvancements: true +commandBlockOutput: false +disableElytraMovementCheck: false +doDaylightCycle: false +doEntityDrops: true +doFireTick: true +doLimitedCrafting: false +doMobLoot: true +doMobSpawning: true +doTileDrops: false +doWeatherCycle: false +gameLoopFunction: false +keepInventory: true +logAdminCommands: true +maxCommandChainLength: 65536 +maxEntityCramming: 24 +mobGriefing: true +naturalRegeneration: true +randomTickSpeed: 3 +reducedDebugInfo: false +sendCommandFeedback: true +showDeathMessages: true +spawnRadius: 10 +spectatorsGenerateChunks: true \ No newline at end of file