mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-11-05 18:39:49 +01:00
Hooks
This commit is contained in:
parent
1458ee22cb
commit
a96ca65f59
150
.gitignore
vendored
150
.gitignore
vendored
@ -14,3 +14,153 @@ EpicFarming-Plugin/src/main/EpicFarming-Plugin\.iml
|
||||
EpicFarming-Parent\.iml
|
||||
|
||||
*.iml
|
||||
|
||||
EpicFarming-API/target/classes/com/songoda/epicfarming/api/EpicFarming\.class
|
||||
|
||||
EpicFarming-API/target/classes/com/songoda/epicfarming/api/EpicFarmingAPI\.class
|
||||
|
||||
EpicFarming-API/target/classes/com/songoda/epicfarming/api/farming/Farm\.class
|
||||
|
||||
EpicFarming-API/target/classes/com/songoda/epicfarming/api/farming/FarmManager\.class
|
||||
|
||||
EpicFarming-API/target/classes/com/songoda/epicfarming/api/farming/Level\.class
|
||||
|
||||
EpicFarming-API/target/classes/com/songoda/epicfarming/api/farming/LevelManager\.class
|
||||
|
||||
EpicFarming-API/target/classes/com/songoda/epicfarming/api/farming/UpgradeType\.class
|
||||
|
||||
EpicFarming-Plugin/pom\.xml
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/boost/BoostData\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/boost/BoostManager\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/AbstractCommand\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/AbstractCommand\$ReturnType\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/CommandManager\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/commands/CommandBoost\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/commands/CommandEpicFarming\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/commands/CommandGiveFarmItem\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/commands/CommandReload\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/command/commands/CommandSettings\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/EpicFarmingPlugin\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/farming/Crop\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/farming/EFarm\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/farming/EFarmManager\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/farming/ELevel\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/farming/ELevelManager\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/HookManager\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookASkyBlock\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookFactions\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookGriefPrevention\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookKingdoms\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookPlotSquared\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookRedProtect\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookSkyBlockEarth\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookTowny\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookUSkyBlock\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/hooks/HookWorldGuard\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/HookType\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/hook/ProtectionPluginHook\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/listeners/BlockListeners\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/listeners/InteractListeners\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/listeners/InventoryListeners\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/Locale\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/player/PlayerActionManager\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/player/PlayerData\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/References\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/storage/Storage\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/storage/StorageItem\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/storage/StorageRow\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/storage/types/StorageMysql\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/storage/types/StorageYaml\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/tasks/EntityTask\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/tasks/EntityTask\$1\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/tasks/FarmTask\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/tasks/GrowthTask\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/tasks/GrowthTask\$1\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/tasks/HopperTask\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/ConfigWrapper\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/CropType\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Debugger\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/EntityInfo\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Methods\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$1\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$2\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$AdvancedBarChart\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$AdvancedPie\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$CustomChart\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$DrilldownPie\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$MultiLineChart\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$SimpleBarChart\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$SimplePie\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Metrics\$SingleLineChart\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/MySQLDatabase\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/Serializers\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/SettingsManager\.class
|
||||
|
||||
EpicFarming-Plugin/target/classes/com/songoda/epicfarming/utils/SettingsManager\$settings\.class
|
||||
|
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicFarming"
|
||||
path: "/builds/Songoda/$name"
|
||||
version: "2.1.4"
|
||||
version: "2.1.5"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -3,13 +3,10 @@ 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);
|
||||
|
@ -1,39 +0,0 @@
|
||||
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);
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>skyblockearth</artifactId>
|
||||
<version>59</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.arcaniax</groupId>
|
||||
<artifactId>liquidtanks</artifactId>
|
||||
|
@ -1,25 +1,20 @@
|
||||
package com.songoda.epicfarming;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.epicfarming.api.EpicFarming;
|
||||
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.boost.BoostData;
|
||||
import com.songoda.epicfarming.boost.BoostManager;
|
||||
import com.songoda.epicfarming.command.CommandManager;
|
||||
import com.songoda.epicfarming.farming.EFarm;
|
||||
import com.songoda.epicfarming.farming.EFarmManager;
|
||||
import com.songoda.epicfarming.farming.ELevelManager;
|
||||
import com.songoda.epicfarming.hooks.*;
|
||||
import com.songoda.epicfarming.hook.HookManager;
|
||||
import com.songoda.epicfarming.listeners.BlockListeners;
|
||||
import com.songoda.epicfarming.listeners.InteractListeners;
|
||||
import com.songoda.epicfarming.listeners.InventoryListeners;
|
||||
import com.songoda.epicfarming.player.PlayerActionManager;
|
||||
import com.songoda.epicfarming.player.PlayerData;
|
||||
import com.songoda.epicfarming.storage.Storage;
|
||||
import com.songoda.epicfarming.storage.StorageItem;
|
||||
import com.songoda.epicfarming.storage.StorageRow;
|
||||
import com.songoda.epicfarming.storage.types.StorageMysql;
|
||||
import com.songoda.epicfarming.storage.types.StorageYaml;
|
||||
@ -35,7 +30,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -48,11 +42,9 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Created by songoda on 1/23/2018.
|
||||
@ -61,9 +53,6 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
|
||||
private static EpicFarmingPlugin INSTANCE;
|
||||
|
||||
private List<ProtectionPluginHook> protectionHooks = new ArrayList<>();
|
||||
private ClaimableProtectionPluginHook factionsHook, townyHook, aSkyblockHook, uSkyblockHook;
|
||||
|
||||
private SettingsManager settingsManager;
|
||||
private References references;
|
||||
private ConfigWrapper hooksFile = new ConfigWrapper(this, "", "hooks.yml");
|
||||
@ -74,6 +63,7 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
private PlayerActionManager playerActionManager;
|
||||
private CommandManager commandManager;
|
||||
private BoostManager boostManager;
|
||||
private HookManager hookManager;
|
||||
|
||||
private GrowthTask growthTask;
|
||||
private FarmTask farmTask;
|
||||
@ -135,6 +125,7 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
this.playerActionManager = new PlayerActionManager();
|
||||
this.boostManager = new BoostManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.hookManager = new HookManager(this);
|
||||
|
||||
/*
|
||||
* Register Farms into FarmManger from configuration
|
||||
@ -183,17 +174,6 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
pluginManager.registerEvents(new InventoryListeners(this), this);
|
||||
|
||||
// Register default hooks
|
||||
if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new);
|
||||
if (pluginManager.isPluginEnabled("FactionsFramework")) 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);
|
||||
|
||||
// Start tasks
|
||||
this.growthTask = GrowthTask.startTask(this);
|
||||
HopperTask.startTask(this);
|
||||
@ -296,6 +276,7 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
public void reload() {
|
||||
locale.reloadMessages();
|
||||
references = new References();
|
||||
this.hookManager = new HookManager(this);
|
||||
this.setupConfig();
|
||||
saveConfig();
|
||||
}
|
||||
@ -364,41 +345,6 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
return locale;
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -453,6 +399,10 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming {
|
||||
return playerActionManager;
|
||||
}
|
||||
|
||||
public HookManager getHookManager() {
|
||||
return hookManager;
|
||||
}
|
||||
|
||||
public GrowthTask getGrowthTask() {
|
||||
return growthTask;
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ public class EFarm implements Farm {
|
||||
for (int fx = -radius; fx <= radius; fx++) {
|
||||
for (int fy = -2; fy <= 1; fy++) {
|
||||
for (int fz = -radius; fz <= radius; fz++) {
|
||||
if (!instance.canBuild(player, location)) continue;
|
||||
if (!instance.getHookManager().canBuild(player, location)) continue;
|
||||
Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
|
||||
|
||||
// ToDo: enum for all flowers.
|
||||
|
@ -0,0 +1,100 @@
|
||||
package com.songoda.epicfarming.hook;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.epicfarming.EpicFarmingPlugin;
|
||||
import com.songoda.epicfarming.hook.hooks.*;
|
||||
import com.songoda.epicfarming.utils.ConfigWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HookManager {
|
||||
|
||||
private final EpicFarmingPlugin plugin;
|
||||
|
||||
private ConfigWrapper hooksFile;
|
||||
private List<ProtectionPluginHook> registeredHooks = new ArrayList<>();
|
||||
|
||||
public HookManager(EpicFarmingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.hooksFile = new ConfigWrapper(plugin, "", "hooks.yml");
|
||||
this.hooksFile.createNewFile("Loading Hooks File", plugin.getDescription().getName() + " Hooks File");
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
// Register default hooks
|
||||
if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new);
|
||||
if (pluginManager.isPluginEnabled("FactionsFramework")) 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("SkyBlock")) this.register(HookSkyBlockEarth::new);
|
||||
if (pluginManager.isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new);
|
||||
}
|
||||
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
if (player.hasPermission(EpicFarmingPlugin.getInstance().getDescription().getName() + ".bypass")) return true;
|
||||
|
||||
for (ProtectionPluginHook hook : registeredHooks) {
|
||||
if (!hook.isInClaim(location)) continue;
|
||||
|
||||
if (!hook.canBuild(player, location)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isInClaim(HookType hookType, String name, Location l) {
|
||||
List<ProtectionPluginHook> hooks = registeredHooks.stream().filter(hook -> hook.getHookType() == hookType).collect(Collectors.toList());
|
||||
for (ProtectionPluginHook hook : hooks) {
|
||||
if (hook.isInClaim(l, name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getClaimId(HookType hookType, String name) {
|
||||
List<ProtectionPluginHook> hooks = registeredHooks.stream().filter(hook -> hook.getHookType() == hookType).collect(Collectors.toList());
|
||||
for (ProtectionPluginHook hook : hooks) {
|
||||
return hook.getClaimID(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private ProtectionPluginHook register(Supplier<ProtectionPluginHook> hookSupplier) {
|
||||
return this.registerProtectionHook(hookSupplier.get());
|
||||
}
|
||||
|
||||
public ProtectionPluginHook 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 : registeredHooks) {
|
||||
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 null;
|
||||
this.hooksFile.getConfig().options().copyDefaults(true);
|
||||
this.hooksFile.saveConfig();
|
||||
|
||||
this.registeredHooks.add(hook);
|
||||
plugin.getLogger().info("Registered protection hook for plugin: " + hook.getPlugin().getName());
|
||||
return hook;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.songoda.epicfarming.hook;
|
||||
|
||||
public enum HookType {
|
||||
|
||||
FACTION, TOWN, ISLAND, REGULAR
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.songoda.epicfarming.hook;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public interface ProtectionPluginHook {
|
||||
|
||||
JavaPlugin getPlugin();
|
||||
|
||||
HookType getHookType();
|
||||
|
||||
boolean canBuild(Player player, Location location);
|
||||
|
||||
default boolean canBuild(Player player, Block block) {
|
||||
return block != null && canBuild(player, block.getLocation());
|
||||
}
|
||||
|
||||
boolean isInClaim(Location location);
|
||||
|
||||
boolean isInClaim(Location location, String id);
|
||||
|
||||
String getClaimID(String name);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import com.wasteofplastic.askyblock.ASkyBlock;
|
||||
import com.wasteofplastic.askyblock.ASkyBlockAPI;
|
||||
import com.wasteofplastic.askyblock.Island;
|
||||
@ -12,7 +13,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HookASkyBlock implements ClaimableProtectionPluginHook {
|
||||
public class HookASkyBlock implements ProtectionPluginHook {
|
||||
|
||||
private final ASkyBlockAPI skyblock;
|
||||
|
||||
@ -25,6 +26,11 @@ public class HookASkyBlock implements ClaimableProtectionPluginHook {
|
||||
return ASkyBlock.getPlugin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.ISLAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
Island island = skyblock.getIslandAt(location);
|
||||
@ -47,6 +53,11 @@ public class HookASkyBlock implements ClaimableProtectionPluginHook {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return skyblock.getIslandAt(location) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return skyblock.getOwner(location).toString().equals(id);
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import me.markeh.factionsframework.FactionsFramework;
|
||||
import me.markeh.factionsframework.entities.FPlayer;
|
||||
import me.markeh.factionsframework.entities.FPlayers;
|
||||
@ -10,7 +11,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookFactions implements ClaimableProtectionPluginHook {
|
||||
public class HookFactions implements ProtectionPluginHook {
|
||||
|
||||
private final FactionsFramework factions;
|
||||
|
||||
@ -23,14 +24,24 @@ public class HookFactions implements ClaimableProtectionPluginHook {
|
||||
return factions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.FACTION;
|
||||
}
|
||||
|
||||
@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) {
|
||||
return !Factions.getFactionAt(location).isNone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return Factions.getFactionAt(location).getId().equals(id);
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
import org.bukkit.Location;
|
||||
@ -21,10 +22,30 @@ public class HookGriefPrevention implements ProtectionPluginHook {
|
||||
return griefPrevention;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@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;
|
||||
return claim != null && claim.allowBuild(player, Material.SPAWNER) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return griefPrevention.dataStore.getClaimAt(location, false, null) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -23,16 +24,39 @@ public class HookKingdoms implements ProtectionPluginHook {
|
||||
return kingdoms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk());
|
||||
Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation);
|
||||
String owner = land.getOwner();
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.api.PlotAPI;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -21,6 +22,11 @@ public class HookPlotSquared implements ProtectionPluginHook {
|
||||
return JavaPlugin.getPlugin(BukkitMain.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
|
||||
@ -34,4 +40,24 @@ public class HookPlotSquared implements ProtectionPluginHook {
|
||||
&& plot.getMembers().contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location plotLocation =
|
||||
new com.github.intellectualsites.plotsquared.plot.object.Location(location.getWorld().getName(),
|
||||
location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
Plot plot = plotLocation.getPlot();
|
||||
return plot != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.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 com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -21,12 +22,34 @@ public class HookRedProtect implements ProtectionPluginHook {
|
||||
return redProtect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
RedProtectAPI api = redProtect.getAPI();
|
||||
Region region = api.getRegion(location);
|
||||
|
||||
|
||||
return region != null && region.canBuild(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
RedProtectAPI api = redProtect.getAPI();
|
||||
Region region = api.getRegion(location);
|
||||
return region != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import me.goodandevil.skyblock.SkyBlock;
|
||||
import me.goodandevil.skyblock.island.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 HookSkyBlockEarth implements ProtectionPluginHook {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
|
||||
public HookSkyBlockEarth() {
|
||||
this.skyblock = SkyBlock.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return SkyBlock.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.ISLAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
Island island = skyblock.getIslandManager().getIslandAtLocation(location);
|
||||
if (island == null) return true;
|
||||
|
||||
UUID owner = island.getOwnerUUID();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (owner == null || owner.equals(playerUUID)) return true;
|
||||
|
||||
Set<UUID> teamMembers = island.getCoopPlayers();
|
||||
if (teamMembers.contains(playerUUID)) return true;
|
||||
|
||||
List<Island> coopIslands = skyblock.getIslandManager().getCoopIslands(player);
|
||||
for (Island is : coopIslands) {
|
||||
if (is.getOwnerUUID().equals(playerUUID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return skyblock.getIslandManager().getIslandAtLocation(location) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return skyblock.getIslandManager().getIslandAtLocation(location).getOwnerUUID().toString().equals(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.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 com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import com.songoda.epicspawners.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class HookTowny implements ClaimableProtectionPluginHook {
|
||||
public class HookTowny implements ProtectionPluginHook {
|
||||
|
||||
private final Towny towny;
|
||||
|
||||
@ -23,10 +24,16 @@ public class HookTowny implements ClaimableProtectionPluginHook {
|
||||
return towny;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.TOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
if (TownyUniverse.isWilderness(location.getBlock()) || !TownyUniverse.getTownBlock(location).hasTown()) return true;
|
||||
|
||||
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());
|
||||
@ -36,10 +43,15 @@ public class HookTowny implements ClaimableProtectionPluginHook {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return !TownyUniverse.isWilderness(location.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
try {
|
||||
return TownyUniverse.isWilderness(location.getBlock()) && TownyUniverse.getTownBlock(location).getTown().getUID().toString().equals(id);
|
||||
return (!TownyUniverse.isWilderness(location.getBlock())) && TownyUniverse.getTownBlock(location).getTown().getUID().toString().equals(id);
|
||||
} catch (NotRegisteredException e) {
|
||||
Debugger.runReport(e);
|
||||
return false;
|
@ -1,13 +1,14 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
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 {
|
||||
public class HookUSkyBlock implements ProtectionPluginHook {
|
||||
|
||||
private final uSkyBlockAPI uSkyblock;
|
||||
|
||||
@ -20,11 +21,21 @@ public class HookUSkyBlock implements ClaimableProtectionPluginHook {
|
||||
return (JavaPlugin) uSkyblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.ISLAND;
|
||||
}
|
||||
|
||||
@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) {
|
||||
return uSkyblock.getIslandInfo(location) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return uSkyblock.getIslandInfo(location).getLeader().equals(id);
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicfarming.hooks;
|
||||
package com.songoda.epicspawners.hook.hooks;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
@ -6,7 +6,8 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import com.songoda.epicfarming.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epicspawners.hook.HookType;
|
||||
import com.songoda.epicspawners.hook.ProtectionPluginHook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -24,6 +25,11 @@ public class HookWorldGuard implements ProtectionPluginHook {
|
||||
return WorldGuardPlugin.inst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HookType getHookType() {
|
||||
return HookType.REGULAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
RegionQuery q = worldGuard.getPlatform().getRegionContainer().createQuery();
|
||||
@ -31,4 +37,19 @@ public class HookWorldGuard implements ProtectionPluginHook {
|
||||
return ars.testState(WorldGuardPlugin.inst().wrapPlayer(player), Flags.BUILD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInClaim(Location location, String id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -84,7 +84,7 @@ public class BlockListeners implements Listener {
|
||||
|
||||
if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true);
|
||||
|
||||
if (!instance.canBuild(e.getPlayer(), e.getBlock().getLocation())) return;
|
||||
if (!instance.getHookManager().canBuild(e.getPlayer(), e.getBlock().getLocation())) return;
|
||||
|
||||
int amt = 0;
|
||||
for (Farm farmm : instance.getFarmManager().getFarms().values()) {
|
||||
@ -163,7 +163,7 @@ public class BlockListeners implements Listener {
|
||||
if (farm == null) return;
|
||||
|
||||
|
||||
if (!instance.canBuild(event.getPlayer(), event.getBlock().getLocation())) {
|
||||
if (!instance.getHookManager().canBuild(event.getPlayer(), event.getBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -27,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.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) {
|
||||
if (!instance.getHookManager().canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user