forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ShopRemovalLogger.java
45 lines (37 loc) · 1.81 KB
/
ShopRemovalLogger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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.ChestShopMetaData;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
/**
* @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) {
if (event.getDestroyer() != null) {
return;
}
ChestShopMetaData chestShopMetaData = ChestShopSign.getChestShopMetaData(event.getSign());
if (chestShopMetaData == null)
return;
String shopOwner = NameManager.getFullNameFor(chestShopMetaData.getOwner());
String typeOfShop = event.isAdminshop() ? "An Admin Shop" : "A shop belonging to " + shopOwner;
String item = chestShopMetaData.getQuantity() + ' ' + chestShopMetaData.getItemStack().getType().toString();
String prices = "B " + chestShopMetaData.getBuyPrice() + " : " + chestShopMetaData.getSellPrice() + " S";
String location = LocationUtil.locationToString(event.getSign().getLocation());
String message = String.format(REMOVAL_MESSAGE, typeOfShop, item, prices, location);
ChestShop.getBukkitServer().getScheduler().runTaskAsynchronously(ChestShop.getPlugin(), new Runnable() {
@Override
public void run() {
ChestShop.getBukkitLogger().info(message);
}
});
}
}