diff --git a/src/main/java/com/Acrobot/Breeze/Utils/LocationUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/LocationUtil.java new file mode 100644 index 0000000..5160478 --- /dev/null +++ b/src/main/java/com/Acrobot/Breeze/Utils/LocationUtil.java @@ -0,0 +1,20 @@ +package com.Acrobot.Breeze.Utils; + +import org.bukkit.Location; + +/** + * An utility class providing various methods to deal with locations + * + * @author Acrobot + */ +public class LocationUtil { + /** + * Returns a string representing the location + * + * @param location Location represented + * @return Representation of the location + */ + public static String locationToString(Location location) { + return '[' + location.getWorld().getName() + "] " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ(); + } +} diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index 3c21904..59517a9 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -21,13 +21,15 @@ import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule; import com.Acrobot.ChestShop.Listeners.Player.*; import com.Acrobot.ChestShop.Listeners.PostShopCreation.CreationFeeGetter; import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender; +import com.Acrobot.ChestShop.Listeners.PostShopCreation.ShopCreationLogger; import com.Acrobot.ChestShop.Listeners.PostShopCreation.SignSticker; import com.Acrobot.ChestShop.Listeners.PostTransaction.*; import com.Acrobot.ChestShop.Listeners.PreShopCreation.*; import com.Acrobot.ChestShop.Listeners.PreTransaction.*; import com.Acrobot.ChestShop.Listeners.PreTransaction.ErrorMessageSender; import com.Acrobot.ChestShop.Listeners.PreTransaction.PermissionChecker; -import com.Acrobot.ChestShop.Listeners.ShopRefundListener; +import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRefundListener; +import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRemovalLogger; import com.Acrobot.ChestShop.Logging.FileFormatter; import com.Acrobot.ChestShop.Metadata.ItemDatabase; import com.Acrobot.ChestShop.Signs.RestrictedSign; @@ -169,6 +171,7 @@ public class ChestShop extends JavaPlugin { registerPreTransactionEvents(); registerPostShopCreationEvents(); registerPostTransactionEvents(); + registerShopRemovalEvents(); registerModules(); @@ -186,11 +189,14 @@ public class ChestShop extends JavaPlugin { registerEvent(new ItemInfoListener()); registerEvent(new RestrictedSign()); - registerEvent(new ShopRefundListener()); - registerEvent(new ShortNameSaver()); } + private void registerShopRemovalEvents() { + registerEvent(new ShopRefundListener()); + registerEvent(new ShopRemovalLogger()); + } + private void registerPreShopCreationEvents() { if (Properties.BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE) { registerEvent(new PriceRatioChecker()); @@ -211,6 +217,7 @@ public class ChestShop extends JavaPlugin { registerEvent(new CreationFeeGetter()); registerEvent(new MessageSender()); registerEvent(new SignSticker()); + registerEvent(new ShopCreationLogger()); } private void registerPreTransactionEvents() { diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostShopCreation/ShopCreationLogger.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostShopCreation/ShopCreationLogger.java new file mode 100644 index 0000000..cf83e49 --- /dev/null +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostShopCreation/ShopCreationLogger.java @@ -0,0 +1,42 @@ +package com.Acrobot.ChestShop.Listeners.PostShopCreation; + +import com.Acrobot.Breeze.Utils.LocationUtil; +import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Events.ShopCreatedEvent; +import com.Acrobot.ChestShop.Signs.ChestShopSign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +import static com.Acrobot.ChestShop.Signs.ChestShopSign.*; + +/** + * @author Acrobot + */ +public class ShopCreationLogger implements Listener { + private static final String CREATION_MESSAGE = "%1$s created %2$s - %3$s - %4$s - at %5$s"; + + @EventHandler(priority = EventPriority.MONITOR) + public static void onShopCreation(final ShopCreatedEvent event) { + ChestShop.getBukkitServer().getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), new Runnable() { + @Override public void run() { + String creator = event.getPlayer().getName(); + String shopOwner = event.getSignLine(NAME_LINE); + String typeOfShop = ChestShopSign.isAdminShop(shopOwner) ? "an Admin Shop" : "a shop"; + + String item = event.getSignLine(QUANTITY_LINE) + ' ' + event.getSignLine(ITEM_LINE); + String prices = event.getSignLine(PRICE_LINE); + String location = LocationUtil.locationToString(event.getSign().getLocation()); + + String message = String.format(CREATION_MESSAGE, + creator, + typeOfShop, + item, + prices, + location); + + ChestShop.getBukkitLogger().info(message); + } + }); + } +} diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionLogger.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionLogger.java index 5ccfe1b..914e9ff 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionLogger.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionLogger.java @@ -1,5 +1,6 @@ package com.Acrobot.ChestShop.Listeners.PostTransaction; +import com.Acrobot.Breeze.Utils.LocationUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.DB.Queue; @@ -38,7 +39,7 @@ public class TransactionLogger implements Listener { items.toString(), event.getPrice(), event.getOwner().getName(), - locationToString(event.getSign().getLocation())); + LocationUtil.locationToString(event.getSign().getLocation())); ChestShop.getBukkitLogger().info(message); } @@ -72,8 +73,4 @@ public class TransactionLogger implements Listener { Queue.addToQueue(transaction); } } - - private static String locationToString(Location loc) { - return '[' + loc.getWorld().getName() + "] " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ(); - } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRefundListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java similarity index 96% rename from src/main/java/com/Acrobot/ChestShop/Listeners/ShopRefundListener.java rename to src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java index 1ff80a1..f8d337f 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRefundListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java @@ -1,4 +1,4 @@ -package com.Acrobot.ChestShop.Listeners; +package com.Acrobot.ChestShop.Listeners.ShopRemoval; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Messages; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRemovalLogger.java b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRemovalLogger.java new file mode 100644 index 0000000..50bfae5 --- /dev/null +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRemovalLogger.java @@ -0,0 +1,40 @@ +package com.Acrobot.ChestShop.Listeners.ShopRemoval; + +import com.Acrobot.Breeze.Utils.LocationUtil; +import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Events.ShopDestroyedEvent; +import com.Acrobot.ChestShop.Signs.ChestShopSign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +import static com.Acrobot.ChestShop.Signs.ChestShopSign.*; + +/** + * @author Acrobot + */ +public class ShopRemovalLogger implements Listener { + private static final String REMOVAL_MESSAGE = "%1$s was removed - %2$s - %3$s - at %4$s"; + + @EventHandler(priority = EventPriority.MONITOR) + public static void onShopRemoval(final ShopDestroyedEvent event) { + ChestShop.getBukkitServer().getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), new Runnable() { + @Override public void run() { + String shopOwner = event.getSign().getLine(NAME_LINE); + String typeOfShop = ChestShopSign.isAdminShop(shopOwner) ? "An Admin Shop" : "A shop belonging to " + shopOwner; + + String item = event.getSign().getLine(QUANTITY_LINE) + ' ' + event.getSign().getLine(ITEM_LINE); + String prices = event.getSign().getLine(PRICE_LINE); + String location = LocationUtil.locationToString(event.getSign().getLocation()); + + String message = String.format(REMOVAL_MESSAGE, + typeOfShop, + item, + prices, + location); + + ChestShop.getBukkitLogger().info(message); + } + }); + } +}