Added towny support

- Players can only create shops in shop plots, not in wilderness or normal
  plots
- Added permission "shopchest.extend.protected"
- Changed permission "shopchest.extendOther" to "shopchest.extend.other"
- When creating a shop on a double chest, both chests must not be
  protected/in a protected region
- To extend a shop into a protected region (e.g. WorldGuard/Towny), you
  need permission (shopchest.extend.protected)
- Added no-permission message for "shopchest.extend.protected"
This commit is contained in:
Eric 2016-11-20 14:15:53 +01:00
parent dcd50bad33
commit 04a6d836b9
10 changed files with 119 additions and 21 deletions

10
pom.xml
View File

@ -46,6 +46,10 @@
<id>sk89q-repo</id> <id>sk89q-repo</id>
<url>http://maven.sk89q.com/artifactory/repo/</url> <url>http://maven.sk89q.com/artifactory/repo/</url>
</repository> </repository>
<repository>
<id>epiceric-repo</id>
<url>http://epicericee.github.io/ShopChest/maven/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -67,6 +71,12 @@
<version>6.1.1-SNAPSHOT</version> <version>6.1.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.palmergames</groupId>
<artifactId>Towny</artifactId>
<version>0.91.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<distributionManagement> <distributionManagement>

View File

@ -1,5 +1,6 @@
package de.epiceric.shopchest; package de.epiceric.shopchest;
import com.palmergames.bukkit.towny.Towny;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.Regex; import de.epiceric.shopchest.config.Regex;
@ -44,6 +45,7 @@ public class ShopChest extends JavaPlugin {
private ShopUtils shopUtils; private ShopUtils shopUtils;
private FileWriter fw; private FileWriter fw;
private WorldGuardPlugin worldGuard; private WorldGuardPlugin worldGuard;
private Towny towny;
/** /**
* @return An instance of ShopChest * @return An instance of ShopChest
@ -137,6 +139,11 @@ public class ShopChest extends JavaPlugin {
} }
} }
Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny");
if (townyPlugin instanceof Towny) {
towny = (Towny) townyPlugin;
}
debug("Loading utils and extras..."); debug("Loading utils and extras...");
LanguageUtils.load(); LanguageUtils.load();
@ -292,7 +299,7 @@ public class ShopChest extends JavaPlugin {
getServer().getPluginManager().registerEvents(new ShopItemListener(this), this); getServer().getPluginManager().registerEvents(new ShopItemListener(this), this);
getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this); getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this);
getServer().getPluginManager().registerEvents(new NotifyUpdateOnJoinListener(this), this); getServer().getPluginManager().registerEvents(new NotifyUpdateOnJoinListener(this), this);
getServer().getPluginManager().registerEvents(new ChestProtectListener(this), this); getServer().getPluginManager().registerEvents(new ChestProtectListener(this, worldGuard), this);
if (!Utils.getServerVersion().equals("v1_8_R1")) if (!Utils.getServerVersion().equals("v1_8_R1"))
getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this); getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this);
@ -373,6 +380,20 @@ public class ShopChest extends JavaPlugin {
debug("Initialized " + count + " Shops"); debug("Initialized " + count + " Shops");
} }
/**
* @return Whether the plugin 'Towny' is enabled
*/
public boolean hasTowny() {
return towny != null;
}
/**
* @return An instance of {@link Towny} or {@code null} if Towny is not enabled
*/
public Towny getTowny() {
return towny;
}
/** /**
* @return Whether the plugin 'WorldGuard' is enabled * @return Whether the plugin 'WorldGuard' is enabled
*/ */

View File

@ -969,6 +969,7 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_UPDATE, langConfig.getString("message.noPermission.update", "&cYou don't have permission to check for updates."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_UPDATE, langConfig.getString("message.noPermission.update", "&cYou don't have permission to check for updates.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG, langConfig.getString("message.noPermission.config", "&cYou don't have permission to change configuration values."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG, langConfig.getString("message.noPermission.config", "&cYou don't have permission to change configuration values.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS, langConfig.getString("message.noPermission.extend-others", "&cYou don't have permission to extend this chest."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS, langConfig.getString("message.noPermission.extend-others", "&cYou don't have permission to extend this chest.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_PROTECTED, langConfig.getString("message.noPermission.extend-protected", "&cYou don't have permission to extend this chest to here.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_INFO, langConfig.getString("message.commandDescription.info", "Retrieve shop information."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_INFO, langConfig.getString("message.commandDescription.info", "Retrieve shop information.")));

View File

@ -115,6 +115,7 @@ public class LocalizedMessage {
NO_PERMISSION_UPDATE, NO_PERMISSION_UPDATE,
NO_PERMISSION_CONFIG, NO_PERMISSION_CONFIG,
NO_PERMISSION_EXTEND_OTHERS, NO_PERMISSION_EXTEND_OTHERS,
NO_PERMISSION_EXTEND_PROTECTED,
COMMAND_DESC_CREATE, COMMAND_DESC_CREATE,
COMMAND_DESC_REMOVE, COMMAND_DESC_REMOVE,
COMMAND_DESC_INFO, COMMAND_DESC_INFO,

View File

@ -1,11 +1,18 @@
package de.epiceric.shopchest.listeners; package de.epiceric.shopchest.listeners;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage; import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.Permissions; import de.epiceric.shopchest.utils.Permissions;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.worldguard.ShopFlag;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -29,10 +36,12 @@ public class ChestProtectListener implements Listener {
private ShopChest plugin; private ShopChest plugin;
private ShopUtils shopUtils; private ShopUtils shopUtils;
private WorldGuardPlugin worldGuard;
public ChestProtectListener(ShopChest plugin) { public ChestProtectListener(ShopChest plugin, WorldGuardPlugin worldGuard) {
this.plugin = plugin; this.plugin = plugin;
this.shopUtils = plugin.getShopUtils(); this.shopUtils = plugin.getShopUtils();
this.worldGuard = worldGuard;
} }
@EventHandler @EventHandler
@ -124,7 +133,22 @@ public class ChestProtectListener implements Listener {
plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
boolean externalPluginsAllowed = true;
if (plugin.hasWorldGuard()) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
externalPluginsAllowed = query.testState(b.getLocation(), p, ShopFlag.CREATE_SHOP);
}
if (plugin.hasTowny()) {
TownBlock townBlock = TownyUniverse.getTownBlock(b.getLocation());
externalPluginsAllowed &= (townBlock != null && townBlock.getType() == TownBlockType.COMMERCIAL);
}
if (externalPluginsAllowed || p.hasPermission(Permissions.EXTEND_PROTECTED)) {
if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.EXTEND_OTHER)) { if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.EXTEND_OTHER)) {
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
shopUtils.removeShop(shop, true); shopUtils.removeShop(shop, true);
Shop newShop = new Shop(shop.getID(), ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); Shop newShop = new Shop(shop.getID(), ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());
@ -138,6 +162,11 @@ public class ChestProtectListener implements Listener {
e.setCancelled(true); e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS)); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS));
} }
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_PROTECTED));
}
} }
} }

