Added SongodaCore, Updated to support 1.15

This commit is contained in:
Brianna 2019-12-28 16:00:25 -05:00
parent 716375e112
commit 2ce8ea7a00
18 changed files with 87 additions and 746 deletions

View File

@ -1,21 +0,0 @@
stages:
- build
variables:
name: "EpicEnchants"
path: "/builds/$CI_PROJECT_PATH"
version: "1.0.10"
build:
stage: build
image: maven:3.5.3-jdk-8
script:
- find $path/ -type f -name "*.xml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g
- find $path/ -type f -name "*.yml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g
- mvn clean package
- find $path/ -depth -path '*original*' -delete
- mv $path/target/*.jar $path/
artifacts:
name: $name-$version
paths:
- "$path/*.jar"

53
pom.xml
View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>EpicEnchants</artifactId> <artifactId>EpicEnchants</artifactId>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>maven-version-number</version> <version>1.1</version>
<build> <build>
<defaultGoal>clean install</defaultGoal> <defaultGoal>clean install</defaultGoal>
<finalName>EpicEnchants-${project.version}</finalName> <finalName>EpicEnchants-${project.version}</finalName>
@ -16,6 +16,28 @@
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.build.directory}/classes/plugin.yml</file>
<replacements>
<replacement>
<token>maven-version-number</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
@ -32,7 +54,7 @@
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet> <artifactSet>
<includes> <includes>
<include>com.songoda:songodaupdater</include> <include>com.songoda:SongodaCore</include>
<include>fr.mymicky:FastInv</include> <include>fr.mymicky:FastInv</include>
</includes> </includes>
</artifactSet> </artifactSet>
@ -58,10 +80,6 @@
<id>private</id> <id>private</id>
<url>http://repo.songoda.com/artifactory/private/</url> <url>http://repo.songoda.com/artifactory/private/</url>
</repository> </repository>
<repository>
<id>reserve-repo</id>
<url>https://dl.bintray.com/theneweconomy/java/</url>
</repository>
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
@ -72,7 +90,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.14.4</version> <version>1.15</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.mrmicky</groupId> <groupId>fr.mrmicky</groupId>
@ -82,24 +100,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>songodaupdater</artifactId> <artifactId>SongodaCore</artifactId>
<version>1</version> <version>LATEST</version>
</dependency> <scope>compile</scope>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>Reserve</artifactId>
<version>0.1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.black_ixx</groupId>
<artifactId>playerpoints</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>net.milkbowl</groupId>
<artifactId>vault</artifactId>
<version>1.7.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>

View File

@ -1,10 +1,11 @@
package com.songoda.epicenchants; package com.songoda.epicenchants;
import com.songoda.core.SongodaCore;
import com.songoda.core.SongodaPlugin;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicenchants.command.CommandManager; import com.songoda.epicenchants.command.CommandManager;
import com.songoda.epicenchants.economy.Economy;
import com.songoda.epicenchants.economy.PlayerPointsEconomy;
import com.songoda.epicenchants.economy.ReserveEconomy;
import com.songoda.epicenchants.economy.VaultEconomy;
import com.songoda.epicenchants.listeners.ArmorListener; import com.songoda.epicenchants.listeners.ArmorListener;
import com.songoda.epicenchants.listeners.EntityListener; import com.songoda.epicenchants.listeners.EntityListener;
import com.songoda.epicenchants.listeners.PlayerListener; import com.songoda.epicenchants.listeners.PlayerListener;
@ -16,27 +17,21 @@ import com.songoda.epicenchants.managers.*;
import com.songoda.epicenchants.objects.Enchant; import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.EnchantUtils; import com.songoda.epicenchants.utils.EnchantUtils;
import com.songoda.epicenchants.utils.Metrics; import com.songoda.epicenchants.utils.Metrics;
import com.songoda.epicenchants.utils.ServerVersion;
import com.songoda.epicenchants.utils.SpecialItems; import com.songoda.epicenchants.utils.SpecialItems;
import com.songoda.epicenchants.utils.locale.Locale;
import com.songoda.epicenchants.utils.objects.FastInv; import com.songoda.epicenchants.utils.objects.FastInv;
import com.songoda.epicenchants.utils.settings.Setting; import com.songoda.epicenchants.utils.settings.Setting;
import com.songoda.epicenchants.utils.settings.SettingsManager; import com.songoda.epicenchants.utils.settings.SettingsManager;
import com.songoda.epicenchants.utils.single.ItemGroup; import com.songoda.epicenchants.utils.single.ItemGroup;
import com.songoda.epicenchants.utils.updateModules.LocaleModule;
import com.songoda.update.Plugin;
import com.songoda.update.SongodaUpdate;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color; import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static org.bukkit.Bukkit.getConsoleSender; import static org.bukkit.Bukkit.getConsoleSender;
public class EpicEnchants extends JavaPlugin { public class EpicEnchants extends SongodaPlugin {
private static EpicEnchants INSTANCE; private static EpicEnchants INSTANCE;
@ -48,12 +43,7 @@ public class EpicEnchants extends JavaPlugin {
private SettingsManager settingsManager; private SettingsManager settingsManager;
private CommandManager commandManager; private CommandManager commandManager;
private Locale locale;
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
private SpecialItems specialItems; private SpecialItems specialItems;
private Economy economy;
private EnchantUtils enchantUtils; private EnchantUtils enchantUtils;
private ItemGroup itemGroup; private ItemGroup itemGroup;
@ -62,25 +52,21 @@ public class EpicEnchants extends JavaPlugin {
} }
@Override @Override
public void onEnable() { public void onPluginLoad() {
INSTANCE = this; INSTANCE = this;
}
getConsoleSender().sendMessage(color("&a=============================")); @Override
getConsoleSender().sendMessage(color("&7" + getDescription().getName() + " " + getDescription().getVersion() + " by &5Songoda <3&7!")); public void onPluginEnable() {
getConsoleSender().sendMessage(color("&7Action: &aEnabling&7...")); // Run Songoda Updater
SongodaCore.registerPlugin(this, 67, CompatibleMaterial.DIAMOND_SWORD);
// Setup Setting Manager // Setup Setting Manager
this.settingsManager = new SettingsManager(this); this.settingsManager = new SettingsManager(this);
this.settingsManager.setupConfig(); this.settingsManager.setupConfig();
// Setup Language // Setup Language
new Locale(this, "en_US"); this.setLocale(getConfig().getString("System.Language Mode"), false);
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
// Running Songoda Updater
Plugin plugin = new Plugin(this, 67);
plugin.addModule(new LocaleModule());
SongodaUpdate.load(plugin);
preload(); preload();
@ -109,13 +95,19 @@ public class EpicEnchants extends JavaPlugin {
pluginManager.registerEvents(new BlackScrollListener(this), this); pluginManager.registerEvents(new BlackScrollListener(this), this);
pluginManager.registerEvents(new DustListener(this), this); pluginManager.registerEvents(new DustListener(this), this);
String economyPlugin = null;
// Setup Economy // Setup Economy
if (Setting.VAULT_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Vault")) if (Setting.VAULT_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Vault"))
this.economy = new VaultEconomy(); economyPlugin = "Vault";
else if (Setting.RESERVE_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Reserve")) else if (Setting.RESERVE_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Reserve"))
this.economy = new ReserveEconomy(); economyPlugin = "Reserve";
else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("PlayerPoints")) else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("PlayerPoints"))
this.economy = new PlayerPointsEconomy(); economyPlugin = "PlayerPoints";
EconomyManager.load();
if (economyPlugin != null)
EconomyManager.getManager().setPreferredHook(economyPlugin);
// Start Metrics // Start Metrics
new Metrics(this); new Metrics(this);
@ -123,8 +115,6 @@ public class EpicEnchants extends JavaPlugin {
if (!enchantManager.getValues().isEmpty()) { if (!enchantManager.getValues().isEmpty()) {
getLogger().info("Successfully loaded enchants: " + enchantManager.getValues().stream().map(Enchant::getIdentifier).collect(Collectors.joining(", "))); getLogger().info("Successfully loaded enchants: " + enchantManager.getValues().stream().map(Enchant::getIdentifier).collect(Collectors.joining(", ")));
} }
getConsoleSender().sendMessage(color("&a============================="));
} }
private void preload() { private void preload() {
@ -134,13 +124,23 @@ public class EpicEnchants extends JavaPlugin {
} }
@Override @Override
public void onDisable() { public void onPluginDisable() {
getConsoleSender().sendMessage(color("&a=============================")); getConsoleSender().sendMessage(color("&a============================="));
getConsoleSender().sendMessage(color("&7" + getDescription().getName() + " " + getDescription().getVersion() + " by &5Songoda <3&7!")); getConsoleSender().sendMessage(color("&7" + getDescription().getName() + " " + getDescription().getVersion() + " by &5Songoda <3&7!"));
getConsoleSender().sendMessage(color("&7Action: &cDisabling&7...")); getConsoleSender().sendMessage(color("&7Action: &cDisabling&7..."));
getConsoleSender().sendMessage(color("&a=============================")); getConsoleSender().sendMessage(color("&a============================="));
} }
@Override
public void onConfigReload() {
}
@Override
public List<Config> getExtraConfig() {
return null;
}
public void reload() { public void reload() {
reloadConfig(); reloadConfig();
@ -156,26 +156,10 @@ public class EpicEnchants extends JavaPlugin {
infoManager.clear(); infoManager.clear();
infoManager.loadMenus(); infoManager.loadMenus();
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode")); this.setLocale(getConfig().getString("System.Language Mode"), true);
this.locale.reloadMessages(); this.locale.reloadMessages();
} }
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 EnchantManager getEnchantManager() { public EnchantManager getEnchantManager() {
return this.enchantManager; return this.enchantManager;
} }
@ -200,10 +184,6 @@ public class EpicEnchants extends JavaPlugin {
return this.specialItems; return this.specialItems;
} }
public Economy getEconomy() {
return this.economy;
}
public EnchantUtils getEnchantUtils() { public EnchantUtils getEnchantUtils() {
return this.enchantUtils; return this.enchantUtils;
} }
@ -212,10 +192,6 @@ public class EpicEnchants extends JavaPlugin {
return this.itemGroup; return this.itemGroup;
} }
public Locale getLocale() {
return locale;
}
public CommandManager getCommandManager() { public CommandManager getCommandManager() {
return commandManager; return commandManager;
} }

View File

@ -1,15 +0,0 @@
package com.songoda.epicenchants.economy;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public interface Economy {
boolean hasBalance(OfflinePlayer player, double cost);
double getBalance(Player player);
boolean withdrawBalance(OfflinePlayer player, double cost);
boolean deposit(OfflinePlayer player, double amount);
}

View File

@ -1,44 +0,0 @@
package com.songoda.epicenchants.economy;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class PlayerPointsEconomy implements Economy {
private final PlayerPoints playerPoints;
public PlayerPointsEconomy() {
this.playerPoints = (PlayerPoints) Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints");
}
private int convertAmount(double amount) {
return (int) Math.ceil(amount);
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
int amount = convertAmount(cost);
return playerPoints.getAPI().look(player.getUniqueId()) >= amount;
}
@Override
public double getBalance(Player player) {
return playerPoints.getAPI().look(player.getUniqueId());
}
@Override
public boolean withdrawBalance(OfflinePlayer player, double cost) {
int amount = convertAmount(cost);
return playerPoints.getAPI().take(player.getUniqueId(), amount);
}
@Override
public boolean deposit(OfflinePlayer player, double amount) {
int amt = convertAmount(amount);
return playerPoints.getAPI().give(player.getUniqueId(), amt);
}
}

View File

@ -1,38 +0,0 @@
package com.songoda.epicenchants.economy;
import net.tnemc.core.Reserve;
import net.tnemc.core.economy.EconomyAPI;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.math.BigDecimal;
public class ReserveEconomy implements Economy {
EconomyAPI economyAPI;
public ReserveEconomy() {
if (Reserve.instance().economyProvided())
economyAPI = Reserve.instance().economy();
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost));
}
@Override
public double getBalance(Player player) {
return economyAPI.getHoldings(player.getUniqueId()).doubleValue();
}
@Override
public boolean withdrawBalance(OfflinePlayer player, double cost) {
return economyAPI.removeHoldings(player.getUniqueId(), new BigDecimal(cost));
}
@Override
public boolean deposit(OfflinePlayer player, double amount) {
return economyAPI.addHoldings(player.getUniqueId(), new BigDecimal(amount));
}
}

View File

@ -1,34 +0,0 @@
package com.songoda.epicenchants.economy;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class VaultEconomy implements Economy {
private final net.milkbowl.vault.economy.Economy vault;
public VaultEconomy() {
this.vault = Bukkit.getServicesManager().
getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider();
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
return vault.has(player, cost);
}
@Override
public double getBalance(Player player) {
return vault.getBalance(player);
}
@Override
public boolean withdrawBalance(OfflinePlayer player, double cost) {
return vault.withdrawPlayer(player, cost).transactionSuccess();
}
@Override
public boolean deposit(OfflinePlayer player, double amount) {
return vault.depositPlayer(player, amount).transactionSuccess();
}
}

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.managers; package com.songoda.epicenchants.managers;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.ServerVersion;
import com.songoda.epicenchants.utils.objects.FileLocation; import com.songoda.epicenchants.utils.objects.FileLocation;
import com.songoda.epicenchants.utils.settings.Setting; import com.songoda.epicenchants.utils.settings.Setting;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -81,8 +81,8 @@ public class FileManager extends Manager<String, FileConfiguration> {
public FileManager(EpicEnchants instance) { public FileManager(EpicEnchants instance) {
super(instance); super(instance);
directory = instance.isServerVersionAtLeast(ServerVersion.V1_13) ? "master" : "legacy"; directory = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? "master" : "legacy";
Bukkit.getConsoleSender().sendMessage("Using the " + directory + " configurations because version is " + instance.getServerVersion().name()); Bukkit.getConsoleSender().sendMessage("Using the " + directory + " configurations because version is " + ServerVersion.getServerVersion().name());
} }
public void loadFiles() { public void loadFiles() {

View File

@ -1,5 +1,6 @@
package com.songoda.epicenchants.menus; package com.songoda.epicenchants.menus;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant; import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group; import com.songoda.epicenchants.objects.Group;
@ -263,12 +264,12 @@ public class AlchemistMenu extends FastInv {
of("eco_cost", ecoCost), of("eco_cost", ecoCost),
of("exp_cost", expCost) of("exp_cost", expCost)
).build(), event -> { ).build(), event -> {
if (!instance.getEconomy().hasBalance(event.getPlayer(), ecoCost) || getExp(event.getPlayer()) < expCost) { if (!EconomyManager.hasBalance(event.getPlayer(), ecoCost) || getExp(event.getPlayer()) < expCost) {
instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer()); instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer());
return; return;
} }
instance.getEconomy().withdrawBalance(event.getPlayer(), ecoCost); EconomyManager.withdrawBalance(event.getPlayer(), ecoCost);
changeExp(event.getPlayer(), -expCost); changeExp(event.getPlayer(), -expCost);
instance.getLocale().getMessage("alchemist.success") instance.getLocale().getMessage("alchemist.success")
.processPlaceholder("eco_cost", ecoCost) .processPlaceholder("eco_cost", ecoCost)

View File

@ -1,5 +1,6 @@
package com.songoda.epicenchants.menus; package com.songoda.epicenchants.menus;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group; import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.objects.FastInv; import com.songoda.epicenchants.utils.objects.FastInv;
@ -36,8 +37,8 @@ public class EnchanterMenu extends FastInv {
int ecoCost = section.getInt("eco-cost"); int ecoCost = section.getInt("eco-cost");
int xpLeft = Math.max(expCost - player.getLevel(), 0); int xpLeft = Math.max(expCost - player.getLevel(), 0);
double ecoLeft = 0.0d; double ecoLeft = 0.0d;
if (instance.getEconomy() != null) if (EconomyManager.isEnabled())
ecoLeft = ecoCost - instance.getEconomy().getBalance(player) < 0 ? 0 : ecoCost - instance.getEconomy().getBalance(player); ecoLeft = ecoCost - EconomyManager.getBalance(player) < 0 ? 0 : ecoCost - EconomyManager.getBalance(player);
Group group = instance.getGroupManager().getValue(section.getString("group").toUpperCase()) Group group = instance.getGroupManager().getValue(section.getString("group").toUpperCase())
.orElseThrow(() -> new IllegalArgumentException("Invalid group set in enchanter: " + section.getString("group"))); .orElseThrow(() -> new IllegalArgumentException("Invalid group set in enchanter: " + section.getString("group")));
ItemStack itemStack = new ItemBuilder(section, ItemStack itemStack = new ItemBuilder(section,
@ -52,13 +53,13 @@ public class EnchanterMenu extends FastInv {
return; return;
} }
if (instance.getEconomy() != null && !instance.getEconomy().hasBalance((player), ecoCost) || getExp(player) < expCost) { if (EconomyManager.isEnabled() && !EconomyManager.hasBalance((player), ecoCost) || getExp(player) < expCost) {
instance.getLocale().getMessage("enchanter.cannotafford").sendPrefixedMessage(player); instance.getLocale().getMessage("enchanter.cannotafford").sendPrefixedMessage(player);
return; return;
} }
if (instance.getEconomy() != null) { if (EconomyManager.isEnabled()) {
instance.getEconomy().withdrawBalance(player, ecoCost); EconomyManager.withdrawBalance(player, ecoCost);
instance.getLocale().getMessage("enchanter.success") instance.getLocale().getMessage("enchanter.success")
.processPlaceholder("group_name", group.getName()) .processPlaceholder("group_name", group.getName())
.processPlaceholder("group_color", group.getColor()) .processPlaceholder("group_color", group.getColor())

View File

@ -1,5 +1,6 @@
package com.songoda.epicenchants.utils; package com.songoda.epicenchants.utils;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.EpicEnchants;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -25,10 +26,10 @@ public class Methods {
int randomNum = 1 + (int) (Math.random() * 6); int randomNum = 1 + (int) (Math.random() * 6);
ItemStack glass; ItemStack glass;
if (rainbow) { if (rainbow) {
glass = new ItemStack(EpicEnchants.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? glass = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
} else { } else {
glass = new ItemStack(EpicEnchants.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? glass = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type); Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type);
} }
ItemMeta glassmeta = glass.getItemMeta(); ItemMeta glassmeta = glass.getItemMeta();

View File

@ -1,27 +0,0 @@
package com.songoda.epicenchants.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;
}
}

View File

@ -1,302 +0,0 @@
package com.songoda.epicenchants.utils.locale;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.util.ArrayList;
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 utilization of localization files.
* Created to be used by the Songoda Team.
*
* @author Brianna O'Keefe - Songoda
*/
public class Locale {
private static final List<Locale> LOCALES = new ArrayList<>();
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 final Map<String, String> nodes = new HashMap<>();
private static String defaultLocale;
private File file;
private String name;
/**
* Instantiate the Locale class for future use
*
* @param name the name of the instantiated language
*/
private Locale(String name) {
if (plugin == null)
return;
this.name = name;
String fileName = name + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
if (!this.reloadMessages()) return;
plugin.getLogger().info("Loaded locale \"" + fileName + "\"");
}
/**
* Initialize the class to load all existing language files and update them.
* This must be called before any other methods in this class as otherwise
* the methods will fail to invoke
*
* @param plugin the plugin instance
* @param defaultLocale the default language
*/
public Locale(JavaPlugin plugin, String defaultLocale) {
Locale.plugin = plugin;
Locale.localeFolder = new File(plugin.getDataFolder(), "locales/");
if (!localeFolder.exists()) localeFolder.mkdirs();
//Save the default locale file.
Locale.defaultLocale = defaultLocale;
saveLocale(defaultLocale);
for (File file : localeFolder.listFiles()) {
String fileName = file.getName();
if (!fileName.endsWith(FILE_EXTENSION)) continue;
String name = fileName.substring(0, fileName.lastIndexOf('.'));
if (name.split("_").length != 2) continue;
if (localeLoaded(name)) continue;
LOCALES.add(new Locale(name));
}
}
/**
* Save a locale file from the InputStream, 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 saveLocale(String fileName) {
return saveLocale(plugin.getResource(defaultLocale + FILE_EXTENSION), fileName);
}
/**
* Save a locale file from the InputStream, 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 saveLocale(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(in, destinationFile);
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
copy(in, outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
if (fileName.split("_").length != 2) return false;
LOCALES.add(new Locale(fileName));
if (defaultLocale == null) defaultLocale = fileName;
return true;
} catch (IOException e) {
return false;
}
}
// Write new changes to existing files, if any at all
private static boolean compareFiles(InputStream in, File existingFile) {
InputStream defaultFile =
in == null ? plugin.getResource((defaultLocale != null ? defaultLocale : "en_US") + FILE_EXTENSION) : in;
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();
// Leave a note alerting the user of the newly added messages.
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + ".");
// If changes were found outside of the default file leave a note explaining that.
if (in == null) {
writer.newLine();
writer.write("# These translations were found untranslated, join");
writer.newLine();
writer.write("# our translation Discord https://discord.gg/f7fpZEf");
writer.newLine();
writer.write("# to request an official update!");
}
}
writer.newLine();
writer.write(defaultValue);
changed = true;
}
}
if (in != null && !changed) compareFiles(null, existingFile);
} catch (IOException e) {
return false;
}
return changed;
}
/**
* 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 localeLoaded(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equals(name)) return true;
return false;
}
/**
* 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.getName().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* 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.trim().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;
}
/**
* Supply the Message object with the plugins prefix.
*
* @param message message to be applied
* @return applied message
*/
private Message supplyPrefix(Message message) {
return message.setPrefix(this.nodes.getOrDefault("general.nametag.prefix", "[Plugin]"));
}
/**
* Create a new unsaved Message
*
* @param message the message to create
* @return the created message
*/
public Message newMessage(String message) {
return supplyPrefix(new Message(message));
}
/**
* Get a message set for a specific node.
*
* @param node the node to get
* @return the message for the specified node
*/
public Message getMessage(String node) {
return this.getMessageOrDefault(node, node);
}
/**
* 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 Message getMessageOrDefault(String node, String defaultValue) {
return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
}
/**
* Return the locale name (i.e. "en_US")
*
* @return the locale name
*/
public String getName() {
return name;
}
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();
}
}
}

