Ignore-System initial push
Dieser Commit ist enthalten in:
Ursprung
a0058f468b
Commit
1e2f2441ab
@ -51,6 +51,8 @@ public class BungeeCore extends Plugin {
|
|||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
setInstance(this);
|
setInstance(this);
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
IgnoreSystem.folder = new File(getDataFolder() + "/ignoreSystem/"); //folder where the playerdata from the "/ignore" system is saved
|
||||||
|
|
||||||
new ErrorLogger();
|
new ErrorLogger();
|
||||||
new ConnectionListener();
|
new ConnectionListener();
|
||||||
|
157
src/de/steamwar/bungeecore/IgnoreSystem.java
Normale Datei
157
src/de/steamwar/bungeecore/IgnoreSystem.java
Normale Datei
@ -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<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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,12 +22,22 @@ public class ChallengeCommand extends BasicCommand {
|
|||||||
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§8]");
|
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§8]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(sender instanceof ProxiedPlayer)) {
|
||||||
|
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "You cant run this from the Console..");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
||||||
if(target == null){
|
if(target == null){
|
||||||
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler ist nicht online.");
|
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler ist nicht online.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IgnoreSystem.isIgnored(target.getUniqueId(), ((ProxiedPlayer) sender).getUniqueId())) {
|
||||||
|
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler hat dich geblockt.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Subserver subserver = Subserver.getSubserver(target);
|
Subserver subserver = Subserver.getSubserver(target);
|
||||||
if(subserver != null && subserver.getType() == Servertype.ARENA){
|
if(subserver != null && subserver.getType() == Servertype.ARENA){
|
||||||
|
32
src/de/steamwar/bungeecore/commands/IgnoreCommand.java
Normale Datei
32
src/de/steamwar/bungeecore/commands/IgnoreCommand.java
Normale Datei
@ -0,0 +1,32 @@
|
|||||||
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.IgnoreSystem;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
public class IgnoreCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public IgnoreCommand() {
|
||||||
|
super("ignore", "steamwar.ignore");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender s, String[] args) {
|
||||||
|
if (!(s instanceof ProxiedPlayer)) return;
|
||||||
|
ProxiedPlayer p = (ProxiedPlayer) s;
|
||||||
|
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
||||||
|
if(target == null){
|
||||||
|
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!");
|
||||||
|
return;
|
||||||
|
}else if(target.equals(p)){
|
||||||
|
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cWie willst du dich selber Ignorieren?");
|
||||||
|
return;
|
||||||
|
}else {
|
||||||
|
IgnoreSystem.ignore(p, target);
|
||||||
|
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du ignorierst nun " + target.getDisplayName() + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.IgnoreSystem;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -37,6 +38,9 @@ public class MsgCommand extends BasicCommand {
|
|||||||
if(target == null){
|
if(target == null){
|
||||||
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!");
|
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!");
|
||||||
return;
|
return;
|
||||||
|
}else if (IgnoreSystem.isIgnored(target.getUniqueId(), player.getUniqueId())) {
|
||||||
|
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat dich geblockt!");
|
||||||
|
return;
|
||||||
}else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){
|
}else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){
|
||||||
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!");
|
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!");
|
||||||
return;
|
return;
|
||||||
|
29
src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java
Normale Datei
29
src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java
Normale Datei
@ -0,0 +1,29 @@
|
|||||||
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.IgnoreSystem;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
public class UnIgnoreCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public UnIgnoreCommand() {
|
||||||
|
super("unignore", "steamwar.ignore");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender s, String[] args) {
|
||||||
|
if (!(s instanceof ProxiedPlayer)) return;
|
||||||
|
ProxiedPlayer p = (ProxiedPlayer) s;
|
||||||
|
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
||||||
|
if(target == null){
|
||||||
|
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!");
|
||||||
|
return;
|
||||||
|
}else {
|
||||||
|
IgnoreSystem.unIgnore(p, target);
|
||||||
|
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du beachtest nun " + target.getDisplayName() + " wieder.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package de.steamwar.bungeecore.listeners;
|
package de.steamwar.bungeecore.listeners;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.IgnoreSystem;
|
||||||
import de.steamwar.bungeecore.Servertype;
|
import de.steamwar.bungeecore.Servertype;
|
||||||
import de.steamwar.bungeecore.Subserver;
|
import de.steamwar.bungeecore.Subserver;
|
||||||
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
||||||
@ -123,10 +124,12 @@ public class ConnectionListener extends BasicListener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDisconnect(PlayerDisconnectEvent e){
|
public void onDisconnect(PlayerDisconnectEvent e){
|
||||||
ChallengeCommand.remove(e.getPlayer());
|
ChallengeCommand.remove(e.getPlayer());
|
||||||
|
IgnoreSystem.unLoad(e.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onServerDisconnect(ServerDisconnectEvent e){
|
public void onServerDisconnect(ServerDisconnectEvent e){
|
||||||
|
IgnoreSystem.onStop(); //save all
|
||||||
ServerInfo server = e.getTarget();
|
ServerInfo server = e.getTarget();
|
||||||
Subserver subserver = Subserver.getSubserver(server);
|
Subserver subserver = Subserver.getSubserver(server);
|
||||||
if(subserver == null)
|
if(subserver == null)
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren