Skip to content

Commit

Permalink
make tag permission checking optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Refrac committed May 21, 2024
1 parent 08bed71 commit a5955db
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public void perform(CommandSender commandSender, String[] args) {
}

// Show list of all available tags
RyMessageUtils.sendSender(player, "&7-------------------------------------");
RyMessageUtils.sendPlayer(player, "&7-------------------------------------");
SimpleTags.getInstance().getTagManager().getLoadedTags().forEach(tag -> {
RyMessageUtils.sendPlayer(player, "&e" + tag.getConfigName() + "&7(" + tag.getTagName() + "&7) &7- " + tag.getTagPrefix());
});
RyMessageUtils.sendSender(player, "&7-------------------------------------");
RyMessageUtils.sendPlayer(player, "&7-------------------------------------");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void onChat(AsyncPlayerChatEvent event) {
ProfileData profile = SimpleTags.getInstance().getProfileManager().getProfile(player.getUniqueId()).getData();

if (SimpleTags.getInstance().getSettings().USE_CHAT)
event.setFormat(ChatColor.translateAlternateColorCodes('&', profile.getTagPrefix() + event.getFormat()));
event.setFormat(ChatColor.translateAlternateColorCodes('&', profile.getTagPrefix() + ChatColor.RESET + event.getFormat()));
}

@EventHandler
Expand All @@ -73,7 +73,7 @@ public void onReload(PlayerCommandPreprocessEvent event) {
if (!event.getMessage().equalsIgnoreCase("/reload confirm"))
return;

RyMessageUtils.sendSender(player, "&cUse of /reload is not recommended as it can cause issues often cases. Please restart your server when possible.");
RyMessageUtils.sendPlayer(player, "&cUse of /reload is not recommended as it can cause issues often cases. Please restart your server when possible.");
}

private void sendDevMessage(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void loadTags() {
SimpleTags.getInstance().getTags().TAGS.getRoutesAsStrings(false).forEach(tag ->
addTag(new Tag(tag, SimpleTags.getInstance().getTagsFile().getString("tags." + tag + ".name"),
SimpleTags.getInstance().getTagsFile().getString("tags." + tag + ".prefix"),
SimpleTags.getInstance().getTagsFile().getString("tags." + tag + ".item"))));
SimpleTags.getInstance().getTagsFile().getString("tags." + tag + ".item.material"))));

