mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 18:45:31 +01:00
- Reformatted code
- Switched from YamlConfiguration to BreezeConfiguration (from ChestShop 4) - Fixed getDouble() - Instead of checking for Admin Shops, we just pass in a new AdminShop Container - Created events for shop creation, protection checks and protection creation - Expanded string data value parsing, for example - you can use "Ocelot Monster" on the sign - Collected all external plugin wrappers in a single folder - Instead of using statics, now we use objects - Fixed enchantments for armour - Made config more readable - Added a setting for removing empty shops - Switched from System.out to logger - Also, switched from ugly file logging to Java's native one (FileHandler) - Added an option to tax transactions even when SERVER_ECONOMY_ACCOUNT is empty - Changed the Container interface
This commit is contained in:
parent
e28548d534
commit
f1ee558e3a
@ -3,27 +3,28 @@ package com.Acrobot.ChestShop;
|
||||
import com.Acrobot.ChestShop.Commands.ItemInfo;
|
||||
import com.Acrobot.ChestShop.Commands.Version;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.ConfigObject;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.DB.Generator;
|
||||
import com.Acrobot.ChestShop.DB.Queue;
|
||||
import com.Acrobot.ChestShop.DB.Transaction;
|
||||
import com.Acrobot.ChestShop.Listeners.*;
|
||||
import com.Acrobot.ChestShop.Logging.FileWriterQueue;
|
||||
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
||||
import com.Acrobot.ChestShop.Utils.uNumber;
|
||||
import com.Acrobot.ChestShop.Logging.FileFormatter;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.lennardf1989.bukkitex.Database;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Main file of the plugin
|
||||
@ -31,38 +32,49 @@ import java.util.List;
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ChestShop extends JavaPlugin {
|
||||
public static File dataFolder = new File("plugins/ChestShop");
|
||||
|
||||
public static File folder = new File("plugins/ChestShop");
|
||||
public static final String chatPrefix = "[ChestShop] ";
|
||||
private static EbeanServer DB;
|
||||
|
||||
private static PluginDescriptionFile description;
|
||||
private static Server server;
|
||||
private static Logger logger;
|
||||
private static PluginManager pluginManager;
|
||||
private static ChestShop plugin;
|
||||
|
||||
public static PluginManager pm;
|
||||
private FileHandler handler;
|
||||
|
||||
public void onEnable() {
|
||||
pm = getServer().getPluginManager();
|
||||
folder = getDataFolder();
|
||||
plugin = this;
|
||||
logger = getLogger();
|
||||
pluginManager = getServer().getPluginManager();
|
||||
dataFolder = getDataFolder();
|
||||
description = getDescription();
|
||||
server = getServer();
|
||||
|
||||
//Set up our config file!
|
||||
Config.setup(new ConfigObject());
|
||||
Config.setup();
|
||||
Dependencies.load();
|
||||
|
||||
//Register our events
|
||||
registerEvents();
|
||||
|
||||
description = this.getDescription(); //Description of the plugin
|
||||
server = getServer(); //Setting out server variable
|
||||
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) {
|
||||
setupDB();
|
||||
}
|
||||
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) {
|
||||
File htmlFolder = new File(dataFolder, "HTML");
|
||||
scheduleTask(new Generator(htmlFolder), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
|
||||
}
|
||||
if (Config.getBoolean(Property.LOG_TO_FILE)) {
|
||||
File log = loadFile(new File(ChestShop.getFolder(), "ChestShop.log"));
|
||||
|
||||
pluginEnable.initializePlugins();
|
||||
FileHandler handler = loadHandler(log.getAbsolutePath());
|
||||
handler.setFormatter(new FileFormatter());
|
||||
|
||||
warnAboutSpawnProtection();
|
||||
warnAboutOldBukkit();
|
||||
|
||||
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) setupDB();
|
||||
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) scheduleTask(new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
|
||||
if (Config.getBoolean(Property.LOG_TO_FILE)) scheduleTask(new FileWriterQueue(), 201L, 201L);
|
||||
playerInteract.interval = Config.getInteger(Property.SHOP_INTERACTION_INTERVAL);
|
||||
this.handler = handler;
|
||||
logger.addHandler(handler);
|
||||
}
|
||||
if (!Config.getBoolean(Property.LOG_TO_CONSOLE)) {
|
||||
logger.setUseParentHandlers(false);
|
||||
}
|
||||
|
||||
//Register our commands!
|
||||
getCommand("iteminfo").setExecutor(new ItemInfo());
|
||||
@ -72,19 +84,50 @@ public class ChestShop extends JavaPlugin {
|
||||
startStatistics();
|
||||
}
|
||||
|
||||
private static File loadFile(File file) {
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
private static FileHandler loadHandler(String path) {
|
||||
FileHandler handler = null;
|
||||
|
||||
try {
|
||||
handler = new FileHandler(path, true);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
|
||||
if (handler != null) {
|
||||
handler.close();
|
||||
getLogger().removeHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////// REGISTER EVENTS, SCHEDULER & STATS ///////////////////////////
|
||||
private void registerEvents() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
registerEvent(new BlockBreak());
|
||||
registerEvent(new BlockPlace());
|
||||
registerEvent(new SignChange());
|
||||
registerEvent(new PlayerInteract(Config.getInteger(Property.SHOP_INTERACTION_INTERVAL)));
|
||||
registerEvent(new EntityExplode());
|
||||
}
|
||||
|
||||
pm.registerEvents(new blockBreak(), this);
|
||||
pm.registerEvents(new blockPlace(), this);
|
||||
pm.registerEvents(new signChange(), this);
|
||||
pm.registerEvents(new playerInteract(), this);
|
||||
pm.registerEvents(new entityExplode(), this);
|
||||
public void registerEvent(Listener listener) {
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
}
|
||||
|
||||
private void scheduleTask(Runnable runnable, long startTime, long repetetionTime) {
|
||||
@ -94,23 +137,8 @@ public class ChestShop extends JavaPlugin {
|
||||
private void startStatistics() {
|
||||
try {
|
||||
new Metrics(this).start();
|
||||
} catch (Exception ex) {
|
||||
System.err.println(chatPrefix + "There was an error while submitting statistics.");
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////// WARN ///////////////////////////
|
||||
private static void warnAboutSpawnProtection() {
|
||||
if (getBukkitConfig().getInt("settings.spawn-radius") > 0)
|
||||
System.err.println(ChestShop.chatPrefix + "WARNING! Your spawn-radius in bukkit.yml isn't set to 0! " +
|
||||
"You won't be able to sell to shops built near spawn!");
|
||||
}
|
||||
|
||||
private static void warnAboutOldBukkit() {
|
||||
String split[] = Bukkit.getBukkitVersion().split("-R");
|
||||
if (split[0].equals("1.1") && split.length > 1 && uNumber.isInteger(split[1]) && (Integer.parseInt(split[1])) < 7) {
|
||||
System.err.println(ChestShop.chatPrefix + "Your CraftBukkit version is outdated! Use at least 1.1-R7 or 1.2.3-R0!");
|
||||
ShopManagement.useOldChest = true;
|
||||
} catch (IOException ex) {
|
||||
ChestShop.getBukkitLogger().severe("There was an error while submitting statistics.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,6 +178,14 @@ public class ChestShop extends JavaPlugin {
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static File getFolder() {
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
public static Logger getBukkitLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static Server getBukkitServer() {
|
||||
return server;
|
||||
}
|
||||
@ -167,6 +203,18 @@ public class ChestShop extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static List getDependencies() {
|
||||
return (List) description.getSoftDepend();
|
||||
return description.getSoftDepend();
|
||||
}
|
||||
|
||||
public static PluginManager getPluginManager() {
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
public static void registerListener(Listener listener) {
|
||||
plugin.registerEvent(listener);
|
||||
}
|
||||
|
||||
public static void callEvent(Event event) {
|
||||
pluginManager.callEvent(event);
|
||||
}
|
||||
}
|
||||
|
@ -42,25 +42,35 @@ public class ItemInfo implements CommandExecutor {
|
||||
|
||||
Map<Enchantment, Integer> map = item.getEnchantments();
|
||||
for (Map.Entry<Enchantment, Integer> e : map.entrySet())
|
||||
sender.sendMessage(ChatColor.DARK_GRAY + uSign.capitalizeFirst(e.getKey().getName()) + ' ' + intToRoman(e.getValue()));
|
||||
sender.sendMessage(ChatColor.DARK_GRAY + uSign.capitalizeFirstLetter(e.getKey().getName()) + ' ' + intToRoman(e.getValue()));
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static String intToRoman(int integer) {
|
||||
if (integer == 1) return "I";
|
||||
if (integer == 2) return "II";
|
||||
if (integer == 3) return "III";
|
||||
if (integer == 4) return "IV";
|
||||
if (integer == 5) return "V";
|
||||
switch (integer) {
|
||||
case 1:
|
||||
return "I";
|
||||
case 2:
|
||||
return "II";
|
||||
case 3:
|
||||
return "III";
|
||||
case 4:
|
||||
return "IV";
|
||||
case 5:
|
||||
return "V";
|
||||
default:
|
||||
return Integer.toString(integer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String joinArray(String[] array) {
|
||||
StringBuilder b = new StringBuilder(array.length);
|
||||
for (String s : array) b.append(s).append(' ');
|
||||
for (String s : array) {
|
||||
b.append(s).append(' ');
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.Acrobot.ChestShop.Commands;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.ConfigObject;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -14,10 +13,11 @@ import org.bukkit.command.CommandSender;
|
||||
public class Version implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args.length > 0 && args[0].equals("reload")) {
|
||||
Config.config = new ConfigObject();
|
||||
Config.setup();
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "The config was reloaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.GRAY + ChestShop.getPluginName() + "'s version is: " + ChatColor.GREEN + ChestShop.getVersion());
|
||||
return true;
|
||||
}
|
||||
|
154
com/Acrobot/ChestShop/Config/BreezeConfiguration.java
Normal file
154
com/Acrobot/ChestShop/Config/BreezeConfiguration.java
Normal file
@ -0,0 +1,154 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class BreezeConfiguration extends YamlConfiguration {
|
||||
protected final File file;
|
||||
protected final Map<String, Value> defaultValues = new LinkedHashMap<String, Value>();
|
||||
|
||||
protected BreezeConfiguration(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds default values for the config
|
||||
*
|
||||
* @param map The default values to add
|
||||
*/
|
||||
public void addDefaultValues(Map<String, ? extends Value> map) {
|
||||
defaultValues.putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BreezeConfiguration object
|
||||
*
|
||||
* @param file file to load config from
|
||||
* @return BreezeConfiguration object
|
||||
*/
|
||||
public static BreezeConfiguration loadConfiguration(File file) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
}
|
||||
|
||||
BreezeConfiguration config = new BreezeConfiguration(file);
|
||||
|
||||
config.load();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BreezeConfiguration object
|
||||
*
|
||||
* @param file file to load config from
|
||||
* @param defaults default values
|
||||
* @return BreezeConfiguration object
|
||||
*/
|
||||
public static BreezeConfiguration loadConfiguration(File file, Map<String, Value> defaults) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
}
|
||||
|
||||
BreezeConfiguration config = new BreezeConfiguration(file);
|
||||
|
||||
config.addDefaultValues(defaults);
|
||||
|
||||
config.load();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the config
|
||||
*/
|
||||
public void load() {
|
||||
try {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdir();
|
||||
}
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
super.load(file);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (createDefaultValues()) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads (saves and loads) the config
|
||||
*/
|
||||
public void reload() {
|
||||
save();
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates default values
|
||||
*
|
||||
* @return were any values added?
|
||||
*/
|
||||
private boolean createDefaultValues() {
|
||||
boolean changed = false;
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||
|
||||
for (Map.Entry<String, Value> entry : defaultValues.entrySet()) {
|
||||
if (this.contains(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
bw.write('\n' + entry.getKey() + ": " + entry.getValue().retrieveValue());
|
||||
}
|
||||
|
||||
bw.close();
|
||||
|
||||
if (changed) {
|
||||
load();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the config
|
||||
*/
|
||||
public void save() {
|
||||
try {
|
||||
super.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,26 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import com.nijikokun.register.payment.forChestShop.Methods;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Config {
|
||||
public static ConfigObject config;
|
||||
public static BreezeConfiguration normalConfig;
|
||||
public static BreezeConfiguration languageConfig;
|
||||
|
||||
public static void setup() {
|
||||
File configFolder = ChestShop.getFolder();
|
||||
|
||||
normalConfig = BreezeConfiguration.loadConfiguration(new File(configFolder, "config.yml"), Property.getValues());
|
||||
languageConfig = BreezeConfiguration.loadConfiguration(new File(configFolder, "local.yml"), Language.getValues());
|
||||
|
||||
uName.config = BreezeConfiguration.loadConfiguration(new File(configFolder, "longName.storage"));
|
||||
|
||||
public static void setup(ConfigObject cfg) {
|
||||
config = cfg;
|
||||
Methods.setPreferred(Config.getString(Property.PREFERRED_ECONOMY_PLUGIN));
|
||||
}
|
||||
|
||||
@ -34,19 +45,19 @@ public class Config {
|
||||
}
|
||||
|
||||
public static double getDouble(Property value) {
|
||||
return getDouble(getValue(value.name()).toString());
|
||||
return getDouble(value.name());
|
||||
}
|
||||
|
||||
public static double getDouble(String value) {
|
||||
return Double.parseDouble(getValue(value).toString());
|
||||
return new Double(getValue(value).toString());
|
||||
}
|
||||
|
||||
private static String getColored(String msg) {
|
||||
return msg.replaceAll("&([0-9a-f])", "\u00A7$1");
|
||||
return msg.replaceAll("&([0-9a-fk-or])", "\u00A7$1");
|
||||
}
|
||||
|
||||
public static String getLocal(Language lang) {
|
||||
return getColored(config.getLanguageConfig().getString(Language.prefix.name()) + config.getLanguageConfig().getString(lang.name()));
|
||||
return getColored(languageConfig.getString(Language.prefix.name()) + languageConfig.getString(lang.name()));
|
||||
}
|
||||
|
||||
public static boolean exists(String value) {
|
||||
@ -54,6 +65,6 @@ public class Config {
|
||||
}
|
||||
|
||||
private static Object getValue(String node) {
|
||||
return config.getProperty(node);
|
||||
return normalConfig.get(node);
|
||||
}
|
||||
}
|
||||
|
@ -1,88 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ConfigObject {
|
||||
private final File configFile = new File(ChestShop.folder, "config.yml");
|
||||
private final File langFile = new File(ChestShop.folder, "local.yml");
|
||||
private final YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
private final YamlConfiguration language = YamlConfiguration.loadConfiguration(langFile);
|
||||
|
||||
public ConfigObject() {
|
||||
if (!ChestShop.folder.exists()) ChestShop.folder.mkdir();
|
||||
|
||||
reloadConfig();
|
||||
load(config, configFile);
|
||||
|
||||
reloadLanguage();
|
||||
load(language, langFile);
|
||||
|
||||
uLongName.configFile = new File(ChestShop.folder, "longName.storage");
|
||||
uLongName.config = YamlConfiguration.loadConfiguration(uLongName.configFile);
|
||||
}
|
||||
|
||||
private void reloadConfig() {
|
||||
for (Property def : Property.values()) {
|
||||
if (config.get(def.name()) == null) {
|
||||
writeToFile('\n' + def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadLanguage() {
|
||||
for (Language def : Language.values()) {
|
||||
if (language.get(def.name()) == null) {
|
||||
writeToFile('\n' + def.name() + ": \"" + def.toString() + '\"', langFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeToFile(String string, File file) {
|
||||
try {
|
||||
FileWriter fw = new FileWriter(file, true);
|
||||
fw.write(string);
|
||||
fw.close();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Couldn't write to file - " + file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration getLanguageConfig() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public Object getProperty(String property) {
|
||||
return config.get(property);
|
||||
}
|
||||
|
||||
public static void load(FileConfiguration config, File file) {
|
||||
try {
|
||||
config.load(file);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(FileConfiguration config, File file) {
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadConfig(FileConfiguration config, File file) {
|
||||
save(config, file);
|
||||
load(config, file);
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
@ -45,6 +48,7 @@ public enum Language {
|
||||
|
||||
|
||||
private final String text;
|
||||
private static final Map<String, Value> values = new LinkedHashMap<String, Value>();
|
||||
|
||||
private Language(String def) {
|
||||
text = def;
|
||||
@ -53,4 +57,18 @@ public enum Language {
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public Value getValue() {
|
||||
return new Value(text);
|
||||
}
|
||||
|
||||
public static Map<String, Value> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
static {
|
||||
for (Language property : Language.values()) {
|
||||
values.put(property.name(), property.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,78 +1,94 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public enum Property {
|
||||
PREFERRED_ECONOMY_PLUGIN("", "WHEN NOT USING VAULT. Preferred (if not found, uses any other) economy plugin (iConomy, BOSEconomy, Essentials)."),
|
||||
//I put \n here, so the properties are nicely spaced out
|
||||
PREFERRED_ECONOMY_PLUGIN("", "WHEN NOT USING VAULT. Preferred (if not found, uses any other) economy plugin (iConomy, BOSEconomy, Essentials).\n"),
|
||||
|
||||
SHOP_INTERACTION_INTERVAL(100, "(In 1/1000th of a second) How often can a player use the shop sign?"),
|
||||
IGNORE_CREATIVE_MODE(true, "Do you want to allow using shops to people in creative mode?"),
|
||||
REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."),
|
||||
ALLOW_SIGN_CHEST_OPEN(true, "Can shop's chest be opened by owner with right-clicking a shop's sign?"),
|
||||
ALLOW_LEFT_CLICK_DESTROYING(true, "If true, if you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign."),
|
||||
ALLOW_LEFT_CLICK_DESTROYING(true, "If true, if you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign.\n"),
|
||||
|
||||
REMOVE_EMPTY_SHOPS(false, "If true, if the shop is empty, the sign is destroyed and put into the chest, so the shop isn't usable anymore.\n"),
|
||||
|
||||
ADMIN_SHOP_NAME("Admin Shop", "First line of your Admin Shop's sign should look like this"),
|
||||
SERVER_ECONOMY_ACCOUNT("", "The economy account which Admin Shops should use and to which all taxes will go"),
|
||||
TAX_AMOUNT(0, "Percent of the price that should go to the server's account. (100 = 100 percent)"),
|
||||
SERVER_TAX_AMOUNT(0, "Percent of the price that should go to the server's account when buying from an Admin Shop"),
|
||||
SERVER_TAX_AMOUNT(0, "Percent of the price that should go to the server's account when buying from an Admin Shop\n"),
|
||||
|
||||
SHOP_CREATION_PRICE(0, "Amount of money player must pay to create a shop"),
|
||||
SHOP_REFUND_PRICE(0, "How much money do you get back when destroying a sign?"),
|
||||
SHOP_REFUND_PRICE(0, "How much money do you get back when destroying a sign?\n"),
|
||||
|
||||
BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE(true, "Should we block shops that sell things for more than they buy? (This prevents newbies from creating shops that would be exploited)\n"),
|
||||
|
||||
ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK(false, "Do you want to allow other players to build a shop on a block where there's one already?"),
|
||||
ALLOW_PARTIAL_TRANSACTIONS(true, "Can shops be used even when the seller doesn't have enough items? (The price will be scaled adequatly to the item amount)"),
|
||||
ALLOW_PARTIAL_TRANSACTIONS(true, "Can shops be used even when the seller doesn't have enough items? (The price will be scaled adequatly to the item amount)\n"),
|
||||
|
||||
STACK_UNSTACKABLES(false, "If true, ALL things (including food, etc.) will stack up to 64"),
|
||||
STACK_UNSTACKABLES(false, "If true, ALL things (including food, etc.) will stack up to 64\n"),
|
||||
|
||||
SHOW_MESSAGE_OUT_OF_STOCK(true, "Do you want to show \"Out of stock\" messages?"),
|
||||
SHOW_TRANSACTION_INFORMATION_CLIENT(true, "Do you want to show \"You bought/sold... \" messages?"),
|
||||
SHOW_TRANSACTION_INFORMATION_OWNER(true, "Do you want to show \"Somebody bought/sold... \" messages?"),
|
||||
SHOW_TRANSACTION_INFORMATION_OWNER(true, "Do you want to show \"Somebody bought/sold... \" messages?\n"),
|
||||
|
||||
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?"),
|
||||
LOG_TO_DATABASE(false, "If true, plugin will log transactions in EBean database"),
|
||||
RECORD_TIME_TO_LIVE(600, "How long should transaction information be stored in the database (in seconds)?"),
|
||||
RECORD_TIME_TO_LIVE(600, "How long should transaction information be stored in the database (in seconds, -1 means forever)?\n"),
|
||||
|
||||
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?"),
|
||||
PROTECT_SIGN_WITH_LWC(false, "Do you want to protect shop signs with LWC?\n"),
|
||||
|
||||
//Statistics page
|
||||
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?"),
|
||||
STATISTICS_PAGE_GENERATION_INTERVAL(60, "How often should the website be generated?"),
|
||||
STATISTICS_PAGE_GENERATION_INTERVAL(60, "How often should the website be generated?\n"),
|
||||
|
||||
//Towny stuff
|
||||
TOWNY_INTEGRATION(false, "Do you want to only let people build inside shop plots?"),
|
||||
TOWNY_SHOPS_FOR_OWNERS_ONLY(true, "If true, only plot owners are able to build inside a shop plot. If false, every town's resident is able to build there."),
|
||||
TOWNY_SHOPS_FOR_OWNERS_ONLY(true, "If true, only plot owners are able to build inside a shop plot. If false, every town's resident is able to build there.\n"),
|
||||
|
||||
//WorldGuard stuff
|
||||
WORLDGUARD_INTEGRATION(false, "Do you want to only let people build inside regions?"),
|
||||
WORLDGUARD_USE_FLAG(true, "Do you want to only let poeple build inside region flagged by doing /region regionName flag chestshop allow?"),
|
||||
WORLDGUARD_USE_PROTECTION(false, "Do you want ChestShop to respect WorldGuard's chest protection?\n"),
|
||||
|
||||
//Heroes stuff
|
||||
HEROES_EXP(100, "How much Heroes exp should people get for creating a ChestShop?");
|
||||
|
||||
HEROES_EXP(100, "How much Heroes exp should people get for creating a ChestShop?\n");
|
||||
|
||||
|
||||
private final Object value;
|
||||
private final String comment;
|
||||
|
||||
private static final Map<String, Value> values = new LinkedHashMap<String, Value>();
|
||||
|
||||
private Property(Object value, String comment) {
|
||||
this.value = value;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return (value instanceof String ? "\"" + value + '\"' : value);
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
public Value getValue() {
|
||||
return new Value(value, comment);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static Map<String, Value> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
static {
|
||||
for (Property property : Property.values()) {
|
||||
values.put(property.name(), property.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
39
com/Acrobot/ChestShop/Config/Value.java
Normal file
39
com/Acrobot/ChestShop/Config/Value.java
Normal file
@ -0,0 +1,39 @@
|
||||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Value {
|
||||
public final Object value;
|
||||
public final String comment;
|
||||
|
||||
public Value(Object value, String comment) {
|
||||
this.value = value;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Value(Object value) {
|
||||
this(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of that Value
|
||||
*
|
||||
* @return The value
|
||||
*/
|
||||
public String retrieveValue() {
|
||||
StringBuilder toReturn = new StringBuilder(30);
|
||||
|
||||
if (value instanceof Number || value instanceof Boolean) {
|
||||
toReturn.append(String.valueOf(value));
|
||||
} else {
|
||||
toReturn.append('\"').append(String.valueOf(value)).append('\"');
|
||||
}
|
||||
|
||||
if (comment != null) {
|
||||
toReturn.append('\n').append('#').append(comment);
|
||||
}
|
||||
|
||||
return toReturn.toString();
|
||||
}
|
||||
}
|
30
com/Acrobot/ChestShop/Containers/AdminChest.java
Normal file
30
com/Acrobot/ChestShop/Containers/AdminChest.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.Acrobot.ChestShop.Containers;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class AdminChest implements Container {
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addItem(ItemStack item, int amount) {
|
||||
}
|
||||
|
||||
public void removeItem(ItemStack item, short durability, int amount) {
|
||||
}
|
||||
|
||||
public int amount(ItemStack item, short durability) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public boolean hasEnough(ItemStack item, int amount, short durability) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean fits(ItemStack item, int amount, short durability) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -6,11 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
* @author Acrobot
|
||||
*/
|
||||
public interface Container {
|
||||
public ItemStack[] getContents();
|
||||
|
||||
public void setSlot(int slot, ItemStack item);
|
||||
|
||||
public void clearSlot(int slot);
|
||||
public boolean isEmpty();
|
||||
|
||||
public void addItem(ItemStack item, int amount);
|
||||
|
||||
@ -21,6 +17,4 @@ public interface Container {
|
||||
public boolean hasEnough(ItemStack item, int amount, short durability);
|
||||
|
||||
public boolean fits(ItemStack item, int amount, short durability);
|
||||
|
||||
public int getSize();
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ package com.Acrobot.ChestShop.Containers;
|
||||
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import com.Acrobot.ChestShop.Utils.uInventory;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
@ -10,21 +13,20 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class MinecraftChest implements Container {
|
||||
private final Chest chest;
|
||||
private final BlockFace[] neighborFaces = new BlockFace[]{BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
|
||||
|
||||
public MinecraftChest(Chest chest) {
|
||||
this.chest = chest;
|
||||
}
|
||||
|
||||
public ItemStack[] getContents() {
|
||||
return chest.getInventory().getContents();
|
||||
public boolean isEmpty() {
|
||||
for (ItemStack item : chest.getInventory()) {
|
||||
if (item != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSlot(int slot, ItemStack item) {
|
||||
chest.getInventory().setItem(slot, item);
|
||||
}
|
||||
|
||||
public void clearSlot(int slot) {
|
||||
chest.getInventory().setItem(slot, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addItem(ItemStack item, int amount) {
|
||||
@ -47,11 +49,27 @@ public class MinecraftChest implements Container {
|
||||
return uInventory.fits(chest.getInventory(), item, amount, durability) <= 0;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return chest.getInventory().getSize();
|
||||
public Sign findShopSign() {
|
||||
Sign sign = uBlock.findAnyNearbyShopSign(chest.getBlock());
|
||||
|
||||
if (sign == null && getNeighbor() != null) {
|
||||
sign = uBlock.findAnyNearbyShopSign(getNeighbor().getBlock());
|
||||
}
|
||||
|
||||
public Chest getNeighbor() {
|
||||
return uBlock.findNeighbor(chest);
|
||||
return sign;
|
||||
}
|
||||
|
||||
private Chest getNeighbor() {
|
||||
Block chestBlock = chest.getBlock();
|
||||
|
||||
for (BlockFace chestFace : neighborFaces) {
|
||||
Block relative = chestBlock.getRelative(chestFace);
|
||||
|
||||
if (relative.getState() instanceof Chest) {
|
||||
return (Chest) relative.getState();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.Acrobot.ChestShop.DB;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Logging.Logging;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import com.avaje.ebean.ExpressionList;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.io.*;
|
||||
@ -13,9 +13,7 @@ import java.util.List;
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Generator implements Runnable {
|
||||
private static final String filePath = Config.getString(Property.STATISTICS_PAGE_PATH);
|
||||
|
||||
private static double generationTime;
|
||||
private final File pagePath;
|
||||
|
||||
private static String header;
|
||||
private static String row;
|
||||
@ -23,32 +21,43 @@ public class Generator implements Runnable {
|
||||
|
||||
private static BufferedWriter buf;
|
||||
|
||||
|
||||
public Generator(File pagePath) {
|
||||
this.pagePath = pagePath;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
header = fileToString("header");
|
||||
row = fileToString("row");
|
||||
footer = fileToString("footer");
|
||||
|
||||
if (row.isEmpty()) System.err.println(ChestShop.chatPrefix + "You lack the necessary HTML files in your plugins/ChestShop/HTML folder!");
|
||||
if (row.isEmpty()) {
|
||||
ChestShop.getBukkitLogger().severe("You lack the necessary HTML files in your plugins/ChestShop/HTML folder!");
|
||||
return;
|
||||
}
|
||||
|
||||
generateStats();
|
||||
}
|
||||
|
||||
private static void fileStart() throws IOException {
|
||||
FileWriter fw = new FileWriter(filePath);
|
||||
private void fileStart() throws IOException {
|
||||
FileWriter fw = new FileWriter(pagePath);
|
||||
fw.write(header);
|
||||
fw.close();
|
||||
}
|
||||
|
||||
private static void fileEnd() throws IOException {
|
||||
FileWriter fw = new FileWriter(filePath, true);
|
||||
private void fileEnd(long generationTime) throws IOException {
|
||||
FileWriter fw = new FileWriter(pagePath, true);
|
||||
fw.write(footer.replace("%time", String.valueOf(generationTime)));
|
||||
fw.close();
|
||||
}
|
||||
|
||||
private static String fileToString(String fileName) {
|
||||
try {
|
||||
File f = new File(ChestShop.folder + File.separator + "HTML" + File.separator + fileName + ".html");
|
||||
FileReader rd = new FileReader(f);
|
||||
char[] buf = new char[(int) f.length()];
|
||||
File htmlFolder = new File(ChestShop.getFolder(), "HTML");
|
||||
File fileToRead = new File(htmlFolder, fileName + ".html");
|
||||
|
||||
FileReader rd = new FileReader(fileToRead);
|
||||
char[] buf = new char[(int) fileToRead.length()];
|
||||
rd.read(buf);
|
||||
return new String(buf);
|
||||
} catch (Exception e) {
|
||||
@ -57,13 +66,25 @@ public class Generator implements Runnable {
|
||||
}
|
||||
|
||||
private static double generateItemTotal(int itemID, boolean bought, boolean sold) {
|
||||
double amount = 0;
|
||||
List<Transaction> list;
|
||||
if (bought) list = ChestShop.getDB().find(Transaction.class).where().eq("buy", 1).eq("itemID", itemID).findList();
|
||||
else if (sold) list = ChestShop.getDB().find(Transaction.class).where().eq("buy", 0).eq("itemID", itemID).findList();
|
||||
else list = ChestShop.getDB().find(Transaction.class).where().eq("itemID", itemID).findList();
|
||||
ExpressionList<Transaction> checkIf = ChestShop.getDB().find(Transaction.class).where();
|
||||
|
||||
if (bought || sold) {
|
||||
list = checkIf.eq("buy", bought ? 1 : 0).eq("itemID", itemID).findList();
|
||||
} else {
|
||||
list = checkIf.eq("itemID", itemID).findList();
|
||||
}
|
||||
|
||||
return countTransactionAmount(list);
|
||||
}
|
||||
|
||||
private static double countTransactionAmount(List<Transaction> list) {
|
||||
double amount = 0;
|
||||
|
||||
for (Transaction transaction : list) {
|
||||
amount += transaction.getAmount();
|
||||
}
|
||||
|
||||
for (Transaction t : list) amount += t.getAmount();
|
||||
return amount;
|
||||
}
|
||||
|
||||
@ -82,7 +103,11 @@ public class Generator implements Runnable {
|
||||
private static float generateAveragePrice(int itemID) {
|
||||
float price = 0;
|
||||
List<Transaction> prices = ChestShop.getDB().find(Transaction.class).where().eq("itemID", itemID).eq("buy", true).findList();
|
||||
for (Transaction t : prices) price += t.getAveragePricePerItem();
|
||||
|
||||
for (Transaction t : prices) {
|
||||
price += t.getAveragePricePerItem();
|
||||
}
|
||||
|
||||
float toReturn = price / prices.size();
|
||||
return (!Float.isNaN(toReturn) ? toReturn : 0);
|
||||
}
|
||||
@ -100,7 +125,7 @@ public class Generator implements Runnable {
|
||||
double sold = generateTotalSold(itemID);
|
||||
|
||||
Material material = Material.getMaterial(itemID);
|
||||
String matName = material.name().replace("_", " ").toLowerCase();
|
||||
String matName = uSign.capitalizeFirstLetter(material.name(), '_');
|
||||
|
||||
int maxStackSize = material.getMaxStackSize();
|
||||
|
||||
@ -115,22 +140,27 @@ public class Generator implements Runnable {
|
||||
.replace("%pricePerItem", String.valueOf(buyPrice)));
|
||||
}
|
||||
|
||||
private static void generateStats() {
|
||||
private void generateStats() {
|
||||
try {
|
||||
|
||||
File f = new File(filePath).getParentFile();
|
||||
if (!f.exists()) f.mkdir();
|
||||
File parentFolder = pagePath.getParentFile();
|
||||
if (!parentFolder.exists()) {
|
||||
parentFolder.mkdir();
|
||||
}
|
||||
|
||||
fileStart();
|
||||
|
||||
buf = new BufferedWriter(new FileWriter(filePath, true));
|
||||
buf = new BufferedWriter(new FileWriter(pagePath, true));
|
||||
|
||||
long genTime = System.currentTimeMillis();
|
||||
for (Material m : Material.values()) generateItemStats(m.getId());
|
||||
for (Material m : Material.values()) {
|
||||
generateItemStats(m.getId());
|
||||
}
|
||||
|
||||
buf.close();
|
||||
|
||||
generationTime = (System.currentTimeMillis() - genTime) / 1000;
|
||||
fileEnd();
|
||||
long generationTime = (System.currentTimeMillis() - genTime) / 1000;
|
||||
|
||||
fileEnd(generationTime);
|
||||
} catch (Exception e) {
|
||||
Logging.log("Couldn't generate statistics page!");
|
||||
e.printStackTrace();
|
||||
|
@ -1,38 +1,32 @@
|
||||
package com.Acrobot.ChestShop.Listeners;
|
||||
package com.Acrobot.ChestShop;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Economy.NoProvider;
|
||||
import com.Acrobot.ChestShop.Economy.Register;
|
||||
import com.Acrobot.ChestShop.Economy.Vault;
|
||||
import com.Acrobot.ChestShop.Items.Odd;
|
||||
import com.Acrobot.ChestShop.Protection.Plugins.*;
|
||||
import com.Acrobot.ChestShop.Protection.Security;
|
||||
import com.Acrobot.ChestShop.Utils.WorldGuard.uWorldGuard;
|
||||
import com.Acrobot.ChestShop.Utils.uHeroes;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import com.griefcraft.lwc.LWCPlugin;
|
||||
import com.herocraftonline.heroes.Heroes;
|
||||
import com.Acrobot.ChestShop.Plugins.*;
|
||||
import com.griefcraft.lwc.LWC;
|
||||
import com.nijikokun.register.payment.forChestShop.Method;
|
||||
import com.nijikokun.register.payment.forChestShop.Methods;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.webkonsept.bukkit.simplechestlock.SCL;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.yi.acru.bukkit.Lockette.Lockette;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class pluginEnable {
|
||||
public class Dependencies {
|
||||
|
||||
public static void initializePlugins() {
|
||||
Security.protections.add(Security.getDefaultProtection());
|
||||
public static void load() {
|
||||
initializeSecurity();
|
||||
|
||||
for (Object plugin : ChestShop.getDependencies()) {
|
||||
Plugin pl = ChestShop.pm.getPlugin((String) plugin);
|
||||
Plugin pl = ChestShop.getPluginManager().getPlugin((String) plugin);
|
||||
if (pl != null) {
|
||||
initializePlugin((String) plugin, pl);
|
||||
}
|
||||
@ -40,35 +34,47 @@ public class pluginEnable {
|
||||
loadRegister();
|
||||
}
|
||||
|
||||
private static void initializeSecurity() {
|
||||
ChestShop.registerListener(new com.Acrobot.ChestShop.Plugins.ChestShop());
|
||||
}
|
||||
|
||||
private static void loadRegister() {
|
||||
if (Economy.economy != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Method method = Methods.load(ChestShop.pm);
|
||||
Method method = Methods.load(ChestShop.getPluginManager());
|
||||
if (method == null) {
|
||||
Economy.economy = new NoProvider();
|
||||
return;
|
||||
}
|
||||
Economy.economy = new Register(method);
|
||||
System.out.println(ChestShop.chatPrefix + method.getName() + " version " + method.getVersion() + " loaded.");
|
||||
ChestShop.getBukkitLogger().info(method.getName() + " version " + method.getVersion() + " loaded.");
|
||||
}
|
||||
|
||||
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)
|
||||
if (name.equals("LWC")) {
|
||||
Security.protections.add(new LWCplugin(((LWCPlugin) plugin).getLWC()));
|
||||
ChestShop.registerListener(new LightweightChestProtection(LWC.getInstance()));
|
||||
} else if (name.equals("Lockette")) {
|
||||
Security.protections.add(new LockettePlugin((Lockette) plugin));
|
||||
ChestShop.registerListener(new Lockette());
|
||||
} else if (name.equals("Deadbolt")) {
|
||||
Security.protections.add(new DeadboltPlugin());
|
||||
ChestShop.registerListener(new Deadbolt());
|
||||
} else if (name.equals("OddItem")) {
|
||||
Odd.isInitialized = true;
|
||||
} else if (name.equals("Towny")) {
|
||||
uSign.towny = (Towny) plugin;
|
||||
if (!Config.getBoolean(Property.TOWNY_INTEGRATION)) {
|
||||
return;
|
||||
}
|
||||
ChestShop.registerListener(new Towny());
|
||||
} else if (name.equals("WorldGuard")) {
|
||||
Security.protections.add(new WorldGuardProtectionPlugin((WorldGuardPlugin) plugin));
|
||||
uWorldGuard.wg = (WorldGuardPlugin) plugin;
|
||||
uWorldGuard.injectHax(); //Inject hax into WorldGuard
|
||||
WorldGuardPlugin worldGuard = (WorldGuardPlugin) plugin;
|
||||
if (Config.getBoolean(Property.WORLDGUARD_USE_PROTECTION)) {
|
||||
ChestShop.registerListener(new WorldGuardProtection(worldGuard));
|
||||
}
|
||||
if (!Config.getBoolean(Property.WORLDGUARD_INTEGRATION)) {
|
||||
return;
|
||||
}
|
||||
ChestShop.registerListener(new WorldGuardBuilding(worldGuard));
|
||||
} else if (name.equals("Vault")) {
|
||||
if (Economy.economy != null) return;
|
||||
|
||||
@ -79,21 +85,17 @@ public class pluginEnable {
|
||||
if (Vault.economy == null) return;
|
||||
|
||||
Economy.economy = new Vault();
|
||||
System.out.println(ChestShop.chatPrefix + "Vault loaded using economy plugin " + Vault.economy.getName());
|
||||
ChestShop.getBukkitLogger().info("Vault loaded - using " + Vault.economy.getName());
|
||||
return;
|
||||
} else if (name.equals("Heroes")) {
|
||||
uHeroes.heroes = (Heroes) plugin;
|
||||
ChestShop.registerListener(new Heroes((com.herocraftonline.heroes.Heroes) plugin));
|
||||
} else if (name.equals("SimpleChestLock")) {
|
||||
Security.protections.add(new SCLplugin((SCL) plugin));
|
||||
ChestShop.registerListener(new SimpleChestLock((SCL) plugin));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
System.out.println(ChestShop.chatPrefix + description.getName() + " version " + description.getVersion() + " loaded.");
|
||||
}
|
||||
|
||||
private static String generateOutdatedVersion(String pluginName, String curVersion, String neededVersion) {
|
||||
return ChestShop.chatPrefix + "Your " + pluginName + " is outdated! Need version AT LEAST " + neededVersion + " - Your version is " + curVersion;
|
||||
ChestShop.getBukkitLogger().info(description.getName() + " version " + description.getVersion() + " loaded.");
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package com.Acrobot.ChestShop.Economy;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
@ -12,28 +12,26 @@ public class Economy {
|
||||
public static EcoPlugin economy;
|
||||
|
||||
public static boolean hasAccount(String p) {
|
||||
return economy.hasAccount(uLongName.getName(p));
|
||||
return !p.isEmpty() && economy.hasAccount(uName.getName(p));
|
||||
}
|
||||
|
||||
public static void add(String name, double amount) {
|
||||
String account = Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
|
||||
if (!account.isEmpty()) {
|
||||
double tax = getTax(Property.TAX_AMOUNT, amount);
|
||||
economy.add(account, tax);
|
||||
amount = amount - tax;
|
||||
if (!hasAccount(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
economy.add(uLongName.getName(name), amount);
|
||||
String serverAccount = Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
|
||||
Property taxAmount = name.equals(serverAccount) ? Property.SERVER_TAX_AMOUNT : Property.TAX_AMOUNT;
|
||||
|
||||
if (Config.getFloat(taxAmount) != 0) {
|
||||
double tax = getTax(taxAmount, amount);
|
||||
if (!serverAccount.isEmpty()) {
|
||||
economy.add(serverAccount, tax);
|
||||
}
|
||||
amount -= tax;
|
||||
}
|
||||
|
||||
public static void addServer(String name, double amount) {
|
||||
String account = Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
|
||||
if (!account.isEmpty()) {
|
||||
double tax = getTax(Property.SERVER_TAX_AMOUNT, amount);
|
||||
economy.add(account, tax);
|
||||
amount = amount - tax;
|
||||
}
|
||||
economy.add(uLongName.getName(name), amount);
|
||||
economy.add(uName.getName(name), amount);
|
||||
}
|
||||
|
||||
public static double getTax(Property tax, double price) {
|
||||
@ -41,15 +39,23 @@ public class Economy {
|
||||
}
|
||||
|
||||
public static void subtract(String name, double amount) {
|
||||
economy.subtract(uLongName.getName(name), amount);
|
||||
if (!hasAccount(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
economy.subtract(uName.getName(name), amount);
|
||||
}
|
||||
|
||||
public static boolean hasEnough(String name, double amount) {
|
||||
return economy.hasEnough(uLongName.getName(name), amount);
|
||||
if (!hasAccount(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return economy.hasEnough(uName.getName(name), amount);
|
||||
}
|
||||
|
||||
public static double balance(String name) {
|
||||
return economy.balance(uLongName.getName(name));
|
||||
return economy.balance(uName.getName(name));
|
||||
}
|
||||
|
||||
public static String formatBalance(double amount) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.Acrobot.ChestShop.Economy;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
@ -33,6 +35,6 @@ public class NoProvider implements EcoPlugin {
|
||||
}
|
||||
|
||||
private static void printError() {
|
||||
System.err.println("[ChestShop] You haven't got any economy plugin!");
|
||||
ChestShop.getBukkitLogger().severe("You haven't got any economy plugin!");
|
||||
}
|
||||
}
|
||||
|
66
com/Acrobot/ChestShop/Events/BuildPermissionEvent.java
Normal file
66
com/Acrobot/ChestShop/Events/BuildPermissionEvent.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.Acrobot.ChestShop.Events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class BuildPermissionEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private Location chest, sign;
|
||||
|
||||
private int disallowed = 0;
|
||||
private int received = 0;
|
||||
|
||||
public BuildPermissionEvent(Player player, Location chest, Location sign) {
|
||||
this.player = player;
|
||||
this.chest = chest;
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Location getChest() {
|
||||
return chest;
|
||||
}
|
||||
|
||||
public Location getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void allow() {
|
||||
received++;
|
||||
}
|
||||
|
||||
public boolean isAllowed() {
|
||||
return disallowed != received || received == 0;
|
||||
}
|
||||
|
||||
public void allow(boolean yesOrNot) {
|
||||
if (yesOrNot) {
|
||||
allow();
|
||||
} else {
|
||||
disallow();
|
||||
}
|
||||
}
|
||||
|
||||
public void disallow() {
|
||||
received++;
|
||||
disallowed++;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
47
com/Acrobot/ChestShop/Events/ProtectBlockEvent.java
Normal file
47
com/Acrobot/ChestShop/Events/ProtectBlockEvent.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.Acrobot.ChestShop.Events;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ProtectBlockEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Block block;
|
||||
private String name;
|
||||
|
||||
boolean isProtected = false;
|
||||
|
||||
public ProtectBlockEvent(Block block, String name) {
|
||||
this.block = block;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isProtected() {
|
||||
return isProtected;
|
||||
}
|
||||
|
||||
public void setProtected(boolean yesOrNo) {
|
||||
isProtected = yesOrNo;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
46
com/Acrobot/ChestShop/Events/ProtectionCheckEvent.java
Normal file
46
com/Acrobot/ChestShop/Events/ProtectionCheckEvent.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.Acrobot.ChestShop.Events;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ProtectionCheckEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Result result = Result.DEFAULT;
|
||||
private Block block;
|
||||
private Player player;
|
||||
|
||||
public ProtectionCheckEvent(Block block, Player player) {
|
||||
this.block = block;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
50
com/Acrobot/ChestShop/Events/ShopCreatedEvent.java
Normal file
50
com/Acrobot/ChestShop/Events/ShopCreatedEvent.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.Acrobot.ChestShop.Events;
|
||||
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ShopCreatedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Player player;
|
||||
private Sign sign;
|
||||
private Chest chest;
|
||||
private String[] signLines;
|
||||
|
||||
public ShopCreatedEvent(Player player, Sign sign, Chest chest, String[] signLines) {
|
||||
this.player = player;
|
||||
this.sign = sign;
|
||||
this.chest = chest;
|
||||
this.signLines = signLines;
|
||||
}
|
||||
|
||||
public String[] getSignLines() {
|
||||
return signLines;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Sign getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public Chest getChest() {
|
||||
return chest;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -4,79 +4,103 @@ import org.bukkit.CoalType;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.*;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class DataValue {
|
||||
/**
|
||||
* Gets the data value from a string
|
||||
*
|
||||
* @param type Data Value string
|
||||
* @param material Material
|
||||
* @return data value
|
||||
*/
|
||||
public static byte get(String type, Material material) {
|
||||
if (material == null) return 0;
|
||||
|
||||
type = type.toUpperCase().replace(" ", "_");
|
||||
MaterialData materialData = null;
|
||||
|
||||
try {
|
||||
switch (material) {
|
||||
case SAPLING:
|
||||
case LOG:
|
||||
materialData = new Tree(TreeSpecies.valueOf(type));
|
||||
break;
|
||||
case STEP:
|
||||
case DOUBLE_STEP:
|
||||
materialData = new Step(Items.getMaterial(type));
|
||||
break;
|
||||
case WOOL:
|
||||
materialData = new Wool(DyeColor.valueOf(type));
|
||||
break;
|
||||
case INK_SACK:
|
||||
byte data = (byte) (15 - DyeColor.valueOf(type).getData());
|
||||
materialData = new Wool(DyeColor.getByData(data));
|
||||
break;
|
||||
case COAL:
|
||||
materialData = new Coal(CoalType.valueOf(type));
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (material == null || material.getData() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (materialData == null ? 0 : materialData.getData());
|
||||
type = type.toUpperCase().replace(" ", "_");
|
||||
|
||||
MaterialData materialData = material.getNewData((byte) 0);
|
||||
|
||||
if (materialData instanceof TexturedMaterial) {
|
||||
TexturedMaterial texturedMaterial = (TexturedMaterial) materialData;
|
||||
|
||||
for (Material mat : texturedMaterial.getTextures()) {
|
||||
if (mat.name().startsWith(type)) {
|
||||
return (byte) texturedMaterial.getTextures().indexOf(mat);
|
||||
}
|
||||
|
||||
public static String getName(ItemStack is) {
|
||||
short dur = is.getDurability();
|
||||
if (dur == 0) return null;
|
||||
|
||||
Material material = is.getType();
|
||||
|
||||
String name = null;
|
||||
}
|
||||
} else if (materialData instanceof Colorable) {
|
||||
DyeColor color;
|
||||
|
||||
try {
|
||||
switch (material) {
|
||||
case SAPLING:
|
||||
case LOG:
|
||||
name = TreeSpecies.getByData((byte) dur).name();
|
||||
break;
|
||||
case STEP:
|
||||
case DOUBLE_STEP:
|
||||
name = new Step(Material.getMaterial(dur)).getMaterial().name();
|
||||
break;
|
||||
case WOOL:
|
||||
name = DyeColor.getByData((byte) dur).name();
|
||||
break;
|
||||
case INK_SACK:
|
||||
name = DyeColor.getByData((byte) (15 - dur)).name();
|
||||
break;
|
||||
case COAL:
|
||||
name = CoalType.getByData((byte) dur).name();
|
||||
break;
|
||||
color = DyeColor.valueOf(type);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
if (material == Material.INK_SACK) {
|
||||
color = DyeColor.getByData((byte) (15 - color.getData()));
|
||||
}
|
||||
|
||||
return color.getData();
|
||||
} else if (materialData instanceof Tree) {
|
||||
try {
|
||||
return TreeSpecies.valueOf(type).getData();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return 0;
|
||||
}
|
||||
} else if (materialData instanceof SpawnEgg) {
|
||||
try {
|
||||
EntityType entityType = EntityType.valueOf(type);
|
||||
|
||||
return (byte) entityType.getTypeId();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return 0;
|
||||
}
|
||||
} else if (materialData instanceof Coal) {
|
||||
try {
|
||||
return CoalType.valueOf(type).getData();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string with the DataValue
|
||||
*
|
||||
* @param itemStack ItemStack to describe
|
||||
* @return Data value string
|
||||
*/
|
||||
public static String name(ItemStack itemStack) {
|
||||
MaterialData data = itemStack.getData();
|
||||
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return name;
|
||||
if (data instanceof TexturedMaterial) {
|
||||
return ((TexturedMaterial) data).getMaterial().name();
|
||||
} else if (data instanceof Colorable) {
|
||||
return ((Colorable) data).getColor().name();
|
||||
} else if (data instanceof Tree) {
|
||||
//TreeSpecies specie = TreeSpecies.getByData((byte) (data.getData() & 3)); //This works, but not as intended
|
||||
TreeSpecies specie = ((Tree) data).getSpecies();
|
||||
return (specie != null && specie != TreeSpecies.GENERIC ? specie.name() : null);
|
||||
} else if (data instanceof SpawnEgg) {
|
||||
EntityType type = ((SpawnEgg) data).getSpawnedType();
|
||||
return (type != null ? type.name() : null);
|
||||
} else if (data instanceof Coal) {
|
||||
CoalType coal = ((Coal) data).getType();
|
||||
return (coal != null && coal != CoalType.COAL ? coal.name() : null);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -43,8 +43,8 @@ public class Items {
|
||||
}
|
||||
|
||||
public static String getName(ItemStack is, boolean showData) {
|
||||
String name = DataValue.getName(is);
|
||||
return uSign.capitalizeFirst((name != null && showData ? name + '_' : "") + is.getType());
|
||||
String name = DataValue.name(is);
|
||||
return uSign.capitalizeFirstLetter((name != null && showData ? name + '_' : "") + is.getType());
|
||||
}
|
||||
|
||||
public static String getSignName(ItemStack is) {
|
||||
@ -68,7 +68,9 @@ public class Items {
|
||||
|
||||
Material material = getMaterial(first);
|
||||
|
||||
for (int i = (space.length > 1 ? 1 : 0); i >= 0 && material == null; i--) material = getMaterial(space[i]);
|
||||
for (int i = (space.length > 1 ? 1 : 0); i >= 0 && material == null; i--) {
|
||||
material = getMaterial(space[i]);
|
||||
}
|
||||
|
||||
if (material == null) return null;
|
||||
|
||||
@ -89,7 +91,7 @@ public class Items {
|
||||
String data = m.group();
|
||||
if (data == null || data.isEmpty()) return toReturn;
|
||||
data = data.substring(1);
|
||||
if (uNumber.isInteger(data)) toReturn.setDurability(Short.valueOf(data));
|
||||
if (uNumber.isShort(data)) toReturn.setDurability(Short.valueOf(data));
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
@ -106,8 +108,10 @@ public class Items {
|
||||
}
|
||||
|
||||
private static ItemStack addEnchantments(ItemStack is, String itemname) {
|
||||
try { is.addEnchantments(getEnchant(itemname));
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
is.addEnchantments(getEnchant(itemname));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Signs.restrictedSign;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -20,6 +20,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.material.Directional;
|
||||
import org.bukkit.material.PistonBaseMaterial;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -28,7 +29,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class blockBreak implements Listener {
|
||||
public class BlockBreak implements Listener {
|
||||
public static boolean cancellingBlockBreak(Block block, Player player) {
|
||||
if (block == null) return false;
|
||||
|
||||
@ -36,13 +37,13 @@ public class blockBreak implements Listener {
|
||||
|
||||
if (restrictedSign(block)) return !restrictedSign.canDestroy(player, uBlock.findRestrictedSign(block));
|
||||
|
||||
Sign sign = uBlock.findSign(block, (player != null ? uLongName.stripName(player.getName()) : null));
|
||||
Sign sign = uBlock.findValidShopSign(block, (player != null ? uName.stripName(player.getName()) : null));
|
||||
if (!isCorrectSign(sign, block)) return false; //It's not a correct shop sign, so don't cancel it
|
||||
if (playerIsNotOwner(player, sign)) return !isAdmin(player); //If the player isn't the owner or an admin - cancel!
|
||||
|
||||
if (weShouldReturnMoney() && !Permission.has(player, Permission.NOFEE)) {
|
||||
float refundPrice = Config.getFloat(Property.SHOP_REFUND_PRICE);
|
||||
Economy.add(uLongName.getName(sign.getLine(0)), refundPrice); //Add some money
|
||||
Economy.add(uName.getName(sign.getLine(0)), refundPrice); //Add some money
|
||||
player.sendMessage(Config.getLocal(Language.SHOP_REFUNDED).replace("%amount", Economy.formatBalance(refundPrice)));
|
||||
}
|
||||
|
||||
@ -68,15 +69,11 @@ public class blockBreak implements Listener {
|
||||
}
|
||||
|
||||
private static boolean isCorrectSign(Sign sign, Block block) {
|
||||
return sign != null && (sign.getBlock().equals(block) || getAttachedFace(sign).equals(block));
|
||||
}
|
||||
|
||||
public static Block getAttachedFace(Sign sign) {
|
||||
return sign.getBlock().getRelative(((org.bukkit.material.Sign) sign.getData()).getAttachedFace());
|
||||
return sign != null && (sign.getBlock().equals(block) || uBlock.getAttachedFace(sign).equals(block));
|
||||
}
|
||||
|
||||
private static boolean playerIsNotOwner(Player player, Sign sign) {
|
||||
return player == null || (!uLongName.stripName(player.getName()).equals(sign.getLine(0))
|
||||
return player == null || (!uName.stripName(player.getName()).equals(sign.getLine(0))
|
||||
&& !Permission.otherName(player, sign.getLine(0)));
|
||||
}
|
||||
|
||||
@ -102,7 +99,7 @@ public class blockBreak implements Listener {
|
||||
|
||||
//Those are fixes for CraftBukkit's piston bug, where piston appears not to be a piston.
|
||||
private static BlockFace getPistonDirection(Block block) {
|
||||
return block.getState().getData() instanceof PistonBaseMaterial ? ((PistonBaseMaterial) block.getState().getData()).getFacing() : null;
|
||||
return block.getState().getData() instanceof PistonBaseMaterial ? ((Directional) block.getState().getData()).getFacing() : null;
|
||||
}
|
||||
|
||||
private static Block getRetractLocationBlock(BlockPistonRetractEvent event) {
|
||||
@ -112,15 +109,25 @@ public class blockBreak implements Listener {
|
||||
|
||||
private static List<Block> getExtendBlocks(BlockPistonExtendEvent event) {
|
||||
BlockFace pistonDirection = getPistonDirection(event.getBlock());
|
||||
if (pistonDirection == null) return new ArrayList<Block>();
|
||||
Block piston = event.getBlock();
|
||||
ArrayList<Block> list = new ArrayList<Block>();
|
||||
for (int b = 1; b < event.getLength() + 1; b++) {
|
||||
Block block = piston.getRelative(pistonDirection, b);
|
||||
Material blockType = block.getType();
|
||||
if (blockType == Material.AIR) break;
|
||||
list.add(block);
|
||||
|
||||
if (pistonDirection == null) {
|
||||
return new ArrayList<Block>();
|
||||
}
|
||||
return list;
|
||||
|
||||
Block piston = event.getBlock();
|
||||
List<Block> pushedBlocks = new ArrayList<Block>();
|
||||
|
||||
for (int currentBlock = 1; currentBlock < event.getLength() + 1; currentBlock++) {
|
||||
Block block = piston.getRelative(pistonDirection, currentBlock);
|
||||
Material blockType = block.getType();
|
||||
|
||||
if (blockType == Material.AIR) {
|
||||
break;
|
||||
}
|
||||
|
||||
pushedBlocks.add(block);
|
||||
}
|
||||
|
||||
return pushedBlocks;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.Acrobot.ChestShop.Listeners;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Language;
|
||||
import com.Acrobot.ChestShop.Protection.Security;
|
||||
import com.Acrobot.ChestShop.Security;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.Material;
|
||||
@ -16,22 +16,26 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class blockPlace implements Listener {
|
||||
@EventHandler
|
||||
public class BlockPlace implements Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public static void onBlockPlace(BlockPlaceEvent event) {
|
||||
Block block = event.getBlockAgainst();
|
||||
|
||||
if (uSign.isSign(block) && uSign.isValid((Sign) block.getState())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Block placed = event.getBlockPlaced();
|
||||
|
||||
if (placed.getType() == Material.CHEST) {
|
||||
Chest neighbor = uBlock.findNeighbor(placed);
|
||||
if (neighbor == null) return;
|
||||
if (neighbor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block neighborBlock = neighbor.getBlock();
|
||||
if (Security.isProtected(neighborBlock) && !Security.canAccess(event.getPlayer(), neighborBlock)) {
|
||||
if (!Security.canAccess(event.getPlayer(), neighborBlock)) {
|
||||
event.getPlayer().sendMessage(Config.getLocal(Language.ACCESS_DENIED));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -10,12 +10,15 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class entityExplode implements Listener {
|
||||
public class EntityExplode implements Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public static void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (event.blockList() == null || !Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return;
|
||||
if (event.blockList() == null || !Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Block block : event.blockList()) {
|
||||
if (blockBreak.cancellingBlockBreak(block, null)) {
|
||||
if (BlockBreak.cancellingBlockBreak(block, null)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Language;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Protection.Plugins.Default;
|
||||
import com.Acrobot.ChestShop.Protection.Security;
|
||||
import com.Acrobot.ChestShop.Plugins.ChestShop;
|
||||
import com.Acrobot.ChestShop.Security;
|
||||
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
||||
import com.Acrobot.ChestShop.Signs.restrictedSign;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
@ -28,21 +28,26 @@ import java.util.HashMap;
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class playerInteract implements Listener {
|
||||
public class PlayerInteract implements Listener {
|
||||
private static final HashMap<Player, Long> timeOfTheLatestSignClick = new HashMap<Player, Long>();
|
||||
public static int interval = 100;//Minimal interval between transactions
|
||||
public int transactionBlockInterval = 100;
|
||||
|
||||
public PlayerInteract(int transactionInterval) {
|
||||
this.transactionBlockInterval = transactionInterval;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public static void onPlayerInteract(PlayerInteractEvent event) {
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Action action = event.getAction();
|
||||
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (!playerClickedBlock(action)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) {
|
||||
Default protection = Security.getDefaultProtection();
|
||||
if (!hasAdminPermissions(player) && (protection.isProtected(block) && !protection.canAccess(player, block))) {
|
||||
if (!hasAdminPermissions(player) && !ChestShop.canAccess(player, block)) {
|
||||
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -86,16 +91,21 @@ public class playerInteract implements Listener {
|
||||
else ShopManagement.sell(sign, player);
|
||||
}
|
||||
|
||||
private static boolean enoughTimeHasPassed(Player player) {
|
||||
return !timeOfTheLatestSignClick.containsKey(player) || (System.currentTimeMillis() - timeOfTheLatestSignClick.get(player)) >= interval;
|
||||
private boolean enoughTimeHasPassed(Player player) {
|
||||
return !timeOfTheLatestSignClick.containsKey(player) || (System.currentTimeMillis() - timeOfTheLatestSignClick.get(player)) >= transactionBlockInterval;
|
||||
}
|
||||
|
||||
private static boolean playerClickedBlock(Action action) {
|
||||
return action == Action.LEFT_CLICK_BLOCK || action == Action.RIGHT_CLICK_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
private static boolean hasAdminPermissions(Player player) {
|
||||
return Permission.has(player, Permission.ADMIN) || Permission.has(player, Permission.MOD);
|
||||
}
|
||||
|
||||
private static void showChestGUI(Player player, Block block) {
|
||||
Chest chest = uBlock.findChest(block);
|
||||
Chest chest = uBlock.findConnectedChest(block);
|
||||
if (chest == null) { //Sorry, no chest found
|
||||
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
||||
return;
|
||||
|
@ -1,16 +1,21 @@
|
||||
package com.Acrobot.ChestShop.Listeners;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Language;
|
||||
import com.Acrobot.ChestShop.Config.MaxPrice;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Events.BuildPermissionEvent;
|
||||
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
|
||||
import com.Acrobot.ChestShop.Items.Items;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Protection.Security;
|
||||
import com.Acrobot.ChestShop.Security;
|
||||
import com.Acrobot.ChestShop.Signs.restrictedSign;
|
||||
import com.Acrobot.ChestShop.Utils.WorldGuard.uWorldGuard;
|
||||
import com.Acrobot.ChestShop.Utils.*;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import com.Acrobot.ChestShop.Utils.uNumber;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -25,8 +30,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class signChange implements Listener {
|
||||
|
||||
public class SignChange implements Listener {
|
||||
@EventHandler
|
||||
public static void onSignChange(SignChangeEvent event) {
|
||||
Block signBlock = event.getBlock();
|
||||
@ -60,7 +64,9 @@ public class signChange implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (formatFirstLine(line[0], player)) event.setLine(0, uLongName.stripName(player.getName()));
|
||||
if (!playerCanUseName(player, line[0])) {
|
||||
event.setLine(0, uName.stripName(player.getName()));
|
||||
}
|
||||
|
||||
String thirdLine = formatThirdLine(line[2]);
|
||||
if (thirdLine == null) {
|
||||
@ -71,7 +77,7 @@ public class signChange implements Listener {
|
||||
event.setLine(2, thirdLine);
|
||||
event.setLine(3, formatFourthLine(line[3], stock));
|
||||
|
||||
Chest chest = uBlock.findChest(signBlock);
|
||||
Chest chest = uBlock.findConnectedChest(signBlock);
|
||||
|
||||
boolean isAdminShop = uSign.isAdminShop(event.getLine(0));
|
||||
if (!isAdminShop) {
|
||||
@ -87,19 +93,17 @@ public class signChange implements Listener {
|
||||
}
|
||||
|
||||
Block chestBlock = chest.getBlock();
|
||||
boolean canBuildTowny = uSign.towny == null || uTowny.canBuild(player, signBlock.getLocation(), chest.getLocation());
|
||||
boolean canBuildWorldGuard = uWorldGuard.wg == null || uWorldGuard.canBuildShopHere(signBlock.getLocation());
|
||||
boolean bothActive = (uSign.towny != null && Config.getBoolean(Property.TOWNY_INTEGRATION))
|
||||
&& (uWorldGuard.wg != null && Config.getBoolean(Property.WORLDGUARD_INTEGRATION));
|
||||
BuildPermissionEvent bEvent = new BuildPermissionEvent(player, chest.getLocation(), signBlock.getLocation());
|
||||
|
||||
if (((!canBuildTowny || !canBuildWorldGuard) && !bothActive) || (bothActive && !canBuildTowny && !canBuildWorldGuard)) {
|
||||
ChestShop.callEvent(bEvent);
|
||||
|
||||
if (!bEvent.isAllowed()) {
|
||||
player.sendMessage(Config.getLocal(Language.CANNOT_CREATE_SHOP_HERE));
|
||||
dropSign(event);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean canAccess = !Security.isProtected(chestBlock) || Security.canAccess(player, chestBlock);
|
||||
if (!canAccess) {
|
||||
if (!Security.canAccess(player, chestBlock)) {
|
||||
player.sendMessage(Config.getLocal(Language.CANNOT_ACCESS_THE_CHEST));
|
||||
dropSign(event);
|
||||
return;
|
||||
@ -107,10 +111,10 @@ public class signChange implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
float buyPrice = uSign.buyPrice(thirdLine);
|
||||
float sellPrice = uSign.sellPrice(thirdLine);
|
||||
double buyPrice = uSign.buyPrice(thirdLine);
|
||||
double sellPrice = uSign.sellPrice(thirdLine);
|
||||
|
||||
if (!playerIsAdmin && (!canCreateShop(player, mat.getId(), buyPrice != -1, sellPrice != -1) || !MaxPrice.canCreate(buyPrice, sellPrice, mat))) {
|
||||
if (!playerIsAdmin && (!canCreateShop(player, mat, buyPrice != -1, sellPrice != -1) || !MaxPrice.canCreate(buyPrice, sellPrice, mat))) {
|
||||
player.sendMessage(Config.getLocal(Language.YOU_CANNOT_CREATE_SHOP));
|
||||
dropSign(event);
|
||||
return;
|
||||
@ -135,14 +139,26 @@ public class signChange implements Listener {
|
||||
player.sendMessage(Config.getLocal(Language.PROTECTED_SHOP));
|
||||
}
|
||||
|
||||
uLongName.saveName(player.getName());
|
||||
uName.saveName(player.getName());
|
||||
player.sendMessage(Config.getLocal(Language.SHOP_CREATED) + (paid ? " - " + Economy.formatBalance(shopCreationPrice) : ""));
|
||||
|
||||
uHeroes.addHeroExp(player);
|
||||
ShopCreatedEvent sEvent = new ShopCreatedEvent(player, (Sign) signBlock.getState(), chest, event.getLines());
|
||||
ChestShop.callEvent(sEvent);
|
||||
}
|
||||
|
||||
private static boolean canCreateShop(Player player, int ID, boolean buy, boolean sell) {
|
||||
if (Permission.has(player, Permission.SHOP_CREATION_ID + Integer.toString(ID))) return true;
|
||||
private static boolean canCreateShop(Player player, Material mat, double buyPrice, double sellPrice) {
|
||||
if (Config.getBoolean(Property.BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE)) {
|
||||
if (buyPrice != -1 && sellPrice != -1 && sellPrice > buyPrice) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return canCreateShop(player, mat, buyPrice != -1, sellPrice != -1) && MaxPrice.canCreate(buyPrice, sellPrice, mat);
|
||||
}
|
||||
|
||||
private static boolean canCreateShop(Player player, Material material, boolean buy, boolean sell) {
|
||||
if (Permission.has(player, Permission.SHOP_CREATION_ID + Integer.toString(material.getId()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (buy && !Permission.has(player, Permission.SHOP_CREATION_BUY)) return false;
|
||||
if (sell && !Permission.has(player, Permission.SHOP_CREATION_SELL)) return false;
|
||||
@ -151,45 +167,59 @@ public class signChange implements Listener {
|
||||
}
|
||||
|
||||
private static String formatThirdLine(String thirdLine) {
|
||||
thirdLine = thirdLine.toUpperCase();
|
||||
String[] split = thirdLine.split(":");
|
||||
if (uNumber.isFloat(split[0])) thirdLine = "B " + thirdLine;
|
||||
if (split.length == 2 && uNumber.isFloat(split[1])) thirdLine = thirdLine + " S";
|
||||
if (thirdLine.length() > 15) thirdLine = thirdLine.replace(" ", "");
|
||||
String line = thirdLine.toUpperCase();
|
||||
String[] split = line.split(":");
|
||||
|
||||
|
||||
return (thirdLine.length() > 15 ? null : thirdLine);
|
||||
if (uNumber.isFloat(split[0])) {
|
||||
line = "B " + line;
|
||||
}
|
||||
if (split.length == 2 && uNumber.isFloat(split[1])) {
|
||||
line = line + " S";
|
||||
}
|
||||
|
||||
private static String formatFourthLine(String fourthLine, ItemStack is) {
|
||||
int index = (fourthLine.indexOf(':') != -1 ? fourthLine.indexOf(':') : 9999);
|
||||
if (fourthLine.indexOf('-') < index && fourthLine.indexOf('-') != -1) index = fourthLine.indexOf('-');
|
||||
|
||||
StringBuilder toReturn = new StringBuilder(3);
|
||||
String matName = fourthLine.split(":|-")[0];
|
||||
matName = matName.trim();
|
||||
if (uNumber.isInteger(matName)) matName = Items.getName(is, false);
|
||||
int iPos = 15 - (fourthLine.length() - index);
|
||||
if (index != 9999 && matName.length() > iPos) matName = matName.substring(0, iPos);
|
||||
if (Items.getItemStack(matName).getType() == is.getType()) toReturn.append(matName);
|
||||
else toReturn.append(is.getTypeId());
|
||||
|
||||
if (index != -1 && index != 9999) toReturn.append(fourthLine.substring(index));
|
||||
return uSign.capitalizeFirst(toReturn.toString(), ' ');
|
||||
if (line.length() > 15) {
|
||||
line.replace(" ", "");
|
||||
}
|
||||
|
||||
private static boolean formatFirstLine(String line1, Player player) {
|
||||
return line1.isEmpty() ||
|
||||
(!line1.equals(uLongName.stripName(player.getName()))
|
||||
&& !Permission.has(player, Permission.ADMIN)
|
||||
&& !Permission.otherName(player, line1));
|
||||
return (line.length() > 15 ? null : line);
|
||||
}
|
||||
|
||||
private static String formatFourthLine(String line, ItemStack itemStack) {
|
||||
StringBuilder formatted = new StringBuilder(15);
|
||||
|
||||
String[] split = line.split(":|-", 2);
|
||||
String itemName = Items.getName(itemStack, false);
|
||||
|
||||
short dataLength = (short) (line.length() - split[0].length());
|
||||
|
||||
if (itemName.length() > (15 - dataLength)) {
|
||||
itemName = itemName.substring(0, 15 - dataLength);
|
||||
}
|
||||
|
||||
if (Items.getItemStack(itemName).getType() != itemStack.getType()) {
|
||||
itemName = String.valueOf(itemStack.getTypeId());
|
||||
}
|
||||
|
||||
formatted.append(itemName);
|
||||
if (split.length == 2) {
|
||||
formatted.append(line.charAt(line.indexOf(split[1]) - 1)).append(split[1]);
|
||||
}
|
||||
|
||||
return uSign.capitalizeFirstLetter(formatted.toString(), ' ');
|
||||
}
|
||||
|
||||
private static boolean playerCanUseName(Player player, String name) {
|
||||
return !name.isEmpty() && (uName.canUseName(player, name) || Permission.has(player, Permission.ADMIN));
|
||||
}
|
||||
|
||||
private static void sendMessageAndExit(Player player, Language message, SignChangeEvent event) {
|
||||
player.sendMessage(Config.getLocal(message));
|
||||
|
||||
dropSign(event);
|
||||
}
|
||||
|
||||
private static void dropSign(SignChangeEvent event) {
|
||||
event.setCancelled(true);
|
||||
|
||||
Block block = event.getBlock();
|
||||
block.setType(Material.AIR);
|
||||
block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.SIGN, 1));
|
||||
event.getBlock().breakNaturally();
|
||||
}
|
||||
}
|
||||
|
25
com/Acrobot/ChestShop/Logging/FileFormatter.java
Normal file
25
com/Acrobot/ChestShop/Logging/FileFormatter.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.Acrobot.ChestShop.Logging;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class FileFormatter extends Formatter {
|
||||
private final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
return getDateAndTime() + ' ' + record.getMessage() + '\n';
|
||||
}
|
||||
|
||||
private String getDateAndTime() {
|
||||
Date date = new Date();
|
||||
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Logging;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class FileWriterQueue implements Runnable {
|
||||
private static final List<String> queue = new LinkedList<String>();
|
||||
private static final String filePath = new File(ChestShop.folder, "ChestShop.log").getPath();
|
||||
|
||||
public static void addToQueue(String message) {
|
||||
queue.add(message);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(filePath, true));
|
||||
|
||||
for (String msg : queue) {
|
||||
bw.write(msg);
|
||||
bw.newLine();
|
||||
}
|
||||
|
||||
bw.close();
|
||||
|
||||
queue.clear();
|
||||
} catch (Exception e) {
|
||||
Logging.log("Couldn't write to log file!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.Acrobot.ChestShop.Logging;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.DB.Queue;
|
||||
@ -10,9 +11,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -20,28 +18,43 @@ import java.util.logging.Logger;
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Logging {
|
||||
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
private static final Logger logger = Logger.getLogger("ChestShop");
|
||||
|
||||
private static String getDateAndTime() {
|
||||
Date date = new Date();
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
private static final Logger logger = ChestShop.getBukkitLogger();
|
||||
|
||||
public static void log(String string) {
|
||||
if (Config.getBoolean(Property.LOG_TO_CONSOLE)) logger.log(Level.INFO, "[ChestShop] " + string);
|
||||
if (Config.getBoolean(Property.LOG_TO_FILE)) FileWriterQueue.addToQueue(getDateAndTime() + ' ' + string);
|
||||
logger.log(Level.INFO, string);
|
||||
}
|
||||
|
||||
public static void logTransaction(boolean isBuying, Shop shop, double price, Player player) {
|
||||
log(player.getName()
|
||||
+ (isBuying ? " bought " : " sold ")
|
||||
+ shop.stockAmount + ' '
|
||||
+ Items.getSignName(shop.stock) + " for "
|
||||
+ price + (isBuying ? " from " : " to ")
|
||||
+ shop.owner + " at "
|
||||
+ locationToString(shop.sign.getLocation()));
|
||||
if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) logToDatabase(isBuying, shop, price, player);
|
||||
public static void logTransaction(boolean playerIsBuyingFromShop, Shop shop, double price, Player player) {
|
||||
StringBuilder builder = new StringBuilder(player.getName());
|
||||
|
||||
if (playerIsBuyingFromShop) {
|
||||
builder.append(" bought ");
|
||||
} else {
|
||||
builder.append(" sold ");
|
||||
}
|
||||
|
||||
builder.append(shop.stockAmount).append(' ');
|
||||
builder.append(Items.getSignName(shop.stock)).append(" for ");
|
||||
builder.append(price);
|
||||
|
||||
if (playerIsBuyingFromShop) {
|
||||
builder.append(" from ");
|
||||
} else {
|
||||
builder.append(" to ");
|
||||
}
|
||||
|
||||
builder.append(shop.owner).append(" at ");
|
||||
builder.append(locationToString(shop.sign.getLocation()));
|
||||
|
||||
log(builder.toString());
|
||||
|
||||
if (weShouldLogToDB()) {
|
||||
logToDatabase(playerIsBuyingFromShop, shop, price, player);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean weShouldLogToDB() {
|
||||
return Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE);
|
||||
}
|
||||
|
||||
private static String locationToString(Location loc) {
|
||||
|
@ -6,12 +6,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.*;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
@ -146,7 +141,7 @@ public class Metrics {
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] {0}", e.getMessage());
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}, 0, PING_INTERVAL * 1200);
|
||||
@ -161,7 +156,7 @@ public class Metrics {
|
||||
* @return
|
||||
*/
|
||||
public boolean isOptOut() {
|
||||
synchronized(optOutLock) {
|
||||
synchronized (optOutLock) {
|
||||
try {
|
||||
// Reload the metrics file
|
||||
configuration.load(CONFIG_FILE);
|
||||
|
@ -38,7 +38,10 @@ public enum Permission {
|
||||
}
|
||||
|
||||
public static boolean otherName(Player p, String name) {
|
||||
if (has(p, Permission.ADMIN)) return false;
|
||||
if (has(p, Permission.ADMIN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String node = OTHER_NAME + name;
|
||||
return hasPermissionSet(p, node) || hasPermissionSet(p, node.toLowerCase());
|
||||
}
|
||||
|
79
com/Acrobot/ChestShop/Plugins/ChestShop.java
Normal file
79
com/Acrobot/ChestShop/Plugins/ChestShop.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Containers.MinecraftChest;
|
||||
import com.Acrobot.ChestShop.Events.ProtectionCheckEvent;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ChestShop implements Listener {
|
||||
@EventHandler
|
||||
public static void onProtectionCheck(ProtectionCheckEvent event) {
|
||||
if (event.getResult() == Event.Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!canAccess(player, block)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canAccess(Player player, Block block) {
|
||||
if (!canBeProtected(block)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isSign(block)) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
|
||||
if (!uSign.isValid(sign)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isShopMember(player, sign)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isChest(block)) {
|
||||
MinecraftChest chest = new MinecraftChest((Chest) block.getState());
|
||||
|
||||
Sign sign = chest.findShopSign();
|
||||
|
||||
if (sign != null && !isShopMember(player, sign)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isChest(Block block) {
|
||||
return block.getType() == Material.CHEST;
|
||||
}
|
||||
|
||||
private static boolean isSign(Block block) {
|
||||
return uSign.isSign(block);
|
||||
}
|
||||
|
||||
private static boolean canBeProtected(Block block) {
|
||||
return isSign(block) || isChest(block);
|
||||
}
|
||||
|
||||
private static boolean isShopMember(Player player, Sign sign) {
|
||||
return uName.canUseName(player, sign.getLine(0));
|
||||
}
|
||||
}
|
34
com/Acrobot/ChestShop/Plugins/Deadbolt.java
Normal file
34
com/Acrobot/ChestShop/Plugins/Deadbolt.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Events.ProtectionCheckEvent;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Deadbolt implements Listener {
|
||||
@EventHandler
|
||||
public static void onProtectionCheck(ProtectionCheckEvent event) {
|
||||
if (event.getResult() == Event.Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!com.daemitus.deadbolt.Deadbolt.isProtected(block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String shortPlayerName = uName.shortenName(player);
|
||||
|
||||
if (!com.daemitus.deadbolt.Deadbolt.getAllNames(block).contains(shortPlayerName)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
}
|
37
com/Acrobot/ChestShop/Plugins/Heroes.java
Normal file
37
com/Acrobot/ChestShop/Plugins/Heroes.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
|
||||
import com.herocraftonline.heroes.characters.Hero;
|
||||
import com.herocraftonline.heroes.characters.classes.HeroClass;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Heroes implements Listener {
|
||||
private com.herocraftonline.heroes.Heroes heroes;
|
||||
|
||||
public Heroes(com.herocraftonline.heroes.Heroes heroes) {
|
||||
this.heroes = heroes;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void shopCreated(ShopCreatedEvent event) {
|
||||
double heroExp = Config.getDouble(Property.HEROES_EXP);
|
||||
|
||||
if (heroExp == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Hero hero = heroes.getCharacterManager().getHero(event.getPlayer());
|
||||
|
||||
if (hero.hasParty()) {
|
||||
hero.getParty().gainExp(heroExp, HeroClass.ExperienceType.EXTERNAL, event.getPlayer().getLocation());
|
||||
} else {
|
||||
hero.gainExp(heroExp, HeroClass.ExperienceType.EXTERNAL);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Events.ProtectBlockEvent;
|
||||
import com.Acrobot.ChestShop.Events.ProtectionCheckEvent;
|
||||
import com.griefcraft.lwc.LWC;
|
||||
import com.griefcraft.model.Protection;
|
||||
import com.griefcraft.modules.limits.LimitsV2;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class LightweightChestProtection implements Listener {
|
||||
private LWC lwc;
|
||||
private LimitsV2 limitsModule;
|
||||
|
||||
public LightweightChestProtection(LWC lwc) {
|
||||
this.lwc = lwc;
|
||||
limitsModule = new LimitsV2();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProtectionCheck(ProtectionCheckEvent event) {
|
||||
if (event.getResult() == Event.Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Protection protection = lwc.findProtection(block);
|
||||
|
||||
if (protection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!lwc.canAccessProtection(player, protection)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockProtect(ProtectBlockEvent event) {
|
||||
if (event.isProtected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
Player player = Bukkit.getPlayer(event.getName());
|
||||
|
||||
if (player == null || limitsModule.hasReachedLimit(player, block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
String worldName = block.getWorld().getName();
|
||||
|
||||
Protection protection = lwc.getPhysicalDatabase().registerProtection(block.getTypeId(), Protection.Type.PRIVATE, worldName, event.getName(), "", x, y, z);
|
||||
|
||||
if (protection != null) {
|
||||
event.setProtected(true);
|
||||
}
|
||||
}
|
||||
}
|
34
com/Acrobot/ChestShop/Plugins/Lockette.java
Normal file
34
com/Acrobot/ChestShop/Plugins/Lockette.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Events.ProtectionCheckEvent;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Lockette implements Listener {
|
||||
@EventHandler
|
||||
public static void onProtectionCheck(ProtectionCheckEvent event) {
|
||||
if (event.getResult() == Event.Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!org.yi.acru.bukkit.Lockette.Lockette.isProtected(block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String shortPlayerName = uName.shortenName(player);
|
||||
|
||||
if (!org.yi.acru.bukkit.Lockette.Lockette.isUser(block, shortPlayerName, true)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
}
|
40
com/Acrobot/ChestShop/Plugins/SimpleChestLock.java
Normal file
40
com/Acrobot/ChestShop/Plugins/SimpleChestLock.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Events.ProtectionCheckEvent;
|
||||
import com.webkonsept.bukkit.simplechestlock.SCL;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class SimpleChestLock implements Listener {
|
||||
private SCL scl;
|
||||
|
||||
public SimpleChestLock(SCL scl) {
|
||||
this.scl = scl;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProtectionCheck(ProtectionCheckEvent event) {
|
||||
if (event.getResult() == Event.Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!scl.chests.isLocked(block)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String playerName = player.getName();
|
||||
|
||||
if (!scl.chests.getOwner(block).equals(playerName)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
}
|
104
com/Acrobot/ChestShop/Plugins/Towny.java
Normal file
104
com/Acrobot/ChestShop/Plugins/Towny.java
Normal file
@ -0,0 +1,104 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Events.BuildPermissionEvent;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.TownBlockOwner;
|
||||
import com.palmergames.bukkit.towny.object.TownBlockType;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Towny implements Listener {
|
||||
@EventHandler
|
||||
public static void canBuild(BuildPermissionEvent event) {
|
||||
Location chest = event.getChest();
|
||||
Location sign = event.getSign();
|
||||
|
||||
if (isInWilderness(chest, sign) || !isInsideShopPlot(chest, sign)) {
|
||||
event.disallow();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean allow;
|
||||
|
||||
if (Config.getBoolean(Property.TOWNY_SHOPS_FOR_OWNERS_ONLY)) {
|
||||
allow = isPlotOwner(event.getPlayer(), chest, sign);
|
||||
} else {
|
||||
allow = isResident(event.getPlayer(), chest, sign);
|
||||
}
|
||||
|
||||
event.allow(allow);
|
||||
}
|
||||
|
||||
private static boolean isResident(Player player, Location location) throws NotRegisteredException {
|
||||
return TownyUniverse.getTownBlock(location).getTown().hasResident(player.getName());
|
||||
}
|
||||
|
||||
private static boolean isResident(Player player, Location... locations) {
|
||||
try {
|
||||
for (Location location : locations) {
|
||||
if (!isResident(player, location)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException exception) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isPlotOwner(Player player, Location location) throws NotRegisteredException {
|
||||
TownBlockOwner owner = TownyUniverse.getDataSource().getResident(player.getName());
|
||||
return TownyUniverse.getTownBlock(location).isOwner(owner);
|
||||
}
|
||||
|
||||
private static boolean isPlotOwner(Player player, Location... locations) {
|
||||
try {
|
||||
for (Location location : locations) {
|
||||
if (!isPlotOwner(player, location)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException exception) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isInsideShopPlot(Location location) {
|
||||
return TownyUniverse.getTownBlock(location).getType() == TownBlockType.COMMERCIAL;
|
||||
}
|
||||
|
||||
private static boolean isInsideShopPlot(Location... locations) {
|
||||
for (Location location : locations) {
|
||||
if (!isInsideShopPlot(location)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isInWilderness(Location location) {
|
||||
return TownyUniverse.isWilderness(location.getBlock());
|
||||
}
|
||||
|
||||
private static boolean isInWilderness(Location... locations) {
|
||||
for (Location location : locations) {
|
||||
if (!isInWilderness(location)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
101
com/Acrobot/ChestShop/Plugins/WorldGuardBuilding.java
Normal file
101
com/Acrobot/ChestShop/Plugins/WorldGuardBuilding.java
Normal file
@ -0,0 +1,101 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Events.BuildPermissionEvent;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class WorldGuardBuilding implements Listener {
|
||||
private WorldGuardPlugin worldGuard;
|
||||
|
||||
public WorldGuardBuilding(WorldGuardPlugin plugin) {
|
||||
this.worldGuard = plugin;
|
||||
|
||||
if (Config.getBoolean(Property.WORLDGUARD_USE_FLAG)) {
|
||||
ChestShopFlag.injectHax();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void canBuild(BuildPermissionEvent event) {
|
||||
ApplicableRegionSet regions = getApplicableRegions(event.getSign().getBlock().getLocation());
|
||||
|
||||
if (Config.getBoolean(Property.WORLDGUARD_USE_FLAG)) {
|
||||
event.allow(ChestShopFlag.setAllowsFlag(regions));
|
||||
} else {
|
||||
event.allow(regions.size() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicableRegionSet getApplicableRegions(Location location) {
|
||||
return worldGuard.getGlobalRegionManager().get(location.getWorld()).getApplicableRegions(BukkitUtil.toVector(location));
|
||||
}
|
||||
|
||||
public static class ChestShopFlag extends StateFlag {
|
||||
public static ChestShopFlag flag = new ChestShopFlag();
|
||||
|
||||
public ChestShopFlag() {
|
||||
super("chestshop", false);
|
||||
}
|
||||
|
||||
public static boolean setAllowsFlag(ApplicableRegionSet set) {
|
||||
return set.allows(flag);
|
||||
}
|
||||
|
||||
private static List elements() {
|
||||
List<Flag> elements = new ArrayList(Arrays.asList(DefaultFlag.getFlags()));
|
||||
elements.add(flag);
|
||||
return elements;
|
||||
}
|
||||
|
||||
public static void injectHax() {
|
||||
try {
|
||||
Field field = DefaultFlag.class.getDeclaredField("flagsList");
|
||||
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
List<Flag> elements = elements();
|
||||
|
||||
Flag<?> list[] = new Flag<?>[elements.size()];
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
list[i] = elements.get(i);
|
||||
}
|
||||
|
||||
field.set(null, list);
|
||||
|
||||
Field grm = WorldGuardPlugin.class.getDeclaredField("globalRegionManager");
|
||||
grm.setAccessible(true);
|
||||
GlobalRegionManager globalRegionManager = (GlobalRegionManager) grm.get(ChestShop.getBukkitServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
|
||||
globalRegionManager.preload();
|
||||
|
||||
} catch (Exception e) {
|
||||
ChestShop.getBukkitLogger().severe("Oh noes! Something wrong happened! Be sure to paste that in your bug report:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
com/Acrobot/ChestShop/Plugins/WorldGuardProtection.java
Normal file
50
com/Acrobot/ChestShop/Plugins/WorldGuardProtection.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.Acrobot.ChestShop.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Events.ProtectionCheckEvent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class WorldGuardProtection implements Listener {
|
||||
private WorldGuardPlugin worldGuard;
|
||||
|
||||
public WorldGuardProtection(WorldGuardPlugin worldGuard) {
|
||||
this.worldGuard = worldGuard;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProtectionCheck(ProtectionCheckEvent event) {
|
||||
if (event.getResult() == Event.Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Vector blockPos = BukkitUtil.toVector(block);
|
||||
RegionManager manager = worldGuard.getRegionManager(block.getWorld());
|
||||
ApplicableRegionSet set = manager.getApplicableRegions(blockPos);
|
||||
|
||||
LocalPlayer localPlayer = worldGuard.wrapPlayer(player);
|
||||
|
||||
if (!canAccess(localPlayer, block, set)) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canAccess(LocalPlayer player, Block block, ApplicableRegionSet set) {
|
||||
return worldGuard.getGlobalRegionManager().hasBypass(player, block.getWorld()) || set.canBuild(player) || set.allows(DefaultFlag.CHEST_ACCESS, player);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Protection.Protection;
|
||||
import com.daemitus.deadbolt.Deadbolt;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class DeadboltPlugin implements Protection {
|
||||
public boolean isProtected(Block block) {
|
||||
return Deadbolt.isProtected(block);
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
int length = (player.getName().length() > 15 ? 15 : player.getName().length());
|
||||
return Deadbolt.getAllNames(block).contains(player.getName().substring(0, length));
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Protection.Protection;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Default implements Protection {
|
||||
public boolean isProtected(Block block) {
|
||||
if (!(block.getState() instanceof Chest)) return false;
|
||||
if (uBlock.findSign2(block) != null) return true;
|
||||
|
||||
Chest neighbor = uBlock.findNeighbor(block);
|
||||
return neighbor != null && uBlock.findSign2(neighbor.getBlock()) != null;
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
String playerName = player.getName();
|
||||
|
||||
Sign sign = uBlock.findSign2(block);
|
||||
|
||||
if (sign != null) return uLongName.stripName(playerName).equals(sign.getLine(0))
|
||||
|| Permission.otherName(player, sign.getLine(0));
|
||||
|
||||
Chest neighborChest = uBlock.findNeighbor(block);
|
||||
Sign neighborSign = (neighborChest != null ? uBlock.findSign2(neighborChest.getBlock()) : null);
|
||||
|
||||
return neighborSign == null
|
||||
|| uLongName.stripName(playerName).equals(neighborSign.getLine(0))
|
||||
|| Permission.otherName(player, neighborSign.getLine(0));
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Protection.Protection;
|
||||
import com.griefcraft.lwc.LWC;
|
||||
import com.griefcraft.modules.limits.LimitsModule;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class LWCplugin implements Protection {
|
||||
public LWC lwc;
|
||||
private LimitsModule limitsModule;
|
||||
|
||||
|
||||
public LWCplugin(LWC lwc) {
|
||||
this.lwc = lwc;
|
||||
limitsModule = new LimitsModule();
|
||||
}
|
||||
|
||||
public boolean isProtected(Block block) {
|
||||
return lwc.findProtection(block) != null;
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
return lwc.findProtection(block) == null || lwc.canAccessProtection(player, block);
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
if (lwc.findProtection(block) != null) return false;
|
||||
Player player = ChestShop.getBukkitServer().getPlayer(name);
|
||||
if (player != null && limitsModule.hasReachedLimit(player, block)) return false;
|
||||
|
||||
lwc.getPhysicalDatabase().registerProtection(block.getTypeId(), com.griefcraft.model.Protection.Type.PRIVATE, block.getWorld().getName(), name, "", block.getX(), block.getY(), block.getZ());
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Protection.Protection;
|
||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.yi.acru.bukkit.Lockette.Lockette;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class LockettePlugin implements Protection {
|
||||
public Lockette lockette;
|
||||
|
||||
public LockettePlugin(Lockette lockette) {
|
||||
this.lockette = lockette;
|
||||
}
|
||||
|
||||
public boolean isProtected(Block block) {
|
||||
return Lockette.isProtected(block);
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
String pName = player.getName();
|
||||
|
||||
String owner = Lockette.getProtectedOwner(block);
|
||||
return owner == null || owner.equals(uLongName.stripName(pName));
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Protection.Protection;
|
||||
import com.webkonsept.bukkit.simplechestlock.SCL;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class SCLplugin implements Protection {
|
||||
public SCL scl;
|
||||
|
||||
public SCLplugin(SCL scl) {
|
||||
this.scl = scl;
|
||||
}
|
||||
|
||||
public boolean isProtected(Block block) {
|
||||
return scl.chests.isLocked(block);
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
return scl.chests.getOwner(block).equalsIgnoreCase(player.getName());
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection.Plugins;
|
||||
|
||||
import com.Acrobot.ChestShop.Protection.Protection;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class WorldGuardProtectionPlugin implements Protection {
|
||||
private WorldGuardPlugin plugin;
|
||||
|
||||
public WorldGuardProtectionPlugin(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public boolean isProtected(Block block) {
|
||||
Vector pt = BukkitUtil.toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
|
||||
return !set.allows(DefaultFlag.CHEST_ACCESS);
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
Vector pt = BukkitUtil.toVector(block);
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
|
||||
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
|
||||
LocalPlayer locPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
return plugin.getGlobalRegionManager().hasBypass(locPlayer, block.getWorld()) || set.canBuild(locPlayer) || set.allows(DefaultFlag.CHEST_ACCESS, locPlayer);
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection;
|
||||
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public interface Protection {
|
||||
public boolean isProtected(Block block);
|
||||
|
||||
public boolean canAccess(Player player, Block block);
|
||||
|
||||
public boolean protect(String name, Block block);
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Protection;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Listeners.blockBreak;
|
||||
import com.Acrobot.ChestShop.Protection.Plugins.Default;
|
||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Security {
|
||||
private static final BlockFace[] faces = {BlockFace.UP, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
|
||||
private static final BlockFace[] blockFaces = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
|
||||
public static ArrayList<Protection> protections = new ArrayList<Protection>();
|
||||
private static Default defaultProtection = new Default();
|
||||
|
||||
public static Default getDefaultProtection() {
|
||||
return defaultProtection;
|
||||
}
|
||||
|
||||
public static boolean protect(String name, Block block) {
|
||||
boolean works = false;
|
||||
for (int i = 0; i < protections.size() && !works; i++){
|
||||
works = protections.get(i).protect(name, block);
|
||||
}
|
||||
return works;
|
||||
}
|
||||
|
||||
public static boolean canAccess(Player player, Block block) {
|
||||
boolean works = true;
|
||||
for (int i = 0; i < protections.size() && works; i++){
|
||||
works = protections.get(i).canAccess(player, block);
|
||||
}
|
||||
return works;
|
||||
}
|
||||
|
||||
public static boolean isProtected(Block block) {
|
||||
boolean isProt = false;
|
||||
for (int i = 0; i < protections.size() && !isProt; i++){
|
||||
isProt = protections.get(i).isProtected(block);
|
||||
}
|
||||
return isProt;
|
||||
}
|
||||
|
||||
public static boolean canPlaceSign(Player p, Sign sign) {
|
||||
return !anotherShopFound(blockBreak.getAttachedFace(sign), sign.getBlock(), p) && canBePlaced(p, sign.getBlock());
|
||||
}
|
||||
|
||||
private static boolean canBePlaced(Player p, Block signBlock) {
|
||||
for (BlockFace bf : blockFaces) {
|
||||
Block block = signBlock.getRelative(bf);
|
||||
|
||||
if (block.getType() != Material.CHEST) continue;
|
||||
if (isProtected(block) && !canAccess(p, block)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean anotherShopFound(Block baseBlock, Block signBlock, Player p) {
|
||||
String shortName = uLongName.stripName(p.getName());
|
||||
if (Config.getBoolean(Property.ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK)) return false;
|
||||
|
||||
for (BlockFace bf : faces) {
|
||||
Block block = baseBlock.getRelative(bf);
|
||||
|
||||
if (!uSign.isSign(block)) continue;
|
||||
|
||||
Sign s = (Sign) block.getState();
|
||||
if (uSign.isValid(s) && !block.equals(signBlock) && blockBreak.getAttachedFace(s).equals(baseBlock) && !s.getLine(0).equals(shortName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
72
com/Acrobot/ChestShop/Security.java
Normal file
72
com/Acrobot/ChestShop/Security.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.Acrobot.ChestShop;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Events.ProtectBlockEvent;
|
||||
import com.Acrobot.ChestShop.Events.ProtectionCheckEvent;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class Security {
|
||||
private static final BlockFace[] faces = {BlockFace.UP, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
|
||||
private static final BlockFace[] blockFaces = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH};
|
||||
|
||||
public static boolean protect(String playerName, Block block) {
|
||||
ProtectBlockEvent event = new ProtectBlockEvent(block, playerName);
|
||||
ChestShop.callEvent(event);
|
||||
|
||||
return event.isProtected();
|
||||
}
|
||||
|
||||
public static boolean canAccess(Player player, Block block) {
|
||||
ProtectionCheckEvent event = new ProtectionCheckEvent(block, player);
|
||||
ChestShop.callEvent(event);
|
||||
|
||||
return event.getResult() != Event.Result.DENY;
|
||||
}
|
||||
|
||||
public static boolean canPlaceSign(Player p, Sign sign) {
|
||||
return !anotherShopFound(uBlock.getAttachedFace(sign), sign.getBlock(), p) && canBePlaced(p, sign.getBlock());
|
||||
}
|
||||
|
||||
private static boolean canBePlaced(Player player, Block signBlock) {
|
||||
for (BlockFace bf : blockFaces) {
|
||||
Block block = signBlock.getRelative(bf);
|
||||
|
||||
if (block.getType() != Material.CHEST) {
|
||||
continue;
|
||||
}
|
||||
if (!canAccess(player, block)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean anotherShopFound(Block baseBlock, Block signBlock, Player p) {
|
||||
String shortName = uName.stripName(p.getName());
|
||||
if (Config.getBoolean(Property.ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK)) return false;
|
||||
|
||||
for (BlockFace bf : faces) {
|
||||
Block block = baseBlock.getRelative(bf);
|
||||
|
||||
if (!uSign.isSign(block)) continue;
|
||||
|
||||
Sign s = (Sign) block.getState();
|
||||
if (uSign.isValid(s) && !block.equals(signBlock) && uBlock.getAttachedFace(s).equals(baseBlock) && !s.getLine(0).equals(shortName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
package com.Acrobot.ChestShop.Shop;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Containers.Container;
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Language;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Containers.Container;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Logging.Logging;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Utils.uInventory;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -35,25 +36,28 @@ public class Shop {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public void buy(Player player) {
|
||||
public void buyItemFrom(Player player) {
|
||||
double buyPrice = uSign.buyPrice(sign.getLine(2));
|
||||
if (chest == null && !isAdminShop()) {
|
||||
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
||||
|
||||
if (chest == null) {
|
||||
sendMessage(player, Language.NO_CHEST_DETECTED);
|
||||
return;
|
||||
}
|
||||
if (buyPrice == -1) {
|
||||
player.sendMessage(Config.getLocal(Language.NO_BUYING_HERE));
|
||||
if (Double.compare(buyPrice, 0.01D) < 0) {
|
||||
sendMessage(player, Language.NO_BUYING_HERE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Permission.has(player, Permission.BUY) && !Permission.has(player, Permission.BUY_ID + Integer.toString(stock.getTypeId()))) {
|
||||
player.sendMessage(Config.getLocal(Language.NO_PERMISSION));
|
||||
sendMessage(player, Language.NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
String playerName = player.getName();
|
||||
|
||||
if (!Economy.hasEnough(playerName, buyPrice)) {
|
||||
int items = calculateItemAmount(Economy.balance(playerName), buyPrice);
|
||||
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY));
|
||||
sendMessage(player, Language.NOT_ENOUGH_MONEY);
|
||||
return;
|
||||
} else {
|
||||
buyPrice = (buyPrice / stockAmount) * items;
|
||||
@ -61,18 +65,21 @@ public class Shop {
|
||||
}
|
||||
}
|
||||
if (!stockFitsPlayer(player)) {
|
||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_INVENTORY));
|
||||
sendMessage(player, Language.NOT_ENOUGH_SPACE_IN_INVENTORY);
|
||||
return;
|
||||
}
|
||||
|
||||
String materialName = uSign.capitalizeFirst(stock.getType().name());
|
||||
String materialName = uSign.capitalizeFirstLetter(stock.getType().name());
|
||||
|
||||
if (!isAdminShop() && !hasEnoughStock()) {
|
||||
if (!hasEnoughStock()) {
|
||||
int items = stockAmount(stock, durability);
|
||||
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_STOCK));
|
||||
sendMessage(player, Language.NOT_ENOUGH_STOCK);
|
||||
|
||||
if (!Config.getBoolean(Property.SHOW_MESSAGE_OUT_OF_STOCK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Config.getBoolean(Property.SHOW_MESSAGE_OUT_OF_STOCK)) return;
|
||||
sendMessageToOwner(Config.getLocal(Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP).replace("%material", materialName));
|
||||
return;
|
||||
} else {
|
||||
@ -81,23 +88,18 @@ public class Shop {
|
||||
}
|
||||
}
|
||||
|
||||
String account = getOwnerAccount();
|
||||
if (!account.isEmpty() && Economy.hasAccount(account)) {
|
||||
if (!isAdminShop()) Economy.add(account, buyPrice);
|
||||
else Economy.addServer(account, buyPrice);
|
||||
}
|
||||
|
||||
Economy.add(getOwnerAccount(), buyPrice);
|
||||
Economy.subtract(playerName, buyPrice);
|
||||
|
||||
if (!isAdminShop()) chest.removeItem(stock, durability, stockAmount);
|
||||
chest.removeItem(stock, durability, stockAmount);
|
||||
|
||||
|
||||
String formatedPrice = Economy.formatBalance(buyPrice);
|
||||
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_CLIENT)) {
|
||||
player.sendMessage(Config.getLocal(Language.YOU_BOUGHT_FROM_SHOP)
|
||||
.replace("%amount", String.valueOf(stockAmount))
|
||||
.replace("%item", materialName)
|
||||
.replace("%owner", owner)
|
||||
.replace("%price", formatedPrice));
|
||||
String message = formatMessage(Language.YOU_BOUGHT_FROM_SHOP, materialName, formatedPrice);
|
||||
message = message.replace("%owner", owner);
|
||||
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
uInventory.add(player.getInventory(), stock, stockAmount);
|
||||
@ -105,37 +107,39 @@ public class Shop {
|
||||
player.updateInventory();
|
||||
|
||||
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_OWNER)) {
|
||||
sendMessageToOwner(Config.getLocal(Language.SOMEBODY_BOUGHT_FROM_YOUR_SHOP)
|
||||
.replace("%amount", String.valueOf(stockAmount))
|
||||
.replace("%item", materialName)
|
||||
.replace("%buyer", playerName)
|
||||
.replace("%price", formatedPrice));
|
||||
String message = formatMessage(Language.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, materialName, formatedPrice);
|
||||
message = message.replace("%buyer", player.getName());
|
||||
|
||||
sendMessageToOwner(message);
|
||||
}
|
||||
|
||||
if (shopShouldBeRemoved()) {
|
||||
removeShop();
|
||||
}
|
||||
}
|
||||
|
||||
public void sell(Player player) {
|
||||
public void sellItemTo(Player player) {
|
||||
double sellPrice = uSign.sellPrice(sign.getLine(2));
|
||||
|
||||
if (chest == null && !isAdminShop()) {
|
||||
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
||||
if (chest == null) {
|
||||
sendMessage(player, Language.NO_CHEST_DETECTED);
|
||||
return;
|
||||
}
|
||||
if (sellPrice == -1) {
|
||||
player.sendMessage(Config.getLocal(Language.NO_SELLING_HERE));
|
||||
if (Double.compare(sellPrice, 0.01D) < 0) {
|
||||
sendMessage(player, Language.NO_SELLING_HERE);
|
||||
return;
|
||||
}
|
||||
if (!Permission.has(player, Permission.SELL) && !Permission.has(player, Permission.SELL_ID + Integer.toString(stock.getTypeId()))) {
|
||||
player.sendMessage(Config.getLocal(Language.NO_PERMISSION));
|
||||
sendMessage(player, Language.NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
String account = getOwnerAccount();
|
||||
boolean accountExists = !account.isEmpty() && Economy.hasAccount(account);
|
||||
|
||||
if (accountExists && !Economy.hasEnough(account, sellPrice)) {
|
||||
if (!Economy.hasEnough(account, sellPrice)) {
|
||||
int items = calculateItemAmount(Economy.balance(account), sellPrice);
|
||||
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY_SHOP));
|
||||
sendMessage(player, Language.NOT_ENOUGH_MONEY_SHOP);
|
||||
return;
|
||||
} else {
|
||||
sellPrice = (sellPrice / stockAmount) * items;
|
||||
@ -145,7 +149,7 @@ public class Shop {
|
||||
if (uInventory.amount(player.getInventory(), stock, durability) < stockAmount) {
|
||||
int items = uInventory.amount(player.getInventory(), stock, durability);
|
||||
if (!Config.getBoolean(Property.ALLOW_PARTIAL_TRANSACTIONS) || items < 1) {
|
||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_ITEMS_TO_SELL));
|
||||
sendMessage(player, Language.NOT_ENOUGH_ITEMS_TO_SELL);
|
||||
return;
|
||||
} else {
|
||||
sellPrice = (sellPrice / stockAmount) * items;
|
||||
@ -153,43 +157,63 @@ public class Shop {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAdminShop() && !stockFitsChest(chest)) {
|
||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_CHEST));
|
||||
if (!stockFitsChest(chest)) {
|
||||
sendMessage(player, Language.NOT_ENOUGH_SPACE_IN_CHEST);
|
||||
return;
|
||||
}
|
||||
|
||||
if (accountExists) Economy.subtract(account, sellPrice);
|
||||
if (!isAdminShop()) chest.addItem(stock, stockAmount);
|
||||
Economy.subtract(account, sellPrice);
|
||||
Economy.add(player.getName(), sellPrice);
|
||||
|
||||
if (!isAdminShop()) Economy.add(player.getName(), sellPrice);
|
||||
else Economy.addServer(player.getName(), sellPrice);
|
||||
chest.addItem(stock, stockAmount);
|
||||
|
||||
String materialName = uSign.capitalizeFirst(stock.getType().name());
|
||||
String materialName = uSign.capitalizeFirstLetter(stock.getType().name());
|
||||
String formatedBalance = Economy.formatBalance(sellPrice);
|
||||
|
||||
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_CLIENT)) {
|
||||
player.sendMessage(Config.getLocal(Language.YOU_SOLD_TO_SHOP)
|
||||
.replace("%amount", String.valueOf(stockAmount))
|
||||
.replace("%item", materialName)
|
||||
.replace("%buyer", owner)
|
||||
.replace("%price", formatedBalance));
|
||||
String message = formatMessage(Language.YOU_SOLD_TO_SHOP, materialName, formatedBalance);
|
||||
message = message.replace("%buyer", owner);
|
||||
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
uInventory.remove(player.getInventory(), stock, stockAmount, durability);
|
||||
|
||||
Logging.logTransaction(false, this, sellPrice, player);
|
||||
|
||||
player.updateInventory();
|
||||
|
||||
if (Config.getBoolean(Property.SHOW_TRANSACTION_INFORMATION_OWNER)) {
|
||||
sendMessageToOwner(Config.getLocal(Language.SOMEBODY_SOLD_TO_YOUR_SHOP)
|
||||
.replace("%amount", String.valueOf(stockAmount))
|
||||
.replace("%item", materialName)
|
||||
.replace("%seller", player.getName())
|
||||
.replace("%price", formatedBalance));
|
||||
String message = formatMessage(Language.SOMEBODY_SOLD_TO_YOUR_SHOP, materialName, formatedBalance);
|
||||
message = message.replace("%seller", player.getName());
|
||||
|
||||
sendMessageToOwner(message);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shopShouldBeRemoved() {
|
||||
return Config.getBoolean(Property.REMOVE_EMPTY_SHOPS) && shopIsEmpty();
|
||||
}
|
||||
|
||||
private boolean shopIsEmpty() {
|
||||
return chest.isEmpty();
|
||||
}
|
||||
|
||||
private void removeShop() {
|
||||
sign.getBlock().setType(Material.AIR);
|
||||
|
||||
chest.addItem(new ItemStack(Material.SIGN, 1), 1);
|
||||
}
|
||||
|
||||
private String formatMessage(Language message, String materialName, String price) {
|
||||
return Config.getLocal(message)
|
||||
.replace("%amount", String.valueOf(stockAmount))
|
||||
.replace("%item", materialName)
|
||||
.replace("%price", price);
|
||||
}
|
||||
|
||||
private String getOwnerAccount() {
|
||||
return uSign.isAdminShop(owner) ? Config.getString(Property.SERVER_ECONOMY_ACCOUNT) : owner;
|
||||
return isAdminShop() ? Config.getString(Property.SERVER_ECONOMY_ACCOUNT) : owner;
|
||||
}
|
||||
|
||||
private boolean isAdminShop() {
|
||||
@ -216,6 +240,10 @@ public class Shop {
|
||||
return (int) Math.floor(money / (basePrice / stockAmount));
|
||||
}
|
||||
|
||||
private static void sendMessage(Player player, Language message) {
|
||||
player.sendMessage(Config.getLocal(message));
|
||||
}
|
||||
|
||||
private void sendMessageToOwner(String msg) {
|
||||
if (!isAdminShop()) {
|
||||
Player player = ChestShop.getBukkitServer().getPlayer(owner);
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.Acrobot.ChestShop.Shop;
|
||||
|
||||
import com.Acrobot.ChestShop.Containers.AdminChest;
|
||||
import com.Acrobot.ChestShop.Containers.MinecraftChest;
|
||||
import com.Acrobot.ChestShop.Items.Items;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import com.Acrobot.ChestShop.Utils.uSign;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
@ -13,29 +15,34 @@ import org.bukkit.inventory.ItemStack;
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ShopManagement {
|
||||
public static boolean useOldChest = false;
|
||||
|
||||
public static void buy(Sign sign, Player player) {
|
||||
Shop shop = getShop(sign, player);
|
||||
if (shop != null) {
|
||||
shop.buy(player);
|
||||
shop.buyItemFrom(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sell(Sign sign, Player player) {
|
||||
Shop shop = getShop(sign, player);
|
||||
if (shop != null) {
|
||||
shop.sell(player);
|
||||
shop.sellItemTo(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop getShop(Sign sign, Player player) {
|
||||
Chest chestMc = uBlock.findChest(sign);
|
||||
Chest chestMc = uBlock.findConnectedChest(sign);
|
||||
ItemStack item = Items.getItemStack(sign.getLine(3));
|
||||
|
||||
if (item == null) {
|
||||
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (uSign.isAdminShop(sign.getLine(0))) {
|
||||
return new Shop(new AdminChest(), sign, item);
|
||||
} else {
|
||||
return new Shop(chestMc != null ? new MinecraftChest(chestMc) : null, sign, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,10 +41,14 @@ public class restrictedSign {
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Player p, String[] lines) {
|
||||
if (Permission.has(p, Permission.ADMIN)) return true;
|
||||
if (Permission.has(p, Permission.ADMIN)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
if (p.hasPermission(Permission.GROUP.toString() + lines[i])) return true;
|
||||
for (String line : lines) {
|
||||
if (p.hasPermission(Permission.GROUP.toString() + line)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Utils.WorldGuard;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ChestShopFlag extends StateFlag {
|
||||
public static ChestShopFlag flag = new ChestShopFlag();
|
||||
|
||||
public ChestShopFlag() {
|
||||
super("chestshop", false);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Utils.WorldGuard;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.GlobalRegionManager;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class JavaWorkaround {
|
||||
public static boolean setAllowsFlag(ApplicableRegionSet set) {
|
||||
return set.allows(ChestShopFlag.flag);
|
||||
}
|
||||
|
||||
private static List elements() {
|
||||
List<Flag> elements = new ArrayList(Arrays.asList(DefaultFlag.getFlags()));
|
||||
elements.add(ChestShopFlag.flag);
|
||||
return elements;
|
||||
}
|
||||
|
||||
public static void injectHax() {
|
||||
try {
|
||||
Field field = DefaultFlag.class.getDeclaredField("flagsList");
|
||||
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
List<Flag> elements = elements();
|
||||
|
||||
Flag<?> list[] = new Flag<?>[elements.size()];
|
||||
for (int i = 0; i < elements.size(); i++) {
|
||||
list[i] = elements.get(i);
|
||||
}
|
||||
|
||||
field.set(null, list);
|
||||
|
||||
Field grm = WorldGuardPlugin.class.getDeclaredField("globalRegionManager");
|
||||
grm.setAccessible(true);
|
||||
GlobalRegionManager globalRegionManager = (GlobalRegionManager) grm.get(ChestShop.getBukkitServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
|
||||
globalRegionManager.preload();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println(ChestShop.chatPrefix + "Oh noes! Something wrong happened! Be sure to paste that in your bug report:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Utils.WorldGuard;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.sk89q.worldguard.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class uWorldGuard {
|
||||
public static WorldGuardPlugin wg;
|
||||
|
||||
public static void injectHax() {
|
||||
if (!Config.getBoolean(Property.WORLDGUARD_INTEGRATION) || wg == null) return;
|
||||
|
||||
JavaWorkaround.injectHax();
|
||||
}
|
||||
|
||||
public static boolean canBuildShopHere(Location loc) {
|
||||
return !turnedOn() || canCreateShops(getRegions(loc));
|
||||
|
||||
}
|
||||
|
||||
public static boolean canCreateShops(ApplicableRegionSet set) {
|
||||
if (Config.getBoolean(Property.WORLDGUARD_USE_FLAG)) {
|
||||
return JavaWorkaround.setAllowsFlag(set);
|
||||
} else {
|
||||
return set.size() != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static ApplicableRegionSet getRegions(Location loc) {
|
||||
return wg.getGlobalRegionManager().get(loc.getWorld()).getApplicableRegions(BukkitUtil.toVector(loc));
|
||||
}
|
||||
|
||||
private static boolean turnedOn() {
|
||||
return wg != null && Config.getBoolean(Property.WORLDGUARD_INTEGRATION);
|
||||
}
|
||||
}
|
@ -1,65 +1,71 @@
|
||||
package com.Acrobot.ChestShop.Utils;
|
||||
|
||||
import com.Acrobot.ChestShop.Listeners.blockBreak;
|
||||
import com.Acrobot.ChestShop.Signs.restrictedSign;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.material.Attachable;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class uBlock {
|
||||
|
||||
private static final BlockFace[] chestFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
|
||||
private static final BlockFace[] shopFaces = {BlockFace.SELF, BlockFace.DOWN, BlockFace.UP, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
|
||||
|
||||
public static Chest findChest(Sign sign) {
|
||||
public static Chest findConnectedChest(Sign sign) {
|
||||
Block block = sign.getBlock();
|
||||
return findChest(block);
|
||||
return findConnectedChest(block);
|
||||
}
|
||||
|
||||
public static Chest findChest(Block block) {
|
||||
public static Chest findConnectedChest(Block block) {
|
||||
for (BlockFace bf : shopFaces) {
|
||||
Block faceBlock = block.getRelative(bf);
|
||||
if (faceBlock.getType() == Material.CHEST) return (Chest) faceBlock.getState();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void blockUpdate(Block block) {
|
||||
for (BlockFace bf : shopFaces) {
|
||||
block.getRelative(bf).getState().update(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static Sign findSign(Block block, String originalName) {
|
||||
for (BlockFace bf : shopFaces) {
|
||||
Block faceBlock = block.getRelative(bf);
|
||||
if (uSign.isSign(faceBlock)) {
|
||||
Sign sign = (Sign) faceBlock.getState();
|
||||
if (uSign.isValid(sign) && !sign.getLine(0).equals(originalName) && (faceBlock.equals(block) || blockBreak.getAttachedFace(sign).equals(block))) return sign;
|
||||
}
|
||||
}
|
||||
for (BlockFace bf : shopFaces) {
|
||||
Block faceBlock = block.getRelative(bf);
|
||||
if (uSign.isSign(faceBlock)) {
|
||||
Sign sign = (Sign) faceBlock.getState();
|
||||
if (uSign.isValid(sign) && (faceBlock.equals(block) || blockBreak.getAttachedFace(sign).equals(block))) return sign;
|
||||
if (faceBlock.getType() == Material.CHEST) {
|
||||
return (Chest) faceBlock.getState();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//Well, I need to re-write this plugin... I hate to code like that - sorry!
|
||||
public static Sign findSign2(Block block) {
|
||||
public static Sign findValidShopSign(Block block, String originalName) {
|
||||
Sign ownerShopSign = null;
|
||||
|
||||
for (BlockFace bf : shopFaces) {
|
||||
Block faceBlock = block.getRelative(bf);
|
||||
if (uSign.isSign(faceBlock)) {
|
||||
|
||||
if (!uSign.isSign(faceBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Sign sign = (Sign) faceBlock.getState();
|
||||
if (uSign.isValid(sign)) return sign;
|
||||
|
||||
if (uSign.isValid(sign) && signIsAttachedToBlock(sign, block)) {
|
||||
if (!sign.getLine(0).equals(originalName)) {
|
||||
return sign;
|
||||
} else if (ownerShopSign == null) {
|
||||
ownerShopSign = sign;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ownerShopSign;
|
||||
}
|
||||
|
||||
public static Sign findAnyNearbyShopSign(Block block) {
|
||||
for (BlockFace bf : shopFaces) {
|
||||
Block faceBlock = block.getRelative(bf);
|
||||
|
||||
if (!uSign.isSign(faceBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Sign sign = (Sign) faceBlock.getState();
|
||||
|
||||
if (uSign.isValid(sign)) {
|
||||
return sign;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -68,9 +74,15 @@ public class uBlock {
|
||||
public static Sign findRestrictedSign(Block block) {
|
||||
for (BlockFace bf : shopFaces) {
|
||||
Block faceBlock = block.getRelative(bf);
|
||||
if (uSign.isSign(faceBlock)) {
|
||||
|
||||
if (!uSign.isSign(faceBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Sign sign = (Sign) faceBlock.getState();
|
||||
if (restrictedSign.isRestricted(sign) && (faceBlock.equals(block) || blockBreak.getAttachedFace(sign).equals(block))) return sign;
|
||||
|
||||
if (restrictedSign.isRestricted(sign) && signIsAttachedToBlock(sign, block)) {
|
||||
return sign;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -86,7 +98,11 @@ public class uBlock {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Chest findNeighbor(Chest chest) {
|
||||
return findNeighbor(chest.getBlock());
|
||||
private static boolean signIsAttachedToBlock(Sign sign, Block block) {
|
||||
return sign.getBlock().equals(block) || getAttachedFace(sign).equals(block);
|
||||
}
|
||||
|
||||
public static Block getAttachedFace(Sign sign) {
|
||||
return sign.getBlock().getRelative(((Attachable) sign.getData()).getAttachedFace());
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ public class uEnchantment {
|
||||
|
||||
public static String encodeEnchantment(Map<Enchantment, Integer> map) {
|
||||
int integer = 0;
|
||||
for (Map.Entry<Enchantment, Integer> entry : map.entrySet()) {
|
||||
integer = integer * 1000 + (entry.getKey().getId()) * 10 + entry.getValue();
|
||||
for (Map.Entry<Enchantment, Integer> enchantment : map.entrySet()) {
|
||||
integer = integer * 1000 + (enchantment.getKey().getId()) * 10 + enchantment.getValue();
|
||||
}
|
||||
|
||||
if (integer == 0) return null;
|
||||
@ -26,14 +26,22 @@ public class uEnchantment {
|
||||
}
|
||||
|
||||
public static Map<Enchantment, Integer> decodeEnchantment(String base32) {
|
||||
if (base32 == null) return new HashMap<Enchantment, Integer>();
|
||||
Map<Enchantment, Integer> map = new HashMap<Enchantment, Integer>();
|
||||
|
||||
String integer = String.valueOf(Integer.parseInt(base32, 32));
|
||||
if (integer.length() < 3) integer = '0' + integer;
|
||||
if (base32 == null) {
|
||||
return map;
|
||||
}
|
||||
|
||||
for (int i = 0; i < integer.length() / 3; i++) {
|
||||
String item = integer.substring(i * 3, i * 3 + 3);
|
||||
StringBuilder integer = new StringBuilder(String.valueOf(Integer.parseInt(base32, 32)));
|
||||
|
||||
while (integer.length() % 3 != 0) {
|
||||
integer.insert(0, '0');
|
||||
}
|
||||
|
||||
String enchantment = integer.toString();
|
||||
|
||||
for (int i = 0; i < enchantment.length() / 3; i++) {
|
||||
String item = enchantment.substring(i * 3, i * 3 + 3);
|
||||
|
||||
Enchantment ench = Enchantment.getById(Integer.parseInt(item.substring(0, 2)));
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Utils;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.herocraftonline.heroes.Heroes;
|
||||
import com.herocraftonline.heroes.characters.Hero;
|
||||
import com.herocraftonline.heroes.characters.classes.HeroClass;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class uHeroes {
|
||||
public static Heroes heroes;
|
||||
|
||||
public static void addHeroExp(Player p) {
|
||||
if (heroes != null) {
|
||||
Hero hero = heroes.getCharacterManager().getHero(p);
|
||||
if (hero.hasParty()) {
|
||||
hero.getParty().gainExp(Config.getDouble(Property.HEROES_EXP), HeroClass.ExperienceType.EXTERNAL, p.getLocation());
|
||||
} else {
|
||||
hero.gainExp(Config.getDouble(Property.HEROES_EXP), HeroClass.ExperienceType.EXTERNAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -52,7 +52,10 @@ public class uInventory {
|
||||
|
||||
HashMap<Integer, ItemStack> items = inv.addItem(itemstack);
|
||||
amount = 0;
|
||||
for (ItemStack toAdd : items.values()) amount += toAdd.getAmount();
|
||||
|
||||
for (ItemStack toAdd : items.values()) {
|
||||
amount += toAdd.getAmount();
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
@ -87,11 +90,20 @@ public class uInventory {
|
||||
}
|
||||
|
||||
public static int amount(Inventory inv, ItemStack item, short durability) {
|
||||
if (!inv.contains(item.getType())) return 0;
|
||||
if (!inv.contains(item.getType())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
HashMap<Integer, ? extends ItemStack> items = inv.all(item.getType());
|
||||
|
||||
int amount = 0;
|
||||
for (ItemStack i : inv.getContents()) {
|
||||
if (equals(i, item, durability)) amount += i.getAmount();
|
||||
|
||||
for (ItemStack i : items.values()) {
|
||||
if (!equals(i, item, durability)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
amount += i.getAmount();
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
@ -102,7 +114,9 @@ public class uInventory {
|
||||
int amountLeft = amount;
|
||||
|
||||
for (ItemStack currentItem : inv.getContents()) {
|
||||
if (amountLeft <= 0) return 0;
|
||||
if (amountLeft <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (currentItem == null || currentItem.getType() == Material.AIR) {
|
||||
amountLeft -= maxStackSize;
|
||||
@ -111,9 +125,11 @@ public class uInventory {
|
||||
|
||||
int currentAmount = currentItem.getAmount();
|
||||
|
||||
if (currentAmount != maxStackSize && equals(currentItem, item, durability)) {
|
||||
amountLeft = currentAmount + amountLeft <= maxStackSize ? 0 : amountLeft - (maxStackSize - currentAmount);
|
||||
if (currentAmount == maxStackSize || !equals(currentItem, item, durability)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
amountLeft = currentAmount + amountLeft <= maxStackSize ? 0 : amountLeft - (maxStackSize - currentAmount);
|
||||
}
|
||||
|
||||
return amountLeft;
|
||||
|
@ -1,28 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Utils;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.ConfigObject;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class uLongName {
|
||||
public static YamlConfiguration config;
|
||||
public static File configFile;
|
||||
|
||||
public static String getName(final String shortName) {
|
||||
return config.getString(shortName, shortName);
|
||||
}
|
||||
|
||||
public static void saveName(String name) {
|
||||
if (name.length() != 16) return;
|
||||
config.set(name.substring(0, 15), name);
|
||||
ConfigObject.reloadConfig(config, configFile);
|
||||
}
|
||||
|
||||
public static String stripName(String name) {
|
||||
return (name.length() > 15 ? name.substring(0, 15) : name);
|
||||
}
|
||||
}
|
37
com/Acrobot/ChestShop/Utils/uName.java
Normal file
37
com/Acrobot/ChestShop/Utils/uName.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.Acrobot.ChestShop.Utils;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.BreezeConfiguration;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class uName {
|
||||
public static BreezeConfiguration config;
|
||||
|
||||
public static String getName(String shortName) {
|
||||
return config.getString(shortName, shortName);
|
||||
}
|
||||
|
||||
public static void saveName(String name) {
|
||||
if (name.length() <= 15) {
|
||||
return;
|
||||
}
|
||||
|
||||
config.set(stripName(name), name);
|
||||
config.reload();
|
||||
}
|
||||
|
||||
public static String stripName(String name) {
|
||||
return (name.length() > 15 ? name.substring(0, 15) : name);
|
||||
}
|
||||
|
||||
public static String shortenName(Player player) {
|
||||
return stripName(player.getName());
|
||||
}
|
||||
|
||||
public static boolean canUseName(Player player, String name) {
|
||||
return shortenName(player).equals(name) || Permission.otherName(player, name);
|
||||
}
|
||||
}
|
@ -32,4 +32,13 @@ public class uNumber {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShort(String string) {
|
||||
try {
|
||||
Short.parseShort(string);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package com.Acrobot.ChestShop.Utils;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,15 +12,13 @@ import java.util.regex.Pattern;
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class uSign {
|
||||
private static final Pattern[] patterns = {
|
||||
private static final Pattern[] signPattern = {
|
||||
Pattern.compile("^$|^\\w.+$"),
|
||||
Pattern.compile("[0-9]+"),
|
||||
Pattern.compile(".+"),
|
||||
Pattern.compile("[\\w : -]+")
|
||||
};
|
||||
|
||||
public static Towny towny; //Moved this here - somehow, java fails at try/catch
|
||||
|
||||
public static boolean isSign(Block block) {
|
||||
return block.getState() instanceof Sign;
|
||||
}
|
||||
@ -39,42 +35,52 @@ public class uSign {
|
||||
return isValidPreparedSign(line) && (line[2].contains("B") || line[2].contains("S")) && !line[0].isEmpty();
|
||||
}
|
||||
|
||||
public static boolean canAccess(Player p, Sign s) {
|
||||
if (p == null) return false;
|
||||
if (s == null) return true;
|
||||
public static boolean isValid(Block sign) {
|
||||
return isSign(sign) && isValid((Sign) sign.getState());
|
||||
}
|
||||
|
||||
String line = s.getLine(0);
|
||||
return uLongName.stripName(p.getName()).equals(line) || Permission.otherName(p, line);
|
||||
public static boolean canAccess(Player player, Sign sign) {
|
||||
if (player == null) return false;
|
||||
if (sign == null) return true;
|
||||
|
||||
return uName.canUseName(player, sign.getLine(0));
|
||||
}
|
||||
|
||||
public static boolean isValidPreparedSign(String[] lines) {
|
||||
boolean toReturn = true;
|
||||
for (int i = 0; i < 4 && toReturn; i++) toReturn = patterns[i].matcher(lines[i]).matches();
|
||||
return toReturn && lines[2].indexOf(':') == lines[2].lastIndexOf(':');
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!signPattern[i].matcher(lines[i]).matches()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return lines[2].indexOf(':') == lines[2].lastIndexOf(':');
|
||||
}
|
||||
|
||||
public static float buyPrice(String text) {
|
||||
return price(text, true);
|
||||
public static double buyPrice(String text) {
|
||||
return getPrice(text, 'b');
|
||||
}
|
||||
|
||||
public static float sellPrice(String text) {
|
||||
return price(text, false);
|
||||
public static double sellPrice(String text) {
|
||||
return getPrice(text, 's');
|
||||
}
|
||||
|
||||
private static float price(String text, boolean buy) {
|
||||
String toContain = buy ? "b" : "s";
|
||||
private static double getPrice(String text, char indicator) {
|
||||
String sign = String.valueOf(indicator);
|
||||
|
||||
text = text.replace(" ", "").toLowerCase();
|
||||
|
||||
String[] split = text.split(":");
|
||||
int part = (text.contains(toContain) ? (split[0].contains(toContain) ? 0 : 1) : -1);
|
||||
int part = (text.contains(sign) ? (split[0].contains(sign) ? 0 : 1) : -1);
|
||||
if (part == -1 || (part == 1 && split.length != 2)) return -1;
|
||||
|
||||
split[part] = split[part].replace(toContain, "");
|
||||
split[part] = split[part].replace(sign, "");
|
||||
|
||||
if (uNumber.isFloat(split[part])) {
|
||||
Float price = Float.parseFloat(split[part]);
|
||||
if (uNumber.isDouble(split[part])) {
|
||||
double price = Double.parseDouble(split[part]);
|
||||
return (price > 0 ? price : -1);
|
||||
} else if (split[part].equals("free")) return 0;
|
||||
} else if (split[part].equals("free")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -85,15 +91,18 @@ public class uSign {
|
||||
} else return 1;
|
||||
}
|
||||
|
||||
public static String capitalizeFirst(String name) {
|
||||
return capitalizeFirst(name, '_');
|
||||
public static String capitalizeFirstLetter(String name) {
|
||||
return capitalizeFirstLetter(name, '_');
|
||||
}
|
||||
|
||||
public static String capitalizeFirst(String name, char separator) {
|
||||
public static String capitalizeFirstLetter(String name, char separator) {
|
||||
name = name.toLowerCase();
|
||||
String[] split = name.split(Character.toString(separator));
|
||||
StringBuilder total = new StringBuilder(3);
|
||||
for (String s : split) total.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).append(' ');
|
||||
|
||||
for (String s : split) {
|
||||
total.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).append(' ');
|
||||
}
|
||||
|
||||
return total.toString().trim();
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
package com.Acrobot.ChestShop.Utils;
|
||||
|
||||
import com.Acrobot.ChestShop.Config.Config;
|
||||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.TownBlockType;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class uTowny {
|
||||
public static boolean isInsideShopPlot(Location chestlocation, Location signLocation) {
|
||||
return TownyUniverse.getTownBlock(chestlocation).getType() == TownBlockType.COMMERCIAL && TownyUniverse.getTownBlock(signLocation).getType() == TownBlockType.COMMERCIAL;
|
||||
}
|
||||
|
||||
public static boolean isPlotOwner(Player player, Location chestLocation, Location signLocation) {
|
||||
if (Config.getBoolean(Property.TOWNY_SHOPS_FOR_OWNERS_ONLY)) return isBlockOwner(player, chestLocation) && isBlockOwner(player, signLocation);
|
||||
return isResident(player, chestLocation) && isResident(player, signLocation);
|
||||
}
|
||||
|
||||
public static boolean isInWilderness(Location chestLocation, Location signLocation) {
|
||||
return isInWilderness(chestLocation.getBlock()) || isInWilderness(signLocation.getBlock());
|
||||
}
|
||||
|
||||
private static boolean isInWilderness(Block block) {
|
||||
return TownyUniverse.isWilderness(block);
|
||||
}
|
||||
|
||||
public static boolean canBuild(Player player, Location chestLocation, Location signLocation) {
|
||||
return uSign.towny == null || !Config.getBoolean(Property.TOWNY_INTEGRATION) || (!isInWilderness(chestLocation, signLocation) && isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation));
|
||||
}
|
||||
|
||||
private static boolean isBlockOwner(Player player, Location location) {
|
||||
try {
|
||||
return TownyUniverse.getTownBlock(location).isOwner(TownyUniverse.getDataSource().getResident(player.getName()));
|
||||
} catch (NotRegisteredException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isResident(Player p, Location l) {
|
||||
try {
|
||||
return TownyUniverse.getTownBlock(l).getTown().hasResident(p.getName());
|
||||
} catch (NotRegisteredException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -45,9 +45,8 @@ public abstract class Database {
|
||||
method.setAccessible(true);
|
||||
|
||||
//Store the ClassLoader
|
||||
this.classLoader = (ClassLoader)method.invoke(javaPlugin);
|
||||
}
|
||||
catch(Exception ex ) {
|
||||
this.classLoader = (ClassLoader) method.invoke(javaPlugin);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Failed to retrieve the ClassLoader of the plugin using Reflection", ex);
|
||||
}
|
||||
}
|
||||
@ -75,11 +74,9 @@ public abstract class Database {
|
||||
|
||||
//Create all tables
|
||||
installDatabase(false);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("An exception has occured while initializing the database", ex);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
//Enable all logging
|
||||
enableDatabaseLogging(false);
|
||||
}
|
||||
@ -104,7 +101,7 @@ public abstract class Database {
|
||||
List<Class<?>> classes = getDatabaseClasses();
|
||||
|
||||
//Do a sanity check first
|
||||
if(classes.isEmpty()) {
|
||||
if (classes.isEmpty()) {
|
||||
//Exception: There is no use in continuing to load this database
|
||||
throw new RuntimeException("Database has been enabled, but no classes are registered to it");
|
||||
}
|
||||
@ -154,23 +151,20 @@ public abstract class Database {
|
||||
|
||||
//Setup Ebean based on the configuration
|
||||
ebeanServer = EbeanServerFactory.create(serverConfig);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Failed to create a new instance of the EbeanServer", ex);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
//Revert the ClassLoader back to its original value
|
||||
if(currentClassLoader != null) {
|
||||
if (currentClassLoader != null) {
|
||||
Thread.currentThread().setContextClassLoader(currentClassLoader);
|
||||
}
|
||||
|
||||
//Revert the "defaultUseCaches"-field in URLConnection back to its original value
|
||||
try {
|
||||
if(cacheField != null) {
|
||||
if (cacheField != null) {
|
||||
cacheField.setBoolean(null, cacheValue);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed to revert the \"defaultUseCaches\"-field back to its original value, URLConnection-caching remains disabled.");
|
||||
}
|
||||
}
|
||||
@ -195,7 +189,7 @@ public abstract class Database {
|
||||
}
|
||||
|
||||
//Check if the database has to be created or rebuilt
|
||||
if(!rebuild && databaseExists) {
|
||||
if (!rebuild && databaseExists) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -206,10 +200,9 @@ public abstract class Database {
|
||||
//Fire "before drop" event
|
||||
try {
|
||||
beforeDropDatabase();
|
||||
}
|
||||
catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
//If the database exists, dropping has to be canceled to prevent data-loss
|
||||
if(databaseExists) {
|
||||
if (databaseExists) {
|
||||
throw new RuntimeException("An unexpected exception occured", ex);
|
||||
}
|
||||
}
|
||||
@ -218,24 +211,22 @@ public abstract class Database {
|
||||
gen.runScript(true, gen.generateDropDdl());
|
||||
|
||||
//If SQLite is being used, the database has to reloaded to release all resources
|
||||
if(usingSQLite) {
|
||||
if (usingSQLite) {
|
||||
loadDatabase();
|
||||
}
|
||||
|
||||
//Generate a CreateDDL-script
|
||||
if(usingSQLite) {
|
||||
if (usingSQLite) {
|
||||
//If SQLite is being used, the CreateDLL-script has to be validated and potentially fixed to be valid
|
||||
gen.runScript(false, validateCreateDDLSqlite(gen.generateCreateDdl()));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
gen.runScript(false, gen.generateCreateDdl());
|
||||
}
|
||||
|
||||
//Fire "after create" event
|
||||
try {
|
||||
afterCreateDatabase();
|
||||
}
|
||||
catch(Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("An unexpected exception occured", ex);
|
||||
}
|
||||
}
|
||||
@ -270,12 +261,11 @@ public abstract class Database {
|
||||
scriptLines.add(currentLine.trim());
|
||||
|
||||
//Check if the current line is of any use
|
||||
if(currentLine.startsWith("create table")) {
|
||||
if (currentLine.startsWith("create table")) {
|
||||
//Found a table, so get its name and remember the line it has been encountered on
|
||||
currentTable = currentLine.split(" ", 4)[2];
|
||||
foundTables.put(currentLine.split(" ", 3)[2], scriptLines.size() - 1);
|
||||
}
|
||||
else if(!currentLine.isEmpty() && currentLine.charAt(0) == ';' && currentTable != null && !currentTable.isEmpty()) {
|
||||
} else if (!currentLine.isEmpty() && currentLine.charAt(0) == ';' && currentTable != null && !currentTable.isEmpty()) {
|
||||
//Found the end of a table definition, so update the entry
|
||||
int index = scriptLines.size() - 1;
|
||||
foundTables.put(currentTable, index);
|
||||
@ -290,17 +280,16 @@ public abstract class Database {
|
||||
|
||||
//Reset the table-tracker
|
||||
currentTable = null;
|
||||
}
|
||||
else if(currentLine.startsWith("alter table")) {
|
||||
} else if (currentLine.startsWith("alter table")) {
|
||||
//Found a potentially unsupported action
|
||||
String[] alterTableLine = currentLine.split(" ", 4);
|
||||
|
||||
if(alterTableLine[3].startsWith("add constraint")) {
|
||||
if (alterTableLine[3].startsWith("add constraint")) {
|
||||
//Found an unsupported action: ALTER TABLE using ADD CONSTRAINT
|
||||
String[] addConstraintLine = alterTableLine[3].split(" ", 4);
|
||||
|
||||
//Check if this line can be fixed somehow
|
||||
if(addConstraintLine[3].startsWith("foreign key")) {
|
||||
if (addConstraintLine[3].startsWith("foreign key")) {
|
||||
//Calculate the index of last line of the current table
|
||||
int tableLastLine = foundTables.get(alterTableLine[2]) + tableOffset;
|
||||
|
||||
@ -314,8 +303,7 @@ public abstract class Database {
|
||||
//Remove this line and raise the table offset because a line has been inserted
|
||||
scriptLines.remove(scriptLines.size() - 1);
|
||||
tableOffset++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//Exception: This line cannot be fixed but is known the be unsupported by SQLite
|
||||
throw new RuntimeException("Unsupported action encountered: ALTER TABLE using ADD CONSTRAINT with " + addConstraintLine[3]);
|
||||
}
|
||||
@ -325,15 +313,14 @@ public abstract class Database {
|
||||
|
||||
//Turn all the lines back into a single string
|
||||
StringBuilder newScript = new StringBuilder(5);
|
||||
for(String newLine : scriptLines) newScript.append(newLine).append('\n');
|
||||
for (String newLine : scriptLines) newScript.append(newLine).append('\n');
|
||||
|
||||
//Print the new script
|
||||
System.out.println(newScript);
|
||||
|
||||
//Return the fixed script
|
||||
return newScript.toString();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
//Exception: Failed to fix the DDL or something just went plain wrong
|
||||
throw new RuntimeException("Failed to validate the CreateDDL-script for SQLite", ex);
|
||||
}
|
||||
@ -341,7 +328,7 @@ public abstract class Database {
|
||||
|
||||
private void disableDatabaseLogging(boolean logging) {
|
||||
//If logging is allowed, nothing has to be changed
|
||||
if(logging) {
|
||||
if (logging) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -354,7 +341,7 @@ public abstract class Database {
|
||||
|
||||
private void enableDatabaseLogging(boolean logging) {
|
||||
//If logging is allowed, nothing has to be changed
|
||||
if(logging) {
|
||||
if (logging) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public interface Method {
|
||||
* Encodes the Plugin into an Object disguised as the Plugin.
|
||||
* If you want the original Plugin Class you must cast it to the correct
|
||||
* Plugin, to do so you have to verify the name and or version then cast.
|
||||
*
|
||||
* <p/>
|
||||
* <pre>
|
||||
* if(method.getName().equalsIgnoreCase("iConomy"))
|
||||
* iConomy plugin = ((iConomy)method.getPlugin());</pre>
|
||||
@ -144,15 +144,25 @@ public interface Method {
|
||||
*/
|
||||
public interface MethodAccount {
|
||||
public double balance();
|
||||
|
||||
public boolean set(double amount);
|
||||
|
||||
public boolean add(double amount);
|
||||
|
||||
public boolean subtract(double amount);
|
||||
|
||||
public boolean multiply(double amount);
|
||||
|
||||
public boolean divide(double amount);
|
||||
|
||||
public boolean hasEnough(double amount);
|
||||
|
||||
public boolean hasOver(double amount);
|
||||
|
||||
public boolean hasUnder(double amount);
|
||||
|
||||
public boolean isNegative();
|
||||
|
||||
public boolean remove();
|
||||
|
||||
@Override
|
||||
@ -164,17 +174,29 @@ public interface Method {
|
||||
*/
|
||||
public interface MethodBankAccount {
|
||||
public double balance();
|
||||
|
||||
public String getBankName();
|
||||
|
||||
public int getBankId();
|
||||
|
||||
public boolean set(double amount);
|
||||
|
||||
public boolean add(double amount);
|
||||
|
||||
public boolean subtract(double amount);
|
||||
|
||||
public boolean multiply(double amount);
|
||||
|
||||
public boolean divide(double amount);
|
||||
|
||||
public boolean hasEnough(double amount);
|
||||
|
||||
public boolean hasOver(double amount);
|
||||
|
||||
public boolean hasUnder(double amount);
|
||||
|
||||
public boolean isNegative();
|
||||
|
||||
public boolean remove();
|
||||
|
||||
@Override
|
||||
|
@ -29,17 +29,17 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static Method load(PluginManager pm) {
|
||||
if (!preferred.isEmpty()){
|
||||
if (!preferred.isEmpty()) {
|
||||
Plugin plugin = pm.getPlugin(preferred);
|
||||
if (plugin != null){
|
||||
if (plugin != null) {
|
||||
Method m = createMethod(plugin);
|
||||
if (m != null) return m;
|
||||
}
|
||||
}
|
||||
|
||||
for (String plugin : toLoad){
|
||||
for (String plugin : toLoad) {
|
||||
Plugin pl = pm.getPlugin(plugin);
|
||||
if (pl != null){
|
||||
if (pl != null) {
|
||||
Method m = createMethod(pl);
|
||||
if (m != null) return m;
|
||||
}
|
||||
@ -48,7 +48,7 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static Method createMethod(Plugin plugin) {
|
||||
for (Method method : methods){
|
||||
for (Method method : methods) {
|
||||
if (method.isCompatible(plugin)) {
|
||||
method.setPlugin(plugin);
|
||||
return method;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.nijikokun.register.payment.forChestShop.methods;
|
||||
|
||||
import com.nijikokun.register.payment.forChestShop.Method;
|
||||
|
||||
import cosine.boseconomy.BOSEconomy;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@ -35,7 +34,7 @@ public class BOSE7 implements Method {
|
||||
public String format(double amount) {
|
||||
String currency = this.BOSEconomy.getMoneyNamePlural();
|
||||
|
||||
if(amount == 1)
|
||||
if (amount == 1)
|
||||
currency = this.BOSEconomy.getMoneyName();
|
||||
|
||||
return amount + " " + currency;
|
||||
@ -58,7 +57,7 @@ public class BOSE7 implements Method {
|
||||
}
|
||||
|
||||
public boolean createAccount(String name) {
|
||||
if(hasAccount(name))
|
||||
if (hasAccount(name))
|
||||
return false;
|
||||
|
||||
this.BOSEconomy.registerPlayer(name);
|
||||
@ -66,7 +65,7 @@ public class BOSE7 implements Method {
|
||||
}
|
||||
|
||||
public boolean createAccount(String name, double balance) {
|
||||
if(hasAccount(name))
|
||||
if (hasAccount(name))
|
||||
return false;
|
||||
|
||||
this.BOSEconomy.registerPlayer(name);
|
||||
@ -75,14 +74,14 @@ public class BOSE7 implements Method {
|
||||
}
|
||||
|
||||
public MethodAccount getAccount(String name) {
|
||||
if(!hasAccount(name))
|
||||
if (!hasAccount(name))
|
||||
return null;
|
||||
|
||||
return new BOSEAccount(name, this.BOSEconomy);
|
||||
}
|
||||
|
||||
public MethodBankAccount getBankAccount(String bank, String name) {
|
||||
if(!hasBankAccount(bank, name))
|
||||
if (!hasBankAccount(bank, name))
|
||||
return null;
|
||||
|
||||
return new BOSEBankAccount(bank, BOSEconomy);
|
||||
@ -95,7 +94,7 @@ public class BOSE7 implements Method {
|
||||
}
|
||||
|
||||
public void setPlugin(Plugin plugin) {
|
||||
BOSEconomy = (BOSEconomy)plugin;
|
||||
BOSEconomy = (BOSEconomy) plugin;
|
||||
}
|
||||
|
||||
public static class BOSEAccount implements MethodAccount {
|
||||
|
@ -1,9 +1,8 @@
|
||||
package com.nijikokun.register.payment.forChestShop.methods;
|
||||
|
||||
import com.nijikokun.register.payment.forChestShop.Method;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.api.Economy;
|
||||
|
||||
import com.nijikokun.register.payment.forChestShop.Method;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
@ -56,7 +55,7 @@ public class EE17 implements Method {
|
||||
}
|
||||
|
||||
public boolean createAccount(String name) {
|
||||
if(hasAccount(name))
|
||||
if (hasAccount(name))
|
||||
return false;
|
||||
|
||||
Economy.createNPC(name);
|
||||
@ -64,7 +63,7 @@ public class EE17 implements Method {
|
||||
}
|
||||
|
||||
public boolean createAccount(String name, double balance) {
|
||||
if(hasAccount(name))
|
||||
if (hasAccount(name))
|
||||
return false;
|
||||
|
||||
Economy.createNPC(name);
|
||||
@ -80,7 +79,7 @@ public class EE17 implements Method {
|
||||
}
|
||||
|
||||
public MethodAccount getAccount(String name) {
|
||||
if(!hasAccount(name))
|
||||
if (!hasAccount(name))
|
||||
return null;
|
||||
|
||||
return new EEcoAccount(name);
|
||||
@ -91,15 +90,18 @@ public class EE17 implements Method {
|
||||
}
|
||||
|
||||
public boolean isCompatible(Plugin plugin) {
|
||||
try { Class.forName("com.earth2me.essentials.api.Economy"); }
|
||||
catch(Exception e) { return false; }
|
||||
try {
|
||||
Class.forName("com.earth2me.essentials.api.Economy");
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return plugin.getDescription().getName().equalsIgnoreCase("essentials")
|
||||
&& plugin instanceof Essentials;
|
||||
}
|
||||
|
||||
public void setPlugin(Plugin plugin) {
|
||||
Essentials = (Essentials)plugin;
|
||||
Essentials = (Essentials) plugin;
|
||||
}
|
||||
|
||||
public static class EEcoAccount implements MethodAccount {
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.nijikokun.register.payment.forChestShop.methods;
|
||||
|
||||
import com.nijikokun.register.payment.forChestShop.Method;
|
||||
import com.iCo6.iConomy;
|
||||
import com.iCo6.system.Account;
|
||||
import com.iCo6.system.Accounts;
|
||||
import com.iCo6.system.Holdings;
|
||||
|
||||
|
||||
import com.nijikokun.register.payment.forChestShop.Method;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
@ -80,7 +78,7 @@ public class iCo6 implements Method {
|
||||
}
|
||||
|
||||
public void setPlugin(Plugin plugin) {
|
||||
iConomy = (iConomy)plugin;
|
||||
iConomy = (iConomy) plugin;
|
||||
}
|
||||
|
||||
public static class iCoAccount implements MethodAccount {
|
||||
@ -101,31 +99,31 @@ public class iCo6 implements Method {
|
||||
}
|
||||
|
||||
public boolean set(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
if (this.holdings == null) return false;
|
||||
this.holdings.setBalance(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean add(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
if (this.holdings == null) return false;
|
||||
this.holdings.add(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean subtract(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
if (this.holdings == null) return false;
|
||||
this.holdings.subtract(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean multiply(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
if (this.holdings == null) return false;
|
||||
this.holdings.multiply(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean divide(double amount) {
|
||||
if(this.holdings == null) return false;
|
||||
if (this.holdings == null) return false;
|
||||
this.holdings.divide(amount);
|
||||
return true;
|
||||
}
|
||||
@ -147,7 +145,7 @@ public class iCo6 implements Method {
|
||||
}
|
||||
|
||||
public boolean remove() {
|
||||
if(this.account == null) return false;
|
||||
if (this.account == null) return false;
|
||||
this.account.remove();
|
||||
return true;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ name: ChestShop
|
||||
|
||||
main: com.Acrobot.ChestShop.ChestShop
|
||||
|
||||
version: 3.40
|
||||
version: 3.41
|
||||
|
||||
#for CButD
|
||||
dev-url: http://dev.bukkit.org/server-mods/chestshop/
|
||||
|
Loading…
Reference in New Issue
Block a user