From 6483729608113793f45a61f71907495aee031ef4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 30 Oct 2020 17:08:17 +0100 Subject: [PATCH] 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 a77fd08b..bc615690 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 d3cb3fb0..123ef946 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 4a42e5c8..0cbc3d23 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 00000000..330f69dd --- /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