Add BentoBox integration

Added a custom protection flag CREATE_SHOP that defaults to trusted members

Shops are removed if an island is deleted or reset, or if a player is banned or expelled from the island
This commit is contained in:
Eric 2020-03-16 13:35:22 +01:00
parent 59ea803f5d
commit 8ac7d85f1e
8 changed files with 212 additions and 1 deletions

View File

@ -138,6 +138,12 @@
<version>2.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>1.11.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.palmergames</groupId>
<artifactId>Towny</artifactId>

View File

@ -6,6 +6,7 @@ import de.epiceric.shopchest.command.ShopCommand;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.HologramFormat;
import de.epiceric.shopchest.event.ShopInitializedEvent;
import de.epiceric.shopchest.external.BentoBoxShopFlag;
import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.external.WorldGuardShopFlag;
import de.epiceric.shopchest.external.listeners.ASkyBlockListener;
@ -16,6 +17,7 @@ import de.epiceric.shopchest.external.listeners.TownyListener;
import de.epiceric.shopchest.external.listeners.USkyBlockListener;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.listeners.AreaShopListener;
import de.epiceric.shopchest.listeners.BentoBoxListener;
import de.epiceric.shopchest.listeners.BlockExplodeListener;
import de.epiceric.shopchest.listeners.ChestProtectListener;
import de.epiceric.shopchest.listeners.CreativeModeListener;
@ -54,6 +56,7 @@ import org.codemc.worldguardwrapper.WorldGuardWrapper;
import pl.islandworld.IslandWorld;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
import world.bentobox.bentobox.BentoBox;
import java.io.File;
import java.io.FileWriter;
@ -92,6 +95,7 @@ public class ShopChest extends JavaPlugin {
private IslandWorld islandWorld;
private GriefPrevention griefPrevention;
private AreaShop areaShop;
private BentoBox bentoBox;
private ShopUpdater updater;
private ExecutorService shopCreationThreadPool;
@ -303,6 +307,11 @@ public class ShopChest extends JavaPlugin {
areaShop = (AreaShop) areaShopPlugin;
}
Plugin bentoBoxPlugin = getServer().getPluginManager().getPlugin("BentoBox");
if (bentoBoxPlugin instanceof BentoBox) {
bentoBox = (BentoBox) bentoBoxPlugin;
}
if (hasWorldGuard()) {
WorldGuardWrapper.getInstance().registerEvents(this);
}
@ -310,6 +319,10 @@ public class ShopChest extends JavaPlugin {
if (hasPlotSquared()) {
PlotSquaredShopFlag.register(this);
}
if (hasBentoBox()) {
BentoBoxShopFlag.register(this);
}
}
private void loadMetrics() {
@ -422,6 +435,10 @@ public class ShopChest extends JavaPlugin {
getServer().getPluginManager().registerEvents(new AreaShopListener(this), this);
}
}
if (hasBentoBox()) {
getServer().getPluginManager().registerEvents(new BentoBoxListener(this), this);
}
}
private void registerExternalListeners() {
@ -439,6 +456,8 @@ public class ShopChest extends JavaPlugin {
getServer().getPluginManager().registerEvents(new USkyBlockListener(this), this);
if (hasWorldGuard())
getServer().getPluginManager().registerEvents(new de.epiceric.shopchest.external.listeners.WorldGuardListener(this), this);
if (hasBentoBox())
getServer().getPluginManager().registerEvents(new de.epiceric.shopchest.external.listeners.BentoBoxListener(this), this);
}
/**
@ -623,6 +642,13 @@ public class ShopChest extends JavaPlugin {
return worldGuard != null && worldGuard.isEnabled();
}
/**
* @return Whether the plugin 'WorldGuard' is enabled
*/
public boolean hasBentoBox() {
return bentoBox != null && bentoBox.isEnabled();
}
/**
* @return ShopChest's {@link ShopUtils} containing some important methods
*/

View File

@ -194,6 +194,11 @@ public class Config {
**/
public static boolean enableASkyblockIntegration;
/**
* Whether BentoBox integration should be enabled
**/
public static boolean enableBentoBoxIntegration;
/**
* Whether IslandWorld integration should be enabled
**/
@ -476,6 +481,7 @@ public class Config {
enablePlotsquaredIntegration = plugin.getConfig().getBoolean("enable-plotsquared-integration");
enableUSkyblockIntegration = plugin.getConfig().getBoolean("enable-uskyblock-integration");
enableASkyblockIntegration = plugin.getConfig().getBoolean("enable-askyblock-integration");
enableBentoBoxIntegration = plugin.getConfig().getBoolean("enable-bentobox-integration");
enableIslandWorldIntegration = plugin.getConfig().getBoolean("enable-islandworld-integration");
enableGriefPreventionIntegration = plugin.getConfig().getBoolean("enable-griefprevention-integration");
enableAreaShopIntegration = plugin.getConfig().getBoolean("enable-areashop-integration");

View File

@ -0,0 +1,25 @@
package de.epiceric.shopchest.external;
import org.bukkit.Material;
import de.epiceric.shopchest.ShopChest;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.managers.RanksManager;
public class BentoBoxShopFlag {
public static final Flag SHOP_FLAG = new Flag.Builder("CREATE_SHOPS", Material.CHEST)
.type(Flag.Type.PROTECTION)
.mode(Flag.Mode.BASIC)
.defaultRank(RanksManager.TRUSTED_RANK)
.build();
public static void register(ShopChest plugin) {
if (BentoBox.getInstance().getFlagsManager().registerFlag(SHOP_FLAG)) {
plugin.debug("Registered BentoBox shop flag");
} else {
plugin.getLogger().warning("Failed to register BentoBox shop flag");
plugin.debug("Failed to register BentoBox shop flag");
}
}
}

View File

@ -0,0 +1,57 @@
package de.epiceric.shopchest.external.listeners;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.event.ShopCreateEvent;
import de.epiceric.shopchest.event.ShopExtendEvent;
import de.epiceric.shopchest.external.BentoBoxShopFlag;
import de.epiceric.shopchest.utils.Utils;
import world.bentobox.bentobox.api.flags.FlagListener;
public class BentoBoxListener extends FlagListener {
private ShopChest plugin;
public BentoBoxListener(ShopChest plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCreateShop(ShopCreateEvent e) {
if (!Config.enableBentoBoxIntegration)
return;
Set<Location> chestLocations = Utils.getChestLocations(e.getShop());
for (Location loc : chestLocations) {
if (handleForLocation(e.getPlayer(), loc, e))
return;
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onExtendShop(ShopExtendEvent e) {
if (!Config.enableBentoBoxIntegration)
return;
handleForLocation(e.getPlayer(), e.getNewChestLocation(), e);
}
private boolean handleForLocation(Player player, Location loc, Cancellable e) {
boolean allowed = checkIsland((Event) e, player, loc, BentoBoxShopFlag.SHOP_FLAG, true);
if (!allowed) {
e.setCancelled(true);
plugin.debug("Cancel Reason: BentoBox");
return true;
}
return false;
}
}

View File

@ -0,0 +1,90 @@
package de.epiceric.shopchest.listeners;
import java.util.Collection;
import java.util.UUID;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.util.BoundingBox;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop;
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandBanEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandDeleteChunksEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandDeletedEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandExpelEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandResettedEvent;
import world.bentobox.bentobox.database.objects.Island;
public class BentoBoxListener implements Listener {
private ShopChest plugin;
public BentoBoxListener(ShopChest plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onIslandDeleted(IslandDeletedEvent e) {
deleteShops(e.getIsland().getWorld(), e.getDeletedIslandInfo().getBox());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandBan(IslandBanEvent e) {
deleteShops(e.getIsland(), e.getPlayerUUID());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onIslandResetted(IslandResettedEvent e) {
deleteShops(e.getIsland());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandResettead(IslandDeleteChunksEvent e) {
deleteShops(e.getIsland().getWorld(), e.getDeletedIslandInfo().getBox());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandResettead(IslandExpelEvent e) {
deleteShops(e.getIsland(), e.getPlayerUUID());
}
// Utility methods
private void deleteShops(Island island) {
deleteShops(island.getWorld(), island.getBoundingBox(), null);
}
private void deleteShops(Island island, UUID vendorUuid) {
deleteShops(island.getWorld(), island.getBoundingBox(), vendorUuid);
}
private void deleteShops(World world, BoundingBox box) {
deleteShops(world, box, null);
}
private void deleteShops(World world, BoundingBox box, UUID vendorUuid) {
if (!Config.enableBentoBoxIntegration)
return;
Collection<Shop> shops = plugin.getShopUtils().getShopsCopy();
for (Shop shop : shops) {
if (!shop.getLocation().getWorld().getName().equals(world.getName())) {
continue;
}
if (vendorUuid != null && !shop.getVendor().getUniqueId().equals(vendorUuid)) {
continue;
}
int x = shop.getLocation().getBlockX();
int z = shop.getLocation().getBlockZ();
if (box.contains(x, 0, z)) {
plugin.getShopUtils().removeShop(shop, true);
}
}
}
}

View File

@ -57,6 +57,7 @@ enable-authme-integration: true
enable-plotsquared-integration: true
enable-uskyblock-integration: true
enable-askyblock-integration: true
enable-bentobox-integration: true
enable-islandworld-integration: true
enable-griefprevention-integration: true
enable-areashop-integration: true

View File

@ -6,7 +6,7 @@ version: ${project.version}
author: EpicEric
website: ${project.url}
description: Create your own nice-looking chest shops and sell your stuff to other players!
softdepend: [WorldGuard, Towny, AuthMe, PlotSquared, uSkyBlock, ASkyBlock, IslandWorld, GriefPrevention, AreaShop, Multiverse-Core, MultiWorld]
softdepend: [WorldGuard, Towny, AuthMe, PlotSquared, uSkyBlock, ASkyBlock, IslandWorld, GriefPrevention, AreaShop, Multiverse-Core, MultiWorld, BentoBox]
depend: [Vault]
api-version: 1.13