mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-10-31 23:59:35 +01:00
Merge branch 'development'
This commit is contained in:
commit
b19e40f08a
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicAnchors"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "1.2.8"
|
||||
version: "1.4.2"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -1,16 +0,0 @@
|
||||
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);
|
||||
|
||||
AnchorManager getAnchorManager();
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.songoda.epicanchors.api;
|
||||
|
||||
|
||||
/**
|
||||
* The access point of the EpicAnchorsAPI, a class acting as a bridge between API
|
||||
* and plugin implementation. It is from here where developers should access the
|
||||
* important and core methods in the API. All static methods in this class will
|
||||
* call directly upon the implementation at hand (in most cases this will be the
|
||||
* EpicAnchors plugin itself), therefore a call to {@link #getImplementation()} is
|
||||
* not required and redundant in most situations. Method calls from this class are
|
||||
* preferred the majority of time, though an instance of {@link EpicAnchors} may
|
||||
* be passed if absolutely necessary.
|
||||
*
|
||||
* @see EpicAnchors
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class EpicAnchorsAPI {
|
||||
|
||||
private static EpicAnchors implementation;
|
||||
|
||||
/**
|
||||
* Set the EpicAnchors implementation. Once called for the first time, this
|
||||
* method will throw an exception on any subsequent invocations. The implementation
|
||||
* may only be set a single time, presumably by the EpicAnchors plugin
|
||||
*
|
||||
* @param implementation the implementation to set
|
||||
*/
|
||||
public static void setImplementation(EpicAnchors implementation) {
|
||||
if (EpicAnchorsAPI.implementation != null) {
|
||||
throw new IllegalArgumentException("Cannot set API implementation twice");
|
||||
}
|
||||
|
||||
EpicAnchorsAPI.implementation = implementation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the EpicAnchors implementation. This method may be redundant in most
|
||||
* situations as all methods present in {@link EpicAnchors} will be mirrored
|
||||
* with static modifiers in the {@link EpicAnchorsAPI} class
|
||||
*
|
||||
* @return the EpicAnchors implementation
|
||||
*/
|
||||
public static EpicAnchors getImplementation() {
|
||||
return implementation;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.songoda.epicanchors.api.anchor;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface Anchor {
|
||||
|
||||
Location getLocation();
|
||||
|
||||
int getTicksLeft();
|
||||
|
||||
void setTicksLeft(int ticksLeft);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.songoda.epicanchors.api.anchor;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface AnchorManager {
|
||||
Anchor addAnchor(Location location, Anchor anchor);
|
||||
|
||||
void removeAnchor(Location location);
|
||||
|
||||
Anchor getAnchor(Location location);
|
||||
|
||||
boolean isAnchor(Location location);
|
||||
|
||||
Map<Location, Anchor> getAnchors();
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
String getClaimID(String name);
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
default boolean canBuild(Player player, Block block) {
|
||||
return block != null && canBuild(player, block.getLocation());
|
||||
}
|
||||
|
||||
}
|
@ -1,300 +0,0 @@
|
||||
package com.songoda.epicanchors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
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.handlers.AnchorHandler;
|
||||
import com.songoda.epicanchors.hooks.HookASkyBlock;
|
||||
import com.songoda.epicanchors.hooks.HookFactions;
|
||||
import com.songoda.epicanchors.hooks.HookGriefPrevention;
|
||||
import com.songoda.epicanchors.hooks.HookKingdoms;
|
||||
import com.songoda.epicanchors.hooks.HookPlotSquared;
|
||||
import com.songoda.epicanchors.hooks.HookRedProtect;
|
||||
import com.songoda.epicanchors.hooks.HookTowny;
|
||||
import com.songoda.epicanchors.hooks.HookUSkyBlock;
|
||||
import com.songoda.epicanchors.hooks.HookWorldGuard;
|
||||
import com.songoda.epicanchors.listeners.BlockListeners;
|
||||
import com.songoda.epicanchors.listeners.InteractListeners;
|
||||
import com.songoda.epicanchors.utils.ConfigWrapper;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import com.songoda.epicanchors.utils.Metrics;
|
||||
import com.songoda.epicanchors.utils.ServerVersion;
|
||||
import com.songoda.epicanchors.utils.SettingsManager;
|
||||
import com.songoda.epicanchors.utils.updateModules.LocaleModule;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
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 ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
||||
|
||||
private static EpicAnchorsPlugin INSTANCE;
|
||||
|
||||
private SettingsManager settingsManager;
|
||||
private EAnchorManager anchorManager;
|
||||
|
||||
private CommandManager commandManager;
|
||||
|
||||
private References references;
|
||||
|
||||
private Locale locale;
|
||||
|
||||
public static EpicAnchorsPlugin getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
CommandSender console = Bukkit.getConsoleSender();
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7EpicAnchors " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||
|
||||
this.settingsManager = new SettingsManager(this);
|
||||
|
||||
setupConfig();
|
||||
|
||||
// Locales
|
||||
String langMode = SettingsManager.Setting.LANGUGE_MODE.getString();
|
||||
Locale.init(this);
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
this.locale = Locale.getLocale(langMode);
|
||||
|
||||
//Running Songoda Updater
|
||||
Plugin plugin = new Plugin(this, 31);
|
||||
plugin.addModule(new LocaleModule());
|
||||
SongodaUpdate.load(plugin);
|
||||
|
||||
dataFile.createNewFile("Loading Data File", "EpicAnchors Data File");
|
||||
|
||||
this.references = new References();
|
||||
this.anchorManager = new EAnchorManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, this::loadAnchorsFromFile, 5L);
|
||||
|
||||
new AnchorHandler(this);
|
||||
|
||||
// Command registration
|
||||
this.getCommand("EpicAnchors").setExecutor(new CommandManager(this));
|
||||
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
// Event registration
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(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 Metrics
|
||||
new Metrics(this);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000);
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
saveToFile();
|
||||
CommandSender console = Bukkit.getConsoleSender();
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7EpicAnchors " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
settingsManager.updateSettings();
|
||||
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void loadAnchorsFromFile() {
|
||||
if (dataFile.getConfig().contains("Anchors")) {
|
||||
for (String locationStr : dataFile.getConfig().getConfigurationSection("Anchors").getKeys(false)) {
|
||||
Location location = Methods.unserializeLocation(locationStr);
|
||||
int ticksLeft = dataFile.getConfig().getInt("Anchors." + locationStr + ".ticksLeft");
|
||||
|
||||
EAnchor anchor = new EAnchor(location, ticksLeft);
|
||||
|
||||
anchorManager.addAnchor(location, anchor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToFile() {
|
||||
dataFile.getConfig().set("Anchors", null);
|
||||
for (Anchor anchor : anchorManager.getAnchors().values()) {
|
||||
String locationStr = Methods.serializeLocation(anchor.getLocation());
|
||||
dataFile.getConfig().set("Anchors." + locationStr + ".ticksLeft", anchor.getTicksLeft());
|
||||
}
|
||||
dataFile.saveConfig();
|
||||
}
|
||||
|
||||
|
||||
public void reload() {
|
||||
this.locale.reloadMessages();
|
||||
this.references = new References();
|
||||
this.loadAnchorsFromFile();
|
||||
this.reloadConfig();
|
||||
this.setupConfig();
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
if (item.getItemMeta().getDisplayName().contains(":")) {
|
||||
return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack makeAnchorItem(int ticks) {
|
||||
ItemStack item = new ItemStack(Material.valueOf(EpicAnchorsPlugin.getInstance().getConfig().getString("Main.Anchor Block Material")), 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText(Methods.formatName(ticks, true)));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
String[] parts = getConfig().getString("Main.Anchor-Lore").split("\\|");
|
||||
for (String line : parts) {
|
||||
lore.add(Methods.formatText(line));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void bust(Location location) {
|
||||
if (!getAnchorManager().isAnchor(location)) return;
|
||||
|
||||
Anchor anchor = getAnchorManager().getAnchor(location);
|
||||
|
||||
if (getConfig().getBoolean("Main.Allow Anchor Breaking")) {
|
||||
ItemStack item = makeAnchorItem(anchor.getTicksLeft());
|
||||
anchor.getLocation().getWorld().dropItemNaturally(anchor.getLocation(), item);
|
||||
}
|
||||
location.getBlock().setType(Material.AIR);
|
||||
|
||||
if (isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
location.getWorld().spawnParticle(Particle.LAVA, location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
||||
|
||||
location.getWorld().playSound(location, this.isServerVersionAtLeast(ServerVersion.V1_9)
|
||||
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE"), 10, 10);
|
||||
|
||||
getAnchorManager().removeAnchor(location);
|
||||
}
|
||||
|
||||
public ServerVersion getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
|
||||
public boolean isServerVersion(ServerVersion version) {
|
||||
return serverVersion == version;
|
||||
}
|
||||
|
||||
public boolean isServerVersion(ServerVersion... versions) {
|
||||
return ArrayUtils.contains(versions, serverVersion);
|
||||
}
|
||||
|
||||
public boolean isServerVersionAtLeast(ServerVersion version) {
|
||||
return serverVersion.ordinal() >= version.ordinal();
|
||||
}
|
||||
|
||||
public SettingsManager getSettingsManager() {
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnchorManager getAnchorManager() {
|
||||
return anchorManager;
|
||||
}
|
||||
|
||||
public References getReferences() {
|
||||
return references;
|
||||
}
|
||||
}
|
@ -1,384 +0,0 @@
|
||||
package com.songoda.epicanchors;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Assists in the creation of multiple localizations and languages,
|
||||
* as well as the generation of default .lang files
|
||||
*
|
||||
* @author Parker Hawke - 2008Choco
|
||||
*/
|
||||
public class Locale {
|
||||
|
||||
private static final List<Locale> LOCALES = Lists.newArrayList();
|
||||
private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\"");
|
||||
private static final String FILE_EXTENSION = ".lang";
|
||||
private static JavaPlugin plugin;
|
||||
private static File localeFolder;
|
||||
|
||||
private static String defaultLocale;
|
||||
|
||||
private final Map<String, String> nodes = new HashMap<>();
|
||||
|
||||
private final File file;
|
||||
private final String name, region;
|
||||
|
||||
private Locale(String name, String region) {
|
||||
if (plugin == null)
|
||||
throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))");
|
||||
|
||||
this.name = name.toLowerCase();
|
||||
this.region = region.toUpperCase();
|
||||
|
||||
String fileName = name + "_" + region + FILE_EXTENSION;
|
||||
this.file = new File(localeFolder, fileName);
|
||||
|
||||
if (this.reloadMessages()) return;
|
||||
|
||||
plugin.getLogger().info("Loaded locale " + fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the locale class to generate information and search for localizations.
|
||||
* This must be called before any other methods in the Locale class can be invoked.
|
||||
* Note that this will also call {@link #searchForLocales()}, so there is no need to
|
||||
* invoke it for yourself after the initialization
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public static void init(JavaPlugin plugin) {
|
||||
Locale.plugin = plugin;
|
||||
|
||||
if (localeFolder == null) {
|
||||
localeFolder = new File(plugin.getDataFolder(), "locales/");
|
||||
}
|
||||
|
||||
localeFolder.mkdirs();
|
||||
Locale.searchForLocales();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all .lang file locales under the "locales" folder
|
||||
*/
|
||||
public static void searchForLocales() {
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
for (File file : localeFolder.listFiles()) {
|
||||
String name = file.getName();
|
||||
if (!name.endsWith(".lang")) continue;
|
||||
|
||||
String fileName = name.substring(0, name.lastIndexOf('.'));
|
||||
String[] localeValues = fileName.split("_");
|
||||
|
||||
if (localeValues.length != 2) continue;
|
||||
if (localeExists(localeValues[0] + "_" + localeValues[1])) continue;
|
||||
|
||||
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
|
||||
plugin.getLogger().info("Found and loaded locale \"" + fileName + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a locale by its entire proper name (i.e. "en_US")
|
||||
*
|
||||
* @param name the full name of the locale
|
||||
* @return locale of the specified name
|
||||
*/
|
||||
public static Locale getLocale(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getLanguageTag().equalsIgnoreCase(name)) return locale;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a locale from the cache by its name (i.e. "en" from "en_US")
|
||||
*
|
||||
* @param name the name of the language
|
||||
* @return locale of the specified language. Null if not cached
|
||||
*/
|
||||
public static Locale getLocaleByName(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getName().equalsIgnoreCase(name)) return locale;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a locale from the cache by its region (i.e. "US" from "en_US")
|
||||
*
|
||||
* @param region the name of the region
|
||||
* @return locale of the specified region. Null if not cached
|
||||
*/
|
||||
public static Locale getLocaleByRegion(String region) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getRegion().equalsIgnoreCase(region)) return locale;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a locale exists and is registered or not
|
||||
*
|
||||
* @param name the whole language tag (i.e. "en_US")
|
||||
* @return true if it exists
|
||||
*/
|
||||
public static boolean localeExists(String name) {
|
||||
for (Locale locale : LOCALES)
|
||||
if (locale.getLanguageTag().equals(name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an immutable list of all currently loaded locales
|
||||
*
|
||||
* @return list of all locales
|
||||
*/
|
||||
public static List<Locale> getLocales() {
|
||||
return ImmutableList.copyOf(LOCALES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a default locale file from the project source directory, to the locale folder
|
||||
*
|
||||
* @param in file to save
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveDefaultLocale(InputStream in, String fileName) {
|
||||
if (!localeFolder.exists()) localeFolder.mkdirs();
|
||||
|
||||
if (!fileName.endsWith(FILE_EXTENSION))
|
||||
fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION;
|
||||
|
||||
File destinationFile = new File(localeFolder, fileName);
|
||||
if (destinationFile.exists()) {
|
||||
return compareFiles(plugin.getResource(fileName), destinationFile);
|
||||
}
|
||||
|
||||
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
|
||||
copy(in == null ? plugin.getResource(fileName) : in, outputStream);
|
||||
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
String[] localeValues = fileName.split("_");
|
||||
|
||||
if (localeValues.length != 2) return false;
|
||||
|
||||
LOCALES.add(new Locale(localeValues[0], localeValues[1]));
|
||||
if (defaultLocale == null) defaultLocale = fileName;
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a default locale file from the project source directory, to the locale folder
|
||||
*
|
||||
* @param fileName the name of the file to save
|
||||
* @return true if the operation was successful, false otherwise
|
||||
*/
|
||||
public static boolean saveDefaultLocale(String fileName) {
|
||||
return saveDefaultLocale(null, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all current locale data
|
||||
*/
|
||||
public static void clearLocaleData() {
|
||||
for (Locale locale : LOCALES)
|
||||
locale.nodes.clear();
|
||||
LOCALES.clear();
|
||||
}
|
||||
|
||||
// Write new changes to existing files, if any at all
|
||||
private static boolean compareFiles(InputStream defaultFile, File existingFile) {
|
||||
// Look for default
|
||||
if (defaultFile == null) {
|
||||
defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US");
|
||||
if (defaultFile == null) return false; // No default at all
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
List<String> defaultLines, existingLines;
|
||||
try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile));
|
||||
BufferedReader existingReader = new BufferedReader(new FileReader(existingFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) {
|
||||
defaultLines = defaultReader.lines().collect(Collectors.toList());
|
||||
existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList());
|
||||
|
||||
for (String defaultValue : defaultLines) {
|
||||
if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue;
|
||||
|
||||
String key = defaultValue.split("\\s*=")[0];
|
||||
|
||||
if (!existingLines.contains(key)) {
|
||||
if (!changed) {
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
writer.newLine();
|
||||
writer.write(defaultValue);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static void copy(InputStream input, OutputStream output) {
|
||||
int n;
|
||||
byte[] buffer = new byte[1024 * 4];
|
||||
|
||||
try {
|
||||
while ((n = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, n);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the language that this locale is based on.
|
||||
* (i.e. "en" for English, or "fr" for French)
|
||||
*
|
||||
* @return the name of the language
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the region that this locale is from.
|
||||
* (i.e. "US" for United States or "CA" for Canada)
|
||||
*
|
||||
* @return the name of the region
|
||||
*/
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entire locale tag (i.e. "en_US")
|
||||
*
|
||||
* @return the language tag
|
||||
*/
|
||||
public String getLanguageTag() {
|
||||
return name + "_" + region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file that represents this locale
|
||||
*
|
||||
* @return the locale file (.lang)
|
||||
*/
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node
|
||||
*
|
||||
* @param node the node to get
|
||||
* @return the message for the specified node
|
||||
*/
|
||||
public String getMessage(String node) {
|
||||
return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node and replace its params with a supplied arguments.
|
||||
*
|
||||
* @param node the node to get
|
||||
* @param args the replacement arguments
|
||||
* @return the message for the specified node
|
||||
*/
|
||||
public String getMessage(String node, Object... args) {
|
||||
String message = getMessage(node);
|
||||
for (Object arg : args) {
|
||||
message = message.replaceFirst("\\%.*?\\%", arg.toString());
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message set for a specific node
|
||||
*
|
||||
* @param node the node to get
|
||||
* @param defaultValue the default value given that a value for the node was not found
|
||||
* @return the message for the specified node. Default if none found
|
||||
*/
|
||||
public String getMessageOrDefault(String node, String defaultValue) {
|
||||
return this.nodes.getOrDefault(node, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key-value map of nodes to messages
|
||||
*
|
||||
* @return node-message map
|
||||
*/
|
||||
public Map<String, String> getMessageNodeMap() {
|
||||
return ImmutableMap.copyOf(nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the previous message cache and load new messages directly from file
|
||||
*
|
||||
* @return reload messages from file
|
||||
*/
|
||||
public boolean reloadMessages() {
|
||||
if (!this.file.exists()) {
|
||||
plugin.getLogger().warning("Could not find file for locale " + this.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.nodes.clear(); // Clear previous data (if any)
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
|
||||
if (line.isEmpty() || line.startsWith("#") /* Comment */) continue;
|
||||
|
||||
Matcher matcher = NODE_PATTERN.matcher(line);
|
||||
if (!matcher.find()) {
|
||||
System.err.println("Invalid locale syntax at (line=" + lineNumber + ")");
|
||||
continue;
|
||||
}
|
||||
|
||||
nodes.put(matcher.group(1), matcher.group(2));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.songoda.epicanchors;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public References() {
|
||||
prefix = EpicAnchorsPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
package com.songoda.epicanchors.anchor;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import com.songoda.epicanchors.gui.GUIOverview;
|
||||
import com.songoda.epicanchors.utils.ServerVersion;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class EAnchor implements Anchor {
|
||||
|
||||
private Location location;
|
||||
private int ticksLeft;
|
||||
|
||||
public EAnchor(Location location, int ticksLeft) {
|
||||
this.location = location;
|
||||
this.ticksLeft = ticksLeft;
|
||||
}
|
||||
|
||||
public void overview(Player player) {
|
||||
new GUIOverview(EpicAnchorsPlugin.getInstance(), this, player);
|
||||
}
|
||||
|
||||
public void addTime(String type, Player player) {
|
||||
EpicAnchorsPlugin instance = EpicAnchorsPlugin.getInstance();
|
||||
|
||||
if (type.equals("ECO")) {
|
||||
if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
|
||||
double cost = instance.getConfig().getDouble("Main.Economy Cost");
|
||||
if (econ.has(player, cost)) {
|
||||
econ.withdrawPlayer(player, cost);
|
||||
} else {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("Vault is not installed.");
|
||||
return;
|
||||
}
|
||||
} else if (type.equals("XP")) {
|
||||
int cost = instance.getConfig().getInt("Main.XP Cost");
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(instance.getLocale().getMessage("event.upgrade.cannotafford"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ticksLeft = ticksLeft + 20 * 60 * 30;
|
||||
Sound sound = EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP");
|
||||
player.playSound(player.getLocation(), sound, 0.6F, 15.0F);
|
||||
|
||||
if (EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
player.getWorld().spawnParticle(Particle.SPELL_WITCH, getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksLeft() {
|
||||
return ticksLeft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTicksLeft(int ticksLeft) {
|
||||
this.ticksLeft = ticksLeft;
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package com.songoda.epicanchors.command;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
|
||||
|
||||
private final AbstractCommand parent;
|
||||
|
||||
private final String command;
|
||||
|
||||
private final boolean noConsole;
|
||||
|
||||
protected AbstractCommand(String command, AbstractCommand parent, boolean noConsole) {
|
||||
this.command = command;
|
||||
this.parent = parent;
|
||||
this.noConsole = noConsole;
|
||||
}
|
||||
|
||||
public AbstractCommand getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public boolean isNoConsole() {
|
||||
return noConsole;
|
||||
}
|
||||
|
||||
protected abstract ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package com.songoda.epicanchors.command;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.command.commands.CommandEpicAnchors;
|
||||
import com.songoda.epicanchors.command.commands.CommandGive;
|
||||
import com.songoda.epicanchors.command.commands.CommandReload;
|
||||
import com.songoda.epicanchors.command.commands.CommandSettings;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager implements CommandExecutor {
|
||||
|
||||
private EpicAnchorsPlugin instance;
|
||||
|
||||
private List<AbstractCommand> commands = new ArrayList<>();
|
||||
|
||||
public CommandManager(EpicAnchorsPlugin instance) {
|
||||
this.instance = instance;
|
||||
|
||||
AbstractCommand commandEpicAnchors = addCommand(new CommandEpicAnchors());
|
||||
|
||||
addCommand(new CommandGive(commandEpicAnchors));
|
||||
addCommand(new CommandReload(commandEpicAnchors));
|
||||
addCommand(new CommandSettings(commandEpicAnchors));
|
||||
}
|
||||
|
||||
private AbstractCommand addCommand(AbstractCommand abstractCommand) {
|
||||
commands.add(abstractCommand);
|
||||
return abstractCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
if (abstractCommand.getCommand().equalsIgnoreCase(command.getName())) {
|
||||
if (strings.length == 0) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
} else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) {
|
||||
String cmd = strings[0];
|
||||
if (cmd.equalsIgnoreCase(abstractCommand.getCommand())) {
|
||||
processRequirements(abstractCommand, commandSender, strings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) {
|
||||
if (!(sender instanceof Player) && command.isNoConsole()) {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return;
|
||||
}
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.songoda.epicanchors.command.commands;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.command.AbstractCommand;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandEpicAnchors extends AbstractCommand {
|
||||
|
||||
public CommandEpicAnchors() {
|
||||
super("EpicAnchors", null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/EpicAnchors";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays this page.";
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package com.songoda.epicanchors.command.commands;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.command.AbstractCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CommandGive extends AbstractCommand {
|
||||
|
||||
public CommandGive(AbstractCommand abstractCommand) {
|
||||
super("give", abstractCommand, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
||||
if (args.length != 3) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
if (Bukkit.getPlayer(args[1]) == null && !args[1].trim().toLowerCase().equals("all")) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "Not a player...");
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
ItemStack itemStack = instance.makeAnchorItem(Integer.parseInt(args[2]) * 20 * 60 * 60);
|
||||
|
||||
if (!args[1].trim().toLowerCase().equals("all")) {
|
||||
Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer();
|
||||
player.getInventory().addItem(itemStack);
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success"));
|
||||
} else {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.getInventory().addItem(itemStack);
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success"));
|
||||
}
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicanchors.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ea give <player/all> <amount in hours>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives an operator the ability to spawn a ChunkAnchor of his or her choice.";
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.songoda.epicanchors.command.commands;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.command.AbstractCommand;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload(AbstractCommand parent) {
|
||||
super("reload", parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicanchors.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ea reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Reload the Configuration and Language files.";
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
package com.songoda.epicanchors.command.commands;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.command.AbstractCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
public CommandSettings(AbstractCommand parent) {
|
||||
super("settings", parent, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
||||
instance.getSettingsManager().openSettingsManager((Player) sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicanchors.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ea settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Edit the EpicAnchors Settings.";
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
package com.songoda.epicanchors.gui;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import com.songoda.epicanchors.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GUIOverview extends AbstractGUI {
|
||||
|
||||
private final EpicAnchorsPlugin plugin;
|
||||
private final EAnchor anchor;
|
||||
|
||||
private int task;
|
||||
|
||||
public GUIOverview(EpicAnchorsPlugin plugin, EAnchor anchor, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.anchor = anchor;
|
||||
|
||||
|
||||
init(Methods.formatText(plugin.getLocale().getMessage("interface.anchor.title")), 27);
|
||||
runTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void constructGUI() {
|
||||
String timeRemaining = Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining.";
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
inventory.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
inventory.setItem(0, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(1, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(2, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(6, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(7, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(8, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(9, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(10, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(16, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(17, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(18, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(19, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(20, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(24, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(25, Methods.getBackgroundGlass(true));
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
ItemStack itemXP = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.XP Icon")), 1);
|
||||
ItemMeta itemmetaXP = itemXP.getItemMeta();
|
||||
itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.button.addtimewithxp"));
|
||||
ArrayList<String> loreXP = new ArrayList<>();
|
||||
loreXP.add(plugin.getLocale().getMessage("interface.button.addtimewithxplore", Integer.toString(plugin.getConfig().getInt("Main.XP Cost"))));
|
||||
itemmetaXP.setLore(loreXP);
|
||||
itemXP.setItemMeta(itemmetaXP);
|
||||
|
||||
ItemStack itemECO = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Economy Icon")), 1);
|
||||
ItemMeta itemmetaECO = itemECO.getItemMeta();
|
||||
itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.button.addtimewitheconomy"));
|
||||
ArrayList<String> loreECO = new ArrayList<>();
|
||||
loreECO.add(plugin.getLocale().getMessage("interface.button.addtimewitheconomylore", Methods.formatEconomy(plugin.getConfig().getInt("Main.Economy Cost"))));
|
||||
itemmetaECO.setLore(loreECO);
|
||||
itemECO.setItemMeta(itemmetaECO);
|
||||
|
||||
ItemStack item = plugin.makeAnchorItem(anchor.getTicksLeft());
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText(plugin.getLocale().getMessage("interface.anchor.smalltitle")));
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add(Methods.formatText("&7" + timeRemaining));
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(13, item);
|
||||
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With Economy")) {
|
||||
inventory.setItem(11, itemECO);
|
||||
}
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With XP")) {
|
||||
inventory.setItem(15, itemXP);
|
||||
}
|
||||
}
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::constructGUI, 5L, 5L);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(11, ((player, inventory, cursor, slot, type) -> {
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With Economy"))
|
||||
anchor.addTime("ECO", player);
|
||||
}));
|
||||
|
||||
registerClickable(15, ((player, inventory, cursor, slot, type) -> {
|
||||
if (plugin.getConfig().getBoolean("Main.Add Time With XP"))
|
||||
anchor.addTime("XP", player);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
registerOnClose(((player1, inventory1) -> Bukkit.getScheduler().cancelTask(task)));
|
||||
}
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
package com.songoda.epicanchors.handlers;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import com.songoda.epicanchors.utils.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnchorHandler {
|
||||
|
||||
private EpicAnchorsPlugin instance;
|
||||
private Map<Location, Integer> delays = new HashMap<>();
|
||||
|
||||
private Class<?> clazzEntity, clazzCraftEntity, clazzMinecraftServer;
|
||||
|
||||
private Method methodTick, methodGetHandle;
|
||||
|
||||
private Field fieldCurrentTick, fieldActivatedTick;
|
||||
|
||||
private boolean epicSpawners;
|
||||
|
||||
public AnchorHandler(EpicAnchorsPlugin instance) {
|
||||
this.instance = instance;
|
||||
|
||||
try {
|
||||
String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
||||
clazzMinecraftServer = Class.forName("net.minecraft.server." + ver + ".MinecraftServer");
|
||||
clazzEntity = Class.forName("net.minecraft.server." + ver + ".Entity");
|
||||
clazzCraftEntity = Class.forName("org.bukkit.craftbukkit." + ver + ".entity.CraftEntity");
|
||||
|
||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
methodTick = clazzEntity.getDeclaredMethod("tick");
|
||||
else if (instance.isServerVersion(ServerVersion.V1_12))
|
||||
methodTick = clazzEntity.getDeclaredMethod("B_");
|
||||
else if (instance.isServerVersion(ServerVersion.V1_11))
|
||||
methodTick = clazzEntity.getDeclaredMethod("A_");
|
||||
else if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
methodTick = clazzEntity.getDeclaredMethod("m");
|
||||
else
|
||||
methodTick = clazzEntity.getDeclaredMethod("t_");
|
||||
|
||||
methodGetHandle = clazzCraftEntity.getDeclaredMethod("getHandle");
|
||||
|
||||
fieldCurrentTick = clazzMinecraftServer.getDeclaredField("currentTick");
|
||||
fieldActivatedTick = clazzEntity.getDeclaredField("activatedTick");
|
||||
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
epicSpawners = instance.getServer().getPluginManager().getPlugin("EpicSpawners") != null;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::doAnchorCheck, 0, 1); //ToDo: way to fast.
|
||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::doParticle, 0, 2); //ToDo: way to fast.
|
||||
}
|
||||
|
||||
private void doParticle() {
|
||||
for (Anchor anchor : instance.getAnchorManager().getAnchors().values()) {
|
||||
Location location1 = anchor.getLocation().add(.5, .5, .5);
|
||||
if (location1.getWorld() == null) continue;
|
||||
float xx = (float) (0 + (Math.random() * .15));
|
||||
float yy = (float) (0 + (Math.random() * 1));
|
||||
float zz = (float) (0 + (Math.random() * .15));
|
||||
location1.getWorld().spawnParticle(Particle.SPELL, location1, 5, xx, yy, zz, 5);
|
||||
|
||||
xx = (float) (0 + (Math.random() * .75));
|
||||
yy = (float) (0 + (Math.random() * 1));
|
||||
zz = (float) (0 + (Math.random() * .75));
|
||||
if (!instance.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
location1.getWorld().spawnParticle(Particle.REDSTONE, location1, 5, xx, yy, zz, 1);
|
||||
else
|
||||
location1.getWorld().spawnParticle(Particle.REDSTONE, location1, 5, xx, yy, zz, 1, new Particle.DustOptions(Color.WHITE, 1F));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void doAnchorCheck() {
|
||||
for (Anchor anchor : instance.getAnchorManager().getAnchors().values()) {
|
||||
|
||||
if (anchor.getLocation() == null) continue;
|
||||
|
||||
Location location = anchor.getLocation();
|
||||
|
||||
if (anchor.getLocation().getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Anchor Block Material")))
|
||||
continue;
|
||||
|
||||
Chunk chunk = location.getChunk();
|
||||
chunk.load();
|
||||
|
||||
// Load entities
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
if (!(entity instanceof LivingEntity) || entity instanceof Player) continue;
|
||||
|
||||
if (entity.getNearbyEntities(32, 32, 32).stream().anyMatch(entity1 -> entity1 instanceof Player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Object objCraftEntity = clazzCraftEntity.cast(entity);
|
||||
Object objEntity = methodGetHandle.invoke(objCraftEntity);
|
||||
|
||||
fieldActivatedTick.set(objEntity, fieldCurrentTick.getLong(objEntity));
|
||||
methodTick.invoke(objEntity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
int ticksLeft = anchor.getTicksLeft();
|
||||
anchor.setTicksLeft(ticksLeft - 1);
|
||||
|
||||
if (ticksLeft <= 0) {
|
||||
instance.getAnchorManager().removeAnchor(location);
|
||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
location.getWorld().spawnParticle(Particle.LAVA, location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
||||
location.getWorld().playSound(location, instance.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE"), 10, 10);
|
||||
location.getBlock().setType(Material.AIR);
|
||||
chunk.unload();
|
||||
}
|
||||
|
||||
if (!epicSpawners || com.songoda.epicspawners.EpicSpawners.getInstance().getSpawnerManager() == null) continue;
|
||||
|
||||
com.songoda.epicspawners.EpicSpawners.getInstance().getSpawnerManager().getSpawners().stream()
|
||||
.filter(spawner -> spawner.getWorld().isChunkLoaded(spawner.getX() >> 4, spawner.getZ() >> 4)
|
||||
&& chunk == spawner.getLocation().getChunk()).forEach(spawner -> {
|
||||
Block block = spawner.getLocation().getBlock();
|
||||
|
||||
if (!delays.containsKey(block.getLocation())) {
|
||||
delays.put(block.getLocation(), spawner.updateDelay());
|
||||
return;
|
||||
}
|
||||
int delay = delays.get(block.getLocation());
|
||||
delay -= 1;
|
||||
delays.put(block.getLocation(), delay);
|
||||
if (delay <= 0) {
|
||||
spawner.spawn();
|
||||
delays.remove(block.getLocation());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.songoda.epicanchors.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.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) {
|
||||
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
|
||||
&& plot.getOwners().contains(player.getUniqueId())
|
||||
&& plot.getMembers().contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
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 java.lang.reflect.Method;
|
||||
|
||||
public class HookWorldGuard implements ProtectionPluginHook {
|
||||
|
||||
private Method wg6canBuild;
|
||||
private Object wg6inst;
|
||||
private boolean isWorldGuard7;
|
||||
|
||||
public HookWorldGuard() {
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.WorldGuard");
|
||||
this.isWorldGuard7 = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
this.isWorldGuard7 = false;
|
||||
try {
|
||||
this.wg6inst = Class.forName("com.sk89q.worldguard.bukkit.WorldGuardPlugin").getMethod("inst").invoke(null);
|
||||
this.wg6canBuild = this.wg6inst.getClass().getMethod("canBuild", Player.class, Location.class);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getPlugin() {
|
||||
try {
|
||||
if (this.isWorldGuard7)
|
||||
return com.sk89q.worldguard.bukkit.WorldGuardPlugin.inst();
|
||||
return (JavaPlugin) Class.forName("com.sk89q.worldguard.bukkit.WorldGuardPlugin").getMethod("inst").invoke(null);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBuild(Player player, Location location) {
|
||||
if (this.isWorldGuard7) {
|
||||
com.sk89q.worldguard.protection.regions.RegionQuery q = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
com.sk89q.worldguard.protection.ApplicableRegionSet ars = q.getApplicableRegions(com.sk89q.worldedit.bukkit.BukkitAdapter.adapt(player.getLocation()));
|
||||
return ars.testState(com.sk89q.worldguard.bukkit.WorldGuardPlugin.inst().wrapPlayer(player), com.sk89q.worldguard.protection.flags.Flags.BUILD);
|
||||
} else {
|
||||
try {
|
||||
return (boolean) this.wg6canBuild.invoke(this.wg6inst, player, location);
|
||||
} catch (Exception ex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityCreatePortalEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private EpicAnchorsPlugin instance;
|
||||
|
||||
public BlockListeners(EpicAnchorsPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!instance.canBuild(player, block.getLocation())
|
||||
|| event.getBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Anchor Block Material")))
|
||||
return;
|
||||
|
||||
ItemStack item = event.getItemInHand();
|
||||
|
||||
if (!item.hasItemMeta()
|
||||
|| !item.getItemMeta().hasDisplayName()
|
||||
|| instance.getTicksFromItem(item) == 0) return;
|
||||
|
||||
instance.getAnchorManager().addAnchor(event.getBlock().getLocation(), new EAnchor(event.getBlock().getLocation(), instance.getTicksFromItem(item)));
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPortalCreation(EntityCreatePortalEvent e) {
|
||||
if (e.getBlocks().size() < 1) return;
|
||||
if (instance.getAnchorManager().isAnchor(e.getBlocks().get(0).getLocation())) e.setCancelled(true);
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import com.songoda.epicanchors.utils.ServerVersion;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private EpicAnchorsPlugin instance;
|
||||
|
||||
public InteractListeners(EpicAnchorsPlugin instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockInteract(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) return;
|
||||
|
||||
if (instance.getAnchorManager().getAnchor(event.getClickedBlock().getLocation()) == null) return;
|
||||
|
||||
if (!instance.canBuild(event.getPlayer(), event.getClickedBlock().getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
instance.bust(event.getClickedBlock().getLocation());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Anchor anchor = instance.getAnchorManager().getAnchor(event.getClickedBlock().getLocation());
|
||||
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (item.getType() == (instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.ENDER_EYE : Material.valueOf("EYE_OF_ENDER"))
|
||||
&& Material.valueOf(instance.getConfig().getString("Main.Anchor Block Material")) == (instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.END_PORTAL_FRAME : Material.valueOf("ENDER_PORTAL_FRAME"))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.getType() == Material.valueOf(instance.getConfig().getString("Main.Anchor Block Material"))) {
|
||||
if (instance.getTicksFromItem(item) == 0) return;
|
||||
|
||||
anchor.setTicksLeft(anchor.getTicksLeft() + instance.getTicksFromItem(item));
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
Methods.takeItem(player, 1);
|
||||
|
||||
Sound sound = EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP");
|
||||
player.playSound(player.getLocation(), sound, 0.6F, 15.0F);
|
||||
|
||||
if (EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
player.getWorld().spawnParticle(Particle.SPELL_WITCH, anchor.getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
((EAnchor) anchor).overview(player);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package com.songoda.epicanchors.utils;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* ConfigWrapper made by @clip
|
||||
*/
|
||||
public class ConfigWrapper {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final String folderName, fileName;
|
||||
private FileConfiguration config;
|
||||
private File configFile;
|
||||
|
||||
public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) {
|
||||
this.plugin = instance;
|
||||
this.folderName = folderName;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public void createNewFile(final String message, final String header) {
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
loadConfig(header);
|
||||
|
||||
if (message != null) {
|
||||
plugin.getLogger().info(message);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (config == null) {
|
||||
reloadConfig();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public void loadConfig(final String header) {
|
||||
config.options().header(header);
|
||||
config.options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder() + folderName, fileName);
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (config == null || configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
} catch (final IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,695 +0,0 @@
|
||||
package com.songoda.epicanchors.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
* <p>
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
||||
final String defaultPackage = new String(
|
||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private boolean enabled;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
*/
|
||||
public Metrics(Plugin plugin) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
// Add default values
|
||||
config.addDefault("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
// Should failed request be logged?
|
||||
config.addDefault("logFailedRequests", false);
|
||||
// Should the sent data be logged?
|
||||
config.addDefault("logSentData", false);
|
||||
// Should the response text be logged?
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
// Load the data
|
||||
enabled = config.getBoolean("enabled", true);
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
logSentData = config.getBoolean("logSentData", false);
|
||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
|
||||
if (enabled) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
// Register our service
|
||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||
if (!found) {
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
* @return Whether bStats is enabled or not.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
throw new IllegalArgumentException("Chart cannot be null!");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||
}
|
||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data.
|
||||
* This method is called using Reflection.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JSONObject getPluginData() {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JSONObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.put("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JSONObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||
}
|
||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = Bukkit.getVersion();
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
data.put("serverUUID", serverUUID);
|
||||
|
||||
data.put("playerAmount", playerAmount);
|
||||
data.put("onlineMode", onlineMode);
|
||||
data.put("bukkitVersion", bukkitVersion);
|
||||
|
||||
data.put("javaVersion", javaVersion);
|
||||
data.put("osName", osName);
|
||||
data.put("osArch", osArch);
|
||||
data.put("osVersion", osVersion);
|
||||
data.put("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JSONObject data = getServerData();
|
||||
|
||||
JSONArray pluginData = new JSONArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JSONObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data.toString());
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
bufferedReader.close();
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
gzip.close();
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
try {
|
||||
JSONObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.put("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JSONObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JSONObject value = new JSONObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.put(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
categoryValues.add(entry.getValue());
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(categoryValue);
|
||||
}
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.songoda.epicanchors.utils;
|
||||
|
||||
public enum ServerVersion {
|
||||
|
||||
UNKNOWN("unknown_server_version"),
|
||||
V1_7("org.bukkit.craftbukkit.v1_7"),
|
||||
V1_8("org.bukkit.craftbukkit.v1_8"),
|
||||
V1_9("org.bukkit.craftbukkit.v1_9"),
|
||||
V1_10("org.bukkit.craftbukkit.v1_10"),
|
||||
V1_11("org.bukkit.craftbukkit.v1_11"),
|
||||
V1_12("org.bukkit.craftbukkit.v1_12"),
|
||||
V1_13("org.bukkit.craftbukkit.v1_13"),
|
||||
V1_14("org.bukkit.craftbukkit.v1_14");
|
||||
|
||||
|
||||
private final String packagePrefix;
|
||||
|
||||
private ServerVersion(String packagePrefix) {
|
||||
this.packagePrefix = packagePrefix;
|
||||
}
|
||||
|
||||
public static ServerVersion fromPackageName(String packageName) {
|
||||
for (ServerVersion version : values())
|
||||
if (packageName.startsWith(version.packagePrefix)) return version;
|
||||
return ServerVersion.UNKNOWN;
|
||||
}
|
||||
}
|
@ -1,222 +0,0 @@
|
||||
package com.songoda.epicanchors.utils;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by songo on 6/4/2017.
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
|
||||
private final EpicAnchorsPlugin instance;
|
||||
private String pluginName = "EpicAnchors";
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
private Map<Player, String> current = new HashMap<>();
|
||||
|
||||
public SettingsManager(EpicAnchorsPlugin plugin) {
|
||||
this.instance = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
|
||||
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|
||||
|| clickedItem == null || !clickedItem.hasItemMeta()
|
||||
|| !clickedItem.getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getView().getTitle().equals(pluginName + " Settings Manager")) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
this.cat.put((Player) event.getWhoClicked(), type);
|
||||
this.openEditor((Player) event.getWhoClicked());
|
||||
} else if (event.getView().getTitle().equals(pluginName + " Settings Editor")) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
|
||||
if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
|
||||
this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key));
|
||||
this.finishEditing(player);
|
||||
} else {
|
||||
this.editObject(player, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!current.containsKey(player)) return;
|
||||
|
||||
String value = current.get(player);
|
||||
FileConfiguration config = instance.getConfig();
|
||||
if (config.isInt(value)) {
|
||||
config.set(value, Integer.parseInt(event.getMessage()));
|
||||
} else if (config.isDouble(value)) {
|
||||
config.set(value, Double.parseDouble(event.getMessage()));
|
||||
} else if (config.isString(value)) {
|
||||
config.set(value, event.getMessage());
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicAnchorsPlugin.getInstance(), () ->
|
||||
this.finishEditing(player), 0L);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void finishEditing(Player player) {
|
||||
this.current.remove(player);
|
||||
this.instance.saveConfig();
|
||||
this.openEditor(player);
|
||||
}
|
||||
|
||||
private void editObject(Player player, String current) {
|
||||
this.current.put(player, ChatColor.stripColor(current));
|
||||
|
||||
player.closeInventory();
|
||||
player.sendMessage("");
|
||||
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
|
||||
if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) {
|
||||
player.sendMessage(Methods.formatText("&cUse only numbers."));
|
||||
}
|
||||
player.sendMessage("");
|
||||
}
|
||||
|
||||
public void openSettingsManager(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
|
||||
ItemStack glass = Methods.getGlass();
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, glass);
|
||||
}
|
||||
|
||||
int slot = 10;
|
||||
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
|
||||
ItemStack item = new ItemStack(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
|
||||
meta.setDisplayName(Methods.formatText("&f&l" + key));
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
private void openEditor(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
int slot = 0;
|
||||
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
|
||||
String fKey = cat.get(player) + "." + key;
|
||||
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatText("&6" + key));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (config.isBoolean(fKey)) {
|
||||
item.setType(Material.LEVER);
|
||||
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
|
||||
} else if (config.isString(fKey)) {
|
||||
item.setType(Material.PAPER);
|
||||
lore.add(Methods.formatText("&9" + config.getString(fKey)));
|
||||
} else if (config.isInt(fKey)) {
|
||||
item.setType(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&5" + config.getInt(fKey)));
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inventory.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void updateSettings() {
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
for (Setting setting : Setting.values()) {
|
||||
config.addDefault(setting.setting, setting.option);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Setting {
|
||||
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", EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "END_PORTAL_FRAME" : "ENDER_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", EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "SUNFLOWER" : "GOLD_INGOT"),
|
||||
o10("Interfaces.XP Icon", EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "EXPERIENCE_BOTTLE" : "EXP_BOTTLE"),
|
||||
o11("Interfaces.Glass Type 1", 7),
|
||||
o12("Interfaces.Glass Type 2", 11),
|
||||
o13("Interfaces.Glass Type 3", 3),
|
||||
|
||||
LANGUGE_MODE("System.Language Mode", "en_US");
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
|
||||
Setting(String setting, Object option) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return EpicAnchorsPlugin.getInstance().getConfig().getStringList(setting);
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return EpicAnchorsPlugin.getInstance().getConfig().getBoolean(setting);
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return EpicAnchorsPlugin.getInstance().getConfig().getInt(setting);
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return EpicAnchorsPlugin.getInstance().getConfig().getString(setting);
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
return EpicAnchorsPlugin.getInstance().getConfig().getString(setting).charAt(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,226 +0,0 @@
|
||||
package com.songoda.epicanchors.utils.gui;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractGUI implements Listener {
|
||||
|
||||
private static boolean listenersInitialized = false;
|
||||
protected Player player;
|
||||
protected Inventory inventory = null;
|
||||
protected String setTitle = null;
|
||||
protected boolean cancelBottom = false;
|
||||
private Map<Range, Clickable> clickables = new HashMap<>();
|
||||
private List<OnClose> onCloses = new ArrayList<>();
|
||||
private Map<Range, Boolean> draggableRanges = new HashMap<>();
|
||||
|
||||
public AbstractGUI(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static void initializeListeners(JavaPlugin plugin) {
|
||||
if (listenersInitialized) return;
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||
@EventHandler
|
||||
public void onClickGUI(InventoryClickEvent event) {
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
if (inventory == null) return;
|
||||
AbstractGUI gui = getGUIFromInventory(inventory);
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
boolean bottom = false;
|
||||
|
||||
InventoryType type = event.getClickedInventory().getType();
|
||||
if (type != InventoryType.CHEST && type != InventoryType.PLAYER) return;
|
||||
|
||||
if (gui == null && event.getWhoClicked().getOpenInventory().getTopInventory() != null) {
|
||||
Inventory top = event.getWhoClicked().getOpenInventory().getTopInventory();
|
||||
gui = getGUIFromInventory(top);
|
||||
|
||||
if (gui != null && gui.cancelBottom) event.setCancelled(true);
|
||||
bottom = true;
|
||||
}
|
||||
|
||||
if (gui == null) return;
|
||||
|
||||
if (!bottom) event.setCancelled(true);
|
||||
|
||||
if (!gui.draggableRanges.isEmpty() && !bottom) {
|
||||
for (Map.Entry<Range, Boolean> entry : gui.draggableRanges.entrySet()) {
|
||||
Range range = entry.getKey();
|
||||
if (range.getMax() == range.getMin() && event.getSlot() == range.getMin()
|
||||
|| event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
|
||||
event.setCancelled(!entry.getValue());
|
||||
if (!entry.getValue()) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<Range, Clickable> entries = new HashMap<>(gui.clickables);
|
||||
|
||||
for (Map.Entry<Range, Clickable> entry : entries.entrySet()) {
|
||||
Range range = entry.getKey();
|
||||
if (range.isBottom() && !bottom || !range.isBottom() && bottom || range.getClickType() != null && range.getClickType() != event.getClick())
|
||||
continue;
|
||||
if (event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
|
||||
entry.getValue().Clickable(player, inventory, event.getCursor(), event.getSlot(), event.getClick());
|
||||
player.playSound(player.getLocation(), entry.getKey().getOnClickSound(), 1F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCloseGUI(InventoryCloseEvent event) {
|
||||
Inventory inventory = event.getInventory();
|
||||
AbstractGUI gui = getGUIFromInventory(inventory);
|
||||
|
||||
if (gui == null || gui.inventory == null) return;
|
||||
|
||||
for (OnClose onClose : gui.onCloses) {
|
||||
onClose.OnClose((Player) event.getPlayer(), inventory);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractGUI getGUIFromInventory(Inventory inventory) {
|
||||
if (inventory.getHolder() == null) return null;
|
||||
InventoryHolder holder = inventory.getHolder();
|
||||
if (!(holder instanceof GUIHolder)) return null;
|
||||
|
||||
return ((AbstractGUI.GUIHolder) holder).getGUI();
|
||||
}
|
||||
}, plugin);
|
||||
listenersInitialized = true;
|
||||
}
|
||||
|
||||
public void init(String title, int slots) {
|
||||
if (inventory == null
|
||||
|| inventory.getSize() != slots
|
||||
|| ChatColor.translateAlternateColorCodes('&', title) != player.getOpenInventory().getTitle()) {
|
||||
this.inventory = Bukkit.getServer().createInventory(new GUIHolder(), slots, Methods.formatText(title));
|
||||
this.setTitle = Methods.formatText(title);
|
||||
if (this.clickables.size() == 0)
|
||||
registerClickables();
|
||||
if (this.onCloses.size() == 0)
|
||||
registerOnCloses();
|
||||
}
|
||||
constructGUI();
|
||||
initializeListeners(EpicAnchorsPlugin.getInstance());
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public abstract void constructGUI();
|
||||
|
||||
protected void addDraggable(Range range, boolean option) {
|
||||
this.draggableRanges.put(range, option);
|
||||
}
|
||||
|
||||
protected void removeDraggable() {
|
||||
this.draggableRanges.clear();
|
||||
}
|
||||
|
||||
protected abstract void registerClickables();
|
||||
|
||||
protected abstract void registerOnCloses();
|
||||
|
||||
protected ItemStack createButton(int slot, Inventory inventory, ItemStack item, String name, String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
if (lore != null && lore.length != 0) {
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : lore) newLore.add(ChatColor.translateAlternateColorCodes('&', line));
|
||||
meta.setLore(newLore);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(slot, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, ItemStack item, String name, String... lore) {
|
||||
return createButton(slot, inventory, item, name, lore);
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) {
|
||||
return createButton(slot, inventory, new ItemStack(material), name, lore);
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, Material material, String name, String... lore) {
|
||||
return createButton(slot, inventory, new ItemStack(material), name, lore);
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, Material material, String name, ArrayList<String> lore) {
|
||||
return createButton(slot, material, name, lore.toArray(new String[0]));
|
||||
}
|
||||
|
||||
protected void registerClickable(int min, int max, ClickType clickType, boolean bottom, Clickable clickable) {
|
||||
clickables.put(new Range(min, max, clickType, bottom), clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int min, int max, ClickType clickType, Clickable clickable) {
|
||||
registerClickable(min, max, clickType, false, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int slot, ClickType clickType, Clickable clickable) {
|
||||
registerClickable(slot, slot, clickType, false, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int min, int max, Clickable clickable) {
|
||||
registerClickable(min, max, null, false, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int slot, boolean bottom, Clickable clickable) {
|
||||
registerClickable(slot, slot, null, bottom, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int slot, Clickable clickable) {
|
||||
registerClickable(slot, slot, null, false, clickable);
|
||||
}
|
||||
|
||||
protected void resetClickables() {
|
||||
clickables.clear();
|
||||
}
|
||||
|
||||
protected void registerOnClose(OnClose onClose) {
|
||||
onCloses.add(onClose);
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public class GUIHolder implements InventoryHolder {
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public AbstractGUI getGUI() {
|
||||
return AbstractGUI.this;
|
||||
}
|
||||
}
|
||||
|
||||
public String getSetTitle() {
|
||||
return setTitle;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.songoda.epicanchors.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Clickable {
|
||||
|
||||
void Clickable(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.songoda.epicanchors.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface OnClose {
|
||||
|
||||
void OnClose(Player player, Inventory inventory);
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.songoda.epicanchors.utils.gui;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.utils.ServerVersion;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class Range {
|
||||
|
||||
private int min;
|
||||
private int max;
|
||||
private ClickType clickType;
|
||||
private boolean bottom;
|
||||
private Sound onClickSound;
|
||||
|
||||
public Range(int min, int max, ClickType clickType, boolean bottom) {
|
||||
this(min, max, null, clickType, bottom);
|
||||
}
|
||||
|
||||
public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
|
||||
if (onClickSound == null) {
|
||||
if (EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
this.onClickSound = Sound.UI_BUTTON_CLICK;
|
||||
} else {
|
||||
this.onClickSound = Sound.valueOf("CLICK");
|
||||
}
|
||||
} else {
|
||||
this.onClickSound = onClickSound;
|
||||
}
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
|
||||
public boolean isBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
public Sound getOnClickSound() {
|
||||
return onClickSound;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.songoda.epicanchors.utils.updateModules;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.update.Module;
|
||||
import com.songoda.update.Plugin;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class LocaleModule implements Module {
|
||||
|
||||
@Override
|
||||
public void run(Plugin plugin) {
|
||||
JSONObject json = plugin.getJson();
|
||||
try {
|
||||
JSONArray files = (JSONArray) json.get("neededFiles");
|
||||
for (Object o : files) {
|
||||
JSONObject file = (JSONObject) o;
|
||||
|
||||
if (file.get("type").equals("locale")) {
|
||||
InputStream in = new URL((String) file.get("link")).openStream();
|
||||
EpicAnchorsPlugin.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
116
pom.xml
116
pom.xml
@ -4,31 +4,13 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>maven-version-number</version>
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>EpicAnchors-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>EpicAnchors-API/src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<version>3.6.1</version>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@ -48,12 +30,20 @@
|
||||
<configuration>
|
||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.songoda:songodaupdater</include>
|
||||
<include>com.songoda:SongodaCore</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<!-- This filter is primarily for anvil gui right now -->
|
||||
<!--<filter>
|
||||
<artifact>com.songoda:SongodaCore-NMS*</artifact>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
</filter>-->
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
@ -63,90 +53,40 @@
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.songoda.core</pattern>
|
||||
<shadedPattern>${project.groupId}.epicanchors.core</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>EpicAnchors-Plugin/src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<sourceDirectory>EpicAnchors-Plugin/src/main/java</sourceDirectory>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>private</id>
|
||||
<url>http://repo.songoda.com/artifactory/private/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14</version>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>songodaupdater</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org</groupId>
|
||||
<artifactId>kingdoms</artifactId>
|
||||
<version>13.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl</groupId>
|
||||
<artifactId>vault</artifactId>
|
||||
<version>1.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.ryanhamshire</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>16.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>7.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>7.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com</groupId>
|
||||
<artifactId>plotsquared</artifactId>
|
||||
<version>BREAKING</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.palmergames.bukkit</groupId>
|
||||
<artifactId>towny</artifactId>
|
||||
<version>0.93.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.wasteofplastic</groupId>
|
||||
<artifactId>askyblock</artifactId>
|
||||
<version>3.0.6.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.talabrek</groupId>
|
||||
<artifactId>ultimateskyblock</artifactId>
|
||||
<version>2.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.markeh</groupId>
|
||||
<artifactId>factionsframework</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>br.net.fabiozumbi12</groupId>
|
||||
<artifactId>RedProtect</artifactId>
|
||||
<version>7.3.0</version>
|
||||
<artifactId>SongodaCore</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
|
191
src/main/java/com/songoda/epicanchors/EpicAnchors.java
Normal file
191
src/main/java/com/songoda/epicanchors/EpicAnchors.java
Normal file
@ -0,0 +1,191 @@
|
||||
package com.songoda.epicanchors;
|
||||
|
||||
import com.songoda.core.SongodaCore;
|
||||
import com.songoda.core.SongodaPlugin;
|
||||
import com.songoda.core.commands.CommandManager;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.core.hooks.HologramManager;
|
||||
import com.songoda.epicanchors.anchor.Anchor;
|
||||
import com.songoda.epicanchors.anchor.AnchorManager;
|
||||
import com.songoda.epicanchors.commands.CommandEpicAnchors;
|
||||
import com.songoda.epicanchors.commands.CommandGive;
|
||||
import com.songoda.epicanchors.commands.CommandReload;
|
||||
import com.songoda.epicanchors.commands.CommandSettings;
|
||||
import com.songoda.epicanchors.listeners.BlockListeners;
|
||||
import com.songoda.epicanchors.listeners.InteractListeners;
|
||||
import com.songoda.epicanchors.settings.Settings;
|
||||
import com.songoda.epicanchors.tasks.AnchorTask;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class EpicAnchors extends SongodaPlugin {
|
||||
|
||||
private static EpicAnchors INSTANCE;
|
||||
|
||||
private final Config dataFile = new Config(this, "data.yml");
|
||||
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private AnchorManager anchorManager;
|
||||
private CommandManager commandManager;
|
||||
|
||||
public static EpicAnchors getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
saveToFile();
|
||||
HologramManager.removeAllHolograms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginEnable() {
|
||||
// Run Songoda Updater
|
||||
SongodaCore.registerPlugin(this, 31, CompatibleMaterial.END_PORTAL_FRAME);
|
||||
|
||||
// Load Economy
|
||||
EconomyManager.load();
|
||||
|
||||
// Setup Config
|
||||
Settings.setupConfig();
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), false);
|
||||
|
||||
// Set economy preference
|
||||
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString());
|
||||
|
||||
// Register commands
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.commandManager.addCommand(new CommandEpicAnchors(this))
|
||||
.addSubCommands(
|
||||
new CommandGive(this),
|
||||
new CommandReload(this),
|
||||
new CommandSettings(this, guiManager)
|
||||
);
|
||||
|
||||
anchorManager = new AnchorManager();
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> loadAnchorsFromFile(), 5L);
|
||||
|
||||
// Start tasks
|
||||
new AnchorTask(this);
|
||||
|
||||
// Register Listeners
|
||||
guiManager.init();
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
|
||||
// Register Hologram Plugin
|
||||
HologramManager.load(this);
|
||||
|
||||
if (Settings.HOLOGRAMS.getBoolean())
|
||||
loadHolograms();
|
||||
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigReload() {
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), true);
|
||||
this.loadAnchorsFromFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Config> getExtraConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void loadHolograms() {
|
||||
Collection<Anchor> anchors = getAnchorManager().getAnchors().values();
|
||||
if (anchors.size() == 0) return;
|
||||
|
||||
for (Anchor anchor : anchors) {
|
||||
if (anchor.getWorld() == null) continue;
|
||||
updateHologram(anchor);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearHologram(Anchor anchor) {
|
||||
HologramManager.removeHologram(anchor.getLocation());
|
||||
}
|
||||
|
||||
public void updateHologram(Anchor anchor) {
|
||||
// are holograms enabled?
|
||||
if (!Settings.HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) return;
|
||||
// verify that this is a anchor
|
||||
if (anchor.getLocation().getBlock().getType() != Settings.MATERIAL.getMaterial().getMaterial()) return;
|
||||
// grab the name
|
||||
String name = Methods.formatName(anchor.getTicksLeft(), false).trim();
|
||||
// create the hologram
|
||||
HologramManager.updateHologram(anchor.getLocation(), name);
|
||||
}
|
||||
|
||||
private void loadAnchorsFromFile() {
|
||||
dataFile.load();
|
||||
if (!dataFile.contains("Anchors")) return;
|
||||
for (String locationStr : dataFile.getConfigurationSection("Anchors").getKeys(false)) {
|
||||
Location location = Methods.unserializeLocation(locationStr);
|
||||
int ticksLeft = dataFile.getInt("Anchors." + locationStr + ".ticksLeft");
|
||||
anchorManager.addAnchor(location, new Anchor(location, ticksLeft));
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToFile() {
|
||||
dataFile.clearConfig(true);
|
||||
for (Anchor anchor : anchorManager.getAnchors().values()) {
|
||||
String locationStr = Methods.serializeLocation(anchor.getLocation());
|
||||
dataFile.set("Anchors." + locationStr + ".ticksLeft", anchor.getTicksLeft());
|
||||
}
|
||||
dataFile.save();
|
||||
}
|
||||
|
||||
public int getTicksFromItem(ItemStack item) {
|
||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0;
|
||||
if (item.getItemMeta().getDisplayName().contains(":")) {
|
||||
return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ItemStack makeAnchorItem(int ticks) {
|
||||
ItemStack item = getCoreConfig().getMaterial("Main.Anchor Block Material", CompatibleMaterial.END_PORTAL_FRAME).getItem();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(Methods.formatName(ticks, true));
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
String[] parts = Settings.LORE.getString().split("\\|");
|
||||
for (String line : parts) {
|
||||
lore.add(Methods.formatText(line));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public GuiManager getGuiManager() {
|
||||
return guiManager;
|
||||
}
|
||||
|
||||
public AnchorManager getAnchorManager() {
|
||||
return anchorManager;
|
||||
}
|
||||
}
|
101
src/main/java/com/songoda/epicanchors/anchor/Anchor.java
Normal file
101
src/main/java/com/songoda/epicanchors/anchor/Anchor.java
Normal file
@ -0,0 +1,101 @@
|
||||
package com.songoda.epicanchors.anchor;
|
||||
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Anchor {
|
||||
|
||||
private Location location;
|
||||
private int ticksLeft;
|
||||
|
||||
public Anchor(Location location, int ticksLeft) {
|
||||
this.location = location;
|
||||
this.ticksLeft = ticksLeft;
|
||||
}
|
||||
|
||||
public void addTime(String type, Player player) {
|
||||
EpicAnchors instance = EpicAnchors.getInstance();
|
||||
|
||||
if (type.equals("ECO")) {
|
||||
if (!EconomyManager.isEnabled()) return;
|
||||
double cost = instance.getConfig().getDouble("Main.Economy Cost");
|
||||
if (EconomyManager.hasBalance(player, cost)) {
|
||||
EconomyManager.withdrawBalance(player, cost);
|
||||
} else {
|
||||
instance.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
} else if (type.equals("XP")) {
|
||||
int cost = instance.getConfig().getInt("Main.XP Cost");
|
||||
if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
player.setLevel(player.getLevel() - cost);
|
||||
}
|
||||
} else {
|
||||
instance.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ticksLeft = ticksLeft + 20 * 60 * 30;
|
||||
Sound sound = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP");
|
||||
player.playSound(player.getLocation(), sound, 0.6F, 15.0F);
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
player.getWorld().spawnParticle(Particle.SPELL_WITCH, getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
||||
}
|
||||
|
||||
public void bust() {
|
||||
EpicAnchors plugin = EpicAnchors.getInstance();
|
||||
|
||||
if (plugin.getConfig().getBoolean("Main.Allow Anchor Breaking")) {
|
||||
ItemStack item = plugin.makeAnchorItem(getTicksLeft());
|
||||
getLocation().getWorld().dropItemNaturally(getLocation(), item);
|
||||
}
|
||||
location.getBlock().setType(Material.AIR);
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
location.getWorld().spawnParticle(Particle.LAVA, location.clone().add(.5, .5, .5), 5, 0, 0, 0, 5);
|
||||
|
||||
location.getWorld().playSound(location, ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)
|
||||
? Sound.ENTITY_GENERIC_EXPLODE : Sound.valueOf("EXPLODE"), 10, 10);
|
||||
|
||||
plugin.getAnchorManager().removeAnchor(location);
|
||||
plugin.clearHologram(this);
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location.clone();
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return location.getBlockX();
|
||||
}
|
||||
|
||||
|
||||
public int getY() {
|
||||
return location.getBlockY();
|
||||
}
|
||||
|
||||
|
||||
public int getZ() {
|
||||
return location.getBlockZ();
|
||||
}
|
||||
|
||||
|
||||
public World getWorld() {
|
||||
return location.getWorld();
|
||||
}
|
||||
|
||||
public int getTicksLeft() {
|
||||
return ticksLeft;
|
||||
}
|
||||
|
||||
public void setTicksLeft(int ticksLeft) {
|
||||
this.ticksLeft = ticksLeft;
|
||||
}
|
||||
}
|
@ -1,38 +1,31 @@
|
||||
package com.songoda.epicanchors.anchor;
|
||||
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import com.songoda.epicanchors.api.anchor.AnchorManager;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EAnchorManager implements AnchorManager {
|
||||
public class AnchorManager {
|
||||
|
||||
private final Map<Location, Anchor> registeredAnchors = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Anchor addAnchor(Location location, Anchor anchor) {
|
||||
return registeredAnchors.put(roundLocation(location), anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAnchor(Location location) {
|
||||
registeredAnchors.remove(roundLocation(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Anchor getAnchor(Location location) {
|
||||
return registeredAnchors.get(roundLocation(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnchor(Location location) {
|
||||
return registeredAnchors.containsKey(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Location, Anchor> getAnchors() {
|
||||
return Collections.unmodifiableMap(registeredAnchors);
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.songoda.epicanchors.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEpicAnchors extends AbstractCommand {
|
||||
|
||||
final EpicAnchors instance;
|
||||
|
||||
public CommandEpicAnchors(EpicAnchors instance) {
|
||||
super(false, "EpicAnchors");
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion()
|
||||
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getAllCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender commandSender, String... strings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/EpicAnchors";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays this page.";
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.songoda.epicanchors.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandGive extends AbstractCommand {
|
||||
|
||||
final EpicAnchors instance;
|
||||
|
||||
public CommandGive(EpicAnchors instance) {
|
||||
super(false, "give");
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 2) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null && !args[0].trim().toLowerCase().equals("all")) {
|
||||
instance.getLocale().newMessage("&cThat is not a player...").sendMessage(sender);
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
ItemStack itemStack = instance.makeAnchorItem(Integer.parseInt(args[1]) * 20 * 60 * 60);
|
||||
|
||||
if (target != null) {
|
||||
target.getInventory().addItem(itemStack);
|
||||
instance.getLocale().getMessage("command.give.success").sendPrefixedMessage(target);
|
||||
} else {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.getInventory().addItem(itemStack);
|
||||
instance.getLocale().getMessage("command.give.success").sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender commandSender, String... strings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicanchors.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ea give <player/all> <amount in hours>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gives an operator the ability to spawn a ChunkAnchor of his or her choice.";
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.songoda.epicanchors.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
final EpicAnchors instance;
|
||||
|
||||
public CommandReload(EpicAnchors instance) {
|
||||
super(false, "reload");
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
instance.reloadConfig();
|
||||
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicanchors.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ea reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Reload the Configuration and Language files.";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.songoda.epicanchors.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
final EpicAnchors instance;
|
||||
final GuiManager guiManager;
|
||||
|
||||
public CommandSettings(EpicAnchors instance, GuiManager manager) {
|
||||
super(true, "settings");
|
||||
this.instance = instance;
|
||||
this.guiManager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
guiManager.showGUI((Player) sender, new PluginConfigGui(instance));
|
||||
return AbstractCommand.ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender commandSender, String... strings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "epicanchors.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ea settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Edit the EpicAnchors Settings.";
|
||||
}
|
||||
}
|
78
src/main/java/com/songoda/epicanchors/gui/GUIOverview.java
Normal file
78
src/main/java/com/songoda/epicanchors/gui/GUIOverview.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.songoda.epicanchors.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import com.songoda.epicanchors.anchor.Anchor;
|
||||
import com.songoda.epicanchors.settings.Settings;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class GUIOverview extends Gui {
|
||||
|
||||
private final EpicAnchors plugin;
|
||||
private final Anchor anchor;
|
||||
private final Player player;
|
||||
|
||||
private int task;
|
||||
|
||||
public GUIOverview(EpicAnchors plugin, Anchor anchor, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.anchor = anchor;
|
||||
this.player = player;
|
||||
|
||||
this.setRows(3);
|
||||
this.setTitle(Methods.formatText(plugin.getLocale().getMessage("interface.anchor.title").getMessage()));
|
||||
|
||||
runTask();
|
||||
constructGUI();
|
||||
this.setOnClose(action -> Bukkit.getScheduler().cancelTask(task));
|
||||
}
|
||||
|
||||
private void constructGUI() {
|
||||
ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial());
|
||||
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial());
|
||||
ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial());
|
||||
|
||||
setDefaultItem(glass1);
|
||||
|
||||
GuiUtils.mirrorFill(this, 0, 0, true, true, glass2);
|
||||
GuiUtils.mirrorFill(this, 0, 1, true, true, glass2);
|
||||
GuiUtils.mirrorFill(this, 0, 2, true, true, glass3);
|
||||
GuiUtils.mirrorFill(this, 1, 0, false, true, glass2);
|
||||
GuiUtils.mirrorFill(this, 1, 1, false, true, glass3);
|
||||
|
||||
setItem(13, GuiUtils.createButtonItem(plugin.makeAnchorItem(anchor.getTicksLeft()),
|
||||
plugin.getLocale().getMessage("interface.anchor.smalltitle").getMessage(),
|
||||
ChatColor.GRAY + Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining."));
|
||||
|
||||
if (EconomyManager.isEnabled() && Settings.ADD_TIME_WITH_ECONOMY.getBoolean()) {
|
||||
setButton(11, GuiUtils.createButtonItem(Settings.ECO_ICON.getMaterial(CompatibleMaterial.SUNFLOWER),
|
||||
plugin.getLocale().getMessage("interface.button.addtimewitheconomy").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.button.addtimewitheconomylore")
|
||||
.processPlaceholder("cost", Methods.formatEconomy(Settings.ECONOMY_COST.getDouble())).getMessage()), // EconomyManager.formatEconomy adds its own prefix/suffix
|
||||
event -> anchor.addTime("ECO", event.player));
|
||||
}
|
||||
|
||||
if (Settings.ADD_TIME_WITH_XP.getBoolean()) {
|
||||
setButton(15, GuiUtils.createButtonItem(Settings.XP_ICON.getMaterial(CompatibleMaterial.EXPERIENCE_BOTTLE),
|
||||
plugin.getLocale().getMessage("interface.button.addtimewithxp").getMessage(),
|
||||
plugin.getLocale().getMessage("interface.button.addtimewithxplore")
|
||||
.processPlaceholder("cost", String.valueOf(Settings.XP_COST.getInt())).getMessage()),
|
||||
event -> anchor.addTime("XP", event.player));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
updateItem(13, plugin.getLocale().getMessage("interface.anchor.smalltitle").getMessage(),
|
||||
ChatColor.GRAY + Methods.makeReadable((long) (anchor.getTicksLeft() / 20) * 1000) + " remaining.");
|
||||
}, 5L, 5L);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import com.songoda.epicanchors.anchor.Anchor;
|
||||
import com.songoda.epicanchors.settings.Settings;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
private EpicAnchors plugin;
|
||||
|
||||
public BlockListeners(EpicAnchors instance) {
|
||||
this.plugin = instance;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
|
||||
ItemStack item = event.getItemInHand();
|
||||
|
||||
if (!item.hasItemMeta()
|
||||
|| !item.getItemMeta().hasDisplayName()
|
||||
|| Material.valueOf(Settings.MATERIAL.getString()) != event.getBlock().getType()
|
||||
|| plugin.getTicksFromItem(item) == 0) return;
|
||||
|
||||
Anchor anchor = new Anchor(event.getBlock().getLocation(), plugin.getTicksFromItem(item));
|
||||
plugin.getAnchorManager().addAnchor(event.getBlock().getLocation(), anchor);
|
||||
|
||||
plugin.updateHologram(anchor);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPortalCreation(PortalCreateEvent e) {
|
||||
if (e.getBlocks().size() < 1) return;
|
||||
if (plugin.getAnchorManager().isAnchor(e.getBlocks().get(0).getLocation())) e.setCancelled(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import com.songoda.epicanchors.anchor.Anchor;
|
||||
import com.songoda.epicanchors.gui.GUIOverview;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final EpicAnchors instance;
|
||||
|
||||
public InteractListeners(EpicAnchors instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockInteract(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) return;
|
||||
|
||||
Anchor anchor = instance.getAnchorManager().getAnchor(event.getClickedBlock().getLocation());
|
||||
|
||||
if (anchor == null) return;
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
anchor.bust();
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (instance.getCoreConfig().getMaterial("Main.Anchor Block Material", CompatibleMaterial.AIR).matches(item)) {
|
||||
if (instance.getTicksFromItem(item) == 0) return;
|
||||
|
||||
anchor.setTicksLeft(anchor.getTicksLeft() + instance.getTicksFromItem(item));
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE)
|
||||
ItemUtils.takeActiveItem(player);
|
||||
|
||||
player.playSound(player.getLocation(), CompatibleSound.ENTITY_PLAYER_LEVELUP.getSound(), 0.6F, 15.0F);
|
||||
|
||||
CompatibleParticleHandler.spawnParticles(CompatibleParticleHandler.ParticleType.SPELL_WITCH, anchor.getLocation().add(.5, .5, .5), 100, .5, .5, .5);
|
||||
|
||||
} else {
|
||||
instance.getGuiManager().showGUI(player, new GUIOverview(EpicAnchors.getInstance(), anchor, player));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
94
src/main/java/com/songoda/epicanchors/settings/Settings.java
Normal file
94
src/main/java/com/songoda/epicanchors/settings/Settings.java
Normal file
@ -0,0 +1,94 @@
|
||||
package com.songoda.epicanchors.settings;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.configuration.ConfigSetting;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Settings {
|
||||
|
||||
static final Config config = EpicAnchors.getInstance().getCoreConfig();
|
||||
|
||||
public static final ConfigSetting NAMETAG = new ConfigSetting(config, "Main.Name Tag", "&6Anchor &8(&7{REMAINING}&8)",
|
||||
"The anchor name tag used on the item and in the hologram.");
|
||||
|
||||
public static final ConfigSetting LORE = new ConfigSetting(config, "Main.Anchor Lore", "&7Place down to keep that chunk|&7loaded until the time runs out.",
|
||||
"The lore on the anchor item.");
|
||||
|
||||
public static final ConfigSetting MATERIAL = new ConfigSetting(config, "Main.Anchor Block Material", "END_PORTAL_FRAME",
|
||||
"The material an anchor is represented with?");
|
||||
|
||||
public static final ConfigSetting ADD_TIME_WITH_ECONOMY = new ConfigSetting(config, "Main.Add Time With Economy", true,
|
||||
"Should players be able to add time to their anchors",
|
||||
"by using economy?");
|
||||
|
||||
public static final ConfigSetting ECONOMY_COST = new ConfigSetting(config, "Main.Economy Cost", 5000.0,
|
||||
"The cost in economy to add 30 minutes to an anchor.");
|
||||
|
||||
public static final ConfigSetting ADD_TIME_WITH_XP = new ConfigSetting(config, "Main.Add Time With XP", true,
|
||||
"Should players be able to add time to their anchors",
|
||||
"by using experience?");
|
||||
|
||||
public static final ConfigSetting XP_COST = new ConfigSetting(config, "Main.XP Cost", 10,
|
||||
"The cost in experience to add 30 minutes to an anchor.");
|
||||
|
||||
public static final ConfigSetting ALLOW_ANCHOR_BREAKING = new ConfigSetting(config, "Main.Allow Anchor Breaking", false,
|
||||
"Should players be able to break anchors?");
|
||||
|
||||
public static final ConfigSetting HOLOGRAMS = new ConfigSetting(config, "Main.Holograms", true,
|
||||
"Toggle holograms showing above anchors.");
|
||||
|
||||
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
|
||||
"Which economy plugin should be used?",
|
||||
"Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
|
||||
|
||||
public static final ConfigSetting ECO_ICON = new ConfigSetting(config, "Interfaces.Economy Icon", "SUNFLOWER",
|
||||
"Item to be displayed as the icon for economy upgrades.");
|
||||
|
||||
public static final ConfigSetting XP_ICON = new ConfigSetting(config, "Interfaces.XP Icon", "EXPERIENCE_BOTTLE",
|
||||
"Item to be displayed as the icon for XP upgrades.");
|
||||
|
||||
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", "GRAY_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", "BLUE_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", "LIGHT_BLUE_STAINED_GLASS_PANE");
|
||||
|
||||
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
|
||||
"The enabled language file.",
|
||||
"More language files (if available) can be found in the plugins data folder.");
|
||||
|
||||
/**
|
||||
* In order to set dynamic economy comment correctly, this needs to be
|
||||
* called after EconomyManager load
|
||||
*/
|
||||
public static void setupConfig() {
|
||||
config.load();
|
||||
config.setAutoremove(true).setAutosave(true);
|
||||
|
||||
// convert glass pane settings
|
||||
int color;
|
||||
if ((color = GLASS_TYPE_1.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_1.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
if ((color = GLASS_TYPE_2.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_2.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
if ((color = GLASS_TYPE_3.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_3.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
|
||||
// convert economy settings
|
||||
if (config.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) {
|
||||
config.set("Main.Economy", "Vault");
|
||||
} else if (config.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) {
|
||||
config.set("Main.Economy", "Reserve");
|
||||
} else if (config.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) {
|
||||
config.set("Main.Economy", "PlayerPoints");
|
||||
}
|
||||
|
||||
config.saveChanges();
|
||||
}
|
||||
}
|
@ -1,16 +1,8 @@
|
||||
package com.songoda.epicanchors.utils;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import com.songoda.epicanchors.settings.Settings;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
@ -23,27 +15,11 @@ public class Methods {
|
||||
|
||||
private static Map<String, Location> serializeCache = new HashMap<>();
|
||||
|
||||
public static void takeItem(Player p, int amt) {
|
||||
if (p.getGameMode() != GameMode.CREATIVE) {
|
||||
int result = p.getInventory().getItemInHand().getAmount() - amt;
|
||||
if (result > 0) {
|
||||
ItemStack is = p.getItemInHand();
|
||||
is.setAmount(is.getAmount() - amt);
|
||||
p.setItemInHand(is);
|
||||
} else {
|
||||
p.setItemInHand(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatName(int ticks2, boolean full) {
|
||||
int hours = ((ticks2 / 20) / 60) / 60;
|
||||
int minutes = ((ticks2 / 20) / 60) - hours * 60;
|
||||
|
||||
String remaining = minutes == 0 ? String.format("%sh", hours) : String.format("%sh %sm", hours, minutes);
|
||||
String remaining = Methods.makeReadable((ticks2 / 20L) * 1000L);
|
||||
|
||||
|
||||
String name = EpicAnchorsPlugin.getInstance().getConfig().getString("Main.Name-Tag").replace("{REMAINING}", remaining);
|
||||
String name = Settings.NAMETAG.getString().replace("{REMAINING}", remaining);
|
||||
|
||||
String info = "";
|
||||
if (full) {
|
||||
@ -53,36 +29,6 @@ public class Methods {
|
||||
return info + formatText(name);
|
||||
}
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
EpicAnchorsPlugin instance = EpicAnchorsPlugin.getInstance();
|
||||
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
EpicAnchorsPlugin instance = EpicAnchorsPlugin.getInstance();
|
||||
if (type)
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
|
||||
}
|
||||
|
||||
private static ItemStack getGlass(Boolean rainbow, int type) {
|
||||
int randomNum = 1 + (int) (Math.random() * 6);
|
||||
ItemStack glass;
|
||||
if (rainbow) {
|
||||
glass = new ItemStack(EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
|
||||
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
|
||||
} else {
|
||||
glass = new ItemStack(EpicAnchorsPlugin.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
|
||||
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type);
|
||||
}
|
||||
ItemMeta glassmeta = glass.getItemMeta();
|
||||
glassmeta.setDisplayName("§l");
|
||||
glass.setItemMeta(glassmeta);
|
||||
return glass;
|
||||
}
|
||||
|
||||
|
||||
public static String formatText(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
@ -158,16 +104,56 @@ public class Methods {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the specified Unix Epoch time human readable as per the format settings in the Arconix config.
|
||||
*
|
||||
* @param time The time to convert.
|
||||
* @return A human readable string representing to specified time.
|
||||
*/
|
||||
public static String makeReadable(Long time) {
|
||||
if (time == null)
|
||||
return "";
|
||||
return String.format("%d hour(s), %d min(s), %d sec(s)", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(time);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time));
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time));
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time));
|
||||
|
||||
if (days != 0L)
|
||||
sb.append(" ").append(days).append("d");
|
||||
if (hours != 0L)
|
||||
sb.append(" ").append(hours).append("h");
|
||||
if (minutes != 0L)
|
||||
sb.append(" ").append(minutes).append("m");
|
||||
if (seconds != 0L)
|
||||
sb.append(" ").append(seconds).append("s");
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
|
||||
public static long parseTime(String input) {
|
||||
long result = 0;
|
||||
StringBuilder number = new StringBuilder();
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (Character.isDigit(c)) {
|
||||
number.append(c);
|
||||
} else if (Character.isLetter(c) && (number.length() > 0)) {
|
||||
result += convert(Integer.parseInt(number.toString()), c);
|
||||
number = new StringBuilder();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static long convert(long value, char unit) {
|
||||
switch (unit) {
|
||||
case 'd':
|
||||
return value * 1000 * 60 * 60 * 24;
|
||||
case 'h':
|
||||
return value * 1000 * 60 * 60;
|
||||
case 'm':
|
||||
return value * 1000 * 60;
|
||||
case 's':
|
||||
return value * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,8 +163,8 @@ public class Methods {
|
||||
* @return The economy formatted double.
|
||||
*/
|
||||
public static String formatEconomy(double amt) {
|
||||
DecimalFormat formatter = new DecimalFormat("#,###.00");
|
||||
return formatter.format(amt);
|
||||
}
|
||||
static DecimalFormat formatter = new DecimalFormat("#,###.00");
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
name: EpicAnchors
|
||||
description: EpicAnchors
|
||||
version: maven-version-number
|
||||
softdepend: [EpicSpawners, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault]
|
||||
main: com.songoda.epicanchors.EpicAnchorsPlugin
|
||||
softdepend: [EpicSpawners, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault, HolographicDisplays, Holograms, CMI]
|
||||
main: com.songoda.epicanchors.EpicAnchors
|
||||
author: songoda
|
||||
api-version: 1.13
|
||||
commands:
|
Loading…
Reference in New Issue
Block a user