Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.burnico.dustsystem.clanapi;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import de.burnico.dustsystem.main.Main;
- import de.burnico.dustsystem.mysql.ClanManager;
- import de.burnico.dustsystem.tablist.Tablist;
- public class Clan {
- String name;
- Player pl;
- String pr = "§bClan : §7";
- String tag;
- public static ArrayList<Player> invite = new ArrayList<Player>();
- public static HashMap<Player, String> clan = new HashMap<Player, String>();
- public Clan(String names){
- name = names;
- }
- public static boolean existsClan(String name){
- File file = new File("plugins//DustSystem//Clans//" + name + ".yml");
- if(file.exists()){
- return true;
- }
- return false;
- }
- public void sendMessage(String msg){
- for(Player all : Bukkit.getOnlinePlayers()){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> players = cfg.getStringList("Clan.players");
- if(players.contains(all.getUniqueId().toString())){
- all.sendMessage(Main.getInstance().pr + msg);
- }
- }
- }
- public static String getClan(Player p){
- File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
- YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
- return cfg1.getString("Clan");
- }
- public static String getClan(String name){
- @SuppressWarnings("deprecation")
- OfflinePlayer p = Bukkit.getOfflinePlayer(name);
- File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
- YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
- return cfg1.getString("Clan");
- }
- public void create(Player p, String tags){
- pl = p;
- tag = tags;
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- File file1 = new File("plugins//DustSystem//Clan.yml//" + pl.getUniqueId().toString() + ".yml");
- YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
- cfg1.set("Clan", this.name);
- try {
- cfg1.save(file1);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- List<String> owners = cfg.getStringList("Clan.owners");
- List<String> players = cfg.getStringList("Clan.players");
- owners.add(this.pl.getUniqueId().toString());
- players.add(this.pl.getUniqueId().toString());
- if(!exist()){
- createFile();
- }
- cfg.set("Clan.name", this.name);
- cfg.set("Clan.tag", this.tag);
- cfg.set("Clan.owners", owners);
- cfg.set("Clan.moderatoren", "");
- cfg.set("Clan.players", players);
- cfg.set("Clan.level", 1);
- cfg.set("Clan.base", p.getLocation());
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- for(Player all : Bukkit.getOnlinePlayers()){
- Tablist tab = new Tablist(all);
- tab.updatePrefixs();
- }
- }
- public boolean exist(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- if(file.exists()){
- return true;
- }
- return false;
- }
- public void joinClan(Player p){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
- YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
- cfg1.set("Clan", this.name);
- try {
- cfg1.save(file1);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- List<String> players = cfg.getStringList("Clan.players");
- players.add(p.getUniqueId().toString());
- cfg.set("Clan.players", players);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- for(Player all : Bukkit.getOnlinePlayers()){
- Tablist tab = new Tablist(all);
- tab.updatePrefixs();
- }
- }
- public void createFile(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- try {
- file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void saveFile(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void leaveClan(Player p){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
- if(file1.exists()){
- file1.delete();
- }
- List<String> mods = cfg.getStringList("Clan.moderatoren");
- List<String> players = cfg.getStringList("Clan.players");
- String uuid = p.getUniqueId().toString();
- players.remove(uuid);
- cfg.set("Clan.players", players);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- if(mods.contains(uuid)){
- mods.remove(uuid);
- cfg.set("Clan.moderatoren", mods);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- for(Player all : Bukkit.getOnlinePlayers()){
- Tablist tab = new Tablist(all);
- tab.updatePrefixs();
- }
- }
- public String getRank(Player p){
- String rank = "";
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> owners = cfg.getStringList("Clan.owners");
- List<String> mods = cfg.getStringList("Clan.moderatoren");
- List<String> players = cfg.getStringList("Clan.players");
- String uuid = p.getUniqueId().toString();
- if(owners.contains(uuid)){
- rank = "Owner";
- } else if(mods.contains(uuid)){
- rank = "Moderator";
- } else if(players.contains(uuid)&&!(owners.contains(uuid))){
- rank = "Member";
- } else {
- rank = "null";
- }
- return rank;
- }
- public String getRank(String name){
- String rank = "";
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> owners = cfg.getStringList("Clan.owners");
- List<String> mods = cfg.getStringList("Clan.moderatoren");
- List<String> players = cfg.getStringList("Clan.players");
- @SuppressWarnings("deprecation")
- OfflinePlayer p = Bukkit.getOfflinePlayer(name);
- String uuid = p.getUniqueId().toString();
- if(owners.contains(uuid)){
- rank = "Owner";
- } else if(mods.contains(uuid)){
- rank = "Moderator";
- } else if(players.contains(uuid)&&!(owners.contains(uuid))){
- rank = "Member";
- } else {
- rank = "null";
- }
- return rank;
- }
- public void sendClanMessage(Player sender, String message){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> owners = cfg.getStringList("Clan.owners");
- List<String> mods = cfg.getStringList("Clan.moderatoren");
- List<String> players = cfg.getStringList("Clan.players");
- for(Player all : Bukkit.getOnlinePlayers()){
- if(players.contains(all.getUniqueId().toString())){
- if(!all.getName().equalsIgnoreCase(sender.getName())){
- all.sendMessage("");
- }
- }
- }
- }
- public static boolean isInClan(Player p){
- File file = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
- if(file.exists()){
- return true;
- }
- return false;
- }
- public String getName(){
- return this.name;
- }
- public String getTag(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- return cfg.getString("Clan.tag");
- }
- public void invitePlayer(Player target){
- invite.add(target);
- clan.remove(target);
- clan.put(target, this.name);
- Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable(){
- @Override
- public void run() {
- if(target != null){
- if(invite.contains(target)){
- invite.remove(target);
- }
- }
- }
- }, 20*30L);
- }
- public void acceptInvitation(Player p){
- invite.remove(p);
- joinClan(p);
- }
- public Integer getLevel(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- return cfg.getInt("Clan.level");
- }
- public void updateLevel(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- cfg.set("Clan.level", getLevel() +1);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- sendMessage("Der Clan ist zu Level §6§l" + getLevel() + "§7 aufgestiegen!");
- for(Player all : Bukkit.getOnlinePlayers()){
- Tablist tab = new Tablist(all);
- tab.updatePrefixs();
- tab.updateScores();
- }
- }
- public String getColor(){
- String color = "";
- if(getLevel()==1){
- color = "§e";
- } else if(getLevel()==2){
- color = "§6";
- } else if(getLevel()==3){
- color = "§b";
- } else if(getLevel()==4){
- color = "§9";
- } else if(getLevel()==5){
- color = "§1";
- } else if(getLevel()==6){
- color = "§d";
- } else if(getLevel()==7){
- color = "§5";
- } else if(getLevel()==8){
- color = "§c";
- } else if(getLevel()==9){
- color = "§4";
- } else if(getLevel()==10){
- color = "§f";
- }
- return color;
- }
- public void kick(UUID uuid){
- File file1 = new File("plugins//DustSystem//Clan.yml//" + uuid + ".yml");
- if(file1.exists()){
- file1.delete();
- }
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> players = cfg.getStringList("Clan.players");
- if(players.contains(uuid.toString())){
- players.remove(uuid.toString());
- cfg.set("Clan.players", players);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- for(Player all : Bukkit.getOnlinePlayers()){
- Tablist tab = new Tablist(all);
- tab.updatePrefixs();
- }
- }
- public void promotePlayer(Player p){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> mods = cfg.getStringList("Clan.moderatoren");
- mods.add(p.getUniqueId().toString());
- cfg.set("Clan.moderatoren", mods);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void demotePlayer(Player p){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> mods = cfg.getStringList("Clan.moderatoren");
- mods.remove(p.getUniqueId().toString());
- cfg.set("Clan.moderatoren", mods);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public List<String> Owners(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> owners = cfg.getStringList("Clan.owners");
- List<String> names = new ArrayList<>();
- owners.forEach(uuids ->{
- names.add(Main.getName(UUID.fromString(uuids)));
- });
- return names;
- }
- public List<String> Moderatoren(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> owners = cfg.getStringList("Clan.moderatoren");
- List<String> names = new ArrayList<>();
- owners.forEach(uuids ->{
- names.add(Main.getName(UUID.fromString(uuids)));
- });
- return names;
- }
- public List<String> Players(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> owners = cfg.getStringList("Clan.players");
- List<String> names = new ArrayList<>();
- owners.forEach(uuids ->{
- names.add(Main.getName(UUID.fromString(uuids)));
- });
- return names;
- }
- public void deomotePlayer(UUID uid){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> mods = cfg.getStringList("Clan.moderatoren");
- mods.remove(uid.toString());
- cfg.set("Clan.moderatoren", mods);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void setBase(Location loc){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- cfg.set("Clan.base", loc);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void setTag(String tag){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- cfg.set("Clan.tag", tag);
- try {
- cfg.save(file);
- } catch (IOException e) {
- e.printStackTrace();
- }
- for(Player all : Bukkit.getOnlinePlayers()){
- Tablist tab = new Tablist(all);
- tab.updatePrefixs();
- }
- }
- public Location getBase(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- return (Location) cfg.get("Clan.base");
- }
- public void delete(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> players = cfg.getStringList("Clan.players");
- players.forEach(uid -> {
- File file1 = new File("plugins//DustSystem//Clan.yml//" + uid + ".yml");
- if(file1.exists()){
- file1.delete();
- }
- });
- if(file.exists()){
- file.delete();
- }
- for(Player all : Bukkit.getOnlinePlayers()){
- Tablist tab = new Tablist(all);
- tab.updatePrefixs();
- }
- ClanManager.setKills(getOwner(), 0);
- }
- public UUID getOwner(){
- File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
- YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
- List<String> owners = cfg.getStringList("Clan.owners");
- int i = 0;
- for(String s : owners){
- i++;
- if(i < 2){
- return UUID.fromString(s);
- }
- }
- return null;
- }
- public static String getClanName(UUID owner){
- File file1 = new File("plugins//DustSystem//Clan.yml//" + owner.toString() + ".yml");
- YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
- return cfg1.getString("Clan");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement