Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finally, added entire bin to gitignore. Adding everything back in.

  • Loading branch information...
commit ac5fd64c78ef4c595dbd239b2a2ca91de67abe58 1 parent 6da55d5
@Malikk authored
Showing with 3,224 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +44 −0 Shield/src/com/malikk/shield/IncompatibilityHandler.java
  3. +168 −0 Shield/src/com/malikk/shield/Shield.java
  4. +254 −0 Shield/src/com/malikk/shield/ShieldAPI.java
  5. +171 −0 Shield/src/com/malikk/shield/ShieldAPIManager.java
  6. +105 −0 Shield/src/com/malikk/shield/ShieldConfig.java
  7. +384 −0 Shield/src/com/malikk/shield/ShieldPluginManager.java
  8. +35 −0 Shield/src/com/malikk/shield/exceptions/FlagNotFoundException.java
  9. +35 −0 Shield/src/com/malikk/shield/exceptions/InvalidFlagException.java
  10. +36 −0 Shield/src/com/malikk/shield/exceptions/InvalidRegionException.java
  11. +36 −0 Shield/src/com/malikk/shield/exceptions/RegionNotFoundException.java
  12. +128 −0 Shield/src/com/malikk/shield/flags/Flag.java
  13. +105 −0 Shield/src/com/malikk/shield/flags/FlagManager.java
  14. +120 −0 Shield/src/com/malikk/shield/flags/FlagPersister.java
  15. +617 −0 Shield/src/com/malikk/shield/metrics/Metrics.java
  16. +59 −0 Shield/src/com/malikk/shield/plugins/Protect.java
  17. +158 −0 Shield/src/com/malikk/shield/plugins/Protect_PreciousStones.java
  18. +175 −0 Shield/src/com/malikk/shield/plugins/Protect_Regios.java
  19. +199 −0 Shield/src/com/malikk/shield/plugins/Protect_Residence.java
  20. +244 −0 Shield/src/com/malikk/shield/plugins/Protect_WorldGuard.java
  21. +78 −0 Shield/src/com/malikk/shield/regions/RegionManager.java
  22. +69 −0 Shield/src/com/malikk/shield/regions/ShieldRegion.java
