Implemented real API system.

Added in the HookHandler v3
This commit is contained in:
Brianna O'Keefe 2018-08-30 14:47:46 -04:00
parent 7454ac519b
commit 7a97c45fa1
55 changed files with 866 additions and 697 deletions

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/../target/classes" />
<output-test url="file://$MODULE_DIR$/../target/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="spigot-1.13.1" level="project" />
<orderEntry type="library" name="Lib" level="project" />
</component>
</module>

View File

@ -0,0 +1,20 @@
package com.songoda.epicfarming.api;
import com.songoda.epicfarming.api.farming.FarmManager;
import com.songoda.epicfarming.api.farming.Level;
import com.songoda.epicfarming.api.farming.LevelManager;
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
import org.bukkit.inventory.ItemStack;
public interface EpicFarming {
void registerProtectionHook(ProtectionPluginHook hook);
int getLevelFromItem(ItemStack item);
ItemStack makeFarmItem(Level level);
FarmManager getFarmManager();
LevelManager getLevelManager();
}

View File

@ -0,0 +1,46 @@
package com.songoda.epicfarming.api;
/**
* The access point of the EpicFarmingAPI, a class acting as a bridge between API
* and plugin implementation. It is from here where developers should access the
* important and core methods in the API. All static methods in this class will
* call directly upon the implementation at hand (in most cases this will be the
* EpicFarming plugin itself), therefore a call to {@link #getImplementation()} is
* not required and redundant in most situations. Method calls from this class are
* preferred the majority of time, though an instance of {@link EpicFarming} may
* be passed if absolutely necessary.
*
* @see EpicFarming
* @since 3.0.0
*/
public class EpicFarmingAPI {
private static EpicFarming implementation;
/**
* Set the EpicFarming implementation. Once called for the first time, this
* method will throw an exception on any subsequent invocations. The implementation
* may only be set a single time, presumably by the EpicFarming plugin
*
* @param implementation the implementation to set
*/
public static void setImplementation(EpicFarming implementation) {
if (EpicFarmingAPI.implementation != null) {
throw new IllegalArgumentException("Cannot set API implementation twice");
}
EpicFarmingAPI.implementation = implementation;
}
/**
* Get the EpicFarming implementation. This method may be redundant in most
* situations as all methods present in {@link EpicFarming} will be mirrored
* with static modifiers in the {@link EpicFarmingAPI} class
*
* @return the EpicFarming implementation
*/
public static EpicFarming getImplementation() {
return implementation;
}
}

View File

@ -0,0 +1,14 @@
package com.songoda.epicfarming.api.farming;
import org.bukkit.Location;
import org.bukkit.inventory.Inventory;
public interface Farm {
Inventory getInventory();
Location getLocation();
void setLocation(Location location);
Level getLevel();
}

View File

@ -0,0 +1,18 @@
package com.songoda.epicfarming.api.farming;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.Map;
public interface FarmManager {
void addFarm(Location location, Farm farm);
Farm removeFarm(Location location);
Farm getFarm(Location location);
Farm getFarm(Block block);
Map<Location, Farm> getFarms();
}

View File

@ -0,0 +1,21 @@
package com.songoda.epicfarming.api.farming;
import java.util.List;
public interface Level {
List<String> getDescription();
int getLevel();
int getRadius();
boolean isAutoHarvest();
boolean isAutoReplant();
double getSpeedMultiplier();
int getCostExperiance();
int getCostEconomy();
}

View File

