From 9bdc4b2f1d7c139819eccfef22998dda1315f132 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 8 Nov 2020 16:36:08 +0100 Subject: [PATCH] Changing Color on Bauservers --- .../core/events/PlayerJoinedEvent.java | 33 ++--------- .../src/de/steamwar/sql/SteamwarUser.java | 2 +- .../src/de/steamwar/sql/UserGroup.java | 59 ++++++++++++++++--- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java b/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java index d698238..8b78106 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java @@ -20,6 +20,7 @@ package de.steamwar.core.events; import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserGroup; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -34,33 +35,11 @@ public class PlayerJoinedEvent implements Listener{ Player player = event.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - switch(user.getUserGroup()){ - case Admin: - player.setDisplayName("§4Admin " + player.getName() + "§r"); - break; - case Developer: - player.setDisplayName("§3Developer " + player.getName() + "§r"); - break; - case Moderator: - player.setDisplayName("§bModerator " + player.getName() + "§r"); - break; - case Supporter: - player.setDisplayName("§1Supporter " + player.getName() + "§r"); - break; - case Builder: - player.setDisplayName("§2Architekt " + player.getName() + "§r"); - break; - case Youtuber: - player.setDisplayName("§5Youtuber " + player.getName() + "§r"); - break; - case Premium: - player.setDisplayName("§6Premium " + player.getName() + "§r"); - break; - case Member: - default: - player.setDisplayName("§7" + player.getName() + "§r"); - break; - } + if(user.getUserGroup() != UserGroup.Member) { + UserGroup group = user.getUserGroup(); + player.setDisplayName(group.getColorCode() + group.name() + " " + player.getName() + "§r"); + } else + player.setDisplayName(user.getUserGroup().getColorCode() + player.getName() + "§r"); event.setJoinMessage("§a§l» §r" + player.getDisplayName()); } diff --git a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java index d05202c..76e8c2a 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java @@ -52,7 +52,7 @@ public class SteamwarUser { id = rs.getInt("id"); uuid = java.util.UUID.fromString(rs.getString("UUID")); userName = rs.getString("UserName"); - userGroup = UserGroup.valueOf(rs.getString("UserGroup")); + userGroup = UserGroup.getUsergroup(rs.getString("UserGroup")); team = rs.getInt("Team"); bedrock = rs.getBoolean("Bedrock"); diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserGroup.java b/SpigotCore_Main/src/de/steamwar/sql/UserGroup.java index a315d74..617f6f8 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/UserGroup.java +++ b/SpigotCore_Main/src/de/steamwar/sql/UserGroup.java @@ -19,13 +19,54 @@ package de.steamwar.sql; +import java.util.Arrays; +import java.util.stream.Collectors; + public enum UserGroup { - Admin, - Developer, - Moderator, - Supporter, - Builder, - Youtuber, - Premium, - Member -} + + Admin("§4", "§e", true, true, true), + Developer("§3", "§f", true, true, true), + Moderator("§c", "§f", true, true, true), + Supporter("§9", "§f", false, true, true), + Builder("§2", "§f", false, true, false), + YouTuber("§5", "§f", 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, String chatColorCode, boolean adminGroup, boolean teamGroup, boolean checkSchematics) { + this.colorCode = colorCode; + this.chatColorCode = chatColorCode; + this.adminGroup = adminGroup; + this.teamGroup = teamGroup; + this.checkSchematics = checkSchematics; + } + + public String getColorCode() { + return colorCode; + } + + public boolean isAdminGroup() { + return adminGroup; + } + + public boolean isTeamGroup() { + return teamGroup; + } + + 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 -- 2.39.5