Improved Towny integration

Closes #95
This commit is contained in:
Eric 2017-04-17 16:35:43 +02:00
parent bf6f24313b
commit dcea39ab9e
4 changed files with 78 additions and 13 deletions

View File

@ -33,6 +33,15 @@ public class Config {
/** The default value for the custom WorldGuard flag 'use-shop' **/ /** The default value for the custom WorldGuard flag 'use-shop' **/
public boolean wg_allow_use_shop_default; public boolean wg_allow_use_shop_default;
/** The types of town plots residents are allowed to create shops in **/
public List<String> towny_shop_plots_residents;
/** The types of town plots the mayor is allowed to create shops in **/
public List<String> towny_shop_plots_mayor;
/** The types of town plots the king is allowed to create shops in **/
public List<String> towny_shop_plots_king;
/** The hostname used in ShopChest's MySQL database **/ /** The hostname used in ShopChest's MySQL database **/
public String database_mysql_host; public String database_mysql_host;
@ -326,6 +335,9 @@ public class Config {
wg_allow_create_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.create-shop"); wg_allow_create_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.create-shop");
wg_allow_use_admin_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.use-admin-shop"); wg_allow_use_admin_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.use-admin-shop");
wg_allow_use_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.use-shop"); wg_allow_use_shop_default = plugin.getConfig().getBoolean("worldguard-default-flag-values.use-shop");
towny_shop_plots_residents = plugin.getConfig().getStringList("towny-shop-plots.residents");
towny_shop_plots_mayor = plugin.getConfig().getStringList("towny-shop-plots.mayor");
towny_shop_plots_king = plugin.getConfig().getStringList("towny-shop-plots.king");
database_mysql_ping_interval = plugin.getConfig().getInt("database.mysql.ping-interval"); database_mysql_ping_interval = plugin.getConfig().getInt("database.mysql.ping-interval");
database_mysql_host = plugin.getConfig().getString("database.mysql.hostname"); database_mysql_host = plugin.getConfig().getString("database.mysql.hostname");
database_mysql_port = plugin.getConfig().getInt("database.mysql.port"); database_mysql_port = plugin.getConfig().getInt("database.mysql.port");

View File

