From 02d18455828ad9f9612134558294504bef583ece Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 28 Oct 2020 19:26:18 +0100 Subject: [PATCH 1/9] Unified Color and Groups for Tablist and Chat --- .../listeners/ConnectionListener.java | 63 +++++-------------- .../bungeecore/listeners/TablistManager.java | 15 +++-- .../steamwar/bungeecore/sql/SteamwarUser.java | 62 ++++++++++++++++-- 3 files changed, 82 insertions(+), 58 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index f34022c..a77fd08 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -58,53 +58,24 @@ public class ConnectionListener extends BasicListener { public void onPostLogin(PostLoginEvent event) { ProxiedPlayer player = event.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - player.removeGroups("Admin", "team"); - switch(user.getUserGroup()){ - case "Admin": - player.addGroups(ADMIN_GROUP, TEAM_GROUP); - player.setPermission("bungeecore.group.admin", true); - player.setPermission(CHECK_PERMISSION, true); - player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName("§4Admin " + player.getName() + "§r"); - break; - case "Developer": - player.addGroups(ADMIN_GROUP, TEAM_GROUP); - player.setPermission("bungeecore.group.developer", true); - player.setPermission(CHECK_PERMISSION, true); - player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName("§3Developer " + player.getName() + "§r"); - break; - case "Moderator": - player.addGroups(ADMIN_GROUP, TEAM_GROUP); - player.setPermission("bungeecore.group.moderator", true); - player.setPermission(CHECK_PERMISSION, true); - player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName("§bModerator " + player.getName() + "§r"); - break; - case "Supporter": - player.addGroups(TEAM_GROUP); - player.setPermission("bungeecore.group.supporter", true); - player.setPermission(CHECK_PERMISSION, true); - player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName("§1Supporter " + player.getName() + "§r"); - break; - case "Builder": - player.addGroups(TEAM_GROUP); - player.setPermission("bungeecore.group.builder", true); - player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName("§2Architekt " + player.getName() + "§r"); - break; - case "Youtuber": - player.setPermission("bungeecore.group.youtuber", true); - player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName("§5Youtuber " + player.getName() + "§r"); - break; - case "Member": - default: - player.setDisplayName(player.getName()); - break; - } + player.removeGroups("Admin", "team"); + player.setDisplayName(player.getName()); + + if(user.getUserGroup().isAdminGroup()) + player.addGroups(ADMIN_GROUP, TEAM_GROUP); + + if(user.getUserGroup().isTeamGroup()) + player.addGroups(TEAM_GROUP); + + if(user.getUserGroup().isCheckSchematics()) + player.setPermission(CHECK_PERMISSION, true); + + if(user.getUserGroup() != SteamwarUser.UserGroup.MEMBER) { + player.setPermission(YOUTUBER_MODS, true); + player.setDisplayName(user.getUserGroup().getColorCode() + user.getUserGroup().getDisplayName() + " " + player.getName() + "§r"); + player.setPermission("bungeecore.group." + user.getUserGroup().getDisplayName().toLowerCase(), true); + } for(Subserver subserver : Subserver.getServerList()){ if(subserver.getType() == Servertype.ARENA){ diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index d79be22..74f2e3c 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -25,6 +25,7 @@ import codecrafter47.bungeetablistplus.tablist.DefaultCustomTablist; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -197,15 +198,13 @@ public class TablistManager extends BasicListener { private String getTablistName(ProxiedPlayer p, boolean sameServer) { StringBuilder st = new StringBuilder(); - if (p.hasPermission("bungeecore.group.admin")) st.append("§4"); - else if (p.hasPermission("bungeecore.group.developer")) st.append("§3"); - else if (p.hasPermission("bungeecore.group.moderator")) st.append("§b"); - else if (p.hasPermission("bungeecore.group.supporter")) st.append("§1"); - else if (p.hasPermission("bungeecore.group.builder")) st.append("§2"); - else if (p.hasPermission("bungeecore.group.youtuber")) st.append("§5"); + SteamwarUser.UserGroup group = SteamwarUser.UserGroup.getUserGroupByPermission(p); + //else st.append("§7"); - else if (sameServer) st.append("§f"); - else st.append("§7"); + if(group == SteamwarUser.UserGroup.MEMBER && sameServer) + st.append("§f"); + else + st.append(group.getColorCode()); // if (!sameServer) st.append("§o"); return st.append(p.getName()).toString(); diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 43d2398..b2b21f2 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -42,7 +42,7 @@ public class SteamwarUser { private final int id; private final UUID uuid; private String userName; - private String userGroup; + private UserGroup userGroup; private Timestamp banTime; private String banReason; private int team; @@ -68,7 +68,7 @@ public class SteamwarUser { id = rs.getInt("id"); uuid = UUID.fromString(rs.getString("UUID")); userName = rs.getString("UserName"); - userGroup = rs.getString("UserGroup"); + userGroup = UserGroup.valueOf(rs.getString("UserGroup").toUpperCase()); 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 (?, ?, 'Member')", connection.getUniqueId().toString(), connection.getName()); + SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, ?)", connection.getUniqueId().toString(), connection.getName(), UserGroup.STANDARD_GROUP.getDisplayName()); user = dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", connection.getUniqueId().toString())); if(user == null) throw new SecurityException("user == null"); @@ -148,7 +148,7 @@ public class SteamwarUser { return userName; } - public String getUserGroup() { + public UserGroup getUserGroup() { return userGroup; } @@ -254,4 +254,58 @@ public class SteamwarUser { throw new SecurityException("Could not load First Join"); } } + + public enum UserGroup { + + ADMIN("Admin", "§4", true, true, true), + DEVELOPER("Developer", "§3", true, true, true), + MODERATOR("Moderator", "§b", true, true, true), + SUPPORTER("Supporter", "§1", false, true, true), + BUILDER("Builder", "§2", false, true, false), + YOUTUBER("Youtuber", "§5", false, false, false), + MEMBER("Member", "§7", false, false, false); + + public static final UserGroup STANDARD_GROUP = UserGroup.MEMBER; + + private final String displayName; + private final String colorCode; + private final boolean adminGroup; + private final boolean teamGroup; + private final boolean checkSchematics; + + UserGroup(String displayName, String colorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics) { + this.displayName = displayName; + this.colorCode = colorCode; + this.adminGroup = adminGroup; + this.teamGroup = teamGroup; + this.checkSchematics = checkSchematics; + } + + public String getDisplayName() { + return displayName; + } + + public String getColorCode() { + return colorCode; + } + + public boolean isAdminGroup() { + return adminGroup; + } + + public boolean isTeamGroup() { + return teamGroup; + } + + public boolean isCheckSchematics() { + return checkSchematics; + } + + public static UserGroup getUserGroupByPermission(ProxiedPlayer p) { + for (UserGroup group : UserGroup.values()) { + if (p.hasPermission("bungeecore.group." + group.getDisplayName().toLowerCase())) return group; + } + return UserGroup.STANDARD_GROUP; + } + } } From 5913ee5f42c5902f22593d7fb3658ae1f6cdda1f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 28 Oct 2020 22:35:08 +0100 Subject: [PATCH 2/9] Changed Color of Mods. and Supps. --- src/de/steamwar/bungeecore/sql/SteamwarUser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index b2b21f2..4a42e5c 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -259,8 +259,8 @@ public class SteamwarUser { ADMIN("Admin", "§4", true, true, true), DEVELOPER("Developer", "§3", true, true, true), - MODERATOR("Moderator", "§b", true, true, true), - SUPPORTER("Supporter", "§1", false, true, true), + MODERATOR("Moderator", "§c", true, true, true), + SUPPORTER("Supporter", "§6", false, true, true), BUILDER("Builder", "§2", false, true, false), YOUTUBER("Youtuber", "§5", false, false, false), MEMBER("Member", "§7", false, false, false); From 6483729608113793f45a61f71907495aee031ef4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 17:08:17 +0100 Subject: [PATCH 3/9] Refactored UserGroup --- .../listeners/ConnectionListener.java | 9 +-- .../bungeecore/listeners/TablistManager.java | 5 +- .../steamwar/bungeecore/sql/SteamwarUser.java | 56 +-------------- src/de/steamwar/bungeecore/sql/UserGroup.java | 69 +++++++++++++++++++ 4 files changed, 78 insertions(+), 61 deletions(-) create mode 100644 src/de/steamwar/bungeecore/sql/UserGroup.java diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index a77fd08..bc61569 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -25,6 +25,7 @@ import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.commands.ChallengeCommand; import de.steamwar.bungeecore.commands.MsgCommand; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.UserGroup; import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; @@ -63,7 +64,7 @@ public class ConnectionListener extends BasicListener { player.setDisplayName(player.getName()); if(user.getUserGroup().isAdminGroup()) - player.addGroups(ADMIN_GROUP, TEAM_GROUP); + player.addGroups(ADMIN_GROUP); if(user.getUserGroup().isTeamGroup()) player.addGroups(TEAM_GROUP); @@ -71,10 +72,10 @@ public class ConnectionListener extends BasicListener { if(user.getUserGroup().isCheckSchematics()) player.setPermission(CHECK_PERMISSION, true); - if(user.getUserGroup() != SteamwarUser.UserGroup.MEMBER) { + if(user.getUserGroup() != UserGroup.Member) { player.setPermission(YOUTUBER_MODS, true); - player.setDisplayName(user.getUserGroup().getColorCode() + user.getUserGroup().getDisplayName() + " " + player.getName() + "§r"); - player.setPermission("bungeecore.group." + user.getUserGroup().getDisplayName().toLowerCase(), true); + player.setDisplayName(user.getUserGroup().getColorCode() + user.getUserGroup().name() + " " + player.getName() + "§r"); + player.setPermission("bungeecore.group." + user.getUserGroup().name().toLowerCase(), true); } for(Subserver subserver : Subserver.getServerList()){ diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index d3cb3fb..123ef94 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -26,6 +26,7 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.UserGroup; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -205,10 +206,10 @@ public class TablistManager extends BasicListener { } StringBuilder st = new StringBuilder(); - SteamwarUser.UserGroup group = SteamwarUser.UserGroup.getUserGroupByPermission(p); + UserGroup group = SteamwarUser.get(p).getUserGroup(); //else st.append("§7"); - if(group == SteamwarUser.UserGroup.MEMBER && sameServer) + if(group == UserGroup.Member && sameServer) st.append("§f"); else st.append(group.getColorCode()); diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 4a42e5c..0cbc3d2 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -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.STANDARD_GROUP.getDisplayName()); + SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, ?)", connection.getUniqueId().toString(), connection.getName(), UserGroup.Member.name()); user = dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", connection.getUniqueId().toString())); if(user == null) throw new SecurityException("user == null"); @@ -254,58 +254,4 @@ public class SteamwarUser { throw new SecurityException("Could not load First Join"); } } - - public enum UserGroup { - - ADMIN("Admin", "§4", true, true, true), - DEVELOPER("Developer", "§3", true, true, true), - MODERATOR("Moderator", "§c", true, true, true), - SUPPORTER("Supporter", "§6", false, true, true), - BUILDER("Builder", "§2", false, true, false), - YOUTUBER("Youtuber", "§5", false, false, false), - MEMBER("Member", "§7", false, false, false); - - public static final UserGroup STANDARD_GROUP = UserGroup.MEMBER; - - private final String displayName; - private final String colorCode; - private final boolean adminGroup; - private final boolean teamGroup; - private final boolean checkSchematics; - - UserGroup(String displayName, String colorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics) { - this.displayName = displayName; - this.colorCode = colorCode; - this.adminGroup = adminGroup; - this.teamGroup = teamGroup; - this.checkSchematics = checkSchematics; - } - - public String getDisplayName() { - return displayName; - } - - public String getColorCode() { - return colorCode; - } - - public boolean isAdminGroup() { - return adminGroup; - } - - public boolean isTeamGroup() { - return teamGroup; - } - - public boolean isCheckSchematics() { - return checkSchematics; - } - - public static UserGroup getUserGroupByPermission(ProxiedPlayer p) { - for (UserGroup group : UserGroup.values()) { - if (p.hasPermission("bungeecore.group." + group.getDisplayName().toLowerCase())) return group; - } - return UserGroup.STANDARD_GROUP; - } - } } diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java new file mode 100644 index 0000000..330f69d --- /dev/null +++ b/src/de/steamwar/bungeecore/sql/UserGroup.java @@ -0,0 +1,69 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.bungeecore.sql; + +public enum UserGroup { + + Admin("§4", true, true, true, 6), + Developer("§3", true, true, true, 5), + Moderator("§c", true, true, true, 4), + Supporter("§6", false, true, true, 3), + Builder("§2", false, true, false, 2), + Youtuber("§5", false, false, false, 1), + Member("§7", false, false, false, 0); + + private final String colorCode; + private final boolean adminGroup; + private final boolean teamGroup; + private final boolean checkSchematics; + private final int permissionlevel; + + UserGroup(String colorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics, int permissionlevel) { + this.colorCode = colorCode; + this.adminGroup = adminGroup; + this.teamGroup = teamGroup; + this.checkSchematics = checkSchematics; + this.permissionlevel = permissionlevel; + } + + public String getColorCode() { + return colorCode; + } + + public boolean isAdminGroup() { + return adminGroup; + } + + public boolean isTeamGroup() { + return teamGroup; + } + + public boolean isCheckSchematics() { + return checkSchematics; + } + + public int getPermissionlevel() { + return permissionlevel; + } + + public boolean isHigherThen(UserGroup checkAgainst) { + return permissionlevel >= checkAgainst.permissionlevel; + } +} \ No newline at end of file From 349e67ed5c527f6673759947bc495033af09f602 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 19:45:16 +0100 Subject: [PATCH 4/9] Refactored Ban Command to only allow downwards bans --- src/de/steamwar/bungeecore/commands/BanCommand.java | 8 ++++++++ src/de/steamwar/bungeecore/commands/MuteCommand.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 9ac7ff8..355efec 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -46,6 +46,14 @@ public class BanCommand extends BasicCommand { if(target == null) return; + SteamwarUser p = SteamwarUser.get(sender.getName()); + if(p.getUserGroup().isHigherThen(target.getUserGroup())) { + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDu kannst diesen Spieler nicht muten"); + BungeeCore.send(BungeeCore.get().getProxy().getPlayer(target.getUuid()), + BungeeCore.CHAT_PREFIX + "§c" + p.getUserName() + " hat versucht dich zu Muten!"); + return; + } + Timestamp banTime = parseTime(sender, args[1]); if(banTime == null) return; diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index dc0d681..7ddd303 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -42,6 +42,14 @@ public class MuteCommand extends BasicCommand { if(target == null) return; + SteamwarUser p = SteamwarUser.get(sender.getName()); + if(p.getUserGroup().isHigherThen(target.getUserGroup())) { + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDu kannst diesen Spieler nicht bannen"); + BungeeCore.send(BungeeCore.get().getProxy().getPlayer(target.getUuid()), + BungeeCore.CHAT_PREFIX + "§c" + p.getUserName() + " hat versucht dich zu Bannen!"); + return; + } + Timestamp muteTime = BanCommand.parseTime(sender, args[1]); if(muteTime == null) return; From be1aa30cd3e10e21adbb9c1411ba48f1a38bad48 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 21:46:20 +0100 Subject: [PATCH 5/9] Removed Ban Limiting --- .../bungeecore/commands/BanCommand.java | 8 ------ .../bungeecore/commands/MuteCommand.java | 8 ------ src/de/steamwar/bungeecore/sql/UserGroup.java | 26 ++++++------------- 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 355efec..9ac7ff8 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -46,14 +46,6 @@ public class BanCommand extends BasicCommand { if(target == null) return; - SteamwarUser p = SteamwarUser.get(sender.getName()); - if(p.getUserGroup().isHigherThen(target.getUserGroup())) { - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDu kannst diesen Spieler nicht muten"); - BungeeCore.send(BungeeCore.get().getProxy().getPlayer(target.getUuid()), - BungeeCore.CHAT_PREFIX + "§c" + p.getUserName() + " hat versucht dich zu Muten!"); - return; - } - Timestamp banTime = parseTime(sender, args[1]); if(banTime == null) return; diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index 7ddd303..dc0d681 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -42,14 +42,6 @@ public class MuteCommand extends BasicCommand { if(target == null) return; - SteamwarUser p = SteamwarUser.get(sender.getName()); - if(p.getUserGroup().isHigherThen(target.getUserGroup())) { - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDu kannst diesen Spieler nicht bannen"); - BungeeCore.send(BungeeCore.get().getProxy().getPlayer(target.getUuid()), - BungeeCore.CHAT_PREFIX + "§c" + p.getUserName() + " hat versucht dich zu Bannen!"); - return; - } - Timestamp muteTime = BanCommand.parseTime(sender, args[1]); if(muteTime == null) return; diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java index 330f69d..632ef28 100644 --- a/src/de/steamwar/bungeecore/sql/UserGroup.java +++ b/src/de/steamwar/bungeecore/sql/UserGroup.java @@ -21,26 +21,24 @@ package de.steamwar.bungeecore.sql; public enum UserGroup { - Admin("§4", true, true, true, 6), - Developer("§3", true, true, true, 5), - Moderator("§c", true, true, true, 4), - Supporter("§6", false, true, true, 3), - Builder("§2", false, true, false, 2), - Youtuber("§5", false, false, false, 1), - Member("§7", false, false, false, 0); + 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); private final String colorCode; private final boolean adminGroup; private final boolean teamGroup; private final boolean checkSchematics; - private final int permissionlevel; - UserGroup(String colorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics, int permissionlevel) { + UserGroup(String colorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics) { this.colorCode = colorCode; this.adminGroup = adminGroup; this.teamGroup = teamGroup; this.checkSchematics = checkSchematics; - this.permissionlevel = permissionlevel; } public String getColorCode() { @@ -58,12 +56,4 @@ public enum UserGroup { public boolean isCheckSchematics() { return checkSchematics; } - - public int getPermissionlevel() { - return permissionlevel; - } - - public boolean isHigherThen(UserGroup checkAgainst) { - return permissionlevel >= checkAgainst.permissionlevel; - } } \ No newline at end of file From 915c8d1d25b1e47e8b3eafebde3b8040e07c9b8c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 22:16:55 +0100 Subject: [PATCH 6/9] Fixing... --- src/de/steamwar/bungeecore/listeners/ConnectionListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index bc61569..0deb468 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -61,7 +61,6 @@ public class ConnectionListener extends BasicListener { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); player.removeGroups("Admin", "team"); - player.setDisplayName(player.getName()); if(user.getUserGroup().isAdminGroup()) player.addGroups(ADMIN_GROUP); @@ -76,6 +75,8 @@ public class ConnectionListener extends BasicListener { player.setPermission(YOUTUBER_MODS, true); player.setDisplayName(user.getUserGroup().getColorCode() + user.getUserGroup().name() + " " + player.getName() + "§r"); player.setPermission("bungeecore.group." + user.getUserGroup().name().toLowerCase(), true); + }else { + player.setDisplayName(player.getName()); } for(Subserver subserver : Subserver.getServerList()){ From edd81c6ca66927f947970f10d4d378bd5034ce36 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 22:34:29 +0100 Subject: [PATCH 7/9] 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 dcb95b9..0ee6265 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 0cbc3d2..61625ea 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 632ef28..62c026f 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 From 5d5df4ed2a7c3a9309dd5531024180406153820f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 22:40:57 +0100 Subject: [PATCH 8/9] Changed Supporter Color to &9 --- src/de/steamwar/bungeecore/sql/UserGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java index 62c026f..fbb0a3a 100644 --- a/src/de/steamwar/bungeecore/sql/UserGroup.java +++ b/src/de/steamwar/bungeecore/sql/UserGroup.java @@ -27,7 +27,7 @@ public enum UserGroup { Admin("§4", "§e", true, true, true), Developer("§3", "§f", true, true, true), Moderator("§c", "§f", true, true, true), - Supporter("§6", "§f", false, true, true), + Supporter("§9", "§f", false, true, true), Builder("§2", "§f", false, true, false), Youtuber("§5", "§7", false, false, false), Member("§7", "§7", false, false, false); From 12e27ca6c0f39c22ee5afc6a4c2ebdcbc19cd2f4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 23:13:10 +0100 Subject: [PATCH 9/9] Changed YouTube Name --- src/de/steamwar/bungeecore/sql/UserGroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/sql/UserGroup.java b/src/de/steamwar/bungeecore/sql/UserGroup.java index fbb0a3a..73273dc 100644 --- a/src/de/steamwar/bungeecore/sql/UserGroup.java +++ b/src/de/steamwar/bungeecore/sql/UserGroup.java @@ -29,7 +29,7 @@ public enum UserGroup { Moderator("§c", "§f", true, true, true), Supporter("§9", "§f", false, true, true), Builder("§2", "§f", false, true, false), - Youtuber("§5", "§7", false, false, false), + YouTuber("§5", "§f", false, false, false), Member("§7", "§7", false, false, false); private final String colorCode;