From edd81c6ca66927f947970f10d4d378bd5034ce36 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 22:34:29 +0100 Subject: [PATCH] Add Chatcolor to UserGroup --- .../bungeecore/listeners/ChatListener.java | 17 ++--------- .../steamwar/bungeecore/sql/SteamwarUser.java | 4 +-- src/de/steamwar/bungeecore/sql/UserGroup.java | 29 ++++++++++++++----- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index dcb95b95..0ee62653 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -27,6 +27,7 @@ import de.steamwar.bungeecore.commands.TpCommand; import de.steamwar.bungeecore.comms.packets.PingPacket; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; +import de.steamwar.bungeecore.sql.UserGroup; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ProxyServer; @@ -158,22 +159,10 @@ public class ChatListener extends BasicListener { private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){ String name = sender.getDisplayName(); - String chatcolor = "§7"; + String chatcolor = user.getUserGroup().getChatColorCode(); - message = message.replace('§', '&'); - if(sender.hasPermission("bungeecore.group.admin")){ - chatcolor = "§e"; + if(user.getUserGroup() != UserGroup.Member) message = ChatColor.translateAlternateColorCodes('&', message); - }else if( - sender.hasPermission("bungeecore.group.developer") || - sender.hasPermission("bungeecore.group.moderator") || - sender.hasPermission("bungeecore.group.supporter") || - sender.hasPermission("bungeecore.group.builder")){ - chatcolor = "§r"; - message = ChatColor.translateAlternateColorCodes('&', message); - }else if(sender.hasPermission("bungeecore.group.youtuber")){ - message = ChatColor.translateAlternateColorCodes('&', message); - } String msg = name + "§7»" + chatcolor + " " + message; if(user.getTeam() != 0){ diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 0cbc3d23..61625eab 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -68,7 +68,7 @@ public class SteamwarUser { id = rs.getInt("id"); uuid = UUID.fromString(rs.getString("UUID")); userName = rs.getString("UserName"); - userGroup = UserGroup.valueOf(rs.getString("UserGroup").toUpperCase()); + userGroup = UserGroup.getUsergroup(rs.getString("UserGroup")); banTime = rs.getTimestamp("BanTime"); banReason = rs.getString("BanReason"); team = rs.getInt("Team"); @@ -90,7 +90,7 @@ public class SteamwarUser { user.userName = userName; } }else{ - SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, ?)", connection.getUniqueId().toString(), connection.getName(), UserGroup.Member.name()); + SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", connection.getUniqueId().toString(), connection.getName()); user = dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", connection.getUniqueId().toString())); if(user == null) throw new SecurityException("user == null"); diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java index 632ef285..62c026f7 100644 --- a/src/de/steamwar/bungeecore/sql/UserGroup.java +++ b/src/de/steamwar/bungeecore/sql/UserGroup.java @@ -19,23 +19,28 @@ package de.steamwar.bungeecore.sql; +import java.util.Arrays; +import java.util.stream.Collectors; + public enum UserGroup { - Admin("§4", true, true, true), - Developer("§3", true, true, true), - Moderator("§c", true, true, true), - Supporter("§6", false, true, true), - Builder("§2", false, true, false), - Youtuber("§5", false, false, false), - Member("§7", false, false, false); + Admin("§4", "§e", true, true, true), + Developer("§3", "§f", true, true, true), + Moderator("§c", "§f", true, true, true), + Supporter("§6", "§f", false, true, true), + Builder("§2", "§f", false, true, false), + Youtuber("§5", "§7", false, false, false), + Member("§7", "§7", false, false, false); private final String colorCode; + private final String chatColorCode; private final boolean adminGroup; private final boolean teamGroup; private final boolean checkSchematics; - UserGroup(String colorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics) { + UserGroup(String colorCode, String chatColorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics) { this.colorCode = colorCode; + this.chatColorCode = chatColorCode; this.adminGroup = adminGroup; this.teamGroup = teamGroup; this.checkSchematics = checkSchematics; @@ -56,4 +61,12 @@ public enum UserGroup { public boolean isCheckSchematics() { return checkSchematics; } + + public String getChatColorCode() { + return chatColorCode; + } + + public static UserGroup getUsergroup(String name) { + return Arrays.stream(UserGroup.values()).filter(userGroup -> userGroup.name().equalsIgnoreCase(name)).collect(Collectors.toList()).get(0); + } } \ No newline at end of file