Anchors are now breakable.

Anchors are now properly identified before breaking.
This commit is contained in:
Brianna O'Keefe 2018-09-12 12:06:14 -04:00
parent c76370af43
commit 89c3856ae1
6 changed files with 27 additions and 15 deletions

View File

@ -11,5 +11,7 @@ public interface AnchorManager {
Anchor getAnchor(Location location);
boolean isAnchor(Location location);
Map<Location, Anchor> getAnchors();
}

View File

@ -237,6 +237,19 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
return item;
}
public void bust(Location location) {
if (!getAnchorManager().isAnchor(location)) return;
Anchor anchor = getAnchorManager().getAnchor(location);
if (getConfig().getBoolean("Main.Allow Anchor Breaking")) {
ItemStack item = makeAnchorItem(anchor.getTicksLeft());
anchor.getLocation().getWorld().dropItemNaturally(anchor.getLocation(), item);
}
location.getBlock().setType(Material.AIR);
getAnchorManager().removeAnchor(location);
}
public MenuHandler getMenuHandler() {
return menuHandler;
}

View File

@ -14,7 +14,7 @@ public class EAnchorManager implements AnchorManager {
@Override
public Anchor addAnchor(Location location, Anchor anchor) {
return registeredAnchors.put(location, anchor);
return registeredAnchors.put(roundLocation(location), anchor);
}
@Override
@ -24,7 +24,12 @@ public class EAnchorManager implements AnchorManager {
@Override
public Anchor getAnchor(Location location) {
return registeredAnchors.get(location);
return registeredAnchors.get(roundLocation(location));
}
@Override
public boolean isAnchor(Location location) {
return registeredAnchors.containsKey(location);
}
@Override

View File

@ -34,15 +34,4 @@ public class BlockListeners implements Listener {
instance.getAnchorManager().addAnchor(event.getBlock().getLocation(), new EAnchor(event.getBlock().getLocation(), instance.getTicksFromItem(item)));
}
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Anchor anchor = instance.getAnchorManager().getAnchor(event.getBlock().getLocation());
if (instance.getConfig().getBoolean("Main.Allow Anchor Breaking")) {
ItemStack item = instance.makeAnchorItem(anchor.getTicksLeft());
anchor.getLocation().getWorld().dropItemNaturally(anchor.getLocation(), item);
}
instance.getAnchorManager().removeAnchor(event.getBlock().getLocation());
}
}

View File

@ -27,7 +27,10 @@ public class InteractListeners implements Listener {
@EventHandler
public void onBlockInteract(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) {
instance.bust(e.getClickedBlock().getLocation());
return;
}
if (instance.getAnchorManager().getAnchor(e.getClickedBlock().getLocation()) == null) return;

View File

@ -1,6 +1,6 @@
name: EpicAnchors
description: EpicAnchors
version: 1.1
version: 1.1.2
depend: [Arconix]
main: com.songoda.epicanchors.EpicAnchorsPlugin
author: songoda