View File

@ -1,5 +1,8 @@
package de.epiceric.shopchest.listeners; package de.epiceric.shopchest.listeners;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownBlockType;
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;
@ -30,6 +33,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -41,10 +45,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.*;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion; import org.bukkit.potion.Potion;
@ -82,15 +83,38 @@ public class ShopInteractListener implements Listener {
if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) { if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) {
if (!shopUtils.isShop(b.getLocation())) { if (!shopUtils.isShop(b.getLocation())) {
boolean worldGuardAllowed = true; boolean externalPluginsAllowed = true;
Location[] chestLocations = {b.getLocation(), null};
InventoryHolder ih = ((Chest) b.getState()).getInventory().getHolder();
if (ih instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) ih;
chestLocations[0] = ((Chest) dc.getLeftSide()).getLocation();
chestLocations[1] = ((Chest) dc.getRightSide()).getLocation();
}
if (plugin.hasWorldGuard()) { if (plugin.hasWorldGuard()) {
RegionContainer container = worldGuard.getRegionContainer(); RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery(); RegionQuery query = container.createQuery();
worldGuardAllowed = query.testState(b.getLocation(), p, ShopFlag.CREATE_SHOP);
for (Location loc : chestLocations) {
if (loc != null) {
externalPluginsAllowed &= query.testState(loc, p, ShopFlag.CREATE_SHOP);
}
}
} }
if ((e.isCancelled() || !worldGuardAllowed) && !p.hasPermission(Permissions.CREATE_PROTECTED)) { if (plugin.hasTowny()) {
for (Location loc : chestLocations) {
if (loc != null) {
TownBlock townBlock = TownyUniverse.getTownBlock(loc);
externalPluginsAllowed &= (townBlock != null && townBlock.getType() == TownBlockType.COMMERCIAL);
}
}
}
if ((e.isCancelled() || !externalPluginsAllowed) && !p.hasPermission(Permissions.CREATE_PROTECTED)) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED));
ClickType.removePlayerClickType(p); ClickType.removePlayerClickType(p);
plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest"); plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest");

