| @@ -0,0 +1,41 @@ | ||
| # World Configuration | ||
| # The defaults here are the same as the config.yml | ||
| # If you would like to use a "global" value, set the value here as 'global' (like in defaults) | ||
| # Otherwise, use a custom value. | ||
| # For an explanation of each value, see config.yml | ||
| events: | ||
| block_break: global | ||
| block_place: global | ||
| death: global | ||
| drop_item: global | ||
| interact: global | ||
| commands: global | ||
| messages: | ||
| block_break: global | ||
| block_place: global | ||
| death: global | ||
| drop_item: global | ||
| interact: global | ||
| eggs: global | ||
| exp_bottle: global | ||
| inventory_swap: global | ||
| creativeModeBlock: global | ||
| bedrock: global | ||
| pvp: global | ||
| mobpvp: global | ||
| noBlockDrop: global | ||
| illegalCommand: global | ||
| worldSwap: global | ||
| throwItemIntoRegion: global | ||
| other: | ||
| only_if_creative: global | ||
| allow_eggs: global | ||
| allow_exp_bottle: global | ||
| inventory_swap: global | ||
| track_blocks: global | ||
| allow_bedrock: global | ||
| pvp: global | ||
| pvp-mobs: global | ||
| blockDrops: global | ||
| worldTransfer: global | ||
| cannot_throw_into_regions: global |
| @@ -0,0 +1,353 @@ | ||
| package com.feildmaster.lib.configuration; | ||
|
|
||
| import java.io.File; | ||
| import java.io.InputStream; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.bukkit.configuration.MemoryConfiguration; | ||
| import org.bukkit.plugin.Plugin; | ||
|
|
||
| /* | ||
| * __ Things to do __ | ||
| * Path Comments | ||
| * - The next thing to code | ||
| * Case Insensitivity | ||
| * - The "proper" way for this would increase configuration memory. Look into further. | ||
| * Lowercase Keys | ||
| * - This is terrible to implement as well... | ||
| * Comments. Steal from here | ||
| * https://github.com/dumptruckman/PluginTemplate/blob/master/src/main/java/com/dumptruckman/plugintemplate/config/CommentedConfig.java | ||
| * I want to add 'literalsections' :D | ||
| */ | ||
|
|
||
| /** | ||
| * Enhancing configuration to do the following: <li>Stores a file for configuration to use.</li> <li>Self contained "load," "reload," and "save" functions.</li> <li>Self contained "loadDefaults" functions that set defaults.</li> <li>Adds "getLastException" to return the last exception from self contained functions.</li> <li>Adds "options().header(String, String)" to build multiline headers easier(?)</li> | ||
| * | ||
| * @author Feildmaster | ||
| */ | ||
| public class EnhancedConfiguration extends org.bukkit.configuration.file.YamlConfiguration { | ||
| private final Pattern pattern = Pattern.compile("\n"); // Static? Maybe bad? I'm not sure. | ||
| private final File file; | ||
| private final Plugin plugin; | ||
| private Exception exception; | ||
| private Map<String, Object> cache = new HashMap<String, Object>(); | ||
| private boolean modified = false; | ||
| private long last_modified = -1L; | ||
|
|
||
| /** | ||
| * Creates a new EnhancedConfiguration with a file named "config.yml," stored in the plugin DataFolder | ||
| * <p /> | ||
| * Will fail if plugin is null. | ||
| * | ||
| * @param plugin The plugin registered to this Configuration | ||
| */ | ||
| public EnhancedConfiguration(Plugin plugin){ | ||
| this("config.yml", plugin); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new EnhancedConfiguration with a file stored in the plugin DataFolder | ||
| * <p /> | ||
| * Will fail if plugin is null. | ||
| * | ||
| * @param file The name of the file | ||
| * @param plugin The plugin registered to this Configuration | ||
| */ | ||
| public EnhancedConfiguration(String file, Plugin plugin){ | ||
| this(new File(plugin.getDataFolder(), file), plugin); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new EnhancedConfiguration with the file provided and a null {@link Plugin} | ||
| * | ||
| * @param file The file to store in this configuration | ||
| */ | ||
| public EnhancedConfiguration(File file){ | ||
| this(file, null); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new EnhancedConfiguration with given File and Plugin. | ||
| * | ||
| * @param file The file to store in this configuration | ||
| * @param plugin The plugin registered to this Configuration | ||
| */ | ||
| public EnhancedConfiguration(File file, Plugin plugin){ | ||
| this.file = file; | ||
| this.plugin = plugin; | ||
| options = new EnhancedConfigurationOptions(this); | ||
| load(); | ||
| } | ||
|
|
||
| /** | ||
| * Loads set file | ||
| * <p /> | ||
| * Does not load if file has not been changed since last load | ||
| * <p /> | ||
| * Stores exception if possible. | ||
| * | ||
| * @return True on successful load | ||
| */ | ||
| public final boolean load(){ | ||
| if(last_modified != -1L && !isFileModified()){ // File hasn't been modified since last load | ||
| return true; | ||
| } | ||
|
|
||
| try{ | ||
| load(file); | ||
| clearCache(); | ||
| last_modified = file.lastModified(); | ||
| return true; | ||
| }catch(Exception ex){ | ||
| exception = ex; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Saves to the set file | ||
| * <p /> | ||
| * Stores exception if possible. | ||
| * | ||
| * @return True on successful save | ||
| */ | ||
| public final boolean save(){ | ||
| try{ | ||
| save(file); | ||
| modified = false; | ||
| return true; | ||
| }catch(Exception ex){ | ||
| exception = ex; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the last stored exception | ||
| * | ||
| * @return Last stored Exception | ||
| */ | ||
| public Exception getLastException(){ | ||
| return exception; | ||
| } | ||
|
|
||
| /** | ||
| * Loads defaults based off the name of stored file. | ||
| * <p /> | ||
| * Stores exception if possible. | ||
| * <p /> | ||
| * Will fail if Plugin is null. | ||
| * | ||
| * @return True on success | ||
| */ | ||
| public boolean loadDefaults(){ | ||
| try{ | ||
| return loadDefaults(file.getName()); | ||
| }catch(Exception ex){ | ||
| exception = ex; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sets your defaults after loading the Plugin file. | ||
| * <p /> | ||
| * Stores exception if possible. | ||
| * <p /> | ||
| * Will fail if Plugin is null. | ||
| * | ||
| * @param filename File to load from Plugin jar | ||
| * @return True on success | ||
| */ | ||
| public boolean loadDefaults(String filename){ | ||
| try{ | ||
| return loadDefaults(plugin.getResource(filename)); | ||
| }catch(Exception ex){ | ||
| exception = ex; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sets your defaults after loading them. | ||
| * <p /> | ||
| * Stores exception if possible. | ||
| * | ||
| * @param filestream Stream to load defaults from | ||
| * @return True on success, false otherwise. | ||
| */ | ||
| public boolean loadDefaults(InputStream filestream){ | ||
| try{ | ||
| setDefaults(loadConfiguration(filestream)); | ||
| clearCache(); | ||
| return true; | ||
| }catch(Exception ex){ | ||
| exception = ex; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Saves configuration with all defaults | ||
| * | ||
| * @return True if saved | ||
| */ | ||
| public boolean saveDefaults(){ | ||
| options().copyDefaults(true); // These stay so future saves continue to copy over. | ||
| options().copyHeader(true); | ||
| return save(); | ||
| } | ||
|
|
||
| /** | ||
| * Check loaded defaults against current configuration | ||
| * | ||
| * @return false When all defaults aren't present in config | ||
| */ | ||
| public boolean checkDefaults(){ | ||
| if(getDefaults() == null){ | ||
| return true; | ||
| } | ||
| return getKeys(true).containsAll(getDefaults().getKeys(true)); | ||
| } | ||
|
|
||
| /** | ||
| * Clear the defaults from memory | ||
| */ | ||
| public final void clearDefaults(){ | ||
| setDefaults(new MemoryConfiguration()); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the file exists, contains all defaults and if this configuration has been modified. | ||
| * | ||
| * @return True if the file should be updated (saved) | ||
| */ | ||
| public boolean needsUpdate(){ | ||
| return !fileExists() || !checkDefaults() || isModified(); | ||
| } | ||
|
|
||
| /** | ||
| * @return True if file exists, False if not, or if there was an exception. | ||
| */ | ||
| public boolean fileExists(){ | ||
| try{ | ||
| return file.exists(); | ||
| }catch(Exception ex){ | ||
| exception = ex; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @return {@link EnhancedConfigurationOptions} | ||
| */ | ||
| @Override | ||
| public EnhancedConfigurationOptions options(){ | ||
| return (EnhancedConfigurationOptions) options; | ||
| } | ||
|
|
||
| @Override | ||
| public Object get(String path, Object def){ | ||
| Object value = cache.get(path); | ||
| if(value != null){ | ||
| return value; | ||
| } | ||
|
|
||
| value = super.get(path, def); | ||
| if(value != null){ | ||
| cache.put(path, value); | ||
| } | ||
|
|
||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public void set(String path, Object value){ | ||
| if(value == null && cache.containsKey(path)){ | ||
| cache.remove(path); | ||
| modified = true; | ||
| }else if(value != null){ | ||
| if(!value.equals(get(path))){ | ||
| modified = true; | ||
| } | ||
| cache.put(path, value); | ||
|
|
||
| } | ||
| super.set(path, value); | ||
| } | ||
|
|
||
| /** | ||
| * Removes the specified path from the configuration. | ||
| * <p /> | ||
| * Currently equivilent to set(path, null). | ||
| * | ||
| * @param path The path to remove | ||
| */ | ||
| public void unset(String path){ | ||
| set(path, null); | ||
| } | ||
|
|
||
| @SuppressWarnings ("rawtypes") | ||
| @Override | ||
| public List<?> getList(String path, List<?> def){ | ||
| List<?> list = super.getList(path, def); | ||
| return list == null ? new ArrayList(0) : list; | ||
| } | ||
|
|
||
| /** | ||
| * Call this method to clear the cache manually. | ||
| * | ||
| * Automatically clears on "load" | ||
| */ | ||
| public void clearCache(){ | ||
| cache.clear(); | ||
| } | ||
|
|
||
| // Replaces \n with System line.separator | ||
| @Override | ||
| public String saveToString(){ | ||
| String separator = System.getProperty("line.separator"); | ||
| if(separator.equals("\n")){ // Do nothing | ||
| return super.saveToString(); | ||
| } | ||
| return pattern.matcher(super.saveToString()).replaceAll(separator); | ||
| } | ||
|
|
||
| /** | ||
| * @return The plugin associated with this configuration. | ||
| */ | ||
| public Plugin getPlugin(){ | ||
| return plugin; | ||
| } | ||
|
|
||
| protected File getFile(){ | ||
| return file; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if loaded configuration (not the file) has been modified. | ||
| * | ||
| * @return True if local configuration has been modified | ||
| */ | ||
| public boolean isModified(){ | ||
| return modified; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if file has been modified since last load(). | ||
| * | ||
| * @return True if file has been modified | ||
| */ | ||
| public boolean isFileModified(){ | ||
| try{ | ||
| return last_modified != file.lastModified(); | ||
| }catch(Exception e){ | ||
| this.exception = e; | ||
| return false; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,90 @@ | ||
| package com.feildmaster.lib.configuration; | ||
|
|
||
| import org.bukkit.configuration.file.YamlConfigurationOptions; | ||
|
|
||
| /** | ||
| * Enhanced Options, contains Header options | ||
| * | ||
| * @author Feildmaster | ||
| */ | ||
| public class EnhancedConfigurationOptions extends YamlConfigurationOptions { | ||
| // private boolean lowercaseKeys = false; | ||
|
|
||
| public EnhancedConfigurationOptions(EnhancedConfiguration configuration){ | ||
| super(configuration); | ||
| } | ||
|
|
||
| @Override | ||
| public EnhancedConfiguration configuration(){ | ||
| return (EnhancedConfiguration) super.configuration(); | ||
| } | ||
|
|
||
| @Override | ||
| public EnhancedConfigurationOptions copyDefaults(boolean value){ | ||
| super.copyDefaults(value); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public EnhancedConfigurationOptions header(String value){ | ||
| super.header(value); | ||
| return this; | ||
| } | ||
|
|
||
| // /** | ||
| // * Allows case-insensitive lookups | ||
| // * | ||
| // * @param value True to turn off sensitivity | ||
| // * @return This Instance | ||
| // */ | ||
| // public EnhancedConfigurationOptions lowercaseKeys(boolean value) { | ||
| // lowercaseKeys = value; | ||
| // return this; | ||
| // } | ||
| // | ||
| // public boolean lowercaseKeys() { | ||
| // return lowercaseKeys; | ||
| // } | ||
|
|
||
| /** | ||
| * | ||
| * | ||
| * @param lines Comma Separated strings to build into the header | ||
| * @return This Instance | ||
| */ | ||
| public EnhancedConfigurationOptions header(String... lines){ | ||
| StringBuilder string = new StringBuilder(); | ||
| //String separator = System.getProperty("line.separator"); // This wont do anything... | ||
|
|
||
| for(String s : lines){ | ||
| if(s == null) | ||
| continue; | ||
| if(string.length() > 0){ | ||
| string.append("\n"); | ||
| } | ||
| string.append(s); | ||
| } | ||
|
|
||
| header(string.length() == 0 ? null : string.toString()); | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public EnhancedConfigurationOptions copyHeader(boolean value){ | ||
| super.copyHeader(value); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public EnhancedConfigurationOptions pathSeparator(char value){ | ||
| super.pathSeparator(value); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public EnhancedConfigurationOptions indent(int value){ | ||
| super.indent(value); | ||
| return this; | ||
| } | ||
| } |
| @@ -0,0 +1,24 @@ | ||
| package com.feildmaster.lib.configuration; | ||
|
|
||
| public class PluginWrapper extends org.bukkit.plugin.java.JavaPlugin { | ||
| private EnhancedConfiguration config; | ||
|
|
||
| public EnhancedConfiguration getConfig() { | ||
| if(config == null) { | ||
| config = new EnhancedConfiguration(this); | ||
| } | ||
| return config; | ||
| } | ||
|
|
||
| public void reloadConfig() { | ||
| getConfig().load(); | ||
| } | ||
|
|
||
| public void saveConfig() { | ||
| getConfig().save(); | ||
| } | ||
|
|
||
| public void saveDefaultConfig() { | ||
| getConfig().saveDefaults(); | ||
| } | ||
| } |
| @@ -0,0 +1,100 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileInputStream; | ||
| import java.io.FileOutputStream; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.conversations.Conversable; | ||
|
|
||
| public class ASUtils { | ||
| public static String addColor(String message){ | ||
| String colorSeperator = "&"; | ||
| message = message.replaceAll(colorSeperator + "0", ChatColor.getByChar('0').toString()); | ||
| message = message.replaceAll(colorSeperator + "1", ChatColor.getByChar('1').toString()); | ||
| message = message.replaceAll(colorSeperator + "2", ChatColor.getByChar('2').toString()); | ||
| message = message.replaceAll(colorSeperator + "3", ChatColor.getByChar('3').toString()); | ||
| message = message.replaceAll(colorSeperator + "4", ChatColor.getByChar('4').toString()); | ||
| message = message.replaceAll(colorSeperator + "5", ChatColor.getByChar('5').toString()); | ||
| message = message.replaceAll(colorSeperator + "6", ChatColor.getByChar('6').toString()); | ||
| message = message.replaceAll(colorSeperator + "7", ChatColor.getByChar('7').toString()); | ||
| message = message.replaceAll(colorSeperator + "8", ChatColor.getByChar('8').toString()); | ||
| message = message.replaceAll(colorSeperator + "9", ChatColor.getByChar('9').toString()); | ||
| message = message.replaceAll(colorSeperator + "a", ChatColor.getByChar('a').toString()); | ||
| message = message.replaceAll(colorSeperator + "b", ChatColor.getByChar('b').toString()); | ||
| message = message.replaceAll(colorSeperator + "c", ChatColor.getByChar('c').toString()); | ||
| message = message.replaceAll(colorSeperator + "d", ChatColor.getByChar('d').toString()); | ||
| message = message.replaceAll(colorSeperator + "e", ChatColor.getByChar('e').toString()); | ||
| message = message.replaceAll(colorSeperator + "f", ChatColor.getByChar('f').toString()); | ||
| message = message.replaceAll(colorSeperator + "A", ChatColor.getByChar('a').toString()); | ||
| message = message.replaceAll(colorSeperator + "B", ChatColor.getByChar('b').toString()); | ||
| message = message.replaceAll(colorSeperator + "C", ChatColor.getByChar('c').toString()); | ||
| message = message.replaceAll(colorSeperator + "D", ChatColor.getByChar('d').toString()); | ||
| message = message.replaceAll(colorSeperator + "E", ChatColor.getByChar('e').toString()); | ||
| message = message.replaceAll(colorSeperator + "F", ChatColor.getByChar('f').toString()); | ||
| return message; | ||
| } | ||
|
|
||
| public static void sendToPlayer(CommandSender target, String message){ | ||
| if(!message.equalsIgnoreCase("nomsg") | ||
| && !message.equalsIgnoreCase("no message") | ||
| && !message.equalsIgnoreCase("none") | ||
| && !message.equalsIgnoreCase("noshow") | ||
| && !message.equalsIgnoreCase("no show")){ | ||
| message = addColor(message); | ||
| if(!ChatColor.stripColor(message).startsWith("[AntiShare]")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.WHITE + message; | ||
| } | ||
| target.sendMessage(message); | ||
| } | ||
| } | ||
|
|
||
| public static void sendToConversable(Conversable target, String message){ | ||
| if(!message.equalsIgnoreCase("nomsg") | ||
| && !message.equalsIgnoreCase("no message") | ||
| && !message.equalsIgnoreCase("none") | ||
| && !message.equalsIgnoreCase("noshow") | ||
| && !message.equalsIgnoreCase("no show")){ | ||
| message = addColor(message); | ||
| if(!ChatColor.stripColor(message).startsWith("[AntiShare]")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.WHITE + message; | ||
| } | ||
| target.sendRawMessage(message); | ||
| } | ||
| } | ||
|
|
||
| public static void transfer(File original, File destination){ | ||
| try{ | ||
| if(!destination.exists()){ | ||
| File d = new File(destination.getParent()); | ||
| d.mkdirs(); | ||
| destination.createNewFile(); | ||
| } | ||
| InputStream in = new FileInputStream(original); | ||
| OutputStream out = new FileOutputStream(destination); | ||
| byte[] buf = new byte[1024]; | ||
| int len; | ||
| while ((len = in.read(buf)) > 0){ | ||
| out.write(buf, 0, len); | ||
| } | ||
| in.close(); | ||
| out.close(); | ||
| }catch(Exception e){ | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| public static Boolean getValueOf(String value){ | ||
| if(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("t") || value.equalsIgnoreCase("on") | ||
| || value.equalsIgnoreCase("active") || value.equalsIgnoreCase("1")){ | ||
| return true; | ||
| }else if(value.equalsIgnoreCase("false") || value.equalsIgnoreCase("f") || value.equalsIgnoreCase("off") | ||
| || value.equalsIgnoreCase("inactive") || value.equalsIgnoreCase("0")){ | ||
| return false; | ||
| } | ||
| return null; | ||
| } | ||
| } |
| @@ -0,0 +1,144 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import java.io.File; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
|
|
||
| import com.feildmaster.lib.configuration.PluginWrapper; | ||
| import com.turt2live.antishare.SQL.SQLManager; | ||
| import com.turt2live.antishare.debug.Debugger; | ||
| import com.turt2live.antishare.permissions.PermissionsHandler; | ||
| import com.turt2live.antishare.regions.RegionHandler; | ||
| import com.turt2live.antishare.storage.VirtualStorage; | ||
|
|
||
| public class AntiShare extends PluginWrapper { | ||
|
|
||
| /* TODO: All this | ||
| * Exp bottle blocks [WAITING ON API] | ||
| * Fix 'throw items into regions' [WAITING ON... Something?] | ||
| * Find a work around to get CommandSender from Conversable | ||
| * - This is for the Edit Region inventory/area options | ||
| * - For Add Region | ||
| * - Permissions check on edit region | ||
| * Mirror inventory (with restore) | ||
| * GameMode Changer | ||
| * | ||
| * TODO: Add these permissions to the config helper: | ||
| * AntiShare.mirror | ||
| * AntiShare.gamemode | ||
| * | ||
| * TODO: Add these to the config.yml: | ||
| * AntiShare.mirror | ||
| * GameMode Changer (AntiShare.gamemode) | ||
| * | ||
| * TODO: This is how I (can) fix the item in regions thing | ||
| * 1) Tag item as it comes out of player | ||
| * 2) Set a pickup delay of 20 ticks on item | ||
| * 3) Add chunk to a scheduler list to scan | ||
| * 4) On scan, check for item | ||
| * 5) Check item location and stuff | ||
| * 6) Return item if required | ||
| */ | ||
|
|
||
| // TODO: SET TO FALSE BEFORE RELEASE | ||
| public static boolean DEBUG_MODE = true; | ||
|
|
||
| private Configuration config; | ||
| public static Logger log = Logger.getLogger("Minecraft"); | ||
| private SQLManager sql; | ||
| public VirtualStorage storage; | ||
| private RegionHandler regions; | ||
| private Conflicts conflicts; | ||
| private Debugger debugger; | ||
| private TimedSave timedSave; | ||
| private PermissionsHandler perms; | ||
|
|
||
| @Override | ||
| public void onEnable(){ | ||
| config = new Configuration(this); | ||
| config.create(); | ||
| config.reload(); | ||
| new File(getDataFolder(), "inventories").mkdirs(); // Setup folders | ||
| cleanInventoryFolder(); | ||
| getServer().getPluginManager().registerEvents(new ASListener(this), this); | ||
| MultiWorld.detectWorlds(this); | ||
| storage = new VirtualStorage(this); | ||
| log.info("[" + getDescription().getFullName() + "] Converting pre-3.0.0 creative blocks..."); | ||
| int converted = storage.convertCreativeBlocks(); | ||
| log.info("[" + getDescription().getFullName() + "] Converted " + converted + " blocks!"); | ||
| if(getConfig().getBoolean("SQL.use")){ | ||
| sql = new SQLManager(this); | ||
| if(sql.attemptConnectFromConfig()){ | ||
| sql.checkValues(); | ||
| } | ||
| } | ||
| String.format("%.2f", 1.22222); | ||
| regions = new RegionHandler(this); | ||
| debugger = new Debugger(this); | ||
| if(DEBUG_MODE){ | ||
| getServer().getPluginManager().registerEvents(debugger, this); | ||
| } | ||
| conflicts = new Conflicts(this); | ||
| perms = new PermissionsHandler(this); | ||
| UsageStatistics.send(this); | ||
| getCommand("as").setExecutor(new CommandHandler(this)); | ||
| log.info("[" + getDescription().getFullName() + "] Enabled! (turt2live)"); | ||
| if(getConfig().getInt("settings.save-interval") > 0){ | ||
| int saveTime = (getConfig().getInt("settings.save-interval") * 60) * 20; | ||
| timedSave = new TimedSave(this, saveTime); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onDisable(){ | ||
| if(timedSave != null){ | ||
| timedSave.cancel(); | ||
| } | ||
| log.info("[" + getDescription().getFullName() + "] Saving virtual storage to disk/SQL"); | ||
| storage.saveToDisk(); | ||
| regions.saveStatusToDisk(); | ||
| if(sql != null){ | ||
| sql.disconnect(); | ||
| } | ||
| log.info("[" + getDescription().getFullName() + "] Disabled! (turt2live)"); | ||
| } | ||
|
|
||
| public Configuration config(){ | ||
| return config; | ||
| } | ||
|
|
||
| public SQLManager getSQLManager(){ | ||
| return sql; | ||
| } | ||
|
|
||
| public RegionHandler getRegionHandler(){ | ||
| return regions; | ||
| } | ||
|
|
||
| public Conflicts getConflicts(){ | ||
| return conflicts; | ||
| } | ||
|
|
||
| public Debugger getDebugger(){ | ||
| return debugger; | ||
| } | ||
|
|
||
| public PermissionsHandler getPermissions(){ | ||
| return perms; | ||
| } | ||
|
|
||
| public void cleanInventoryFolder(){ | ||
| File sdir = new File(getDataFolder(), "inventories"); | ||
| String world = Bukkit.getWorlds().get(0).getName(); | ||
| if(sdir.exists()){ | ||
| for(File f : sdir.listFiles()){ | ||
| if(f.getName().endsWith("CREATIVE.yml") | ||
| || f.getName().endsWith("SURVIVAL.yml")){ | ||
| File newName = new File(f.getParent(), f.getName().replace("SURVIVAL", "SURVIVAL_" + world).replace("CREATIVE", "CREATIVE_" + world)); | ||
| f.renameTo(newName); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,184 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import java.util.Vector; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| import com.turt2live.antishare.conversations.ConfigurationConversation; | ||
| import com.turt2live.antishare.regions.ASRegion; | ||
| import com.turt2live.antishare.regions.RegionKey; | ||
|
|
||
| public class CommandHandler implements CommandExecutor { | ||
|
|
||
| private AntiShare plugin; | ||
|
|
||
| public CommandHandler(AntiShare plugin){ | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command command, String cmd, String[] args){ | ||
| if(cmd.equalsIgnoreCase("antishare") || | ||
| cmd.equalsIgnoreCase("as") || | ||
| cmd.equalsIgnoreCase("antis") || | ||
| cmd.equalsIgnoreCase("ashare")){ | ||
| if(args.length > 0){ | ||
| if(args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("rl")){ | ||
| if(plugin.getPermissions().has(sender, "AntiShare.reload")){ | ||
| plugin.reloadConfig(); | ||
| MultiWorld.detectWorlds((AntiShare) Bukkit.getServer().getPluginManager().getPlugin("AntiShare")); | ||
| plugin.storage.reload(sender); | ||
| AntiShare.log.info("AntiShare Reloaded."); | ||
| if(sender instanceof Player){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.GREEN + "AntiShare Reloaded."); | ||
| } | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "You do not have permission!"); | ||
| } | ||
| return true; | ||
| }else if(args[0].equalsIgnoreCase("region")){ | ||
| if(plugin.getPermissions().has(sender, "AntiShare.regions")){ | ||
| if(args.length < 3){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "Syntax error, try: /as region <gamemode> <name>"); | ||
| }else{ | ||
| plugin.getRegionHandler().newRegion(sender, args[1], args[2]); | ||
| } | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "You do not have permission!"); | ||
| } | ||
| return true; | ||
| }else if(args[0].equalsIgnoreCase("rmregion")){ | ||
| if(plugin.getPermissions().has(sender, "AntiShare.regions")){ | ||
| if(args.length > 1){ | ||
| plugin.getRegionHandler().removeRegion(args[1], sender); | ||
| }else{ | ||
| if(!(sender instanceof Player)){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "You have not supplied a name, try /as rmregion <name>"); | ||
| }else{ | ||
| plugin.getRegionHandler().removeRegion(((Player) sender).getLocation(), (Player) sender); | ||
| } | ||
| } | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "You do not have permission!"); | ||
| } | ||
| return true; | ||
| }else if(args[0].equalsIgnoreCase("editregion")){ | ||
| if(plugin.getPermissions().has(sender, "AntiShare.regions")){ | ||
| boolean valid = false; | ||
| if(args.length >= 3){ | ||
| if(RegionKey.isKey(args[2])){ | ||
| if(!RegionKey.requiresValue(RegionKey.getKey(args[2]))){ | ||
| valid = true; // we have at least 3 values in args[] and the key does not need a value | ||
| } | ||
| } | ||
| } | ||
| if(args.length >= 4){ | ||
| valid = true; | ||
| } | ||
| if(!valid){ | ||
| if(args.length >= 2){ | ||
| if(args[1].equalsIgnoreCase("help")){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.GOLD + "/as editregion <name> <key> <value>"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "name " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "<any name>"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "ShowEnterMessage " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "true/false"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "ShowExitMessage " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "true/false"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "EnterMessage " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "<enter message>"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "ExitMessage " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "<exit message>"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "inventory " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "'none'/'set'"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "gamemode " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "survival/creative"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.AQUA + "Key: " + ChatColor.WHITE + "area " + ChatColor.AQUA + "Value: " + ChatColor.WHITE + "No Value"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.YELLOW + "'Show____Message'" + ChatColor.WHITE + " - True to show the message"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.YELLOW + "'____Message'" + ChatColor.WHITE + " - Use {name} to input the region name."); | ||
| ASUtils.sendToPlayer(sender, ChatColor.YELLOW + "'inventory'" + ChatColor.WHITE + " - Sets the region's inventory. 'none' to not have a default inventory, 'set' to mirror yours"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.YELLOW + "'area'" + ChatColor.WHITE + " - Sets the area based on your WorldEdit selection"); | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "Incorrect syntax, try: /as editregion <name> <key> <value>"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "For keys and values type /as editregion help"); | ||
| } | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "Incorrect syntax, try: /as editregion <name> <key> <value>"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "For keys and values type /as editregion help"); | ||
| } | ||
| }else{ | ||
| String name = args[1]; | ||
| String key = args[2]; | ||
| String value = args[3]; | ||
| if(args.length > 4){ | ||
| for(int i = 4; i < args.length; i++){ // Starts at args[4] | ||
| value = value + args[i] + " "; | ||
| } | ||
| value = value.substring(0, value.length() - 1); | ||
| } | ||
| if(plugin.getRegionHandler().getRegionByName(name) == null){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "That region does not exist!"); | ||
| }else{ | ||
| if(RegionKey.isKey(key)){ | ||
| plugin.getRegionHandler().editRegion(plugin.getRegionHandler().getRegionByName(name), RegionKey.getKey(key), value, sender); | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "That is not a valid region key"); | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "For keys and values type /as editregion help"); | ||
| } | ||
| } | ||
| } | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "You do not have permission!"); | ||
| } | ||
| return true; | ||
| }else if(args[0].equalsIgnoreCase("listplugins")){ | ||
| if(plugin.getPermissions().has(sender, "AntiShare.regions")){ | ||
| int page = 1; | ||
| if(args.length >= 2){ | ||
| try{ | ||
| page = Integer.parseInt(args[1]); | ||
| }catch(Exception e){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "'" + args[1] + "' is not a number!"); | ||
| return true; | ||
| } | ||
| } | ||
| page = Math.abs(page); | ||
| int resultsPerPage = 6; // For ease of changing | ||
| Vector<ASRegion> regions = plugin.storage.getAllRegions(); | ||
| int maxPages = (int) Math.ceil(regions.size() / resultsPerPage); | ||
| if(maxPages < 1){ | ||
| maxPages = 1; | ||
| } | ||
| if(maxPages < page){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "Page " + page + " does not exist! The last page is " + maxPages); | ||
| return true; | ||
| } | ||
| String pagenation = ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "AntiShare Regions " + ChatColor.DARK_GREEN + "|" + ChatColor.GREEN + " Page " + page + "/" + maxPages + ChatColor.DARK_GREEN + " ]======="; | ||
| ASUtils.sendToPlayer(sender, pagenation); | ||
| for(int i = ((page - 1) * resultsPerPage); i < (resultsPerPage < regions.size() ? (resultsPerPage * page) : regions.size()); i++){ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_AQUA + "#" + (i + 1) + " " + ChatColor.GOLD + regions.get(i).getName() | ||
| + ChatColor.YELLOW + " Created By: " + ChatColor.AQUA + regions.get(i).getWhoSet() | ||
| + ChatColor.YELLOW + " World: " + ChatColor.AQUA + regions.get(i).getWorld().getName()); | ||
| } | ||
| ASUtils.sendToPlayer(sender, pagenation); | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.DARK_RED + "You do not have permission!"); | ||
| } | ||
| return true; | ||
| }else if(args[0].equalsIgnoreCase("config")){ | ||
| if(plugin.getPermissions().has(sender, "AntiShare.config")){ | ||
| if(sender instanceof Player){ | ||
| new ConfigurationConversation(plugin, (Player) sender); | ||
| }else{ | ||
| ASUtils.sendToPlayer(sender, ChatColor.RED + "There is no console support for the configuration helper."); | ||
| } | ||
| } | ||
| }else{ | ||
| return false; //Shows usage in plugin.yml | ||
| } | ||
| } | ||
| // Unhandled command (such as /as help, or /as asjkdhgasjdg) | ||
| return false; //Shows usage in plugin.yml | ||
| } | ||
| return false; //Shows usage in plugin.yml | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,82 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import org.bukkit.World; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| import com.feildmaster.lib.configuration.EnhancedConfiguration; | ||
|
|
||
| public class Configuration { | ||
|
|
||
| private AntiShare plugin; | ||
|
|
||
| public Configuration(AntiShare plugin){ | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| public void create(){ | ||
| plugin.getConfig().loadDefaults(plugin.getResource("resources/config.yml")); | ||
| if(!plugin.getConfig().fileExists() || !plugin.getConfig().checkDefaults()){ | ||
| plugin.getConfig().saveDefaults(); | ||
| } | ||
| load(); | ||
| } | ||
|
|
||
| public boolean onlyIfCreative(Player player){ | ||
| if(plugin.getPermissions().has(player, "AntiShare.onlyIfCreative.global", player.getWorld())){ | ||
| return getBoolean("other.only_if_creative", player.getWorld()); | ||
| }else if(plugin.getPermissions().has(player, "AntiShare.onlyIfCreative", player.getWorld())){ | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public Object get(String path, World world){ | ||
| File worldConfig = new File(plugin.getDataFolder(), world.getName() + "_config.yml"); | ||
| EnhancedConfiguration config = new EnhancedConfiguration(worldConfig, plugin); | ||
| Object value = null; | ||
| if(!config.getString(path).equalsIgnoreCase("global")){ | ||
| value = config.get(path); | ||
| }else{ | ||
| value = plugin.getConfig().get(path); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| public boolean getBoolean(String path, World world){ | ||
| File worldConfig = new File(plugin.getDataFolder(), world.getName() + "_config.yml"); | ||
| EnhancedConfiguration config = new EnhancedConfiguration(worldConfig, plugin); | ||
| boolean value = false; | ||
| if(!config.getString(path).equalsIgnoreCase("global")){ | ||
| value = config.getBoolean(path); | ||
| }else{ | ||
| value = plugin.getConfig().getBoolean(path); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| public String getString(String path, World world){ | ||
| File worldConfig = new File(plugin.getDataFolder(), world.getName() + "_config.yml"); | ||
| EnhancedConfiguration config = new EnhancedConfiguration(worldConfig, plugin); | ||
| String value = null; | ||
| if(!config.getString(path).equalsIgnoreCase("global")){ | ||
| value = config.getString(path); | ||
| }else{ | ||
| value = plugin.getConfig().getString(path); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| public void reload(){ | ||
| load(); | ||
| } | ||
|
|
||
| public void save(){ | ||
| plugin.saveConfig(); | ||
| } | ||
|
|
||
| public void load(){ | ||
| plugin.reloadConfig(); | ||
| } | ||
| } |
| @@ -0,0 +1,153 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import org.bukkit.plugin.Plugin; | ||
|
|
||
| public class Conflicts { | ||
|
|
||
| public boolean INVENTORY_CONFLICT_PRESENT = false; | ||
| public boolean CREATIVE_MANAGER_CONFLICT_PRESENT = false; | ||
| public boolean WORLD_MANAGER_CONFLICT_PRESENT = false; | ||
| public boolean OTHER_CONFLICT_PRESENT = false; | ||
|
|
||
| public String INVENTORY_CONFLICT = "None"; | ||
| public String CREATIVE_MANAGER_CONFLICT = "None"; | ||
| public String WORLD_MANAGER_CONFLICT = "None"; | ||
| public String OTHER_CONFLICT = "None"; | ||
|
|
||
| public Conflicts(AntiShare plugin){ | ||
| findInventoryManagerConflicts(plugin.getServer().getPluginManager().getPlugins()); | ||
| findCreativeModeManagerConflicts(plugin.getServer().getPluginManager().getPlugins()); | ||
| findWorldManagerConflicts(plugin.getServer().getPluginManager().getPlugins()); | ||
| findOtherConflicts(plugin.getServer().getPluginManager().getPlugins()); | ||
| if(INVENTORY_CONFLICT_PRESENT){ | ||
| AntiShare.log.severe("[AntiShare-Conflicts] Inventory Manager Conflict: " + INVENTORY_CONFLICT); | ||
| AntiShare.log.severe("[AntiShare-Conflicts] AntiShare will not deal with inventories because of the conflict"); | ||
| } | ||
| if(CREATIVE_MANAGER_CONFLICT_PRESENT){ | ||
| AntiShare.log.severe("[AntiShare-Conflicts] Creative Mode Manager Conflict: " + CREATIVE_MANAGER_CONFLICT); | ||
| AntiShare.log.severe("[AntiShare-Conflicts] AntiShare will disable itself because of the conflict"); | ||
| plugin.getServer().getPluginManager().disablePlugin(plugin); | ||
| } | ||
| if(WORLD_MANAGER_CONFLICT_PRESENT){ | ||
| AntiShare.log.severe("[AntiShare-Conflicts] World Manager Conflict: " + WORLD_MANAGER_CONFLICT); | ||
| AntiShare.log.severe("[AntiShare-Conflicts] AntiShare will not deal with allowance of world transfers because of the conflict"); | ||
| } | ||
| if(OTHER_CONFLICT_PRESENT){ | ||
| AntiShare.log.severe("[AntiShare-Conflicts] Other Conflict: " + OTHER_CONFLICT); | ||
| AntiShare.log.severe("[AntiShare-Conflicts] AntiShare won't do anything, but there may be problems because of the conflict"); | ||
| } | ||
| } | ||
|
|
||
| private void findInventoryManagerConflicts(Plugin[] plugins){ | ||
| for(Plugin plugin : plugins){ | ||
| String name = plugin.getName(); | ||
| if(name.equalsIgnoreCase("ClearInv")){ | ||
| INVENTORY_CONFLICT_PRESENT = true; | ||
| INVENTORY_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("ChangeDat")){ | ||
| INVENTORY_CONFLICT_PRESENT = true; | ||
| INVENTORY_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("MultiInv") || name.equalsIgnoreCase("Multiverse-Inventories")){ | ||
| INVENTORY_CONFLICT_PRESENT = true; | ||
| INVENTORY_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("Multiworld")){ | ||
| INVENTORY_CONFLICT_PRESENT = true; | ||
| INVENTORY_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("AutoGamemode")){ | ||
| INVENTORY_CONFLICT_PRESENT = true; | ||
| INVENTORY_CONFLICT = name; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void findCreativeModeManagerConflicts(Plugin[] plugins){ | ||
| for(Plugin plugin : plugins){ | ||
| String name = plugin.getName(); | ||
| if(name.equalsIgnoreCase("CreativeControl")){ | ||
| CREATIVE_MANAGER_CONFLICT_PRESENT = true; | ||
| CREATIVE_MANAGER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("BurningCreativeSuite") || name.equalsIgnoreCase("BurningCreative") || name.equalsIgnoreCase("BCS")){ | ||
| CREATIVE_MANAGER_CONFLICT_PRESENT = true; | ||
| CREATIVE_MANAGER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("LimitedCreative")){ | ||
| CREATIVE_MANAGER_CONFLICT_PRESENT = true; | ||
| CREATIVE_MANAGER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("Anti-Place-Destroy-Ignite") || name.equalsIgnoreCase("APDI")){ | ||
| CREATIVE_MANAGER_CONFLICT_PRESENT = true; | ||
| CREATIVE_MANAGER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("iCreative")){ | ||
| CREATIVE_MANAGER_CONFLICT_PRESENT = true; | ||
| CREATIVE_MANAGER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("GameModeNoPlace")){ | ||
| CREATIVE_MANAGER_CONFLICT_PRESENT = true; | ||
| CREATIVE_MANAGER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("NoDrop")){ | ||
| CREATIVE_MANAGER_CONFLICT_PRESENT = true; | ||
| CREATIVE_MANAGER_CONFLICT = name; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void findWorldManagerConflicts(Plugin[] plugins){ | ||
| for(Plugin plugin : plugins){ | ||
| String name = plugin.getName(); | ||
| if(name.toLowerCase().contains("multiverse")){ // Will likely have MV-Core | ||
| WORLD_MANAGER_CONFLICT_PRESENT = true; | ||
| WORLD_MANAGER_CONFLICT = "Multiverse"; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("Multiworld")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void findOtherConflicts(Plugin[] plugins){ | ||
| for(Plugin plugin : plugins){ | ||
| String name = plugin.getName(); | ||
| if(name.equalsIgnoreCase("AntiGrief")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("MobEggs")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("WorldGuard")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("CreativeStick")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| }else if(name.equalsIgnoreCase("Regios")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| }else if(name.toLowerCase().startsWith("voxel")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| }else if(name.toLowerCase().startsWith("essentials")){ | ||
| OTHER_CONFLICT_PRESENT = true; | ||
| OTHER_CONFLICT = name; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,53 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.GameMode; | ||
| import org.bukkit.Location; | ||
| import org.bukkit.World; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| import com.feildmaster.lib.configuration.EnhancedConfiguration; | ||
|
|
||
| public class MultiWorld { | ||
|
|
||
| public static void detectWorlds(AntiShare plugin){ | ||
| for(World w : Bukkit.getWorlds()){ | ||
| String worldName = w.getName(); | ||
| File worldConfig = new File(plugin.getDataFolder(), worldName + "_config.yml"); | ||
| EnhancedConfiguration worldSettings = new EnhancedConfiguration(worldConfig, plugin); | ||
| worldSettings.loadDefaults(plugin.getResource("resources/world.yml")); | ||
| if(!worldSettings.fileExists() || !worldSettings.checkDefaults()){ | ||
| worldSettings.saveDefaults(); | ||
| } | ||
| worldSettings.load(); | ||
| } | ||
| } | ||
|
|
||
| // Returns allowance of worldSwap | ||
| public static boolean worldSwap(AntiShare plugin, Player player, Location from, Location to){ | ||
| if(plugin.getPermissions().has(player, "AntiShare.worlds", to.getWorld())){ | ||
| return true; | ||
| } | ||
| if(plugin.getConflicts().WORLD_MANAGER_CONFLICT_PRESENT){ | ||
| return true; | ||
| } | ||
| World worldTo = to.getWorld(); | ||
| boolean transfers = plugin.config().getBoolean("other.worldTransfer", worldTo); | ||
| boolean creative = plugin.config().getBoolean("other.only_if_creative", worldTo); | ||
| if(transfers){ | ||
| return true; | ||
| }else{ | ||
| if(creative){ | ||
| if(player.getGameMode() == GameMode.CREATIVE){ | ||
| return false; | ||
| }else{ | ||
| return true; | ||
| } | ||
| }else{ | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,233 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| import com.turt2live.antishare.enums.BlockedType; | ||
| import com.turt2live.antishare.enums.NotificationType; | ||
|
|
||
| public class Notification { | ||
|
|
||
| public static void sendNotification(NotificationType type, AntiShare plugin, Player player, String variable, Material material){ | ||
| if(!plugin.getConfig().getBoolean("notifications.send")){ | ||
| return; | ||
| } | ||
| if(plugin.getPermissions().has(player, "AntiShare.silent", player.getWorld())){ | ||
| return; | ||
| } | ||
| variable = variable.replaceAll("_", " "); | ||
| String message = ""; | ||
| switch (type){ | ||
| // ILLEGAL actions | ||
| case ILLEGAL_BLOCK_PLACE: | ||
| if(variable.equalsIgnoreCase("BEDROCK")){ | ||
| break; | ||
| } | ||
| if(plugin.storage.isBlocked(material, BlockedType.INTERACT, player.getWorld())){ | ||
| break; | ||
| } | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.block_place")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to place " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_BLOCK_BREAK: | ||
| if(variable.equalsIgnoreCase("BEDROCK")){ | ||
| break; | ||
| } | ||
| if(plugin.storage.isBlocked(material, BlockedType.INTERACT, player.getWorld())){ | ||
| break; | ||
| } | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.block_break")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to break " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_CREATIVE_BLOCK_BREAK: | ||
| if(variable.equalsIgnoreCase("BEDROCK")){ | ||
| break; | ||
| } | ||
| if(plugin.storage.isBlocked(material, BlockedType.INTERACT, player.getWorld())){ | ||
| break; | ||
| } | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.creative_block_break")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to break the creative block " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_WORLD_CHANGE: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.world_transfer")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to go to world " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_COMMAND: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.command")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to send the command " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_DEATH: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.death")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to die in " + ChatColor.DARK_RED + variable + ChatColor.AQUA + " mode!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_DROP_ITEM: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.drop_item")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to drop the item " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_INTERACTION: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.interact")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to interact with " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_PLAYER_PVP: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.pvp")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to hit " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_MOB_PVP: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.mob-pvp")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to hit a " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_EGG: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.egg")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to use a " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_EXP_BOTTLE: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.exp_bottle")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to use an " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_BEDROCK: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.bedrock_attempt")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " tried to use " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case ILLEGAL_ITEM_THROW_INTO_REGION: | ||
| if(plugin.getConfig().getBoolean("notifications.illegal.drop_item_to_region")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " threw an item into the region " + ChatColor.DARK_RED + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
|
|
||
| // LEGAL actions | ||
| case LEGAL_BLOCK_PLACE: | ||
| if(variable.equalsIgnoreCase("BEDROCK")){ | ||
| break; | ||
| } | ||
| if(plugin.storage.isBlocked(material, BlockedType.INTERACT, player.getWorld())){ | ||
| break; | ||
| } | ||
| if(plugin.getConfig().getBoolean("notifications.legal.block_place")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " placed " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_BLOCK_BREAK: | ||
| if(variable.equalsIgnoreCase("BEDROCK")){ | ||
| break; | ||
| } | ||
| if(plugin.storage.isBlocked(material, BlockedType.INTERACT, player.getWorld())){ | ||
| break; | ||
| } | ||
| if(plugin.getConfig().getBoolean("notifications.legal.block_break")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " broke " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_CREATIVE_BLOCK_BREAK: | ||
| if(variable.equalsIgnoreCase("BEDROCK")){ | ||
| break; | ||
| } | ||
| if(plugin.storage.isBlocked(material, BlockedType.INTERACT, player.getWorld())){ | ||
| break; | ||
| } | ||
| if(plugin.getConfig().getBoolean("notifications.legal.creative_block_break")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " broke the creative block " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_WORLD_CHANGE: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.world_transfer")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " went to world " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_COMMAND: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.command")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " sent the command " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_DEATH: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.death")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " died in " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + " mode!"; | ||
| } | ||
| break; | ||
| case LEGAL_DROP_ITEM: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.drop_item")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " dropped the item " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_INTERACTION: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.interact")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " interacted with " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_PLAYER_PVP: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.pvp")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " hit " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_MOB_PVP: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.mob-pvp")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " hit a " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_EGG: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.egg")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " used a " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_EXP_BOTTLE: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.exp_bottle")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " used an " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_BEDROCK: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.bedrock_attempt")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " used " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case LEGAL_ITEM_THROW_INTO_REGION: | ||
| if(plugin.getConfig().getBoolean("notifications.legal.drop_item_to_region")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " threw an item into the region " + ChatColor.DARK_GREEN + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
|
|
||
| // GENERAL actions | ||
| case GAMEMODE_CHANGE: | ||
| if(plugin.getConfig().getBoolean("notifications.general.gamemode_change")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " changed to gamemode " + ChatColor.BLUE + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case REGION_ENTER: | ||
| if(plugin.getConfig().getBoolean("notifications.general.region_enter")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " entered the region " + ChatColor.BLUE + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| case REGION_EXIT: | ||
| if(plugin.getConfig().getBoolean("notifications.general.region_exit")){ | ||
| message = ChatColor.GRAY + "[AntiShare] " + ChatColor.AQUA + player.getName() + " left the region " + ChatColor.BLUE + variable + ChatColor.AQUA + "!"; | ||
| } | ||
| break; | ||
| } | ||
| if(message.length() > 0){ | ||
| Bukkit.broadcast(message, "AntiShare.notify"); | ||
| } | ||
| } | ||
|
|
||
| public static void sendNotification(NotificationType type, Player player, String variable, Material material){ | ||
| sendNotification(type, (AntiShare) Bukkit.getServer().getPluginManager().getPlugin("AntiShare"), player, variable, material); | ||
| } | ||
|
|
||
| public static void sendNotification(NotificationType type, Player player, String variable){ | ||
| sendNotification(type, (AntiShare) Bukkit.getServer().getPluginManager().getPlugin("AntiShare"), player, variable, null); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,175 @@ | ||
| package com.turt2live.antishare.SQL; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.sql.Statement; | ||
|
|
||
| import com.turt2live.antishare.AntiShare; | ||
|
|
||
| /* | ||
| * Thanks go to Example Depot for teaching me everything in this class. | ||
| * http://www.exampledepot.com/egs/java.sql/pkg.html | ||
| */ | ||
| public class SQLManager { | ||
|
|
||
| private AntiShare plugin; | ||
| private Connection connection; | ||
|
|
||
| public SQLManager(AntiShare plugin){ | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| public boolean attemptConnectFromConfig(){ | ||
| String host = plugin.getConfig().getString("SQL.host"); | ||
| String username = plugin.getConfig().getString("SQL.username"); | ||
| String password = plugin.getConfig().getString("SQL.password"); | ||
| int port = plugin.getConfig().getInt("SQL.port"); | ||
| String database = plugin.getConfig().getString("SQL.database"); | ||
| return connect(host, username, password, port, database); | ||
| } | ||
|
|
||
| public boolean connect(String host, String username, String password, int port, String database){ | ||
| try{ | ||
| String driverName = "org.gjt.mm.mysql.Driver"; | ||
| Class.forName(driverName); | ||
| String url = "jdbc:mysql://" + host + "/" + database; | ||
| connection = DriverManager.getConnection(url, username, password); | ||
| return true; | ||
| }catch(ClassNotFoundException e){ | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] You do not have a MySQL driver, please install one. AntiShare will use Flat-File for now"); | ||
| }catch(SQLException e){ | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] Cannot connect to SQL! Check your settings. AntiShare will use Flat-File for now"); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public void disconnect(){ | ||
| if(connection != null){ | ||
| try{ | ||
| if(!connection.isClosed()){ | ||
| connection.close(); | ||
| } | ||
| }catch(SQLException e){ | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] Cannot close SQL connection: " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void checkConnection(){ | ||
| if(connection == null){ | ||
| attemptConnectFromConfig(); | ||
| } | ||
| } | ||
|
|
||
| public boolean isConnected(){ | ||
| return connection != null; | ||
| } | ||
|
|
||
| public void checkValues(){ | ||
| if(!isConnected()){ | ||
| return; | ||
| } | ||
| createQuery("CREATE TABLE IF NOT EXISTS `AntiShare_Inventory` (" + | ||
| " `id` int(11) NOT NULL AUTO_INCREMENT," + | ||
| " `username` varchar(20) NOT NULL," + | ||
| " `gamemode` varchar(25) NOT NULL," + | ||
| " `slot` int(11) NOT NULL," + | ||
| " `itemID` int(11) NOT NULL," + | ||
| " `itemName` varchar(25) NOT NULL," + | ||
| " `itemDurability` int(11) NOT NULL," + | ||
| " `itemAmount` int(11) NOT NULL," + | ||
| " `itemData` int(11) NOT NULL," + | ||
| " `itemEnchant` varchar(100) NOT NULL," + | ||
| " `world` varchar(100) NOT NULL," + | ||
| " PRIMARY KEY (`id`)" + | ||
| ")"); | ||
| createQuery("CREATE TABLE IF NOT EXISTS `AntiShare_Regions` (" + | ||
| " `id` int(11) NOT NULL AUTO_INCREMENT," + | ||
| " `regionName` varchar(255) NOT NULL," + | ||
| " `mix` decimal(11,25) NOT NULL," + | ||
| " `miy` decimal(11,25) NOT NULL," + | ||
| " `miz` decimal(11,25) NOT NULL," + | ||
| " `max` decimal(11,25) NOT NULL," + | ||
| " `may` decimal(11,25) NOT NULL," + | ||
| " `maz` decimal(11,25) NOT NULL," + | ||
| " `creator` varchar(25) NOT NULL," + | ||
| " `gamemode` varchar(25) NOT NULL," + | ||
| " `showEnter` int(11) NOT NULL," + | ||
| " `showExit` int(11) NOT NULL," + | ||
| " `world` varchar(100) NOT NULL," + | ||
| " `uniqueID` varchar(100) NOT NULL," + | ||
| " `enterMessage` varchar(300) NOT NULL," + | ||
| " `exitMessage` varchar(300) NOT NULL," + | ||
| " PRIMARY KEY (`id`)" + | ||
| ")"); | ||
| createQuery("CREATE TABLE IF NOT EXISTS `AntiShare_RegionInfo` (" + | ||
| " `id` int(11) NOT NULL AUTO_INCREMENT," + | ||
| " `player` varchar(255) NOT NULL," + | ||
| " `region` varchar(255) NOT NULL," + | ||
| " `gamemode` varchar(255) NOT NULL," + | ||
| " PRIMARY KEY (`id`)" + | ||
| ")"); | ||
| createQuery("CREATE TABLE IF NOT EXISTS `AntiShare_MiscInventory` (" + | ||
| " `id` int(11) NOT NULL AUTO_INCREMENT," + | ||
| " `uniqueID` varchar(255) NOT NULL," + | ||
| " `slot` int(11) NOT NULL," + | ||
| " `itemID` int(11) NOT NULL," + | ||
| " `itemName` varchar(25) NOT NULL," + | ||
| " `itemDurability` int(11) NOT NULL," + | ||
| " `itemAmount` int(11) NOT NULL," + | ||
| " `itemData` int(11) NOT NULL," + | ||
| " `itemEnchant` varchar(100) NOT NULL," + | ||
| " PRIMARY KEY (`id`)" + | ||
| ")"); | ||
| } | ||
|
|
||
| public String getDatabase(){ | ||
| return plugin.getConfig().getString("SQL.database"); | ||
| } | ||
|
|
||
| public void createQuery(String query){ | ||
| updateQuery(query); | ||
| } | ||
|
|
||
| public int deleteQuery(String query){ | ||
| return updateQuery(query); | ||
| } | ||
|
|
||
| public ResultSet getQuery(String query){ | ||
| try{ | ||
| Statement stmt = connection.createStatement(); | ||
| return stmt.executeQuery(query); | ||
| }catch(SQLException e){ | ||
| e.printStackTrace(); | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] Something went wrong with the query. Send this to the developer:"); | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] QUERY: " + query); | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] MESSAGE: " + e.getMessage()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public void insertQuery(String query){ | ||
| try{ | ||
| Statement stmt = connection.createStatement(); | ||
| stmt.executeUpdate(query); | ||
| }catch(SQLException e){ | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] Something went wrong with the query. Send this to the developer:"); | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] QUERY: " + query); | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] MESSAGE: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public int updateQuery(String query){ | ||
| try{ | ||
| Statement stmt = connection.createStatement(); | ||
| return stmt.executeUpdate(query); | ||
| }catch(SQLException e){ | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] Something went wrong with the query. Send this to the developer:"); | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] QUERY: " + query); | ||
| AntiShare.log.severe("[" + plugin.getDescription().getFullName() + "] MESSAGE: " + e.getMessage()); | ||
| } | ||
| return 0; | ||
| } | ||
| } |
| @@ -0,0 +1,26 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
|
|
||
| public class TimedSave { | ||
|
|
||
| private int id = -1; | ||
|
|
||
| public TimedSave(final AntiShare plugin, int ticks){ | ||
| id = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable(){ | ||
| @Override | ||
| public void run(){ | ||
| plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), "as rl"); | ||
| } | ||
| }, ticks, ticks); | ||
| if(id == -1){ | ||
| AntiShare.log.severe("[AntiShare] Save thread cannot be created."); | ||
| } | ||
| } | ||
|
|
||
| public void cancel(){ | ||
| if(id != -1){ | ||
| Bukkit.getScheduler().cancelTask(id); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,30 @@ | ||
| package com.turt2live.antishare; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.net.URL; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
|
|
||
| public class UsageStatistics { | ||
|
|
||
| public static void send(AntiShare plugin){ | ||
| if(!plugin.getConfig().getBoolean("settings.send-use-info")){ | ||
| return; | ||
| } | ||
| String pluginVersion = plugin.getDescription().getVersion(); | ||
| String bukkitVersion = Bukkit.getBukkitVersion(); | ||
| try{ | ||
| URL statsURL = new URL("http://mc.turt2live.com/plugins/plugin_stats.php?plugin=AntiShare&version=" + pluginVersion + "&cbVersion=" + bukkitVersion); | ||
| BufferedReader in = new BufferedReader(new InputStreamReader(statsURL.openConnection().getInputStream())); | ||
| String line = in.readLine(); | ||
| if(!line.equalsIgnoreCase("sent")){ | ||
| AntiShare.log.warning("[AntiShare] Could not send usage statistics."); | ||
| } | ||
| in.close(); | ||
| }catch(Exception e){ | ||
| AntiShare.log.warning("[AntiShare] Could not send usage statistics."); | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,37 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.FixedSetPrompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
|
|
||
| public abstract class ASMenu extends FixedSetPrompt { | ||
|
|
||
| public ASMenu(String... set){ | ||
| super(set); | ||
| } | ||
|
|
||
| public abstract void displayMenu(Conversable target); | ||
|
|
||
| @Override | ||
| public String getPromptText(ConversationContext context){ | ||
| displayMenu(context.getForWhom()); | ||
| return "Enter an option (" + ChatColor.DARK_AQUA + "dark aqua" + ChatColor.WHITE + " text) from above:"; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getFailedValidationText(ConversationContext context, String invalidInput){ | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.DARK_RED + "=======[ " + ChatColor.RED + "Invalid Option" + ChatColor.DARK_RED + " ]======="); | ||
| return "Please enter one of the following: "; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isInputValid(ConversationContext context, String input){ | ||
| if(ConfigurationConversation.isValid(fixedSet, input, context)){ | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } |
| @@ -0,0 +1,59 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.ConversationFactory; | ||
| import org.bukkit.conversations.ConversationPrefix; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.AntiShare; | ||
|
|
||
| public class ConfigurationConversation extends ConversationFactory { | ||
|
|
||
| public static String PREFIX = ChatColor.GRAY + "[AntiShare] " + ChatColor.WHITE; | ||
|
|
||
| public ConfigurationConversation(AntiShare plugin, Conversable target){ | ||
| super(plugin); | ||
| withModality(true); | ||
| withPrefix(new ConversationPrefix(){ | ||
| @Override | ||
| public String getPrefix(ConversationContext context){ | ||
| return PREFIX; | ||
| } | ||
| }); | ||
| withFirstPrompt(new StartupMessage()); | ||
| withLocalEcho(false); | ||
| thatExcludesNonPlayersWithMessage("Sorry! In-game only!"); | ||
| withConversationCanceller(new ExitInactiveConversation(plugin, 600)); | ||
| withConversationCanceller(new ExitMessageConversation()); | ||
| addConversationAbandonedListener(new ConversationSessionAbandonedListener()); | ||
| buildConversation(target).begin(); | ||
| } | ||
|
|
||
| public static boolean isValid(List<String> list, String input, ConversationContext context){ | ||
| String originalInput = input; | ||
| input = input.trim().toLowerCase(); | ||
| if(input.startsWith("back")){ | ||
| return true; | ||
| } | ||
| for(String item : list){ | ||
| item = item.toLowerCase().trim(); | ||
| if(input.startsWith(item)){ | ||
| String tempInput = originalInput.substring(0, item.length()).toLowerCase() + originalInput.substring(item.length()); | ||
| context.setSessionData("msg_no_node", tempInput.replaceFirst(item, "").trim()); | ||
| context.setSessionData("notification_no_node", tempInput.replaceFirst(item, "").trim()); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public static void showError(Conversable target, String message){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_RED + "=======[ " + ChatColor.RED + "Invalid Option" + ChatColor.DARK_RED + " ]======="); | ||
| ASUtils.sendToConversable(target, message); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,16 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.ConversationAbandonedEvent; | ||
| import org.bukkit.conversations.ConversationAbandonedListener; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
|
|
||
| public class ConversationSessionAbandonedListener implements ConversationAbandonedListener { | ||
|
|
||
| @Override | ||
| public void conversationAbandoned(ConversationAbandonedEvent event){ | ||
| ASUtils.sendToConversable(event.getContext().getForWhom(), ChatColor.GREEN + "Your session was closed."); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,50 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversation; | ||
| import org.bukkit.conversations.InactivityConversationCanceller; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.AntiShare; | ||
|
|
||
| public class ExitInactiveConversation extends InactivityConversationCanceller { | ||
|
|
||
| String time = ""; | ||
|
|
||
| public ExitInactiveConversation(AntiShare plugin, int timeout){ | ||
| super(plugin, timeout); | ||
| int hours = (int) Math.floor(timeout / 3600); | ||
| int minutes = (int) Math.floor((timeout - (hours * 3600)) / 60); | ||
| int seconds = (timeout - ((minutes * 60) + (hours * 3600))); | ||
| if(hours > 0){ | ||
| time = hours + " Hour" + (hours > 1 ? "s" : ""); | ||
| } | ||
| if(minutes > 0){ | ||
| if(time.length() > 0){ | ||
| time = time + ", " + minutes + " Minute" + (minutes > 1 ? "s" : ""); | ||
| }else{ | ||
| time = minutes + " Minute" + (minutes > 1 ? "s" : ""); | ||
| } | ||
| } | ||
| if(seconds > 0){ | ||
| if(time.length() > 0){ | ||
| time = time + ", " + seconds + " Second" + (seconds > 1 ? "s" : ""); | ||
| }else{ | ||
| time = seconds + " Second" + (seconds > 1 ? "s" : ""); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void cancelling(Conversation conversation){ | ||
| ASUtils.sendToConversable(conversation.getForWhom(), ChatColor.RED + "You were inactive for " + time + "."); | ||
| conversation.getContext().setSessionData("terminate", "timeout;" + time); | ||
| super.cancelling(conversation); | ||
| } | ||
|
|
||
| @Override | ||
| public ExitInactiveConversation clone(){ | ||
| return new ExitInactiveConversation((AntiShare) plugin, timeoutSeconds); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,32 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import org.bukkit.conversations.Conversation; | ||
| import org.bukkit.conversations.ConversationCanceller; | ||
| import org.bukkit.conversations.ConversationContext; | ||
|
|
||
| public class ExitMessageConversation implements ConversationCanceller { | ||
|
|
||
| private Conversation conversation; | ||
|
|
||
| @Override | ||
| public boolean cancelBasedOnInput(ConversationContext context, String input){ | ||
| input = input.replaceFirst("/", ""); | ||
| if(input.toLowerCase().startsWith("quit") || input.toLowerCase().startsWith("exit")){ | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void setConversation(Conversation conversation){ | ||
| this.conversation = conversation; | ||
| } | ||
|
|
||
| @Override | ||
| public ConversationCanceller clone(){ | ||
| ExitMessageConversation ret = new ExitMessageConversation(); | ||
| ret.setConversation(conversation); | ||
| return ret; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,54 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.Prompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.AntiShare; | ||
| import com.turt2live.antishare.conversations.configuration.EditConfigurationMenu; | ||
| import com.turt2live.antishare.conversations.permissions.PermissionsMenu; | ||
| import com.turt2live.antishare.conversations.region.EditRegionMenu; | ||
|
|
||
| public class MainMenu extends ASMenu { | ||
|
|
||
| /* | ||
| * TODO: Create a work around | ||
| * ========================= | ||
| * ADD REGION IS UNSUPPORTED | ||
| * ========================= | ||
| * | ||
| * This is because there is no way to get the CommandSender | ||
| * involved. | ||
| */ | ||
|
|
||
| public MainMenu(){ | ||
| super("edit configuration", "edit config", "edit region", "add region", "permissions help", "permissions", "perms", "perms help"); | ||
| } | ||
|
|
||
| @Override | ||
| public void displayMenu(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "Main Menu" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "edit configuration" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the configuration"); | ||
| //ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "add region" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Create a GameMode Region"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "edit region" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit a GameMode Region"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "permissions help" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Get help with the permissions"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Prompt acceptValidatedInput(ConversationContext context, String input){ | ||
| input = input.trim(); | ||
| if(input.equalsIgnoreCase("edit configuration") || input.equalsIgnoreCase("edit config")){ | ||
| return new EditConfigurationMenu(); | ||
| }else if(input.equalsIgnoreCase("edit region")){ | ||
| return new EditRegionMenu(1, (AntiShare) context.getPlugin()); | ||
| }else if(input.equalsIgnoreCase("permissions help") || input.equalsIgnoreCase("perms help") | ||
| || input.equalsIgnoreCase("permissions") || input.equalsIgnoreCase("perms")){ | ||
| return new PermissionsMenu(); | ||
| }else if(input.equalsIgnoreCase("back")){ | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.RED + "You cannot go back from here! If you want to leave try: exit"); | ||
| } | ||
| return new MainMenu(); | ||
| } | ||
| } |
| @@ -0,0 +1,26 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.MessagePrompt; | ||
| import org.bukkit.conversations.Prompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
|
|
||
| public class StartupMessage extends MessagePrompt { | ||
|
|
||
| @Override | ||
| public String getPromptText(ConversationContext context){ | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "AntiShare Configuration Helper" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.GREEN + "These commands will work at anytime!"); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.DARK_AQUA + "exit" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Exits your session, be sure to save first!"); | ||
| return ChatColor.DARK_AQUA + "back" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Sends you back one screen"; | ||
| // Final line is a return to avoid formatting issues client-side | ||
| } | ||
|
|
||
| @Override | ||
| protected Prompt getNextPrompt(ConversationContext context){ | ||
| return new MainMenu(); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,25 @@ | ||
| package com.turt2live.antishare.conversations; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.Prompt; | ||
| import org.bukkit.conversations.StringPrompt; | ||
|
|
||
| public class WaitPrompt extends StringPrompt { | ||
|
|
||
| private Prompt next; | ||
|
|
||
| public WaitPrompt(Prompt next){ | ||
| this.next = next; | ||
| } | ||
|
|
||
| @Override | ||
| public String getPromptText(ConversationContext context){ | ||
| return ChatColor.YELLOW + "Enter anything to continue..."; | ||
| } | ||
|
|
||
| @Override | ||
| public Prompt acceptInput(ConversationContext context, String input){ | ||
| return next; | ||
| } | ||
| } |
| @@ -0,0 +1,47 @@ | ||
| package com.turt2live.antishare.conversations.configuration; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.Prompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.conversations.ASMenu; | ||
| import com.turt2live.antishare.conversations.MainMenu; | ||
|
|
||
| public class EditConfigurationMenu extends ASMenu { | ||
|
|
||
| public EditConfigurationMenu(){ | ||
| super("events", "messages", "notifications", "sql", "other"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Prompt acceptValidatedInput(ConversationContext context, String input){ | ||
| input = input.replaceFirst("/", ""); | ||
| if(input.equalsIgnoreCase("events")){ | ||
| return new EventEditor(); | ||
| }else if(input.equalsIgnoreCase("messages")){ | ||
| return new MessageEditor(); | ||
| }else if(input.equalsIgnoreCase("notifications")){ | ||
| return new NotificationEditor(); | ||
| }else if(input.equalsIgnoreCase("sql")){ | ||
| return new SQLEditor(); | ||
| }else if(input.equalsIgnoreCase("other")){ | ||
| return new OtherEditor(); | ||
| }else if(input.equalsIgnoreCase("back")){ | ||
| return new MainMenu(); | ||
| } | ||
| return new EditConfigurationMenu(); | ||
| } | ||
|
|
||
| @Override | ||
| public void displayMenu(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "Edit Configuration" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "events" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the blocked lists"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "messages" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the messages sent to users"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "notifications" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit which notifications are sent"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "sql" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the SQL options"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "other" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit other options"); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,51 @@ | ||
| package com.turt2live.antishare.conversations.configuration; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.Prompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.AntiShare; | ||
| import com.turt2live.antishare.conversations.ASMenu; | ||
|
|
||
| public class EventEditor extends ASMenu { | ||
|
|
||
| public EventEditor(){ | ||
| super("block place", "block break", "item drop", "interact", "death", "commands"); | ||
| } | ||
|
|
||
| @Override | ||
| public void displayMenu(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "Events" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "block place" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the block place blacklist"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "block break" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the block break blacklist"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "item drop" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the items that cannot be thrown"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "interact" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the clicked blocks blacklist"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "death" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the spewed items on death blacklist"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "commands" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Edit the commands blcacklist"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Prompt acceptValidatedInput(ConversationContext context, String input){ | ||
| input = input.toLowerCase().trim(); | ||
| AntiShare plugin = (AntiShare) context.getPlugin(); | ||
| if(input.equalsIgnoreCase("block place")){ | ||
| return new EventOptionEditor(plugin.getConfig().getString("events.block_place"), "block_place", "Block Place Blacklist Editor"); | ||
| }else if(input.equalsIgnoreCase("block break")){ | ||
| return new EventOptionEditor(plugin.getConfig().getString("events.block_break"), "block_break", "Block Break Blacklist Editor"); | ||
| }else if(input.equalsIgnoreCase("item drop")){ | ||
| return new EventOptionEditor(plugin.getConfig().getString("events.drop_item"), "drop_item", "Blocked Item Drops Editor"); | ||
| }else if(input.equalsIgnoreCase("interact")){ | ||
| return new EventOptionEditor(plugin.getConfig().getString("events.interact"), "interact", "Blocked Interactions Editor"); | ||
| }else if(input.equalsIgnoreCase("death")){ | ||
| return new EventOptionEditor(plugin.getConfig().getString("events.death"), "death", "Blocked Death Item Editor"); | ||
| }else if(input.equalsIgnoreCase("commands")){ | ||
| return new EventOptionEditor(plugin.getConfig().getString("events.commands"), "commands", "Blocked Commands Editor"); | ||
| }else if(input.equalsIgnoreCase("back")){ | ||
| return new EditConfigurationMenu(); | ||
| } | ||
| return new EventEditor(); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,68 @@ | ||
| package com.turt2live.antishare.conversations.configuration; | ||
|
|
||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.Prompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.AntiShare; | ||
| import com.turt2live.antishare.conversations.ASMenu; | ||
| import com.turt2live.antishare.conversations.WaitPrompt; | ||
|
|
||
| public class EventOptionEditor extends ASMenu { | ||
|
|
||
| private String value; | ||
| private String eventName; | ||
| private String menuTitle; | ||
|
|
||
| public EventOptionEditor(String value, String eventName, String menuTitle){ | ||
| super("add", "set"); | ||
| this.value = value; | ||
| this.eventName = eventName; | ||
| this.menuTitle = menuTitle; | ||
| } | ||
|
|
||
| @Override | ||
| public void displayMenu(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + menuTitle + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "add <value>" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Adds a value to the list"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "set <value>" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Sets the list equal to <value>"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA + "Note: You must use spaces to idenity item IDs! For example: add 1 384 46"); | ||
| ASUtils.sendToConversable(target, ChatColor.YELLOW + "Don't want anyting blocked? Use " + ChatColor.GOLD + "set none"); | ||
| ASUtils.sendToConversable(target, ChatColor.YELLOW + "Want everything blocked? Use " + ChatColor.GOLD + "set *"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "Current Value: " + ChatColor.GREEN + value); | ||
| } | ||
|
|
||
| @Override | ||
| protected Prompt acceptValidatedInput(ConversationContext context, String input){ | ||
| input = input.toLowerCase().trim(); | ||
| if(input.startsWith("set")){ | ||
| input = input.replaceFirst("set", "").trim(); | ||
| value = input; | ||
| }else if(input.startsWith("add")){ | ||
| input = input.replaceFirst("add", "").trim(); | ||
| value = value + " " + input; | ||
| }else if(input.startsWith("back")){ | ||
| return new EventEditor(); | ||
| } | ||
| value = value.trim(); | ||
| ((AntiShare) context.getPlugin()).getConfig().set("events." + eventName, value); | ||
| ((AntiShare) context.getPlugin()).getConfig().save(); | ||
| ((AntiShare) context.getPlugin()).reloadConfig(); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.GREEN + "Value Saved!"); | ||
| return new WaitPrompt(new EventEditor()); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPromptText(ConversationContext context){ | ||
| displayMenu(context.getForWhom()); | ||
| return "Enter a value using the prefixes listed above:"; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getFailedValidationText(ConversationContext context, String invalidInput){ | ||
| return "Please use add or set!"; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,126 @@ | ||
| package com.turt2live.antishare.conversations.configuration; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.Prompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.AntiShare; | ||
| import com.turt2live.antishare.conversations.ASMenu; | ||
| import com.turt2live.antishare.conversations.WaitPrompt; | ||
|
|
||
| public class MessageEditor extends ASMenu { | ||
|
|
||
| public MessageEditor(){ | ||
| super("show", "help", "block break", "block place", "death", "drop item", "eggs", "interact", | ||
| "exp bottle", "inventory swap", "bedrock", "creative block", "pvp", "mob pvp", "no drops", | ||
| "command", "world swap", "throw to region"); | ||
| } | ||
|
|
||
| @Override | ||
| public void displayMenu(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "Messages" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "<type> <value>" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Sets the message for <type>"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "help" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Shows a list of <type>'s"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "show <type>" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Shows the current value of <type>"); | ||
| ASUtils.sendToConversable(target, ChatColor.GOLD + "Note: " + ChatColor.YELLOW + "Messages are only sent on illegal actions"); | ||
| ASUtils.sendToConversable(target, ChatColor.GOLD + "Note: " + ChatColor.YELLOW + "For 'throw to region', use {name} to use the name of the region!"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Prompt acceptValidatedInput(ConversationContext context, String input){ | ||
| input = input.toLowerCase().trim(); | ||
| AntiShare plugin = (AntiShare) context.getPlugin(); | ||
| Conversable target = context.getForWhom(); | ||
| if(input.startsWith("help")){ | ||
| showMessageTypes(target); | ||
| return new WaitPrompt(new MessageEditor()); | ||
| }else if(input.startsWith("show")){ | ||
| String node = input.replace("show", "").trim(); | ||
| if(nodeIsValid(node)){ | ||
| String value = plugin.getConfig().getString("messages." + getProperNode(node)); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "Current value for '" + node + "': " + value); | ||
| }else{ | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.DARK_RED + "=======[ " + ChatColor.RED + "Invalid Type" + ChatColor.DARK_RED + " ]======="); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.RED + "Please use one of the following: "); | ||
| showMessageTypes(target); | ||
| } | ||
| return new WaitPrompt(new MessageEditor()); | ||
| }else if(input.startsWith("back")){ | ||
| return new EditConfigurationMenu(); | ||
| }else{ // All the other nodes, no need to check if valid | ||
| String value = (String) context.getSessionData("msg_no_node"); | ||
| plugin.getConfig().set("messages." + getProperNode(input), value); | ||
| plugin.getConfig().save(); | ||
| Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "as rl"); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.GREEN + "Value Saved!"); | ||
| return new WaitPrompt(new MessageEditor()); | ||
| } | ||
| } | ||
|
|
||
| private String getProperNode(String node){ | ||
| node = node.toLowerCase().trim(); | ||
| if(node.startsWith("block")){ // Place / Break | ||
| node = node.replace("block ", "block_"); | ||
| }else if(node.startsWith("drop item")){ | ||
| node = "drop_item"; | ||
| }else if(node.startsWith("inventory swap")){ | ||
| node = "inventory_swap"; | ||
| }else if(node.startsWith("creative block")){ | ||
| node = "creativeModeBlock"; | ||
| }else if(node.startsWith("exp bottle")){ | ||
| node = "exp_bottle"; | ||
| }else if(node.startsWith("mob pvp")){ | ||
| node = "mobpvp"; | ||
| }else if(node.startsWith("no drops")){ | ||
| node = "noBlockDrop"; | ||
| }else if(node.startsWith("command")){ | ||
| node = "illegalCommand"; | ||
| }else if(node.startsWith("world swap")){ | ||
| node = "worldSwap"; | ||
| }else if(node.startsWith("throw to region")){ | ||
| node = "throwItemIntoRegion"; | ||
| } | ||
| // death, interact, bedrock, pvp, and eggs are all covered | ||
| return node; | ||
| } | ||
|
|
||
| private boolean nodeIsValid(String node){ | ||
| node = node.toLowerCase().trim(); | ||
| return node.startsWith("block break") || node.startsWith("block place") || node.startsWith("death") | ||
| || node.startsWith("drop item") || node.startsWith("eggs") || node.startsWith("interact") | ||
| || node.startsWith("exp bottle") || node.startsWith("inventory swap") || node.startsWith("bedrock") | ||
| || node.startsWith("creative block") || node.startsWith("pvp") || node.startsWith("mob pvp") | ||
| || node.startsWith("no drops") || node.startsWith("command") || node.startsWith("world swap") | ||
| || node.startsWith("throw to region"); | ||
|
|
||
| } | ||
|
|
||
| private void showMessageTypes(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "Message Types" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "block break " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " block place " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " death"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "drop item " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " interact " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " eggs"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "exp bottle " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " inventory swap " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " bedrock"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "creative block " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " pvp " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " mob pvp"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "no drops " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " command " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " world swap"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA + "throw to region"); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,181 @@ | ||
| package com.turt2live.antishare.conversations.configuration; | ||
|
|
||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.ChatColor; | ||
| import org.bukkit.conversations.Conversable; | ||
| import org.bukkit.conversations.ConversationContext; | ||
| import org.bukkit.conversations.Prompt; | ||
|
|
||
| import com.turt2live.antishare.ASUtils; | ||
| import com.turt2live.antishare.AntiShare; | ||
| import com.turt2live.antishare.conversations.ASMenu; | ||
| import com.turt2live.antishare.conversations.ConfigurationConversation; | ||
| import com.turt2live.antishare.conversations.WaitPrompt; | ||
|
|
||
| public class NotificationEditor extends ASMenu { | ||
|
|
||
| public NotificationEditor(){ | ||
| super("show", "help", "on", "off", | ||
|
|
||
| "legal block break", "legal block place", "legal death", "legal drop item", "legal eggs", "legal interact", | ||
| "legal exp bottle", "legal bedrock", "legal creative block", "legal pvp", "legal mob pvp", "legal command", "legal world swap", | ||
| "legal throw to region", | ||
|
|
||
| "illegal block break", "illegal block place", "illegal death", "illegal drop item", "illegal eggs", "illegal interact", | ||
| "illegal exp bottle", "illegal bedrock", "illegal creative block", "illegal pvp", "illegal mob pvp", "illegal command", "illegal world swap", | ||
| "illegal throw to region", | ||
|
|
||
| "gamemode change", "region enter", "region exit"); | ||
| } | ||
|
|
||
| @Override | ||
| public void displayMenu(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "Notifications" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "<type> <value>" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Sets <type> to on or off"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "help" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Shows a list of <type>'s"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "on" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Allows sending of notifications"); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "off" + ChatColor.GOLD + " - " + ChatColor.AQUA + "Stops sending of notifications"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Prompt acceptValidatedInput(ConversationContext context, String input){ | ||
| input = input.toLowerCase().trim(); | ||
| AntiShare plugin = (AntiShare) context.getPlugin(); | ||
| Conversable target = context.getForWhom(); | ||
| if(input.startsWith("help")){ | ||
| showMessageTypes(target); | ||
| return new WaitPrompt(new NotificationEditor()); | ||
| }else if(input.startsWith("show")){ | ||
| String node = input.replace("show", "").trim(); | ||
| if(nodeIsValid(node)){ | ||
| String value = plugin.getConfig().getString("messages." + getProperNode(node)); | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_AQUA + "Current value for '" + node + "': " + value); | ||
| }else{ | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.DARK_RED + "=======[ " + ChatColor.RED + "Invalid Type" + ChatColor.DARK_RED + " ]======="); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.RED + "Please use one of the following: "); | ||
| showMessageTypes(target); | ||
| } | ||
| return new WaitPrompt(new NotificationEditor()); | ||
| }else if(input.startsWith("back")){ | ||
| return new EditConfigurationMenu(); | ||
| }else if(input.equalsIgnoreCase("on")){ | ||
| plugin.getConfig().set("notification.send", true); | ||
| plugin.getConfig().save(); | ||
| Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "as rl"); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.GREEN + "Value Saved!"); | ||
| return new WaitPrompt(new NotificationEditor()); | ||
| }else if(input.equalsIgnoreCase("off")){ | ||
| plugin.getConfig().set("notification.send", false); | ||
| plugin.getConfig().save(); | ||
| Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "as rl"); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.GREEN + "Value Saved!"); | ||
| return new WaitPrompt(new NotificationEditor()); | ||
| }else{ // All the other nodes | ||
| String value = (String) context.getSessionData("notifications_no_node"); | ||
| if(ASUtils.getValueOf(value) == null){ | ||
| ConfigurationConversation.showError(target, ChatColor.RED + "'" + input + "' is not valid! Did you mean true, or false?"); | ||
| return new NotificationEditor(); | ||
| }else{ | ||
| plugin.getConfig().set("notification." + getProperNode(input), value); | ||
| plugin.getConfig().save(); | ||
| Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "as rl"); | ||
| ASUtils.sendToConversable(context.getForWhom(), ChatColor.GREEN + "Value Saved!"); | ||
| return new WaitPrompt(new NotificationEditor()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private String getProperNode(String node){ | ||
| node = node.toLowerCase().trim(); | ||
| boolean legal = node.startsWith("legal"); | ||
| boolean illegal = node.startsWith("illegal"); | ||
| if(legal){ | ||
| node = node.replaceFirst("legal", ""); | ||
| }else if(illegal){ | ||
| node = node.replaceFirst("illegal", ""); | ||
| } | ||
| if(node.startsWith("block")){ // Place / Break | ||
| node = node.replace("block ", "block_"); | ||
| }else if(node.startsWith("drop item")){ | ||
| node = "drop_item"; | ||
| }else if(node.startsWith("gamemode change")){ | ||
| node = "gamemode_change"; | ||
| }else if(node.startsWith("creative block")){ | ||
| node = "creative_block_break"; | ||
| }else if(node.startsWith("eggs")){ | ||
| node = "egg"; | ||
| }else if(node.startsWith("exp bottle")){ | ||
| node = "exp_bottle"; | ||
| }else if(node.startsWith("mob pvp")){ | ||
| node = "mob-pvp"; | ||
| }else if(node.startsWith("command")){ | ||
| node = "illegalCommand"; | ||
| }else if(node.startsWith("world swap")){ | ||
| node = "world_transfer"; | ||
| }else if(node.startsWith("throw to region")){ | ||
| node = "drop_item_to_region"; | ||
| }else if(node.startsWith("bedrock")){ | ||
| node = "bedrock_attempt"; | ||
| }else if(node.startsWith("region")){ // Enter / Exit | ||
| node = node.replace("region ", "region_"); | ||
| } | ||
| // death, interact, and pvp are all covered | ||
| String prefix = "general."; | ||
| if(legal){ | ||
| prefix = "legal."; | ||
| }else if(illegal){ | ||
| prefix = "illegal."; | ||
| } | ||
| return prefix + node; | ||
| } | ||
|
|
||
| private boolean nodeIsValid(String node){ | ||
| node = node.toLowerCase().trim(); | ||
| if(!node.startsWith("illegal") && !node.startsWith("legal")){ | ||
| return false; | ||
| } | ||
| return node.startsWith("legal block break") || node.startsWith("legal block place") || node.startsWith("legal death") | ||
| || node.startsWith("legal drop item") || node.startsWith("legal eggs") || node.startsWith("legal interact") | ||
| || node.startsWith("legal exp bottle") || node.startsWith("legal bedrock") || node.startsWith("legal creative block") | ||
| || node.startsWith("legal pvp") || node.startsWith("legal mob pvp") || node.startsWith("legal command") | ||
| || node.startsWith("legal world swap") || node.startsWith("legal throw to region") | ||
|
|
||
| || node.startsWith("illegal block break") || node.startsWith("illegal block place") || node.startsWith("illegal death") | ||
| || node.startsWith("illegal drop item") || node.startsWith("illegal eggs") || node.startsWith("illegal interact") | ||
| || node.startsWith("illegal exp bottle") || node.startsWith("illegal bedrock") || node.startsWith("illegal creative block") | ||
| || node.startsWith("illegal pvp") || node.startsWith("illegal mob pvp") || node.startsWith("illegal command") | ||
| || node.startsWith("illegal world swap") || node.startsWith("illegal throw to region") | ||
|
|
||
| || node.startsWith("gamemode change") || node.startsWith("region enter") || node.startsWith("region exit"); | ||
|
|
||
| } | ||
|
|
||
| private void showMessageTypes(Conversable target){ | ||
| ASUtils.sendToConversable(target, ChatColor.DARK_GREEN + "=======[ " + ChatColor.GREEN + "Notification Types" + ChatColor.DARK_GREEN + " ]======="); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "<i/l> block break " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> block place " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> death"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "<i/l> drop item " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> interact " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> eggs"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "<i/l> exp bottle " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> command " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> bedrock"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "<i/l> creative block " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> pvp " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> mob pvp"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "<i/l> throw to region " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " <i/l> world swap " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " gamemode change"); | ||
| ASUtils.sendToConversable(target, ChatColor.AQUA | ||
| + "region enter " + ChatColor.DARK_AQUA + "|" + ChatColor.AQUA | ||
| + " region exit"); | ||
| ASUtils.sendToConversable(target, ChatColor.GREEN + "Note: " + ChatColor.DARK_GREEN + "<i/l>" + ChatColor.GREEN + " means you need to specify illegal or legal"); | ||
| } | ||
|
|
||
| } |