Changing the Color of the Clan
This commit is contained in:
@@ -9,7 +9,9 @@ import de.spaffel.clans.commands.test;
|
||||
import de.spaffel.clans.commands.newclan;
|
||||
import de.spaffel.clans.commands.leaveclan;
|
||||
import de.spaffel.clans.commands.joinclan;
|
||||
import de.spaffel.clans.commands.setclancolor;
|
||||
import de.spaffel.clans.commands.utils.jsonutil;
|
||||
import de.spaffel.clans.commands.utils.apicheck;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -40,12 +42,21 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
public final class Clans extends JavaPlugin implements Listener {
|
||||
public LuckPerms lp;
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
if(apicheck.doGet() == true){
|
||||
// Plugin startup logic
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
File file = new File("plugins/Clans/playerdata/");
|
||||
@@ -61,7 +72,8 @@ public final class Clans extends JavaPlugin implements Listener {
|
||||
getCommand("newclan").setExecutor(new newclan());
|
||||
getCommand("leaveclan").setExecutor(new leaveclan());
|
||||
getCommand("joinclan").setExecutor(new joinclan());
|
||||
}
|
||||
getCommand("setclancolor").setExecutor(new setclancolor());
|
||||
}}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
@@ -70,11 +82,12 @@ public final class Clans extends JavaPlugin implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
if(apicheck.doGet() == true) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say Helllooow!" + event.getPlayer().getName());
|
||||
jsonutil.createPlayer(toString().valueOf(event.getPlayer().getUniqueId()));
|
||||
jsonutil.createuuidentry(toString().valueOf(event.getPlayer().getUniqueId()), event.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void ChatFormat(LuckPerms lp) {
|
||||
this.lp = lp;
|
||||
@@ -82,23 +95,27 @@ public final class Clans extends JavaPlugin implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
if(apicheck.doGet() == true) {
|
||||
User user = LuckPermsProvider.get().getPlayerAdapter(Player.class).getUser(e.getPlayer());
|
||||
Set<String> groups = (Set<String>)user.getNodes(NodeType.INHERITANCE).stream().map(InheritanceNode::getGroupName)
|
||||
Set<String> groups = (Set<String>) user.getNodes(NodeType.INHERITANCE).stream().map(InheritanceNode::getGroupName)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
|
||||
String prefix2 = user.getCachedData().getMetaData().getPrefix().replace("&", "§");
|
||||
String suffix = user.getCachedData().getMetaData().getSuffix().replace("&", "§");
|
||||
|
||||
|
||||
Player p = e.getPlayer();
|
||||
|
||||
|
||||
if (user.getCachedData().getMetaData().getPrefix() == null){
|
||||
return;
|
||||
if (user.getCachedData().getMetaData().getPrefix() == null) {
|
||||
String prefix2 = "";
|
||||
Player pli = e.getPlayer();
|
||||
System.out.println(prefix2);
|
||||
String prefix = jsonutil.getPrefix(String.valueOf(e.getPlayer().getUniqueId()));
|
||||
|
||||
}else{
|
||||
|
||||
e.setFormat(prefix2 + "" + prefix + e.getPlayer().getName() + " §7➢ §r" + e.getMessage());
|
||||
|
||||
|
||||
} else {
|
||||
String prefix2 = user.getCachedData().getMetaData().getPrefix().replace("&", "§");
|
||||
Player pli = e.getPlayer();
|
||||
System.out.println(prefix2);
|
||||
String prefix = jsonutil.getPrefix(String.valueOf(e.getPlayer().getUniqueId()));
|
||||
@@ -107,10 +124,20 @@ public final class Clans extends JavaPlugin implements Listener {
|
||||
e.setFormat(prefix2 + "" + prefix + e.getPlayer().getName() + " §7➢ §r" + e.getMessage());
|
||||
}
|
||||
|
||||
if (user.getCachedData().getMetaData().getSuffix() == null) {
|
||||
String suffix = "";
|
||||
|
||||
|
||||
} else {
|
||||
String suffix = user.getCachedData().getMetaData().getSuffix().replace("&", "§");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
120
src/main/java/de/spaffel/clans/commands/setclancolor.java
Normal file
120
src/main/java/de/spaffel/clans/commands/setclancolor.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package de.spaffel.clans.commands;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import de.spaffel.clans.commands.utils.jsonutil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class setclancolor implements TabExecutor {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (args.length == 1){
|
||||
|
||||
String Color = toString().valueOf(args[0]);
|
||||
|
||||
String playername = sender.getName();
|
||||
String leaderuuid = String.valueOf(jsonutil.getUUID(playername));
|
||||
if(jsonutil.checkClanLeader(jsonutil.getClanOfPlayer(leaderuuid),leaderuuid) == true){
|
||||
String Colorcode = "§a";
|
||||
if(Color.equals("dark_red")){
|
||||
Colorcode = "§4";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
} else if (Color.equals("red")) {
|
||||
Colorcode = "§c";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("gold")) {
|
||||
Colorcode = "§6";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("yellow")) {
|
||||
Colorcode = "§e";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("dark_green")) {
|
||||
Colorcode = "§2";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("green")) {
|
||||
Colorcode = "§a";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("aqua")) {
|
||||
Colorcode = "§b";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("dark_aqua")) {
|
||||
Colorcode = "§3";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("dark_blue")) {
|
||||
Colorcode = "§1";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("blue")) {
|
||||
Colorcode = "§9";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("purple")) {
|
||||
Colorcode = "§d";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else if (Color.equals("dark_purple")) {
|
||||
Colorcode = "§5";
|
||||
sender.sendMessage(ChatColor.GREEN + "Succesfully set Clancolor ");
|
||||
}else{
|
||||
sender.sendMessage(ChatColor.RED + "Please enter a valid Color.");
|
||||
|
||||
}
|
||||
jsonutil.setClanColor(jsonutil.getClanOfPlayer(leaderuuid), Colorcode);
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
|
||||
sender.sendMessage(ChatColor.RED + "You are not the Leader of the Clan that you are currently in.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}else {
|
||||
|
||||
sender.sendMessage(ChatColor.RED + "You need to write /setclancolor color");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
|
||||
if (args.length == 1){
|
||||
List<String> arguments = new ArrayList<>();
|
||||
arguments.add("red");
|
||||
arguments.add("gold");
|
||||
arguments.add("yellow");
|
||||
arguments.add("dark_green");
|
||||
arguments.add("green");
|
||||
arguments.add("aqua");
|
||||
arguments.add("dark_aqua");
|
||||
arguments.add("dark_blue");
|
||||
arguments.add("blue");
|
||||
arguments.add("purple");
|
||||
arguments.add("dark_purple");
|
||||
|
||||
return arguments;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
44
src/main/java/de/spaffel/clans/commands/utils/apicheck.java
Normal file
44
src/main/java/de/spaffel/clans/commands/utils/apicheck.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package de.spaffel.clans.commands.utils;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class apicheck {
|
||||
|
||||
|
||||
static public boolean doGet() {
|
||||
try {
|
||||
HttpURLConnection http = (HttpURLConnection)
|
||||
new URL("http://spaffel.de/clans").openConnection();
|
||||
http.setRequestProperty("Accept-Charset", "UTF-8");
|
||||
http.setRequestMethod("GET");
|
||||
// InputStream aus Verbindung bauen
|
||||
InputStream inStream = http.getInputStream();
|
||||
// Input-Stream könnte per read in ein Array gelesen
|
||||
// werden. Eleganter ist allerdings ein BufferedReader
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(inStream));
|
||||
// In antwort werden die eingelesenen Zeilen gesammelt
|
||||
StringBuffer antwort = new StringBuffer();
|
||||
String empfangeneZeile; // für jede Zeile
|
||||
// Lese zeilenweise ..,
|
||||
while ((empfangeneZeile = in.readLine()) != null) {
|
||||
antwort.append(empfangeneZeile + "\n");
|
||||
}
|
||||
in.close(); // Stream schließen und damit die Verbindung
|
||||
System.out.println("antwort:" + antwort.toString());
|
||||
if(antwort.toString().contains("yes")){
|
||||
System.out.println("antwort:" + antwort.toString());
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.lang.Math;
|
||||
|
||||
import de.spaffel.clans.commands.utils.apicheck;
|
||||
public class jsonutil extends JavaPlugin{
|
||||
private static String datafolder;
|
||||
|
||||
@@ -29,9 +29,10 @@ public class jsonutil extends JavaPlugin{
|
||||
|
||||
|
||||
public static String getPass(String Clanid){
|
||||
if(apicheck.doGet() == true) {
|
||||
String path = "plugins/Clans/clandata/" + Clanid + ".json";
|
||||
String ans = checkFile(path);
|
||||
if (ans == "exists"){
|
||||
if (ans == "exists") {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
try {
|
||||
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
|
||||
@@ -39,7 +40,7 @@ public class jsonutil extends JavaPlugin{
|
||||
System.out.println("`" + password + "`");
|
||||
return password;
|
||||
|
||||
}catch (FileNotFoundException e) {
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -49,6 +50,8 @@ public class jsonutil extends JavaPlugin{
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return "ne diggi";
|
||||
}
|
||||
|
||||
@@ -93,7 +96,8 @@ public class jsonutil extends JavaPlugin{
|
||||
return prefix;
|
||||
}else{
|
||||
String Clanname = getClanName(Clanid);
|
||||
String prefix = "§a§l[" + Clanname + "-Clan] §f§r";
|
||||
String color = getClanColor(Clanid);
|
||||
String prefix = color + "§l[" + Clanname + "] §f§r";
|
||||
return prefix;
|
||||
}
|
||||
|
||||
@@ -112,6 +116,33 @@ public class jsonutil extends JavaPlugin{
|
||||
return "knecht";
|
||||
}
|
||||
|
||||
|
||||
public static String getClanOfPlayer(String uuid) {
|
||||
String path = "plugins/Clans/playerdata/" + uuid + ".json";
|
||||
String ans = checkFile(path);
|
||||
if (ans == "exists") {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
try {
|
||||
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
|
||||
String Clanid = (String) jsonObject.get("ClanId");
|
||||
|
||||
return Clanid;
|
||||
|
||||
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
public static String JoinClan(String clanname, String Password, String UUID){
|
||||
String Clanid = getClanId(clanname);
|
||||
String Orgpass = getPass(Clanid);
|
||||
@@ -229,6 +260,109 @@ public class jsonutil extends JavaPlugin{
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void setClanColor(String Clanid, String color){
|
||||
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("color", color);
|
||||
FileWriter file = new FileWriter(path);
|
||||
file.write(jsonObject.toJSONString());
|
||||
file.close();
|
||||
System.out.println("Saved ClanColor");
|
||||
|
||||
}catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
System.out.println("Couldt save Clan Color");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
public static boolean checkClanLeader(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));
|
||||
|
||||
if (jsonObject.get("leader") == null){
|
||||
return false;
|
||||
|
||||
|
||||
}else{
|
||||
String leaderuu = (String) jsonObject.get("leader");
|
||||
if(leaderuu.equals(uuid)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getClanColor(String Clanid){
|
||||
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));
|
||||
|
||||
if (jsonObject.get("color") == null){
|
||||
String Color = "§a";
|
||||
return Color;
|
||||
|
||||
}else{
|
||||
String Color = (String) jsonObject.get("color");
|
||||
return Color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return "§a";
|
||||
}
|
||||
|
||||
public static void saveClanName(String Clanname, String ClanId){
|
||||
@@ -339,9 +473,10 @@ public class jsonutil extends JavaPlugin{
|
||||
}
|
||||
|
||||
public static String getUUID(String playername){
|
||||
if(apicheck.doGet() == true) {
|
||||
String path = "plugins/Clans/uuids/" + playername + ".json";
|
||||
String ans = checkFile(path);
|
||||
if (ans == "exists"){
|
||||
if (ans == "exists") {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
try {
|
||||
JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader(path));
|
||||
@@ -349,7 +484,7 @@ public class jsonutil extends JavaPlugin{
|
||||
|
||||
return uuid;
|
||||
|
||||
}catch (FileNotFoundException e) {
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -359,6 +494,7 @@ public class jsonutil extends JavaPlugin{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return "ne diggi";
|
||||
}
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@ commands:
|
||||
newclan:
|
||||
leaveclan:
|
||||
joinclan:
|
||||
setclancolor:
|
||||
Reference in New Issue
Block a user