View File

@ -1,128 +0,0 @@
package com.songoda.epicenchants.utils.locale;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* The Message object. This holds the message to be sent
* as well as the plugins prefix so that they can both be
* easily manipulated then deployed
*/
public class Message {
private String prefix = null;
private String message;
/**
* create a new message
*
* @param message the message text
*/
public Message(String message) {
this.message = message;
}
/**
* Format and send the held message to a player
*
* @param player player to send the message to
*/
public void sendMessage(Player player) {
player.sendMessage(this.getMessage());
}
/**
* Format and send the held message with the
* appended plugin prefix to a player
*
* @param player player to send the message to
*/
public void sendPrefixedMessage(Player player) {
player.sendMessage(this.getPrefixedMessage());
}
/**
* Format and send the held message to a player
*
* @param sender command sender to send the message to
*/
public void sendMessage(CommandSender sender) {
sender.sendMessage(this.getMessage());
}
/**
* Format and send the held message to a player as a title message
*
* @param sender command sender to send the message to
*/
public void sendTitle(CommandSender sender) {
if(sender instanceof Player) {
((Player) sender).sendTitle("", this.getMessage(), 10, 20, 10);
} else {
sender.sendMessage(this.getMessage());
}
}
/**
* Format and send the held message with the
* appended plugin prefix to a command sender
*
* @param sender command sender to send the message to
*/
public void sendPrefixedMessage(CommandSender sender) {
sender.sendMessage(this.getPrefixedMessage());
}
/**
* Format the held message and append the plugins
* prefix
*
* @return the prefixed message
*/
public String getPrefixedMessage() {
return ChatColor.translateAlternateColorCodes('&',(prefix == null ? "" : this.prefix)
+ " " + this.message);
}
/**
* Get and format the held message
*
* @return the message
*/
public String getMessage() {
return ChatColor.translateAlternateColorCodes('&', this.message);
}
/**
* Get the held message
*
* @return the message
*/
public String getUnformattedMessage() {
return this.message;
}
/**
* Replace the provided placeholder with the
* provided object
*
* @param placeholder the placeholder to replace
* @param replacement the replacement object
* @return the modified Message
*/
public Message processPlaceholder(String placeholder, Object replacement) {
this.message = message.replace("{" + placeholder + "}", replacement.toString());
return this;
}
Message setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String toString() {
return this.message;
}
}

