Skip to content

Commit

Permalink
Permissions refactor
Browse files Browse the repository at this point in the history
Remove use-permissions option from the config and give all permissions by default.
  • Loading branch information
Majekdor committed Jun 25, 2021
1 parent 477524b commit dd8994a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.majek.hexnicks</groupId>
<artifactId>HexNicks</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
<packaging>jar</packaging>

<name>HexNicks</name>
Expand Down
56 changes: 22 additions & 34 deletions src/main/java/dev/majek/hexnicks/CommandNick.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
FileConfiguration config = HexNicks.instance.getConfig();
int max = config.getInt("max-length");
int min = config.getInt("min-length");
String foo = "&#336633$This is a &btest message with a <gradient:#00a5e3:#8dd7bf>gradient</gradient> &fwoo! &c and maybe some fancy ${hover,&ahover,WOOO} text? ${";

//player.sendMessage(TextUtils.parseExpression(BaseComponent.toLegacyText(BungeeComponentSerializer.get().serialize(MiniMessage.get().parse(HexNicks.applyColorCodes(foo))))));
//player.sendMessage(MiniMessage.get().parse("&#336633This is a &btest message with a <gradient:#00a5e3:#8dd7bf>gradient</gradient> &fwoo!"));
//player.sendMessage(HexNicks.format("&#336633This is a &btest message with a <gradient:#00a5e3:#8dd7bf>gradient</gradient> &fwoo!"));

