mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-10-31 23:59:35 +01:00
HookHandler.
Redid the look of the anchor item titles. added customizable lore for anchors.
This commit is contained in:
parent
04912463e4
commit
c76370af43
@ -1,10 +1,13 @@
|
||||
package com.songoda.epicanchors.api;
|
||||
|
||||
import com.songoda.epicanchors.api.anchor.AnchorManager;
|
||||
import com.songoda.epicanchors.api.utils.ProtectionPluginHook;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface EpicAnchors {
|
||||
|
||||
void registerProtectionHook(ProtectionPluginHook hook);
|
||||
|
||||
int getTicksFromItem(ItemStack item);
|
||||
|
||||
ItemStack makeAnchorItem(int ticks);
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.songoda.epicanchors.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.epicanchors.api.utils;
|
||||
|
||||
import com.songoda.epicanchors.api.EpicAnchors;
|
||||
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 EpicAnchors#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.epicanchors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.arconix.api.methods.formatting.TextComponent;
|
||||
import com.songoda.arconix.api.utils.ConfigWrapper;
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
@ -8,12 +9,15 @@ import com.songoda.epicanchors.anchor.EAnchorManager;
|
||||
import com.songoda.epicanchors.api.EpicAnchors;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import com.songoda.epicanchors.api.anchor.AnchorManager;
|
||||
import com.songoda.epicanchors.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epicanchors.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epicanchors.command.CommandManager;
|
||||
import com.songoda.epicanchors.events.BlockListeners;
|
||||
import com.songoda.epicanchors.events.InteractListeners;
|
||||
import com.songoda.epicanchors.events.InventoryListeners;
|
||||
import com.songoda.epicanchors.handlers.AnchorHandler;
|
||||
import com.songoda.epicanchors.handlers.MenuHandler;
|
||||
import com.songoda.epicanchors.hooks.*;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import com.songoda.epicanchors.utils.SettingsManager;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
@ -22,14 +26,25 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
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.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
|
||||
public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
|
||||
|
||||
private List<ProtectionPluginHook> protectionHooks = new ArrayList<>();
|
||||
private ClaimableProtectionPluginHook factionsHook, townyHook, aSkyblockHook, uSkyblockHook;
|
||||
|
||||
private ConfigWrapper hooksFile = new ConfigWrapper(this, "", "hooks.yml");
|
||||
|
||||
private static EpicAnchorsPlugin INSTANCE;
|
||||
|
||||
private SettingsManager settingsManager;
|
||||
@ -92,11 +107,23 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
// Command registration
|
||||
this.getCommand("EpicAnchors").setExecutor(new CommandManager(this));
|
||||
|
||||
// Event registration
|
||||
getServer().getPluginManager().registerEvents(new BlockListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InteractListeners(this), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListeners(this), this);
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
// Event registration
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
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);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
console.sendMessage(TextComponent.formatText("&a============================="));
|
||||
@ -149,6 +176,43 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
//this.saveConfig();
|
||||
}
|
||||
|
||||
|
||||
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 getTicksFromItem(ItemStack item) {
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0;
|
||||
@ -163,6 +227,12 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
ItemStack item = new ItemStack(Material.valueOf(EpicAnchorsPlugin.getInstance().getConfig().getString("Main.Anchor Block Material")), 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(ticks, true)));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
String[] parts = getConfig().getString("Main.Anchor-Lore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lore.add(Arconix.pl().getApi().format().formatText(line));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
@ -31,6 +31,11 @@ public class InteractListeners implements Listener {
|
||||
|
||||
if (instance.getAnchorManager().getAnchor(e.getClickedBlock().getLocation()) == null) return;
|
||||
|
||||
if (!instance.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Anchor anchor = instance.getAnchorManager().getAnchor(e.getClickedBlock().getLocation());
|
||||
|
||||
Player player = e.getPlayer();
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.songoda.epicanchors.hooks;
|
||||
|
||||
import com.songoda.epicanchors.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.epicanchors.hooks;
|
||||
|
||||
import com.songoda.epicanchors.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.epicanchors.hooks;
|
||||
|
||||
import com.songoda.epicanchors.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.epicanchors.hooks;
|
||||
|
||||
import com.songoda.epicanchors.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.epicanchors.hooks;
|
||||
|
||||
import com.intellectualcrafters.plot.api.PlotAPI;
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.songoda.epicanchors.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.epicanchors.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.epicanchors.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,56 @@
|
||||
package com.songoda.epicanchors.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.epicanchors.api.utils.ClaimableProtectionPluginHook;
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClaimID(String name) {
|
||||
try {
|
||||
return TownyUniverse.getDataSource().getTown(name).getUID().toString();
|
||||
} catch (NotRegisteredException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.songoda.epicanchors.hooks;
|
||||
|
||||
import com.songoda.epicanchors.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,34 @@
|
||||
package com.songoda.epicanchors.hooks;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
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.epicanchors.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 WorldGuard worldGuard;
|
||||
|
||||
public HookWorldGuard() {
|
||||
this.worldGuard = WorldGuard.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
return WorldGuardPlugin.inst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
RegionQuery q = worldGuard.getPlatform().getRegionContainer().createQuery();
|
||||
ApplicableRegionSet ars = q.getApplicableRegions(BukkitAdapter.adapt(player.getLocation()));
|
||||
return ars.testState(WorldGuardPlugin.inst().wrapPlayer(player), Flags.BUILD);
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package com.songoda.epicanchors.utils;
|
||||
|
||||
import com.songoda.arconix.plugin.Arconix;
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.api.EpicAnchors;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -38,11 +39,13 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static String formatName(int ticks2, boolean full) {
|
||||
int ticks = (((ticks2 / 20) / 60) / 60);
|
||||
String hours = "Hours";
|
||||
if (ticks == 1) hours = "Hour";
|
||||
int hours = ((ticks2 / 20) / 60) / 60;
|
||||
int minutes = ((ticks2 / 20) / 60) - hours * 60;
|
||||
|
||||
String name = "&eAnchor &8(&7" + ticks + " " + hours + "&8)";
|
||||
String remaining = minutes == 0 ? String.format("%sh", hours) : String.format("%sh %sm", hours, minutes);
|
||||
|
||||
|
||||
String name = EpicAnchorsPlugin.getInstance().getConfig().getString("Main.Name-Tag").replace("{REMAINING}", remaining);
|
||||
|
||||
String info = "";
|
||||
if (full) {
|
||||
|
@ -22,17 +22,19 @@ public class SettingsManager implements Listener {
|
||||
}
|
||||
|
||||
public enum settings {
|
||||
o1("Main.Anchor Block Material", "END_PORTAL_FRAME"),
|
||||
o2("Main.Add Time With Economy", true),
|
||||
o3("Main.Economy Cost", 5000.0),
|
||||
o4("Main.Add Time With XP", true),
|
||||
o5("Main.XP Cost", 10),
|
||||
o6("Main.Allow Anchor Breaking", false),
|
||||
o7("Interfaces.Economy Icon", "SUNFLOWER"),
|
||||
o8("Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
|
||||
o9("Interfaces.Glass Type 1", 7),
|
||||
o10("Interfaces.Glass Type 2", 11),
|
||||
o11("Interfaces.Glass Type 3", 3);
|
||||
o1("Main.Name-Tag", "&eAnchor &8(&7{REMAINING}&8)"),
|
||||
o2("Main.Anchor-Lore", "&7Place down to keep that chunk|&7loaded until the time runs out."),
|
||||
o3("Main.Anchor Block Material", "END_PORTAL_FRAME"),
|
||||
o4("Main.Add Time With Economy", true),
|
||||
o5("Main.Economy Cost", 5000.0),
|
||||
o6("Main.Add Time With XP", true),
|
||||
o7("Main.XP Cost", 10),
|
||||
o8("Main.Allow Anchor Breaking", false),
|
||||
o9("Interfaces.Economy Icon", "SUNFLOWER"),
|
||||
o10("Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
|
||||
o11("Interfaces.Glass Type 1", 7),
|
||||
o12("Interfaces.Glass Type 2", 11),
|
||||
o13("Interfaces.Glass Type 3", 3);
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
|
Loading…
Reference in New Issue
Block a user