|
Post by Telesphoreo on May 16, 2020 22:30:48 GMT
so i'm wondering if theres a better way to store the ranks in SMP rather than a bunch of if statements like this like how could i implement this sorta like TFM where it's a nice list and all you need is Rank.SUPER_ADMIN or something like that or is doing these if statements once the most efficient way? dumb question sorry
|
|
Wild1145
Club 4000 Member
Inactive Player & Inactive Senior Admin
Posts: 10,414
| Likes: 9,680
|
Post by Wild1145 on May 16, 2020 22:39:45 GMT
One option is to just use a CASE Statement? Probably not going to really save you a lot though..?
Other option is to just implement a vanilla permission model and avoid these changes entirely?
Other thing to look at would be DarthCraftMod, probably doing something similar to what you want, it's not maintained now but might give some inspiration, I can't recall how we did it in there though off the top of my head...
|
|
|
Post by Polaris Seltzeris on May 16, 2020 23:25:42 GMT
Very simple, use a single method.
public boolean inGroup(Player player, Group group) { return getGroup(player).equals(group); }
`Group` could be an Enum representing whatever group the player would be in, rather than using strings to do that which sucks.
|
|
|
Post by Telesphoreo on May 17, 2020 1:50:49 GMT
Very simple, use a single method. public boolean inGroup(Player player, Group group) { return getGroup(player).equals(group); }
`Group` could be an Enum representing whatever group the player would be in, rather than using strings to do that which sucks. should've been more clear i have this. what i meant was that i wanted to unify the checking what player the group is and how they show up in tab and how the name appears because then we have stupid shit like this: how could i make it so that it only needs to do this once instead of checking every group. what i imagine is something like @EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer(); player.setPlayerListName(plugin.perms.getTheColorBasedOnTheirRank()); }
TFM has this nice system where each group has each rank have these properties (what it looks like to players, what color the rank is), but I'm not sure how to recreate this using LuckPerms.
|
|
|
Post by Polaris Seltzeris on May 17, 2020 1:54:54 GMT
Very simple, use a single method. public boolean inGroup(Player player, Group group) { return getGroup(player).equals(group); }
`Group` could be an Enum representing whatever group the player would be in, rather than using strings to do that which sucks. how could i make it so that it only needs to do this once instead of checking every group. The 2 solutions off the top of my head are 1: to create some sort of structure/class with basic rank properties including ChatColor, justifiable by the fact that you need it in multiple places 2: add a method which uses a switch/case and returns the ChatColor for group.
|
|
StevenNL2000
Forum Admin
Posts: 6,415
| Likes: 6,936
IGN: StevenNL2000
Timezone: UTC+01:00
Member is Staff. Need immediate assistance? Send a PM
|
Post by StevenNL2000 on May 17, 2020 9:44:50 GMT
import org.bukkit.ChatColor;
import java.util.HashMap; import java.util.Map;
public enum Group {
MODERATOR(ChatColor.LIGHT_PURPLE), ADMIN(ChatColor.RED), DEVELOPER(ChatColor.DARK_PURPLE), MANAGER(ChatColor.YELLOW), BUILDER(ChatColor.DARK_AQUA), OWNER(ChatColor.DARK_RED), DEFAULT(ChatColor.WHITE);
private final ChatColor chatColor; private static final Map<String, Group> BY_NAME = new HashMap<>();
private Group(ChatColor chatColor) { this.chatColor = chatColor; }
public ChatColor getChatColor() { return this.chatColor; }
public static Group getByName(String name) { return BY_NAME.getOrDefault(name, DEFAULT); }
static { for (Group group : Group.values()) { BY_NAME.put(group.toString().toLowerCase(), group); } }
}
|
|
|
Post by Telesphoreo on May 17, 2020 19:34:59 GMT
import org.bukkit.ChatColor;
import java.util.HashMap; import java.util.Map;
public enum Group {
MODERATOR(ChatColor.LIGHT_PURPLE), ADMIN(ChatColor.RED), DEVELOPER(ChatColor.DARK_PURPLE), MANAGER(ChatColor.YELLOW), BUILDER(ChatColor.DARK_AQUA), OWNER(ChatColor.DARK_RED), DEFAULT(ChatColor.WHITE);
private final ChatColor chatColor; private static final Map<String, Group> BY_NAME = new HashMap<>();
private Group(ChatColor chatColor) { this.chatColor = chatColor; }
public ChatColor getChatColor() { return this.chatColor; }
public static Group getByName(String name) { return BY_NAME.getOrDefault(name, DEFAULT); }
static { for (Group group : Group.values()) { BY_NAME.put(group.toString().toLowerCase(), group); } }
} Obviously I'm missing something really obvious or am just really dumb. I don't understand how to make this corrospond to the actual group in LuckPerms. This only seems to make the existing endless if statements look more pretty i added a second thing to the enum which is just a nice name for the variables themselves. it seems as if i cant use the getGroup method in these enums, so my second option would be to use a permission node. luckperms used to use group.<groupname> to define what group a player was in and all you had to do was if (player.hasPermission("group.mod") { // bruh }
this didn't seem to work for me in LuckPerms 5.0 when they redid the API. so i could just have a permission like "smp.mod" and give that to the mods and do the same for every other group. the problem is that permissions are inherited and then i have to take away the tfsmp.mod permission from the admin group, which is a pain in the ass, but i guess i have to do that. but then how do i check it? its still endless for loops to check what permission the group has. and ideally i would only need a one liner for the tab listener and get rid of this hellhole public String getDisplay(Player player)
{
if (!(player instanceof Player))
{
return ChatColor.DARK_PURPLE + "Console";
}
else if (isModerator(player))
{
return Group.MODERATOR.name;
}
else if (isAdmin(player))
{
return ChatColor.RED + "Admin";
}
else if (isDeveloper(player))
{
return ChatColor.DARK_PURPLE + "Developer";
}
else if (isBuilder(player))
{
return ChatColor.DARK_AQUA + "Builder";
}
else if (isManager(player))
{
return ChatColor.YELLOW + "Manager";
}
else if (isOwner(player))
{
return ChatColor.DARK_RED + "Owner";
}
return ChatColor.GREEN + "Player";
}
public boolean isPlayer(Player player)
{
return inGroup(player, "default");
}
public boolean isModerator(Player player)
{
return getGroup(player).equals("mod");
}
public boolean isAdmin(Player player)
{
return getGroup(player).equals("admin");
}
public boolean isDeveloper(Player player)
{
return getGroup(player).equals("developer");
}
public boolean isManager(Player player)
{
return getGroup(player).equals("manager");
}
public boolean isBuilder(Player player)
{
return getGroup(player).equals("builder");
}
public boolean isOwner(Player player)
{
return getGroup(player).equals("owner");
}
|
|
|
Post by Polaris Seltzeris on May 17, 2020 20:03:37 GMT
import org.bukkit.ChatColor;
import java.util.HashMap; import java.util.Map;
public enum Group {
MODERATOR(ChatColor.LIGHT_PURPLE), ADMIN(ChatColor.RED), DEVELOPER(ChatColor.DARK_PURPLE), MANAGER(ChatColor.YELLOW), BUILDER(ChatColor.DARK_AQUA), OWNER(ChatColor.DARK_RED), DEFAULT(ChatColor.WHITE);
private final ChatColor chatColor; private static final Map<String, Group> BY_NAME = new HashMap<>();
private Group(ChatColor chatColor) { this.chatColor = chatColor; }
public ChatColor getChatColor() { return this.chatColor; }
public static Group getByName(String name) { return BY_NAME.getOrDefault(name, DEFAULT); }
static { for (Group group : Group.values()) { BY_NAME.put(group.toString().toLowerCase(), group); } }
} Obviously I'm missing something really obvious or am just really dumb. I don't understand how to make this corrospond to the actual group in LuckPerms. This only seems to make the existing endless if statements look more pretty public Group getPlayerGroup(Player player) { return Group.getByName(getGroup(player).toLowerCase()); }
public String getDisplay(Player player) { if(!(player instanceof Player)) { return ChatColor.DARK_PURPLE + "Console"; }
Group group = getPlayerGroup(player);
return group.getChatColor() + group.getName(); }
|
|
|
Post by Telesphoreo on May 17, 2020 22:09:48 GMT
Obviously I'm missing something really obvious or am just really dumb. I don't understand how to make this corrospond to the actual group in LuckPerms. This only seems to make the existing endless if statements look more pretty public Group getPlayerGroup(Player player) { return Group.getByName(getGroup(player).toLowerCase()); }
public String getDisplay(Player player) { if(!(player instanceof Player)) { return ChatColor.DARK_PURPLE + "Console"; }
Group group = getPlayerGroup(player);
return group.getChatColor() + group.getName(); } i love you
|
|
|
Post by Polaris Seltzeris on May 17, 2020 22:11:10 GMT
public Group getPlayerGroup(Player player) { return Group.getByName(getGroup(player).toLowerCase()); }
public String getDisplay(Player player) { if(!(player instanceof Player)) { return ChatColor.DARK_PURPLE + "Console"; }
Group group = getPlayerGroup(player);
return group.getChatColor() + group.getName(); } i love you Who
|
|
|
Post by Telesphoreo on May 18, 2020 20:21:41 GMT
How does it feel to have your code on the SMP Deployment System?
|
|
|
Post by Polaris Seltzeris on May 18, 2020 20:26:02 GMT
How does it feel to have your code on the SMP Deployment Sytem? What's a sytem?
|
|
|
Post by Telesphoreo on May 18, 2020 23:52:02 GMT
How does it feel to have your code on the SMP Deployment System? What's a sytem? I sense forgery of my post for comedic effect. It always has said "System"
|
|
|
Post by DragonSlayer2189 on May 19, 2020 23:21:37 GMT
I program in python, and I'm just like: ._. to this entire post
|
|
|
Post by Polaris Seltzeris on May 19, 2020 23:39:33 GMT
|
|