regionpostitemwatcher: simplify compass item management
This commit is contained in:
parent
2fd43aba13
commit
4573e9473e
@ -46,11 +46,21 @@ public class RegionPostItemWatcher implements Listener {
|
|||||||
m_plugin = plugin;
|
m_plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public ItemStack createCompass() {
|
static public ItemStack createCompass(Region r) {
|
||||||
ItemStack stack = new ItemStack(Material.COMPASS);
|
ItemStack stack = new ItemStack(Material.COMPASS);
|
||||||
ItemMeta meta = stack.getItemMeta();
|
ItemMeta meta = stack.getItemMeta();
|
||||||
List<String> lore = new ArrayList<String>();
|
List<String> lore = new ArrayList<String>();
|
||||||
|
if (r == null) {
|
||||||
lore.add("Right click to locate the nearest Region Post");
|
lore.add("Right click to locate the nearest Region Post");
|
||||||
|
} else {
|
||||||
|
CompassMeta compassMeta = (CompassMeta)meta;
|
||||||
|
compassMeta.setDisplayName(r.name() + " Region Compass");
|
||||||
|
compassMeta.setLodestone(r.location());
|
||||||
|
compassMeta.setLodestoneTracked(false);
|
||||||
|
lore.add("Right click to locate the nearest Region Post");
|
||||||
|
lore.add("Tracking: " + r.name());
|
||||||
|
lore.add("Coordinates: " + r.location().getX() + ", " + r.location().getY());
|
||||||
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
@ -83,7 +93,7 @@ public class RegionPostItemWatcher implements Listener {
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack m_theCompass = createCompass();
|
private ItemStack m_theCompass = createCompass(null);
|
||||||
private ItemStack m_theItem = createCreateItem();
|
private ItemStack m_theItem = createCreateItem();
|
||||||
private static ItemStack m_theChargeItem = createChargeItem();
|
private static ItemStack m_theChargeItem = createChargeItem();
|
||||||
|
|
||||||
@ -140,15 +150,7 @@ public class RegionPostItemWatcher implements Listener {
|
|||||||
player.sendMessage("There are no regions in this world!");
|
player.sendMessage("There are no regions in this world!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CompassMeta compassMeta = (CompassMeta)compassItem.getItemMeta();
|
compassItem = createCompass(nearest);
|
||||||
compassMeta.setDisplayName(nearest.name());
|
|
||||||
compassMeta.setLodestone(nearest.location());
|
|
||||||
compassMeta.setLodestoneTracked(false);
|
|
||||||
ArrayList<String> newLore = new ArrayList<String>();
|
|
||||||
newLore.add("Right click to locate the nearest Region Post");
|
|
||||||
newLore.add("Tracking: " + nearest.name());
|
|
||||||
compassMeta.setLore(newLore);
|
|
||||||
compassItem.setItemMeta(compassMeta);
|
|
||||||
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()) {
|
||||||
@ -162,7 +164,6 @@ public class RegionPostItemWatcher implements Listener {
|
|||||||
player.sendMessage("You are too close to the region post for " + nearest.name());
|
player.sendMessage("You are 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());
|
||||||
//player.teleport(r.teleportLocation());
|
|
||||||
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);
|
||||||
builder.build();
|
builder.build();
|
||||||
|
@ -62,7 +62,7 @@ public class RegionOpCommand implements CommandExecutor, TabCompleter {
|
|||||||
});
|
});
|
||||||
} else if (subCommand.equals("compass") && sender.hasPermission("regions.give-items.compass")) {
|
} else if (subCommand.equals("compass") && sender.hasPermission("regions.give-items.compass")) {
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
ItemStack compassItem = RegionPostItemWatcher.createCreateItem();
|
ItemStack compassItem = RegionPostItemWatcher.createCompass(m_plugin.regionManager().nearestRegion(player.getLocation()));
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
compassItem.setAmount(Integer.parseInt(split[1]));
|
compassItem.setAmount(Integer.parseInt(split[1]));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user