Update src/net/ardakaz/griefalert/GriefAlert.java
This commit is contained in:
parent
3bc045e799
commit
594523fb38
@ -15,6 +15,8 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -36,6 +38,8 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
private String MAP_LINK;
|
private String MAP_LINK;
|
||||||
private Boolean ALLOW_STEALING;
|
private Boolean ALLOW_STEALING;
|
||||||
|
|
||||||
|
private AlertsLogic alertsLogic;
|
||||||
|
|
||||||
// Init GriefAlert
|
// Init GriefAlert
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -59,13 +63,40 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
|
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
|
||||||
|
|
||||||
getLogger().info("GriefAlert has been enabled.");
|
getLogger().info("GriefAlert has been enabled.");
|
||||||
|
|
||||||
|
// Initialize AlertsLogic and register commands
|
||||||
|
alertsLogic = new AlertsLogic(this);
|
||||||
|
getCommand("disablelocation").setExecutor(this);
|
||||||
|
getCommand("enablelocation").setExecutor(this);
|
||||||
|
getCommand("clearlocations").setExecutor(this);
|
||||||
|
getCommand("checklocation").setExecutor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
if (alertsLogic != null) {
|
||||||
|
alertsLogic.close();
|
||||||
|
}
|
||||||
getLogger().info("GriefAlert has been disabled.");
|
getLogger().info("GriefAlert has been disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
String cmd = command.getName().toLowerCase();
|
||||||
|
switch (cmd) {
|
||||||
|
case "disablelocation":
|
||||||
|
return alertsLogic.handleDisableLocation(sender, args);
|
||||||
|
case "enablelocation":
|
||||||
|
return alertsLogic.handleEnableLocation(sender, args);
|
||||||
|
case "clearlocations":
|
||||||
|
return alertsLogic.handleClearLocations(sender, args);
|
||||||
|
case "checklocation":
|
||||||
|
return alertsLogic.handleCheckLocation(sender, args);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler (ignoreCancelled = true)
|
@EventHandler (ignoreCancelled = true)
|
||||||
// Block break alerts
|
// Block break alerts
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
@ -82,6 +113,11 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
int z = event.getBlock().getZ();
|
int z = event.getBlock().getZ();
|
||||||
String worldName = event.getBlock().getWorld().getName();
|
String worldName = event.getBlock().getWorld().getName();
|
||||||
|
|
||||||
|
// Check if alerts are disabled for this location
|
||||||
|
if (alertsLogic != null && alertsLogic.isLocationSaved(x, y, z, worldName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if grief
|
// Check if grief
|
||||||
String target = inspectBlock(event.getBlock(), event.getPlayer());
|
String target = inspectBlock(event.getBlock(), event.getPlayer());
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
@ -115,6 +151,15 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if alerts are disabled for this location
|
||||||
|
int x = inventory.getLocation().getBlockX();
|
||||||
|
int y = inventory.getLocation().getBlockY();
|
||||||
|
int z = inventory.getLocation().getBlockZ();
|
||||||
|
String worldName = inventory.getLocation().getWorld().getName();
|
||||||
|
if (alertsLogic != null && alertsLogic.isLocationSaved(x, y, z, worldName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Inv actions (needs fixing)
|
// Inv actions (needs fixing)
|
||||||
InventoryAction action = event.getAction();
|
InventoryAction action = event.getAction();
|
||||||
if ((action == InventoryAction.PICKUP_ALL || action == InventoryAction.PICKUP_HALF ||
|
if ((action == InventoryAction.PICKUP_ALL || action == InventoryAction.PICKUP_HALF ||
|
||||||
@ -134,10 +179,7 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
|||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
String itemName = item.getType().toString();
|
String itemName = item.getType().toString();
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
int x = inventory.getLocation().getBlockX();
|
// x, y, z, worldName already defined above
|
||||||
int y = inventory.getLocation().getBlockY();
|
|
||||||
int z = inventory.getLocation().getBlockZ();
|
|
||||||
String worldName = inventory.getLocation().getWorld().getName();
|
|
||||||
|
|
||||||
if (stealing) {
|
if (stealing) {
|
||||||
// Stealing
|
// Stealing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user