Remove old unused debugger from 2017.

This commit is contained in:
Brianna 2020-01-31 11:18:09 -05:00
parent 3b3f2f7ae2
commit 709f8f29af
7 changed files with 197 additions and 276 deletions

View File

@ -10,7 +10,10 @@ import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.hooks.HologramManager; import com.songoda.core.hooks.HologramManager;
import com.songoda.ultimaterepairing.anvil.AnvilManager; import com.songoda.ultimaterepairing.anvil.AnvilManager;
import com.songoda.ultimaterepairing.anvil.UAnvil; import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.commands.*; import com.songoda.ultimaterepairing.commands.CommandReload;
import com.songoda.ultimaterepairing.commands.CommandSettings;
import com.songoda.ultimaterepairing.commands.CommandURAnvil;
import com.songoda.ultimaterepairing.commands.CommandUltimateRepairing;
import com.songoda.ultimaterepairing.handlers.ParticleTask; import com.songoda.ultimaterepairing.handlers.ParticleTask;
import com.songoda.ultimaterepairing.handlers.RepairHandler; import com.songoda.ultimaterepairing.handlers.RepairHandler;
import com.songoda.ultimaterepairing.listeners.BlockListeners; import com.songoda.ultimaterepairing.listeners.BlockListeners;
@ -18,14 +21,14 @@ import com.songoda.ultimaterepairing.listeners.InteractListeners;
import com.songoda.ultimaterepairing.listeners.InventoryListeners; import com.songoda.ultimaterepairing.listeners.InventoryListeners;
import com.songoda.ultimaterepairing.listeners.PlayerListeners; import com.songoda.ultimaterepairing.listeners.PlayerListeners;
import com.songoda.ultimaterepairing.settings.Settings; import com.songoda.ultimaterepairing.settings.Settings;
import com.songoda.ultimaterepairing.utils.Debugger;
import com.songoda.ultimaterepairing.utils.Methods; import com.songoda.ultimaterepairing.utils.Methods;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import java.util.Arrays;
import java.util.List;
public class UltimateRepairing extends SongodaPlugin { public class UltimateRepairing extends SongodaPlugin {
private static UltimateRepairing INSTANCE; private static UltimateRepairing INSTANCE;
@ -58,7 +61,7 @@ public class UltimateRepairing extends SongodaPlugin {
EconomyManager.load(); EconomyManager.load();
HologramManager.load(this); HologramManager.load(this);
this.setLocale(Settings.LANGUGE_MODE.getString(), false); this.setLocale(Settings.LANGUGE_MODE.getString(), false);
PluginManager pluginManager = getServer().getPluginManager(); PluginManager pluginManager = getServer().getPluginManager();
@ -142,12 +145,8 @@ public class UltimateRepairing extends SongodaPlugin {
@Override @Override
public void onConfigReload() { public void onConfigReload() {
try { this.setLocale(Settings.LANGUGE_MODE.getString(), true);
this.setLocale(Settings.LANGUGE_MODE.getString(), true); particleTask.reload();
particleTask.reload();
} catch (Exception ex) {
Debugger.runReport(ex);
}
} }
public RepairHandler getRepairHandler() { public RepairHandler getRepairHandler() {

View File

@ -3,7 +3,6 @@ package com.songoda.ultimaterepairing.handlers;
import com.songoda.core.compatibility.CompatibleParticleHandler; import com.songoda.core.compatibility.CompatibleParticleHandler;
import com.songoda.core.compatibility.CompatibleParticleHandler.ParticleType; import com.songoda.core.compatibility.CompatibleParticleHandler.ParticleType;
import com.songoda.ultimaterepairing.UltimateRepairing; import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.utils.Debugger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -48,12 +47,8 @@ public class ParticleTask implements Listener {
public void applyParticles() { public void applyParticles() {
if (instance.getAnvilManager().getAnvils().isEmpty()) return; if (instance.getAnvilManager().getAnvils().isEmpty()) return;
try { instance.getAnvilManager().getAnvils().parallelStream()
instance.getAnvilManager().getAnvils().parallelStream() .filter(anvil -> anvil.isParticles() && anvil.isInLoadedChunk())
.filter(anvil -> anvil.isParticles() && anvil.isInLoadedChunk()) .forEach(anvil -> CompatibleParticleHandler.spawnParticles(type, anvil.getLocation().add(.5, 0, .5), amt, 0.25, 0.25, 0.25));
.forEach(anvil -> CompatibleParticleHandler.spawnParticles(type, anvil.getLocation().add(.5, 0, .5), amt, 0.25, 0.25, 0.25));
} catch (Exception ex) {
Debugger.runReport(ex);
}
} }
} }

View File

@ -9,22 +9,18 @@ import com.songoda.ultimaterepairing.anvil.PlayerAnvilData;
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType; import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
import com.songoda.ultimaterepairing.gui.RepairTypeGui; import com.songoda.ultimaterepairing.gui.RepairTypeGui;
import com.songoda.ultimaterepairing.gui.StartConfirmGui; import com.songoda.ultimaterepairing.gui.StartConfirmGui;
import com.songoda.ultimaterepairing.utils.Debugger;
import com.songoda.ultimaterepairing.utils.Methods; import com.songoda.ultimaterepairing.utils.Methods;
import java.util.HashMap; import org.bukkit.*;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/** /**
* Created by songoda on 2/25/2017. * Created by songoda on 2/25/2017.
*/ */
@ -41,56 +37,48 @@ public class RepairHandler {
} }
private void repairType(Player p, Location l) { private void repairType(Player p, Location l) {
try { if (getDataFor(p).getInRepair()) {
if (getDataFor(p).getInRepair()) { yesNo(p, getDataFor(p).getType(), getDataFor(p).getToBeRepaired());
yesNo(p, getDataFor(p).getType(), getDataFor(p).getToBeRepaired()); } else {
} else { guiManager.showGUI(p, new RepairTypeGui(p, l));
guiManager.showGUI(p, new RepairTypeGui(p, l));
}
} catch (Exception ex) {
Debugger.runReport(ex);
} }
} }
public void preRepair(Player player, RepairType type, Location anvil) { public void preRepair(Player player, RepairType type, Location anvil) {
try { ItemStack itemStack = player.getItemInHand();
ItemStack itemStack = player.getItemInHand(); player.setItemInHand(null);
player.setItemInHand(null); Item item = player.getWorld().dropItem(anvil.add(0.5, 2, 0.5), itemStack);
Item item = player.getWorld().dropItem(anvil.add(0.5, 2, 0.5), itemStack);
// Support for EpicHoppers suction. // Support for EpicHoppers suction.
item.setMetadata("grabbed", new FixedMetadataValue(instance, "true")); item.setMetadata("grabbed", new FixedMetadataValue(instance, "true"));
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(instance, true)); item.setMetadata("betterdrops_ignore", new FixedMetadataValue(instance, true));
Vector vec = player.getEyeLocation().getDirection(); Vector vec = player.getEyeLocation().getDirection();
vec.setX(0); vec.setX(0);
vec.setY(0); vec.setY(0);
vec.setZ(0); vec.setZ(0);
item.setVelocity(vec); item.setVelocity(vec);
item.setPickupDelay(3600); item.setPickupDelay(3600);
item.setMetadata("UltimateRepairing", new FixedMetadataValue(instance, "")); item.setMetadata("UltimateRepairing", new FixedMetadataValue(instance, ""));
// Get from Map, put new instance in Map if it doesn't exist // Get from Map, put new instance in Map if it doesn't exist
PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData()); PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData());
playerData.setItem(item); playerData.setItem(item);
playerData.setToBeRepaired(itemStack); playerData.setToBeRepaired(itemStack);
playerData.setLocations(anvil.add(0, -2, 0)); playerData.setLocations(anvil.add(0, -2, 0));
yesNo(player, type, itemStack); yesNo(player, type, itemStack);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
if (item.isValid() && !playerData.isBeingRepaired()) { if (item.isValid() && !playerData.isBeingRepaired()) {
instance.getLocale().getMessage("event.repair.timeout").sendPrefixedMessage(player); instance.getLocale().getMessage("event.repair.timeout").sendPrefixedMessage(player);
removeItem(playerData, player); removeItem(playerData, player);
player.closeInventory(); player.closeInventory();
} }
}, instance.getConfig().getLong("Main.Time Before Repair Auto Canceled")); }, instance.getConfig().getLong("Main.Time Before Repair Auto Canceled"));
} catch (Exception ex) {
Debugger.runReport(ex);
}
} }
public void initRepair(Player player, Location anvil) { public void initRepair(Player player, Location anvil) {
@ -128,141 +116,127 @@ public class RepairHandler {
} }
private void yesNo(Player p, RepairType type, ItemStack item) { private void yesNo(Player p, RepairType type, ItemStack item) {
try { PlayerAnvilData playerData = getDataFor(p);
PlayerAnvilData playerData = getDataFor(p);
if (playerData.isBeingRepaired()) { if (playerData.isBeingRepaired()) {
return; return;
}
int price = Methods.getCost(type, item);
playerData.setInRepair(true);
playerData.setType(type);
playerData.setPrice(price);
guiManager.showGUI(p, new StartConfirmGui(playerData.getLocation(), type, p, item));
} catch (Exception ex) {
Debugger.runReport(ex);
} }
int price = Methods.getCost(type, item);
playerData.setInRepair(true);
playerData.setType(type);
playerData.setPrice(price);
guiManager.showGUI(p, new StartConfirmGui(playerData.getLocation(), type, p, item));
} }
public void finish(boolean answer, Player player) { public void finish(boolean answer, Player player) {
try { PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData());
PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData()); if (!answer) {
if (!answer) { removeItem(playerData, player);
removeItem(playerData, player); instance.getLocale().getMessage("event.repair.cancelled").sendPrefixedMessage(player);
instance.getLocale().getMessage("event.repair.cancelled").sendPrefixedMessage(player); return;
return; }
} RepairType type = playerData.getType();
RepairType type = playerData.getType(); ItemStack players = playerData.getToBeRepaired();
ItemStack players = playerData.getToBeRepaired();
boolean sold = false; boolean sold = false;
if (type == RepairType.ECONOMY && EconomyManager.isEnabled()) { if (type == RepairType.ECONOMY && EconomyManager.isEnabled()) {
int price = playerData.getPrice(); int price = playerData.getPrice();
if(EconomyManager.hasBalance(player, price)) { if (EconomyManager.hasBalance(player, price)) {
EconomyManager.withdrawBalance(player, price); EconomyManager.withdrawBalance(player, price);
sold = true;
}
}
int cost = Methods.getCost(type, players);
ItemStack item2 = new ItemStack(Methods.getType(players), cost);
String name = (item2.getType().name().substring(0, 1).toUpperCase() + item2.getType().name().toLowerCase().substring(1)).replace("_", " ");
if (type == RepairType.ITEM && Methods.inventoryContains(player.getInventory(), item2)) {
Methods.removeFromInventory(player.getInventory(), item2);
sold = true; sold = true;
} }
}
if (type == RepairType.XP && player.getLevel() >= playerData.getPrice() || sold || player.getGameMode() == GameMode.CREATIVE) { int cost = Methods.getCost(type, players);
playerData.setBeingRepaired(true); ItemStack item2 = new ItemStack(Methods.getType(players), cost);
String name = (item2.getType().name().substring(0, 1).toUpperCase() + item2.getType().name().toLowerCase().substring(1)).replace("_", " ");
if (type == RepairType.ITEM && Methods.inventoryContains(player.getInventory(), item2)) {
Methods.removeFromInventory(player.getInventory(), item2);
sold = true;
}
Effect effect = Effect.STEP_SOUND; if (type == RepairType.XP && player.getLevel() >= playerData.getPrice() || sold || player.getGameMode() == GameMode.CREATIVE) {
playerData.setBeingRepaired(true);
Material blockType = Material.REDSTONE_BLOCK; Effect effect = Effect.STEP_SOUND;
String typeStr = playerData.getToBeRepaired().getType().name().toUpperCase(); Material blockType = Material.REDSTONE_BLOCK;
if (typeStr.contains("DIAMOND")) { String typeStr = playerData.getToBeRepaired().getType().name().toUpperCase();
blockType = Material.DIAMOND_BLOCK;
} else if (typeStr.contains("IRON")) {
blockType = Material.IRON_BLOCK;
} else if (typeStr.contains("GOLD")) {
blockType = Material.GOLD_BLOCK;
} else if (typeStr.contains("STONE")) {
blockType = Material.STONE;
} else if (typeStr.contains("WOOD")) {
blockType = CompatibleMaterial.OAK_WOOD.getMaterial();
}
final Material blockTypeFinal = blockType; if (typeStr.contains("DIAMOND")) {
blockType = Material.DIAMOND_BLOCK;
Location location = playerData.getLocations(); } else if (typeStr.contains("IRON")) {
player.getWorld().playEffect(location, effect, blockType); blockType = Material.IRON_BLOCK;
Runnable runnable = () -> player.getWorld().playEffect(location, effect, blockTypeFinal); } else if (typeStr.contains("GOLD")) {
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 5L); blockType = Material.GOLD_BLOCK;
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> { } else if (typeStr.contains("STONE")) {
player.getWorld().playEffect(location, effect, blockTypeFinal); blockType = Material.STONE;
player.getWorld().playEffect(location, effect, Material.STONE); } else if (typeStr.contains("WOOD")) {
CompatibleSound.BLOCK_ANVIL_LAND.play(player); blockType = CompatibleMaterial.OAK_WOOD.getMaterial();
}, 10L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 15L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
player.getWorld().playEffect(location, effect, blockTypeFinal);
player.getWorld().playEffect(location, effect, Material.ANVIL);
instance.getLocale().getMessage("event.repair.success").sendPrefixedMessage(player);
playerData.getToBeRepaired().setDurability((short) 0);
HashMap<Integer, ItemStack> items = player.getInventory().addItem(playerData.getToBeRepaired());
for (ItemStack item : items.values()) {
player.getWorld().dropItemNaturally(player.getLocation(), item);
}
playerData.getItem().remove();
if (player.getGameMode() != GameMode.CREATIVE &&
type == RepairType.XP) {
player.setLevel(player.getLevel() - playerData.getPrice());
}
this.playerAnvilData.remove(player.getUniqueId());
player.closeInventory();
}, 25L);
return;
} }
if (type == RepairType.ECONOMY) { final Material blockTypeFinal = blockType;
instance.getLocale().getMessage("event.repair.notenough")
.processPlaceholder("type", instance.getLocale().getMessage("interface.repair.eco").getMessage())
.sendPrefixedMessage(player);
} else if (type == RepairType.XP)
instance.getLocale().getMessage("event.repair.notenough")
.processPlaceholder("type", instance.getLocale().getMessage("interface.repair.xp").getMessage())
.sendPrefixedMessage(player);
else
instance.getLocale().getMessage("event.repair.notenough")
.processPlaceholder("type", name).sendPrefixedMessage(player);
// we've failed to repair, so return the item Location location = playerData.getLocations();
removeItem(playerData, player); player.getWorld().playEffect(location, effect, blockType);
Runnable runnable = () -> player.getWorld().playEffect(location, effect, blockTypeFinal);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 5L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
player.getWorld().playEffect(location, effect, blockTypeFinal);
player.getWorld().playEffect(location, effect, Material.STONE);
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
}, 10L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 15L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
player.getWorld().playEffect(location, effect, blockTypeFinal);
player.getWorld().playEffect(location, effect, Material.ANVIL);
instance.getLocale().getMessage("event.repair.success").sendPrefixedMessage(player);
} catch (Exception ex) { playerData.getToBeRepaired().setDurability((short) 0);
Debugger.runReport(ex); HashMap<Integer, ItemStack> items = player.getInventory().addItem(playerData.getToBeRepaired());
for (ItemStack item : items.values()) {
player.getWorld().dropItemNaturally(player.getLocation(), item);
}
playerData.getItem().remove();
if (player.getGameMode() != GameMode.CREATIVE &&
type == RepairType.XP) {
player.setLevel(player.getLevel() - playerData.getPrice());
}
this.playerAnvilData.remove(player.getUniqueId());
player.closeInventory();
}, 25L);
return;
} }
if (type == RepairType.ECONOMY) {
instance.getLocale().getMessage("event.repair.notenough")
.processPlaceholder("type", instance.getLocale().getMessage("interface.repair.eco").getMessage())
.sendPrefixedMessage(player);
} else if (type == RepairType.XP)
instance.getLocale().getMessage("event.repair.notenough")
.processPlaceholder("type", instance.getLocale().getMessage("interface.repair.xp").getMessage())
.sendPrefixedMessage(player);
else
instance.getLocale().getMessage("event.repair.notenough")
.processPlaceholder("type", name).sendPrefixedMessage(player);
// we've failed to repair, so return the item
removeItem(playerData, player);
} }
public void removeItem(PlayerAnvilData playerData, Player player) { public void removeItem(PlayerAnvilData playerData, Player player) {
try { player.getInventory().addItem(playerData.getToBeRepaired());
player.getInventory().addItem(playerData.getToBeRepaired()); playerData.getItem().remove();
playerData.getItem().remove();
this.playerAnvilData.remove(player.getUniqueId()); this.playerAnvilData.remove(player.getUniqueId());
} catch (Exception ex) {
Debugger.runReport(ex);
}
} }
public boolean hasInstance(Player player) { public boolean hasInstance(Player player) {

View File

@ -2,7 +2,6 @@ package com.songoda.ultimaterepairing.listeners;
import com.songoda.ultimaterepairing.UltimateRepairing; import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil; import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.utils.Debugger;
import com.songoda.ultimaterepairing.utils.Methods; import com.songoda.ultimaterepairing.utils.Methods;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -23,33 +22,24 @@ public class BlockListeners implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
try { if (!event.getBlockPlaced().getType().name().contains("ANVIL")
if (!event.getBlockPlaced().getType().name().contains("ANVIL") || !event.getPlayer().hasPermission("ultimaterepairing.permPlace")) {
|| !event.getPlayer().hasPermission("ultimaterepairing.permPlace")) { return;
return;
}
instance.getAnvilManager().getAnvil(event.getBlock()).setPermPlaced(true);
} catch (Exception ex) {
Debugger.runReport(ex);
} }
instance.getAnvilManager().getAnvil(event.getBlock()).setPermPlaced(true);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
try { String loc = Methods.serializeLocation(event.getBlock());
String loc = Methods.serializeLocation(event.getBlock());
if (!event.getBlock().getType().name().contains("ANVIL") && !instance.getConfig().contains("data.anvil." + loc)) { if (!event.getBlock().getType().name().contains("ANVIL") && !instance.getConfig().contains("data.anvil." + loc)) {
return; return;
}
UAnvil anvil = instance.getAnvilManager().getAnvil(event.getBlock());
anvil.setHologram(false);
instance.getAnvilManager().removeAnvil(event.getBlock().getLocation());
} catch (Exception ex) {
Debugger.runReport(ex);
} }
UAnvil anvil = instance.getAnvilManager().getAnvil(event.getBlock());
anvil.setHologram(false);
instance.getAnvilManager().removeAnvil(event.getBlock().getLocation());
} }
} }

