mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-02 15:03:22 +01:00
Add shop created/removed logging
This commit is contained in:
parent
2d295e1421
commit
e1cb30a0e8
20
src/main/java/com/Acrobot/Breeze/Utils/LocationUtil.java
Normal file
20
src/main/java/com/Acrobot/Breeze/Utils/LocationUtil.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -21,13 +21,15 @@ import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule;
|
|||||||
import com.Acrobot.ChestShop.Listeners.Player.*;
|
import com.Acrobot.ChestShop.Listeners.Player.*;
|
||||||
import com.Acrobot.ChestShop.Listeners.PostShopCreation.CreationFeeGetter;
|
import com.Acrobot.ChestShop.Listeners.PostShopCreation.CreationFeeGetter;
|
||||||
import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender;
|
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.PostShopCreation.SignSticker;
|
||||||
import com.Acrobot.ChestShop.Listeners.PostTransaction.*;
|
import com.Acrobot.ChestShop.Listeners.PostTransaction.*;
|
||||||
import com.Acrobot.ChestShop.Listeners.PreShopCreation.*;
|
import com.Acrobot.ChestShop.Listeners.PreShopCreation.*;
|
||||||
import com.Acrobot.ChestShop.Listeners.PreTransaction.*;
|
import com.Acrobot.ChestShop.Listeners.PreTransaction.*;
|
||||||
import com.Acrobot.ChestShop.Listeners.PreTransaction.ErrorMessageSender;
|
import com.Acrobot.ChestShop.Listeners.PreTransaction.ErrorMessageSender;
|
||||||
import com.Acrobot.ChestShop.Listeners.PreTransaction.PermissionChecker;
|
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.Logging.FileFormatter;
|
||||||
import com.Acrobot.ChestShop.Metadata.ItemDatabase;
|
import com.Acrobot.ChestShop.Metadata.ItemDatabase;
|
||||||
import com.Acrobot.ChestShop.Signs.RestrictedSign;
|
import com.Acrobot.ChestShop.Signs.RestrictedSign;
|
||||||
@ -169,6 +171,7 @@ public class ChestShop extends JavaPlugin {
|
|||||||
registerPreTransactionEvents();
|
registerPreTransactionEvents();
|
||||||
registerPostShopCreationEvents();
|
registerPostShopCreationEvents();
|
||||||
registerPostTransactionEvents();
|
registerPostTransactionEvents();
|
||||||
|
registerShopRemovalEvents();
|
||||||
|
|
||||||
registerModules();
|
registerModules();
|
||||||
|
|
||||||
@ -186,11 +189,14 @@ public class ChestShop extends JavaPlugin {
|
|||||||
registerEvent(new ItemInfoListener());
|
registerEvent(new ItemInfoListener());
|
||||||
|
|
||||||
registerEvent(new RestrictedSign());
|
registerEvent(new RestrictedSign());
|
||||||
registerEvent(new ShopRefundListener());
|
|
||||||
|
|
||||||
registerEvent(new ShortNameSaver());
|
registerEvent(new ShortNameSaver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerShopRemovalEvents() {
|
||||||
|
registerEvent(new ShopRefundListener());
|
||||||
|
registerEvent(new ShopRemovalLogger());
|
||||||
|
}
|
||||||
|
|
||||||
private void registerPreShopCreationEvents() {
|
private void registerPreShopCreationEvents() {
|
||||||
if (Properties.BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE) {
|
if (Properties.BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE) {
|
||||||
registerEvent(new PriceRatioChecker());
|
registerEvent(new PriceRatioChecker());
|
||||||
@ -211,6 +217,7 @@ public class ChestShop extends JavaPlugin {
|
|||||||
registerEvent(new CreationFeeGetter());
|
registerEvent(new CreationFeeGetter());
|
||||||
registerEvent(new MessageSender());
|
registerEvent(new MessageSender());
|
||||||
registerEvent(new SignSticker());
|
registerEvent(new SignSticker());
|
||||||
|
registerEvent(new ShopCreationLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPreTransactionEvents() {
|
private void registerPreTransactionEvents() {
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
||||||
|
|
||||||
|
import com.Acrobot.Breeze.Utils.LocationUtil;
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||||
import com.Acrobot.ChestShop.DB.Queue;
|
import com.Acrobot.ChestShop.DB.Queue;
|
||||||
@ -38,7 +39,7 @@ public class TransactionLogger implements Listener {
|
|||||||
items.toString(),
|
items.toString(),
|
||||||
event.getPrice(),
|
event.getPrice(),
|
||||||
event.getOwner().getName(),
|
event.getOwner().getName(),
|
||||||
locationToString(event.getSign().getLocation()));
|
LocationUtil.locationToString(event.getSign().getLocation()));
|
||||||
|
|
||||||
ChestShop.getBukkitLogger().info(message);
|
ChestShop.getBukkitLogger().info(message);
|
||||||
}
|
}
|
||||||
@ -72,8 +73,4 @@ public class TransactionLogger implements Listener {
|
|||||||
Queue.addToQueue(transaction);
|
Queue.addToQueue(transaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String locationToString(Location loc) {
|
|
||||||
return '[' + loc.getWorld().getName() + "] " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.Acrobot.ChestShop.Listeners;
|
package com.Acrobot.ChestShop.Listeners.ShopRemoval;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
import com.Acrobot.ChestShop.Configuration.Messages;
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user