View File

@ -14,6 +14,7 @@ public class Permissions {
public static final String UPDATE = "shopchest.update"; public static final String UPDATE = "shopchest.update";
public static final String NO_LIMIT = "shopchest.limit.*"; public static final String NO_LIMIT = "shopchest.limit.*";
public static final String CONFIG = "shopchest.config"; public static final String CONFIG = "shopchest.config";
public static final String EXTEND_OTHER = "shopchest.extendOther"; public static final String EXTEND_OTHER = "shopchest.extend.other";
public static final String EXTEND_PROTECTED = "shopchest.extend.protected";
} }

View File

@ -71,6 +71,7 @@ message.noPermission.reload=&cDu hast keine Berechtigung die Shops neu zu laden.
message.noPermission.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen. message.noPermission.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen.
message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern. message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern.
message.noPermission.extend-others=&cDu hast keine Berechtigung diesen Shop zu erweitern. message.noPermission.extend-others=&cDu hast keine Berechtigung diesen Shop zu erweitern.
message.noPermission.extend-protected=&cDu hast keine Berechtigung diesen Shop nach hier zu erweitern.
message.commandDescription.create=Erstelle einen Shop. message.commandDescription.create=Erstelle einen Shop.
message.commandDescription.remove=Entferne einen Shop. message.commandDescription.remove=Entferne einen Shop.
message.commandDescription.info=Rufe Informationen über den Shop ab. message.commandDescription.info=Rufe Informationen über den Shop ab.

View File

@ -247,6 +247,9 @@ message.noPermission.config=&cYou don't have permission to change configuration
# Set the message when a not permitted player tries to extend another player's shop's chest. # Set the message when a not permitted player tries to extend another player's shop's chest.
message.noPermission.extend-others=&cYou don't have permission to extend this chest. message.noPermission.extend-others=&cYou don't have permission to extend this chest.
# Set the message when a not permitted player tries to extend a chest into a protected region (e.g. WorldGuard/Towny).
message.noPermission.extend-protected=&cYou don't have permission to extend this chest to here.
# Set the command description message for '/shop create' when you type '/shop'. # Set the command description message for '/shop create' when you type '/shop'.
message.commandDescription.create=Create a shop. message.commandDescription.create=Create a shop.

View File

@ -5,7 +5,7 @@ main: de.epiceric.shopchest.ShopChest
version: ${project.version} version: ${project.version}
author: EpicEric author: EpicEric
website: ${project.url} website: ${project.url}
softdepend: [WorldGuard] softdepend: [WorldGuard, Towny]
depend: [Vault] depend: [Vault]
permissions: permissions:
@ -13,6 +13,8 @@ permissions:
description: Gives access to all ShopChest permissions. description: Gives access to all ShopChest permissions.
children: children:
shopchest.create: true shopchest.create: true
shopchest.create.admin: true
shopchest.create.protected: true
shopchest.removeOther: true shopchest.removeOther: true
shopchest.buy: true shopchest.buy: true
shopchest.openOther: true shopchest.openOther: true
@ -21,6 +23,8 @@ permissions:
shopchest.update: true shopchest.update: true
shopchest.limit.*: true shopchest.limit.*: true
shopchest.config: true shopchest.config: true
shopchest.extend.other: true
shopchest.extend.protected: true
shopchest.create: shopchest.create:
description: Allows you to create a shop. description: Allows you to create a shop.
default: true default: true
@ -30,7 +34,7 @@ permissions:
shopchest.create: true shopchest.create: true
default: op default: op
shopchest.create.protected: shopchest.create.protected:
description: Allows you to create a shop on a protected chest. description: Allows you to create a shop on a protected chest or in a protected region.
children: children:
shopchest.create: true shopchest.create: true
default: op default: op
@ -60,6 +64,9 @@ permissions:
shopchest.config: shopchest.config:
description: Allows you to change configuration values per command. description: Allows you to change configuration values per command.
default: op default: op
shopchest.extendOther: shopchest.extend.other:
description: Allows you to extend other players' shops. description: Allows you to extend other players' shops.
default: op default: op
shopchest.extend.protected:
description: Allows you to extend shops into a protected region.
default: op