v0.3 #1
@ -15,6 +15,8 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
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.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -32,10 +34,12 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
private String lastAlert;
|
||||
|
||||
private Set<Material> EXCLUDED_BLOCKS;
|
||||
private Set<InventoryType> VALID_CONTAINERS;
|
||||
private Set<InventoryType> VALID_CONTAINERS;
|
||||
private String MAP_LINK;
|
||||
private Boolean ALLOW_STEALING;
|
||||
|
||||
private AlertsLogic alertsLogic;
|
||||
|
||||
// Init GriefAlert
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -59,20 +63,47 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
ALLOW_STEALING = getConfig().getBoolean("allow-stealing");
|
||||
|
||||
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
|
||||
public void onDisable() {
|
||||
if (alertsLogic != null) {
|
||||
alertsLogic.close();
|
||||
}
|
||||
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)
|
||||
// Block break alerts
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
// Exclusion list
|
||||
if (EXCLUDED_BLOCKS.contains(event.getBlock().getType())) {
|
||||
return;
|
||||
}
|
||||
// Exclusion list
|
||||
if (EXCLUDED_BLOCKS.contains(event.getBlock().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Event parser
|
||||
String playerName = event.getPlayer().getName();
|
||||
@ -82,6 +113,11 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
int z = event.getBlock().getZ();
|
||||
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
|
||||
String target = inspectBlock(event.getBlock(), event.getPlayer());
|
||||
if (target != null) {
|
||||
@ -94,12 +130,12 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
// Stealing alerts
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (ALLOW_STEALING) {
|
||||
return;
|
||||
}
|
||||
boolean stealing;
|
||||
if (ALLOW_STEALING) {
|
||||
return;
|
||||
}
|
||||
boolean stealing;
|
||||
|
||||
// Event parser for inv
|
||||
// Event parser for inv
|
||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
Inventory inventory = event.getInventory();
|
||||
@ -107,13 +143,22 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
|
||||
if (item == null || inventory.getLocation() == null || item.getType() == Material.AIR) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
// Exclusion list
|
||||
if (!VALID_CONTAINERS.contains(inventory.getType())) {
|
||||
return;
|
||||
}
|
||||
if (!VALID_CONTAINERS.contains(inventory.getType())) {
|
||||
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)
|
||||
InventoryAction action = event.getAction();
|
||||
@ -123,30 +168,27 @@ public class GriefAlert extends JavaPlugin implements Listener {
|
||||
stealing = true;
|
||||
} else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_SOME ||
|
||||
action == InventoryAction.PLACE_ONE || (action == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedInventory != inventory)) {
|
||||
stealing = false;
|
||||
stealing = false;
|
||||
} else {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
// Event parser for container + check if grief
|
||||
String target = inspectBlock(inventory.getLocation().getBlock(), player);
|
||||
if (target != null) {
|
||||
String playerName = player.getName();
|
||||
String playerName = player.getName();
|
||||
String itemName = item.getType().toString();
|
||||
int amount = item.getAmount();
|
||||
int x = inventory.getLocation().getBlockX();
|
||||
int y = inventory.getLocation().getBlockY();
|
||||
int z = inventory.getLocation().getBlockZ();
|
||||
String worldName = inventory.getLocation().getWorld().getName();
|
||||
// x, y, z, worldName already defined above
|
||||
|
||||
if (stealing) {
|
||||
// Stealing
|
||||
String message = ChatColor.GRAY + playerName + " took " + amount + " " + itemName + " from " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
||||
// Stealing
|
||||
String message = ChatColor.GRAY + playerName + " took " + amount + " " + itemName + " from " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
||||
} else {
|
||||
// Putting back
|
||||
String message = ChatColor.GRAY + playerName + " put " + amount + " " + itemName + " into " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
||||
// Putting back
|
||||
String message = ChatColor.GRAY + playerName + " put " + amount + " " + itemName + " into " + target + "'s container at " + x + " " + y + " " + z + getHumanWorldName(worldName);
|
||||
alert(message, playerName, "[Map Link](" + MAP_LINK + "/?worldname=" + worldName + "&zoom=7&x=" + x + "&y=" + y + "&z=" + z + ")", target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user