Redid how infinity works.

This commit is contained in:
Brianna 2020-12-10 12:50:59 -06:00
parent 5f9dce66c9
commit a878521e98
2 changed files with 15 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent;
/**
@ -46,4 +47,17 @@ public class BlockListeners implements Listener {
anvil.setHologram(false);
plugin.getAnvilManager().removeAnvil(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) {
String loc = Methods.serializeLocation(event.getBlock());
if (!event.getBlock().getType().name().contains("ANVIL") && !plugin.getConfig().contains("data.anvil." + loc))
return;
UAnvil anvil = plugin.getAnvilManager().getAnvil(event.getBlock());
if (anvil.isInfinity())
event.setCancelled(true);
}
}

View File

@ -33,7 +33,6 @@ public class InteractListeners implements Listener {
@EventHandler
public void onAnvilClick(PlayerInteractEvent event) {
boolean ourRepair = false;
boolean vanillaRepair = false;
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if (block == null) return;
@ -63,10 +62,7 @@ public class InteractListeners implements Listener {
return;
}
ourRepair = true;
} else if (rightClick) {
// allowing normal repair
vanillaRepair = true;
} else if (!player.isSneaking()) {
} else if (!rightClick && !player.isSneaking()) {
// that's us!
ourRepair = true;
}
@ -74,9 +70,6 @@ public class InteractListeners implements Listener {
if (ourRepair) {
RepairGui.newGui(player, anvil1.getLocation());
event.setCancelled(true);
} else if (vanillaRepair && anvil1.isInfinity()) {
player.openInventory(Bukkit.createInventory(null, InventoryType.ANVIL, ChatColor.DARK_GRAY + "Repair & Name"));
event.setCancelled(true);
}
}
}