@ -1,12 +1,14 @@
package de.epiceric.shopchest.listeners; package de.epiceric.shopchest.listeners;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.object.TownyUniverse; import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.sk89q.worldguard.bukkit.RegionContainer; import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery; import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.external.WorldGuardShopFlag; import de.epiceric.shopchest.external.WorldGuardShopFlag;
import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LanguageUtils;
@ -43,11 +45,13 @@ public class ChestProtectListener implements Listener {
private ShopChest plugin; private ShopChest plugin;
private ShopUtils shopUtils; private ShopUtils shopUtils;
private Config config;
private WorldGuardPlugin worldGuard; private WorldGuardPlugin worldGuard;
public ChestProtectListener(ShopChest plugin, WorldGuardPlugin worldGuard) { public ChestProtectListener(ShopChest plugin, WorldGuardPlugin worldGuard) {
this.plugin = plugin; this.plugin = plugin;
this.shopUtils = plugin.getShopUtils(); this.shopUtils = plugin.getShopUtils();
this.config = plugin.getShopChestConfig();
this.worldGuard = worldGuard; this.worldGuard = worldGuard;
} }
@ -110,7 +114,7 @@ public class ChestProtectListener implements Listener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent e) { public void onEntityExplode(EntityExplodeEvent e) {
if (plugin.getShopChestConfig().explosion_protection) { if (config.explosion_protection) {
ArrayList<Block> bl = new ArrayList<>(e.blockList()); ArrayList<Block> bl = new ArrayList<>(e.blockList());
for (Block b : bl) { for (Block b : bl) {
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
@ -149,25 +153,41 @@ public class ChestProtectListener implements Listener {
boolean externalPluginsAllowed = true; boolean externalPluginsAllowed = true;
if (plugin.hasWorldGuard() && plugin.getShopChestConfig().enable_worldguard_integration) { if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
RegionContainer container = worldGuard.getRegionContainer(); RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery(); RegionQuery query = container.createQuery();
externalPluginsAllowed = query.testState(b.getLocation(), p, WorldGuardShopFlag.CREATE_SHOP); externalPluginsAllowed = query.testState(b.getLocation(), p, WorldGuardShopFlag.CREATE_SHOP);
} }
if (plugin.hasTowny() && plugin.getShopChestConfig().enable_towny_integration) { if (plugin.hasTowny() && config.enable_towny_integration) {
TownBlock townBlock = TownyUniverse.getTownBlock(b.getLocation()); TownBlock townBlock = TownyUniverse.getTownBlock(b.getLocation());
externalPluginsAllowed &= (townBlock != null && townBlock.getType() == TownBlockType.COMMERCIAL); if (townBlock != null) {
try {
Town town = townBlock.getTown();
for (Resident resident : town.getResidents()) {
if (resident.getName().equals(p.getName())) {
if (resident.isMayor()) {
externalPluginsAllowed &= (config.towny_shop_plots_mayor.contains(townBlock.getType().name()));
} else if (resident.isKing()) {
externalPluginsAllowed &= (config.towny_shop_plots_king.contains(townBlock.getType().name()));
} else {
externalPluginsAllowed &= (config.towny_shop_plots_residents.contains(townBlock.getType().name()));
}
}
}
} catch (Exception ignored) {
}
}
} }
if (plugin.hasPlotSquared() && plugin.getShopChestConfig().enable_plotsquared_integration) { if (plugin.hasPlotSquared() && config.enable_plotsquared_integration) {
com.intellectualcrafters.plot.object.Location loc = com.intellectualcrafters.plot.object.Location loc =
new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ()); new com.intellectualcrafters.plot.object.Location(b.getWorld().getName(), b.getX(), b.getY(), b.getZ());
externalPluginsAllowed &= Utils.isFlagAllowedOnPlot(loc.getOwnedPlot(), PlotSquaredShopFlag.CREATE_SHOP, p); externalPluginsAllowed &= Utils.isFlagAllowedOnPlot(loc.getOwnedPlot(), PlotSquaredShopFlag.CREATE_SHOP, p);
} }
if (plugin.hasUSkyBlock() && plugin.getShopChestConfig().enable_uskyblock_integration) { if (plugin.hasUSkyBlock() && config.enable_uskyblock_integration) {
IslandInfo islandInfo = plugin.getUSkyBlock().getIslandInfo(b.getLocation()); IslandInfo islandInfo = plugin.getUSkyBlock().getIslandInfo(b.getLocation());
externalPluginsAllowed &= islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName()); externalPluginsAllowed &= islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName());
} }
@ -212,7 +232,7 @@ public class ChestProtectListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemMove(InventoryMoveItemEvent e) { public void onItemMove(InventoryMoveItemEvent e) {
if (plugin.getShopChestConfig().hopper_protection) { if (config.hopper_protection) {
if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) { if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) {
if (e.getSource().getHolder() instanceof DoubleChest) { if (e.getSource().getHolder() instanceof DoubleChest) {

View File

@ -2,8 +2,9 @@ package de.epiceric.shopchest.listeners;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.object.TownyUniverse; import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.sk89q.worldguard.bukkit.RegionContainer; import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery; import com.sk89q.worldguard.bukkit.RegionQuery;
@ -126,7 +127,24 @@ public class ShopInteractListener implements Listener {
for (Location loc : chestLocations) { for (Location loc : chestLocations) {
if (loc != null) { if (loc != null) {
TownBlock townBlock = TownyUniverse.getTownBlock(loc); TownBlock townBlock = TownyUniverse.getTownBlock(loc);
externalPluginsAllowed &= (townBlock != null && townBlock.getType() == TownBlockType.COMMERCIAL); if (townBlock != null) {
try {
Town town = townBlock.getTown();
for (Resident resident : town.getResidents()) {
if (resident.getName().equals(p.getName())) {
if (resident.isMayor()) {
externalPluginsAllowed &= (config.towny_shop_plots_mayor.contains(townBlock.getType().name()));
} else if (resident.isKing()) {
externalPluginsAllowed &= (config.towny_shop_plots_king.contains(townBlock.getType().name()));
} else {
externalPluginsAllowed &= (config.towny_shop_plots_residents.contains(townBlock.getType().name()));
}
}
}
} catch (Exception ex) {
plugin.debug(ex);
}
}
} }
} }
} }

View File

@ -163,7 +163,7 @@ buy-greater-or-equal-sell: true
# Set the minimum prices for each individual Item. Not per Stack, per single Item! # Set the minimum prices for each individual Item. Not per Stack, per single Item!
# To add an item, follow the format below. # To add an item, follow the format below.
# Important: You must have exactly 2 spaces between the text and the edge. # Important: You must have exactly 2 leading spaces in each line
# You can find the item names in the 'item_names.txt' file. # You can find the item names in the 'item_names.txt' file.
minimum-prices: minimum-prices:
# "STONE:1": 0.5 # "STONE:1": 0.5
@ -171,7 +171,7 @@ minimum-prices:
# Set the maximum prices for each individual Item. Not per Stack, per single Item! # Set the maximum prices for each individual Item. Not per Stack, per single Item!
# To add an item, follow the format below. # To add an item, follow the format below.
# Important: You must have exactly 2 spaces between the text and the edge. # Important: You must have exactly 2 leading spaces in each line
# You can find the item names in the 'item_names.txt' file. # You can find the item names in the 'item_names.txt' file.
maximum-prices: maximum-prices:
# "STONE:1": 19.9 # "STONE:1": 19.9
@ -179,7 +179,7 @@ maximum-prices:
# Set the items of which a player can't create a shop. # Set the items of which a player can't create a shop.
# To add an item, follow the format below. # To add an item, follow the format below.
# Important: You must have exactly 2 spaces between the text and edge. # Important: You must have exactly 2 leading spaces in each line
# You can find the item names in the 'item_names.txt' file. # You can find the item names in the 'item_names.txt' file.
blacklist: blacklist:
# - "STONE:1" # - "STONE:1"
@ -195,6 +195,21 @@ worldguard-default-flag-values:
use-shop: false use-shop: false
use-admin-shop: false use-admin-shop: false
# Set the types of Towny plots where shop creation should be allowed for...
# Important: You must have exactly 4 leading spaces in each line
# Valid values are:
# RESIDENTIAL, COMMERCIAL, ARENA, EMBASSY, WILDS, SPLEEF, INN, JAIL, FARM
towny-shop-plots:
residents:
- "COMMERCIAL"
mayor:
- "COMMERCIAL"
king:
- "COMMERCIAL"
# Configuration of the database, where everything is stored. # Configuration of the database, where everything is stored.
# Shops are found in the table 'shop_list', and logged economy # Shops are found in the table 'shop_list', and logged economy
# transactions are found in the table 'shop_log' # transactions are found in the table 'shop_log'