callable) {
+ super(chartId);
+ this.callable = callable;
+ }
+
+ @Override
+ protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
+ int value = callable.call();
+ if (value == 0) {
+ // Null = skip the chart
+ return null;
+ }
+ return new JsonObjectBuilder().appendField("value", value).build();
+ }
+ }
+
+ /**
+ * An extremely simple JSON builder.
+ *
+ * While this class is neither feature-rich nor the most performant one, it's sufficient enough
+ * for its use-case.
+ */
+ public static class JsonObjectBuilder {
+
+ private StringBuilder builder = new StringBuilder();
+
+ private boolean hasAtLeastOneField = false;
+
+ public JsonObjectBuilder() {
+ builder.append("{");
+ }
+
+ /**
+ * Appends a null field to the JSON.
+ *
+ * @param key The key of the field.
+ * @return A reference to this object.
+ */
+ public JsonObjectBuilder appendNull(String key) {
+ appendFieldUnescaped(key, "null");
+ return this;
+ }
+
+ /**
+ * Appends a string field to the JSON.
+ *
+ * @param key The key of the field.
+ * @param value The value of the field.
+ * @return A reference to this object.
+ */
+ public JsonObjectBuilder appendField(String key, String value) {
+ if (value == null) {
+ throw new IllegalArgumentException("JSON value must not be null");
+ }
+ appendFieldUnescaped(key, "\"" + escape(value) + "\"");
+ return this;
+ }
+
+ /**
+ * Appends an integer field to the JSON.
+ *
+ * @param key The key of the field.
+ * @param value The value of the field.
+ * @return A reference to this object.
+ */
+ public JsonObjectBuilder appendField(String key, int value) {
+ appendFieldUnescaped(key, String.valueOf(value));
+ return this;
+ }
+
+ /**
+ * Appends an object to the JSON.
+ *
+ * @param key The key of the field.
+ * @param object The object.
+ * @return A reference to this object.
+ */
+ public JsonObjectBuilder appendField(String key, JsonObject object) {
+ if (object == null) {
+ throw new IllegalArgumentException("JSON object must not be null");
+ }
+ appendFieldUnescaped(key, object.toString());
+ return this;
+ }
+
+ /**
+ * Appends a string array to the JSON.
+ *
+ * @param key The key of the field.
+ * @param values The string array.
+ * @return A reference to this object.
+ */
+ public JsonObjectBuilder appendField(String key, String[] values) {
+ if (values == null) {
+ throw new IllegalArgumentException("JSON values must not be null");
+ }
+ String escapedValues =
+ Arrays.stream(values)
+ .map(value -> "\"" + escape(value) + "\"")
+ .collect(Collectors.joining(","));
+ appendFieldUnescaped(key, "[" + escapedValues + "]");
+ return this;
+ }
+
+ /**
+ * Appends an integer array to the JSON.
+ *
+ * @param key The key of the field.
+ * @param values The integer array.
+ * @return A reference to this object.
+ */
+ public JsonObjectBuilder appendField(String key, int[] values) {
+ if (values == null) {
+ throw new IllegalArgumentException("JSON values must not be null");
+ }
+ String escapedValues =
+ Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
+ appendFieldUnescaped(key, "[" + escapedValues + "]");
+ return this;
+ }
+
+ /**
+ * Appends an object array to the JSON.
+ *
+ * @param key The key of the field.
+ * @param values The integer array.
+ * @return A reference to this object.
+ */
+ public JsonObjectBuilder appendField(String key, JsonObject[] values) {
+ if (values == null) {
+ throw new IllegalArgumentException("JSON values must not be null");
+ }
+ String escapedValues =
+ Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
+ appendFieldUnescaped(key, "[" + escapedValues + "]");
+ return this;
+ }
+
+ /**
+ * Appends a field to the object.
+ *
+ * @param key The key of the field.
+ * @param escapedValue The escaped value of the field.
+ */
+ private void appendFieldUnescaped(String key, String escapedValue) {
+ if (builder == null) {
+ throw new IllegalStateException("JSON has already been built");
+ }
+ if (key == null) {
+ throw new IllegalArgumentException("JSON key must not be null");
+ }
+ if (hasAtLeastOneField) {
+ builder.append(",");
+ }
+ builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
+ hasAtLeastOneField = true;
+ }
+
+ /**
+ * Builds the JSON string and invalidates this builder.
+ *
+ * @return The built JSON string.
+ */
+ public JsonObject build() {
+ if (builder == null) {
+ throw new IllegalStateException("JSON has already been built");
+ }
+ JsonObject object = new JsonObject(builder.append("}").toString());
+ builder = null;
+ return object;
+ }
+
+ /**
+ * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
+ *
+ *
This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
+ * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
+ *
+ * @param value The value to escape.
+ * @return The escaped value.
+ */
+ private static String escape(String value) {
+ final StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < value.length(); i++) {
+ char c = value.charAt(i);
+ if (c == '"') {
+ builder.append("\\\"");
+ } else if (c == '\\') {
+ builder.append("\\\\");
+ } else if (c <= '\u000F') {
+ builder.append("\\u000").append(Integer.toHexString(c));
+ } else if (c <= '\u001F') {
+ builder.append("\\u00").append(Integer.toHexString(c));
+ } else {
+ builder.append(c);
+ }
+ }
+ return builder.toString();
+ }
+
+ /**
+ * A super simple representation of a JSON object.
+ *
+ *
This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
+ * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
+ * JsonObject)}.
+ */
+ public static class JsonObject {
+
+ private final String value;
+
+ private JsonObject(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/spaffel/clans/commands/clanhelp.java b/src/main/java/de/spaffel/clans/commands/clanhelp.java
new file mode 100644
index 0000000..e5ee33c
--- /dev/null
+++ b/src/main/java/de/spaffel/clans/commands/clanhelp.java
@@ -0,0 +1,21 @@
+package de.spaffel.clans.commands;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+
+public class clanhelp implements CommandExecutor {
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ sender.sendMessage("§a <[Commands for Clans by Spaffel]>");
+ sender.sendMessage("§6 /newclan Clanname Password §7|§aTo create a new Clan");
+ sender.sendMessage("§6 /joinclan Clanname Password §7|§aTo join a Clan");
+ sender.sendMessage("§6 /leaveclan §7|§aTo leave a Clan");
+ sender.sendMessage("§6 /setclancolor §7|§aTo set the Color");
+ sender.sendMessage("§6 /clanmsg message §7|§aTo send a Message to all Clan-Members");
+ sender.sendMessage("§6 /setclanbase §7|§aSets you Clanbase");
+ sender.sendMessage("§6 /clanbase §7|§aTeleports you to your Clanbase");
+ sender.sendMessage("§6 /setclanleader §7|§aSets your Clanleader");
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/spaffel/clans/commands/setclanleader.java b/src/main/java/de/spaffel/clans/commands/setclanleader.java
new file mode 100644
index 0000000..bf56f73
--- /dev/null
+++ b/src/main/java/de/spaffel/clans/commands/setclanleader.java
@@ -0,0 +1,37 @@
+package de.spaffel.clans.commands;
+
+import de.spaffel.clans.commands.utils.jsonutil;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class setclanleader implements CommandExecutor {
+
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+
+ if (args.length == 1) {
+
+
+
+ String playername = sender.getName();
+ String newname = toString().valueOf(args[0]);
+ String leaderuuid = String.valueOf(jsonutil.getUUID(playername));
+ if (jsonutil.checkClanLeader(jsonutil.getClanOfPlayer(leaderuuid), leaderuuid) == true) {
+ jsonutil.setClanleader(jsonutil.getClanOfPlayer(leaderuuid), jsonutil.getUUID(newname));
+
+ }else{
+
+
+ sender.sendMessage(ChatColor.RED + "You are not the Leader of the Clan that you are currently in.");
+ }
+ }else{
+
+ sender.sendMessage(ChatColor.RED + "Just use /setclanleader playername");
+ }
+ return true;
+ }
+
+}
diff --git a/src/main/java/de/spaffel/clans/commands/utils/Tab.java b/src/main/java/de/spaffel/clans/commands/utils/Tab.java
index 1a05567..f146811 100644
--- a/src/main/java/de/spaffel/clans/commands/utils/Tab.java
+++ b/src/main/java/de/spaffel/clans/commands/utils/Tab.java
@@ -12,7 +12,7 @@ import org.bukkit.scoreboard.Team;
public class Tab {
public static Thread t;
- public static boolean spaffelsmp = true;
+ public static boolean spaffelsmp = false;
public static void setTab() {
Clans.update();
@@ -49,7 +49,7 @@ public class Tab {
Bukkit.getOnlinePlayers().size() + "§7/§a" +
Bukkit.getMaxPlayers() + "\n" + "§eTPS§7: §a" + TPSUtil.getTPS() + "\n");
- String foot = "\n§e/vote §afür Belohnungen!\n§e/Discord §aUmauf den Discord zu gelangen!\n<§7" +
+ String foot = "\n§e/vote §afür Belohnungen!\n§e/Discord §aUm auf den Discord zu gelangen!\n§e/clanhelp §aInfos zu Clans\n<§7" +
line + "[§dSpaffel-Smp§7]" + line + "§a>\n";
p.setPlayerListHeaderFooter(head, foot);
diff --git a/src/main/java/de/spaffel/clans/commands/utils/jsonutil.java b/src/main/java/de/spaffel/clans/commands/utils/jsonutil.java
index 3c61c5b..76aead0 100644
--- a/src/main/java/de/spaffel/clans/commands/utils/jsonutil.java
+++ b/src/main/java/de/spaffel/clans/commands/utils/jsonutil.java
@@ -296,6 +296,43 @@ public class jsonutil extends JavaPlugin{
}
+
+ public static void setClanleader(String Clanid, String uuid){
+ String path = "plugins/Clans/clandata/" + Clanid + ".json";
+ String ans = checkFile(path);
+ if (ans == "exists"){
+
+ JSONParser jsonParser = new JSONParser();
+ try {
+ JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
+
+ jsonObject.put("leader", uuid);
+ FileWriter file = new FileWriter(path);
+ file.write(jsonObject.toJSONString());
+ file.close();
+ System.out.println("Saved Clanleader");
+
+ }catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+
+
+ }else{
+ System.out.println("Couldt save Clanleader");
+
+ }
+
+
+
+ }
+
+
+
public static void setClanbase(String Clanid, String x, String y, String z){
String path = "plugins/Clans/clandata/" + Clanid + ".json";
String ans = checkFile(path);
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index e5003b1..c770b55 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -14,4 +14,6 @@ commands:
setclancolor:
clanmsg:
setclanbase:
- clanbase:
\ No newline at end of file
+ clanbase:
+ setclanleader:
+ clanhelp:
\ No newline at end of file