diff --git a/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java b/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java index d8631081..772c895b 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java @@ -19,6 +19,14 @@ package com.sk89q.worldguard.blacklist; +import com.sk89q.worldedit.blocks.ItemType; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.blacklist.action.Action; +import com.sk89q.worldguard.blacklist.action.ActionType; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; +import com.sk89q.worldguard.blacklist.event.EventType; +import org.bukkit.ChatColor; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -28,44 +36,22 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.ChatColor; +import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.blocks.ItemType; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; - -/** - * - * @author sk89q - */ public abstract class Blacklist { - /** - * List of entries by block ID. - */ - private Map> blacklist - = new HashMap>(); - /** - * Logger. - */ - private BlacklistLogger blacklistLogger = new BlacklistLogger(); - /** - * Last event. - */ + private Map> blacklist = new HashMap>(); + private Logger blacklistLogger = new Logger(); private BlacklistEvent lastEvent; - /** - * Used to prevent flooding. - */ - Map lastAffected = - new HashMap(); + Map lastAffected = new HashMap(); private boolean useAsWhitelist; - private final Logger logger; + private final java.util.logging.Logger logger; - public Blacklist(Boolean useAsWhitelist, Logger logger) { + public Blacklist(boolean useAsWhitelist, java.util.logging.Logger logger) { + checkNotNull(logger); this.useAsWhitelist = useAsWhitelist; this.logger = logger; } @@ -112,7 +98,7 @@ public boolean isWhitelist() { * * @return The logger used in this blacklist */ - public BlacklistLogger getLogger() { + public Logger getLogger() { return blacklistLogger; } @@ -126,15 +112,19 @@ public BlacklistLogger getLogger() { */ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent) { List entries = getEntries(event.getType()); + if (entries == null) { return true; } + boolean ret = true; + for (BlacklistEntry entry : entries) { if (!entry.check(useAsWhitelist, event, forceRepeat, silent)) { ret = false; } } + return ret; } @@ -146,8 +136,7 @@ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent) */ public void load(File file) throws IOException { FileReader input = null; - Map> blacklist = - new HashMap>(); + Map> blacklist = new HashMap>(); try { input = new FileReader(file); @@ -159,7 +148,7 @@ public void load(File file) throws IOException { line = line.trim(); // Blank line - if (line.length() == 0) { + if (line.isEmpty()) { continue; } else if (line.charAt(0) == ';' || line.charAt(0) == '#') { continue; @@ -207,34 +196,35 @@ public void load(File file) throws IOException { for (BlacklistEntry entry : currentEntries) { if (parts[0].equalsIgnoreCase("ignore-groups")) { entry.setIgnoreGroups(parts[1].split(",")); + } else if (parts[0].equalsIgnoreCase("ignore-perms")) { entry.setIgnorePermissions(parts[1].split(",")); - } else if (parts[0].equalsIgnoreCase("on-break")) { - entry.setBreakActions(parts[1].split(",")); - } else if (parts[0].equalsIgnoreCase("on-destroy-with")) { - entry.setDestroyWithActions(parts[1].split(",")); - } else if (parts[0].equalsIgnoreCase("on-place")) { - entry.setPlaceActions(parts[1].split(",")); - } else if (parts[0].equalsIgnoreCase("on-interact")) { - entry.setInteractActions(parts[1].split(",")); - } else if (parts[0].equalsIgnoreCase("on-use")) { - entry.setUseActions(parts[1].split(",")); - } else if (parts[0].equalsIgnoreCase("on-drop")) { - entry.setDropActions(parts[1].split(",")); - } else if (parts[0].equalsIgnoreCase("on-acquire")) { - entry.setAcquireActions(parts[1].split(",")); + } else if (parts[0].equalsIgnoreCase("message")) { entry.setMessage(parts[1].trim()); + } else if (parts[0].equalsIgnoreCase("comment")) { entry.setComment(parts[1].trim()); + } else { - unknownOption = true; + boolean found = false; + + for (EventType type : EventType.values()) { + if (type.getRuleName().equalsIgnoreCase(parts[0])) { + entry.getActions(type.getEventClass()).addAll(parseActions(entry, parts[1])); + found = true; + break; + } + } + + if (!found) { + unknownOption = true; + } } } if (unknownOption) { - logger.log(Level.WARNING, "Unknown option '" + parts[0] - + "' in " + file.getName() + " for '" + line + "'"); + logger.log(Level.WARNING, "Unknown option '" + parts[0] + "' in " + file.getName() + " for '" + line + "'"); } } else { logger.log(Level.WARNING, "Found option with no heading " @@ -253,6 +243,31 @@ public void load(File file) throws IOException { } } + private List parseActions(BlacklistEntry entry, String raw) { + String[] split = raw.split(","); + List actions = new ArrayList(); + + for (String name : split) { + name = name.trim(); + + boolean found = false; + + for (ActionType type : ActionType.values()) { + if (type.getActionName().equalsIgnoreCase(name)) { + actions.add(type.parseInput(this, entry)); + found = true; + break; + } + } + + if (!found) { + logger.log(Level.WARNING, "Unknown blacklist action: " + name); + } + } + + return actions; + } + /** * Get the last event. * @@ -272,7 +287,7 @@ public void notify(BlacklistEvent event, String comment) { lastEvent = event; broadcastNotification(ChatColor.GRAY + "WG: " - + ChatColor.LIGHT_PURPLE + event.getPlayer().getName() + + ChatColor.LIGHT_PURPLE + event.getCauseName() + ChatColor.GOLD + " (" + event.getDescription() + ") " + ChatColor.WHITE + getFriendlyItemName(event.getType()) @@ -331,4 +346,5 @@ private static String getFriendlyItemName(int id) { return "#" + id + ""; } } + } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java b/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java index 748e099f..bdbfa64f 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java @@ -19,50 +19,26 @@ package com.sk89q.worldguard.blacklist; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.bukkit.ChatColor; - import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; +import com.sk89q.worldguard.blacklist.action.Action; +import com.sk89q.worldguard.blacklist.action.ActionResult; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; -/** - * - * @author sk89q - */ public class BlacklistEntry { - /** - * Parent blacklist entry. - */ + private Blacklist blacklist; - - /** - * List of groups to not affect. - */ private Set ignoreGroups; - - /** - * List of permissions to not affect. - */ private Set ignorePermissions; - - private String[] breakActions; - private String[] destroyWithActions; - private String[] placeActions; - private String[] interactActions; - private String[] useActions; - private String[] dropActions; - private String[] acquireActions; + private Map, List> actions = new HashMap, List>(); private String message; private String comment; @@ -110,104 +86,6 @@ public void setIgnorePermissions(String[] ignorePermissions) { this.ignorePermissions = ignorePermissionsSet; } - /** - * @return The actions that occur when breaking - */ - public String[] getBreakActions() { - return breakActions; - } - - /** - * @param actions The actions to occur when breaking - */ - public void setBreakActions(String[] actions) { - this.breakActions = actions; - } - - /** - * @return The actions that occur when destroying with a specific item - */ - public String[] getDestroyWithActions() { - return destroyWithActions; - } - - /** - * @param actions The actions to occur when destroying with an item - */ - public void setDestroyWithActions(String[] actions) { - this.destroyWithActions = actions; - } - - /** - * @return The actions that will occur when placing - */ - public String[] getPlaceActions() { - return placeActions; - } - - /** - * @param actions The actions to occur when placing - */ - public void setPlaceActions(String[] actions) { - this.placeActions = actions; - } - - /** - * @return The actions that will occur when interacting - */ - public String[] getInteractActions() { - return interactActions; - } - - /** - * @param actions The actions to occur when interacting - */ - public void setInteractActions(String[] actions) { - this.interactActions = actions; - } - - /** - * @return The actions that will occur when using - */ - public String[] getUseActions() { - return useActions; - } - - /** - * @param actions The actions to occur when using - */ - public void setUseActions(String[] actions) { - this.useActions = actions; - } - - /** - * @return The actions that will occur when dropping - */ - public String[] getDropActions() { - return dropActions; - } - - /** - * @param actions The actions to occur when dropping - */ - public void setDropActions(String[] actions) { - this.dropActions = actions; - } - - /** - * @return The actions that will occur when acquiring - */ - public String[] getAcquireActions() { - return acquireActions; - } - - /** - * @param actions The actions to occur when acquiring - */ - public void setAcquireActions(String[] actions) { - this.acquireActions = actions; - } - /** * @return the message */ @@ -265,40 +143,22 @@ public boolean shouldIgnore(LocalPlayer player) { /** * Get the associated actions with an event. * - * @param event The event to check + * @param eventCls The event's class * @return The actions for the given event */ - private String[] getActions(BlacklistEvent event) { - if (event instanceof BlockBreakBlacklistEvent) { - return breakActions; - - } else if (event instanceof BlockPlaceBlacklistEvent) { - return placeActions; - - } else if (event instanceof BlockInteractBlacklistEvent) { - return interactActions; - - } else if (event instanceof DestroyWithBlacklistEvent) { - return destroyWithActions; - - } else if (event instanceof ItemAcquireBlacklistEvent) { - return acquireActions; - - } else if (event instanceof ItemDropBlacklistEvent) { - return dropActions; - - } else if (event instanceof ItemUseBlacklistEvent) { - return useActions; - - } else { - return null; + public List getActions(Class eventCls) { + List ret = actions.get(eventCls); + if (ret == null) { + ret = new ArrayList(); + actions.put(eventCls, ret); } + return ret; } /** * Method to handle the event. * - * @param useAsWhitelist Whether this entry is buing used in a whitelist + * @param useAsWhitelist Whether this entry is being used in a whitelist * @param event The event to check * @param forceRepeat Whether to force repeating notifications even within the delay limit * @param silent Whether to prevent notifications from happening @@ -311,22 +171,23 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force return true; } - String name = player.getName(); + String name = player != null ? player.getName() : ""; long now = System.currentTimeMillis(); boolean repeating = false; // Check to see whether this event is being repeated - BlacklistTrackedEvent tracked = blacklist.lastAffected.get(name); + TrackedEvent tracked = blacklist.lastAffected.get(name); if (tracked != null) { if (tracked.matches(event, now)) { repeating = true; + } else { + tracked.resetTimer(); } } else { - blacklist.lastAffected.put(name, new BlacklistTrackedEvent(event, now)); + blacklist.lastAffected.put(name, new TrackedEvent(event, now)); } - String actions[] = getActions(event); - + List actions = getActions(event.getClass()); boolean ret = !useAsWhitelist; @@ -335,73 +196,21 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force return ret; } - for (String action : actions) { - // Deny - if (action.equalsIgnoreCase("deny")) { - if (silent) { - return false; - } - - ret = false; - - // Allow - } else if (action.equalsIgnoreCase("allow")) { - if (silent) { + for (Action action : actions) { + ActionResult result = action.apply(event, silent, repeating, forceRepeat); + switch (result) { + case INHERIT: + continue; + case ALLOW: + ret = true; + break; + case DENY: + ret = false; + break; + case ALLOW_OVERRIDE: return true; - } - - ret = true; - - // Kick - } else if (action.equalsIgnoreCase("kick")) { - if (silent) { - continue; - } - - if (this.message != null) { - player.kick(String.format(this.message, - getFriendlyItemName(event.getType()))); - } else { - player.kick("You can't " + event.getDescription() + " " - + getFriendlyItemName(event.getType())); - } - - // Ban - } else if (action.equalsIgnoreCase("ban")) { - if (silent) { - continue; - } - - if (this.message != null) { - player.ban("Banned: " + String.format(this.message, - getFriendlyItemName(event.getType()))); - } else { - player.ban("Banned: You can't " - + event.getDescription() + " " - + getFriendlyItemName(event.getType())); - } - - } else if (!silent && (!repeating || forceRepeat)) { - // Notify - if (action.equalsIgnoreCase("notify")) { - blacklist.notify(event, comment); - - // Log - } else if (action.equalsIgnoreCase("log")) { - blacklist.getLogger().logEvent(event, comment); - - // Tell - } else if (action.equalsIgnoreCase("tell")) { - if (this.message != null) { - player.printRaw(ChatColor.YELLOW + - String.format(message, getFriendlyItemName(event.getType())) - + "."); - } else { - player.printRaw(ChatColor.YELLOW + "You're not allowed to " - + event.getDescription() + " " - + getFriendlyItemName(event.getType()) + "."); - } - } + case DENY_OVERRIDE: + return false; } } @@ -413,7 +222,7 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force * * @param id The id to get a name for */ - private static String getFriendlyItemName(int id) { + public static String getFriendlyItemName(int id) { ItemType type = ItemType.fromID(id); if (type != null) { return type.getName() + " (#" + id + ")"; @@ -421,4 +230,5 @@ private static String getFriendlyItemName(int id) { return "#" + id + ""; } } + } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistLogger.java b/src/main/java/com/sk89q/worldguard/blacklist/Logger.java similarity index 74% rename from src/main/java/com/sk89q/worldguard/blacklist/BlacklistLogger.java rename to src/main/java/com/sk89q/worldguard/blacklist/Logger.java index 3f428534..2be27166 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistLogger.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/Logger.java @@ -19,29 +19,26 @@ package com.sk89q.worldguard.blacklist; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; +import com.sk89q.worldguard.blacklist.logger.LoggerHandler; + import java.util.HashSet; import java.util.Set; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; -import com.sk89q.worldguard.blacklist.loggers.BlacklistLoggerHandler; +public class Logger implements LoggerHandler { -/** - * - * @author sk89q - */ -public class BlacklistLogger implements BlacklistLoggerHandler { /** * List of logger handlers. */ - private Set handlers - = new HashSet(); + private Set handlers + = new HashSet(); /** * Add a handler. * * @param handler The handler to add */ - public void addHandler(BlacklistLoggerHandler handler) { + public void addHandler(LoggerHandler handler) { handlers.add(handler); } @@ -50,7 +47,7 @@ public void addHandler(BlacklistLoggerHandler handler) { * * @param handler The handler to remove */ - public void removeHandler(BlacklistLoggerHandler handler) { + public void removeHandler(LoggerHandler handler) { handlers.remove(handler); } @@ -66,8 +63,9 @@ public void clearHandlers() { * * @param event The event to log */ + @Override public void logEvent(BlacklistEvent event, String comment) { - for (BlacklistLoggerHandler handler : handlers) { + for (LoggerHandler handler : handlers) { handler.logEvent(event, comment); } } @@ -75,9 +73,11 @@ public void logEvent(BlacklistEvent event, String comment) { /** * Close the connection. */ + @Override public void close() { - for (BlacklistLoggerHandler handler : handlers) { + for (LoggerHandler handler : handlers) { handler.close(); } } + } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistTrackedEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/TrackedEvent.java similarity index 86% rename from src/main/java/com/sk89q/worldguard/blacklist/BlacklistTrackedEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/TrackedEvent.java index 73818691..8df63041 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistTrackedEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/TrackedEvent.java @@ -19,13 +19,10 @@ package com.sk89q.worldguard.blacklist; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +class TrackedEvent { -/** - * - * @author sk89q - */ -public class BlacklistTrackedEvent { private BlacklistEvent event; private long time; @@ -35,7 +32,7 @@ public class BlacklistTrackedEvent { * @param event The event tracked * @param time The time at which the event occurred */ - public BlacklistTrackedEvent(BlacklistEvent event, long time) { + TrackedEvent(BlacklistEvent event, long time) { this.event = event; this.time = time; } @@ -45,4 +42,9 @@ public boolean matches(BlacklistEvent other, long now) { && time > now - 3000 && other.getClass() == event.getClass(); } + + public void resetTimer() { + time = System.currentTimeMillis(); + } + } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/action/Action.java similarity index 71% rename from src/main/java/com/sk89q/worldguard/blacklist/events/ItemBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/action/Action.java index cff7827a..ef9d6923 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/Action.java @@ -1,29 +1,28 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public abstract class ItemBlacklistEvent extends BlacklistEvent { - public ItemBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +public interface Action { + + ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat); + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/action/ActionResult.java similarity index 71% rename from src/main/java/com/sk89q/worldguard/blacklist/events/BlockBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/action/ActionResult.java index 5fa204ac..f96b472b 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/ActionResult.java @@ -1,29 +1,30 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public abstract class BlockBlacklistEvent extends BlacklistEvent { - public BlockBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +public enum ActionResult { + + INHERIT, + DENY, + ALLOW, + DENY_OVERRIDE, + ALLOW_OVERRIDE + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/ActionType.java b/src/main/java/com/sk89q/worldguard/blacklist/action/ActionType.java new file mode 100644 index 00000000..c9a2379a --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/ActionType.java @@ -0,0 +1,81 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.Blacklist; +import com.sk89q.worldguard.blacklist.BlacklistEntry; + +public enum ActionType { + + ALLOW("allow") { + @Override + public Action parseInput(Blacklist blacklist, BlacklistEntry entry) { + return AllowAction.getInstance(); + } + }, + DENY("deny") { + @Override + public Action parseInput(Blacklist blacklist, BlacklistEntry entry) { + return DenyAction.getInstance(); + } + }, + BAN("ban") { + @Override + public Action parseInput(Blacklist blacklist, BlacklistEntry entry) { + return new BanAction(entry); + } + }, + KICK("kick") { + @Override + public Action parseInput(Blacklist blacklist, BlacklistEntry entry) { + return new KickAction(entry); + } + }, + LOG("log") { + @Override + public Action parseInput(Blacklist blacklist, BlacklistEntry entry) { + return new LogAction(blacklist, entry); + } + }, + NOTIFY("notify") { + @Override + public Action parseInput(Blacklist blacklist, BlacklistEntry entry) { + return new NotifyAction(blacklist, entry); + } + }, + TELL("tell") { + @Override + public Action parseInput(Blacklist blacklist, BlacklistEntry entry) { + return new TellAction(entry); + } + }; + + private final String actionName; + + ActionType(String actionName) { + this.actionName = actionName; + } + + public abstract Action parseInput(Blacklist blacklist, BlacklistEntry entry); + + public String getActionName() { + return actionName; + } +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/AllowAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/AllowAction.java new file mode 100644 index 00000000..9186f317 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/AllowAction.java @@ -0,0 +1,44 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +public final class AllowAction implements Action { + + private static final AllowAction INSTANCE = new AllowAction(); + + private AllowAction() { + } + + @Override + public ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat) { + if (silent) { + return ActionResult.ALLOW_OVERRIDE; + } + + return ActionResult.ALLOW; + } + + public static AllowAction getInstance() { + return INSTANCE; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/BanAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/BanAction.java new file mode 100644 index 00000000..0af27873 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/BanAction.java @@ -0,0 +1,55 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.BlacklistEntry; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class BanAction implements Action { + + private final BlacklistEntry entry; + + public BanAction(BlacklistEntry entry) { + checkNotNull(entry); + this.entry = entry; + } + + @Override + public ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat) { + if (silent) { + return ActionResult.INHERIT; + } + + if (event.getPlayer() != null) { + String message = entry.getMessage(); + + if (message != null) { + event.getPlayer().ban("Banned: " + String.format(message, BlacklistEntry.getFriendlyItemName(event.getType()))); + } else { + event.getPlayer().ban("Banned: You can't " + event.getDescription() + " " + BlacklistEntry.getFriendlyItemName(event.getType())); + } + } + + return ActionResult.INHERIT; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/DenyAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/DenyAction.java new file mode 100644 index 00000000..cb45a250 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/DenyAction.java @@ -0,0 +1,44 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +public final class DenyAction implements Action { + + private static final DenyAction INSTANCE = new DenyAction(); + + private DenyAction() { + } + + @Override + public ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat) { + if (silent) { + return ActionResult.DENY_OVERRIDE; + } + + return ActionResult.DENY; + } + + public static DenyAction getInstance() { + return INSTANCE; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/KickAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/KickAction.java new file mode 100644 index 00000000..68807a3a --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/KickAction.java @@ -0,0 +1,55 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.BlacklistEntry; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class KickAction implements Action { + + private final BlacklistEntry entry; + + public KickAction(BlacklistEntry entry) { + checkNotNull(entry); + this.entry = entry; + } + + @Override + public ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat) { + if (silent) { + return ActionResult.INHERIT; + } + + if (event.getPlayer() != null) { + String message = entry.getMessage(); + + if (message != null) { + event.getPlayer().kick(String.format(message, BlacklistEntry.getFriendlyItemName(event.getType()))); + } else { + event.getPlayer().kick("You can't " + event.getDescription() + " " + BlacklistEntry.getFriendlyItemName(event.getType())); + } + } + + return ActionResult.INHERIT; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/LogAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/LogAction.java new file mode 100644 index 00000000..eb139924 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/LogAction.java @@ -0,0 +1,51 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.Blacklist; +import com.sk89q.worldguard.blacklist.BlacklistEntry; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class LogAction extends RepeatGuardedAction { + + private final Blacklist blacklist; + private final BlacklistEntry entry; + + public LogAction(Blacklist blacklist, BlacklistEntry entry) { + checkNotNull(blacklist); + checkNotNull(entry); + this.blacklist = blacklist; + this.entry = entry; + } + + @Override + protected ActionResult applyNonRepeated(BlacklistEvent event, boolean silent) { + if (silent) { + return ActionResult.INHERIT; + } + + blacklist.getLogger().logEvent(event, entry.getComment()); + + return ActionResult.INHERIT; + } + +} \ No newline at end of file diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/NotifyAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/NotifyAction.java new file mode 100644 index 00000000..d5d17c54 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/NotifyAction.java @@ -0,0 +1,51 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.Blacklist; +import com.sk89q.worldguard.blacklist.BlacklistEntry; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class NotifyAction extends RepeatGuardedAction { + + private final Blacklist blacklist; + private final BlacklistEntry entry; + + public NotifyAction(Blacklist blacklist, BlacklistEntry entry) { + checkNotNull(blacklist); + checkNotNull(entry); + this.blacklist = blacklist; + this.entry = entry; + } + + @Override + protected ActionResult applyNonRepeated(BlacklistEvent event, boolean silent) { + if (silent) { + return ActionResult.INHERIT; + } + + blacklist.notify(event, entry.getComment()); + + return ActionResult.INHERIT; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/RepeatGuardedAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/RepeatGuardedAction.java new file mode 100644 index 00000000..829cbd05 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/RepeatGuardedAction.java @@ -0,0 +1,37 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +public abstract class RepeatGuardedAction implements Action { + + @Override + public final ActionResult apply(BlacklistEvent event, boolean silent, boolean repeating, boolean forceRepeat) { + if (!repeating || forceRepeat) { + return applyNonRepeated(event, silent); + } + + return ActionResult.INHERIT; + } + + protected abstract ActionResult applyNonRepeated(BlacklistEvent event, boolean silent); + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/action/TellAction.java b/src/main/java/com/sk89q/worldguard/blacklist/action/TellAction.java new file mode 100644 index 00000000..156f083a --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/action/TellAction.java @@ -0,0 +1,58 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.action; + +import com.sk89q.worldguard.blacklist.BlacklistEntry; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; +import org.bukkit.ChatColor; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class TellAction extends RepeatGuardedAction { + + private final BlacklistEntry entry; + + public TellAction(BlacklistEntry entry) { + checkNotNull(entry); + this.entry = entry; + } + + @Override + protected ActionResult applyNonRepeated(BlacklistEvent event, boolean silent) { + if (silent) { + return ActionResult.INHERIT; + } + + String message = entry.getMessage(); + + if (event.getPlayer() != null) { + if (message != null) { + event.getPlayer().printRaw(ChatColor.YELLOW + String.format(message, + BlacklistEntry.getFriendlyItemName(event.getType())) + "."); + } else { + event.getPlayer().printRaw(ChatColor.YELLOW + "You're not allowed to " + event.getDescription() + " " + + BlacklistEntry.getFriendlyItemName(event.getType()) + "."); + } + } + + return ActionResult.INHERIT; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/BlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/AbstractBlacklistEvent.java similarity index 57% rename from src/main/java/com/sk89q/worldguard/blacklist/events/BlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/AbstractBlacklistEvent.java index 6ec2518c..9c089367 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/BlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/AbstractBlacklistEvent.java @@ -1,85 +1,75 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -/** - * Represents a blacklist event. - * - * @author sk89q - */ -public abstract class BlacklistEvent { - private Vector pos; - private int type; - - /** - * Holds the player that triggered the event. - */ - private LocalPlayer player; - - /** - * Construct the object. - * - * @param player The player associated with this event - * @param pos The position the event occurred at - * @param type The type of item used - */ - public BlacklistEvent(LocalPlayer player, Vector pos, int type) { - this.player = player; - this.pos = pos; - this.type = type; - } - - /** - * Get the player. - * - * @return The player associated with this event - */ - public LocalPlayer getPlayer() { - return player; - } - - /** - * Get the position. - * - * @return The position of this event - */ - public Vector getPosition() { - return pos; - } - - /** - * Get the item type. - * - * @return The type associated with this event - */ - public int getType() { - return type; - } - - /** - * Get a short description such as "break" or "destroy with." - * - * @return The event description - */ - public abstract String getDescription(); -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkNotNull; + +abstract class AbstractBlacklistEvent implements BlacklistEvent { + + @Nullable + private LocalPlayer player; + private Vector position; + private int type; + + /** + * Construct the object. + * + * @param player The player associated with this event + * @param position The position the event occurred at + * @param type The type of item used + */ + AbstractBlacklistEvent(@Nullable LocalPlayer player, Vector position, int type) { + checkNotNull(position); + this.player = player; + this.position = position; + this.type = type; + } + + @Nullable + @Override + public LocalPlayer getPlayer() { + return player; + } + + @Override + public String getCauseName() { + return player != null ? player.getName() : position.toString(); + } + + @Override + public Vector getPosition() { + return position; + } + + @Override + public int getType() { + return type; + } + + protected String getPlayerName() { + return player == null ? "(unknown)" : player.getName(); + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/event/BlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/BlacklistEvent.java new file mode 100644 index 00000000..4c912ce1 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/BlacklistEvent.java @@ -0,0 +1,86 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +import javax.annotation.Nullable; + +public interface BlacklistEvent { + + /** + * Get the player. + * + * @return The player associated with this event + */ + @Nullable + LocalPlayer getPlayer(); + + /** + * Get the cause name, which is usually the player name. + * + * @return the cause name + */ + String getCauseName(); + + /** + * Get the position. + * + * @return The position of this event + */ + Vector getPosition(); + + /** + * Get the position that should be logged. + * + * @return The position that be logged. + */ + Vector getLoggedPosition(); + + /** + * Get the item type. + * + * @return The type associated with this event + */ + int getType(); + + /** + * Get a short description such as "break" or "destroy with." + * + * @return The event description + */ + String getDescription(); + + /** + * Get a message for logger outputs. + * + * @return A logging message + */ + String getLoggerMessage(); + + /** + * Get the event type. + * + * @return the type + */ + EventType getEventType(); + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/event/BlockBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockBlacklistEvent.java new file mode 100644 index 00000000..bfed063b --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockBlacklistEvent.java @@ -0,0 +1,42 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.blacklist.BlacklistEntry; + +abstract class BlockBlacklistEvent extends AbstractBlacklistEvent { + + BlockBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getLoggerMessage() { + return getPlayerName() + " tried to " + getDescription() + " " + BlacklistEntry.getFriendlyItemName(getType()); + } + + @Override + public Vector getLoggedPosition() { + return getPosition(); + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockBreakBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockBreakBlacklistEvent.java similarity index 83% rename from src/main/java/com/sk89q/worldguard/blacklist/events/BlockBreakBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/BlockBreakBlacklistEvent.java index a889b8be..b7ff5fc1 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockBreakBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockBreakBlacklistEvent.java @@ -1,34 +1,41 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public class BlockBreakBlacklistEvent extends BlockBlacklistEvent { - public BlockBreakBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } - - @Override - public String getDescription() { - return "break"; - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +public final class BlockBreakBlacklistEvent extends BlockBlacklistEvent { + + public BlockBreakBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getDescription() { + return "break"; + } + + @Override + public EventType getEventType() { + return EventType.BREAK; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockInteractBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockInteractBlacklistEvent.java similarity index 83% rename from src/main/java/com/sk89q/worldguard/blacklist/events/BlockInteractBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/BlockInteractBlacklistEvent.java index 664b3559..6f425502 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockInteractBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockInteractBlacklistEvent.java @@ -1,34 +1,41 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public class BlockInteractBlacklistEvent extends BlockBlacklistEvent { - public BlockInteractBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } - - @Override - public String getDescription() { - return "interact with"; - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +public final class BlockInteractBlacklistEvent extends BlockBlacklistEvent { + + public BlockInteractBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getDescription() { + return "interact with"; + } + + @Override + public EventType getEventType() { + return EventType.INTERACT; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockPlaceBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockPlaceBlacklistEvent.java similarity index 83% rename from src/main/java/com/sk89q/worldguard/blacklist/events/BlockPlaceBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/BlockPlaceBlacklistEvent.java index a543ae17..d93c7f52 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/BlockPlaceBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/BlockPlaceBlacklistEvent.java @@ -1,34 +1,41 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public class BlockPlaceBlacklistEvent extends BlockBlacklistEvent { - public BlockPlaceBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } - - @Override - public String getDescription() { - return "place"; - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +public final class BlockPlaceBlacklistEvent extends BlockBlacklistEvent { + + public BlockPlaceBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getDescription() { + return "place"; + } + + @Override + public EventType getEventType() { + return EventType.PLACE; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/event/EventType.java b/src/main/java/com/sk89q/worldguard/blacklist/event/EventType.java new file mode 100644 index 00000000..d1fb4041 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/EventType.java @@ -0,0 +1,48 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +public enum EventType { + + BREAK(BlockBreakBlacklistEvent.class, "on-break"), + PLACE(BlockPlaceBlacklistEvent.class, "on-place"), + INTERACT(BlockInteractBlacklistEvent.class, "on-interact"), + DESTROY_WITH(ItemDestroyWithBlacklistEvent.class, "on-destroy-with"), + ACQUIRE(ItemAcquireBlacklistEvent.class, "on-acquire"), + DROP(ItemDropBlacklistEvent.class, "on-drop"), + USE(ItemUseBlacklistEvent.class, "on-use"); + + private final Class eventClass; + private final String ruleName; + + private EventType(Class eventClass, String ruleName) { + this.eventClass = eventClass; + this.ruleName = ruleName; + } + + public Class getEventClass() { + return eventClass; + } + + public String getRuleName() { + return ruleName; + } + +} \ No newline at end of file diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemAcquireBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemAcquireBlacklistEvent.java similarity index 83% rename from src/main/java/com/sk89q/worldguard/blacklist/events/ItemAcquireBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/ItemAcquireBlacklistEvent.java index 61f981d9..f085d23a 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemAcquireBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemAcquireBlacklistEvent.java @@ -1,34 +1,41 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public class ItemAcquireBlacklistEvent extends ItemBlacklistEvent { - public ItemAcquireBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } - - @Override - public String getDescription() { - return "acquire"; - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +public final class ItemAcquireBlacklistEvent extends ItemBlacklistEvent { + + public ItemAcquireBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getDescription() { + return "acquire"; + } + + @Override + public EventType getEventType() { + return EventType.ACQUIRE; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/event/ItemBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemBlacklistEvent.java new file mode 100644 index 00000000..d9ff649e --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemBlacklistEvent.java @@ -0,0 +1,42 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.blacklist.BlacklistEntry; + +abstract class ItemBlacklistEvent extends AbstractBlacklistEvent { + + ItemBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getLoggerMessage() { + return getPlayerName() + " tried to " + getDescription() + " " + BlacklistEntry.getFriendlyItemName(getType()); + } + + @Override + public Vector getLoggedPosition() { + return getPlayer() != null ? getPlayer().getPosition() : getPosition(); + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/DestroyWithBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemDestroyWithBlacklistEvent.java similarity index 69% rename from src/main/java/com/sk89q/worldguard/blacklist/events/DestroyWithBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/ItemDestroyWithBlacklistEvent.java index 9c232295..dd11342e 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/DestroyWithBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemDestroyWithBlacklistEvent.java @@ -1,34 +1,47 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public class DestroyWithBlacklistEvent extends BlacklistEvent { - public DestroyWithBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } - - @Override - public String getDescription() { - return "destroy with"; - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +public final class ItemDestroyWithBlacklistEvent extends ItemBlacklistEvent { + + public ItemDestroyWithBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getDescription() { + return "destroy with"; + } + + @Override + public EventType getEventType() { + return EventType.DESTROY_WITH; + } + + @Override + public Vector getLoggedPosition() { + // Use the block position instead + return getPosition(); + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemDropBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemDropBlacklistEvent.java similarity index 84% rename from src/main/java/com/sk89q/worldguard/blacklist/events/ItemDropBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/ItemDropBlacklistEvent.java index 2856148f..43063bb8 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemDropBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemDropBlacklistEvent.java @@ -1,34 +1,41 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public class ItemDropBlacklistEvent extends ItemBlacklistEvent { - public ItemDropBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } - - @Override - public String getDescription() { - return "drop"; - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +public final class ItemDropBlacklistEvent extends ItemBlacklistEvent { + + public ItemDropBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getDescription() { + return "drop"; + } + + @Override + public EventType getEventType() { + return EventType.DROP; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemUseBlacklistEvent.java b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemUseBlacklistEvent.java similarity index 84% rename from src/main/java/com/sk89q/worldguard/blacklist/events/ItemUseBlacklistEvent.java rename to src/main/java/com/sk89q/worldguard/blacklist/event/ItemUseBlacklistEvent.java index 34754fc8..73ae4213 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/events/ItemUseBlacklistEvent.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/event/ItemUseBlacklistEvent.java @@ -1,34 +1,41 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.events; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; - -public class ItemUseBlacklistEvent extends ItemBlacklistEvent { - public ItemUseBlacklistEvent(LocalPlayer player, Vector pos, int type) { - super(player, pos, type); - } - - @Override - public String getDescription() { - return "use"; - } -} +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.event; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; + +public final class ItemUseBlacklistEvent extends ItemBlacklistEvent { + + public ItemUseBlacklistEvent(LocalPlayer player, Vector pos, int type) { + super(player, pos, type); + } + + @Override + public String getDescription() { + return "use"; + } + + @Override + public EventType getEventType() { + return EventType.USE; + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/logger/ConsoleHandler.java b/src/main/java/com/sk89q/worldguard/blacklist/logger/ConsoleHandler.java new file mode 100644 index 00000000..2430b338 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/logger/ConsoleHandler.java @@ -0,0 +1,63 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.logger; + +import com.sk89q.worldedit.blocks.ItemType; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ConsoleHandler implements LoggerHandler { + + private String worldName; + private final Logger logger; + + public ConsoleHandler(String worldName, Logger logger) { + this.worldName = worldName; + this.logger = logger; + } + + @Override + public void logEvent(BlacklistEvent event, String comment) { + logger.log(Level.INFO, "[" + worldName + "] " + event.getLoggerMessage() + + (comment != null ? " (" + comment + ")" : "")); + } + + /** + * Get an item's friendly name with its ID. + * + * @param id The item id + * @return The friendly name of the item + */ + private static String getFriendlyItemName(int id) { + ItemType type = ItemType.fromID(id); + if (type != null) { + return type.getName() + " (#" + id + ")"; + } else { + return "#" + id; + } + } + + @Override + public void close() { + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/logger/DatabaseHandler.java b/src/main/java/com/sk89q/worldguard/blacklist/logger/DatabaseHandler.java new file mode 100644 index 00000000..0841b285 --- /dev/null +++ b/src/main/java/com/sk89q/worldguard/blacklist/logger/DatabaseHandler.java @@ -0,0 +1,125 @@ +/* + * WorldGuard, a suite of tools for Minecraft + * Copyright (C) sk89q + * Copyright (C) WorldGuard team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldguard.blacklist.logger; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; +import com.sk89q.worldguard.blacklist.event.EventType; + +import javax.annotation.Nullable; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class DatabaseHandler implements LoggerHandler { + + private final String dsn; + private final String user; + private final String pass; + private final String table; + private final String worldName; + private Connection conn; + + private final Logger logger; + + /** + * Construct the object. + * + * @param dsn The DSN for the connection + * @param user The username to connect with + * @param pass The password to connect with + * @param table The table to log to + * @param worldName The name of the world to log + * @param logger The logger to log errors to + */ + public DatabaseHandler(String dsn, String user, String pass, String table, String worldName, Logger logger) { + this.dsn = dsn; + this.user = user; + this.pass = pass; + this.table = table; + this.worldName = worldName; + this.logger = logger; + } + + /** + * Gets the database connection. + * + * @return The database connection + * @throws SQLException when the connection cannot be created + */ + private Connection getConnection() throws SQLException { + if (conn == null || conn.isClosed()) { + conn = DriverManager.getConnection(dsn, user, pass); + } + return conn; + } + + /** + * Log an event to the database. + * + * @param eventType The event type to log + * @param player The player associated with the event + * @param pos The location of the event + * @param item The item used + * @param comment The comment associated with the event + */ + private void logEvent(EventType eventType, @Nullable LocalPlayer player, Vector pos, int item, String comment) { + try { + Connection conn = getConnection(); + PreparedStatement stmt = conn.prepareStatement( + "INSERT INTO " + table + + "(event, world, player, x, y, z, item, time, comment) VALUES " + + "(?, ?, ?, ?, ?, ?, ?, ?, ?)"); + stmt.setString(1, eventType.name()); + stmt.setString(2, worldName); + stmt.setString(3, player != null ? player.getName() : ""); + stmt.setInt(4, pos.getBlockX()); + stmt.setInt(5, pos.getBlockY()); + stmt.setInt(6, pos.getBlockZ()); + stmt.setInt(7, item); + stmt.setInt(8, (int)(System.currentTimeMillis() / 1000)); + stmt.setString(9, comment); + stmt.executeUpdate(); + } catch (SQLException e) { + logger.log(Level.SEVERE, "Failed to log blacklist event to database: " + e.getMessage()); + } + } + + @Override + public void logEvent(BlacklistEvent event, String comment) { + logEvent(event.getEventType(), event.getPlayer(), event.getLoggedPosition(), event.getType(), comment); + } + + @Override + public void close() { + try { + if (conn != null && !conn.isClosed()) { + conn.close(); + } + } catch (SQLException ignore) { + + } + } + +} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/loggers/FileLoggerHandler.java b/src/main/java/com/sk89q/worldguard/blacklist/logger/FileHandler.java similarity index 85% rename from src/main/java/com/sk89q/worldguard/blacklist/loggers/FileLoggerHandler.java rename to src/main/java/com/sk89q/worldguard/blacklist/logger/FileHandler.java index 81e63cf3..c74c4581 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/loggers/FileLoggerHandler.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/logger/FileHandler.java @@ -17,7 +17,12 @@ * along with this program. If not, see . */ -package com.sk89q.worldguard.blacklist.loggers; +package com.sk89q.worldguard.blacklist.logger; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.ItemType; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; import java.io.BufferedWriter; import java.io.File; @@ -35,54 +40,26 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.ItemType; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; +public class FileHandler implements LoggerHandler { -/** - * - * @author sk89q - */ -public class FileLoggerHandler implements BlacklistLoggerHandler { - /** - * Regex for patterns in the path. - */ private static Pattern pattern = Pattern.compile("%."); - /** - * Date format. - */ - private static SimpleDateFormat dateFormat = - new SimpleDateFormat("yyyyy-MM-dd HH:mm:ss"); + private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - /** - * Number of files to keep open at a time. - */ private int cacheSize = 10; - /** - * Path pattern. - */ private String pathPattern; - /** - * World name. - */ private String worldName; - /** - * Cache of writers. - */ - private TreeMap writers = - new TreeMap(); + private TreeMap writers = new TreeMap(); private final Logger logger; /** * Construct the object. * - * @param pathPattern The pattern for the logflie path + * @param pathPattern The pattern for the log file path * @param worldName The name of the world * @param logger The logger used to log errors */ - public FileLoggerHandler(String pathPattern, String worldName, Logger logger) { + public FileHandler(String pathPattern, String worldName, Logger logger) { this.pathPattern = pathPattern; this.worldName = worldName; this.logger = logger; @@ -96,7 +73,7 @@ public FileLoggerHandler(String pathPattern, String worldName, Logger logger) { * @param worldName The name of the associated world * @param logger The logger to log errors with */ - public FileLoggerHandler(String pathPattern, int cacheSize, String worldName, Logger logger) { + public FileHandler(String pathPattern, int cacheSize, String worldName, Logger logger) { if (cacheSize < 1) { throw new IllegalArgumentException("Cache size cannot be less than 1"); } @@ -109,7 +86,7 @@ public FileLoggerHandler(String pathPattern, int cacheSize, String worldName, Lo /** * Build the path. * - * @param playerName The name of the playername + * @param playerName The name of the player * @return The path for the logfile */ private String buildPath(String playerName) { @@ -178,7 +155,7 @@ private void log(LocalPlayer player, String message, String comment) { String line = "[" + date + "] " + player.getName() + ": " + message + (comment != null ? " (" + comment + ")" : "") + "\r\n"; - FileLoggerWriter writer = writers.get(path); + LogFileWriter writer = writers.get(path); // Writer already exists! if (writer != null) { @@ -204,17 +181,17 @@ private void log(LocalPlayer player, String message, String comment) { BufferedWriter out = new BufferedWriter(stream); out.write(line); out.flush(); - writer = new FileLoggerWriter(path, out); + writer = new LogFileWriter(path, out); writers.put(path, writer); // Check to make sure our cache doesn't get too big! if (writers.size() > cacheSize) { - Iterator> it = + Iterator> it = writers.entrySet().iterator(); // Remove some entries for (; it.hasNext(); ) { - Map.Entry entry = it.next(); + Map.Entry entry = it.next(); try { entry.getValue().getWriter().close(); } catch (IOException ignore) { @@ -249,11 +226,7 @@ private void logEvent(BlacklistEvent event, String text, int id, Vector pos, Str + " " + getCoordinates(pos), comment); } - /** - * Log an event. - * - * @param event The event to log - */ + @Override public void logEvent(BlacklistEvent event, String comment) { logEvent(event, event.getDescription(), event.getType(), event.getPosition(), comment); } @@ -273,11 +246,9 @@ private static String getFriendlyItemName(int id) { } } - /** - * Close handles. - */ + @Override public void close() { - for (Map.Entry entry : writers.entrySet()) { + for (Map.Entry entry : writers.entrySet()) { try { entry.getValue().getWriter().close(); } catch (IOException ignore) { @@ -286,4 +257,5 @@ public void close() { writers.clear(); } + } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/loggers/FileLoggerWriter.java b/src/main/java/com/sk89q/worldguard/blacklist/logger/LogFileWriter.java similarity index 82% rename from src/main/java/com/sk89q/worldguard/blacklist/loggers/FileLoggerWriter.java rename to src/main/java/com/sk89q/worldguard/blacklist/logger/LogFileWriter.java index a2b6fa25..69203a9c 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/loggers/FileLoggerWriter.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/logger/LogFileWriter.java @@ -17,26 +17,15 @@ * along with this program. If not, see . */ -package com.sk89q.worldguard.blacklist.loggers; +package com.sk89q.worldguard.blacklist.logger; +import javax.annotation.Nullable; import java.io.BufferedWriter; -/** - * - * @author sk89q - */ -public class FileLoggerWriter implements Comparable { - /** - * Path. - */ +public class LogFileWriter implements Comparable { + public String path; - /** - * Writer. - */ private BufferedWriter writer; - /** - * Last use. - */ private long lastUse; /** @@ -45,7 +34,7 @@ public class FileLoggerWriter implements Comparable { * @param path The path to write to * @param writer The writer for the file */ - public FileLoggerWriter(String path, BufferedWriter writer) { + public LogFileWriter(String path, BufferedWriter writer) { this.path = path; this.writer = writer; lastUse = System.currentTimeMillis(); @@ -81,8 +70,11 @@ public void updateLastUse() { lastUse = System.currentTimeMillis(); } - public int compareTo(FileLoggerWriter other) { - if (lastUse > other.lastUse) { + @Override + public int compareTo(@Nullable LogFileWriter other) { + if (other == null) { + return 1; + } else if (lastUse > other.lastUse) { return 1; } else if (lastUse < other.lastUse) { return -1; @@ -90,4 +82,5 @@ public int compareTo(FileLoggerWriter other) { return 0; } } + } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/loggers/BlacklistLoggerHandler.java b/src/main/java/com/sk89q/worldguard/blacklist/logger/LoggerHandler.java similarity index 82% rename from src/main/java/com/sk89q/worldguard/blacklist/loggers/BlacklistLoggerHandler.java rename to src/main/java/com/sk89q/worldguard/blacklist/logger/LoggerHandler.java index 64669dd5..f1fdb199 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/loggers/BlacklistLoggerHandler.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/logger/LoggerHandler.java @@ -17,21 +17,20 @@ * along with this program. If not, see . */ -package com.sk89q.worldguard.blacklist.loggers; +package com.sk89q.worldguard.blacklist.logger; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlacklistEvent; /** * Interface for loggers for the blacklist. - * - * @author sk89q */ -public interface BlacklistLoggerHandler { +public interface LoggerHandler { + /** * Log an event. * - * @param event - * @param comment + * @param event The event + * @param comment The comment to log with the event */ public void logEvent(BlacklistEvent event, String comment); @@ -39,4 +38,5 @@ public interface BlacklistLoggerHandler { * Close the logger. */ public void close(); + } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/loggers/ConsoleLoggerHandler.java b/src/main/java/com/sk89q/worldguard/blacklist/loggers/ConsoleLoggerHandler.java deleted file mode 100644 index a8941b40..00000000 --- a/src/main/java/com/sk89q/worldguard/blacklist/loggers/ConsoleLoggerHandler.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.loggers; - -import com.sk89q.worldedit.blocks.ItemType; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author sk89q - */ -public class ConsoleLoggerHandler implements BlacklistLoggerHandler { - - - private String worldName; - - private final Logger logger; - - public ConsoleLoggerHandler(String worldName, Logger logger) { - this.worldName = worldName; - this.logger = logger; - } - - public void logEvent(BlacklistEvent event, String comment) { - // Block break - if (event instanceof BlockBreakBlacklistEvent) { - BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event; - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " tried to break " + getFriendlyItemName(evt.getType()) - + (comment != null ? " (" + comment + ")" : "")); - - // Block place - } else if (event instanceof BlockPlaceBlacklistEvent) { - BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event; - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " tried to place " + getFriendlyItemName(evt.getType()) - + (comment != null ? " (" + comment + ")" : "")); - - // Block interact - } else if (event instanceof BlockInteractBlacklistEvent) { - BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event; - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " tried to interact with " + getFriendlyItemName(evt.getType()) - + (comment != null ? " (" + comment + ")" : "")); - - // Destroy with - } else if (event instanceof DestroyWithBlacklistEvent) { - DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event; - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " tried to destroy with " + getFriendlyItemName(evt.getType()) - + (comment != null ? " (" + comment + ")" : "")); - - // Acquire - } else if (event instanceof ItemAcquireBlacklistEvent) { - ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event; - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " tried to acquire " + getFriendlyItemName(evt.getType()) - + (comment != null ? " (" + comment + ")" : "")); - - // Drop - } else if (event instanceof ItemDropBlacklistEvent) { - ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event; - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " tried to drop " + getFriendlyItemName(evt.getType()) - + (comment != null ? " (" + comment + ")" : "")); - - // Use - } else if (event instanceof ItemUseBlacklistEvent) { - ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event; - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " tried to use " + getFriendlyItemName(evt.getType()) - + (comment != null ? " (" + comment + ")" : "")); - - // Unknown - } else { - logger.log(Level.INFO, "[" + worldName + "] " + event.getPlayer().getName() - + " caught unknown event: " + event.getClass().getCanonicalName()); - } - } - - /** - * Get an item's friendly name with its ID. - * - * @param id The item id - * @return The friendly name of the item - */ - private static String getFriendlyItemName(int id) { - ItemType type = ItemType.fromID(id); - if (type != null) { - return type.getName() + " (#" + id + ")"; - } else { - return "#" + id; - } - } - - /** - * Close the connection. - */ - public void close() { - } -} diff --git a/src/main/java/com/sk89q/worldguard/blacklist/loggers/DatabaseLoggerHandler.java b/src/main/java/com/sk89q/worldguard/blacklist/loggers/DatabaseLoggerHandler.java deleted file mode 100644 index a51b1872..00000000 --- a/src/main/java/com/sk89q/worldguard/blacklist/loggers/DatabaseLoggerHandler.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * WorldGuard, a suite of tools for Minecraft - * Copyright (C) sk89q - * Copyright (C) WorldGuard team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldguard.blacklist.loggers; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.blacklist.events.BlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; - -/** - * - * @author sk89q - */ -public class DatabaseLoggerHandler implements BlacklistLoggerHandler { - - /** - * DSN. - */ - private final String dsn; - /** - * Username. - */ - private final String user; - /** - * Password. - */ - private final String pass; - /** - * Table. - */ - private final String table; - /** - * World name. - */ - private final String worldName; - /** - * Database connection. - */ - private Connection conn; - - private final Logger logger; - - /** - * Construct the object. - * - * @param dsn The DSN for the connection - * @param user The username to connect with - * @param pass The password to connect with - * @param table The table to log to - * @param worldName The name of the world to log - * @param logger The logger to log errors to - */ - public DatabaseLoggerHandler(String dsn, String user, String pass, String table, String worldName, Logger logger) { - this.dsn = dsn; - this.user = user; - this.pass = pass; - this.table = table; - this.worldName = worldName; - this.logger = logger; - } - - /** - * Gets the database connection. - * - * @return The database connection - * @throws SQLException when the connection cannot be created - */ - private Connection getConnection() throws SQLException { - if (conn == null || conn.isClosed()) { - conn = DriverManager.getConnection(dsn, user, pass); - } - return conn; - } - - /** - * Log an event to the database. - * - * @param event The event to log - * @param player The player associated with the event - * @param pos The location of the event - * @param item The item used - * @param comment The comment associated with the event - */ - private void logEvent(String event, LocalPlayer player, Vector pos, int item, - String comment) { - try { - Connection conn = getConnection(); - PreparedStatement stmt = conn.prepareStatement( - "INSERT INTO " + table - + "(event, world, player, x, y, z, item, time, comment) VALUES " - + "(?, ?, ?, ?, ?, ?, ?, ?, ?)"); - stmt.setString(1, event); - stmt.setString(2, worldName); - stmt.setString(3, player.getName()); - stmt.setInt(4, pos.getBlockX()); - stmt.setInt(5, pos.getBlockY()); - stmt.setInt(6, pos.getBlockZ()); - stmt.setInt(7, item); - stmt.setInt(8, (int)(System.currentTimeMillis() / 1000)); - stmt.setString(9, comment); - stmt.executeUpdate(); - } catch (SQLException e) { - logger.log(Level.SEVERE, "Failed to log blacklist event to database: " - + e.getMessage()); - } - } - - /** - * Log an event. - * - * @param event The event to log - */ - public void logEvent(BlacklistEvent event, String comment) { - // Block break - if (event instanceof BlockBreakBlacklistEvent) { - BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event; - logEvent("BREAK", evt.getPlayer(), evt.getPosition(), - evt.getType(), comment); - - // Block place - } else if (event instanceof BlockPlaceBlacklistEvent) { - BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event; - logEvent("PLACE", evt.getPlayer(), evt.getPosition(), - evt.getType(), comment); - - // Block interact - } else if (event instanceof BlockInteractBlacklistEvent) { - BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event; - logEvent("INTERACT", evt.getPlayer(), evt.getPosition(), - evt.getType(), comment); - - // Destroy with - } else if (event instanceof DestroyWithBlacklistEvent) { - DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event; - logEvent("DESTROY_WITH", evt.getPlayer(), evt.getPosition(), - evt.getType(), comment); - - // Acquire - } else if (event instanceof ItemAcquireBlacklistEvent) { - ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event; - logEvent("ACQUIRE", evt.getPlayer(), evt.getPlayer().getPosition(), - evt.getType(), comment); - - // Drop - } else if (event instanceof ItemDropBlacklistEvent) { - ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event; - logEvent("DROP", evt.getPlayer(), evt.getPlayer().getPosition(), - evt.getType(), comment); - - // Use - } else if (event instanceof ItemUseBlacklistEvent) { - ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event; - logEvent("USE", evt.getPlayer(), evt.getPlayer().getPosition(), - evt.getType(), comment); - - // Unknown - } else { - logEvent("UNKNOWN", event.getPlayer(), event.getPlayer().getPosition(), - -1, comment); - } - } - - /** - * Close the connection. - */ - public void close() { - try { - if (conn != null && !conn.isClosed()) { - conn.close(); - } - } catch (SQLException ignore) { - - } - } -} diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index 5e1f93c1..1cd7824b 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -22,10 +22,10 @@ import com.sk89q.util.yaml.YAMLFormat; import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.worldguard.blacklist.Blacklist; -import com.sk89q.worldguard.blacklist.BlacklistLogger; -import com.sk89q.worldguard.blacklist.loggers.ConsoleLoggerHandler; -import com.sk89q.worldguard.blacklist.loggers.DatabaseLoggerHandler; -import com.sk89q.worldguard.blacklist.loggers.FileLoggerHandler; +import com.sk89q.worldguard.blacklist.Logger; +import com.sk89q.worldguard.blacklist.logger.ConsoleHandler; +import com.sk89q.worldguard.blacklist.logger.DatabaseHandler; +import com.sk89q.worldguard.blacklist.logger.FileHandler; import com.sk89q.worldguard.chest.ChestProtection; import com.sk89q.worldguard.chest.SignChestProtection; import org.bukkit.block.Block; @@ -487,19 +487,19 @@ private void loadConfiguration() { plugin.getLogger().log(Level.INFO, "Blacklist loaded."); } - BlacklistLogger blacklistLogger = blist.getLogger(); + Logger blacklistLogger = blist.getLogger(); if (logDatabase) { - blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table, worldName, plugin.getLogger())); + blacklistLogger.addHandler(new DatabaseHandler(dsn, user, pass, table, worldName, plugin.getLogger())); } if (logConsole) { - blacklistLogger.addHandler(new ConsoleLoggerHandler(worldName, plugin.getLogger())); + blacklistLogger.addHandler(new ConsoleHandler(worldName, plugin.getLogger())); } if (logFile) { - FileLoggerHandler handler = - new FileLoggerHandler(logFilePattern, logFileCacheSize, worldName, plugin.getLogger()); + FileHandler handler = + new FileHandler(logFilePattern, logFileCacheSize, worldName, plugin.getLogger()); blacklistLogger.addHandler(handler); } } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java index 3ef52838..f908c474 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java @@ -27,8 +27,8 @@ import com.sk89q.worldguard.internal.Blocks; import com.sk89q.worldguard.internal.Events; import com.sk89q.worldguard.internal.cause.Causes; -import com.sk89q.worldguard.internal.event.Interaction; import com.sk89q.worldguard.internal.event.BlockInteractEvent; +import com.sk89q.worldguard.internal.event.Interaction; import com.sk89q.worldguard.internal.event.ItemInteractEvent; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.DefaultFlag; diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 680e076b..996beca2 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -22,7 +22,7 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent; import com.sk89q.worldguard.internal.Events; import com.sk89q.worldguard.internal.cause.Causes; import com.sk89q.worldguard.internal.event.Interaction; diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java index 0f370bb3..b558f7a7 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardHangingListener.java @@ -20,8 +20,8 @@ package com.sk89q.worldguard.bukkit; import com.sk89q.worldedit.blocks.ItemID; -import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent; import com.sk89q.worldguard.protection.flags.DefaultFlag; import org.bukkit.ChatColor; import org.bukkit.World; diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java index 86064541..381d6cce 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java @@ -24,12 +24,12 @@ import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.ItemID; import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockInteractBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemAcquireBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemDropBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlockInteractBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlockPlaceBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.ItemAcquireBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.ItemDropBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.ItemUseBlacklistEvent; import com.sk89q.worldguard.bukkit.FlagStateManager.PlayerFlagState; import com.sk89q.worldguard.internal.Events; import com.sk89q.worldguard.internal.cause.Causes; diff --git a/src/main/java/com/sk89q/worldguard/internal/listener/BlacklistListener.java b/src/main/java/com/sk89q/worldguard/internal/listener/BlacklistListener.java index da33547c..db2ba5ec 100644 --- a/src/main/java/com/sk89q/worldguard/internal/listener/BlacklistListener.java +++ b/src/main/java/com/sk89q/worldguard/internal/listener/BlacklistListener.java @@ -19,9 +19,9 @@ package com.sk89q.worldguard.internal.listener; -import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.BlockPlaceBlacklistEvent; -import com.sk89q.worldguard.blacklist.events.DestroyWithBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlockBreakBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.BlockPlaceBlacklistEvent; +import com.sk89q.worldguard.blacklist.event.ItemDestroyWithBlacklistEvent; import com.sk89q.worldguard.bukkit.WorldConfiguration; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.internal.cause.Causes; @@ -67,7 +67,7 @@ public void handleBlockInteract(BlockInteractEvent event) { } if (!wcfg.getBlacklist().check( - new DestroyWithBlacklistEvent(getPlugin().wrapPlayer(player), toVector(target), player.getItemInHand().getTypeId()), false, false)) { + new ItemDestroyWithBlacklistEvent(getPlugin().wrapPlayer(player), toVector(target), player.getItemInHand().getTypeId()), false, false)) { event.setCancelled(true); return; }