Add GriefPreventionListener to listen to GriefPreventionEvents

This commit is contained in:
Len 2023-06-27 16:49:47 +02:00
parent fa2d5689fb
commit 7553df9c12
3 changed files with 42 additions and 16 deletions

View File

@ -32,6 +32,7 @@ public class PlayerShops extends JavaPlugin {
private PlayerListener playerListener;
private TransactionListener transactionListener;
private InventoryListener inventoryListener;
private GriefPreventionListener griefPreventionListener;
public void onEnable() {
instance = this;
@ -92,6 +93,7 @@ public class PlayerShops extends JavaPlugin {
playerListener = new PlayerListener(this);
transactionListener = new TransactionListener(this);
inventoryListener = new InventoryListener(this);
griefPreventionListener = new GriefPreventionListener(this); // TODO hook into GP
}
private void unRegisterListeners() {

View File

@ -0,0 +1,40 @@
package com.alttd.playershops.listener;
import com.alttd.playershops.PlayerShops;
import com.alttd.playershops.handler.ShopHandler;
import com.alttd.playershops.shop.PlayerShop;
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import java.util.List;
import java.util.UUID;
public class GriefPreventionListener extends EventListener {
private final PlayerShops plugin;
ShopHandler shopHandler;
public GriefPreventionListener(PlayerShops plugin) {
this.plugin = plugin;
this.register(this.plugin);
shopHandler = plugin.getShopHandler();
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onClaimExpiration(ClaimExpirationEvent event) {
if(!this.isRegistered)
return;
UUID uuid = event.getClaim().ownerID;
if(uuid == null)
return;
List<PlayerShop> playerShops = shopHandler.getShops(uuid);
for(PlayerShop shop : playerShops) {
shop.expireSign();
shopHandler.removeShop(shop);
}
}
}

View File

@ -243,20 +243,4 @@ public class ShopListener extends EventListener {
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onClaimExpiration(ClaimExpirationEvent event) {
if(!this.isRegistered)
return;
UUID uuid = event.getClaim().ownerID;
if(uuid == null)
return;
List<PlayerShop> playerShops = shopHandler.getShops(uuid);
for(PlayerShop shop : playerShops) {
shop.expireSign();
shopHandler.removeShop(shop);
}
}
}