From cc3a5fcf18e156f9df9a8684d76c395b33562a04 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 25 Aug 2020 19:16:01 +0200 Subject: [PATCH] A probably working ignore system Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 4 +- .../bungeecore/commands/ChallengeCommand.java | 11 ++- .../bungeecore/commands/IgnoreCommand.java | 74 +++++++++++-------- .../bungeecore/commands/MsgCommand.java | 2 +- .../bungeecore/commands/RCommand.java | 10 +-- .../bungeecore/commands/UnIgnoreCommand.java | 67 ++++++++++------- .../steamwar/bungeecore/sql/IgnoreSystem.java | 55 +++++++------- 7 files changed, 124 insertions(+), 99 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 35b9094..94fcd12 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -52,7 +52,7 @@ public class BungeeCore extends Plugin { public void onEnable(){ setInstance(this); loadConfig(); - + new ErrorLogger(); new ConnectionListener(); new Forge(); @@ -99,6 +99,8 @@ public class BungeeCore extends Plugin { new CheckCommand(); new RankedCommand(); new RankCommand(); + new IgnoreCommand(); + new UnIgnoreCommand(); new EventStarter(); new Broadcaster(); diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 28ad61f..18e3ab9 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -24,19 +24,18 @@ public class ChallengeCommand extends BasicCommand { return; } - if (!(sender instanceof ProxiedPlayer)) {return;} + if (!(sender instanceof ProxiedPlayer)) + return; ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); if(target == null){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler ist nicht online."); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer Herausgeforderte ist nicht online."); return; }else if(target == sender){ BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cSchizophren?"); return; - } - - if (IgnoreSystem.isIgnored(target.getUniqueId(), ((ProxiedPlayer) sender).getUniqueId())) { - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler hat dich geblockt."); + }else if (IgnoreSystem.isIgnored(target, (ProxiedPlayer) sender)) { + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer Herausgeforderte hat dich geblockt."); return; } diff --git a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java index 21b00bf..7f7d541 100644 --- a/src/de/steamwar/bungeecore/commands/IgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/IgnoreCommand.java @@ -1,32 +1,42 @@ -package de.steamwar.bungeecore.commands; - -import de.steamwar.bungeecore.BungeeCore; -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.connection.ProxiedPlayer; - -public class IgnoreCommand extends BasicCommand { - - public IgnoreCommand() { - super("ignore", null); - } - - @Override - public void execute(CommandSender s, String[] args) { - if (!(s instanceof ProxiedPlayer)) return; - ProxiedPlayer p = (ProxiedPlayer) s; - SteamwarUser target = SteamwarUser.get(args[0]); - if(target == null){ - BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDieser Spieler wurde nicht in der Datenbank gefunden!"); - return; - }else if(target.equals(p)){ - BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cWie willst du dich selber ignorieren?"); - return; - }else { - IgnoreSystem.ignore(p.getUniqueId(), target.getUuid()); - BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du ignorierst nun " + target.getUserName() + "."); - } - } - -} +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +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.connection.ProxiedPlayer; + +public class IgnoreCommand extends BasicCommand { + + public IgnoreCommand() { + super("ignore", null); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(args.length < 1) { + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eignore §8[§7Spieler§8]"); + return; + } + + if (!(sender instanceof ProxiedPlayer)) + return; + ProxiedPlayer p = (ProxiedPlayer) sender; + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + + SteamwarUser target = SteamwarUser.get(args[0]); + if(target == null){ + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDiesen Spieler gibt es nicht."); + return; + }else if(target.equals(user)){ + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cWie willst du dich selber ignorieren?"); + return; + }else if(IgnoreSystem.isIgnored(user, target)){ + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDu ignorierst diesen Spieler bereits."); + return; + } + + IgnoreSystem.ignore(user, target); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du ignorierst nun §e" + target.getUserName() + "§8."); + } +} diff --git a/src/de/steamwar/bungeecore/commands/MsgCommand.java b/src/de/steamwar/bungeecore/commands/MsgCommand.java index 3b59d96..58b73d0 100644 --- a/src/de/steamwar/bungeecore/commands/MsgCommand.java +++ b/src/de/steamwar/bungeecore/commands/MsgCommand.java @@ -38,7 +38,7 @@ public class MsgCommand extends BasicCommand { if(target == null){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!"); return; - }else if (IgnoreSystem.isIgnored(target.getUniqueId(), player.getUniqueId())) { + }else if (IgnoreSystem.isIgnored(target, player)) { BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat dich geblockt!"); return; }else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ diff --git a/src/de/steamwar/bungeecore/commands/RCommand.java b/src/de/steamwar/bungeecore/commands/RCommand.java index 3f08a4e..2f01303 100644 --- a/src/de/steamwar/bungeecore/commands/RCommand.java +++ b/src/de/steamwar/bungeecore/commands/RCommand.java @@ -31,14 +31,12 @@ public class RCommand extends BasicCommand { if(target == null){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu hast bisher mit niemandem geschrieben!"); return; - } - if (IgnoreSystem.isIgnored(target.getUniqueId(), player.getUniqueId())) { - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat dich geblockt!"); - return; - } - if(!target.isConnected()){ + }else if(!target.isConnected()){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!"); return; + }else if (IgnoreSystem.isIgnored(target, player)) { + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler hat dich geblockt!"); + return; }else if(target.getChatMode() != ProxiedPlayer.ChatMode.SHOWN){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDieser Spieler empfängt derzeit keine Chatnachrichten!"); return; diff --git a/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java b/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java index b172203..94ffa76 100644 --- a/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java +++ b/src/de/steamwar/bungeecore/commands/UnIgnoreCommand.java @@ -1,29 +1,40 @@ -package de.steamwar.bungeecore.commands; - -import de.steamwar.bungeecore.BungeeCore; -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.connection.ProxiedPlayer; - -public class UnIgnoreCommand extends BasicCommand { - - public UnIgnoreCommand() { - super("unignore", null); - } - - @Override - public void execute(CommandSender s, String[] args) { - if (!(s instanceof ProxiedPlayer)) return; - ProxiedPlayer p = (ProxiedPlayer) s; - SteamwarUser t = SteamwarUser.get(args[0]); - if(t == null){ - BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDieser Spieler ist derzeit nicht online!"); - return; - }else { - IgnoreSystem.unIgnore(p.getUniqueId(), t.getUuid()); - BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du beachtest nun " + t.getUserName() + " wieder."); - } - } - +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.BungeeCore; +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.connection.ProxiedPlayer; + +public class UnIgnoreCommand extends BasicCommand { + + public UnIgnoreCommand() { + super("unignore", null); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if(args.length < 1) { + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§eunignore §8[§7Spieler§8]"); + return; + } + + if (!(sender instanceof ProxiedPlayer)) + return; + ProxiedPlayer p = (ProxiedPlayer) sender; + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + + SteamwarUser target = SteamwarUser.get(args[0]); + if(target == null){ + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDiesen Spieler gibt es nicht!"); + return; + }else if(!IgnoreSystem.isIgnored(user, target)){ + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cDu ignorierst diesen Spieler nicht."); + return; + } + + IgnoreSystem.unIgnore(user, target); + BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§7Du empfängst nun wieder Nachrichten von §e" + target.getUserName() + "§8."); + } + } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/sql/IgnoreSystem.java b/src/de/steamwar/bungeecore/sql/IgnoreSystem.java index b087ede..85d3682 100644 --- a/src/de/steamwar/bungeecore/sql/IgnoreSystem.java +++ b/src/de/steamwar/bungeecore/sql/IgnoreSystem.java @@ -1,26 +1,31 @@ -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()); - } +package de.steamwar.bungeecore.sql; + +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.sql.SQLException; + +public class IgnoreSystem{ + private IgnoreSystem(){} + + public static boolean isIgnored(ProxiedPlayer ignorer, ProxiedPlayer ignored){ + SteamwarUser user = SteamwarUser.get(ignorer.getUniqueId()); + SteamwarUser target = SteamwarUser.get(ignored.getUniqueId()); + return isIgnored(user, target); + } + + public static boolean isIgnored(SteamwarUser ignorer, SteamwarUser ignored) { + try { + return !SQL.select("SELECT * FROM Ignore WHERE Ignorer = ? AND Ignored = ?", ignorer.getId(), ignored.getId()).next(); + } catch (SQLException e) { + throw new SecurityException("Could not check if ignored", e); + } + } + + public static void ignore(SteamwarUser ignorer, SteamwarUser ignored) { + SQL.update("INSERT INTO Ignore (Ignorer, Ignored) VALUES (?, ?)", ignorer.getId(), ignored.getId()); + } + + public static void unIgnore(SteamwarUser ignorer, SteamwarUser ignored) { + SQL.update("DELETE FROM Ignore WHERE Ignorer = ? AND Ignored = ?", ignorer.getId(), ignored.getId()); + } } \ No newline at end of file