SteamWar/BungeeCore
Archiviert
13
2
TODO:
 create SQL-Table: UserIgnoreSystem(String a)
Dieser Commit ist enthalten in:
Jan9103 2020-06-25 11:37:59 +02:00
Ursprung 1e2f2441ab
Commit 42cbf18c27
8 geänderte Dateien mit 32 neuen und 167 gelöschten Zeilen

Datei anzeigen

@ -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();

Datei anzeigen

@ -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<UUID, IgnoreSystem> ignorers = new HashMap<UUID, IgnoreSystem>();
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<UUID> 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<UUID>();
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<o.length;k++)
i[k]=o[k];
i[i.length]=(char)-1;
fw.write(i);
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Datei anzeigen

@ -1,6 +1,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.sql.IgnoreSystem;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;

Datei anzeigen

@ -1,7 +1,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.IgnoreSystem;
import de.steamwar.bungeecore.sql.IgnoreSystem;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -24,7 +24,7 @@ public class IgnoreCommand extends BasicCommand {
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cWie willst du dich selber Ignorieren?");
return;
}else {
IgnoreSystem.ignore(p, target);
IgnoreSystem.ignore(p.getUniqueId(), target.getUniqueId());
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du ignorierst nun " + target.getDisplayName() + ".");
}
}

Datei anzeigen

@ -1,7 +1,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.IgnoreSystem;
import de.steamwar.bungeecore.sql.IgnoreSystem;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;

Datei anzeigen

@ -1,7 +1,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.IgnoreSystem;
import de.steamwar.bungeecore.sql.IgnoreSystem;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -21,7 +21,7 @@ public class UnIgnoreCommand extends BasicCommand {
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!");
return;
}else {
IgnoreSystem.unIgnore(p, target);
IgnoreSystem.unIgnore(p.getUniqueId(), target.getUniqueId());
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du beachtest nun " + target.getDisplayName() + " wieder.");
}
}

Datei anzeigen

@ -1,7 +1,6 @@
package de.steamwar.bungeecore.listeners;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.IgnoreSystem;
import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.commands.ChallengeCommand;
@ -124,12 +123,10 @@ public class ConnectionListener extends BasicListener {
@EventHandler
public void onDisconnect(PlayerDisconnectEvent e){
ChallengeCommand.remove(e.getPlayer());
IgnoreSystem.unLoad(e.getPlayer().getUniqueId());
}
@EventHandler
public void onServerDisconnect(ServerDisconnectEvent e){
IgnoreSystem.onStop(); //save all
ServerInfo server = e.getTarget();
Subserver subserver = Subserver.getSubserver(server);
if(subserver == null)

Datei anzeigen

@ -0,0 +1,26 @@
package de.steamwar.bungeecore.sql;
import java.sql.SQLException;
import java.util.UUID;
public class IgnoreSystem{
//SQL-Table:
// Name=UserIgnoreSystem
// Content: a ([UUID des Ignoriers]z[UUID des Ignorierten])
// UUID is a HEX-Number -> 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());
}
}