Clanbase Feature
This commit is contained in:
@@ -98,6 +98,8 @@ public final class Clans extends JavaPlugin implements Listener {
|
||||
getCommand("joinclan").setExecutor(new joinclan());
|
||||
getCommand("setclancolor").setExecutor(new setclancolor());
|
||||
getCommand("clanmsg").setExecutor(new clanmsg());
|
||||
getCommand("setclanbase").setExecutor(new setclanbase());
|
||||
getCommand("clanbase").setExecutor(new clanbase());
|
||||
plugin = this;
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
Tab.update();
|
||||
|
||||
47
src/main/java/de/spaffel/clans/commands/clanbase.java
Normal file
47
src/main/java/de/spaffel/clans/commands/clanbase.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package de.spaffel.clans.commands;
|
||||
|
||||
import de.spaffel.clans.commands.utils.jsonutil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class clanbase implements CommandExecutor {
|
||||
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
|
||||
|
||||
|
||||
String playername = sender.getName();
|
||||
String leaderuuid = String.valueOf(jsonutil.getUUID(playername));
|
||||
|
||||
Player p = (Player)sender;
|
||||
|
||||
double x = Double.parseDouble(jsonutil.getClanbasex(jsonutil.getClanOfPlayer(leaderuuid)));
|
||||
double y = Double.parseDouble(jsonutil.getClanbasey(jsonutil.getClanOfPlayer(leaderuuid)));
|
||||
double z = Double.parseDouble(jsonutil.getClanbasez(jsonutil.getClanOfPlayer(leaderuuid)));
|
||||
|
||||
|
||||
Location location = new Location(Bukkit.getWorld("world"), x, y, z);
|
||||
|
||||
p.teleport(location);
|
||||
sender.sendMessage(ChatColor.GREEN + "Teleported to your Clanbase");
|
||||
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
sender.sendMessage(ChatColor.RED + "Just use /clanbase");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
42
src/main/java/de/spaffel/clans/commands/setclanbase.java
Normal file
42
src/main/java/de/spaffel/clans/commands/setclanbase.java
Normal file
@@ -0,0 +1,42 @@
|
||||
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 setclanbase implements CommandExecutor {
|
||||
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
|
||||
|
||||
|
||||
String playername = sender.getName();
|
||||
String leaderuuid = String.valueOf(jsonutil.getUUID(playername));
|
||||
if (jsonutil.checkClanLeader(jsonutil.getClanOfPlayer(leaderuuid), leaderuuid) == true) {
|
||||
Player p = (Player)sender;
|
||||
p.getLocation().getX();
|
||||
|
||||
jsonutil.setClanbase(jsonutil.getClanOfPlayer(leaderuuid), String.valueOf(p.getLocation().getX()) , String.valueOf(p.getLocation().getY()), String.valueOf(p.getLocation().getZ()) );
|
||||
sender.sendMessage(ChatColor.GREEN + "Congrats! This is now the Base of your Clan!");
|
||||
|
||||
|
||||
|
||||
}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 /setclanbase");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -296,6 +296,127 @@ public class jsonutil extends JavaPlugin{
|
||||
|
||||
|
||||
}
|
||||
public static void setClanbase(String Clanid, String x, String y, String z){
|
||||
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("basex", x);
|
||||
jsonObject.put("basey", y);
|
||||
jsonObject.put("basez", z);
|
||||
FileWriter file = new FileWriter(path);
|
||||
file.write(jsonObject.toJSONString());
|
||||
file.close();
|
||||
System.out.println("Saved Clanbase");
|
||||
|
||||
}catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
System.out.println("Couldt save Clanbase");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String getClanbasex(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));
|
||||
String x = (String) jsonObject.get("basex");
|
||||
String y = (String) jsonObject.get("basey");
|
||||
String z = (String) jsonObject.get("basez");
|
||||
|
||||
|
||||
return x;
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return "nix";
|
||||
}
|
||||
|
||||
public static String getClanbasey(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));
|
||||
String x = (String) jsonObject.get("basex");
|
||||
String y = (String) jsonObject.get("basey");
|
||||
String z = (String) jsonObject.get("basez");
|
||||
|
||||
|
||||
return y;
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return "nix";
|
||||
}
|
||||
|
||||
public static String getClanbasez(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));
|
||||
String x = (String) jsonObject.get("basex");
|
||||
String y = (String) jsonObject.get("basey");
|
||||
String z = (String) jsonObject.get("basez");
|
||||
|
||||
|
||||
return z;
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return "nix";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static boolean checkClanLeader(String Clanid, String uuid){
|
||||
String path = "plugins/Clans/clandata/" + Clanid + ".json";
|
||||
String ans = checkFile(path);
|
||||
|
||||
@@ -12,4 +12,6 @@ commands:
|
||||
leaveclan:
|
||||
joinclan:
|
||||
setclancolor:
|
||||
clanmsg:
|
||||
clanmsg:
|
||||
setclanbase:
|
||||
clanbase:
|
||||
Reference in New Issue
Block a user