if (config.getBoolean("use-permissions", false)) {
if (!player.hasPermission("hexnicks.use")) {
player.sendMessage(TextUtils.applyColorCodes(config.getString("no-permission")));
return true;
}
if (!player.hasPermission("hexnicks.nick")) {
player.sendMessage(TextUtils.applyColorCodes(config.getString("no-permission")));
return true;
}

if (args.length >= 1) {
Expand Down Expand Up @@ -108,11 +101,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
Player player = (Player) sender;
FileConfiguration config = HexNicks.instance.getConfig();

if (config.getBoolean("use-permissions")) {
if (!player.hasPermission("hexnicks.use")) {
player.sendMessage(TextUtils.applyColorCodes(config.getString("no-permission")));
return true;
}
if (!player.hasPermission("hexnicks.nonick")) {
player.sendMessage(TextUtils.applyColorCodes(config.getString("no-permission")));
return true;
}

if (args.length > 0) {
Expand All @@ -130,7 +121,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
} else {

setNickname(player, player.getName(), false);

player.sendMessage(TextUtils.applyColorCodes(config.getString("nickname-removed")));
}

Expand All @@ -148,12 +138,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
Player player = (Player) sender;
FileConfiguration config = HexNicks.instance.getConfig();

if (config.getBoolean("use-permissions")) {
if (!player.hasPermission("hexnicks.changecolor")) {
player.sendMessage(TextUtils.applyColorCodes(config.getString("no-permission")));
return true;
}
if (!player.hasPermission("hexnicks.nickcolor")) {
player.sendMessage(TextUtils.applyColorCodes(config.getString("no-permission")));
return true;
}

if (args.length == 1) {
String nick;
if (TextUtils.removeColorCodes(args[0]).equals("")) {
Expand All @@ -174,7 +163,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N

if (cmd.getName().equalsIgnoreCase("hexreload")) {
FileConfiguration config = HexNicks.instance.getConfig();
if (sender.hasPermission("hexnicks.admin")) {
if (sender.hasPermission("hexnicks.reload")) {
HexNicks.instance.reloadConfig();
HexNicks.instance.loadNicksFromJSON();
sender.sendMessage(TextUtils.applyColorCodes(config.getString("config-reloaded")));
Expand All @@ -199,36 +188,35 @@ public static void setNickname(Player player, String nick, boolean sendMessage)
FileConfiguration config = HexNicks.instance.getConfig();

// Separate lines to help with debugging if something goes wrong
String finalNick = nick;
if (player.hasPermission("hexnicks.colors.hex")) {
Component nickComp = MiniMessage.get().parse(finalNick);
Component nickComp = MiniMessage.get().parse(nick);
BaseComponent[] nickBase = BungeeComponentSerializer.get().serialize(nickComp);
finalNick = BaseComponent.toLegacyText(nickBase);
finalNick = TextUtils.applyColorCodes(finalNick + "&r&f");
nick = BaseComponent.toLegacyText(nickBase);
nick = TextUtils.applyColorCodes(nick + "&r&f");
} else if (player.hasPermission("hexnicks.colors.normal"))
finalNick = TextUtils.applyColorCodes(finalNick, false, true);
nick = TextUtils.applyColorCodes(nick, false, true);
else
finalNick = TextUtils.removeColorCodes(finalNick);
nick = TextUtils.removeColorCodes(nick);

player.setDisplayName(finalNick);
player.setDisplayName(nick);

if (config.getBoolean("tab-nicknames"))
player.setPlayerListName(finalNick);
player.setPlayerListName(nick);

nicks.put(player.getUniqueId(), finalNick);
nicks.put(player.getUniqueId(), nick);

try {
HexNicks.instance.jsonConfig.putInJSONObject(player.getUniqueId().toString(), finalNick);
HexNicks.instance.jsonConfig.putInJSONObject(player.getUniqueId().toString(), nick);
} catch (IOException | ParseException e) {
HexNicks.instance.getLogger().severe("Error saving nickname to nicknames.json data file.");
e.printStackTrace();
}

// SQL shit
if (HexNicks.instance.SQL.isConnected())
HexNicks.instance.data.addNickname(player.getUniqueId(), finalNick);
HexNicks.instance.data.addNickname(player.getUniqueId(), nick);
if (sendMessage)
player.sendMessage(TextUtils.applyColorCodes((config.getString("nickname-set") + "").replace("%nick%", finalNick)));
player.sendMessage(TextUtils.applyColorCodes((config.getString("nickname-set") + "").replace("%nick%", nick)));
}

public String getNickFromMsg(String[] args, Player player) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ max-length: 20
min-length: 3

# If set to true only players with permission hexnicks.use will be able to use /nick (false by default)
# No longer does anything, all permissions are given by default. Must be negated with permission manager,
use-permissions: false

# If set to true then players nicknames will be shown in the tablist
Expand Down
34 changes: 25 additions & 9 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,45 @@ commands:
description: Change your nickname.
aliases: [nickname]
usage: /nick [player] <nickname> | Use /nick help for more
permission: hexnicks.nick
nickcolor:
description: Change just the color of your nickname.
aliases: [colornick]
usage: /nick <colorcode>
permission: hexnicks.nickcolor
nonick:
description: Remove you nickname.
usage: /nonick [player]
permission: hexnicks.nonick
hexreload:
description: Reload the plugin config file and data file.
permission: hexnicks.reload

permissions:
hexnicks.use:
description: Use /nick if use-permissions is enabled in the config.yml
children: [hexnicks.changecolor, hexnicks.colors.normal, hexnicks.colors.hex]
hexnicks.changecolor:
description: Use /nickcolor if use-permissions is enabled in the config.yml
hexnicks.nick:
description: Permission to use /nick with normal and hex color codes.
children:
- hexnicks.colors.normal
- hexnicks.colors.hex
default: true
hexnicks.nickcolor:
description: Permission to use /nickcolor with normal and hex color codes.
children:
- hexnicks.colors.normal
- hexnicks.colors.hex
default: true
hexnicks.colors.normal:
description: Ability to use normal color codes in nicknames
description: Ability to use normal color codes in nicknames.
hexnicks.colors.hex:
description: Ability to use hex color codes in nicknames
description: Ability to use hex color codes in nicknames.
hexnicks.admin:
description: Ability to run HexNicks admin commands.
children:
- hexnicks.reload
default: op
hexnicks.chat:
description: Ability to use color codes in chat if use-permissions is enabled in the config.yml
hexnicks.reload:
description: Permission to reload the plugin.
default: op
hexnicks.chat:
description: Permission to use color codes in chat.
default: true

0 comments on commit dd8994a

Please sign in to comment.