View File

@ -5,15 +5,14 @@ import com.songoda.ultimaterepairing.UltimateRepairing;
import com.songoda.ultimaterepairing.anvil.UAnvil; import com.songoda.ultimaterepairing.anvil.UAnvil;
import com.songoda.ultimaterepairing.gui.AnvilSettingsGui; import com.songoda.ultimaterepairing.gui.AnvilSettingsGui;
import com.songoda.ultimaterepairing.settings.Settings; import com.songoda.ultimaterepairing.settings.Settings;
import com.songoda.ultimaterepairing.utils.Debugger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
/** /**
* Created by songoda on 2/25/2017. * Created by songoda on 2/25/2017.
@ -31,59 +30,54 @@ public class InteractListeners implements Listener {
@EventHandler @EventHandler
public void onAnvilClick(PlayerInteractEvent event) { public void onAnvilClick(PlayerInteractEvent event) {
try { boolean ourRepair = false;
boolean ourRepair = false; boolean vanillaRepair = false;
boolean vanillaRepair = false; Player player = event.getPlayer();
Player player = event.getPlayer(); if (event.getClickedBlock() == null) return;
if (event.getClickedBlock() == null) return;
UAnvil anvil1 = null; UAnvil anvil1 = null;
if (!event.getClickedBlock().getType().name().contains("ANVIL") // don't pay attention if it's not an anvil if (!event.getClickedBlock().getType().name().contains("ANVIL") // don't pay attention if it's not an anvil
// also don't handle if we don't have perms to use this repair anvil // also don't handle if we don't have perms to use this repair anvil
|| (Settings.PERMISSION_ANVIL_PLACE.getBoolean() || (Settings.PERMISSION_ANVIL_PLACE.getBoolean()
&& !(anvil1 = instance.getAnvilManager().getAnvil(event.getClickedBlock())).isPermPlaced())) { && !(anvil1 = instance.getAnvilManager().getAnvil(event.getClickedBlock())).isPermPlaced())) {
return; return;
} }
anvil1 = anvil1 != null ? anvil1 : instance.getAnvilManager().getAnvil(event.getClickedBlock()); anvil1 = anvil1 != null ? anvil1 : instance.getAnvilManager().getAnvil(event.getClickedBlock());
// if (anvil1.isInfinity()) { // if (anvil1.isInfinity()) {
// event.getClickedBlock().setType(Material.AIR); // event.getClickedBlock().setType(Material.AIR);
// event.getClickedBlock().setType(Material.ANVIL); //ToDO: This may not work. // event.getClickedBlock().setType(Material.ANVIL); //ToDO: This may not work.
// } // }
// check if we should process this as a right click // check if we should process this as a right click
boolean rightClick = (event.getAction() == Action.RIGHT_CLICK_BLOCK) ^ (Settings.SWAP_LEFT_RIGHT.getBoolean()); boolean rightClick = (event.getAction() == Action.RIGHT_CLICK_BLOCK) ^ (Settings.SWAP_LEFT_RIGHT.getBoolean());
// admin interface? // admin interface?
if(rightClick && player.isSneaking() && player.hasPermission("ultimaterepairing.admin")) { if (rightClick && player.isSneaking() && player.hasPermission("ultimaterepairing.admin")) {
guiManager.showGUI(player, new AnvilSettingsGui(anvil1)); guiManager.showGUI(player, new AnvilSettingsGui(anvil1));
event.setCancelled(true);
} else if (!Settings.ENABLE_ANVIL_DEFAULT_FUNCTION.getBoolean()) {
// if not allowing default anvil, then always use ourRepair
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
event.setCancelled(true); event.setCancelled(true);
} else if (!Settings.ENABLE_ANVIL_DEFAULT_FUNCTION.getBoolean()) {
// if not allowing default anvil, then always use ourRepair
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
event.setCancelled(true);
}
// replace our functions for vanilla mechanics only
if(!rightClick) {
return;
}
ourRepair = true;
} else if(rightClick) {
// allowing normal repair
vanillaRepair = true;
} else if(!player.isSneaking()) {
// that's us!
ourRepair = true;
} }
// replace our functions for vanilla mechanics only
if (!rightClick) {
return;
}
ourRepair = true;
} else if (rightClick) {
// allowing normal repair
vanillaRepair = true;
} else if (!player.isSneaking()) {
// that's us!
ourRepair = true;
}
if (ourRepair) { if (ourRepair) {
instance.getRepairHandler().initRepair(player, event.getClickedBlock().getLocation()); instance.getRepairHandler().initRepair(player, event.getClickedBlock().getLocation());
event.setCancelled(true); event.setCancelled(true);
} else if (vanillaRepair && anvil1.isInfinity()) { } else if (vanillaRepair && anvil1.isInfinity()) {
Inventory inv = Bukkit.createInventory(null, InventoryType.ANVIL, "Repair & Name"); player.openInventory(Bukkit.createInventory(null, InventoryType.ANVIL, ChatColor.DARK_GRAY + "Repair & Name"));
player.openInventory(inv); event.setCancelled(true);
event.setCancelled(true);
}
} catch (Exception ex) {
Debugger.runReport(ex);
} }
} }
} }

View File

@ -21,5 +21,4 @@ public class InventoryListeners implements Listener {
if (event.getItem().hasMetadata("UltimateRepairing")) if (event.getItem().hasMetadata("UltimateRepairing"))
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -1,30 +0,0 @@
package com.songoda.ultimaterepairing.utils;
import com.songoda.ultimaterepairing.UltimateRepairing;
/**
* Created by songoda on 3/21/2017.
*/
public class Debugger {
public static void runReport(Exception e) {
if (isDebug()) {
System.out.println("==============================================================");
System.out.println("The following is an error encountered in UltimateRepairing.");
System.out.println("--------------------------------------------------------------");
e.printStackTrace();
System.out.println("==============================================================");
}
sendReport(e);
}
public static void sendReport(Exception e) {
}
public static boolean isDebug() {
return UltimateRepairing.getInstance().getConfig().getBoolean("System.Debugger Enabled");
}
}