- Fixed protections

This commit is contained in:
Acrobot 2011-07-02 20:34:14 +02:00
parent e522b33d9d
commit 0bde74f3ad
18 changed files with 72 additions and 67 deletions

View File

@ -1,7 +1,7 @@
package com.Acrobot.ChestShop.Chests;
import com.Acrobot.ChestShop.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Utils.BlockSearch;
import com.Acrobot.ChestShop.Utils.InventoryUtil;
import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

View File

@ -23,8 +23,8 @@ public class Config {
public static void setUp() {
config.load();
for (Property def : com.Acrobot.ChestShop.Config.Property.values()){
if(config.getProperty(def.name()) == null){
for (Property def : com.Acrobot.ChestShop.Config.Property.values()) {
if (config.getProperty(def.name()) == null) {
writeToFile(def.name() + ": " + def.getValue() + " #" + def.getComment(), configFile);
}
}
@ -49,19 +49,19 @@ public class Config {
}
}
public static boolean getBoolean(Property value){
public static boolean getBoolean(Property value) {
return (Boolean) getValue(value.name());
}
public static String getString(Property value){
public static String getString(Property value) {
return (String) getValue(value.name());
}
public static int getInteger(Property value){
public static int getInteger(Property value) {
return Integer.parseInt(getValue(value.name()).toString());
}
public static double getDouble(Property value){
public static double getDouble(Property value) {
return config.getDouble(value.name(), -1);
}

View File

@ -41,7 +41,7 @@ public enum Language {
SHOP_CREATED("Shop successfully created!"),
NO_PERMISSION("You don't have permissions to do that!"),
NAME_TOO_LONG ("Unfortunately, your name is too long :( Please wait for newer shop version!"),
NAME_TOO_LONG("Unfortunately, your name is too long :( Please wait for newer shop version!"),
INCORRECT_ITEM_ID("You have specified invalid item id!");

View File

@ -4,8 +4,8 @@ package com.Acrobot.ChestShop.Config;
* @author Acrobot
*/
public enum Property {
REVERSE_BUTTONS (false, "If true, people will buy with left-click and sell with right-click."),
SERVER_ECONOMY_ACCOUNT ("", "Economy account's name you want Admin Shops to be assigned to"),
REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."),
SERVER_ECONOMY_ACCOUNT("", "Economy account's name you want Admin Shops to be assigned to"),
LOG_TO_FILE(false, "If true, plugin will log transactions in its own file"),
LOG_TO_CONSOLE(true, "Do you want ChestShop's messages to show up in console?"),
USE_DATABASE(false, "If true, plugin will log transactions in EBean database"),
@ -13,11 +13,11 @@ public enum Property {
GENERATE_STATISTICS_PAGE(false, "If true, plugin will generate shop statistics webpage."),
STATISTICS_PAGE_PATH("plugins/ChestShop/website.html", "Where should your generated website be saved?"),
RECORD_TIME_TO_LIVE(600, "How long should transaction information be stored?"),
USE_BUILT_IN_PROTECTION(true, "Do you want to use built-in protection?"),
USE_BUILT_IN_PROTECTION(true, "Do you want to use built-in protection against chest destruction?"),
PROTECT_CHEST_WITH_LWC(false, "Do you want to protect shop chests with LWC?"),
PROTECT_SIGN_WITH_LWC(false, "Do you want to protect shop signs with LWC?");
private Object value;
private String comment;

View File

@ -10,17 +10,17 @@ import org.bukkit.material.*;
* @author Acrobot
*/
public class DataValue {
public static byte get(String arg, Material material){
if(material == null){
public static byte get(String arg, Material material) {
if (material == null) {
return 0;
}
arg = arg.toUpperCase().replace(" ", "_");
MaterialData materialData = null;
switch (material){
switch (material) {
case SAPLING:
case LOG:
materialData = new Tree(TreeSpecies.valueOf(arg));

View File

@ -41,14 +41,14 @@ public class Items {
Material mat;
String[] data = itemName.split(" ");
if(data.length >= 2){
if (data.length >= 2) {
mat = getMat(itemName.substring(itemName.indexOf(' ')));
byte argData = DataValue.get(data[0], mat);
if(argData != 0){
if (argData != 0) {
dataValue = argData;
}
} else{
} else {
mat = getMat(itemName);
}

View File

@ -24,14 +24,14 @@ public class blockBreak extends BlockListener {
return;
}
if(SignUtil.isSign(block)){
if (SignUtil.isSign(block)) {
Sign currentSign = (Sign) block.getState();
if(RestrictedSign.isRestricted(currentSign)){
if (RestrictedSign.isRestricted(currentSign)) {
event.setCancelled(true);
}
currentSign.update(true);
}
Sign sign = BlockSearch.findSign(block);
if (sign != null) {

View File

@ -44,8 +44,8 @@ public class playerInteract extends PlayerListener {
Block block = event.getClickedBlock();
if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) {
Default defProtection = new Default();
if (!Permission.has(player, Permission.ADMIN) && !Permission.has(player, Permission.MOD) && (defProtection.isProtected(block) && !defProtection.canAccess(player, block))) {
Default protection = new Default();
if (!Permission.has(player, Permission.ADMIN) && !Permission.has(player, Permission.MOD) && (protection.isProtected(block) && !protection.canAccess(player, block))) {
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
event.setCancelled(true);
return;
@ -93,8 +93,8 @@ public class playerInteract extends PlayerListener {
return;
}
if(RestrictedSign.isRestricted(sign)){
if(!RestrictedSign.canAccess(sign, player)){
if (RestrictedSign.isRestricted(sign)) {
if (!RestrictedSign.canAccess(sign, player)) {
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
return;
}

View File

@ -7,12 +7,12 @@ import org.bukkit.event.server.ServerListener;
/**
* @author Acrobot
*/
public class pluginDisable extends ServerListener{
public void onPluginDisable(PluginDisableEvent event){
if(Economy.economy != null && pluginEnable.methods.hasMethod()){
public class pluginDisable extends ServerListener {
public void onPluginDisable(PluginDisableEvent event) {
if (Economy.economy != null && pluginEnable.methods.hasMethod()) {
boolean check = pluginEnable.methods.checkDisabled(event.getPlugin());
if(check){
if (check) {
Economy.economy = null;
System.out.println("[ChestShop] Economy plugin disabled!");
}

View File

@ -54,7 +54,7 @@ public class pluginEnable extends ServerListener {
PluginDescriptionFile pDesc = lwcPlugin.getDescription();
LWCplugin.lwc = ((LWCPlugin) lwcPlugin).getLWC();
Security.protection = new LWCplugin();
System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
}
}

View File

@ -43,7 +43,7 @@ public class signChange extends BlockListener {
if (isAlmostReady) {
if(player.getName().length() > 15){
if (player.getName().length() > 15) {
player.sendMessage(Config.getLocal(Language.NAME_TOO_LONG));
dropSign(event);
return;
@ -54,24 +54,23 @@ public class signChange extends BlockListener {
return;
}
if (!(playerIsAdmin ||
Permission.has(player, Permission.SHOP_CREATION) ||
Permission.has(player, Permission.SHOP_CREATION) ||
(Permission.has(player, Permission.SHOP_CREATION + "." + mat.getId()) &&
!Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId()))))
{
!Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId())))) {
player.sendMessage(Config.getLocal(Language.YOU_CANNOT_CREATE_SHOP));
dropSign(event);
return;
}
} else {
if(RestrictedSign.isRestricted(event.getLines())){
if(!playerIsAdmin){
if (RestrictedSign.isRestricted(event.getLines())) {
if (!playerIsAdmin) {
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
dropSign(event);
return;
}
Block secondSign = signBlock.getFace(BlockFace.DOWN);
if(!SignUtil.isSign(secondSign) || !SignUtil.isValid((Sign) secondSign.getState())){
if (!SignUtil.isSign(secondSign) || !SignUtil.isValid((Sign) secondSign.getState())) {
dropSign(event);
}
}
@ -121,29 +120,36 @@ public class signChange extends BlockListener {
dropSign(event);
return;
} else if (!playerIsAdmin) {
boolean canPlaceSign = Security.canPlaceSign(player, signBlock);
if (!canPlaceSign) {
if (!Security.canPlaceSign(player, signBlock)) {
player.sendMessage(Config.getLocal(Language.ANOTHER_SHOP_DETECTED));
dropSign(event);
return;
}
Default protection = new Default();
boolean canAccess = true;
Block chestBlock = chest.getBlock();
if(Security.isProtected(chestBlock) || protection.isProtected(chestBlock)){
if(!Security.canAccess(player, chestBlock) || !protection.canAccess(player, chestBlock)){
player.sendMessage(Config.getLocal(Language.CANNOT_ACCESS_THE_CHEST));
dropSign(event);
return;
if (Security.isProtected(chestBlock) && !Security.canAccess(player, chestBlock)) {
canAccess = false;
}
if (!(Security.protection instanceof Default)) {
Default protection = new Default();
if (protection.isProtected(chestBlock) && !protection.canAccess(player, chestBlock)) {
canAccess = false;
}
}
if (!canAccess) {
player.sendMessage(Config.getLocal(Language.CANNOT_ACCESS_THE_CHEST));
dropSign(event);
return;
}
}
}
if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && chest != null && Security.protect(player.getName(), chest.getBlock())) {
if(Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)){
if (Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)) {
Security.protect(player.getName(), signBlock);
}
player.sendMessage(Config.getLocal(Language.PROTECTED_SHOP));

View File

@ -12,17 +12,17 @@ import org.bukkit.entity.Player;
*/
public class Default implements Protection {
public boolean isProtected(Block block) {
if((SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())) || BlockSearch.findSign(block) != null){
if ((SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())) || BlockSearch.findSign(block) != null) {
return true;
} else {
if(!(block.getState() instanceof Chest)){
if (!(block.getState() instanceof Chest)) {
return false;
}
if(BlockSearch.findSign(block) != null){
if (BlockSearch.findSign(block) != null) {
return true;
}
Chest neighbor = BlockSearch.findNeighbor(block);
if(neighbor != null && BlockSearch.findSign(neighbor.getBlock()) != null){
if (neighbor != null && BlockSearch.findSign(neighbor.getBlock()) != null) {
return true;
}
}

View File

@ -11,18 +11,18 @@ import org.bukkit.entity.Player;
* @author Acrobot
*/
public class RestrictedSign {
public static boolean isRestricted(Sign sign){
public static boolean isRestricted(Sign sign) {
Block blockUp = sign.getBlock().getFace(BlockFace.UP);
return SignUtil.isSign(blockUp) && isRestricted(((Sign) blockUp.getState()).getLines());
}
public static boolean isRestricted(String[] lines){
public static boolean isRestricted(String[] lines) {
return lines[0].equalsIgnoreCase("[restricted]");
}
public static boolean canAccess(Sign sign, Player player){
public static boolean canAccess(Sign sign, Player player) {
Block blockUp = sign.getBlock().getFace(BlockFace.UP);
if(Permission.permissions == null || !SignUtil.isSign(blockUp) || Permission.has(player, Permission.ADMIN)){
if (Permission.permissions == null || !SignUtil.isSign(blockUp) || Permission.has(player, Permission.ADMIN)) {
return true;
}
String world = blockUp.getWorld().getName();
@ -31,7 +31,7 @@ public class RestrictedSign {
sign = (Sign) blockUp.getState();
boolean result = false;
for(int i = 1; i <= 3; i++){
for (int i = 1; i <= 3; i++) {
result = result || Permission.permissions.inGroup(world, playerName, sign.getLine(i));
}
return result;

View File

@ -45,7 +45,7 @@ public class Shop {
player.sendMessage(Config.getLocal(Language.NO_BUYING_HERE));
return false;
}
if(!Permission.has(player, Permission.BUY)){
if (!Permission.has(player, Permission.BUY)) {
player.sendMessage(Config.getLocal(Language.NO_PERMISSION));
return false;
}
@ -104,7 +104,7 @@ public class Shop {
player.sendMessage(Config.getLocal(Language.NO_SELLING_HERE));
return false;
}
if(!Permission.has(player, Permission.SELL)){
if (!Permission.has(player, Permission.SELL)) {
player.sendMessage(Config.getLocal(Language.NO_PERMISSION));
return false;
}

View File

@ -16,7 +16,7 @@ public class ShopManagement {
public static boolean buy(Sign sign, Player player) {
Chest chestMc = BlockSearch.findChest(sign);
ItemStack item = Items.getItemStack(sign.getLine(3));
if(item == null){
if (item == null) {
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");
return false;
}
@ -28,7 +28,7 @@ public class ShopManagement {
public static boolean sell(Sign sign, Player player) {
Chest chestMc = BlockSearch.findChest(sign);
ItemStack item = Items.getItemStack(sign.getLine(3));
if(item == null){
if (item == null) {
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");
return false;
}

View File

@ -52,7 +52,7 @@ public class BlockSearch {
return null; //Shame, we didn't find double chest :/
}
public static Chest findNeighbor(Chest chest){
public static Chest findNeighbor(Chest chest) {
return findNeighbor(chest.getBlock());
}
}

View File

@ -17,7 +17,7 @@ public class InventoryUtil {
Material itemMaterial = item.getType();
int first = inv.first(itemMaterial);
if(first == -1){
if (first == -1) {
return amount;
}
@ -52,7 +52,7 @@ public class InventoryUtil {
public static int add(Inventory inv, ItemStack item, int amount) {
amount = (amount > 0 ? amount : 1);
Material itemMaterial = item.getType();
int maxStackSize = itemMaterial.getMaxStackSize();
@ -84,10 +84,9 @@ public class InventoryUtil {
public static int amount(Inventory inv, ItemStack item, short durability) {
int amount = 0;
if(!inv.contains(item.getType())){
if (!inv.contains(item.getType())) {
return amount;
}
ItemStack[] contents = inv.getContents();
for (ItemStack i : contents) {
if (i != null) {

View File

@ -3,7 +3,7 @@ name: ChestShop
main: com.Acrobot.ChestShop.ChestShop
database: true
version: 3.00 BETA 6
version: 3.00 BETA 7
author: Acrobot