View
4 .gitignore
@@ -6,8 +6,12 @@ Shield/.settings/org.eclipse.jdt.core.prefs
Shield/runnable.jardesc
+<<<<<<< HEAD
Shield/bin/*
*.class
+=======
+Shield/bin
+>>>>>>> Finally, added entire bin to gitignore. Adding everything back in.
Shield/.DS_Store
View
44 Shield/src/com/malikk/shield/IncompatibilityHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield;
+
+import java.util.ArrayList;
+
+public class IncompatibilityHandler {
+
+ Shield plugin;
+
+ ArrayList<String> known = new ArrayList<String>();
+
+ public IncompatibilityHandler(Shield instance){
+ plugin = instance;
+ }
+
+ public void incompatible(String name, String method, String lookingFor, String instead){
+ String warning = name + "." + method;
+
+ if (!known.contains(warning)){
+ plugin.logWarning(String.format("%s API does not support '%s' for %s. Instead, %s", name, method, lookingFor, instead));
+ known.add(warning);
+ }
+
+ }
+
+}
View
168 Shield/src/com/malikk/shield/Shield.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield;
+
+import java.util.logging.Logger;
+
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.RegisteredServiceProvider;
+import org.bukkit.plugin.ServicePriority;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import com.malikk.shield.flags.*;
+import com.malikk.shield.metrics.Metrics;
+import com.malikk.shield.plugins.*;
+import com.malikk.shield.regions.RegionManager;
+
+
+/**
+ * <b>Shield</b> - A collection of common Bukkit protection plugin API
+ * <p>
+ * For help implementing Shield, please visit the <a href="https://github.com/Malikk/Shield">Shield Github</a>
+ * <p>
+ * <img src="/Users/Jordan/git/Shield/Shield/lib/Logo.png">
+ * @author Malikk
+ * @version v0.1, 6-13-2012
+ */
+public class Shield extends JavaPlugin{
+
+ protected Logger log = Logger.getLogger("Minecraft");
+ PluginDescriptionFile pdfile = null;
+
+ private boolean foundPlugin = false;
+
+ //Plugin Classes
+ public Protect_PreciousStones preciousStones = null;
+ public Protect_Regios regios = null;
+ public Protect_Residence residence = null;
+ public Protect_WorldGuard worldGuard = null;
+
+ //Shield Classes
+ public IncompatibilityHandler incompat = new IncompatibilityHandler(this);
+ public FlagPersister flagPersister = new FlagPersister(this);
+ public ShieldConfig config = new ShieldConfig(this);
+ public ShieldPluginManager pm = new ShieldPluginManager(this);
+ public FlagManager fm = new FlagManager(this);
+ public RegionManager rm = new RegionManager(this);
+
+ public void onEnable(){
+ pdfile = this.getDescription();
+
+ loadPlugins();
+ registerAPI();
+
+ config.loadConfig();
+
+ //flagPersister.load();
+
+ startMetrics();
+
+ log("Enabled");
+ }
+
+ public void onDisable(){
+ flagPersister.save();
+
+ log("Disabled");
+ }
+
+ public void log(String msg){
+ log.info("[" + pdfile.getName() + "] " + msg);
+ }
+
+ public void logWarning(String msg){
+ log.warning("[" + pdfile.getName() + "] " + msg);
+ }
+
+ public void logSevere(String msg){
+ log.severe("[" + pdfile.getName() + "] " + msg);
+ }
+
+ private void registerAPI(){
+ ShieldAPI api = new ShieldAPIManager(this);
+ Bukkit.getServicesManager().register(ShieldAPI.class, api, this, ServicePriority.Normal);
+ }
+
+ /**
+ * Gets the Shield API Interface
+ * @return ShieldAPI
+ */
+ public ShieldAPI getAPI(){
+ RegisteredServiceProvider<ShieldAPI> provider = getServer().getServicesManager().getRegistration(com.malikk.shield.ShieldAPI.class);
+ ShieldAPI api = provider.getProvider();
+ return api;
+ }
+
+ private void loadPlugins(){
+
+ log("Scanning for supported protection plugins...");
+
+ //Attempt to load PreciousStones
+ if (packageExists("net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones")){
+ preciousStones = new Protect_PreciousStones(this);
+ log(String.format("Detected PreciousStones: %s", preciousStones.isEnabled() ? "Hooked" : "Waiting"));
+ }
+
+ //Attempt to load Regios
+ if (packageExists("couk.Adamki11s.Regios.Main.Regios")){
+ regios = new Protect_Regios(this);
+ log(String.format("Detected Regios: %s", regios.isEnabled() ? "Hooked" : "Waiting"));
+ }
+
+ //Attempt to load Residence
+ if (packageExists("com.bekvon.bukkit.residence.Residence")){
+ residence = new Protect_Residence(this);
+ log(String.format("Detected Residence: %s", residence.isEnabled() ? "Hooked" : "Waiting"));
+ }
+
+ //Attempt to load WorldGuard
+ if (packageExists("com.sk89q.worldguard.bukkit.WorldGuardPlugin")){
+ worldGuard = new Protect_WorldGuard(this);
+ log(String.format("Detected WorldGuard: %s", worldGuard.isEnabled() ? "Hooked" : "Waiting"));
+ }
+
+ if (foundPlugin == false){
+ log("No supported protection plugins found.");
+ }
+ }
+
+ private boolean packageExists(String...packages){
+ try{
+ for (String pkg : packages){
+ Class.forName(pkg);
+ }
+ foundPlugin = true;
+ return true;
+ }catch (Exception e){
+ return false;
+ }
+ }
+
+ public void startMetrics(){
+ try{
+ Metrics metrics = new Metrics(this);
+ metrics.start();
+ }catch(Exception e){
+ //ignore exception
+ }
+ }
+
+}
View
254 Shield/src/com/malikk/shield/ShieldAPI.java
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield;
+
+import java.util.ArrayList;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+
+import com.malikk.shield.exceptions.FlagNotFoundException;
+import com.malikk.shield.exceptions.InvalidFlagException;
+import com.malikk.shield.exceptions.InvalidRegionException;
+import com.malikk.shield.exceptions.RegionNotFoundException;
+import com.malikk.shield.flags.Flag;
+import com.malikk.shield.regions.ShieldRegion;
+
+/**
+ * This is the interface for the main Shield API. It can be used to get all of Shield's Methods, aside from the methods within the {@link Flag} and {@link ShieldRegion} objects.
+ *
+ */
+public interface ShieldAPI {
+
+ /*
+ * Plugin Methods
+ */
+
+ /**
+ * Gets the ShieldRegion by the passed in name and plugin.
+ *
+ * @param name
+ * @param pluginName
+ * @return {@link ShieldRegion} - The highest priority ShieldRegion
+ * @throws RegionNotFoundException
+ */
+ public ShieldRegion getShieldRegion(String name, String pluginName) throws RegionNotFoundException;
+
+ /**
+ * Gets the highest priority region
+ *
+ * @return {@link ShieldRegion} - The highest priority ShieldRegion
+ */
+ public ShieldRegion getPriorityRegion();
+
+ /**
+ * Gets the highest priority ShieldRegion by the passed in name
+ *
+ * @param name
+ * @return {@link ShieldRegion} - The highest priority ShieldRegion
+ * @throws RegionNotFoundException
+ */
+ public ShieldRegion getPriorityRegion(String name) throws RegionNotFoundException;
+
+ /**
+ * Gets the region with the highest priority, according to the plugin order in the config file.
+ *
+ * @param regions - ArrayList of regions
+ * @return {@link ShieldRegion} - The highest priority ShieldRegion
+ */
+ public ShieldRegion getPriorityRegion(ArrayList<ShieldRegion> regions);
+
+ /**
+ * Gets the highest priority region at the location of the specific entity.
+ * @param entity
+ * @return {@link ShieldRegion} - The highest priority ShieldRegion
+ */
+ public ShieldRegion getPriorityRegion(Entity entity);
+
+ /**
+ * Gets the highest priority region at the specific location.
+ * @param location
+ * @return {@link ShieldRegion} - The highest priority ShieldRegion
+ */
+ public ShieldRegion getPriorityRegion(Location location);
+
+ /**
+ * Gets all regions from all plugins
+ *
+ * @return ArrayList<{@link ShieldRegion}>
+ */
+ public ArrayList<ShieldRegion> getRegions();
+
+ /**
+ * Gets the regions by the passed in name
+ *
+ * @param name
+ * @return ArrayList<{@link ShieldRegion}>
+ * @throws RegionNotFoundException
+ */
+ public ArrayList<ShieldRegion> getRegions(String name) throws RegionNotFoundException;
+
+ /**
+ * Gets the regions that the Entity is in
+ *
+ * @param entity
+ * @return {@link ShieldRegion}
+ */
+ public ArrayList<ShieldRegion> getRegions(Entity entity);
+
+ /**
+ * Gets the regions that the Location is in
+ *
+ * @param location
+ * @return {@link ShieldRegion}
+ */
+ public ArrayList<ShieldRegion> getRegions(Location location);
+
+ /**
+ * Checks whether or not the entity is in any regions
+ * @param entity
+ * @return Boolean
+ */
+ public boolean isInRegion(Entity entity);
+
+ /**
+ * Checks if the location is in any region
+ * @param location
+ * @return Boolean
+ */
+ public boolean isInRegion(Location location);
+
+ /**
+ * Checks whether or not the player owns the region they are in
+ * @param player
+ * @return true or false
+ */
+ //public boolean isOwner(Player player);
+
+ /**
+ * Checks if the player can build where they are standing
+ * @param player
+ * @return Boolean
+ */
+ public boolean canBuild(Player player);
+
+ /**
+ * Checks if the player can build at the specified location
+ * @param player
+ * @param location
+ * @return Boolean
+ */
+ public boolean canBuild(Player player, Location location);
+
+ /**
+ * Checks if the player can use doors, buttons, levers, etc at their current location
+ * @param player
+ * @return Boolean
+ */
+ public boolean canUse(Player player);
+
+ /**
+ * Checks if the player can use doors, buttons, levers, etc at the specified location
+ * @param player
+ * @param location
+ * @return Boolean
+ */
+ public boolean canUse(Player player, Location location);
+
+ /**
+ * Checks if the player can open chests, furnaces, and dispensers at their current location
+ * @param player
+ * @return Boolean
+ */
+ public boolean canOpen(Player player);
+
+ /**
+ * Checks if the player can open chests, furnaces, and dispensers at the specified location
+ * @param player
+ * @param location
+ * @return Boolean
+ */
+ public boolean canOpen(Player player, Location location);
+
+ /*
+ * Custom Flag Methods
+ */
+
+ /**
+ * Adds a flag to the valid flag list
+ *
+ * @param flag - flag name, String
+ */
+ public void addValidFlag(String flag);
+
+ /**
+ * Checks if a flag is in the valid flag list
+ *
+ * @param flag - flag name, String
+ * @return Boolean
+ */
+ public boolean isValidFlag(String flag);
+
+ /**
+ * Sets a Custom flag
+ *
+ * @param flag - flag name, String
+ * @param region - {@link ShieldRegion}
+ * @param players - ArrayList<{@linkplain Player}> that the value is applied to (can be null)
+ * @param value - Boolean value that is applied
+ */
+ public void setFlag(String flag, ShieldRegion region, ArrayList<Player> players, boolean value);
+
+ /**
+ * Checks the value of a flag for a specific Player.
+ * <p>
+ * If the flag's Player list contains the player passed in, then this will return the flag's value. If not, it will return the opposite of the flags value.
+ * @param player - player
+ * @param flag - flag name, String
+ * @param region - {@link ShieldRegion}
+ * @return Boolean
+ * @throws FlagNotFoundException
+ * @throws InvalidRegionException
+ * @throws InvalidFlagException
+ */
+ public boolean getFlagValue(Player player, String flag, ShieldRegion region) throws FlagNotFoundException, InvalidFlagException, InvalidRegionException;
+
+ /**
+ * Checks the value of a flag for a specific Player.
+ * <p>
+ * If the flag's Player list contains the player passed in, then this will return the flag's value. If not, it will return the opposite of the flags value.
+ * @param player - player
+ * @param flag - {@link Flag} object
+ * @return Boolean
+ */
+ public boolean getFlagValue(Player player, Flag flag);
+
+ /**
+ * Gets the flag object for the name and region
+ * @param flag - flag name, String
+ * @param region - {@link ShieldRegion}
+ * @return {@link Flag}
+ * @throws FlagNotFoundException
+ * @throws InvalidRegionException
+ * @throws InvalidFlagException
+ */
+ public Flag getFlag(String flag, ShieldRegion region) throws FlagNotFoundException, InvalidFlagException, InvalidRegionException;
+}
View
171 Shield/src/com/malikk/shield/ShieldAPIManager.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield;
+
+import java.util.ArrayList;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+
+import com.malikk.shield.exceptions.FlagNotFoundException;
+import com.malikk.shield.exceptions.InvalidFlagException;
+import com.malikk.shield.exceptions.InvalidRegionException;
+import com.malikk.shield.exceptions.RegionNotFoundException;
+import com.malikk.shield.flags.Flag;
+import com.malikk.shield.regions.ShieldRegion;
+
+public class ShieldAPIManager implements ShieldAPI{
+
+ Shield plugin;
+
+ public ShieldAPIManager(Shield instance){
+ plugin = instance;
+ }
+
+ /*
+ * Plugin Methods
+ */
+
+ @Override
+ public ShieldRegion getShieldRegion(String name, String pluginName) throws RegionNotFoundException {
+ return plugin.rm.getShieldRegion(name, pluginName);
+ }
+
+ @Override
+ public ShieldRegion getPriorityRegion() {
+ return plugin.config.getHighestPriority(getRegions());
+ }
+
+ @Override
+ public ShieldRegion getPriorityRegion(String name) throws RegionNotFoundException {
+ return plugin.config.getHighestPriority(plugin.rm.getShieldRegions(name));
+ }
+
+ @Override
+ public ShieldRegion getPriorityRegion(ArrayList<ShieldRegion> regions){
+ return plugin.config.getHighestPriority(regions);
+ }
+
+ @Override
+ public ShieldRegion getPriorityRegion(Entity entity){
+ return plugin.config.getHighestPriority(getRegions(entity));
+ }
+
+ @Override
+ public ShieldRegion getPriorityRegion(Location loc){
+ return plugin.config.getHighestPriority(getRegions(loc));
+ }
+
+ @Override
+ public ArrayList<ShieldRegion> getRegions(){
+ return plugin.pm.getRegions();
+ }
+
+ @Override
+ public ArrayList<ShieldRegion> getRegions(String name) throws RegionNotFoundException {
+ return plugin.rm.getShieldRegions(name);
+ }
+
+ @Override
+ public ArrayList<ShieldRegion> getRegions(Entity entity) {
+ return plugin.pm.getRegions(entity);
+ }
+
+ @Override
+ public ArrayList<ShieldRegion> getRegions(Location loc) {
+ return plugin.pm.getRegions(loc);
+ }
+
+ @Override
+ public boolean isInRegion(Entity entity) {
+ return plugin.pm.isInRegion(entity);
+ }
+
+ @Override
+ public boolean isInRegion(Location loc) {
+ return plugin.pm.isInRegion(loc);
+ }
+
+ @Override
+ public boolean canBuild(Player player) {
+ return plugin.pm.canBuild(player);
+ }
+
+ @Override
+ public boolean canBuild(Player player, Location loc) {
+ return plugin.pm.canBuild(player, loc);
+ }
+
+ @Override
+ public boolean canUse(Player player) {
+ return plugin.pm.canUse(player);
+ }
+
+ @Override
+ public boolean canUse(Player player, Location loc) {
+ return plugin.pm.canUse(player, loc);
+ }
+
+ @Override
+ public boolean canOpen(Player player) {
+ return plugin.pm.canOpen(player);
+ }
+
+ @Override
+ public boolean canOpen(Player player, Location loc) {
+ return plugin.pm.canOpen(player, loc);
+ }
+
+ /*
+ * Flag Methods
+ */
+
+ @Override
+ public void addValidFlag(String flag){
+ plugin.fm.addValidFlag(flag);
+ }
+
+ @Override
+ public boolean isValidFlag(String flag){
+ return plugin.fm.isValidFlag(flag);
+ }
+
+ @Override
+ public void setFlag(String flag, ShieldRegion region, ArrayList<Player> players, boolean value) {
+ plugin.fm.createFlag(flag, region, players, value);
+ }
+
+ @Override
+ public boolean getFlagValue(Player player, String flag, ShieldRegion region) throws FlagNotFoundException, InvalidFlagException, InvalidRegionException {
+ return plugin.fm.getFlagAndValue(player, flag, region);
+ }
+
+ @Override
+ public boolean getFlagValue(Player player, Flag flag){
+ return plugin.fm.getValue(player, flag);
+ }
+
+ @Override
+ public Flag getFlag(String flag, ShieldRegion region) throws FlagNotFoundException, InvalidFlagException, InvalidRegionException {
+ return plugin.fm.getFlag(flag, region);
+ }
+
+}
View
105 Shield/src/com/malikk/shield/ShieldConfig.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield;
+
+import org.bukkit.configuration.file.FileConfiguration;
+
+import com.malikk.shield.regions.ShieldRegion;
+
+
+import java.util.ArrayList;
+
+public class ShieldConfig {
+
+ Shield plugin;
+ private FileConfiguration config;
+
+ public ShieldConfig(Shield instance){
+ plugin = instance;
+ }
+
+ public void loadConfig(){
+ config = plugin.getConfig();
+
+ config.options().header("\n Shield v" + plugin.pdfile.getVersion() + "\n By Malikk \n ");
+
+ config.addDefault("Priority.1", "WorldGuard");
+ config.addDefault("Priority.2", "Residence");
+ config.addDefault("Priority.3", "Regios");
+ config.addDefault("Priority.4", "PreciousStones");
+
+ config.options().copyDefaults(true);
+ plugin.saveConfig();
+ }
+
+ public ShieldRegion getHighestPriority(ArrayList<ShieldRegion> regions){
+ int counter = 1;
+
+ plugin.log("Amount of regions passed in: " + regions.size());
+ if (regions.size() == 0){
+ return null;
+ }else if (regions.size() == 1){
+ return regions.get(0);
+ }
+
+ while (config.get("Priority." + counter) != null){
+
+ plugin.log("Priority " + counter + "-----------");
+
+ for (ShieldRegion region: regions){
+
+ plugin.log("Region name: " + region.getName());
+
+ String name = region.getPluginName();
+
+ if (name.equalsIgnoreCase(config.getString("Priority." + counter))){
+
+ plugin.log("Is priority");
+
+ if (name.equalsIgnoreCase("WorldGuard")){
+
+ plugin.log("Priority is WorldGuard");
+
+ ArrayList<ShieldRegion> worldGuardRegions = new ArrayList<ShieldRegion>();
+
+ for (ShieldRegion region2: regions){
+
+ if (region2.getPluginName().equalsIgnoreCase("WorldGuard")){
+ worldGuardRegions.add(region2);
+ }
+ }
+
+ if (worldGuardRegions.size() == 1){
+ return region;
+ }
+
+ return plugin.worldGuard.getHighestPriority(worldGuardRegions);
+ }else{
+ return region;
+ }
+ }
+ }
+
+ counter++;
+
+ }
+ return null;
+ }
+}
View
384 Shield/src/com/malikk/shield/ShieldPluginManager.java
@@ -0,0 +1,384 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+
+import com.malikk.shield.plugins.Protect;
+import com.malikk.shield.regions.ShieldRegion;
+
+public class ShieldPluginManager implements Protect{
+
+ Shield plugin;
+ static ArrayList<String> plugins = new ArrayList<String>();
+
+ public ShieldPluginManager(Shield instance){
+ plugin = instance;
+ }
+
+ /**
+ * Checks whether the ShieldRegion matches up to an actual region
+ *
+ * @param region
+ * @return boolean
+ */
+ public boolean isValidRegion(ShieldRegion region){
+ for (ShieldRegion region2: getRegions()){
+ if (plugin.rm.regionsAreEqual(region, region2)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public ArrayList<ShieldRegion> getRegions(){
+ Object[] args = {};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<ShieldRegion> outcomes = (ArrayList<ShieldRegion>) getOutcomes("getRegions", "ArrayList<Region>", args);
+
+ return outcomes;
+ }
+
+ @Override
+ public ArrayList<ShieldRegion> getRegions(Entity entity){
+ Object[] args = {entity};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<ShieldRegion> outcomes = (ArrayList<ShieldRegion>) getOutcomes("getRegions", "ArrayList<Region>", args);
+
+ return outcomes;
+ }
+
+ @Override
+ public ArrayList<ShieldRegion> getRegions(Location loc){
+ Object[] args = {loc};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<ShieldRegion> outcomes = (ArrayList<ShieldRegion>) getOutcomes("getRegions", "ArrayList<Region>", args);
+
+ return outcomes;
+ }
+
+ /**
+ * Returns true if ANY Protect classes return true
+ */
+ @Override
+ public boolean isInRegion(Entity entity) {
+ Object[] args = {entity};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("isInRegion", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == true){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if ANY Protect classes return true
+ */
+ @Override
+ public boolean isInRegion(Location loc) {
+ Object[] args = {loc};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("isInRegion", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == true){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Only returns true if EVERY Protect class returns true
+ */
+ @Override
+ public boolean canBuild(Player player) {
+ Object[] args = {player};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("canBuild", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == false){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Only returns true is EVERY Protect class returns true
+ */
+ @Override
+ public boolean canBuild(Player player, Location loc) {
+ Object[] args = {player, loc};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("canBuild", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == false){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Only returns true is EVERY Protect class returns true
+ */
+ @Override
+ public boolean canUse(Player player) {
+ Object[] args = {player};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("canUse", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == false){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Only returns true is EVERY Protect class returns true
+ */
+ @Override
+ public boolean canUse(Player player, Location loc) {
+ Object[] args = {player, loc};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("canUse", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == false){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Only returns true is EVERY Protect class returns true
+ */
+ @Override
+ public boolean canOpen(Player player) {
+ Object[] args = {player};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("canOpen", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == false){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Only returns true is EVERY Protect class returns true
+ */
+ @Override
+ public boolean canOpen(Player player, Location loc) {
+ Object[] args = {player, loc};
+
+ @SuppressWarnings("unchecked")
+ ArrayList<Boolean> outcomes = (ArrayList<Boolean>) getOutcomes("canOpen", "boolean", args);
+
+ for (boolean outcome: outcomes){
+ if (outcome == false){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public void addClassToInstantiatedPluginClassesArrayList(String className){
+ plugins.add("Protect_" + className);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ArrayList<?> getOutcomes(String methodName, String outcomeType, Object[] args){
+ ArrayList<String> temp = (ArrayList<String>) plugins.clone();
+ ArrayList<Boolean> booleanOutcomes = new ArrayList<Boolean>();
+ ArrayList<ShieldRegion> regionOutcomes = new ArrayList<ShieldRegion>();
+
+ //plugin.log("------------" + methodName + "------------");
+
+ for (String className: temp){
+
+ //plugin.log(className);
+
+ Class<?> protect = null;
+ try {
+ protect = Class.forName("us.twoguys.shield.plugins." + className, true, this.getClass().getClassLoader());
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ Object obj = null;
+ try {
+ obj = ((Class<?>)protect).getConstructor(Class.forName("us.twoguys.shield.Shield")).newInstance(plugin);
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+
+ Method[] methods = protect.getDeclaredMethods();
+
+ boolean assigned = false;
+
+ for (Method method: methods){
+
+ if (assigned == true){break;}
+
+ Class<?>[] methodArgsTypes = method.getParameterTypes();
+ Class<?>[] argsTypes = new Class<?>[args.length];
+
+ int counter = 0;
+
+ for (Object arg: args){
+ if (arg instanceof Player){
+ argsTypes[counter] = Player.class;
+ counter++;
+ }else if (arg instanceof Entity){
+ argsTypes[counter] = Entity.class;
+ counter++;
+ }else if (arg instanceof Location){
+ argsTypes[counter] = Location.class;
+ counter++;
+ }
+ }
+
+ if (method.getName().equalsIgnoreCase(methodName) && methodArgsTypes.length == argsTypes.length){
+
+ if (outcomeType.equalsIgnoreCase("boolean")){
+ boolean outcome = false;
+
+ try {
+ if (methodArgsTypes.length == 0){
+ outcome = (Boolean) method.invoke(obj);
+ assigned = true;
+ }else if (methodArgsTypes.length == 1){
+ if (equalsOrExtends(argsTypes[0], methodArgsTypes[0])){
+ outcome = (Boolean) method.invoke(obj, args[0]);
+ assigned = true;
+ }
+ }else if (methodArgsTypes.length == 2){
+ if (equalsOrExtends(argsTypes[0], methodArgsTypes[0])){
+ outcome = (Boolean) method.invoke(obj, args[0], args[1]);
+ assigned = true;
+ }else if (equalsOrExtends(argsTypes[0], methodArgsTypes[1])){
+ outcome = (Boolean) method.invoke(obj, args[1], args[0]);
+ assigned = true;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ if (assigned == true){
+ //plugin.log(protect.getSimpleName() + ": " + outcome);
+ booleanOutcomes.add(outcome);
+ }
+
+ }else if (outcomeType.equalsIgnoreCase("ArrayList<Region>")){
+ ArrayList<ShieldRegion> outcome = new ArrayList<ShieldRegion>();
+
+ try {
+ if (methodArgsTypes.length == 0){
+ outcome = (ArrayList<ShieldRegion>) method.invoke(obj);
+ assigned = true;
+ }else if (methodArgsTypes.length == 1){
+ if (equalsOrExtends(argsTypes[0], methodArgsTypes[0])){
+ outcome = (ArrayList<ShieldRegion>) method.invoke(obj, args[0]);
+ assigned = true;
+ }
+ }else if (methodArgsTypes.length == 2){
+ if (equalsOrExtends(argsTypes[0], methodArgsTypes[0])){
+ outcome = (ArrayList<ShieldRegion>) method.invoke(obj, args[0], args[1]);
+ assigned = true;
+ }else if (equalsOrExtends(argsTypes[0], methodArgsTypes[1])){
+ outcome = (ArrayList<ShieldRegion>) method.invoke(obj, args[1], args[0]);
+ assigned = true;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ if (assigned == true){
+ for (ShieldRegion s: outcome){
+ //plugin.log(protect.getSimpleName() + ": " + s.getName());
+ regionOutcomes.add(s);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (outcomeType.equalsIgnoreCase("boolean")){
+ return booleanOutcomes;
+ }else if (outcomeType.equalsIgnoreCase("ArrayList<Region>")){
+ return regionOutcomes;
+ }else{
+ return booleanOutcomes;
+ }
+ }
+
+ public boolean equalsOrExtends(Class<?> c1, Class<?> c2){
+ if (c1 == c2){
+ return true;
+ }else if (c2.isAssignableFrom(c1)){
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ // Dont use
+ return false;
+ }
+
+ @Override
+ public String getPluginName() {
+ // Dont use
+ return null;
+ }
+
+}
View
35 Shield/src/com/malikk/shield/exceptions/FlagNotFoundException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.exceptions;
+
+/**
+ * This exception is thrown only when both the flag and region are valid, but the flag is not set for the region.
+ * <p>
+ * In the catch block, you should set the default action to take when this occurs.
+ * @author Malikk
+ */
+public class FlagNotFoundException extends Exception{
+
+ private static final long serialVersionUID = -563104023059278705L;
+
+ public FlagNotFoundException(){
+ super();
+ }
+}
View
35 Shield/src/com/malikk/shield/exceptions/InvalidFlagException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.exceptions;
+
+/**
+ * This exception is thrown when the flag name being checked is not valid.
+ * <p>
+ * In the catch block, you should set the default action to take when this occurs.
+ * @author Malikk
+ */
+public class InvalidFlagException extends Exception{
+
+ private static final long serialVersionUID = 6511988686703659482L;
+
+ public InvalidFlagException(){
+ super();
+ }
+}
View
36 Shield/src/com/malikk/shield/exceptions/InvalidRegionException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.exceptions;
+
+/**
+ * This exception is thrown when the ShieldRegion object passed in cannot find a region by that name and plugin.
+ * <p>
+ * In the catch block, you should set the default action to take when this occurs.
+ *
+ * @author Malikk
+ */
+public class InvalidRegionException extends Exception{
+
+ private static final long serialVersionUID = 1755159885247872128L;
+
+ public InvalidRegionException(){
+ super();
+ }
+}
View
36 Shield/src/com/malikk/shield/exceptions/RegionNotFoundException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.exceptions;
+
+/**
+ * This exception is thrown when a valid ShieldRegion could not be found for the desired name and/or plugin.
+ * <p>
+ * In the catch block, you should set the default action to take when this occurs.
+ * @author Malikk
+ *
+ */
+public class RegionNotFoundException extends Exception{
+
+ private static final long serialVersionUID = -5506011525478825730L;
+
+ public RegionNotFoundException(){
+ super();
+ }
+}
View
128 Shield/src/com/malikk/shield/flags/Flag.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.flags;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import org.bukkit.entity.Player;
+
+import com.malikk.shield.regions.ShieldRegion;
+
+/**
+ * A flag object allows for lists of players to be assigned boolean values in certain regions.
+ * @author Malikk
+ * @see {@link #getName()}
+ * @see {@link #getRegion()}
+ * @see {@link #getPlayers()}
+ * @see {@link #getValue()}
+ * @see {@link #setPlayers(ArrayList)}
+ * @see {@link #setValue(boolean)}
+ * @see {@link #addPlayer(Player)}
+ * @see {@link #removePlayer(Player)}
+ */
+public class Flag implements Serializable{
+
+ private static final long serialVersionUID = -2914461212107421563L;
+
+ private String name;
+ private ShieldRegion region;
+ private ArrayList<Player> players;
+ private boolean value;
+
+ public Flag(String flag, ShieldRegion region, ArrayList<Player> players, boolean value){
+ this.name = flag;
+ this.region = region;
+ this.players = players;
+ this.value = value;
+ }
+
+ /**
+ * Gets the name of the flag.
+ *
+ * @return String - name
+ */
+ public String getName(){
+ return name;
+ }
+
+ /**
+ * Gets the ShieldRegion the flag is set at.
+ *
+ * @return {@link ShieldRegion} - region that the flag is set on
+ */
+ public ShieldRegion getRegion(){
+ return region;
+ }
+
+ /**
+ * Gets all the Players that the flag is assigned to
+ *
+ * @param players - an ArrayList<{@linkplain Player}>
+ */
+ public ArrayList<Player> getPlayers(){
+ return players;
+ }
+
+ /**
+ * Gets the value that the flag will return for players in its ArrayList. For players not in the ArrayList, the opposite of this value will be returned.
+ *
+ * @return Boolean value assigned to the flag
+ */
+ public boolean getValue(){
+ return value;
+ }
+
+ /**
+ * Sets the ArrayList<Player> for this flag to the ArrayList passed in. (Will completely overwrite the previous list)
+ *
+ * @param players - an ArrayList<{@linkplain Player}>
+ */
+ public void setPlayers(ArrayList<Player> players){
+ this.players = players;
+ }
+
+ /**
+ * Sets the value of the flag.
+ *
+ * @param value - Boolean value
+ */
+ public void setValue(boolean value){
+ this.value = value;
+ }
+
+ /**
+ * Adds a player to the flag's current ArrayList.
+ *
+ * @param player
+ */
+ public void addPlayer(Player player){
+ this.players.add(player);
+ }
+
+ /**
+ * Removes a player from the flag's current ArrayList.
+ *
+ * @param player
+ */
+ public void removePlayer(Player player){
+ this.players.remove(player);
+ }
+}
View
105 Shield/src/com/malikk/shield/flags/FlagManager.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.flags;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+import org.bukkit.entity.Player;
+
+import com.malikk.shield.Shield;
+import com.malikk.shield.exceptions.FlagNotFoundException;
+import com.malikk.shield.exceptions.InvalidFlagException;
+import com.malikk.shield.exceptions.InvalidRegionException;
+import com.malikk.shield.regions.ShieldRegion;
+
+public class FlagManager {
+
+ Shield plugin;
+
+ HashSet<Flag> flags = new HashSet<Flag>();
+ HashSet<String> validFlags = new HashSet<String>();
+
+ public FlagManager(Shield instance){
+ plugin = instance;
+ }
+
+ public void addValidFlag(String flag){
+ if (!validFlags.contains(flag)){
+ validFlags.add(flag);
+ }
+ }
+
+ public boolean isValidFlag(String flag){
+ return (validFlags.contains(flag) ? true : false);
+ }
+
+ public void createFlag(String flag, ShieldRegion region, ArrayList<Player> players, boolean value){
+ Flag f = new Flag(flag, region, players, value);
+
+ for (Flag f1: flags){
+ if (f1.getName().equalsIgnoreCase(flag) && plugin.rm.regionsAreEqual(region, f1.getRegion())){
+ flags.remove(f1);
+ }
+ }
+
+ flags.add(f);
+ }
+
+ public boolean getFlagAndValue(Player player, String flag, ShieldRegion region) throws FlagNotFoundException, InvalidFlagException, InvalidRegionException{
+
+ Flag f = getFlag(flag, region);
+
+ return getValue(player, f);
+ }
+
+ public boolean getValue(Player player, Flag f){
+ boolean fValue = f.getValue();
+
+ if (f.getPlayers().contains(player)){
+ return fValue;
+ }else{
+ return !fValue;
+ }
+ }
+
+ public Flag getFlag(String flag, ShieldRegion region) throws FlagNotFoundException, InvalidFlagException, InvalidRegionException{
+
+ //Check if flag is valid
+ if (!isValidFlag(flag)){
+ throw new InvalidFlagException();
+ }
+
+ //Check if Region is valid
+ if (!plugin.pm.isValidRegion(region)){
+ throw new InvalidRegionException();
+ }
+
+ for (Flag f: flags){
+ if (f.getName().equalsIgnoreCase(flag) && f.getRegion() == region){
+ return f;
+ }
+ }
+
+ throw new FlagNotFoundException();
+ }
+
+
+}
View
120 Shield/src/com/malikk/shield/flags/FlagPersister.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.flags;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import com.malikk.shield.Shield;
+
+public class FlagPersister {
+
+ Shield plugin;
+
+ public FlagPersister(Shield instance){
+ plugin = instance;
+ }
+
+ public void save(){
+ //create a new File
+ File saveFile = new File(plugin.getDataFolder() + File.separator + "Flags.dat");
+
+ if (!saveFile.exists()){
+ try {
+ plugin.getDataFolder().mkdir();
+ saveFile.createNewFile();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ try{
+ FileOutputStream fos = new FileOutputStream(plugin.getDataFolder() + File.separator + "Flags.dat");
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+
+ //Write file here
+ try{
+ oos.writeInt(plugin.fm.flags.size());
+ }catch(Exception e){
+ plugin.log("No Flags to save!");
+ }
+
+ for (Flag f: plugin.fm.flags){
+ oos.writeObject(f);
+ }
+
+ oos.close();
+
+ plugin.log("Flags Saved");
+
+ }catch(Exception e){
+ e.printStackTrace();
+ plugin.log("Failed to save Flags");
+ }
+
+
+ }
+
+ public void load(){
+
+ File saveFile = new File(plugin.getDataFolder() + File.separator + "Flags.dat");
+
+ if(saveFile.exists()){
+ FileInputStream fis = null;
+ ObjectInputStream ois = null;
+
+ try{
+ fis = new FileInputStream(saveFile);
+ ois = new ObjectInputStream(fis);
+
+ Integer recordCount = ois.readInt();
+ int x = 0;
+
+ for(int i = 0; i < recordCount; i ++){
+ Flag f = (Flag) ois.readObject();
+ plugin.fm.flags.add(f);
+
+ x = i;
+ }
+
+ plugin.log(x + " Flags loaded");
+
+ }catch(FileNotFoundException e){
+ plugin.log("Could not locate data file... ");
+ e.printStackTrace();
+ }catch(IOException e){
+ plugin.log("IOException while trying to read data file");
+ }catch(ClassNotFoundException e){
+ plugin.log("Could not find class to load");
+ }finally{
+ try{
+ ois.close();
+ }catch(IOException e){
+ plugin.log("Error while trying to close input stream");
+ }
+ }
+ }
+ }
+}
View
617 Shield/src/com/malikk/shield/metrics/Metrics.java
@@ -0,0 +1,617 @@
+package com.malikk.shield.metrics;
+
+/*
+* Copyright 2011 Tyler Blair. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are
+* permitted provided that the following conditions are met:
+*
+* 1. Redistributions of source code must retain the above copyright notice, this list of
+* conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright notice, this list
+* of conditions and the following disclaimer in the documentation and/or other materials
+* provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* The views and conclusions contained in the software and documentation are those of the
+* authors and contributors and should not be interpreted as representing official policies,
+* either expressed or implied, of anybody else.
+*/
+
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginDescriptionFile;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.UUID;
+import java.util.logging.Level;
+
+/**
+* <p>
+* The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.
+* </p>
+* <p>
+* Public methods provided by this class:
+* </p>
+* <code>
+* Graph createGraph(String name); <br/>
+* void addCustomData(Metrics.Plotter plotter); <br/>
+* void start(); <br/>
+* </code>
+*/
+public class Metrics {
+
+ /**
+* The current revision number
+*/
+ private final static int REVISION = 5;
+
+ /**
+* The base url of the metrics domain
+*/
+ private static final String BASE_URL = "http://mcstats.org";
+
+ /**
+* The url used to report a server's status
+*/
+ private static final String REPORT_URL = "/report/%s";
+
+ /**
+* The file where guid and opt out is stored in
+*/
+ private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml";
+
+ /**
+* The separator to use for custom data. This MUST NOT change unless you are hosting your own
+* version of metrics and want to change it.
+*/
+ private static final String CUSTOM_DATA_SEPARATOR = "~~";
+
+ /**
+* Interval of time to ping (in minutes)
+*/
+ private static final int PING_INTERVAL = 10;
+
+ /**
+* The plugin this metrics submits for
+*/
+ private final Plugin plugin;
+
+ /**
+* All of the custom graphs to submit to metrics
+*/
+ private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
+
+ /**
+* The default graph, used for addCustomData when you don't want a specific graph
+*/
+ private final Graph defaultGraph = new Graph("Default");
+
+ /**
+* The plugin configuration file
+*/
+ private final YamlConfiguration configuration;
+
+ /**
+* The plugin configuration file
+*/
+ private final File configurationFile;
+
+ /**
+* Unique server id
+*/
+ private final String guid;
+
+ /**
+* Lock for synchronization
+*/
+ private final Object optOutLock = new Object();
+
+ /**
+* Id of the scheduled task
+*/
+ private volatile int taskId = -1;
+
+ public Metrics(final Plugin plugin) throws IOException {
+ if (plugin == null) {
+ throw new IllegalArgumentException("Plugin cannot be null");
+ }
+
+ this.plugin = plugin;
+
+ // load the config
+ configurationFile = new File(CONFIG_FILE);
+ configuration = YamlConfiguration.loadConfiguration(configurationFile);
+
+ // add some defaults
+ configuration.addDefault("opt-out", false);
+ configuration.addDefault("guid", UUID.randomUUID().toString());
+
+ // Do we need to create the file?
+ if (configuration.get("guid", null) == null) {
+ configuration.options().header("http://mcstats.org").copyDefaults(true);
+ configuration.save(configurationFile);
+ }
+
+ // Load the guid then
+ guid = configuration.getString("guid");
+ }
+
+ /**
+* Construct and create a Graph that can be used to separate specific plotters to their own graphs
+* on the metrics website. Plotters can be added to the graph object returned.
+*
+* @param name
+* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
+*/
+ public Graph createGraph(final String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Graph name cannot be null");
+ }
+
+ // Construct the graph object
+ final Graph graph = new Graph(name);
+
+ // Now we can add our graph
+ graphs.add(graph);
+
+ // and return back
+ return graph;
+ }
+
+ /**
+* Add a Graph object to Metrics that represents data for the plugin that should be sent to the backend
+*
+* @param graph
+*/
+ public void addGraph(final Graph graph) {
+ if (graph == null) {
+ throw new IllegalArgumentException("Graph cannot be null");
+ }
+
+ graphs.add(graph);
+ }
+
+ /**
+* Adds a custom data plotter to the default graph
+*
+* @param plotter
+*/
+ public void addCustomData(final Plotter plotter) {
+ if (plotter == null) {
+ throw new IllegalArgumentException("Plotter cannot be null");
+ }
+
+ // Add the plotter to the graph o/
+ defaultGraph.addPlotter(plotter);
+
+ // Ensure the default graph is included in the submitted graphs
+ graphs.add(defaultGraph);
+ }
+
+ /**
+* Start measuring statistics. This will immediately create an async repeating task as the plugin and send
+* the initial data to the metrics backend, and then after that it will post in increments of
+* PING_INTERVAL * 1200 ticks.
+*
+* @return True if statistics measuring is running, otherwise false.
+*/
+ public boolean start() {
+ synchronized (optOutLock) {
+ // Did we opt out?
+ if (isOptOut()) {
+ return false;
+ }
+
+ // Is metrics already running?
+ if (taskId >= 0) {
+ return true;
+ }
+
+ // Begin hitting the server with glorious data
+ taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
+
+ private boolean firstPost = true;
+
+ public void run() {
+ try {
+ // This has to be synchronized or it can collide with the disable method.
+ synchronized (optOutLock) {
+ // Disable Task, if it is running and the server owner decided to opt-out
+ if (isOptOut() && taskId > 0) {
+ plugin.getServer().getScheduler().cancelTask(taskId);
+ taskId = -1;
+ // Tell all plotters to stop gathering information.
+ for (Graph graph : graphs){
+ graph.onOptOut();
+ }
+ }
+ }
+
+ // We use the inverse of firstPost because if it is the first time we are posting,
+ // it is not a interval ping, so it evaluates to FALSE
+ // Each time thereafter it will evaluate to TRUE, i.e PING!
+ postPlugin(!firstPost);
+
+ // After the first post we set firstPost to false
+ // Each post thereafter will be a ping
+ firstPost = false;
+ } catch (IOException e) {
+ Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
+ }
+ }
+ }, 0, PING_INTERVAL * 1200);
+
+ return true;
+ }
+ }
+
+ /**
+* Has the server owner denied plugin metrics?
+*
+* @return
+*/
+ public boolean isOptOut() {
+ synchronized(optOutLock) {
+ try {
+ // Reload the metrics file
+ configuration.load(CONFIG_FILE);
+ } catch (IOException ex) {
+ Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
+ return true;
+ } catch (InvalidConfigurationException ex) {
+ Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
+ return true;
+ }
+ return configuration.getBoolean("opt-out", false);
+ }
+ }
+
+ /**
+* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
+*
+* @throws IOException
+*/
+ public void enable() throws IOException {
+ // This has to be synchronized or it can collide with the check in the task.
+ synchronized (optOutLock) {
+ // Check if the server owner has already set opt-out, if not, set it.
+ if (isOptOut()) {
+ configuration.set("opt-out", false);
+ configuration.save(configurationFile);
+ }
+
+ // Enable Task, if it is not running
+ if (taskId < 0) {
+ start();
+ }
+ }
+ }
+
+ /**
+* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
+*
+* @throws IOException
+*/
+ public void disable() throws IOException {
+ // This has to be synchronized or it can collide with the check in the task.
+ synchronized (optOutLock) {
+ // Check if the server owner has already set opt-out, if not, set it.
+ if (!isOptOut()) {
+ configuration.set("opt-out", true);
+ configuration.save(configurationFile);
+ }
+
+ // Disable Task, if it is running
+ if (taskId > 0) {
+ this.plugin.getServer().getScheduler().cancelTask(taskId);
+ taskId = -1;
+ }
+ }
+ }
+
+ /**
+* Generic method that posts a plugin to the metrics website
+*/
+ private void postPlugin(final boolean isPing) throws IOException {
+ // The plugin's description file containg all of the plugin data such as name, version, author, etc
+ final PluginDescriptionFile description = plugin.getDescription();
+
+ // Construct the post data
+ final StringBuilder data = new StringBuilder();
+ data.append(encode("guid")).append('=').append(encode(guid));
+ encodeDataPair(data, "version", description.getVersion());
+ encodeDataPair(data, "server", Bukkit.getVersion());
+ encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length));
+ encodeDataPair(data, "revision", String.valueOf(REVISION));
+
+ // If we're pinging, append it
+ if (isPing) {
+ encodeDataPair(data, "ping", "true");
+ }
+
+ // Acquire a lock on the graphs, which lets us make the assumption we also lock everything
+ // inside of the graph (e.g plotters)
+ synchronized (graphs) {
+ final Iterator<Graph> iter = graphs.iterator();
+
+ while (iter.hasNext()) {
+ final Graph graph = iter.next();
+
+ for (Plotter plotter : graph.getPlotters()) {
+ // The key name to send to the metrics server
+ // The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
+ // Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
+ final String key = String.format("C%s%s%s%s", CUSTOM_DATA_SEPARATOR, graph.getName(), CUSTOM_DATA_SEPARATOR, plotter.getColumnName());
+
+ // The value to send, which for the foreseeable future is just the string
+ // value of plotter.getValue()
+ final String value = Integer.toString(plotter.getValue());
+
+ // Add it to the http post data :)
+ encodeDataPair(data, key, value);
+ }
+ }
+ }
+
+ // Create the url
+ URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName())));
+
+ // Connect to the website
+ URLConnection connection;
+
+ // Mineshafter creates a socks proxy, so we can safely bypass it
+ // It does not reroute POST requests so we need to go around it
+ if (isMineshafterPresent()) {
+ connection = url.openConnection(Proxy.NO_PROXY);
+ } else {
+ connection = url.openConnection();
+ }
+
+ connection.setDoOutput(true);
+
+ // Write the data
+ final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
+ writer.write(data.toString());
+ writer.flush();
+
+ // Now read the response
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ final String response = reader.readLine();
+
+ // close resources
+ writer.close();
+ reader.close();
+
+ if (response == null || response.startsWith("ERR")) {
+ throw new IOException(response); //Throw the exception
+ } else {
+ // Is this the first update this hour?
+ if (response.contains("OK This is your first update this hour")) {
+ synchronized (graphs) {
+ final Iterator<Graph> iter = graphs.iterator();
+
+ while (iter.hasNext()) {
+ final Graph graph = iter.next();
+
+ for (Plotter plotter : graph.getPlotters()) {
+ plotter.reset();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
+*
+* @return
+*/
+ private boolean isMineshafterPresent() {
+ try {
+ Class.forName("mineshafter.MineServer");
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+* <p>Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first
+* key/value pair MUST be included manually, e.g:</p>
+* <code>
+* StringBuffer data = new StringBuffer();
+* data.append(encode("guid")).append('=').append(encode(guid));
+* encodeDataPair(data, "version", description.getVersion());
+* </code>
+*
+* @param buffer
+* @param key
+* @param value
+* @return
+*/
+ private static void encodeDataPair(final StringBuilder buffer, final String key, final String value) throws UnsupportedEncodingException {
+ buffer.append('&').append(encode(key)).append('=').append(encode(value));
+ }
+
+ /**
+* Encode text as UTF-8
+*
+* @param text
+* @return
+*/
+ private static String encode(final String text) throws UnsupportedEncodingException {
+ return URLEncoder.encode(text, "UTF-8");
+ }
+
+ /**
+* Represents a custom graph on the website
+*/
+ public static class Graph {
+
+ /**
+* The graph's name, alphanumeric and spaces only :)
+* If it does not comply to the above when submitted, it is rejected
+*/
+ private final String name;
+
+ /**
+* The set of plotters that are contained within this graph
+*/
+ private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
+
+ private Graph(final String name) {
+ this.name = name;
+ }
+
+ /**
+* Gets the graph's name
+*
+* @return
+*/
+ public String getName() {
+ return name;
+ }
+
+ /**
+* Add a plotter to the graph, which will be used to plot entries
+*
+* @param plotter
+*/
+ public void addPlotter(final Plotter plotter) {
+ plotters.add(plotter);
+ }
+
+ /**
+* Remove a plotter from the graph
+*
+* @param plotter
+*/
+ public void removePlotter(final Plotter plotter) {
+ plotters.remove(plotter);
+ }
+
+ /**
+* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
+*
+* @return
+*/
+ public Set<Plotter> getPlotters() {
+ return Collections.unmodifiableSet(plotters);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object object) {
+ if (!(object instanceof Graph)) {
+ return false;
+ }
+
+ final Graph graph = (Graph) object;
+ return graph.name.equals(name);
+ }
+
+ /**
+* Called when the server owner decides to opt-out of Metrics while the server is running.
+*/
+ protected void onOptOut(){}
+
+ }
+
+ /**
+* Interface used to collect custom data for a plugin
+*/
+ public static abstract class Plotter {
+
+ /**
+* The plot's name
+*/
+ private final String name;
+
+ /**
+* Construct a plotter with the default plot name
+*/
+ public Plotter() {
+ this("Default");
+ }
+
+ /**
+* Construct a plotter with a specific plot name
+*
+* @param name
+*/
+ public Plotter(final String name) {
+ this.name = name;
+ }
+
+ /**
+* Get the current value for the plotted point
+*
+* @return
+*/
+ public abstract int getValue();
+
+ /**
+* Get the column name for the plotted point
+*
+* @return the plotted point's column name
+*/
+ public String getColumnName() {
+ return name;
+ }
+
+ /**
+* Called after the website graphs have been updated
+*/
+ public void reset() {
+ }
+
+ @Override
+ public int hashCode() {
+ return getColumnName().hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object object) {
+ if (!(object instanceof Plotter)) {
+ return false;
+ }
+
+ final Plotter plotter = (Plotter) object;
+ return plotter.name.equals(name) && plotter.getValue() == getValue();
+ }
+
+ }
+
+}
View
59 Shield/src/com/malikk/shield/plugins/Protect.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.plugins;
+
+import java.util.ArrayList;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+
+import com.malikk.shield.regions.ShieldRegion;
+
+public interface Protect {
+
+ //List of methods that every protect class MUST have. Does NOT extend the actual Api.
+
+ public boolean isEnabled();
+
+ public String getPluginName();
+
+ public ArrayList<ShieldRegion> getRegions();
+
+ public ArrayList<ShieldRegion> getRegions(Entity entity);
+
+ public ArrayList<ShieldRegion> getRegions(Location loc);
+
+ public boolean isInRegion(Entity entity);
+
+ public boolean isInRegion(Location loc);
+
+ public boolean canBuild(Player player);
+
+ public boolean canBuild(Player player, Location loc);
+
+ public boolean canUse(Player player);
+
+ public boolean canUse(Player player, Location loc);
+
+ public boolean canOpen(Player player);
+
+ public boolean canOpen(Player player, Location loc);
+}
View
158 Shield/src/com/malikk/shield/plugins/Protect_PreciousStones.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.plugins;
+
+import java.util.ArrayList;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.server.PluginDisableEvent;
+import org.bukkit.event.server.PluginEnableEvent;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
+
+import com.malikk.shield.*;
+import com.malikk.shield.regions.ShieldRegion;
+
+import net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones;
+
+public class Protect_PreciousStones implements Listener, Protect {
+
+ Shield shield;
+
+ private final String name = "PreciousStones";
+ private final String pack = "net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones";
+ private static int instanceCount = 0;
+ private static PreciousStones protect = null;
+
+ public Protect_PreciousStones(Shield instance){
+ this.shield = instance;
+
+ PluginManager pm = shield.getServer().getPluginManager();
+ pm.registerEvents(this, shield);
+
+ if (instanceCount == 0){
+ //Load plugin if it was loaded before Shield
+ if (protect == null) {
+ Plugin p = shield.getServer().getPluginManager().getPlugin(name);
+
+ if (p != null && p.isEnabled() && p.getClass().getName().equals(pack)) {
+ protect = (PreciousStones) p;
+ //shield.pm.addClassToInstantiatedPluginClassesArrayList(name);
+ }
+ }
+ }
+
+ instanceCount++;
+
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPluginEnable(PluginEnableEvent event) {
+ if (protect == null) {
+ Plugin p = shield.getServer().getPluginManager().getPlugin(name);
+
+ if (p != null && p.isEnabled() && p.getClass().getName().equals(pack)) {
+ protect = (PreciousStones) p;
+ //shield.pm.addClassToInstantiatedPluginClassesArrayList(name);
+ shield.log(String.format("%s hooked.", name));
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPluginDisable(PluginDisableEvent event) {
+ if (protect != null) {
+ if (event.getPlugin().getDescription().getName().equals(name)) {
+ protect = null;
+ shield.log(String.format("%s unhooked.", name));
+ }
+ }
+ }
+
+ public boolean isEnabled(){
+ return (protect == null ? false : true);
+ }
+
+ public String getPluginName(){
+ return name;
+ }
+
+ public ArrayList<ShieldRegion> getRegions() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArrayList<ShieldRegion> getRegions(Entity entity) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ArrayList<ShieldRegion> getRegions(Location loc) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isInRegion(Entity entity) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isInRegion(Location loc) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canBuild(Player player) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canBuild(Player player, Location loc) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canUse(Player player) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canUse(Player player, Location loc) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canOpen(Player player) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean canOpen(Player player, Location loc) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
+
View
175 Shield/src/com/malikk/shield/plugins/Protect_Regios.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2012 Jordan Hobgood
+ *
+ * This file is part of Shield.
+ *
+ * Shield is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Shield is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Shield. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.malikk.shield.plugins;
+
+import java.util.ArrayList;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.server.PluginDisableEvent;
+import org.bukkit.event.server.PluginEnableEvent;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
+
+import com.malikk.shield.*;
+import com.malikk.shield.regions.ShieldRegion;
+
+import couk.Adamki11s.Regios.API.RegiosAPI;
+import couk.Adamki11s.Regios.Main.Regios;
+import couk.Adamki11s.Regios.Regions.Region;
+
+public class Protect_Regios implements Listener, Protect {
+
+ Shield shield;
+
+ private final String name = "Regios";
+ private final String pack = "couk.Adamki11s.Regios.Main.Regios";
+ private static int instanceCount = 0;
+ private static Regios protect = null;
+ private static RegiosAPI api = null;
+
+ public Protect_Regios(Shield instance){
+ this.shield = instance;
+
+ PluginManager pm = shield.getServer().getPluginManager();
+ pm.registerEvents(this, shield);
+
+ if (instanceCount == 0){
+ //Load plugin if it was loaded before Shield
+ if (protect == null) {
+ Plugin p = shield.getServer().getPluginManager().getPlugin(name);
+
+ if (p != null && p.isEnabled() && p.getClass().getName().equals(pack)) {
+ protect = (Regios) p;
+ api = new RegiosAPI();
+ shield.pm.addClassToInstantiatedPluginClassesArrayList(name);
+ }
+ }
+ }
+
+ instanceCount++;
+
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPluginEnable(PluginEnableEvent event) {
+ if (protect == null) {
+ Plugin p = shield.getServer().getPluginManager().getPlugin(name);
+
+ if (p != null && p.isEnabled() && p.getClass().getName().equals(pack)) {
+ protect = (Regios) p;
+ api = new RegiosAPI();
+ shield.pm.addClassToInstantiatedPluginClassesArrayList(name);
+ shield.log(String.format("%s hooked.", name));
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPluginDisable(PluginDisableEvent event) {
+ if (protect != null) {
+ if (event.getPlugin().getDescription().getName().equals(name)) {
+ protect = null;
+ api = null;
+ shield.log(String.format("%s unhooked.", name));
+ }
+ }
+ }
+
+ public boolean isEnabled(){
+ return (protect == null ? false : true);
+ }
+
+ public String getPluginName(){
+ return name;
+ }
+
+ public ArrayList<ShieldRegion> getRegions(){
+ ArrayList<ShieldRegion> regions = new ArrayList<ShieldRegion>();
+
+ if (api.getRegions() != null){
+ for (Region r: api.getRegions()){
+ regions.add(shield.rm.createShieldRegion(r.getName(), name, r.getWorld()));
+ }
+ }
+
+ return regions;
+ }
+
+ public ArrayList<ShieldRegion> getRegions(Entity entity){
+ ArrayList<ShieldRegion> regions = new ArrayList<ShieldRegion>();
+
+ if (api.getRegions(entity.getLocation()) != null){
+ for (Region r: api.getRegions(entity.getLocation())){
+ regions.add(shield.rm.createShieldRegion(r.getName(), name, r.getWorld()));
+ }
+ }
+
+ return regions;
+ }
+
+ public ArrayList<ShieldRegion> getRegions(Location loc){
+ ArrayList<ShieldRegion> regions = new ArrayList<ShieldRegion>();
+
+ if (api.getRegions(loc) != null){
+ for (Region r: api.getRegions(loc)){
+ regions.add(shield.rm.createShieldRegion(r.getName(), name, r.getWorld()));
+ }
+ }