items: fix compass item detection, give XP when charging and discovering posts, require sneaking to apply items to posts to cut down on misclicks

This commit is contained in:
Torrie Fischer 2021-06-11 10:19:30 -07:00
parent 41addd1a88
commit d463a31ac0
4 changed files with 13 additions and 9 deletions

View File

@ -4,7 +4,7 @@
<groupId>us.camin.regions</groupId> <groupId>us.camin.regions</groupId>
<artifactId>Regions</artifactId> <artifactId>Regions</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.2.99-rc1</version> <version>0.2.99-rc2</version>
<name>regions</name> <name>regions</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>

View File

@ -131,6 +131,9 @@ public class PlayerNotifier implements Listener {
event.player.sendMessage("You discovered the region " + event.region.name()); event.player.sendMessage("You discovered the region " + event.region.name());
event.player.sendTitle(title); event.player.sendTitle(title);
} }
// TODO: Make this configurable and disablable
event.player.giveExp(10);
} }
for(Region region : nearby) { for(Region region : nearby) {
nearbyText.append(" "); nearbyText.append(" ");

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) && player.hasPermission("regions.charge")) { if (player.isSneaking() && 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,9 @@ 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) && player.hasPermission("regions.setbanner")) { // TODO: Make this configurable and disablable
player.giveExp(1);
} else if (player.isSneaking() && 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);
@ -127,7 +129,7 @@ public class RegionPostInteractionWatcher implements Listener {
} else if (nearest.charges() > 0 || player.hasPermission("regions.bypass.charges")) { } else if (nearest.charges() > 0 || player.hasPermission("regions.bypass.charges")) {
m_plugin.getServer().getPluginManager().callEvent(new PlayerPostInteractEvent(player, nearest)); m_plugin.getServer().getPluginManager().callEvent(new PlayerPostInteractEvent(player, nearest));
} else { } else {
player.sendMessage("This region post is not charged. Right click on it while holding cobblestone."); player.sendMessage("This region post is not charged. Right click on it while sneaking and holding a Region Post Charge.");
} }
} }
} }

View File

@ -107,9 +107,9 @@ public class RegionPostItemWatcher implements Listener {
return true; return true;
} }
if (stack.getType() == m_theAnchor.getType()) { if (stack.getType() == m_theCompass.getType()) {
ItemMeta meta = stack.getItemMeta(); ItemMeta meta = stack.getItemMeta();
ItemMeta theItemMeta = m_theAnchor.getItemMeta(); ItemMeta theItemMeta = m_theCompass.getItemMeta();
if (meta.getItemFlags() == theItemMeta.getItemFlags()) { if (meta.getItemFlags() == theItemMeta.getItemFlags()) {
return true; return true;
} }
@ -126,7 +126,7 @@ public class RegionPostItemWatcher implements Listener {
if (stack.getType() == m_theAnchor.getType()) { if (stack.getType() == m_theAnchor.getType()) {
ItemMeta meta = stack.getItemMeta(); ItemMeta meta = stack.getItemMeta();
ItemMeta theItemMeta = m_theAnchor.getItemMeta(); ItemMeta theItemMeta = m_theAnchor.getItemMeta();
if (meta.getLore().equals(theItemMeta.getLore())) { if (meta.getLore() != null && meta.getLore().equals(theItemMeta.getLore())) {
return true; return true;
} }
} }
@ -145,13 +145,12 @@ public class RegionPostItemWatcher implements Listener {
if (isRegionCompass(handStack) && event.getAction() == Action.RIGHT_CLICK_AIR) { if (isRegionCompass(handStack) && event.getAction() == Action.RIGHT_CLICK_AIR) {
event.setCancelled(true); event.setCancelled(true);
ItemStack compassItem = new ItemStack(Material.COMPASS);
Region nearest = m_manager.nearestRegion(player.getLocation()); Region nearest = m_manager.nearestRegion(player.getLocation());
if (nearest == null) { if (nearest == null) {
player.sendMessage("There are no regions in this world!"); player.sendMessage("There are no regions in this world!");
return; return;
} }
compassItem = createCompass(nearest); ItemStack 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() && player.hasPermission("regions.create")) { } else if (!event.isCancelled() && isRegionCreateItem(handStack, player) && event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.getClickedBlock().getType().isInteractable() && player.hasPermission("regions.create")) {