@ -0,0 +1,20 @@
package com.songoda.epicfarming.api.farming;
import java.util.Map;
public interface LevelManager {
void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant);
Level getLevel(int level);
Level getLowestLevel();
Level getHighestLevel();
boolean isLevel(int level);
Map<Integer, Level> getLevels();
void clear();
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicfarming.api; package com.songoda.epicfarming.api.farming;
public enum UpgradeType { public enum UpgradeType {
EXPERIENCE, ECONOMY EXPERIENCE, ECONOMY

View File

@ -0,0 +1,39 @@
package com.songoda.epicfarming.api.utils;
import org.bukkit.Location;
/**
* A more specific implementation of {@link ProtectionPluginHook} used internally by
* EpicSpawners to retain more information about default hooks. Often times this
* interface is not recommended over the ProtectionPluginHook interface as its methods
* will not often be used by implementation, though they are available if more information
* is desired. It is, however, recommended to use the former
*
* @author Parker Hawke - 2008Choco
*/
public interface ClaimableProtectionPluginHook extends ProtectionPluginHook {
/**
* Check whether the provided location is in the claim with the given String ID
*
* @param location the location to check
* @param id the ID of the claim to check
*
* @return true if the location is within the claim, false otherwise or if the
* claim ID does not exist
*/
public boolean isInClaim(Location location, String id);
/**
* Get the ID of the claim with the given name. Often times this is unnecessary
* as unique IDs are not provided by a claim implementation, though for plugins
* such as factions, the passed parameter is the name of the faction and the
* returned String is its unique ID
*
* @param name the name of the claim to check
*
* @return the unique String ID. null if no claim exists
*/
public String getClaimID(String name);
}

View File

@ -0,0 +1,48 @@
package com.songoda.epicfarming.api.utils;
import com.songoda.epicfarming.api.EpicFarming;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
/**
* Represents a hook for a protection plugin. This is used by EpicSpawners to determine
* whether a block break should be successful or not according to the current state of
* another plugin. For plugins providing claims with unique String IDs, see the
* {@link ClaimableProtectionPluginHook} for a more detailed implementation. To register
* a protection hook implementation, see
* {@link EpicFarming#registerProtectionHook(ProtectionPluginHook)}
*/
public interface ProtectionPluginHook {
/**
* The plugin to which this plugin hook belongs. Must not be null
*
* @return the hooking plugin
*/
public JavaPlugin getPlugin();
/**
* Check whether the provided player may build at the specified location
*
* @param player the player to check
* @param location the location to check
*
* @return true if player is permitted to build, false otherwise
*/
public boolean canBuild(Player player, Location location);
/**
* Check whether the provided player may build at the specified block
*
* @param player the player to check
* @param block the block to check
*
* @return true if player is permitted to build, false otherwise
*/
public default boolean canBuild(Player player, Block block) {
return block != null && canBuild(player, block.getLocation());
}
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/../target/classes" />
<output-test url="file://$MODULE_DIR$/../target/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="spigot-1.13.1" level="project" />
<orderEntry type="library" name="Lib" level="project" />
<orderEntry type="module" module-name="EpicFarming-API" />
</component>
</module>

View File

@ -1,54 +1,72 @@
package com.songoda.epicfarming; package com.songoda.epicfarming;
import com.google.common.base.Preconditions;
import com.songoda.arconix.api.mcupdate.MCUpdate; import com.songoda.arconix.api.mcupdate.MCUpdate;
import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix; import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.api.farming.Level;
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
import com.songoda.epicfarming.events.BlockListeners; import com.songoda.epicfarming.events.BlockListeners;
import com.songoda.epicfarming.events.EntityListeners; import com.songoda.epicfarming.events.EntityListeners;
import com.songoda.epicfarming.events.InteractListeners; import com.songoda.epicfarming.events.InteractListeners;
import com.songoda.epicfarming.events.InventoryListeners; import com.songoda.epicfarming.events.InventoryListeners;
import com.songoda.epicfarming.farming.Farm; import com.songoda.epicfarming.farming.EFarm;
import com.songoda.epicfarming.farming.FarmManager; import com.songoda.epicfarming.farming.EFarmManager;
import com.songoda.epicfarming.farming.LevelManager; import com.songoda.epicfarming.farming.ELevel;
import com.songoda.epicfarming.farming.ELevelManager;
import com.songoda.epicfarming.handlers.CommandHandler; import com.songoda.epicfarming.handlers.CommandHandler;
import com.songoda.epicfarming.handlers.FarmingHandler; import com.songoda.epicfarming.handlers.FarmingHandler;
import com.songoda.epicfarming.handlers.GrowthHandler; import com.songoda.epicfarming.handlers.GrowthHandler;
import com.songoda.epicfarming.handlers.HookHandler; import com.songoda.epicfarming.hooks.*;
import com.songoda.epicfarming.player.PlayerActionManager; import com.songoda.epicfarming.player.PlayerActionManager;
import com.songoda.epicfarming.player.PlayerData; import com.songoda.epicfarming.player.PlayerData;
import com.songoda.epicfarming.utils.Debugger;
import com.songoda.epicfarming.utils.Methods;
import com.songoda.epicfarming.utils.SettingsManager; import com.songoda.epicfarming.utils.SettingsManager;
import com.songoda.epicfarming.api.EpicFarming;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Supplier;
/** /**
* Created by songoda on 1/23/2018. * Created by songoda on 1/23/2018.
*/ */
public class EpicFarming extends JavaPlugin implements Listener { public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
private static EpicFarming INSTANCE; private static EpicFarmingPlugin INSTANCE;
private List<ProtectionPluginHook> protectionHooks = new ArrayList<>();
private ClaimableProtectionPluginHook factionsHook, townyHook, aSkyblockHook, uSkyblockHook;
public SettingsManager settingsManager; public SettingsManager settingsManager;
public References references; public References references;
public HookHandler hooks; public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml"); private ConfigWrapper hooksFile = new ConfigWrapper(this, "", "hooks.yml");
public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
private Locale locale; private Locale locale;
private FarmingHandler farmingHandler; private FarmingHandler farmingHandler;
private GrowthHandler growthHandler; private GrowthHandler growthHandler;
private FarmManager farmManager; private EFarmManager farmManager;
private LevelManager levelManager; private ELevelManager levelManager;
private PlayerActionManager playerActionManager; private PlayerActionManager playerActionManager;
public static EpicFarming pl() { public static EpicFarmingPlugin pl() {
return INSTANCE; return INSTANCE;
} }
public static EpicFarming getInstance() { public static EpicFarmingPlugin getInstance() {
return INSTANCE; return INSTANCE;
} }
@ -74,7 +92,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
loadLevelManager(); loadLevelManager();
farmManager = new FarmManager(); farmManager = new EFarmManager();
/* /*
* Register Farms into FarmManger from configuration * Register Farms into FarmManger from configuration
@ -87,7 +105,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
List<ItemStack> items = (List<ItemStack>) dataFile.getConfig().getList("Farms." + locationStr + ".Contents"); List<ItemStack> items = (List<ItemStack>) dataFile.getConfig().getList("Farms." + locationStr + ".Contents");
Farm farm = new Farm(location, levelManager.getLevel(level)); EFarm farm = new EFarm(location, levelManager.getLevel(level));
farm.loadInventory(items); farm.loadInventory(items);
farmManager.addFarm(location, farm); farmManager.addFarm(location, farm);
@ -95,8 +113,6 @@ public class EpicFarming extends JavaPlugin implements Listener {
} }
playerActionManager = new PlayerActionManager(); playerActionManager = new PlayerActionManager();
hooks = new HookHandler();
hooks.hook();
farmingHandler = new FarmingHandler(this); farmingHandler = new FarmingHandler(this);
growthHandler = new GrowthHandler(this); growthHandler = new GrowthHandler(this);
@ -104,12 +120,25 @@ public class EpicFarming extends JavaPlugin implements Listener {
this.getCommand("EpicFarming").setExecutor(new CommandHandler(this)); this.getCommand("EpicFarming").setExecutor(new CommandHandler(this));
getServer().getPluginManager().registerEvents(new BlockListeners(this), this); PluginManager pluginManager = Bukkit.getPluginManager();
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this); // Register Listeners
getServer().getPluginManager().registerEvents(new EntityListeners(), this); pluginManager.registerEvents(new BlockListeners(this), this);
pluginManager.registerEvents(new InteractListeners(this), this);
pluginManager.registerEvents(new InventoryListeners(this), this);
pluginManager.registerEvents(new EntityListeners(), this);
// Register default hooks
if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new);
if (pluginManager.isPluginEnabled("Factions")) this.register(HookFactions::new);
if (pluginManager.isPluginEnabled("GriefPrevention")) this.register(HookGriefPrevention::new);
if (pluginManager.isPluginEnabled("Kingdoms")) this.register(HookKingdoms::new);
if (pluginManager.isPluginEnabled("PlotSquared")) this.register(HookPlotSquared::new);
if (pluginManager.isPluginEnabled("RedProtect")) this.register(HookRedProtect::new);
if (pluginManager.isPluginEnabled("Towny")) this.register(HookTowny::new);
if (pluginManager.isPluginEnabled("USkyBlock")) this.register(HookUSkyBlock::new);
if (pluginManager.isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new);
this.getServer().getPluginManager().registerEvents(this, this);
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
@ -134,7 +163,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
private void loadLevelManager() { private void loadLevelManager() {
// Load an instance of LevelManager // Load an instance of LevelManager
levelManager = new LevelManager(); levelManager = new ELevelManager();
/* /*
* Register Levels into LevelManager from configuration. * Register Levels into LevelManager from configuration.
@ -168,7 +197,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
|| farm.getLocation().getWorld() == null) continue; || farm.getLocation().getWorld() == null) continue;
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation()); String locationStr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation());
dataFile.getConfig().set("Farms." + locationStr + ".level", farm.getLevel().getLevel()); dataFile.getConfig().set("Farms." + locationStr + ".level", farm.getLevel().getLevel());
dataFile.getConfig().set("Farms." + locationStr + ".Contents", farm.dumpInventory()); dataFile.getConfig().set("Farms." + locationStr + ".Contents", ((EFarm)farm).dumpInventory());
} }
//Save to file //Save to file
@ -177,9 +206,6 @@ public class EpicFarming extends JavaPlugin implements Listener {
} }
public void reload() { public void reload() {
hooks.hooksFile.createNewFile("Loading hooks File", "EpicFarming hooks File");
hooks = new HookHandler();
hooks.hook();
locale.reloadMessages(); locale.reloadMessages();
references = new References(); references = new References();
reloadConfig(); reloadConfig();
@ -243,11 +269,72 @@ public class EpicFarming extends JavaPlugin implements Listener {
return locale; return locale;
} }
public FarmManager getFarmManager() {
private void register(Supplier<ProtectionPluginHook> hookSupplier) {
this.registerProtectionHook(hookSupplier.get());
}
@Override
public void registerProtectionHook(ProtectionPluginHook hook) {
Preconditions.checkNotNull(hook, "Cannot register null hook");
Preconditions.checkNotNull(hook.getPlugin(), "Protection plugin hook returns null plugin instance (#getPlugin())");
JavaPlugin hookPlugin = hook.getPlugin();
for (ProtectionPluginHook existingHook : protectionHooks) {
if (existingHook.getPlugin().equals(hookPlugin)) {
throw new IllegalArgumentException("Hook already registered");
}
}
this.hooksFile.getConfig().addDefault("hooks." + hookPlugin.getName(), true);
if (!hooksFile.getConfig().getBoolean("hooks." + hookPlugin.getName(), true)) return;
this.hooksFile.getConfig().options().copyDefaults(true);
this.hooksFile.saveConfig();
this.protectionHooks.add(hook);
this.getLogger().info("Registered protection hook for plugin: " + hook.getPlugin().getName());
}
public boolean canBuild(Player player, Location location) {
if (player.hasPermission(getDescription().getName() + ".bypass")) {
return true;
}
for (ProtectionPluginHook hook : protectionHooks)
if (!hook.canBuild(player, location)) return false;
return true;
}
@Override
public int getLevelFromItem(ItemStack item) {
try {
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0;
if (item.getItemMeta().getDisplayName().contains(":")) {
return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
return 0;
}
@Override
public ItemStack makeFarmItem(Level level) {
ItemStack item = new ItemStack(Material.valueOf(EpicFarmingPlugin.getInstance().getConfig().getString("Main.Farm Block Material")), 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level.getLevel(), true)));
item.setItemMeta(meta);
return item;
}
@Override
public EFarmManager getFarmManager() {
return farmManager; return farmManager;
} }
public LevelManager getLevelManager() { @Override
public ELevelManager getLevelManager() {
return levelManager; return levelManager;
} }

View File

@ -5,7 +5,7 @@ public class References {
private String prefix; private String prefix;
public References() { public References() {
prefix = EpicFarming.getInstance().getLocale().getMessage("general.nametag.prefix") + " "; prefix = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
} }
public String getPrefix() { public String getPrefix() {

View File

@ -1,9 +1,11 @@
package com.songoda.epicfarming.events; package com.songoda.epicfarming.events;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.farming.Farm; import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.farming.FarmManager; import com.songoda.epicfarming.api.farming.Level;
import com.songoda.epicfarming.farming.Level; import com.songoda.epicfarming.farming.EFarm;
import com.songoda.epicfarming.farming.EFarmManager;
import com.songoda.epicfarming.farming.ELevel;
import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Debugger;
import com.songoda.epicfarming.utils.Methods; import com.songoda.epicfarming.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -24,9 +26,9 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class BlockListeners implements Listener { public class BlockListeners implements Listener {
private EpicFarming instance; private EpicFarmingPlugin instance;
public BlockListeners(EpicFarming instance) { public BlockListeners(EpicFarmingPlugin instance) {
this.instance = instance; this.instance = instance;
} }
@ -63,7 +65,7 @@ public class BlockListeners implements Listener {
boolean allowNonCommandIssued = instance.getConfig().getBoolean("Main.Allow Non Command Issued Farm Items"); boolean allowNonCommandIssued = instance.getConfig().getBoolean("Main.Allow Non Command Issued Farm Items");
if (e.getPlayer().getItemInHand().getType() != farmBlock if (e.getPlayer().getItemInHand().getType() != farmBlock
|| Methods.getLevelFromItem(e.getItemInHand()) == 0 && !allowNonCommandIssued) return; || instance.getLevelFromItem(e.getItemInHand()) == 0 && !allowNonCommandIssued) return;
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true); if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
@ -71,13 +73,13 @@ public class BlockListeners implements Listener {
Bukkit.getScheduler().runTaskLater(instance, () -> { Bukkit.getScheduler().runTaskLater(instance, () -> {
int level = 1; int level = 1;
if (Methods.getLevelFromItem(e.getItemInHand()) != 0) { if (instance.getLevelFromItem(e.getItemInHand()) != 0) {
level = Methods.getLevelFromItem(e.getItemInHand()); level = instance.getLevelFromItem(e.getItemInHand());
} }
if (location.getBlock().getType() != farmBlock) return; if (location.getBlock().getType() != farmBlock) return;
Farm farm = new Farm(location, instance.getLevelManager().getLevel(level)); EFarm farm = new EFarm(location, instance.getLevelManager().getLevel(level));
instance.getFarmManager().addFarm(location, farm); instance.getFarmManager().addFarm(location, farm);
farm.tillLand(e.getBlock().getLocation()); farm.tillLand(e.getBlock().getLocation());
@ -90,7 +92,7 @@ public class BlockListeners implements Listener {
private boolean checkForFarm(Location location) { private boolean checkForFarm(Location location) {
FarmManager farmManager = instance.getFarmManager(); EFarmManager farmManager = instance.getFarmManager();
Block block = location.getBlock(); Block block = location.getBlock();
for(Level level : instance.getLevelManager().getLevels().values()) { for(Level level : instance.getLevelManager().getLevels().values()) {
@ -129,14 +131,14 @@ public class BlockListeners implements Listener {
event.setCancelled(true); event.setCancelled(true);
ItemStack item = Methods.makeFarmItem(farm.getLevel()); ItemStack item = instance.makeFarmItem(farm.getLevel());
Block block = event.getBlock(); Block block = event.getBlock();
block.setType(Material.AIR); block.setType(Material.AIR);
block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5,.5,.5), item); block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5,.5,.5), item);
for (ItemStack itemStack : farm.dumpInventory()) { for (ItemStack itemStack : ((EFarm)farm).dumpInventory()) {
if (itemStack == null) continue; if (itemStack == null) continue;
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5,.5,.5), itemStack); farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5,.5,.5), itemStack);
} }

View File

@ -1,6 +1,7 @@
package com.songoda.epicfarming.events; package com.songoda.epicfarming.events;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.farming.EFarm;
import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -14,9 +15,9 @@ import org.bukkit.event.player.PlayerInteractEvent;
*/ */
public class InteractListeners implements Listener { public class InteractListeners implements Listener {
private EpicFarming instance; private EpicFarmingPlugin instance;
public InteractListeners(EpicFarming instance) { public InteractListeners(EpicFarmingPlugin instance) {
this.instance = instance; this.instance = instance;
} }
@ -26,7 +27,7 @@ public class InteractListeners implements Listener {
if (e.getClickedBlock() == null || e.getClickedBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material"))) if (e.getClickedBlock() == null || e.getClickedBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material")))
return; return;
if (!instance.hooks.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) { if (!instance.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) {
e.setCancelled(true); e.setCancelled(true);
return; return;
} }
@ -37,7 +38,7 @@ public class InteractListeners implements Listener {
if (instance.getFarmManager().getFarms().containsKey(location)) { if (instance.getFarmManager().getFarms().containsKey(location)) {
e.setCancelled(true); e.setCancelled(true);
instance.getFarmManager().getFarm(location).view(e.getPlayer()); ((EFarm)instance.getFarmManager().getFarm(location)).view(e.getPlayer());
} }
} catch (Exception ex) { } catch (Exception ex) {
Debugger.runReport(ex); Debugger.runReport(ex);

View File

@ -1,8 +1,8 @@
package com.songoda.epicfarming.events; package com.songoda.epicfarming.events;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.api.UpgradeType; import com.songoda.epicfarming.api.farming.UpgradeType;
import com.songoda.epicfarming.farming.Farm; import com.songoda.epicfarming.farming.EFarm;
import com.songoda.epicfarming.player.PlayerData; import com.songoda.epicfarming.player.PlayerData;
import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -16,9 +16,9 @@ import org.bukkit.event.inventory.InventoryType;
*/ */
public class InventoryListeners implements Listener { public class InventoryListeners implements Listener {
private EpicFarming instance; private EpicFarmingPlugin instance;
public InventoryListeners(EpicFarming instance) { public InventoryListeners(EpicFarmingPlugin instance) {
this.instance = instance; this.instance = instance;
} }
@ -31,7 +31,7 @@ public class InventoryListeners implements Listener {
if (event.getInventory().getType() != InventoryType.CHEST) return; if (event.getInventory().getType() != InventoryType.CHEST) return;
PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked()); PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked());
Farm farm = playerData.getFarm(); EFarm farm = playerData.getFarm();
if (event.getSlot() <= 26) { if (event.getSlot() <= 26) {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -1,5 +1,6 @@
package com.songoda.epicfarming.farming; package com.songoda.epicfarming.farming;
import com.songoda.epicfarming.api.farming.Farm;
import org.bukkit.Location; import org.bukkit.Location;
public class Crop { public class Crop {

View File

@ -1,11 +1,13 @@
package com.songoda.epicfarming.farming; package com.songoda.epicfarming.farming;
import com.songoda.arconix.plugin.Arconix; import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.api.UpgradeType; import com.songoda.epicfarming.api.farming.Level;
import com.songoda.epicfarming.api.farming.UpgradeType;
import com.songoda.epicfarming.player.PlayerData; import com.songoda.epicfarming.player.PlayerData;
import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Debugger;
import com.songoda.epicfarming.utils.Methods; import com.songoda.epicfarming.utils.Methods;
import com.songoda.epicfarming.api.farming.Farm;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -20,13 +22,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class Farm { public class EFarm implements Farm {
private Location location; private Location location;
private Level level; private Level level;
private Inventory inventory; private Inventory inventory;
public Farm(Location location, Level level) { public EFarm(Location location, Level level) {
this.location = location; this.location = location;
this.level = level; this.level = level;
this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false)); this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
@ -40,7 +42,7 @@ public class Farm {
setupOverview(player); setupOverview(player);
player.openInventory(inventory); player.openInventory(inventory);
PlayerData playerData = EpicFarming.getInstance().getPlayerActionManager().getPlayerAction(player); PlayerData playerData = EpicFarmingPlugin.getInstance().getPlayerActionManager().getPlayerAction(player);
playerData.setFarm(this); playerData.setFarm(this);
@ -56,9 +58,9 @@ public class Farm {
inventory.setContents(this.inventory.getContents()); inventory.setContents(this.inventory.getContents());
this.inventory = inventory; this.inventory = inventory;
EpicFarming instance = EpicFarming.getInstance(); EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel()+1) : null; ELevel nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel()+1) : null;
int level = this.level.getLevel(); int level = this.level.getLevel();
@ -131,6 +133,7 @@ public class Farm {
inventory.setItem(26, Methods.getBackgroundGlass(true)); inventory.setItem(26, Methods.getBackgroundGlass(true));
} }
@Override
public Inventory getInventory() { public Inventory getInventory() {
return inventory; return inventory;
} }
@ -155,10 +158,10 @@ public class Farm {
public void upgrade(UpgradeType type, Player player) { public void upgrade(UpgradeType type, Player player) {
try { try {
EpicFarming instance = EpicFarming.getInstance(); EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel()+1)) { if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel()+1)) {
Level level = instance.getLevelManager().getLevel(this.level.getLevel()+1); com.songoda.epicfarming.api.farming.Level level = instance.getLevelManager().getLevel(this.level.getLevel()+1);
int cost; int cost;
if (type == UpgradeType.EXPERIENCE) { if (type == UpgradeType.EXPERIENCE) {
cost = level.getCostExperiance(); cost = level.getCostExperiance();
@ -198,7 +201,7 @@ public class Farm {
private void upgradeFinal(Level level, Player player) { private void upgradeFinal(Level level, Player player) {
try { try {
EpicFarming instance = EpicFarming.getInstance(); EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
this.level = level; this.level = level;
if (instance.getLevelManager().getHighestLevel() != level) { if (instance.getLevelManager().getHighestLevel() != level) {
player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel())); player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel()));
@ -225,7 +228,7 @@ public class Farm {
private static final Random random = new Random(); private static final Random random = new Random();
public boolean tillLand(Location location) { public boolean tillLand(Location location) {
EpicFarming instance = EpicFarming.getInstance(); EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
Block block = location.getBlock(); Block block = location.getBlock();
int radius = level.getRadius(); int radius = level.getRadius();
int bx = block.getX(); int bx = block.getX();
@ -239,7 +242,7 @@ public class Farm {
// ToDo: enum for all flowers. // ToDo: enum for all flowers.
if (b2.getType() == Material.TALL_GRASS || b2.getType() == Material.GRASS || b2.getType().name().contains("TULIP") || b2.getType() == Material.AZURE_BLUET || if (b2.getType() == Material.TALL_GRASS || b2.getType() == Material.GRASS || b2.getType().name().contains("TULIP") || b2.getType() == Material.AZURE_BLUET ||
b2.getType() == Material.BLUE_ORCHID || b2.getType() == Material.ALLIUM || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) { b2.getType() == Material.BLUE_ORCHID || b2.getType() == Material.ALLIUM || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
b2.getRelative(BlockFace.DOWN).setType(Material.LEGACY_SOIL); b2.getRelative(BlockFace.DOWN).setType(Material.LEGACY_SOIL);
b2.breakNaturally(); b2.breakNaturally();
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) { if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
@ -248,7 +251,7 @@ public class Farm {
}, random.nextInt(30) + 1); }, random.nextInt(30) + 1);
} }
if ((b2.getType() == Material.GRASS_BLOCK || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) { if ((b2.getType() == Material.GRASS_BLOCK || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> {
b2.setType(Material.LEGACY_SOIL); b2.setType(Material.LEGACY_SOIL);
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) { if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15); b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
@ -262,14 +265,17 @@ public class Farm {
return false; return false;
} }
@Override
public Location getLocation() { public Location getLocation() {
return location.clone(); return location.clone();
} }
@Override
public void setLocation(Location location) { public void setLocation(Location location) {
this.location = location; this.location = location;
} }
@Override
public Level getLevel() { public Level getLevel() {
return level; return level;
} }

View File

@ -1,6 +1,7 @@
package com.songoda.epicfarming.farming; package com.songoda.epicfarming.farming;
import org.bukkit.Bukkit; import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.api.farming.FarmManager;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -8,26 +9,31 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class FarmManager { public class EFarmManager implements FarmManager {
private final Map<Location, Farm> registeredFarms = new HashMap<>(); private final Map<Location, Farm> registeredFarms = new HashMap<>();
@Override
public void addFarm(Location location, Farm farm) { public void addFarm(Location location, Farm farm) {
registeredFarms.put(roundLocation(location), farm); registeredFarms.put(roundLocation(location), farm);
} }
@Override
public Farm removeFarm(Location location) { public Farm removeFarm(Location location) {
return registeredFarms.remove(roundLocation(location)); return registeredFarms.remove(roundLocation(location));
} }
@Override
public Farm getFarm(Location location) { public Farm getFarm(Location location) {
return registeredFarms.get(roundLocation(location)); return registeredFarms.get(roundLocation(location));
} }
@Override
public Farm getFarm(Block block) { public Farm getFarm(Block block) {
return getFarm(block.getLocation()); return getFarm(block.getLocation());
} }
@Override
public Map<Location, Farm> getFarms() { public Map<Location, Farm> getFarms() {
return Collections.unmodifiableMap(registeredFarms); return Collections.unmodifiableMap(registeredFarms);
} }

View File

@ -1,11 +1,12 @@
package com.songoda.epicfarming.farming; package com.songoda.epicfarming.farming;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.api.farming.Level;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Level { public class ELevel implements Level {
private int level, costExperiance, costEconomy, radius; private int level, costExperiance, costEconomy, radius;
@ -15,7 +16,7 @@ public class Level {
private List<String> description = new ArrayList<>(); private List<String> description = new ArrayList<>();
public Level(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) { public ELevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) {
this.level = level; this.level = level;
this.costExperiance = costExperiance; this.costExperiance = costExperiance;
this.costEconomy = costEconomy; this.costEconomy = costEconomy;
@ -24,7 +25,7 @@ public class Level {
this.autoHarvest = autoHarvest; this.autoHarvest = autoHarvest;
this.autoReplant = autoReplant; this.autoReplant = autoReplant;
EpicFarming instance = EpicFarming.getInstance(); EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
description.add(instance.getLocale().getMessage("interface.button.radius", radius)); description.add(instance.getLocale().getMessage("interface.button.radius", radius));
description.add(instance.getLocale().getMessage("interface.button.speed", speedMultiplier)); description.add(instance.getLocale().getMessage("interface.button.speed", speedMultiplier));
@ -37,34 +38,42 @@ public class Level {
} }
@Override
public List<String> getDescription() { public List<String> getDescription() {
return new ArrayList<>(description); return new ArrayList<>(description);
} }
@Override
public int getLevel() { public int getLevel() {
return level; return level;
} }
@Override
public int getRadius() { public int getRadius() {
return radius; return radius;
} }
@Override
public boolean isAutoHarvest() { public boolean isAutoHarvest() {
return autoHarvest; return autoHarvest;
} }
@Override
public boolean isAutoReplant() { public boolean isAutoReplant() {
return autoReplant; return autoReplant;
} }
@Override
public double getSpeedMultiplier() { public double getSpeedMultiplier() {
return speedMultiplier; return speedMultiplier;
} }
@Override
public int getCostExperiance() { public int getCostExperiance() {
return costExperiance; return costExperiance;
} }
@Override
public int getCostEconomy() { public int getCostEconomy() {
return costEconomy; return costEconomy;
} }

View File

@ -1,38 +1,48 @@
package com.songoda.epicfarming.farming; package com.songoda.epicfarming.farming;
import com.songoda.epicfarming.api.farming.Level;
import com.songoda.epicfarming.api.farming.LevelManager;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.TreeMap; import java.util.TreeMap;
public class LevelManager { public class ELevelManager implements LevelManager {
private final NavigableMap<Integer, Level> registeredLevels = new TreeMap<>(); private final NavigableMap<Integer, ELevel> registeredLevels = new TreeMap<>();
@Override
public void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) { public void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) {
registeredLevels.put(level, new Level(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant)); registeredLevels.put(level, new ELevel(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant));
} }
public Level getLevel(int level) { @Override
public ELevel getLevel(int level) {
return registeredLevels.get(level); return registeredLevels.get(level);
} }
public Level getLowestLevel() { @Override
public ELevel getLowestLevel() {
return registeredLevels.firstEntry().getValue(); return registeredLevels.firstEntry().getValue();
} }
public Level getHighestLevel() { @Override
public ELevel getHighestLevel() {
return registeredLevels.lastEntry().getValue(); return registeredLevels.lastEntry().getValue();
} }
@Override
public boolean isLevel(int level) { public boolean isLevel(int level) {
return registeredLevels.containsKey(level); return registeredLevels.containsKey(level);
} }
@Override
public Map<Integer, Level> getLevels() { public Map<Integer, Level> getLevels() {
return Collections.unmodifiableMap(registeredLevels); return Collections.unmodifiableMap(registeredLevels);
} }
@Override
public void clear() { public void clear() {
registeredLevels.clear(); registeredLevels.clear();
} }

View File

@ -1,8 +1,8 @@
package com.songoda.epicfarming.handlers; package com.songoda.epicfarming.handlers;
import com.songoda.arconix.plugin.Arconix; import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.farming.Level; import com.songoda.epicfarming.farming.ELevel;
import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Debugger;
import com.songoda.epicfarming.utils.Methods; import com.songoda.epicfarming.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -17,9 +17,9 @@ import org.bukkit.entity.Player;
public class CommandHandler implements CommandExecutor { public class CommandHandler implements CommandExecutor {
private EpicFarming instance; private EpicFarmingPlugin instance;
public CommandHandler(EpicFarming instance) { public CommandHandler(EpicFarmingPlugin instance) {
this.instance = instance; this.instance = instance;
} }
@ -48,7 +48,7 @@ public class CommandHandler implements CommandExecutor {
} }
if (args.length >= 1) { if (args.length >= 1) {
Level level = instance.getLevelManager().getLowestLevel(); ELevel level = instance.getLevelManager().getLowestLevel();
Player player; Player player;
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) { if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat player does not exist or is currently offline.")); sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat player does not exist or is currently offline."));
@ -70,7 +70,7 @@ public class CommandHandler implements CommandExecutor {
} else if (args.length != 1){ } else if (args.length != 1){
level = instance.getLevelManager().getLevel(Integer.parseInt(args[2])); level = instance.getLevelManager().getLevel(Integer.parseInt(args[2]));
} }
player.getInventory().addItem(Methods.makeFarmItem(level)); player.getInventory().addItem(instance.makeFarmItem(level));
player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel())); player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel()));
} else if (Bukkit.getPlayerExact(args[1]) == null) { } else if (Bukkit.getPlayerExact(args[1]) == null) {

View File

@ -1,8 +1,9 @@
package com.songoda.epicfarming.handlers; package com.songoda.epicfarming.handlers;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.api.farming.Farm;
import com.songoda.epicfarming.farming.Crop; import com.songoda.epicfarming.farming.Crop;
import com.songoda.epicfarming.farming.Farm; import com.songoda.epicfarming.farming.EFarm;
import com.songoda.epicfarming.utils.CropType; import com.songoda.epicfarming.utils.CropType;
import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -22,12 +23,12 @@ import java.util.Random;
public class FarmingHandler { public class FarmingHandler {
private EpicFarming instance; private EpicFarmingPlugin instance;
public FarmingHandler(EpicFarming instance) { public FarmingHandler(EpicFarmingPlugin instance) {
this.instance = instance; this.instance = instance;
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::farmRunner, 0, instance.getConfig().getInt("Main.Farm Tick Speed")); Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::farmRunner, 0, instance.getConfig().getInt("Main.Farm Tick Speed"));
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::hopRunner, 0, 8); Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::hopRunner, 0, 8);
} }

View File

@ -1,6 +1,6 @@
package com.songoda.epicfarming.handlers; package com.songoda.epicfarming.handlers;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.farming.Crop; import com.songoda.epicfarming.farming.Crop;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.CropState; import org.bukkit.CropState;
@ -15,9 +15,9 @@ import java.util.Random;
public class GrowthHandler { public class GrowthHandler {
public GrowthHandler(EpicFarming instance) { public GrowthHandler(EpicFarmingPlugin instance) {
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::growthRunner, 0, instance.getConfig().getInt("Main.Growth Tick Speed")); Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::growthRunner, 0, instance.getConfig().getInt("Main.Growth Tick Speed"));
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::clear, 0, instance.getConfig().getInt("Main.Clear Tick Speed")); Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::clear, 0, instance.getConfig().getInt("Main.Clear Tick Speed"));
} }
Map<Location, Crop> liveCrops = new HashMap<>(); Map<Location, Crop> liveCrops = new HashMap<>();

View File

@ -0,0 +1,60 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
import com.wasteofplastic.askyblock.ASkyBlock;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class HookASkyBlock implements ClaimableProtectionPluginHook {
private final ASkyBlockAPI skyblock;
public HookASkyBlock() {
this.skyblock = ASkyBlockAPI.getInstance();
}
@Override
public JavaPlugin getPlugin() {
return ASkyBlock.getPlugin();
}
@Override
public boolean canBuild(Player player, Location location) {
Island island = skyblock.getIslandAt(location);
if (island == null) return true;
UUID owner = island.getOwner();
UUID playerUUID = player.getUniqueId();
if (owner == null || owner.equals(playerUUID)) return true;
List<UUID> teamMembers = skyblock.getTeamMembers(owner);
if (teamMembers.contains(playerUUID)) return true;
Set<Location> coopIslands = skyblock.getCoopIslands(player);
for (Location islandLocation : coopIslands) {
if (skyblock.getIslandAt(islandLocation).getOwner().equals(playerUUID)) {
return true;
}
}
return false;
}
@Override
public boolean isInClaim(Location location, String id) {
return skyblock.getOwner(location).toString().equals(id);
}
@Override
public String getClaimID(String name) {
return null;
}
}

View File

@ -0,0 +1,45 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
import me.markeh.factionsframework.FactionsFramework;
import me.markeh.factionsframework.entities.FPlayer;
import me.markeh.factionsframework.entities.FPlayers;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookFactions implements ClaimableProtectionPluginHook {
private final FactionsFramework factions;
public HookFactions() {
this.factions = FactionsFramework.get();
}
@Override
public JavaPlugin getPlugin() {
return factions;
}
@Override
public boolean canBuild(Player player, Location location) {
FPlayer fPlayer = FPlayers.getBySender(player);
Faction faction = Factions.getFactionAt(location);
return faction.isNone() || fPlayer.getFaction().equals(faction);
}
@Override
public boolean isInClaim(Location location, String id) {
return Factions.getFactionAt(location).getId().equals(id);
}
@Override
public String getClaimID(String name) {
Faction faction = Factions.getByName(name, "");
return (faction != null) ? faction.getId() : null;
}
}

View File

@ -0,0 +1,30 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookGriefPrevention implements ProtectionPluginHook {
private final GriefPrevention griefPrevention;
public HookGriefPrevention() {
this.griefPrevention = GriefPrevention.instance;
}
@Override
public JavaPlugin getPlugin() {
return griefPrevention;
}
@Override
public boolean canBuild(Player player, Location location) {
Claim claim = griefPrevention.dataStore.getClaimAt(location, false, null);
return claim != null && claim.allowBuild(player, Material.STONE) == null;
}
}

View File

@ -0,0 +1,38 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.land.SimpleChunkLocation;
import org.kingdoms.constants.player.KingdomPlayer;
import org.kingdoms.main.Kingdoms;
import org.kingdoms.manager.game.GameManagement;
public class HookKingdoms implements ProtectionPluginHook {
private final Kingdoms kingdoms;
public HookKingdoms() {
this.kingdoms = Kingdoms.getInstance();
}
@Override
public JavaPlugin getPlugin() {
return kingdoms;
}
@Override
public boolean canBuild(Player player, Location location) {
KingdomPlayer kPlayer = GameManagement.getPlayerManager().getOfflineKingdomPlayer(player).getKingdomPlayer();
if (kPlayer.getKingdom() == null) return true;
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk());
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
String owner = land.getOwner();
return owner == null || kPlayer.getKingdom().getKingdomName().equals(owner);
}
}

View File

@ -0,0 +1,29 @@
package com.songoda.epicfarming.hooks;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.plotsquared.bukkit.BukkitMain;
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookPlotSquared implements ProtectionPluginHook {
private final PlotAPI plotSquared;
public HookPlotSquared() {
this.plotSquared = new PlotAPI();
}
@Override
public JavaPlugin getPlugin() { // BukkitMain? Really?
return JavaPlugin.getPlugin(BukkitMain.class);
}
@Override
public boolean canBuild(Player player, Location location) {
return plotSquared.getPlot(location) != null && plotSquared.isInPlot(player)
&& plotSquared.getPlot(location) == plotSquared.getPlot(player);
}
}

View File

@ -0,0 +1,32 @@
package com.songoda.epicfarming.hooks;
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
import br.net.fabiozumbi12.RedProtect.Bukkit.Region;
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookRedProtect implements ProtectionPluginHook {
private final RedProtect redProtect;
public HookRedProtect() {
this.redProtect = RedProtect.get();
}
@Override
public JavaPlugin getPlugin() {
return redProtect;
}
@Override
public boolean canBuild(Player player, Location location) {
RedProtectAPI api = redProtect.getAPI();
Region region = api.getRegion(location);
return region != null && region.canBuild(player);
}
}

View File

@ -0,0 +1,59 @@
package com.songoda.epicfarming.hooks;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookTowny implements ClaimableProtectionPluginHook {
private final Towny towny;
public HookTowny() {
this.towny = Towny.getPlugin();
}
@Override
public JavaPlugin getPlugin() {
return towny;
}
@Override
public boolean canBuild(Player player, Location location) {
if (TownyUniverse.isWilderness(location.getBlock()) || !TownyUniverse.getTownBlock(location).hasTown()) return true;
try {
Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
return resident.hasTown() && TownyUniverse.getTownName(location).equals(resident.getTown().getName());
} catch (NotRegisteredException e) {
Debugger.runReport(e);
return false;
}
}
@Override
public boolean isInClaim(Location location, String id) {
try {
return TownyUniverse.isWilderness(location.getBlock()) && TownyUniverse.getTownBlock(location).getTown().getUID().toString().equals(id);
} catch (NotRegisteredException e) {
Debugger.runReport(e);
return false;
}
}
@Override
public String getClaimID(String name) {
try {
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
} catch (NotRegisteredException e) {
Debugger.runReport(e);
return null;
}
}
}

View File

@ -0,0 +1,38 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
public class HookUSkyBlock implements ClaimableProtectionPluginHook {
private final uSkyBlockAPI uSkyblock;
public HookUSkyBlock() {
this.uSkyblock = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("USkyBlock");
}
@Override
public JavaPlugin getPlugin() { // uSkyBlockAPI is also an instance of JavaPlugin
return (JavaPlugin) uSkyblock;
}
@Override
public boolean canBuild(Player player, Location location) {
return uSkyblock.getIslandInfo(location).getOnlineMembers().contains(player) || uSkyblock.getIslandInfo(location).isLeader(player);
}
@Override
public boolean isInClaim(Location location, String id) {
return uSkyblock.getIslandInfo(location).getLeader().equals(id);
}
@Override
public String getClaimID(String name) {
return null;
}
}

View File

@ -0,0 +1,27 @@
package com.songoda.epicfarming.hooks;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class HookWorldGuard implements ProtectionPluginHook {
private final WorldGuardPlugin worldGuard;
public HookWorldGuard() {
this.worldGuard = WorldGuardPlugin.inst();
}
@Override
public JavaPlugin getPlugin() {
return worldGuard;
}
@Override
public boolean canBuild(Player player, Location location) {
return worldGuard.canBuild(player, location);
}
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicfarming.player; package com.songoda.epicfarming.player;
import com.songoda.epicfarming.farming.Farm; import com.songoda.epicfarming.farming.EFarm;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -9,17 +9,17 @@ import java.util.UUID;
public class PlayerData { public class PlayerData {
private final UUID playerUUID; private final UUID playerUUID;
private Farm farm = null; private EFarm farm = null;
public PlayerData(UUID playerUUID) { public PlayerData(UUID playerUUID) {
this.playerUUID = playerUUID; this.playerUUID = playerUUID;
} }
public Farm getFarm() { public EFarm getFarm() {
return farm; return farm;
} }
public void setFarm(Farm farm) { public void setFarm(EFarm farm) {
this.farm = farm; this.farm = farm;
} }

View File

@ -1,11 +1,7 @@
package com.songoda.epicfarming.utils; package com.songoda.epicfarming.utils;
import com.songoda.epicfarming.EpicFarming;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.ArrayList;
import java.util.List;
public enum CropType { public enum CropType {
WHEAT("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS), WHEAT("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS),

View File

@ -1,6 +1,6 @@
package com.songoda.epicfarming.utils; package com.songoda.epicfarming.utils;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
/** /**
* Created by songoda on 3/21/2017. * Created by songoda on 3/21/2017.
@ -24,7 +24,7 @@ public class Debugger {
} }
public static boolean isDebug() { public static boolean isDebug() {
EpicFarming plugin = EpicFarming.pl(); EpicFarmingPlugin plugin = EpicFarmingPlugin.pl();
return plugin.getConfig().getBoolean("System.Debugger Enabled"); return plugin.getConfig().getBoolean("System.Debugger Enabled");
} }

View File

@ -1,8 +1,8 @@
package com.songoda.epicfarming.utils; package com.songoda.epicfarming.utils;
import com.songoda.arconix.plugin.Arconix; import com.songoda.arconix.plugin.Arconix;
import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.farming.Level; import com.songoda.epicfarming.farming.ELevel;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -12,7 +12,7 @@ public class Methods {
public static ItemStack getGlass() { public static ItemStack getGlass() {
try { try {
EpicFarming plugin = EpicFarming.pl(); EpicFarmingPlugin plugin = EpicFarmingPlugin.pl();
return Arconix.pl().getApi().getGUI().getGlass(plugin.getConfig().getBoolean("settings.Rainbow-Glass"), plugin.getConfig().getInt("Interfaces.Glass Type 1")); return Arconix.pl().getApi().getGUI().getGlass(plugin.getConfig().getBoolean("settings.Rainbow-Glass"), plugin.getConfig().getInt("Interfaces.Glass Type 1"));
} catch (Exception ex) { } catch (Exception ex) {
Debugger.runReport(ex); Debugger.runReport(ex);
@ -22,7 +22,7 @@ public class Methods {
public static ItemStack getBackgroundGlass(boolean type) { public static ItemStack getBackgroundGlass(boolean type) {
try { try {
EpicFarming plugin = EpicFarming.pl(); EpicFarmingPlugin plugin = EpicFarmingPlugin.pl();
if (type) if (type)
return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2")); return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2"));
else else
@ -33,21 +33,9 @@ public class Methods {
return null; return null;
} }
public static int getLevelFromItem(ItemStack item) {
try {
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0;
if (item.getItemMeta().getDisplayName().contains(":")) {
return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0);
}
} catch (Exception ex) {
Debugger.runReport(ex);
}
return 0;
}
public static String formatName(int level, boolean full) { public static String formatName(int level, boolean full) {
try { try {
String name = EpicFarming.getInstance().getLocale().getMessage("general.nametag.farm", level); String name = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.farm", level);
String info = ""; String info = "";
if (full) { if (full) {
@ -60,12 +48,4 @@ public class Methods {
} }
return null; return null;
} }
public static ItemStack makeFarmItem(Level level) {
ItemStack item = new ItemStack(Material.valueOf(EpicFarming.getInstance().getConfig().getString("Main.Farm Block Material")), 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level.getLevel(), true)));
item.setItemMeta(meta);
return item;
}
} }

View File

@ -2,8 +2,7 @@ package com.songoda.epicfarming.utils;
import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.arconix.api.methods.formatting.TextComponent;
import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.arconix.plugin.Arconix; import com.songoda.epicfarming.EpicFarmingPlugin;
import com.songoda.epicfarming.EpicFarming;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -34,9 +33,9 @@ public class SettingsManager implements Listener {
private Map<Player, String> cat = new HashMap<>(); private Map<Player, String> cat = new HashMap<>();
private final EpicFarming instance; private final EpicFarmingPlugin instance;
public SettingsManager(EpicFarming plugin) { public SettingsManager(EpicFarmingPlugin plugin) {
this.instance = plugin; this.instance = plugin;
plugin.saveResource("SettingDefinitions.yml", true); plugin.saveResource("SettingDefinitions.yml", true);

View File

@ -1,114 +0,0 @@
package com.songoda.epicfarming.handlers;
import com.songoda.arconix.api.utils.ConfigWrapper;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.hooks.*;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class HookHandler {
public Hook FactionsHook = null, RedProtectHook = null, ASkyBlockHook = null, USkyBlockHook = null,
WorldGuardHook = null, GriefPreventionHook = null, PlotSquaredHook = null, KingdomsHook = null,
TownyHook = null;
public ConfigWrapper hooksFile = new ConfigWrapper(EpicFarming.getInstance(), "", "hooks.yml");
public HookHandler() {
}
public void hook() {
try {
hooksFile.createNewFile("Loading hooks File", EpicFarming.getInstance().getDescription().getName() + " hooks File");
new FactionsHook();
new RedProtectHook();
new GriefPreventionHook();
new ASkyBlockHook();
new USkyBlockHook();
new WorldGuardHook();
new PlotSquaredHook();
new KingdomsHook();
new TownyHook();
hooksFile.getConfig().options().copyDefaults(true);
hooksFile.saveConfig();
} catch (Exception e) {
Debugger.runReport(e);
}
}
public boolean isInFaction(String name, Location l) {
if (FactionsHook != null) {
return FactionsHook.isInClaim(name, l);
}
return false;
}
public String getFactionId(String name) {
if (FactionsHook != null) {
return FactionsHook.getClaimId(name);
}
return null;
}
public boolean isInTown(String name, Location l) {
if (TownyHook != null) {
return TownyHook.isInClaim(name, l);
}
return false;
}
public String getTownId(String name) {
if (TownyHook != null) {
return TownyHook.getClaimId(name);
}
return null;
}
public boolean isInIsland(String name, Location l) {
if (USkyBlockHook != null)
return USkyBlockHook.isInClaim(name, l);
else if (ASkyBlockHook != null)
return ASkyBlockHook.isInClaim(name, l);
else
return false;
}
public String getIslandId(String name) {
try {
return Bukkit.getOfflinePlayer(name).getUniqueId().toString();
} catch (Exception ignore) {
}
return null;
}
public boolean canBuild(Player p, Location l) {
boolean result = true;
if (WorldGuardHook != null)
result = WorldGuardHook.canBuild(p, l);
if (RedProtectHook != null && result)
result = RedProtectHook.canBuild(p, l);
if (FactionsHook != null && result)
result = FactionsHook.canBuild(p, l);
if (ASkyBlockHook != null && result)
result = ASkyBlockHook.canBuild(p, l);
if (USkyBlockHook != null && result)
result = USkyBlockHook.canBuild(p, l);
if (GriefPreventionHook != null && result)
result = GriefPreventionHook.canBuild(p, l);
if (PlotSquaredHook != null && result)
result = PlotSquaredHook.canBuild(p, l);
if (KingdomsHook != null && result)
result = KingdomsHook.canBuild(p, l);
if (TownyHook != null && result)
result = TownyHook.canBuild(p, l);
return result;
}
}

View File

@ -1,64 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* Created by songoda on 3/17/2017.
*/
public class ASkyBlockHook extends Hook {
private ASkyBlockAPI as;
public ASkyBlockHook() {
super("ASkyblock");
if (isEnabled()) {
as = ASkyBlockAPI.getInstance();
EpicFarming plugin = EpicFarming.pl();
plugin.hooks.ASkyBlockHook = this;
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || as.getIslandAt(location) == null) return true;
UUID owner = as.getOwner(location);
List<UUID> list = as.getTeamMembers(owner);
Set<Location> list2 = as.getCoopIslands(p);
if (owner == null) return true;
for (UUID uuid : list) {
if (uuid.equals(p.getUniqueId())) {
return true;
}
}
for (Location loc: list2) {
if (as.getIslandAt(location).getOwner().equals(as.getIslandAt(loc).getOwner())) {
return true;
}
}
return owner.equals(p.getUniqueId());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return as.getOwner(location).toString().equals(uuid);
}
}

View File

@ -1,56 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import me.markeh.factionsframework.entities.FPlayer;
import me.markeh.factionsframework.entities.FPlayers;
import me.markeh.factionsframework.entities.Faction;
import me.markeh.factionsframework.entities.Factions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class FactionsHook extends Hook {
public FactionsHook() {
super("Factions");
EpicFarming plugin = EpicFarming.pl();
if (isEnabled())
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
FPlayer fp = FPlayers.getBySender(p);
Faction faction = Factions.getFactionAt(location);
return (fp.getFaction().equals(faction) || faction.isNone());
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String id, Location location) {
Faction faction = Factions.getFactionAt(location);
return faction.getId().equals(id);
}
@Override
public String getClaimId(String name) {
try {
Faction faction = Factions.getByName(name, "");
return faction.getId();
} catch (Exception e) {
}
return null;
}
}

View File

@ -1,38 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class GriefPreventionHook extends Hook {
private EpicFarming plugin = EpicFarming.pl();
public GriefPreventionHook() {
super("GriefPrevention");
if (isEnabled())
plugin.hooks.GriefPreventionHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p))
return true;
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
return claim != null && claim.allowBuild(p, Material.STONE) == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}

View File

@ -1,40 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.EpicFarming;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public abstract class Hook {
protected final String pluginName;
protected Hook(String pluginName) {
this.pluginName = pluginName;
if (isEnabled())
EpicFarming.getInstance().hooks.hooksFile.getConfig().addDefault("hooks." + pluginName, true);
}
protected boolean isEnabled() {
return (Bukkit.getPluginManager().isPluginEnabled(pluginName)
&& EpicFarming.getInstance().hooks.hooksFile.getConfig().getBoolean("hooks." + pluginName,true));
}
protected boolean hasBypass(Player p) {
return p.hasPermission(EpicFarming.getInstance().getDescription().getName() + ".bypass");
}
public abstract boolean canBuild(Player p, Location location);
public boolean isInClaim(String id, Location location) {
return false;
}
public String getClaimId(String name) {
return null;
}
}

View File

@ -1,43 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.land.SimpleChunkLocation;
import org.kingdoms.constants.player.OfflineKingdomPlayer;
import org.kingdoms.manager.game.GameManagement;
/**
* Created by songoda on 3/17/2017.
*/
public class KingdomsHook extends Hook {
public KingdomsHook() {
super("Kingdoms");
EpicFarming plugin = EpicFarming.pl();
if (isEnabled())
plugin.hooks.KingdomsHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
OfflineKingdomPlayer pl = GameManagement.getPlayerManager().getOfflineKingdomPlayer(p);
if (pl.getKingdomPlayer().getKingdom() == null) return true;
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ());
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
String owner = land.getOwner();
return pl.getKingdomPlayer().getKingdom().getKingdomName().equals(owner) || owner == null;
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -1,38 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class PlotSquaredHook extends Hook {
private PlotAPI plotAPI;
public PlotSquaredHook() {
super("PlotSquared");
if (isEnabled()) {
EpicFarming plugin = EpicFarming.pl();
plugin.hooks.PlotSquaredHook = this;
this.plotAPI = new PlotAPI();
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return hasBypass(p)
|| (plotAPI.getPlot(location) != null
&& plotAPI.isInPlot(p)
&& plotAPI.getPlot(p) == plotAPI.getPlot(location));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -1,34 +0,0 @@
package com.songoda.epicfarming.hooks;
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class RedProtectHook extends Hook {
private EpicFarming plugin = EpicFarming.pl();
public RedProtectHook() {
super("RedProtect");
if (isEnabled())
plugin.hooks.RedProtectHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
RedProtectAPI rpAPI = RedProtect.get().getAPI();
return hasBypass(p) || (rpAPI.getRegion(location) != null && rpAPI.getRegion(location).canBuild(p));
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
}

View File

@ -1,56 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class TownyHook extends Hook {
public TownyHook() {
super("Towny");
EpicFarming plugin = EpicFarming.pl();
if (isEnabled())
plugin.hooks.TownyHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p) || TownyUniverse.isWilderness(location.getBlock())) return true;
if (!TownyUniverse.getTownBlock(location).hasTown()) return true;
Resident r = TownyUniverse.getDataSource().getResident(p.getName());
return r.hasTown() && TownyUniverse.getTownName(location).equals(r.getTown().getName());
} catch (Exception e) {
Debugger.runReport(e);
}
return true;
}
@Override
public boolean isInClaim(String id, Location location) {
try {
return !TownyUniverse.isWilderness(location.getBlock())
&& TownyUniverse.getTownBlock(location).getTown().getUID() == Integer.parseInt(id);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public String getClaimId(String name) {
try {
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
} catch (Exception e) {
Debugger.runReport(e);
}
return null;
}
}

View File

@ -1,49 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
/**
* Created by songoda on 3/17/2017.
*/
public class USkyBlockHook extends Hook {
private uSkyBlockAPI usb;
private EpicFarming plugin = EpicFarming.pl();
public USkyBlockHook() {
super("USkyBlock");
if (isEnabled()) {
plugin.hooks.USkyBlockHook = this;
this.usb = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin(pluginName);
}
}
@Override
public boolean canBuild(Player p, Location location) {
try {
if (hasBypass(p)) return true;
for (Player pl : usb.getIslandInfo(location).getOnlineMembers()) {
if (pl.equals(p)) {
return true;
}
}
return usb.getIslandInfo(location).isLeader(p);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
@Override
public boolean isInClaim(String uuid, Location location) {
return usb.getIslandInfo(location).getLeader().equals(uuid);
}
}

View File

@ -1,31 +0,0 @@
package com.songoda.epicfarming.hooks;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.songoda.epicfarming.EpicFarming;
import com.songoda.epicfarming.utils.Debugger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Created by songoda on 3/17/2017.
*/
public class WorldGuardHook extends Hook {
private EpicFarming plugin = EpicFarming.pl();
public WorldGuardHook() {
super("WorldGuard");
if (isEnabled())
plugin.hooks.WorldGuardHook = this;
}
@Override
public boolean canBuild(Player p, Location location) {
try {
return p.hasPermission(plugin.getDescription().getName() + ".bypass") || WorldGuardPlugin.inst().canBuild(p, location);
} catch (Exception e) {
Debugger.runReport(e);
}
return false;
}
}