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

View File

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

View File

@ -70,7 +70,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
return true; return true;
} }
String subCommand = split[0]; 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) { if (split.length <= 1) {
p.sendMessage("Must specify a region name"); p.sendMessage("Must specify a region name");
return true; return true;
@ -85,7 +85,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
p.teleport(r.teleportLocation()); p.teleport(r.teleportLocation());
m_plugin.regionManager().addRegion(r); m_plugin.regionManager().addRegion(r);
m_plugin.saveRegions(); 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()); Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
if (r == null) { if (r == null) {
p.sendMessage("There are no regions in this world."); p.sendMessage("There are no regions in this world.");
@ -94,7 +94,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
m_plugin.regionManager().removeRegion(r); m_plugin.regionManager().removeRegion(r);
p.sendMessage("Deleted region " + r.coloredName()); p.sendMessage("Deleted region " + r.coloredName());
m_plugin.saveRegions(); 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()); Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
if (r == null) { if (r == null) {
p.sendMessage("There are no regions in this world."); p.sendMessage("There are no regions in this world.");
@ -106,7 +106,7 @@ public class RegionCommand implements CommandExecutor, TabCompleter {
p.sendMessage("Region post regenerated."); 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())) { for(Region r : m_plugin.regionManager().regionsForWorld(p.getLocation().getWorld())) {
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> { m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
RegionPostBuilder builder = new RegionPostBuilder(r, 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")) { } else if (subCommand.equals("item") && sender.hasPermission("regions.give-items.creator")) {
Player player = (Player)sender; Player player = (Player)sender;
ItemStack createItem = RegionPostItemWatcher.createCreateItem(); ItemStack anchorStack = RegionPostItemWatcher.createAnchor();
if (split.length > 1) { 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()) { for(ItemStack item : rejected.values()) {
player.getLocation().getWorld().dropItem(player.getLocation(), item); player.getLocation().getWorld().dropItem(player.getLocation(), item);
} }

View File

@ -21,7 +21,7 @@ permissions:
description: Allows use of all regions permissions description: Allows use of all regions permissions
children: children:
regions.create: true regions.create: true
regions.remove: true regions.commands.*: true
regions.regen.*: true regions.regen.*: true
regions.bypass.*: true regions.bypass.*: true
regions.give-items.*: true regions.give-items.*: true
@ -35,15 +35,27 @@ permissions:
default: true default: true
description: Use region posts description: Use region posts
regions.create: 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 default: op
description: Create a region children:
regions.remove: regions.commands.remove: true
regions.commands.regen: true
regions.commands.regen.all: true
regions.commands.remove:
default: op default: op
description: Remove a region description: Remove a region
regions.regen: regions.commands.regen:
default: op default: op
description: Regenerates a region post description: Regenerates a region post
regions.regen.all: regions.commands.regen.all:
default: op default: op
description: Regenerates all region posts, including in unloaded chunks description: Regenerates all region posts, including in unloaded chunks
regions.bypass.*: regions.bypass.*: