mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-11-22 18:15:53 +01:00
Added support for 1.14.
Optimized code. Entities are now loaded. Added Updater.
This commit is contained in:
parent
500406d86a
commit
4aa38ed965
197
.gitignore
vendored
197
.gitignore
vendored
@ -1,196 +1,3 @@
|
||||
.idea/*
|
||||
\.idea/compiler\.xml
|
||||
|
||||
\.idea/encodings\.xml
|
||||
|
||||
\.idea/libraries/Arconix\.xml
|
||||
|
||||
\.idea/libraries/EpicSpawners\.xml
|
||||
|
||||
\.idea/libraries/Maven__br_net_fabiozumbi12_RedProtect_7_3_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_github_rlf_uSkyBlock_API_2_6_4\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_github_TechFortress_GriefPrevention_16_7_1\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_google_code_gson_gson_2_8_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_google_guava_guava_21_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_intellectualcrafters_PlotSquared_18_05_01\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_palmergames_Towny_0_92_0_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_commandbook_2_3\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_dummypermscompat_1_8\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_jchronic_0_2_4a\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_lib_jlibnoise_1_0_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_spigot_bukkit_classloader_check_1_8_R0_1_SNAPSHOT\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_worldedit_5_5_8\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_worldedit_worldedit_bukkit_6_1_4_SNAPSHOT\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_worldedit_worldedit_core_6_1_4_SNAPSHOT\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_sk89q_worldguard_6_1_1_SNAPSHOT\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_songoda_arconix_api_2_0_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_songoda_arconix_plugin_2_0_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_thoughtworks_paranamer_paranamer_2_6\.xml
|
||||
|
||||
\.idea/libraries/Maven__com_wasteofplastic_askyblock_3_0_8_2\.xml
|
||||
|
||||
\.idea/libraries/Maven__commons_io_commons_io_2_6\.xml
|
||||
|
||||
\.idea/libraries/Maven__commons_lang_commons_lang_2_6\.xml
|
||||
|
||||
\.idea/libraries/Maven__de_schlichtherle_truezip_6_8_3\.xml
|
||||
|
||||
\.idea/libraries/Maven__javax_persistence_persistence_api_1_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__junit_junit_4_10\.xml
|
||||
|
||||
\.idea/libraries/Maven__me_markeh_factionsframework_1_2_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__net_milkbowl_vault_VaultAPI_1_6\.xml
|
||||
|
||||
\.idea/libraries/Maven__net_sf_opencsv_opencsv_2_0\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_avaje_ebean_2_8_1\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_bukkit_bukkit_1_12_2_R0_1_SNAPSHOT\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_kingdoms_Kingdoms_13_3_40\.xml
|
||||
|
||||
\.idea/libraries/Maven__org_yaml_snakeyaml_1_19\.xml
|
||||
|
||||
\.idea/libraries/Maven__rhino_js_1_7R2\.xml
|
||||
|
||||
\.idea/libraries/spigot_1_13_1\.xml
|
||||
|
||||
\.idea/misc\.xml
|
||||
|
||||
\.idea/modules\.xml
|
||||
|
||||
\.idea/uiDesigner\.xml
|
||||
|
||||
\.idea/vcs\.xml
|
||||
|
||||
\.idea/workspace\.xml
|
||||
|
||||
EpicAnchors-API/EpicAnchors-API\.iml
|
||||
|
||||
EpicAnchors-Plugin/EpicAnchors-Plugin\.iml
|
||||
|
||||
EpicAnchors-Plugin/target/classes/en_US\.lang
|
||||
|
||||
EpicAnchors-Plugin/target/classes/plugin\.yml
|
||||
|
||||
EpicAnchors\.iml
|
||||
|
||||
out/production/EpicAnchors-Plugin/en_US\.lang
|
||||
|
||||
out/production/EpicAnchors-Plugin/plugin\.yml
|
||||
|
||||
target/classes/com/songoda/epicanchors/anchor/EAnchor\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/anchor/EAnchorManager\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/anchor/ELevel\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/anchor/ELevelManager\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/anchor/Anchor\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/anchor/AnchorManager\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/anchor/Level\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/anchor/LevelManager\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/EpicAnchors\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/EpicAnchorsAPI\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/command/AbstractCommand\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/command/CommandManager\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/command/commands/CommandEpicAnchors\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/command/commands/CommandGive\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/command/commands/CommandReload\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/EpicAnchorsPlugin\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/events/BlockListeners\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/events/InteractListeners\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/events/InventoryListeners\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/handlers/AnchorHandler\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/handlers/MenuHandler\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/Locale\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/References\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/utils/Methods\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/utils/SettingsManager\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/utils/SettingsManager\$settings\.class
|
||||
|
||||
target/classes/en_US\.lang
|
||||
|
||||
target/classes/plugin\.yml
|
||||
|
||||
\.idea/libraries/Lib\.xml
|
||||
|
||||
\.idea/libraries/Lib1\.xml
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/utils/ClaimableProtectionPluginHook\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/api/utils/ProtectionPluginHook\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookASkyBlock\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookFactions\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookGriefPrevention\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookKingdoms\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookPlotSquared\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookRedProtect\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookTowny\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookUSkyBlock\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/hooks/HookWorldGuard\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/command/AbstractCommand\$ReturnType\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/command/commands/CommandSettings\.class
|
||||
|
||||
target/classes/com/songoda/epicanchors/utils/ConfigWrapper\.class
|
||||
|
||||
target/classes/SettingDefinitions\.yml
|
||||
target/*
|
||||
EpicAnchors.iml
|
||||
|
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "EpicAnchors"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "1.1.12"
|
||||
version: "1.2"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -9,15 +9,20 @@ import com.songoda.epicanchors.api.anchor.AnchorManager;
|
||||
import com.songoda.epicanchors.api.utils.ClaimableProtectionPluginHook;
|
||||
import com.songoda.epicanchors.api.utils.ProtectionPluginHook;
|
||||
import com.songoda.epicanchors.command.CommandManager;
|
||||
import com.songoda.epicanchors.events.BlockListeners;
|
||||
import com.songoda.epicanchors.events.InteractListeners;
|
||||
import com.songoda.epicanchors.events.InventoryListeners;
|
||||
import com.songoda.epicanchors.listeners.BlockListeners;
|
||||
import com.songoda.epicanchors.listeners.InteractListeners;
|
||||
import com.songoda.epicanchors.listeners.InventoryListeners;
|
||||
import com.songoda.epicanchors.handlers.AnchorHandler;
|
||||
import com.songoda.epicanchors.handlers.MenuHandler;
|
||||
import com.songoda.epicanchors.hooks.*;
|
||||
import com.songoda.epicanchors.utils.ConfigWrapper;
|
||||
import com.songoda.epicanchors.utils.Methods;
|
||||
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.ChatColor;
|
||||
@ -43,6 +48,8 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
|
||||
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;
|
||||
@ -51,7 +58,7 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
|
||||
private CommandManager commandManager;
|
||||
|
||||
public References references = null;
|
||||
private References references;
|
||||
|
||||
private Locale locale;
|
||||
|
||||
@ -59,48 +66,36 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private boolean checkVersion() {
|
||||
int workingVersion = 13;
|
||||
int currentVersion = Integer.parseInt(Bukkit.getServer().getClass()
|
||||
.getPackage().getName().split("\\.")[3].split("_")[1]);
|
||||
|
||||
if (currentVersion < workingVersion) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You installed the 1." + workingVersion + "+ only version of " + this.getDescription().getName() + " on a 1." + currentVersion + " server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using " + this.getDescription().getName() + ".");
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
}, 20L);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Check to make sure the Bukkit version is compatible.
|
||||
if (!checkVersion()) return;
|
||||
|
||||
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(getConfig().getString("Locale", "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.menuHandler = new MenuHandler(this);
|
||||
this.anchorManager = new EAnchorManager();
|
||||
this.settingsManager = new SettingsManager(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
setupConfig();
|
||||
|
||||
loadAnchorsFromFile();
|
||||
|
||||
new AnchorHandler(this);
|
||||
@ -251,6 +246,21 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
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;
|
||||
}
|
||||
@ -271,4 +281,8 @@ public class EpicAnchorsPlugin extends JavaPlugin implements EpicAnchors {
|
||||
public AnchorManager getAnchorManager() {
|
||||
return anchorManager;
|
||||
}
|
||||
|
||||
public References getReferences() {
|
||||
return references;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.songoda.epicanchors;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -23,11 +22,10 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class Locale {
|
||||
|
||||
private static JavaPlugin plugin;
|
||||
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;
|
||||
@ -52,6 +50,212 @@ public class Locale {
|
||||
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)
|
||||
@ -168,197 +372,4 @@ public class Locale {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 path the path to the 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(String path, 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)) {
|
||||
IOUtils.copy(plugin.getResource(fileName), 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("", 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;
|
||||
}
|
||||
|
||||
}
|
@ -52,7 +52,7 @@ public class CommandManager implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage(instance.references.getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -64,12 +64,12 @@ public class CommandManager implements CommandExecutor {
|
||||
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.references.getPrefix() + Methods.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(instance.references.getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
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.references.getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission"));
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
|
@ -14,7 +14,7 @@ public class CommandEpicAnchors extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||
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())) {
|
||||
|
@ -19,7 +19,7 @@ public class CommandGive extends AbstractCommand {
|
||||
if (args.length != 3) return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
if (Bukkit.getPlayer(args[1]) == null && !args[1].trim().toLowerCase().equals("all")) {
|
||||
sender.sendMessage("Not a player...");
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "Not a player...");
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
@ -28,11 +28,11 @@ public class CommandGive extends AbstractCommand {
|
||||
if (!args[1].trim().toLowerCase().equals("all")) {
|
||||
Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer();
|
||||
player.getInventory().addItem(itemStack);
|
||||
player.sendMessage(Methods.formatText(instance.getLocale().getMessage("command.give.success")));
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success"));
|
||||
} else {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
player.getInventory().addItem(itemStack);
|
||||
player.sendMessage(Methods.formatText(instance.getLocale().getMessage("command.give.success")));
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.give.success"));
|
||||
}
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
|
@ -14,7 +14,7 @@ public class CommandReload extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(EpicAnchorsPlugin instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
sender.sendMessage(Methods.formatText(instance.references.getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.songoda.epicanchors.handlers;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import com.songoda.epicspawners.api.EpicSpawnersAPI;
|
||||
import com.songoda.epicspawners.api.spawner.Spawner;
|
||||
import net.minecraft.server.v1_14_R1.EntityInsentient;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AnchorHandler {
|
||||
|
||||
@ -24,14 +24,14 @@ public class AnchorHandler {
|
||||
|
||||
epicSpawners = instance.getServer().getPluginManager().getPlugin("EpicSpawners") != null;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::doAnchorCheck, 0, 20); //ToDo: way to fast.
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, this::doAnchorCheck, 0, 1); //ToDo: way to fast.
|
||||
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 == null || location1.getWorld() == null) continue;
|
||||
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));
|
||||
@ -56,6 +56,14 @@ public class AnchorHandler {
|
||||
Chunk chunk = location.getChunk();
|
||||
chunk.load();
|
||||
|
||||
// Load entities
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
if (!(entity instanceof LivingEntity)) continue;
|
||||
|
||||
((EntityInsentient)entity).movementTick();
|
||||
|
||||
}
|
||||
|
||||
int ticksLeft = anchor.getTicksLeft();
|
||||
anchor.setTicksLeft(ticksLeft - 20);
|
||||
|
||||
|
@ -1,16 +1,12 @@
|
||||
package com.songoda.epicanchors.events;
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.PortalType;
|
||||
import org.bukkit.Sound;
|
||||
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.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityCreatePortalEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicanchors.events;
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
||||
import com.songoda.epicanchors.api.anchor.Anchor;
|
@ -1,4 +1,4 @@
|
||||
package com.songoda.epicanchors.events;
|
||||
package com.songoda.epicanchors.listeners;
|
||||
|
||||
import com.songoda.epicanchors.EpicAnchorsPlugin;
|
||||
import com.songoda.epicanchors.anchor.EAnchor;
|
@ -50,35 +50,27 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
try {
|
||||
EpicAnchorsPlugin instance = EpicAnchorsPlugin.getInstance();
|
||||
return getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return null;
|
||||
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) {
|
||||
try {
|
||||
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"));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return null;
|
||||
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(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum);
|
||||
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(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type);
|
||||
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");
|
||||
|
@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -22,9 +22,8 @@ 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 static ConfigWrapper defs;
|
||||
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<>();
|
||||
@ -32,10 +31,6 @@ public class SettingsManager implements Listener {
|
||||
|
||||
public SettingsManager(EpicAnchorsPlugin plugin) {
|
||||
this.instance = plugin;
|
||||
|
||||
plugin.saveResource("SettingDefinitions.yml", true);
|
||||
defs = new ConfigWrapper(plugin, "", "SettingDefinitions.yml");
|
||||
defs.createNewFile("Loading data file", pluginName + " SettingDefinitions file");
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@ -49,14 +44,14 @@ public class SettingsManager implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
|
||||
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.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
|
||||
} else if (event.getView().getTitle().equals(pluginName + " Settings Editor")) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
@ -88,18 +83,19 @@ public class SettingsManager implements Listener {
|
||||
config.set(value, event.getMessage());
|
||||
}
|
||||
|
||||
this.finishEditing(player);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicAnchorsPlugin.getInstance(), () ->
|
||||
this.finishEditing(player), 0L);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void finishEditing(Player player) {
|
||||
private void finishEditing(Player player) {
|
||||
this.current.remove(player);
|
||||
this.instance.saveConfig();
|
||||
this.openEditor(player);
|
||||
}
|
||||
|
||||
|
||||
public void editObject(Player player, String current) {
|
||||
private void editObject(Player player, String current) {
|
||||
this.current.put(player, ChatColor.stripColor(current));
|
||||
|
||||
player.closeInventory();
|
||||
@ -120,7 +116,7 @@ public class SettingsManager implements Listener {
|
||||
|
||||
int slot = 10;
|
||||
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
|
||||
ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
|
||||
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));
|
||||
@ -132,7 +128,7 @@ public class SettingsManager implements Listener {
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void openEditor(Player player) {
|
||||
private void openEditor(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
@ -151,20 +147,10 @@ public class SettingsManager implements Listener {
|
||||
item.setType(Material.PAPER);
|
||||
lore.add(Methods.formatText("&9" + config.getString(fKey)));
|
||||
} else if (config.isInt(fKey)) {
|
||||
item.setType(Material.CLOCK);
|
||||
item.setType(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&5" + config.getInt(fKey)));
|
||||
}
|
||||
|
||||
if (defs.getConfig().contains(fKey)) {
|
||||
String text = defs.getConfig().getString(key);
|
||||
|
||||
Matcher m = SETTINGS_PATTERN.matcher(text);
|
||||
while (m.find()) {
|
||||
if (m.end() != text.length() || m.group().length() != 0)
|
||||
lore.add(Methods.formatText("&7" + m.group()));
|
||||
}
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
@ -176,15 +162,17 @@ public class SettingsManager implements Listener {
|
||||
}
|
||||
|
||||
public void updateSettings() {
|
||||
for (settings s : settings.values()) {
|
||||
instance.getConfig().addDefault(s.setting, s.option);
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
for (Setting setting : Setting.values()) {
|
||||
config.addDefault(setting.setting, setting.option);
|
||||
}
|
||||
}
|
||||
|
||||
public enum settings {
|
||||
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", "END_PORTAL_FRAME"),
|
||||
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),
|
||||
@ -194,15 +182,36 @@ public class SettingsManager implements Listener {
|
||||
o10("Interfaces.XP Icon", "EXPERIENCE_BOTTLE"),
|
||||
o11("Interfaces.Glass Type 1", 7),
|
||||
o12("Interfaces.Glass Type 2", 11),
|
||||
o13("Interfaces.Glass Type 3", 3);
|
||||
o13("Interfaces.Glass Type 3", 3),
|
||||
|
||||
LANGUGE_MODE("System.Language Mode", "en_US");
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
|
||||
settings(String setting, 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); }
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
40
pom.xml
40
pom.xml
@ -34,6 +34,39 @@
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shaded</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.songoda:songodaupdater</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
@ -53,7 +86,12 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13.2</version>
|
||||
<version>1.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>songodaupdater</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org</groupId>
|
||||
|
Loading…
Reference in New Issue
Block a user