diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 367fddda..aaa88a23 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -52,8 +52,6 @@ public class BungeeCore extends Plugin { setInstance(this); loadConfig(); - IgnoreSystem.folder = new File(getDataFolder() + "/ignoreSystem/"); //folder where the playerdata from the "/ignore" system is saved - new ErrorLogger(); new ConnectionListener(); new Forge(); diff --git a/src/de/steamwar/bungeecore/IgnoreSystem.java b/src/de/steamwar/bungeecore/IgnoreSystem.java deleted file mode 100644 index 4444f757..00000000 --- a/src/de/steamwar/bungeecore/IgnoreSystem.java +++ /dev/null @@ -1,157 +0,0 @@ -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 it cant contain 'z' + + public static boolean isIgnored(UUID ignorer, UUID ignored) { + try { + return !(SQL.select("SELECT * FROM UserIgnoreSystem WHERE a = ?", ignorer.toString()+"z"+ignored.toString())).next(); + } catch (SQLException e) {return false;} + } + public static void ignore(UUID victim, UUID offender) { + if (victim==null || offender==null) return; + if (!isIgnored(victim,offender)) + SQL.update("INSERT INTO UserIgnoreSystem (a) VALUES (?)",victim.toString()+"z"+offender.toString()); + } + public static void unIgnore(UUID victim, UUID offender) { + if (victim==null || offender==null) return; + SQL.update("DELETE FROM UserIgnoreSystem WHERE a = " + victim.toString()+"z"+offender.toString()); + } +} \ No newline at end of file