View File

@ -254,7 +254,7 @@ public class ItemBuilder {
} }
public ItemBuilder unbreakable(boolean unbreakable) { public ItemBuilder unbreakable(boolean unbreakable) {
meta.spigot().setUnbreakable(unbreakable); meta.setUnbreakable(unbreakable);
return this; return this;
} }
@ -304,6 +304,6 @@ public class ItemBuilder {
* Unbreakability: * Unbreakability:
*/ */
public boolean isUnbreakable() { public boolean isUnbreakable() {
return meta.spigot().isUnbreakable(); return meta.isUnbreakable();
} }
} }

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.utils.settings; package com.songoda.epicenchants.utils.settings;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.Methods; import com.songoda.epicenchants.utils.Methods;
import com.songoda.epicenchants.utils.ServerVersion;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -119,7 +119,7 @@ public class SettingsManager implements Listener {
int slot = 10; int slot = 10;
for (String key : plugin.getConfig().getDefaultSection().getKeys(false)) { for (String key : plugin.getConfig().getDefaultSection().getKeys(false)) {
ItemStack item = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.LEGACY_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9)); ItemStack item = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.LEGACY_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9));
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category."))); meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
meta.setDisplayName(Methods.formatText("&f&l" + key)); meta.setDisplayName(Methods.formatText("&f&l" + key));
@ -150,13 +150,13 @@ public class SettingsManager implements Listener {
item.setType(Material.PAPER); item.setType(Material.PAPER);
lore.add(Methods.formatText("&7" + config.getString(fKey))); lore.add(Methods.formatText("&7" + config.getString(fKey)));
} else if (config.isInt(fKey)) { } else if (config.isInt(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); item.setType(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getInt(fKey))); lore.add(Methods.formatText("&7" + config.getInt(fKey)));
} else if (config.isLong(fKey)) { } else if (config.isLong(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); item.setType(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getLong(fKey))); lore.add(Methods.formatText("&7" + config.getLong(fKey)));
} else if (config.isDouble(fKey)) { } else if (config.isDouble(fKey)) {
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); item.setType(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
lore.add(Methods.formatText("&7" + config.getDouble(fKey))); lore.add(Methods.formatText("&7" + config.getDouble(fKey)));
} }

View File

@ -2,8 +2,8 @@ package com.songoda.epicenchants.utils.single;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicenchants.EpicEnchants; import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.ServerVersion;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Material; import org.bukkit.Material;
@ -19,7 +19,7 @@ public class ItemGroup {
public ItemGroup(EpicEnchants instance) { public ItemGroup(EpicEnchants instance) {
groupMap = HashMultimap.create(); groupMap = HashMultimap.create();
if (instance.isServerVersionAtLeast(ServerVersion.V1_13)) setupMaster(); if (com.songoda.core.compatibility.ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) setupMaster();
else setupLegacy(); else setupLegacy();
} }

View File

@ -1,32 +0,0 @@
package com.songoda.epicenchants.utils.updateModules;
import com.songoda.epicenchants.EpicEnchants;
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();
EpicEnchants.getInstance().getLocale().saveLocale(in, (String) file.get("name"));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}