diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 85d43d7..367fddd 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -51,6 +51,8 @@ public class BungeeCore extends Plugin { public void onEnable(){ setInstance(this); loadConfig(); + + IgnoreSystem.folder = new File(getDataFolder() + "/ignoreSystem/"); //folder where the playerdata from the "/ignore" system is saved new ErrorLogger(); new ConnectionListener(); diff --git a/src/de/steamwar/bungeecore/IgnoreSystem.java b/src/de/steamwar/bungeecore/IgnoreSystem.java new file mode 100644 index 0000000..4444f75 --- /dev/null +++ b/src/de/steamwar/bungeecore/IgnoreSystem.java @@ -0,0 +1,157 @@ +package de.steamwar.bungeecore; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.UUID; + +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class IgnoreSystem{ + private static HashMap ignorers = new HashMap(); + public static File folder; //FileSystem-Folder: ../ignoreSystem/ + + //TODO load and unLoad functions - Filesystem + + public static boolean isIgnored(UUID ignorer, UUID ignored) { + if (!ignorers.containsKey(ignorer)) + ignorers.put(ignorer, new IgnoreSystem(ignorer)); + return ignorers.get(ignorer).isIgnoring(ignored); + } + + public static void load(UUID id) { + if (!ignorers.containsKey(id)) + ignorers.put(id, new IgnoreSystem(id)); + } + + public static void onStop() { + ignorers.forEach((u,i) -> { + i.saveId(u); + }); + } + + public static void save(UUID id) { + if (ignorers.containsKey(id)) + ignorers.get(id).saveId(id); + } + + public static void unLoad(UUID id) { + if (ignorers.containsKey(id)) + ignorers.remove(id); + } + + public static void ignore(ProxiedPlayer victim, ProxiedPlayer offender) { + if (victim==null || offender==null) return; + if (!ignorers.containsKey(victim.getUniqueId())) + ignorers.put(victim.getUniqueId(), new IgnoreSystem(victim.getUniqueId())); + ignorers.get(victim.getUniqueId()).ignore(offender.getUniqueId()); + } + + public static void unIgnore(ProxiedPlayer victim, ProxiedPlayer offender) { + if (victim==null || offender==null) return; + if (!ignorers.containsKey(victim.getUniqueId())) + ignorers.put(victim.getUniqueId(), new IgnoreSystem(victim.getUniqueId())); + ignorers.get(victim.getUniqueId()).unIgnore(offender.getUniqueId()); + } + + //--------Ignoring-Player-Instance-Below----------------------------- + + /** + * List of Ignored Players + */ + private ArrayList ignored; + + /** + * is THIS instance ignoring [id] + * @param id the person, which might get ignored + */ + public boolean isIgnoring(UUID id) { + return ignored.contains(id); + } + + /** + * + * @param id + */ + public IgnoreSystem(UUID id) { + ignored = new ArrayList(); + File f = new File(folder+id.toString()+".cfg"); + if (f.exists()) { + try { + FileReader fr = new FileReader(f); + int a=0; + String current=""; + try { + while ((a=fr.read())!=-1) { + char c = (char) a; + if (c=='\n') { + if (current!="") + ignored.add(UUID.fromString(current)); + current=""; + }else + current+=c; + } + } catch (IOException e) { + e.printStackTrace(); + } + } catch (FileNotFoundException e) {} //impossible + } + } + + /** + * start ignoring someone + * @param id annoying person + */ + public void ignore(UUID id) { + if (!ignored.contains(id)) + ignored.add(id); + } + + /** + * stop ignoring someone + * @param id forgiven person + */ + public void unIgnore(UUID id) { + if (ignored.contains(id)) + ignored.remove(id); + } + + /** + * Save this Users-Data to a File + * @param id UUID of Player -> Filename + */ + public void saveId(UUID id) { + File f = new File(folder+id.toString()+".cfg"); + if (!f.exists()) { + try { + f.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + if (ignored.size()<1) { + f.delete(); + return; + } + try { + FileWriter fw = new FileWriter(f); + String s = ""; + for (UUID i : ignored) + s+=i.toString()+'\n'; + char[] o = s.toCharArray(); + char[] i=new char[o.length+1]; + for (int k=0;k