mirror of
https://github.com/songoda/EpicHoppers.git
synced 2025-02-13 10:21:30 +01:00
Hook handler updated to V3, this also includes a fix for towny.
This commit is contained in:
parent
eb46531fdc
commit
ae737e1264
@ -3,6 +3,7 @@ package com.songoda.epichoppers.api;
|
||||
import com.songoda.epichoppers.api.hopper.HopperManager;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.LevelManager;
|
||||
import com.songoda.epichoppers.api.utils.ProtectionPluginHook;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
@ -30,4 +31,13 @@ public interface EpicHoppers {
|
||||
* @return the hopper manager
|
||||
*/
|
||||
HopperManager getHopperManager();
|
||||
|
||||
/**
|
||||
* Register a new {@link ProtectionPluginHook} implementation
|
||||
* in order for EpicSpawners to support plugins that protect
|
||||
* blocks from being interacted with
|
||||
*
|
||||
* @param hook the hook to register
|
||||
*/
|
||||
void registerProtectionHook(ProtectionPluginHook hook);
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.songoda.epichoppers.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.epichoppers.api.utils;
|
||||
|
||||
import com.songoda.epichoppers.api.EpicHoppers;
|
||||
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 EpicHoppers#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());
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epichoppers;
|
||||
|
||||
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;
|
||||
@ -9,8 +10,11 @@ import com.songoda.epichoppers.api.hopper.Hopper;
|
||||
import com.songoda.epichoppers.api.hopper.HopperManager;
|
||||
import com.songoda.epichoppers.api.hopper.Level;
|
||||
import com.songoda.epichoppers.api.hopper.LevelManager;
|
||||
import com.songoda.epichoppers.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epichoppers.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epichoppers.events.*;
|
||||
import com.songoda.epichoppers.handlers.*;
|
||||
import com.songoda.epichoppers.hooks.*;
|
||||
import com.songoda.epichoppers.hopper.EFilter;
|
||||
import com.songoda.epichoppers.hopper.EHopper;
|
||||
import com.songoda.epichoppers.hopper.EHopperManager;
|
||||
@ -23,11 +27,13 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
@ -35,10 +41,13 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
|
||||
private static EpicHoppersPlugin INSTANCE;
|
||||
|
||||
public HookHandler hooks;
|
||||
private List<ProtectionPluginHook> protectionHooks = new ArrayList<>();
|
||||
private ClaimableProtectionPluginHook factionsHook, townyHook, aSkyblockHook, uSkyblockHook;
|
||||
|
||||
public SettingsManager settingsManager;
|
||||
|
||||
public References references = null;
|
||||
private ConfigWrapper hooksFile = new ConfigWrapper(this, "", "hooks.yml");
|
||||
public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
|
||||
|
||||
public EnchantmentHandler enchantmentHandler;
|
||||
@ -119,9 +128,6 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
|
||||
references = new References();
|
||||
|
||||
hooks = new HookHandler();
|
||||
hooks.hook();
|
||||
|
||||
new HopHandler(this);
|
||||
teleportHandler = new TeleportHandler(this);
|
||||
|
||||
@ -136,7 +142,19 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
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 LoginListeners(this), this);
|
||||
|
||||
|
||||
|
||||
// Register default hooks
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Factions")) this.register(HookFactions::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("GriefPrevention")) this.register(HookGriefPrevention::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Kingdoms")) this.register(HookKingdoms::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlotSquared")) this.register(HookPlotSquared::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("RedProtect")) this.register(HookRedProtect::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) this.register(HookTowny::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("USkyBlock")) this.register(HookUSkyBlock::new);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new);
|
||||
|
||||
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
@ -144,6 +162,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
|
||||
public void onDisable() {
|
||||
saveToFile();
|
||||
this.protectionHooks.clear();
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
|
||||
@ -246,9 +265,6 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
|
||||
public void reload() {
|
||||
locale.reloadMessages();
|
||||
hooks.hooksFile.createNewFile("Loading hooks File", "EpicSpawners Spawners File");
|
||||
hooks = new HookHandler();
|
||||
hooks.hook();
|
||||
references = new References();
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
@ -256,6 +272,39 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean isInFaction(String name, Location l) {
|
||||
return factionsHook != null && factionsHook.isInClaim(l, name);
|
||||
}
|
||||
|
||||
public String getFactionId(String name) {
|
||||
return (factionsHook != null) ? factionsHook.getClaimID(name) : null;
|
||||
}
|
||||
|
||||
public boolean isInTown(String name, Location l) {
|
||||
return townyHook != null && townyHook.isInClaim(l, name);
|
||||
}
|
||||
|
||||
public String getTownId(String name) {
|
||||
return (townyHook != null) ? townyHook.getClaimID(name) : null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public String getIslandId(String name) {
|
||||
return Bukkit.getOfflinePlayer(name).getUniqueId().toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Level getLevelFromItem(ItemStack item) {
|
||||
if (item.getItemMeta().getDisplayName().contains(":")) {
|
||||
@ -300,4 +349,30 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers {
|
||||
public static EpicHoppersPlugin getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class InteractListeners implements Listener {
|
||||
|| e.getClickedBlock() == null
|
||||
|| player.isSneaking()
|
||||
|| !player.hasPermission("EpicHoppers.overview")
|
||||
|| !instance.hooks.canBuild(player, e.getClickedBlock().getLocation())
|
||||
|| !instance.canBuild(player, e.getClickedBlock().getLocation())
|
||||
|| !(e.getClickedBlock().getState() instanceof InventoryHolder || e.getClickedBlock().getType().equals(Material.ENDER_CHEST))) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,45 +0,0 @@
|
||||
package com.songoda.epichoppers.events;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/14/2017.
|
||||
*/
|
||||
public class LoginListeners implements Listener {
|
||||
|
||||
private EpicHoppersPlugin instance;
|
||||
|
||||
public LoginListeners(EpicHoppersPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
try {
|
||||
Player p = e.getPlayer();
|
||||
if (p.isOp() && instance.getConfig().getBoolean("Main.Display Helpful Tips For Operators")) {
|
||||
if (instance.getServer().getPluginManager().getPlugin("Factions") != null && instance.hooks.FactionsHook == null) {
|
||||
p.sendMessage("");
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7Here's the deal,"));
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Because you're not using the official versions of &6Factions"));
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7I cannot give you full support out of the box."));
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7Things will work without it but if you wan't a flawless"));
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7experience you need to download"));
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7&6https://www.spigotmc.org/resources/54337/&7."));
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7If you don't care and don't want to see this message again"));
|
||||
p.sendMessage(Arconix.pl().getApi().format().formatText("&7turn &6Helpful-Tips &7off in the config."));
|
||||
p.sendMessage("");
|
||||
}
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
Debugger.runReport(ee);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
package com.songoda.epichoppers.handlers;
|
||||
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.hooks.*;
|
||||
import com.songoda.epichoppers.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(EpicHoppersPlugin.getInstance(), "", "hooks.yml");
|
||||
|
||||
public HookHandler() {
|
||||
}
|
||||
|
||||
public void hook() {
|
||||
try {
|
||||
hooksFile.createNewFile("Loading hooks File", EpicHoppersPlugin.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.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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();
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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");
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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 ignore) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.songoda.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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 {
|
||||
|
||||
public GriefPreventionHook() {
|
||||
super("GriefPrevention");
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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,38 +0,0 @@
|
||||
package com.songoda.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Hook {
|
||||
|
||||
final String pluginName;
|
||||
|
||||
protected Hook(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
if (isEnabled())
|
||||
EpicHoppersPlugin.getInstance().hooks.hooksFile.getConfig().addDefault("hooks." + pluginName, true);
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
return (Bukkit.getPluginManager().isPluginEnabled(pluginName)
|
||||
&& EpicHoppersPlugin.getInstance().hooks.hooksFile.getConfig().getBoolean("hooks." + pluginName, true));
|
||||
}
|
||||
|
||||
boolean hasBypass(Player p) {
|
||||
return p.hasPermission(EpicHoppersPlugin.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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.songoda.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.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.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.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.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.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.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.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.epichoppers.hooks;
|
||||
|
||||
import com.intellectualcrafters.plot.api.PlotAPI;
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.songoda.epichoppers.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.epichoppers.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.epichoppers.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.epichoppers.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.epichoppers.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epichoppers.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.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.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.epichoppers.hooks;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.songoda.epichoppers.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,43 +0,0 @@
|
||||
package com.songoda.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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");
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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,37 +0,0 @@
|
||||
package com.songoda.epichoppers.hooks;
|
||||
|
||||
import com.intellectualcrafters.plot.api.PlotAPI;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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()) {
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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,33 +0,0 @@
|
||||
package com.songoda.epichoppers.hooks;
|
||||
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class RedProtectHook extends Hook {
|
||||
|
||||
public RedProtectHook() {
|
||||
super("RedProtect");
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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.epichoppers.hooks;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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");
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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.epichoppers.hooks;
|
||||
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.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;
|
||||
|
||||
public USkyBlockHook() {
|
||||
super("USkyBlock");
|
||||
if (isEnabled()) {
|
||||
EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
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.epichoppers.hooks;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.songoda.epichoppers.EpicHoppersPlugin;
|
||||
import com.songoda.epichoppers.utils.Debugger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by songoda on 3/17/2017.
|
||||
*/
|
||||
public class WorldGuardHook extends Hook {
|
||||
|
||||
private EpicHoppersPlugin plugin = EpicHoppersPlugin.getInstance();
|
||||
|
||||
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