RyMessageUtils.sendConsole(true, "&aLoaded &e" + getLoadedTags().size() + " &atags.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

public class Config {

public boolean USE_CHAT;
public boolean USE_CHAT, REQUIRE_PERMISSION;
public String DATA_TYPE;

public Config() {
loadConfig();
}

public void loadConfig() {
REQUIRE_PERMISSION = SimpleTags.getInstance().getConfigFile().getBoolean("require-permission");
USE_CHAT = SimpleTags.getInstance().getConfigFile().getBoolean("use-chat");
DATA_TYPE = SimpleTags.getInstance().getConfigFile().getString("data-type");
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/me/refracdevelopment/simpletags/menu/TagsItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,31 @@ public class TagsItem {
private int data, customModelData;
private List<String> lore;

public TagsItem() {
public TagsItem(Tag tag) {
this.material = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getString("tag-item.material");
this.name = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getString("tag-item.name");
this.skullOwner = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getString("tag-item.skullOwner");
this.data = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getInt("tag-item.data");
this.customModelData = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getInt("tag-item.customModelData");
this.customModelData = SimpleTags.getInstance().getTags().TAGS.getInt(tag.getConfigName() + ".item.customModelData");
this.lore = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getStringList("tag-item.lore");

if (SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.head-database"))
if (SimpleTags.getInstance().getMenus().TAGS_ITEMS.get("tag-item.head-database") != null)
this.headDatabase = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.head-database", false);
else
this.headDatabase = false;

if (SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.skulls"))
if (SimpleTags.getInstance().getMenus().TAGS_ITEMS.get("tag-item.skulls") != null)
this.skulls = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.skulls", false);
else
this.skulls = false;

if (SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.customData"))
this.customData = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.customData", false);
if (SimpleTags.getInstance().getTags().TAGS.get("tag-item.customData") != null)
this.customData = SimpleTags.getInstance().getTags().TAGS.getBoolean(tag.getConfigName() + ".item.customData", false);
else
this.customData = false;

if (SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.itemsAdder"))
this.itemsAdder = SimpleTags.getInstance().getMenus().TAGS_ITEMS.getBoolean("tag-item.itemsAdder", false);
if (SimpleTags.getInstance().getTags().TAGS.get(tag.getConfigName() + ".itemsAdder") != null)
this.itemsAdder = SimpleTags.getInstance().getTags().TAGS.getBoolean(tag.getConfigName() + ".item.itemsAdder", false);
else
this.itemsAdder = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ public void setMenuItems() {
if (index >= tags.size())
break;

if (tags.get(index) != null && playerMenuUtility.getOwner().hasPermission("simpletags.tag." + tags.get(index).getConfigName()))
inventory.addItem(tags.get(index).toItemStack(playerMenuUtility.getOwner(), tags.get(index).getConfigName()));
if (tags.get(index) != null) {
if (plugin.getSettings().REQUIRE_PERMISSION && !playerMenuUtility.getOwner().hasPermission("simpletags.tag." + tags.get(index).getConfigName()))
continue;

inventory.addItem(tags.get(index).toItemStack(playerMenuUtility.getOwner()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public Tag(String configName, String tagName, String tagPrefix, String material)
this.material = material;
}

public ItemStack toItemStack(Player player, String tag) {
if (SimpleTags.getInstance().getTagManager().getCachedTag(tag) == null)
return null;

return new TagsItem().getItem(player, SimpleTags.getInstance().getTagManager().getCachedTag(tag));
public ItemStack toItemStack(Player player) {
return new TagsItem(this).getItem(player, this);
}
}
10 changes: 8 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
# \/ \/|__| \/ \//_____/ \/

# This is used for automatic file updating purposes
config-version: '1'
config-version: '2'

# The locale to use in the /locale folder
# Default: en_US
locale: en_US

# Should player's be required to have the tag permission
# in order to see it in commands and menus
# they will still need to have the permission to equip the tag either way
# Default: false
require-permission: false

# Automatically add tags to chat behind a player's name
# This setting should only be used if
# you don't have a chat plugin
Expand All @@ -21,7 +27,7 @@ use-chat: false
# Choose your data saving type:
# MYSQL/MARIADB - Database saving
# SQLITE - Local database saving in a .db file
# Default: FLAT_FILE
# Default: SQLITE
data-type: SQLITE

# Either MySQL or MariaDB will work here.
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/menus.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is used for automatic file updating purposes
config-version: '2'
config-version: '3'

tags:
title: "&8Tags (%total-tags%)"
Expand All @@ -17,9 +17,6 @@ tags:
tag-item:
material: NAME_TAG
data: 0
customData: false
customModelData: "YOURIDHERE"
itemsAdder: false
name: "%tag-name%"
lore:
- "&bPrefix: %tag-prefix%"
Expand Down
13 changes: 10 additions & 3 deletions src/main/resources/tags.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is used for automatic file updating purposes
config-version: '3'
config-version: '4'

tags:
# The tag name used in permissions or commands
Expand All @@ -9,5 +9,12 @@ tags:
name: "&4Dark Red Heart"
# Chat prefix
prefix: '&4❤ '
# Menu item material
item: ''
# Menu item override
item:
# If using ItemsAdder you put the namespaced item id here
material: ''
# Enable this to use custom items from ItemsAdder
itemsAdder: false
# Custom Model Data
customData: false
customModelData: "YOURIDHERE"

0 comments on commit a5955db

Please sign in to comment.