mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-11-27 21:15:28 +01:00
Implemented real API system.
Added in the HookHandler v3
This commit is contained in:
parent
7454ac519b
commit
7a97c45fa1
24
EpicFarming-API/EpicFarming-API.iml
Normal file
24
EpicFarming-API/EpicFarming-API.iml
Normal 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>
|
@ -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();
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
@ -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();
|
||||
}
|
@ -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();
|
||||
}
|
@ -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();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicfarming.api;
|
||||
package com.songoda.epicfarming.api.farming;
|
||||
|
||||
public enum UpgradeType {
|
||||
EXPERIENCE, ECONOMY
|
@ -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);
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
26
EpicFarming-Plugin/EpicFarming-Plugin.iml
Normal file
26
EpicFarming-Plugin/EpicFarming-Plugin.iml
Normal 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>
|
@ -1,54 +1,72 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.arconix.api.mcupdate.MCUpdate;
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
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.EntityListeners;
|
||||
import com.songoda.epicfarming.events.InteractListeners;
|
||||
import com.songoda.epicfarming.events.InventoryListeners;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmManager;
|
||||
import com.songoda.epicfarming.farming.LevelManager;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.farming.EFarmManager;
|
||||
import com.songoda.epicfarming.farming.ELevel;
|
||||
import com.songoda.epicfarming.farming.ELevelManager;
|
||||
import com.songoda.epicfarming.handlers.CommandHandler;
|
||||
import com.songoda.epicfarming.handlers.FarmingHandler;
|
||||
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.PlayerData;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
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.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 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 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 FarmingHandler farmingHandler;
|
||||
private GrowthHandler growthHandler;
|
||||
private FarmManager farmManager;
|
||||
private LevelManager levelManager;
|
||||
private EFarmManager farmManager;
|
||||
private ELevelManager levelManager;
|
||||
private PlayerActionManager playerActionManager;
|
||||
|
||||
public static EpicFarming pl() {
|
||||
public static EpicFarmingPlugin pl() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static EpicFarming getInstance() {
|
||||
public static EpicFarmingPlugin getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@ -74,7 +92,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
||||
|
||||
loadLevelManager();
|
||||
|
||||
farmManager = new FarmManager();
|
||||
farmManager = new EFarmManager();
|
||||
|
||||
/*
|
||||
* 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");
|
||||
|
||||
Farm farm = new Farm(location, levelManager.getLevel(level));
|
||||
EFarm farm = new EFarm(location, levelManager.getLevel(level));
|
||||
farm.loadInventory(items);
|
||||
|
||||
farmManager.addFarm(location, farm);
|
||||
@ -95,8 +113,6 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
||||
}
|
||||
playerActionManager = new PlayerActionManager();
|
||||
|
||||
hooks = new HookHandler();
|
||||
hooks.hook();
|
||||
|
||||
farmingHandler = new FarmingHandler(this);
|
||||
growthHandler = new GrowthHandler(this);
|
||||
@ -104,13 +120,26 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
||||
|
||||
this.getCommand("EpicFarming").setExecutor(new CommandHandler(this));
|
||||
|
||||
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new EntityListeners(), this);
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
// Register Listeners
|
||||
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);
|
||||
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
|
||||
new MCUpdate(this, true);
|
||||
@ -134,7 +163,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
||||
|
||||
private void loadLevelManager() {
|
||||
// Load an instance of LevelManager
|
||||
levelManager = new LevelManager();
|
||||
levelManager = new ELevelManager();
|
||||
|
||||
/*
|
||||
* Register Levels into LevelManager from configuration.
|
||||
@ -168,7 +197,7 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
||||
|| farm.getLocation().getWorld() == null) continue;
|
||||
String locationStr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation());
|
||||
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
|
||||
@ -177,9 +206,6 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
hooks.hooksFile.createNewFile("Loading hooks File", "EpicFarming hooks File");
|
||||
hooks = new HookHandler();
|
||||
hooks.hook();
|
||||
locale.reloadMessages();
|
||||
references = new References();
|
||||
reloadConfig();
|
||||
@ -243,11 +269,72 @@ public class EpicFarming extends JavaPlugin implements Listener {
|
||||
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;
|
||||
}
|
||||
|
||||
public LevelManager getLevelManager() {
|
||||
@Override
|
||||
public ELevelManager getLevelManager() {
|
||||
return levelManager;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ public class References {
|
||||
private String prefix;
|
||||
|
||||
public References() {
|
||||
prefix = EpicFarming.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
prefix = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
@ -1,9 +1,11 @@
|
||||
package com.songoda.epicfarming.events;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.FarmManager;
|
||||
import com.songoda.epicfarming.farming.Level;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import com.songoda.epicfarming.api.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.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -24,9 +26,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private EpicFarming instance;
|
||||
private EpicFarmingPlugin instance;
|
||||
|
||||
public BlockListeners(EpicFarming instance) {
|
||||
public BlockListeners(EpicFarmingPlugin 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");
|
||||
|
||||
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);
|
||||
|
||||
@ -71,13 +73,13 @@ public class BlockListeners implements Listener {
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(instance, () -> {
|
||||
int level = 1;
|
||||
if (Methods.getLevelFromItem(e.getItemInHand()) != 0) {
|
||||
level = Methods.getLevelFromItem(e.getItemInHand());
|
||||
if (instance.getLevelFromItem(e.getItemInHand()) != 0) {
|
||||
level = instance.getLevelFromItem(e.getItemInHand());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
farm.tillLand(e.getBlock().getLocation());
|
||||
@ -90,7 +92,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
private boolean checkForFarm(Location location) {
|
||||
|
||||
FarmManager farmManager = instance.getFarmManager();
|
||||
EFarmManager farmManager = instance.getFarmManager();
|
||||
|
||||
Block block = location.getBlock();
|
||||
for(Level level : instance.getLevelManager().getLevels().values()) {
|
||||
@ -129,14 +131,14 @@ public class BlockListeners implements Listener {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack item = Methods.makeFarmItem(farm.getLevel());
|
||||
ItemStack item = instance.makeFarmItem(farm.getLevel());
|
||||
|
||||
Block block = event.getBlock();
|
||||
|
||||
block.setType(Material.AIR);
|
||||
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;
|
||||
farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5,.5,.5), itemStack);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
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 org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -14,9 +15,9 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
*/
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private EpicFarming instance;
|
||||
private EpicFarmingPlugin instance;
|
||||
|
||||
public InteractListeners(EpicFarming instance) {
|
||||
public InteractListeners(EpicFarmingPlugin 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")))
|
||||
return;
|
||||
|
||||
if (!instance.hooks.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) {
|
||||
if (!instance.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -37,7 +38,7 @@ public class InteractListeners implements Listener {
|
||||
|
||||
if (instance.getFarmManager().getFarms().containsKey(location)) {
|
||||
e.setCancelled(true);
|
||||
instance.getFarmManager().getFarm(location).view(e.getPlayer());
|
||||
((EFarm)instance.getFarmManager().getFarm(location)).view(e.getPlayer());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicfarming.events;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.UpgradeType;
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.api.farming.UpgradeType;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,9 +16,9 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
*/
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
private EpicFarming instance;
|
||||
private EpicFarmingPlugin instance;
|
||||
|
||||
public InventoryListeners(EpicFarming instance) {
|
||||
public InventoryListeners(EpicFarmingPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ public class InventoryListeners implements Listener {
|
||||
if (event.getInventory().getType() != InventoryType.CHEST) return;
|
||||
|
||||
PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked());
|
||||
Farm farm = playerData.getFarm();
|
||||
EFarm farm = playerData.getFarm();
|
||||
if (event.getSlot() <= 26) {
|
||||
event.setCancelled(true);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Crop {
|
@ -1,11 +1,13 @@
|
||||
package com.songoda.epicfarming.farming;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.api.UpgradeType;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.api.farming.Level;
|
||||
import com.songoda.epicfarming.api.farming.UpgradeType;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import com.songoda.epicfarming.api.farming.Farm;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
@ -20,13 +22,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Farm {
|
||||
public class EFarm implements Farm {
|
||||
|
||||
private Location location;
|
||||
private Level level;
|
||||
private Inventory inventory;
|
||||
|
||||
public Farm(Location location, Level level) {
|
||||
public EFarm(Location location, Level level) {
|
||||
this.location = location;
|
||||
this.level = level;
|
||||
this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
|
||||
@ -40,7 +42,7 @@ public class Farm {
|
||||
setupOverview(player);
|
||||
|
||||
player.openInventory(inventory);
|
||||
PlayerData playerData = EpicFarming.getInstance().getPlayerActionManager().getPlayerAction(player);
|
||||
PlayerData playerData = EpicFarmingPlugin.getInstance().getPlayerActionManager().getPlayerAction(player);
|
||||
|
||||
playerData.setFarm(this);
|
||||
|
||||
@ -56,9 +58,9 @@ public class Farm {
|
||||
inventory.setContents(this.inventory.getContents());
|
||||
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();
|
||||
|
||||
@ -131,6 +133,7 @@ public class Farm {
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
@ -155,10 +158,10 @@ public class Farm {
|
||||
|
||||
public void upgrade(UpgradeType type, Player player) {
|
||||
try {
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
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;
|
||||
if (type == UpgradeType.EXPERIENCE) {
|
||||
cost = level.getCostExperiance();
|
||||
@ -198,7 +201,7 @@ public class Farm {
|
||||
|
||||
private void upgradeFinal(Level level, Player player) {
|
||||
try {
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
this.level = level;
|
||||
if (instance.getLevelManager().getHighestLevel() != level) {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel()));
|
||||
@ -225,7 +228,7 @@ public class Farm {
|
||||
private static final Random random = new Random();
|
||||
|
||||
public boolean tillLand(Location location) {
|
||||
EpicFarming instance = EpicFarming.getInstance();
|
||||
EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance();
|
||||
Block block = location.getBlock();
|
||||
int radius = level.getRadius();
|
||||
int bx = block.getX();
|
||||
@ -239,7 +242,7 @@ public class Farm {
|
||||
// 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 ||
|
||||
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.breakNaturally();
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
@ -248,7 +251,7 @@ public class Farm {
|
||||
}, random.nextInt(30) + 1);
|
||||
}
|
||||
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);
|
||||
if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
|
||||
b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
|
||||
@ -262,14 +265,17 @@ public class Farm {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
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.block.Block;
|
||||
|
||||
@ -8,26 +9,31 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FarmManager {
|
||||
public class EFarmManager implements FarmManager {
|
||||
|
||||
private final Map<Location, Farm> registeredFarms = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void addFarm(Location location, Farm farm) {
|
||||
registeredFarms.put(roundLocation(location), farm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Farm removeFarm(Location location) {
|
||||
return registeredFarms.remove(roundLocation(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Farm getFarm(Location location) {
|
||||
return registeredFarms.get(roundLocation(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Farm getFarm(Block block) {
|
||||
return getFarm(block.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Location, Farm> getFarms() {
|
||||
return Collections.unmodifiableMap(registeredFarms);
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
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.List;
|
||||
|
||||
public class Level {
|
||||
public class ELevel implements Level {
|
||||
|
||||
private int level, costExperiance, costEconomy, radius;
|
||||
|
||||
@ -15,7 +16,7 @@ public class Level {
|
||||
|
||||
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.costExperiance = costExperiance;
|
||||
this.costEconomy = costEconomy;
|
||||
@ -24,7 +25,7 @@ public class Level {
|
||||
this.autoHarvest = autoHarvest;
|
||||
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.speed", speedMultiplier));
|
||||
@ -37,34 +38,42 @@ public class Level {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDescription() {
|
||||
return new ArrayList<>(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoHarvest() {
|
||||
return autoHarvest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoReplant() {
|
||||
return autoReplant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeedMultiplier() {
|
||||
return speedMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCostExperiance() {
|
||||
return costExperiance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCostEconomy() {
|
||||
return costEconomy;
|
||||
}
|
@ -1,38 +1,48 @@
|
||||
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.Map;
|
||||
import java.util.NavigableMap;
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
public Level getLowestLevel() {
|
||||
@Override
|
||||
public ELevel getLowestLevel() {
|
||||
return registeredLevels.firstEntry().getValue();
|
||||
}
|
||||
|
||||
public Level getHighestLevel() {
|
||||
@Override
|
||||
public ELevel getHighestLevel() {
|
||||
return registeredLevels.lastEntry().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLevel(int level) {
|
||||
return registeredLevels.containsKey(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Level> getLevels() {
|
||||
return Collections.unmodifiableMap(registeredLevels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
registeredLevels.clear();
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicfarming.handlers;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Level;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.farming.ELevel;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import com.songoda.epicfarming.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -17,9 +17,9 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
|
||||
private EpicFarming instance;
|
||||
private EpicFarmingPlugin instance;
|
||||
|
||||
public CommandHandler(EpicFarming instance) {
|
||||
public CommandHandler(EpicFarmingPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
if (args.length >= 1) {
|
||||
|
||||
Level level = instance.getLevelManager().getLowestLevel();
|
||||
ELevel level = instance.getLevelManager().getLowestLevel();
|
||||
Player player;
|
||||
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."));
|
||||
@ -70,7 +70,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
} else if (args.length != 1){
|
||||
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()));
|
||||
|
||||
} else if (Bukkit.getPlayerExact(args[1]) == null) {
|
@ -1,8 +1,9 @@
|
||||
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.Farm;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.utils.CropType;
|
||||
import com.songoda.epicfarming.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -22,12 +23,12 @@ import java.util.Random;
|
||||
|
||||
public class FarmingHandler {
|
||||
|
||||
private EpicFarming instance;
|
||||
private EpicFarmingPlugin instance;
|
||||
|
||||
public FarmingHandler(EpicFarming instance) {
|
||||
public FarmingHandler(EpicFarmingPlugin instance) {
|
||||
this.instance = instance;
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.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::farmRunner, 0, instance.getConfig().getInt("Main.Farm Tick Speed"));
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::hopRunner, 0, 8);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.handlers;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.farming.Crop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.CropState;
|
||||
@ -15,9 +15,9 @@ import java.util.Random;
|
||||
|
||||
public class GrowthHandler {
|
||||
|
||||
public GrowthHandler(EpicFarming instance) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.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"));
|
||||
public GrowthHandler(EpicFarmingPlugin instance) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::growthRunner, 0, instance.getConfig().getInt("Main.Growth Tick Speed"));
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::clear, 0, instance.getConfig().getInt("Main.Clear Tick Speed"));
|
||||
}
|
||||
|
||||
Map<Location, Crop> liveCrops = new HashMap<>();
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.player;
|
||||
|
||||
import com.songoda.epicfarming.farming.Farm;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -9,17 +9,17 @@ import java.util.UUID;
|
||||
public class PlayerData {
|
||||
|
||||
private final UUID playerUUID;
|
||||
private Farm farm = null;
|
||||
private EFarm farm = null;
|
||||
|
||||
public PlayerData(UUID playerUUID) {
|
||||
this.playerUUID = playerUUID;
|
||||
}
|
||||
|
||||
public Farm getFarm() {
|
||||
public EFarm getFarm() {
|
||||
return farm;
|
||||
}
|
||||
|
||||
public void setFarm(Farm farm) {
|
||||
public void setFarm(EFarm farm) {
|
||||
this.farm = farm;
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum CropType {
|
||||
|
||||
WHEAT("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS),
|
@ -1,6 +1,6 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/21/2017.
|
||||
@ -24,7 +24,7 @@ public class Debugger {
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
EpicFarmingPlugin plugin = EpicFarmingPlugin.pl();
|
||||
return plugin.getConfig().getBoolean("System.Debugger Enabled");
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.farming.Level;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.farming.ELevel;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -12,7 +12,7 @@ public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
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"));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
@ -22,7 +22,7 @@ public class Methods {
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
try {
|
||||
EpicFarming plugin = EpicFarming.pl();
|
||||
EpicFarmingPlugin plugin = EpicFarmingPlugin.pl();
|
||||
if (type)
|
||||
return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
@ -33,21 +33,9 @@ public class Methods {
|
||||
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) {
|
||||
try {
|
||||
String name = EpicFarming.getInstance().getLocale().getMessage("general.nametag.farm", level);
|
||||
String name = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.farm", level);
|
||||
|
||||
String info = "";
|
||||
if (full) {
|
||||
@ -60,12 +48,4 @@ public class Methods {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
@ -2,8 +2,7 @@ package com.songoda.epicfarming.utils;
|
||||
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicfarming.EpicFarming;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -34,9 +33,9 @@ public class SettingsManager implements Listener {
|
||||
|
||||
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;
|
||||
|
||||
plugin.saveResource("SettingDefinitions.yml", true);
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user