permissions: create separate perms for commands vs items, rename creator item to anchor

This commit is contained in:
Torrie Fischer 2021-06-11 09:34:26 -07:00
parent b04ac9e5a4
commit 41addd1a88
5 changed files with 40 additions and 26 deletions

View File

@ -103,7 +103,7 @@ public class RegionPostInteractionWatcher implements Listener {
player.sendMessage("You cannot use region posts at this time.");
return;
}
if (RegionPostItemWatcher.isChargeItem(handStack)) {
if (RegionPostItemWatcher.isChargeItem(handStack) && player.hasPermission("regions.charge")) {
nearest.addCharges(1);
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
RegionPostBuilder builder = new RegionPostBuilder(nearest, m_plugin);
@ -112,7 +112,7 @@ public class RegionPostInteractionWatcher implements Listener {
m_plugin.saveRegions();
player.setItemInHand(handStack.subtract());
m_plugin.getServer().getPluginManager().callEvent(new PlayerAddRegionChargeEvent(player, nearest));
} else if (isBannerItem(handStack)) {
} else if (isBannerItem(handStack) && player.hasPermission("regions.setbanner")) {
DyeColor bannerColor = DyeColor.getByDyeData(handStack.getData().getData());
BannerMeta bannerMeta = (BannerMeta)meta;
log.info("Setting banner color to " + bannerColor);

View File

@ -81,7 +81,7 @@ public class RegionPostItemWatcher implements Listener {
return stack;
}
static public ItemStack createCreateItem() {
static public ItemStack createAnchor() {
ItemStack stack = new ItemStack(Material.LANTERN);
ItemMeta meta = stack.getItemMeta();
List<String> lore = new ArrayList<String>();
@ -89,12 +89,13 @@ public class RegionPostItemWatcher implements Listener {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
meta.setLore(lore);
meta.setDisplayName("Region Post Anchor");
stack.setItemMeta(meta);
return stack;
}
private ItemStack m_theCompass = createCompass(null);
private ItemStack m_theItem = createCreateItem();
private ItemStack m_theAnchor = createAnchor();
private static ItemStack m_theChargeItem = createChargeItem();
public static boolean isChargeItem(ItemStack stack) {
@ -106,9 +107,9 @@ public class RegionPostItemWatcher implements Listener {
return true;
}
if (stack.getType() == m_theItem.getType()) {
if (stack.getType() == m_theAnchor.getType()) {
ItemMeta meta = stack.getItemMeta();
ItemMeta theItemMeta = m_theItem.getItemMeta();
ItemMeta theItemMeta = m_theAnchor.getItemMeta();
if (meta.getItemFlags() == theItemMeta.getItemFlags()) {
return true;
}
@ -118,13 +119,13 @@ public class RegionPostItemWatcher implements Listener {
}
public boolean isRegionCreateItem(ItemStack stack, Player p) {
if (stack.isSimilar(m_theItem)) {
if (stack.isSimilar(m_theAnchor)) {
return true;
}
if (stack.getType() == m_theItem.getType()) {
if (stack.getType() == m_theAnchor.getType()) {
ItemMeta meta = stack.getItemMeta();
ItemMeta theItemMeta = m_theItem.getItemMeta();
ItemMeta theItemMeta = m_theAnchor.getItemMeta();
if (meta.getLore().equals(theItemMeta.getLore())) {
return true;
}
@ -153,15 +154,16 @@ public class RegionPostItemWatcher implements Listener {
compassItem = createCompass(nearest);
player.setItemInHand(compassItem);
player.sendMessage("Now tracking " + nearest.name());
} else if (!event.isCancelled() && isRegionCreateItem(handStack, player) && event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.getClickedBlock().getType().isInteractable()) {
} else if (!event.isCancelled() && isRegionCreateItem(handStack, player) && event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.getClickedBlock().getType().isInteractable() && player.hasPermission("regions.create")) {
event.setUseItemInHand(Event.Result.DENY);
event.setCancelled(true);
if (meta.getDisplayName().equals("")) {
if (meta.getDisplayName().equals("") || meta.getDisplayName().equals("Region Post Anchor")) {
player.sendMessage("You must first give this item a name!");
} else {
Region nearest = m_manager.nearestRegion(player.getLocation());
if (nearest != null && player.getLocation().distance(nearest.interactLocation()) <= 500) {
player.sendMessage("You are too close to the region post for " + nearest.name());
Region nearest = m_manager.nearestRegion(event.getClickedBlock().getLocation());
if (nearest != null && event.getClickedBlock().getLocation().distance(nearest.interactLocation()) < 500) {
int distance = 500 - (int)event.getClickedBlock().getLocation().distance(nearest.interactLocation());
player.sendMessage("You are " + distance + " blocks too close to the region post for " + nearest.name() + ".");
} else {
Region r = new Region(meta.getDisplayName(), event.getClickedBlock().getRelative(event.getBlockFace()).getLocation());
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {

View File

@ -70,7 +70,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
return true;
}
String subCommand = split[0];
if (subCommand.equals("create") && p.hasPermission("regions.create")) {
if (subCommand.equals("create") && p.hasPermission("regions.commands.create")) {
if (split.length <= 1) {
p.sendMessage("Must specify a region name");
return true;
@ -85,7 +85,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
p.teleport(r.teleportLocation());
m_plugin.regionManager().addRegion(r);
m_plugin.saveRegions();
} else if (subCommand.equals("remove") && p.hasPermission("regions.remove")) {
} else if (subCommand.equals("remove") && p.hasPermission("regions.commands.remove")) {
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
if (r == null) {
p.sendMessage("There are no regions in this world.");
@ -94,7 +94,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
m_plugin.regionManager().removeRegion(r);
p.sendMessage("Deleted region " + r.coloredName());
m_plugin.saveRegions();
} else if (subCommand.equals("regen") && p.hasPermission("regions.regen")) {
} else if (subCommand.equals("regen") && p.hasPermission("regions.commands.regen")) {
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
if (r == null) {
p.sendMessage("There are no regions in this world.");
@ -106,7 +106,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
p.sendMessage("Region post regenerated.");
});
}
} else if (subCommand.equals("regenall") && p.hasPermission("regions.regen.all")) {
} else if (subCommand.equals("regenall") && p.hasPermission("regions.commands.regen.all")) {
for(Region r : m_plugin.regionManager().regionsForWorld(p.getLocation().getWorld())) {
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);

View File

@ -72,11 +72,11 @@ public class RegionOpCommand implements CommandExecutor, TabCompleter {
}
} else if (subCommand.equals("item") && sender.hasPermission("regions.give-items.creator")) {
Player player = (Player)sender;
ItemStack createItem = RegionPostItemWatcher.createCreateItem();
ItemStack anchorStack = RegionPostItemWatcher.createAnchor();
if (split.length > 1) {
createItem.setAmount(Integer.parseInt(split[1]));
anchorStack.setAmount(Integer.parseInt(split[1]));
}
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(createItem);
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(anchorStack);
for(ItemStack item : rejected.values()) {
player.getLocation().getWorld().dropItem(player.getLocation(), item);
}

View File

@ -21,7 +21,7 @@ permissions:
description: Allows use of all regions permissions
children:
regions.create: true
regions.remove: true
regions.commands.*: true
regions.regen.*: true
regions.bypass.*: true
regions.give-items.*: true
@ -35,15 +35,27 @@ permissions:
default: true
description: Use region posts
regions.create:
default: true
description: Create a region with a region item
regions.setbanner:
default: true
description: Allows setting a region post banner
regions.charge:
default: true
description: Allows charging a region post with a charge item
regions.commands.*:
default: op
description: Create a region
regions.remove:
children:
regions.commands.remove: true
regions.commands.regen: true
regions.commands.regen.all: true
regions.commands.remove:
default: op
description: Remove a region
regions.regen:
regions.commands.regen:
default: op
description: Regenerates a region post
regions.regen.all:
regions.commands.regen.all:
default: op
description: Regenerates all region posts, including in unloaded chunks
regions.bypass.*: