mirror of
https://github.com/songoda/UltimateRepairing.git
synced 2024-11-26 04:25:17 +01:00
core update, return items if too expensive, fix creative mistakenly destroying anvil settings
This commit is contained in:
parent
78c145642b
commit
269a352bf9
44
pom.xml
44
pom.xml
@ -32,7 +32,7 @@
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.songoda:songodaupdater</include>
|
||||
<include>com.songoda:SongodaCore</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
@ -45,6 +45,12 @@
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.songoda.core</pattern>
|
||||
<shadedPattern>${project.groupId}.ultimatekits.core</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@ -57,42 +63,22 @@
|
||||
<url>http://repo.songoda.com/artifactory/private/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>reserve-repo</id>
|
||||
<url>https://dl.bintray.com/theneweconomy/java/</url>
|
||||
<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.1</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>net.milkbowl</groupId>
|
||||
<artifactId>vault</artifactId>
|
||||
<version>1.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
|
||||
<artifactId>holographicdisplays-api</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.black_ixx</groupId>
|
||||
<artifactId>playerpoints</artifactId>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.tnemc</groupId>
|
||||
<artifactId>Reserve</artifactId>
|
||||
<version>0.1.3.0</version>
|
||||
<scope>provided</scope>
|
||||
<artifactId>SongodaCore</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,162 +1,127 @@
|
||||
package com.songoda.ultimaterepairing;
|
||||
|
||||
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.ultimaterepairing.anvil.AnvilManager;
|
||||
import com.songoda.ultimaterepairing.anvil.UAnvil;
|
||||
import com.songoda.ultimaterepairing.anvil.editor.Editor;
|
||||
import com.songoda.ultimaterepairing.command.CommandManager;
|
||||
import com.songoda.ultimaterepairing.economy.Economy;
|
||||
import com.songoda.ultimaterepairing.economy.PlayerPointsEconomy;
|
||||
import com.songoda.ultimaterepairing.economy.ReserveEconomy;
|
||||
import com.songoda.ultimaterepairing.economy.VaultEconomy;
|
||||
import com.songoda.ultimaterepairing.handlers.ParticleHandler;
|
||||
import com.songoda.ultimaterepairing.commands.*;
|
||||
import com.songoda.ultimaterepairing.handlers.ParticleTask;
|
||||
import com.songoda.ultimaterepairing.handlers.RepairHandler;
|
||||
import com.songoda.ultimaterepairing.hologram.Hologram;
|
||||
import com.songoda.ultimaterepairing.hologram.HologramHolographicDisplays;
|
||||
import com.songoda.ultimaterepairing.listeners.BlockListeners;
|
||||
import com.songoda.ultimaterepairing.listeners.InteractListeners;
|
||||
import com.songoda.ultimaterepairing.listeners.InventoryListeners;
|
||||
import com.songoda.ultimaterepairing.listeners.PlayerListeners;
|
||||
import com.songoda.ultimaterepairing.utils.*;
|
||||
import com.songoda.ultimaterepairing.utils.locale.Locale;
|
||||
import com.songoda.ultimaterepairing.utils.settings.Setting;
|
||||
import com.songoda.ultimaterepairing.utils.settings.SettingsManager;
|
||||
import com.songoda.ultimaterepairing.utils.updateModules.LocaleModule;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import com.songoda.ultimaterepairing.settings.Settings;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class UltimateRepairing extends JavaPlugin {
|
||||
private static CommandSender console = Bukkit.getConsoleSender();
|
||||
public class UltimateRepairing extends SongodaPlugin {
|
||||
|
||||
private static UltimateRepairing INSTANCE;
|
||||
|
||||
private ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
|
||||
|
||||
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
||||
|
||||
private Locale locale;
|
||||
private final Config dataFile = new Config(this, "data.yml");
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private final ParticleTask particleTask = new ParticleTask(this);
|
||||
|
||||
private RepairHandler repairHandler;
|
||||
private SettingsManager settingsManager;
|
||||
private CommandManager commandManager;
|
||||
private AnvilManager anvilManager;
|
||||
|
||||
private Hologram hologram;
|
||||
private Economy economy;
|
||||
|
||||
private Editor editor;
|
||||
|
||||
public static UltimateRepairing getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7UltimateRepairing " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||
@Override
|
||||
public void onPluginEnable() {
|
||||
// Register in Songoda Core
|
||||
SongodaCore.registerPlugin(this, 20, CompatibleMaterial.ANVIL);
|
||||
|
||||
this.settingsManager = new SettingsManager(this);
|
||||
this.settingsManager.setupConfig();
|
||||
Settings.setupConfig();
|
||||
|
||||
new Locale(this, "en_US");
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
||||
// Load Economy & Hologram hooks
|
||||
EconomyManager.load();
|
||||
HologramManager.load(this);
|
||||
|
||||
//Running Songoda Updater
|
||||
Plugin plugin = new Plugin(this, 20);
|
||||
plugin.addModule(new LocaleModule());
|
||||
SongodaUpdate.load(plugin);
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), false);
|
||||
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
|
||||
// Setup Economy
|
||||
if (Setting.VAULT_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Vault"))
|
||||
this.economy = new VaultEconomy();
|
||||
else if (Setting.RESERVE_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Reserve"))
|
||||
this.economy = new ReserveEconomy();
|
||||
else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("PlayerPoints"))
|
||||
this.economy = new PlayerPointsEconomy();
|
||||
// Set Economy & Hologram preference
|
||||
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY.getString());
|
||||
HologramManager.getManager().setPreferredHook(Settings.HOLOGRAM.getString());
|
||||
|
||||
this.editor = new Editor(this);
|
||||
this.anvilManager = new AnvilManager();
|
||||
|
||||
this.repairHandler = new RepairHandler(this);
|
||||
this.repairHandler = new RepairHandler(this, guiManager);
|
||||
this.commandManager = new CommandManager(this);
|
||||
new ParticleHandler(this);
|
||||
this.commandManager.addCommand(new CommandUltimateRepairing())
|
||||
.addSubCommands(
|
||||
new CommandReload(),
|
||||
new CommandSettings(guiManager),
|
||||
new CommandURAnvil());
|
||||
this.commandManager.addCommand(new CommandURAnvil());
|
||||
|
||||
// Register Hologram Plugin
|
||||
if (pluginManager.isPluginEnabled("HolographicDisplays"))
|
||||
hologram = new HologramHolographicDisplays(this);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(this, () -> {
|
||||
/*
|
||||
* Register anvils into AnvilManager from Configuration.
|
||||
*/
|
||||
if (dataFile.getConfig().contains("data")) {
|
||||
for (String key : dataFile.getConfig().getConfigurationSection("data").getKeys(false)) {
|
||||
dataFile.load();
|
||||
if (dataFile.contains("data")) {
|
||||
for (String key : dataFile.getConfigurationSection("data").getKeys(false)) {
|
||||
Location location = Methods.unserializeLocation(key);
|
||||
UAnvil anvil = anvilManager.getAnvil(location);
|
||||
anvil.setHologram(dataFile.getConfig().getBoolean("data." + key + ".hologram"));
|
||||
anvil.setInfinity(dataFile.getConfig().getBoolean("data." + key + ".infinity"));
|
||||
anvil.setParticles(dataFile.getConfig().getBoolean("data." + key + ".particles"));
|
||||
anvil.setPermPlaced(dataFile.getConfig().getBoolean("data." + key + ".permPlaced"));
|
||||
anvil.setHologram(dataFile.getBoolean("data." + key + ".hologram"));
|
||||
anvil.setInfinity(dataFile.getBoolean("data." + key + ".infinity"));
|
||||
anvil.setParticles(dataFile.getBoolean("data." + key + ".particles"));
|
||||
anvil.setPermPlaced(dataFile.getBoolean("data." + key + ".permPlaced"));
|
||||
}
|
||||
}
|
||||
|
||||
particleTask.start();
|
||||
}, 6L);
|
||||
|
||||
// Start Metrics
|
||||
new Metrics(this);
|
||||
|
||||
// Event registration
|
||||
guiManager.init();
|
||||
pluginManager.registerEvents(new PlayerListeners(this), this);
|
||||
pluginManager.registerEvents(new BlockListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this), this);
|
||||
pluginManager.registerEvents(new InteractListeners(this, guiManager), this);
|
||||
pluginManager.registerEvents(new InventoryListeners(this), this);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7UltimateRepairing " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
saveConfig();
|
||||
saveToFile();
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
@Override
|
||||
public List<Config> getExtraConfig() {
|
||||
return Arrays.asList(dataFile);
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves registered kits to file.
|
||||
*/
|
||||
private void saveToFile() {
|
||||
// Wipe old kit information
|
||||
dataFile.getConfig().set("data", null);
|
||||
// Wipe old information
|
||||
dataFile.set("data", null);
|
||||
|
||||
if (anvilManager.getAnvils() == null) return;
|
||||
|
||||
@ -166,52 +131,30 @@ public class UltimateRepairing extends JavaPlugin {
|
||||
for (UAnvil anvil : anvilManager.getAnvils()) {
|
||||
if (!anvil.shouldSave()) continue;
|
||||
String locationStr = Methods.serializeLocation(anvil.getLocation());
|
||||
dataFile.getConfig().set("data." + locationStr + ".hologram", anvil.isHologram());
|
||||
dataFile.getConfig().set("data." + locationStr + ".particles", anvil.isParticles());
|
||||
dataFile.getConfig().set("data." + locationStr + ".infinity", anvil.isInfinity());
|
||||
dataFile.getConfig().set("data." + locationStr + ".permPlaced", anvil.isPermPlaced());
|
||||
dataFile.set("data." + locationStr + ".hologram", anvil.isHologram());
|
||||
dataFile.set("data." + locationStr + ".particles", anvil.isParticles());
|
||||
dataFile.set("data." + locationStr + ".infinity", anvil.isInfinity());
|
||||
dataFile.set("data." + locationStr + ".permPlaced", anvil.isPermPlaced());
|
||||
}
|
||||
|
||||
// Save to file
|
||||
dataFile.saveConfig();
|
||||
dataFile.save();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
@Override
|
||||
public void onConfigReload() {
|
||||
try {
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
||||
this.locale.reloadMessages();
|
||||
this.settingsManager.reloadConfig();
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), true);
|
||||
particleTask.reload();
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
||||
public Editor getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
public RepairHandler getRepairHandler() {
|
||||
return repairHandler;
|
||||
}
|
||||
|
||||
public Hologram getHologram() {
|
||||
return hologram;
|
||||
}
|
||||
|
||||
public SettingsManager getSettingsManager() {
|
||||
return settingsManager;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
@ -1,16 +1,18 @@
|
||||
package com.songoda.ultimaterepairing.anvil;
|
||||
|
||||
import com.songoda.core.hooks.HologramManager;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import com.songoda.ultimaterepairing.settings.Settings;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class UAnvil {
|
||||
|
||||
private Location location;
|
||||
private final Location location;
|
||||
|
||||
private boolean hologram = false;
|
||||
private boolean particles = false;
|
||||
@ -27,14 +29,39 @@ public class UAnvil {
|
||||
|
||||
public void setHologram(boolean hologram) {
|
||||
this.hologram = hologram;
|
||||
if (UltimateRepairing.getInstance().getHologram() != null)
|
||||
UltimateRepairing.getInstance().getHologram().update(this);
|
||||
if (HologramManager.getManager().isEnabled()) {
|
||||
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
if (!Settings.ENABLE_ANVIL_DEFAULT_FUNCTION.getBoolean()) {
|
||||
lines.add(UltimateRepairing.getInstance().getLocale().getMessage("general.hologram.oneclick").getMessage());
|
||||
} else if (Settings.SWAP_LEFT_RIGHT.getBoolean()) {
|
||||
lines.add(UltimateRepairing.getInstance().getLocale().getMessage("general.hologram.swapclick").getMessage());
|
||||
} else {
|
||||
lines.add(UltimateRepairing.getInstance().getLocale().getMessage("general.hologram.torepair").getMessage());
|
||||
}
|
||||
|
||||
lines.add(UltimateRepairing.getInstance().getLocale().getMessage("general.hologram.torepair").getMessage());
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(UltimateRepairing.getInstance(), ()->{
|
||||
if (!hologram) {
|
||||
HologramManager.removeHologram(location);
|
||||
} else {
|
||||
HologramManager.updateHologram(location, lines);
|
||||
}
|
||||
}, 1L);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isParticles() {
|
||||
return particles;
|
||||
}
|
||||
|
||||
public boolean isInLoadedChunk() {
|
||||
return location.getWorld() != null && location.getWorld().isChunkLoaded(((int) location.getX()) >> 4, ((int) location.getZ()) >> 4);
|
||||
}
|
||||
|
||||
public void setParticles(boolean particles) {
|
||||
this.particles = particles;
|
||||
}
|
||||
|
@ -1,93 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.anvil.editor;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.UAnvil;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import com.songoda.ultimaterepairing.utils.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Editor {
|
||||
|
||||
private final UltimateRepairing instance;
|
||||
|
||||
private final Map<UUID, UAnvil> editing = new HashMap<>();
|
||||
|
||||
public Editor(UltimateRepairing instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void open(Player player, Block block) {
|
||||
UAnvil anvil = instance.getAnvilManager().getAnvil(block);
|
||||
open(player, anvil);
|
||||
}
|
||||
|
||||
private void open(Player player, UAnvil anvil) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, Methods.formatText("Anvil Settings"));
|
||||
|
||||
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));
|
||||
|
||||
inventory.setItem(11, Methods.createButton(Material.NAME_TAG, "&9&lToggle Holograms", anvil.isHologram() ? "&7Currently: &aEnabled&7." : "&7Currently &cDisabled&7."));
|
||||
|
||||
inventory.setItem(13, Methods.createButton(Material.BEACON, "&5&lToggle Infinity", anvil.isInfinity() ? "&7Currently: &aEnabled&7." : "&7Currently &cDisabled&7."));
|
||||
|
||||
inventory.setItem(15, Methods.createButton(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.FIREWORK_ROCKET : Material.valueOf("FIREWORK"), "&9&lToggle Particles", anvil.isParticles() ? "&7Currently: &aEnabled&7." : "&7Currently &cDisabled&7."));
|
||||
player.openInventory(inventory);
|
||||
editing.put(player.getUniqueId(), anvil);
|
||||
}
|
||||
|
||||
public void toggleHologram(Player player) {
|
||||
UAnvil anvil = editing.get(player.getUniqueId());
|
||||
anvil.setHologram(!anvil.isHologram());
|
||||
open(player, anvil);
|
||||
}
|
||||
|
||||
public void toggleInfinity(Player player) {
|
||||
UAnvil anvil = editing.get(player.getUniqueId());
|
||||
anvil.setInfinity(!anvil.isInfinity());
|
||||
open(player, anvil);
|
||||
}
|
||||
|
||||
public void toggleParticles(Player player) {
|
||||
UAnvil anvil = editing.get(player.getUniqueId());
|
||||
anvil.setParticles(!anvil.isParticles());
|
||||
open(player, anvil);
|
||||
}
|
||||
|
||||
public boolean isEditing(Player player) {
|
||||
return editing.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void removeEditing(Player player) {
|
||||
editing.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.command;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
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(UltimateRepairing instance, CommandSender sender, String... args);
|
||||
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
public abstract String getSyntax();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.command;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.command.commands.CommandURAnvil;
|
||||
import com.songoda.ultimaterepairing.command.commands.CommandReload;
|
||||
import com.songoda.ultimaterepairing.command.commands.CommandSettings;
|
||||
import com.songoda.ultimaterepairing.command.commands.CommandUltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.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 UltimateRepairing instance;
|
||||
|
||||
private List<AbstractCommand> commands = new ArrayList<>();
|
||||
|
||||
public CommandManager(UltimateRepairing instance) {
|
||||
this.instance = instance;
|
||||
|
||||
instance.getCommand("UltimateRepairing").setExecutor(this);
|
||||
instance.getCommand("uranvil").setExecutor(this);
|
||||
|
||||
AbstractCommand commandUltimateRepairing = addCommand(new CommandUltimateRepairing());
|
||||
addCommand(new CommandURAnvil());
|
||||
|
||||
addCommand(new CommandReload(commandUltimateRepairing));
|
||||
addCommand(new CommandSettings(commandUltimateRepairing));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
instance.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender);
|
||||
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) {
|
||||
instance.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender);
|
||||
instance.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender);
|
||||
}
|
||||
return;
|
||||
}
|
||||
instance.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Collections.unmodifiableList(commands);
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.command.commands;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.command.AbstractCommand;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload(AbstractCommand parent) {
|
||||
super("reload", parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateRepairing instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "ultimaterepairing.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ur reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Reload the Configuration and Language files.";
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.command.commands;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.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(UltimateRepairing instance, CommandSender sender, String... args) {
|
||||
Player p = (Player) sender;
|
||||
instance.getSettingsManager().openSettingsManager(p);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "ultimaterepairing.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ur settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Edit the UltimateRepairing Settings.";
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.songoda.ultimaterepairing.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
public CommandReload() {
|
||||
super(false, "reload");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
UltimateRepairing.getInstance().reloadConfig();
|
||||
UltimateRepairing.getInstance().getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender cs, String... strings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "ultimaterepairing.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ur reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Reload the Configuration and Language files.";
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.songoda.ultimaterepairing.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
GuiManager guiManager;
|
||||
|
||||
public CommandSettings(GuiManager guiManager) {
|
||||
super(true, "settings");
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
guiManager.showGUI((Player) sender, new PluginConfigGui(UltimateRepairing.getInstance()));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender cs, String... strings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "ultimaterepairing.admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/ur settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Edit the UltimateRepairing Settings.";
|
||||
}
|
||||
}
|
@ -1,23 +1,29 @@
|
||||
package com.songoda.ultimaterepairing.command.commands;
|
||||
package com.songoda.ultimaterepairing.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.command.AbstractCommand;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandURAnvil extends AbstractCommand {
|
||||
|
||||
public CommandURAnvil() {
|
||||
super("URAnvil", null, true);
|
||||
super(true, "URAnvil");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateRepairing instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
instance.getRepairHandler().initRepair(player, player.getLocation());
|
||||
UltimateRepairing.getInstance().getRepairHandler().initRepair(player, player.getLocation());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender cs, String... strings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "ultimaterepairing.rpanvil";
|
@ -1,23 +1,25 @@
|
||||
package com.songoda.ultimaterepairing.command.commands;
|
||||
package com.songoda.ultimaterepairing.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.command.AbstractCommand;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandUltimateRepairing extends AbstractCommand {
|
||||
|
||||
public CommandUltimateRepairing() {
|
||||
super("UltimateRepairing", null, false);
|
||||
super(false, "UltimateRepairing");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateRepairing instance, CommandSender sender, String... args) {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
UltimateRepairing instance = UltimateRepairing.getInstance();
|
||||
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion()
|
||||
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
for (AbstractCommand command : instance.getCommandManager().getAllCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
@ -27,6 +29,11 @@ public class CommandUltimateRepairing extends AbstractCommand {
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender cs, String... strings) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
@ -1,12 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.economy;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public interface Economy {
|
||||
|
||||
boolean hasBalance(OfflinePlayer player, double cost);
|
||||
|
||||
boolean withdrawBalance(OfflinePlayer player, double cost);
|
||||
|
||||
boolean deposit(OfflinePlayer player, double amount);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.economy;
|
||||
|
||||
import org.black_ixx.playerpoints.PlayerPoints;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.economy;
|
||||
|
||||
import net.tnemc.core.Reserve;
|
||||
import net.tnemc.core.economy.EconomyAPI;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
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 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));
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.economy;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
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 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();
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.songoda.ultimaterepairing.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.ultimaterepairing.anvil.UAnvil;
|
||||
import com.songoda.ultimaterepairing.settings.Settings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AnvilSettingsGui extends Gui {
|
||||
|
||||
final UAnvil anvil;
|
||||
|
||||
public AnvilSettingsGui(UAnvil anvil, Gui gui) {
|
||||
super(gui);
|
||||
this.anvil = anvil;
|
||||
init();
|
||||
}
|
||||
|
||||
public AnvilSettingsGui(UAnvil anvil) {
|
||||
this.anvil = anvil;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setRows(3);
|
||||
setTitle("Anvil Settings");
|
||||
|
||||
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);
|
||||
|
||||
setButton(1, 2, GuiUtils.createButtonItem(CompatibleMaterial.NAME_TAG, ChatColor.BLUE.toString() + ChatColor.BOLD + "Toggle Holograms",
|
||||
ChatColor.GRAY + "Currently: " + (anvil.isHologram() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled") + ChatColor.GRAY + "."),
|
||||
(event) -> {
|
||||
anvil.setHologram(!anvil.isHologram());
|
||||
updateItemLore(event.slot, ChatColor.GRAY + "Currently: " + (anvil.isHologram() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled") + ChatColor.GRAY + ".");
|
||||
});
|
||||
|
||||
setButton(1, 4, GuiUtils.createButtonItem(CompatibleMaterial.BEACON, ChatColor.DARK_PURPLE.toString() + ChatColor.BOLD + "Toggle Infinity",
|
||||
ChatColor.GRAY + "Currently: " + (anvil.isInfinity() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled") + ChatColor.GRAY + "."),
|
||||
(event) -> {
|
||||
anvil.setInfinity(!anvil.isInfinity());
|
||||
updateItemLore(event.slot, ChatColor.GRAY + "Currently: " + (anvil.isInfinity() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled") + ChatColor.GRAY + ".");
|
||||
});
|
||||
|
||||
setButton(1, 6, GuiUtils.createButtonItem(CompatibleMaterial.FIREWORK_ROCKET, ChatColor.BLUE.toString() + ChatColor.BOLD + "Toggle Particles",
|
||||
ChatColor.GRAY + "Currently: " + (anvil.isParticles() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled") + ChatColor.GRAY + "."),
|
||||
(event) -> {
|
||||
anvil.setParticles(!anvil.isParticles());
|
||||
updateItemLore(event.slot, ChatColor.GRAY + "Currently: " + (anvil.isParticles() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled") + ChatColor.GRAY + ".");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.songoda.ultimaterepairing.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData;
|
||||
import com.songoda.ultimaterepairing.settings.Settings;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class RepairTypeGui extends Gui {
|
||||
|
||||
final Location anvil;
|
||||
final Player player;
|
||||
final UltimateRepairing instance = UltimateRepairing.getInstance();
|
||||
final ItemStack item;
|
||||
|
||||
public RepairTypeGui(Player player, Location anvil) {
|
||||
this(player, anvil, null);
|
||||
}
|
||||
|
||||
public RepairTypeGui(Player player, Location anvil, Gui gui) {
|
||||
super(gui);
|
||||
this.anvil = anvil;
|
||||
this.player = player;
|
||||
this.item = player.getItemInHand();
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setRows(3);
|
||||
setTitle(instance.getLocale().getMessage("interface.repair.title").getMessage());
|
||||
|
||||
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);
|
||||
|
||||
if(player.hasPermission("ultimaterepairing.use.ECO")) {
|
||||
setButton(11, GuiUtils.createButtonItem(Settings.ECO_ICON.getMaterial(CompatibleMaterial.SUNFLOWER),
|
||||
instance.getLocale().getMessage("interface.repair.eco").getMessage(),
|
||||
instance.getLocale().getMessage("interface.repair.ecolore").getMessage()),
|
||||
(event) -> {
|
||||
exit();
|
||||
instance.getRepairHandler().preRepair(player, PlayerAnvilData.RepairType.ECONOMY, anvil);
|
||||
});
|
||||
}
|
||||
|
||||
// Settings.ITEM_ICON.getMaterial(CompatibleMaterial.DIAMOND)
|
||||
if(player.hasPermission("ultimaterepairing.use.ITEM")) {
|
||||
final String itemName = TextUtils.formatText(ItemUtils.getItemName(item).replace("_", " "), true);
|
||||
setButton(15, GuiUtils.createButtonItem(CompatibleMaterial.getMaterial(item),
|
||||
instance.getLocale().getMessage("interface.repair.item")
|
||||
.processPlaceholder("ITEM", itemName).getMessage(),
|
||||
instance.getLocale().getMessage("interface.repair.itemlore")
|
||||
.processPlaceholder("item", itemName).getMessage()),
|
||||
(event) -> {
|
||||
exit();
|
||||
instance.getRepairHandler().preRepair(player, PlayerAnvilData.RepairType.ITEM, anvil);
|
||||
});
|
||||
}
|
||||
|
||||
if(player.hasPermission("ultimaterepairing.use.XP")) {
|
||||
setButton(13, GuiUtils.createButtonItem(Settings.XP_ICON.getMaterial(CompatibleMaterial.EXPERIENCE_BOTTLE),
|
||||
instance.getLocale().getMessage("interface.repair.xp").getMessage(),
|
||||
instance.getLocale().getMessage("interface.repair.xplore").getMessage()),
|
||||
(event) -> {
|
||||
exit();
|
||||
instance.getRepairHandler().preRepair(player, PlayerAnvilData.RepairType.XP, anvil);
|
||||
});
|
||||
}
|
||||
|
||||
if(Settings.RAINBOW.getBoolean()) {
|
||||
for(int cell = 0; cell < rows * 9; ++cell) {
|
||||
if(getItem(cell) == null) {
|
||||
setItem(cell, GuiUtils.getBorderItem(Methods.getRainbowGlass()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.songoda.ultimaterepairing.gui;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData;
|
||||
import com.songoda.ultimaterepairing.settings.Settings;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class StartConfirmGui extends Gui {
|
||||
|
||||
final Location anvil;
|
||||
final Player player;
|
||||
final UltimateRepairing instance = UltimateRepairing.getInstance();
|
||||
final ItemStack item;
|
||||
final PlayerAnvilData.RepairType type;
|
||||
boolean isYes = false;
|
||||
|
||||
public StartConfirmGui(Location anvil, PlayerAnvilData.RepairType type, Player player, ItemStack item) {
|
||||
this(anvil, type, player, item, null);
|
||||
}
|
||||
|
||||
public StartConfirmGui(Location anvil, PlayerAnvilData.RepairType type, Player player, ItemStack item, Gui gui) {
|
||||
super(gui);
|
||||
this.anvil = anvil;
|
||||
this.player = player;
|
||||
this.item = item;
|
||||
this.type = type;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setRows(3);
|
||||
|
||||
String cost = "0";
|
||||
PlayerAnvilData playerData = instance.getRepairHandler().getDataFor(player);
|
||||
|
||||
if (type == PlayerAnvilData.RepairType.XP) {
|
||||
cost = playerData.getPrice() + " XP";
|
||||
} else if (type == PlayerAnvilData.RepairType.ECONOMY) {
|
||||
cost = "$" + playerData.getPrice();
|
||||
} else if (type == PlayerAnvilData.RepairType.ITEM) {
|
||||
cost = playerData.getPrice() + " " + Methods.formatText(Methods.getType(item).name(), true);
|
||||
}
|
||||
|
||||
setTitle(instance.getLocale().getMessage("interface.yesno.title")
|
||||
.processPlaceholder("cost", cost).getMessage());
|
||||
|
||||
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(4, item);
|
||||
|
||||
setButton(11, GuiUtils.createButtonItem(Settings.BUY_ICON.getMaterial(CompatibleMaterial.EMERALD),
|
||||
instance.getLocale().getMessage("interface.yesno.yes").getMessage()),
|
||||
(event) -> {
|
||||
isYes = true;
|
||||
exit();
|
||||
instance.getRepairHandler().finish(true, player);
|
||||
});
|
||||
|
||||
setButton(15, GuiUtils.createButtonItem(Settings.EXIT_ICON.getMaterial(CompatibleMaterial.OAK_DOOR),
|
||||
instance.getLocale().getMessage("interface.yesno.no").getMessage()),
|
||||
(event) -> {
|
||||
exit();
|
||||
instance.getRepairHandler().finish(false, player);
|
||||
});
|
||||
|
||||
if(Settings.RAINBOW.getBoolean()) {
|
||||
for(int cell = 0; cell < rows * 9; ++cell) {
|
||||
if(getItem(cell) == null) {
|
||||
setItem(cell, GuiUtils.getBorderItem(Methods.getRainbowGlass()));
|
||||
}
|
||||
}
|
||||
}
|
||||
setOnClose((event) -> {if(!isYes) instance.getRepairHandler().finish(false, player);});
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.handlers;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.UAnvil;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import com.songoda.ultimaterepairing.utils.ServerVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ParticleHandler implements Listener {
|
||||
|
||||
private UltimateRepairing instance;
|
||||
|
||||
public ParticleHandler(UltimateRepairing instance) {
|
||||
this.instance = instance;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(instance, this::applyParticles, 0L, 10L);
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public void applyParticles() {
|
||||
try {
|
||||
if (instance.getAnvilManager().getAnvils().isEmpty()) return;
|
||||
|
||||
int amt = instance.getConfig().getInt("Main.Particle Amount");
|
||||
String type = instance.getConfig().getString("Main.Particle Type");
|
||||
|
||||
ConfigurationSection section = instance.getConfig().getConfigurationSection("data.anvil");
|
||||
for (UAnvil anvil : instance.getAnvilManager().getAnvils()) {
|
||||
if (anvil.getWorld() == null || !anvil.isParticles()) {
|
||||
continue;
|
||||
}
|
||||
Location location = anvil.getLocation();
|
||||
location.add(.5, 0, .5);
|
||||
if (instance.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
anvil.getWorld().spawnParticle(org.bukkit.Particle.valueOf(type), location, amt, 0.25, 0.25, 0.25);
|
||||
else
|
||||
anvil.getWorld().playEffect(location, Effect.valueOf(type == "SPELL_WITCH" ? "WITCH_MAGIC" : type), 1, 0);
|
||||
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.songoda.ultimaterepairing.handlers;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler;
|
||||
import com.songoda.core.compatibility.CompatibleParticleHandler.ParticleType;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ParticleTask implements Listener {
|
||||
|
||||
private final UltimateRepairing instance;
|
||||
int amt;
|
||||
String typeName;
|
||||
ParticleType type;
|
||||
BukkitTask task = null;
|
||||
|
||||
public ParticleTask(UltimateRepairing instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
reload();
|
||||
if (task == null) {
|
||||
task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(instance, this::applyParticles, 0L, 4L);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (task != null) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(task.getTaskId());
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
amt = instance.getConfig().getInt("Main.Particle Amount", 24) / 2;
|
||||
typeName = instance.getConfig().getString("Main.Particle Type", "SPELL_WITCH");
|
||||
type = ParticleType.getParticle(typeName);
|
||||
if (type == null) {
|
||||
type = ParticleType.SPELL_WITCH;
|
||||
}
|
||||
}
|
||||
|
||||
public void applyParticles() {
|
||||
if (instance.getAnvilManager().getAnvils().isEmpty()) return;
|
||||
try {
|
||||
instance.getAnvilManager().getAnvils().parallelStream()
|
||||
.filter(anvil -> anvil.isParticles() && anvil.isInLoadedChunk())
|
||||
.forEach(anvil -> CompatibleParticleHandler.spawnParticles(type, anvil.getLocation().add(.5, 0, .5), amt, 0.25, 0.25, 0.25));
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +1,29 @@
|
||||
package com.songoda.ultimaterepairing.handlers;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
|
||||
import com.songoda.ultimaterepairing.gui.RepairTypeGui;
|
||||
import com.songoda.ultimaterepairing.gui.StartConfirmGui;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import com.songoda.ultimaterepairing.utils.ServerVersion;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/25/2017.
|
||||
@ -26,90 +31,33 @@ import java.util.UUID;
|
||||
public class RepairHandler {
|
||||
|
||||
private final UltimateRepairing instance;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
private final Map<UUID, PlayerAnvilData> playerAnvilData = new HashMap<>();
|
||||
|
||||
public RepairHandler(UltimateRepairing instance) {
|
||||
public RepairHandler(UltimateRepairing instance, GuiManager guiManager) {
|
||||
this.instance = instance;
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
private void repairType(Player p) {
|
||||
private void repairType(Player p, Location l) {
|
||||
try {
|
||||
if (getDataFor(p).getInRepair()) {
|
||||
yesNo(p, getDataFor(p).getType(), getDataFor(p).getToBeRepaired());
|
||||
return;
|
||||
} else {
|
||||
guiManager.showGUI(p, new RepairTypeGui(p, l));
|
||||
}
|
||||
Inventory i = Bukkit.createInventory(null, 27, Methods.formatText(instance.getLocale().getMessage("interface.repair.title").getMessage()));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
i.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Economy Icon")), 1);
|
||||
ItemMeta itemmeta = item.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(instance.getLocale().getMessage("interface.repair.ecolore").getMessage());
|
||||
itemmeta.setLore(lore);
|
||||
itemmeta.setDisplayName(instance.getLocale().getMessage("interface.repair.eco").getMessage());
|
||||
item.setItemMeta(itemmeta);
|
||||
|
||||
Material mat = Methods.getType(p.getItemInHand());
|
||||
|
||||
ItemStack item3 = new ItemStack(mat, 1);
|
||||
String name = (mat.name().substring(0, 1).toUpperCase() + mat.name().toLowerCase().substring(1)).replace("_", " ");
|
||||
ItemMeta itemmeta3 = item3.getItemMeta();
|
||||
ArrayList<String> lore3 = new ArrayList<>();
|
||||
lore3.add(instance.getLocale().getMessage("interface.repair.itemlore")
|
||||
.processPlaceholder("item", name).getMessage());
|
||||
itemmeta3.setLore(lore3);
|
||||
itemmeta3.setDisplayName(instance.getLocale().getMessage("interface.repair.item")
|
||||
.processPlaceholder("ITEM", name).getMessage());
|
||||
item3.setItemMeta(itemmeta3);
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
|
||||
ItemMeta itemmeta2 = item2.getItemMeta();
|
||||
ArrayList<String> lore2 = new ArrayList<>();
|
||||
lore2.add(instance.getLocale().getMessage("interface.repair.xplore").getMessage());
|
||||
itemmeta2.setLore(lore2);
|
||||
itemmeta2.setDisplayName(instance.getLocale().getMessage("interface.repair.xp").getMessage());
|
||||
item2.setItemMeta(itemmeta2);
|
||||
|
||||
if (p.hasPermission("ultimaterepairing.use.ECO"))
|
||||
i.setItem(11, item);
|
||||
if (p.hasPermission("ultimaterepairing.use.ITEM"))
|
||||
i.setItem(13, item3);
|
||||
if (p.hasPermission("ultimaterepairing.use.XP"))
|
||||
i.setItem(15, item2);
|
||||
|
||||
i.setItem(0, Methods.getBackgroundGlass(true));
|
||||
i.setItem(1, Methods.getBackgroundGlass(true));
|
||||
i.setItem(2, Methods.getBackgroundGlass(false));
|
||||
i.setItem(6, Methods.getBackgroundGlass(false));
|
||||
i.setItem(7, Methods.getBackgroundGlass(true));
|
||||
i.setItem(8, Methods.getBackgroundGlass(true));
|
||||
i.setItem(9, Methods.getBackgroundGlass(true));
|
||||
i.setItem(10, Methods.getBackgroundGlass(false));
|
||||
i.setItem(16, Methods.getBackgroundGlass(false));
|
||||
i.setItem(17, Methods.getBackgroundGlass(true));
|
||||
i.setItem(18, Methods.getBackgroundGlass(true));
|
||||
i.setItem(19, Methods.getBackgroundGlass(true));
|
||||
i.setItem(20, Methods.getBackgroundGlass(false));
|
||||
i.setItem(24, Methods.getBackgroundGlass(false));
|
||||
i.setItem(25, Methods.getBackgroundGlass(true));
|
||||
i.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
p.openInventory(i);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void preRepair(Player player, RepairType type, Location loc) {
|
||||
public void preRepair(Player player, RepairType type, Location anvil) {
|
||||
try {
|
||||
Item item = player.getWorld().dropItem(loc.add(0.5, 2, 0.5), player.getItemInHand());
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
player.setItemInHand(null);
|
||||
Item item = player.getWorld().dropItem(anvil.add(0.5, 2, 0.5), itemStack);
|
||||
|
||||
// Support for EpicHoppers suction.
|
||||
item.setMetadata("grabbed", new FixedMetadataValue(instance, "true"));
|
||||
@ -126,13 +74,11 @@ public class RepairHandler {
|
||||
// Get from Map, put new instance in Map if it doesn't exist
|
||||
PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData());
|
||||
playerData.setItem(item);
|
||||
playerData.setToBeRepaired(player.getItemInHand());
|
||||
playerData.setLocations(loc.add(0, -2, 0));
|
||||
playerData.setToBeRepaired(itemStack);
|
||||
playerData.setLocations(anvil.add(0, -2, 0));
|
||||
|
||||
yesNo(player, type, player.getItemInHand());
|
||||
yesNo(player, type, itemStack);
|
||||
|
||||
|
||||
player.setItemInHand(null);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (item.isValid() && !playerData.isBeingRepaired()) {
|
||||
|
||||
@ -147,17 +93,8 @@ public class RepairHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void initRepair(Player player, Location location) {
|
||||
int num = 0;
|
||||
if (player.hasPermission("ultimaterepairing.use.ECO"))
|
||||
num++;
|
||||
if (player.hasPermission("ultimaterepairing.use.XP"))
|
||||
num++;
|
||||
if (player.hasPermission("ultimaterepairing.use.ITEM"))
|
||||
num++;
|
||||
|
||||
|
||||
if (location.add(0, 1, 0).getBlock().getType() != Material.AIR) {
|
||||
public void initRepair(Player player, Location anvil) {
|
||||
if (anvil.add(0, 1, 0).getBlock().getType() != Material.AIR) {
|
||||
instance.getLocale().getMessage("event.repair.needspace").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
@ -170,15 +107,24 @@ public class RepairHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
if (player.hasPermission("ultimaterepairing.use.ECO"))
|
||||
num++;
|
||||
if (player.hasPermission("ultimaterepairing.use.XP"))
|
||||
num++;
|
||||
if (num != 2 && player.hasPermission("ultimaterepairing.use.ITEM"))
|
||||
num++;
|
||||
|
||||
|
||||
if (num >= 2 || player.hasPermission("ultimaterepairing.use.*")) {
|
||||
repairType(player);
|
||||
getDataFor(player).setLocation(location);
|
||||
repairType(player, anvil);
|
||||
getDataFor(player).setLocation(anvil);
|
||||
} else if (player.hasPermission("ultimaterepairing.use.eco"))
|
||||
instance.getRepairHandler().preRepair(player, RepairType.ECONOMY, location);
|
||||
instance.getRepairHandler().preRepair(player, RepairType.ECONOMY, anvil);
|
||||
else if (player.hasPermission("ultimaterepairing.use.XP"))
|
||||
instance.getRepairHandler().preRepair(player, RepairType.XP, location);
|
||||
instance.getRepairHandler().preRepair(player, RepairType.XP, anvil);
|
||||
else if (player.hasPermission("ultimaterepairing.use.ITEM"))
|
||||
instance.getRepairHandler().preRepair(player, RepairType.ITEM, location);
|
||||
instance.getRepairHandler().preRepair(player, RepairType.ITEM, anvil);
|
||||
}
|
||||
|
||||
private void yesNo(Player p, RepairType type, ItemStack item) {
|
||||
@ -189,66 +135,12 @@ public class RepairHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
playerData.setInRepair(true);
|
||||
|
||||
int price = Methods.getCost(type, item);
|
||||
String cost = "0";
|
||||
|
||||
Material mat = Methods.getType(item);
|
||||
String name = Methods.formatText(mat.name(), true);
|
||||
|
||||
if (type == RepairType.XP)
|
||||
cost = price + " XP";
|
||||
else if (type == RepairType.ECONOMY)
|
||||
cost = "\\$" + price;
|
||||
else if (type == RepairType.ITEM)
|
||||
cost = price + " " + name;
|
||||
|
||||
Inventory inventory = Bukkit.createInventory(null, 27,
|
||||
Methods.formatTitle(instance.getLocale().getMessage("interface.yesno.title")
|
||||
.processPlaceholder("cost", cost).getMessage()));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
inventory.setItem(nu, Methods.getGlass());
|
||||
nu++;
|
||||
}
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Buy Icon")), 1);
|
||||
ItemMeta itemmeta2 = item2.getItemMeta();
|
||||
itemmeta2.setDisplayName(instance.getLocale().getMessage("interface.yesno.yes").getMessage());
|
||||
item2.setItemMeta(itemmeta2);
|
||||
|
||||
ItemStack item3 = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta itemmeta3 = item3.getItemMeta();
|
||||
itemmeta3.setDisplayName(instance.getLocale().getMessage("interface.yesno.no").getMessage());
|
||||
item3.setItemMeta(itemmeta3);
|
||||
|
||||
inventory.setItem(4, item);
|
||||
inventory.setItem(11, item2);
|
||||
inventory.setItem(15, item3);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> p.openInventory(inventory), 1);
|
||||
|
||||
playerData.setInRepair(true);
|
||||
playerData.setType(type);
|
||||
playerData.setPrice(price);
|
||||
|
||||
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));
|
||||
guiManager.showGUI(p, new StartConfirmGui(playerData.getLocation(), type, p, item));
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
@ -268,11 +160,11 @@ public class RepairHandler {
|
||||
ItemStack players = playerData.getToBeRepaired();
|
||||
|
||||
boolean sold = false;
|
||||
if (type == RepairType.ECONOMY && instance.getEconomy() != null) {
|
||||
if (type == RepairType.ECONOMY && EconomyManager.isEnabled()) {
|
||||
int price = playerData.getPrice();
|
||||
|
||||
if (instance.getEconomy().hasBalance(player, price)) {
|
||||
instance.getEconomy().withdrawBalance(player, price);
|
||||
if(EconomyManager.hasBalance(player, price)) {
|
||||
EconomyManager.withdrawBalance(player, price);
|
||||
sold = true;
|
||||
}
|
||||
}
|
||||
@ -303,7 +195,7 @@ public class RepairHandler {
|
||||
} else if (typeStr.contains("STONE")) {
|
||||
blockType = Material.STONE;
|
||||
} else if (typeStr.contains("WOOD")) {
|
||||
blockType = instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_PLANKS : Material.valueOf("WOOD");
|
||||
blockType = CompatibleMaterial.OAK_WOOD.getMaterial();
|
||||
}
|
||||
|
||||
final Material blockTypeFinal = blockType;
|
||||
@ -315,18 +207,12 @@ public class RepairHandler {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
player.getWorld().playEffect(location, effect, blockTypeFinal);
|
||||
player.getWorld().playEffect(location, effect, Material.STONE);
|
||||
if (instance.isServerVersion(ServerVersion.V1_8))
|
||||
player.playSound(location, Sound.valueOf("ANVIL_LAND"), 1L, 1L);
|
||||
else
|
||||
player.playSound(location, Sound.valueOf("BLOCK_ANVIL_LAND"), 1L, 1L);
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
|
||||
}, 10L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 15L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 20L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
if (instance.isServerVersion(ServerVersion.V1_8))
|
||||
player.playSound(location, Sound.valueOf("ANVIL_LAND"), 1L, 1L);
|
||||
else
|
||||
player.playSound(location, Sound.valueOf("BLOCK_ANVIL_LAND"), 1L, 1L);
|
||||
CompatibleSound.BLOCK_ANVIL_LAND.play(player);
|
||||
player.getWorld().playEffect(location, effect, blockTypeFinal);
|
||||
player.getWorld().playEffect(location, effect, Material.ANVIL);
|
||||
instance.getLocale().getMessage("event.repair.success").sendPrefixedMessage(player);
|
||||
@ -360,6 +246,8 @@ public class RepairHandler {
|
||||
instance.getLocale().getMessage("event.repair.notenough")
|
||||
.processPlaceholder("type", name).sendPrefixedMessage(player);
|
||||
|
||||
// we've failed to repair, so return the item
|
||||
removeItem(playerData, player);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
|
@ -1,98 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.hologram;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.UAnvil;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Hologram {
|
||||
|
||||
protected final UltimateRepairing instance;
|
||||
|
||||
Hologram(UltimateRepairing instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void loadHolograms() {
|
||||
Collection<UAnvil> uAnvils = instance.getAnvilManager().getAnvils();
|
||||
if (uAnvils.size() == 0) return;
|
||||
|
||||
for (UAnvil anvil : uAnvils) {
|
||||
if (anvil.getWorld() == null) continue;
|
||||
add(anvil);
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadHolograms() {
|
||||
Collection<UAnvil> uAnvils = instance.getAnvilManager().getAnvils();
|
||||
if (uAnvils.size() == 0) return;
|
||||
|
||||
for (UAnvil anvil : uAnvils) {
|
||||
if (anvil.getWorld() == null) continue;
|
||||
remove(anvil);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(UAnvil anvil) {
|
||||
format(anvil, Action.ADD);
|
||||
}
|
||||
|
||||
public void remove(UAnvil anvil) {
|
||||
format(anvil, Action.REMOVE);
|
||||
}
|
||||
|
||||
public void update(UAnvil anvil) {
|
||||
format(anvil, Action.UPDATE);
|
||||
}
|
||||
|
||||
private void format(UAnvil anvil, Action action) {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
if (!instance.getConfig().getBoolean("Main.Enable Default Anvil Function"))
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.oneclick").getMessage()));
|
||||
else if (instance.getConfig().getBoolean("Main.Swap Right And Left Click Options"))
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.swapclick").getMessage()));
|
||||
else
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.click").getMessage()));
|
||||
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("general.hologram.torepair").getMessage()));
|
||||
|
||||
Location location = anvil.getLocation();
|
||||
|
||||
if (!anvil.isHologram()) {
|
||||
remove(location);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case UPDATE:
|
||||
update(location, lines);
|
||||
break;
|
||||
case ADD:
|
||||
add(location, lines);
|
||||
break;
|
||||
case REMOVE:
|
||||
remove(location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void add(Location location, ArrayList<String> lines);
|
||||
|
||||
protected abstract void remove(Location location);
|
||||
|
||||
protected abstract void update(Location location, ArrayList<String> lines);
|
||||
|
||||
public enum Action {
|
||||
|
||||
UPDATE, ADD, REMOVE
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.hologram;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HologramHolographicDisplays extends Hologram {
|
||||
|
||||
|
||||
public HologramHolographicDisplays(UltimateRepairing instance) {
|
||||
super(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Location location, ArrayList<String> lines) {
|
||||
fixLocation(location);
|
||||
|
||||
com.gmail.filoghost.holographicdisplays.api.Hologram hologram = HologramsAPI.createHologram(instance, location);
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Location location) {
|
||||
fixLocation(location);
|
||||
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) {
|
||||
if (hologram.getX() != location.getX()
|
||||
|| hologram.getY() != location.getY()
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
hologram.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Location location, ArrayList<String> lines) {
|
||||
fixLocation(location);
|
||||
for (com.gmail.filoghost.holographicdisplays.api.Hologram hologram : HologramsAPI.getHolograms(instance)) {
|
||||
if (hologram.getX() != location.getX()
|
||||
|| hologram.getY() != location.getY()
|
||||
|| hologram.getZ() != location.getZ()) continue;
|
||||
hologram.clearLines();
|
||||
for (String line : lines) {
|
||||
hologram.appendTextLine(line);
|
||||
}
|
||||
return;
|
||||
}
|
||||
add(location, lines);
|
||||
}
|
||||
|
||||
private void fixLocation(Location location) {
|
||||
location.add(.25, .95, .25);
|
||||
}
|
||||
}
|
@ -22,10 +22,11 @@ public class BlockListeners implements Listener {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
try {
|
||||
if (!event.getPlayer().hasPermission("ultimaterepairing.permPlace") || !event.getBlockPlaced().getType().equals(Material.ANVIL)) {
|
||||
if (!Methods.isAnvil(event.getBlockPlaced().getType())
|
||||
|| !event.getPlayer().hasPermission("ultimaterepairing.permPlace")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -36,7 +37,7 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
try {
|
||||
String loc = Methods.serializeLocation(event.getBlock());
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.songoda.ultimaterepairing.listeners;
|
||||
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.UAnvil;
|
||||
import com.songoda.ultimaterepairing.gui.AnvilSettingsGui;
|
||||
import com.songoda.ultimaterepairing.settings.Settings;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -20,57 +23,62 @@ import org.bukkit.inventory.Inventory;
|
||||
public class InteractListeners implements Listener {
|
||||
|
||||
private final UltimateRepairing instance;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
public InteractListeners(UltimateRepairing instance) {
|
||||
public InteractListeners(UltimateRepairing instance, GuiManager guiManager) {
|
||||
this.instance = instance;
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAnvilClick(PlayerInteractEvent event) {
|
||||
try {
|
||||
boolean repair = false;
|
||||
boolean anvil = false;
|
||||
boolean ourRepair = false;
|
||||
boolean vanillaRepair = false;
|
||||
Player player = event.getPlayer();
|
||||
if (event.getClickedBlock() == null) return;
|
||||
|
||||
UAnvil anvil1 = instance.getAnvilManager().getAnvil(event.getClickedBlock());
|
||||
UAnvil anvil1 = null;
|
||||
|
||||
if (event.getClickedBlock().getType() != Material.ANVIL
|
||||
|| !(anvil1.isPermPlaced()
|
||||
|| !instance.getConfig().getBoolean("Main.Require Permission On UltimateRepairing Anvil Place"))) {
|
||||
if (!Methods.isAnvil(event.getClickedBlock().getType()) // don't pay attention if it's not an anvil
|
||||
// also don't handle if we don't have perms to use this repair anvil
|
||||
|| !(Settings.PERMISSION_ANVIL_PLACE.getBoolean()
|
||||
|| !((anvil1 = instance.getAnvilManager().getAnvil(event.getClickedBlock())).isPermPlaced()))) {
|
||||
return;
|
||||
}
|
||||
if (anvil1.isInfinity()) {
|
||||
event.getClickedBlock().setType(Material.AIR);
|
||||
event.getClickedBlock().setType(Material.ANVIL); //ToDO: This may not work.
|
||||
}
|
||||
if (!instance.getConfig().getBoolean("Main.Enable Default Anvil Function") && !player.isSneaking())
|
||||
anvil1 = anvil1 != null ? anvil1 : instance.getAnvilManager().getAnvil(event.getClickedBlock());
|
||||
// if (anvil1.isInfinity()) {
|
||||
// event.getClickedBlock().setType(Material.AIR);
|
||||
// event.getClickedBlock().setType(Material.ANVIL); //ToDO: This may not work.
|
||||
// }
|
||||
// check if we should process this as a right click
|
||||
boolean rightClick = (event.getAction() == Action.RIGHT_CLICK_BLOCK) ^ (Settings.SWAP_LEFT_RIGHT.getBoolean());
|
||||
// admin interface?
|
||||
if(rightClick && player.isSneaking() && player.hasPermission("ultimaterepairing.admin")) {
|
||||
guiManager.showGUI(player, new AnvilSettingsGui(anvil1));
|
||||
event.setCancelled(true);
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||
!player.isSneaking()) {
|
||||
if (instance.getConfig().getBoolean("Main.Swap Right And Left Click Options"))
|
||||
repair = true;
|
||||
else if (!instance.getConfig().getBoolean("Main.Enable Default Anvil Function"))
|
||||
repair = true;
|
||||
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK &&
|
||||
!player.isSneaking()) {
|
||||
if (instance.getConfig().getBoolean("Main.Swap Right And Left Click Options")) {
|
||||
if (instance.getConfig().getBoolean("Main.Enable Default Anvil Function"))
|
||||
anvil = true;
|
||||
else
|
||||
repair = true;
|
||||
} else
|
||||
repair = true;
|
||||
} else if (player.isSneaking()
|
||||
&& player.hasPermission("ultimaterepairing.admin")
|
||||
&& event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
instance.getEditor().open(player, event.getClickedBlock());
|
||||
} else if (!Settings.ENABLE_ANVIL_DEFAULT_FUNCTION.getBoolean()) {
|
||||
// if not allowing default anvil, then always use ourRepair
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (repair) {
|
||||
// replace our functions for vanilla mechanics only
|
||||
if(!rightClick) {
|
||||
return;
|
||||
}
|
||||
ourRepair = true;
|
||||
} else if(rightClick) {
|
||||
// allowing normal repair
|
||||
vanillaRepair = true;
|
||||
} else if(!player.isSneaking()) {
|
||||
// that's us!
|
||||
ourRepair = true;
|
||||
}
|
||||
|
||||
if (ourRepair) {
|
||||
instance.getRepairHandler().initRepair(player, event.getClickedBlock().getLocation());
|
||||
event.setCancelled(true);
|
||||
} else if (anvil && instance.getConfig().getBoolean("Main.Enable Default Anvil Function")) {
|
||||
} else if (vanillaRepair && anvil1.isInfinity()) {
|
||||
Inventory inv = Bukkit.createInventory(null, InventoryType.ANVIL, "Repair & Name");
|
||||
player.openInventory(inv);
|
||||
event.setCancelled(true);
|
||||
|
@ -1,17 +1,8 @@
|
||||
package com.songoda.ultimaterepairing.listeners;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
|
||||
import com.songoda.ultimaterepairing.handlers.RepairHandler;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
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.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
|
||||
/**
|
||||
@ -30,55 +21,4 @@ public class InventoryListeners implements Listener {
|
||||
if (event.getItem().hasMetadata("UltimateRepairing"))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event) {
|
||||
try {
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
if (instance.getEditor().isEditing(p)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getSlot() == 11) {
|
||||
instance.getEditor().toggleHologram(p);
|
||||
} else if (event.getSlot() == 13) {
|
||||
instance.getEditor().toggleInfinity(p);
|
||||
} else if (event.getSlot() == 15) {
|
||||
instance.getEditor().toggleParticles(p);
|
||||
}
|
||||
} else if (instance.getRepairHandler().getDataFor(p).getInRepair()) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getSlot() == 11) {
|
||||
instance.getRepairHandler().finish(true, p);
|
||||
p.closeInventory();
|
||||
} else if (event.getSlot() == 15) {
|
||||
instance.getRepairHandler().finish(false, p);
|
||||
p.closeInventory();
|
||||
}
|
||||
} else if (event.getView().getTitle().equals(Methods.formatTitle(instance.getLocale().getMessage("interface.repair.title").getMessage()))) {
|
||||
event.setCancelled(true);
|
||||
Location loc = instance.getRepairHandler().getDataFor(p).getLocation();
|
||||
if (event.getSlot() == 11) {
|
||||
p.closeInventory();
|
||||
if (p.hasPermission("ultimaterepairing.use.ECO"))
|
||||
instance.getRepairHandler().preRepair(p, RepairType.ECONOMY, loc);
|
||||
} else if (event.getSlot() == 13) {
|
||||
p.closeInventory();
|
||||
if (p.hasPermission("ultimaterepairing.use.ITEM"))
|
||||
instance.getRepairHandler().preRepair(p, RepairType.ITEM, loc);
|
||||
} else if (event.getSlot() == 15) {
|
||||
p.closeInventory();
|
||||
if (p.hasPermission("ultimaterepairing.use.XP"))
|
||||
instance.getRepairHandler().preRepair(p, RepairType.XP, loc);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
instance.getEditor().removeEditing((Player)event.getPlayer());
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package com.songoda.ultimaterepairing.settings;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.configuration.ConfigSetting;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.core.hooks.HologramManager;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Settings {
|
||||
|
||||
static final Config config = UltimateRepairing.getInstance().getConfig().getCoreConfig();
|
||||
|
||||
public static final ConfigSetting TIMEOUT = new ConfigSetting(config, "Main.Time Before Repair Auto Canceled", 200L);
|
||||
|
||||
public static final ConfigSetting EXPERIENCE_EQUATION = new ConfigSetting(config, "Main.Experience Cost Equation", "{MaxDurability} - ({MaxDurability} - {Durability} / 40) + 1",
|
||||
"The equation used to generate experience repairing cost.");
|
||||
|
||||
public static final ConfigSetting ECONOMY_EQUATION = new ConfigSetting(config, "Main.Economy Cost Equation", "{XPCost} * 5",
|
||||
"The equation used to generate economy repairing cost.");
|
||||
|
||||
public static final ConfigSetting ITEM_EQUATION = new ConfigSetting(config, "Main.Item Cost Equation", "{XPCost} * 3",
|
||||
"The equation used to generate item repairing cost.");
|
||||
|
||||
public static final ConfigSetting MULTIPLY_COST_FOR_ENCHANTED = new ConfigSetting(config, "Main.Cost Multiplier For Enchanted Items", 2,
|
||||
"Should enchanted items have their repair costs multiplied?");
|
||||
|
||||
public static final ConfigSetting ECONOMY = new ConfigSetting(config, "Main.Economy",
|
||||
EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
|
||||
"Which economy plugin should be used?",
|
||||
"You can choose from \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
|
||||
|
||||
public static final ConfigSetting HOLOGRAM = new ConfigSetting(config, "Main.Hologram",
|
||||
HologramManager.getHolograms() == null ? "HolographicDisplays" : HologramManager.getHolograms().getName(),
|
||||
"Which hologram plugin should be used?",
|
||||
"You can choose from \"" + HologramManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining(", ")) + "\".");
|
||||
|
||||
public static final ConfigSetting ECO_ICON = new ConfigSetting(config, "Interfaces.Economy Icon", "SUNFLOWER");
|
||||
public static final ConfigSetting XP_ICON = new ConfigSetting(config, "Interfaces.XP Icon", "EXPERIENCE_BOTTLE");
|
||||
public static final ConfigSetting ITEM_ICON = new ConfigSetting(config, "Interfaces.Item Icon", "DIAMOND");
|
||||
|
||||
public static final ConfigSetting EXIT_ICON = new ConfigSetting(config, "Interfaces.Exit Icon", "OAK_DOOR");
|
||||
public static final ConfigSetting BUY_ICON = new ConfigSetting(config, "Interfaces.Buy Icon", "EMERALD");
|
||||
|
||||
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 RAINBOW = new ConfigSetting(config, "Interfaces.Replace Glass Type 1 With Rainbow Glass", false);
|
||||
|
||||
public static final ConfigSetting REPAIR_ONLY_SAME_TYPE = new ConfigSetting(config, "Main.Repair Items Only With Items Of That Items Type", true,
|
||||
"Should repairing with items only utilize items of the same type?");
|
||||
|
||||
public static final ConfigSetting ENABLE_ANVIL_DEFAULT_FUNCTION = new ConfigSetting(config, "Main.Enable Default Anvil Function", true,
|
||||
"Should the default anvil function be disabled?");
|
||||
|
||||
public static final ConfigSetting SWAP_LEFT_RIGHT = new ConfigSetting(config, "Main.Swap Right And Left Click Options", false,
|
||||
"Should punching an anvil open up the anvil GUI and right clicking",
|
||||
"open up the repair GUI?");
|
||||
|
||||
public static final ConfigSetting PERMISSION_ANVIL_PLACE = new ConfigSetting(config, "Main.Require Permission On UltimateRepairing Anvil Place", false,
|
||||
"Should players need admin permissions to place anvils?");
|
||||
|
||||
public static final ConfigSetting PARTICLE_AMOUNT = new ConfigSetting(config, "Main.Particle Amount", 25);
|
||||
|
||||
public static final ConfigSetting PARTICLE_TYPE = new ConfigSetting(config, "Main.Particle Type", "SPELL_WITCH");
|
||||
|
||||
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,67 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.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,12 +1,13 @@
|
||||
package com.songoda.ultimaterepairing.utils;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
|
||||
import com.songoda.ultimaterepairing.settings.Settings;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
@ -18,33 +19,9 @@ import java.util.*;
|
||||
*/
|
||||
public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
UltimateRepairing instance = UltimateRepairing.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) {
|
||||
UltimateRepairing instance = UltimateRepairing.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(UltimateRepairing.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
|
||||
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
|
||||
} else {
|
||||
glass = new ItemStack(UltimateRepairing.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;
|
||||
static Random rand = new Random();
|
||||
public static CompatibleMaterial getRainbowGlass() {
|
||||
return CompatibleMaterial.getGlassPaneColor(rand.nextInt(16));
|
||||
}
|
||||
|
||||
public static int getCost(RepairType type, ItemStack item) {
|
||||
@ -53,9 +30,9 @@ public class Methods {
|
||||
ScriptEngineManager mgr = new ScriptEngineManager();
|
||||
ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
||||
|
||||
String equationXP = UltimateRepairing.getInstance().getConfig().getString("Main.Experience Cost Equation");
|
||||
String equationECO = UltimateRepairing.getInstance().getConfig().getString("Main.Economy Cost Equation");
|
||||
String equationITEM = UltimateRepairing.getInstance().getConfig().getString("Main.Item Cost Equation");
|
||||
String equationXP = Settings.EXPERIENCE_EQUATION.getString();
|
||||
String equationECO = Settings.ECONOMY_EQUATION.getString();
|
||||
String equationITEM = Settings.ITEM_EQUATION.getString();
|
||||
|
||||
equationXP = equationXP.replace("{MaxDurability}", Short.toString(item.getType().getMaxDurability()))
|
||||
.replace("{Durability}", Short.toString(item.getDurability()));
|
||||
@ -94,42 +71,23 @@ public class Methods {
|
||||
}
|
||||
|
||||
public static Material getType(ItemStack item) {
|
||||
if (UltimateRepairing.getInstance().getConfig().getBoolean("Main.Repair Items Only With Items Of That Items Type")) {
|
||||
if (Settings.REPAIR_ONLY_SAME_TYPE.getBoolean()) {
|
||||
if (item.getType().name().contains("DIAMOND"))
|
||||
return Material.DIAMOND;
|
||||
return CompatibleMaterial.DIAMOND.getMaterial();
|
||||
if (item.getType().name().contains("IRON"))
|
||||
return Material.IRON_INGOT;
|
||||
return CompatibleMaterial.IRON_INGOT.getMaterial();
|
||||
if (item.getType().name().contains("GOLD"))
|
||||
return Material.GOLD_INGOT;
|
||||
return CompatibleMaterial.GOLD_INGOT.getMaterial();
|
||||
if (item.getType().name().contains("LEATHER"))
|
||||
return Material.LEATHER;
|
||||
return CompatibleMaterial.LEATHER.getMaterial();
|
||||
if (item.getType().name().contains("STONE"))
|
||||
return Material.STONE;
|
||||
return CompatibleMaterial.STONE.getMaterial();
|
||||
if (item.getType().name().contains("WOOD"))
|
||||
return Material.OAK_WOOD;
|
||||
return CompatibleMaterial.OAK_WOOD.getMaterial();
|
||||
}
|
||||
return Material.valueOf(UltimateRepairing.getInstance().getConfig().getString("Interfaces.Item Icon"));
|
||||
return Settings.ITEM_ICON.getMaterial(CompatibleMaterial.DIAMOND).getMaterial();
|
||||
}
|
||||
|
||||
public static ItemStack createButton(ItemStack item, String name, String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(formatText(name));
|
||||
if (lore != null && lore.length != 0) {
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : lore) newLore.add(formatText(line));
|
||||
meta.setLore(newLore);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createButton(Material material, String name, String... lore) {
|
||||
return createButton(new ItemStack(material), name, lore);
|
||||
}
|
||||
|
||||
public static ItemStack createButton(Material material, String name, ArrayList<String> lore) {
|
||||
return createButton(material, name, lore.toArray(new String[0]));
|
||||
}
|
||||
public static boolean isAnvil(Material material){
|
||||
return material.equals(Material.ANVIL) || material.equals(Material.CHIPPED_ANVIL) || material.equals(Material.DAMAGED_ANVIL);
|
||||
}
|
||||
@ -236,19 +194,6 @@ public class Methods {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String formatTitle(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
if (!UltimateRepairing.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
if (text.length() > 31)
|
||||
text = text.substring(0, 29) + "...";
|
||||
}
|
||||
text = formatText(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String formatText(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
|
@ -1,695 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.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.ultimaterepairing.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,302 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.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 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;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.utils.settings;
|
||||
|
||||
public enum Category {
|
||||
|
||||
MAIN("General settings and options."),
|
||||
INTERFACES("These settings allow you to alter the way interfaces look.",
|
||||
"They are used in GUI's to make patterns, change them up then open up a",
|
||||
"GUI to see how it works."),
|
||||
SYSTEM("System related settings.");
|
||||
|
||||
private String[] comments;
|
||||
|
||||
|
||||
Category(String... comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public String[] getComments() {
|
||||
return comments;
|
||||
}
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.utils.settings;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.utils.ServerVersion;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum Setting {
|
||||
|
||||
TIMEOUT("Main.Time Before Repair Auto Canceled", 200L),
|
||||
|
||||
EXPERIENCE_EQUATION("Main.Experience Cost Equation", "{MaxDurability} - ({MaxDurability} - {Durability} / 40) + 1",
|
||||
"The equation used to generate experience repairing cost."),
|
||||
|
||||
ECONOMY_EQUATION("Main.Economy Cost Equation", "{XPCost} * 5",
|
||||
"The equation used to generate economy repairing cost."),
|
||||
|
||||
ITEM_EQUATION("Main.Item Cost Equation", "{XPCost} * 3",
|
||||
"The equation used to generate item repairing cost."),
|
||||
|
||||
MULTIPLY_COST_FOR_ENCHANTED("Main.Cost Multiplier For Enchanted Items", 2,
|
||||
"Should enchanted items have their repair costs multiplied?"),
|
||||
|
||||
VAULT_ECONOMY("Economy.Use Vault Economy", true,
|
||||
"Should Vault be used?"),
|
||||
|
||||
RESERVE_ECONOMY("Economy.Use Reserve Economy", true,
|
||||
"Should Reserve be used?"),
|
||||
|
||||
PLAYER_POINTS_ECONOMY("Economy.Use Player Points Economy", false,
|
||||
"Should PlayerPoints be used?"),
|
||||
|
||||
|
||||
ECO_ICON("Interfaces.Economy Icon", UltimateRepairing.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "SUNFLOWER" : "DOUBLE_PLANT"),
|
||||
XP_ICON("Interfaces.XP Icon", UltimateRepairing.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "EXPERIENCE_BOTTLE" : "EXP_BOTTLE"),
|
||||
ITEM_ICON("Interfaces.Item Icon", "DIAMOND"),
|
||||
|
||||
EXIT_ICON("Interfaces.Exit Icon", UltimateRepairing.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "OAK_DOOR" : "WOOD_DOOR"),
|
||||
BUY_ICON("Interfaces.Buy Icon", "EMERALD"),
|
||||
|
||||
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
|
||||
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
|
||||
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
|
||||
|
||||
RAINBOW("Interfaces.Replace Glass Type 1 With Rainbow Glass", false),
|
||||
|
||||
REPAIR_ONLY_SAME_TYPE("Main.Repair Items Only With Items Of That Items Type", true,
|
||||
"Should repairing with items only utilize items of the same type?"),
|
||||
|
||||
ENABLE_ANVIL_DEFAULT_FUNCTION("Main.Enable Default Anvil Function", true,
|
||||
"Should the default anvil function be disabled?"),
|
||||
|
||||
SWAP_LEFT_RIGHT("Main.Swap Right And Left Click Options", false,
|
||||
"Should punching an anvil open up the anvil GUI and right clicking",
|
||||
"open up the repair GUI?"),
|
||||
|
||||
PERMISSION_ANVIL_PLACE("Main.Require Permission On UltimateRepairing Anvil Place", false,
|
||||
"Should players need admin permissions to place anvils?"),
|
||||
|
||||
PARTICLE_AMOUNT("Main.Particle Amount", 25),
|
||||
|
||||
PARTICLE_TYPE("Main.Particle Type", "SPELL_WITCH"),
|
||||
|
||||
LANGUGE_MODE("System.Language Mode", "en_US",
|
||||
"The enabled language file.",
|
||||
"More language files (if available) can be found in the plugins data folder.");
|
||||
|
||||
private String setting;
|
||||
private Object option;
|
||||
private String[] comments;
|
||||
|
||||
Setting(String setting, Object option, String... comments) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
Setting(String setting, Object option) {
|
||||
this.setting = setting;
|
||||
this.option = option;
|
||||
this.comments = null;
|
||||
}
|
||||
|
||||
public static Setting getSetting(String setting) {
|
||||
List<Setting> settings = Arrays.stream(values()).filter(setting1 -> setting1.setting.equals(setting)).collect(Collectors.toList());
|
||||
if (settings.isEmpty()) return null;
|
||||
return settings.get(0);
|
||||
}
|
||||
|
||||
public String getSetting() {
|
||||
return setting;
|
||||
}
|
||||
|
||||
public Object getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
public String[] getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return UltimateRepairing.getInstance().getConfig().getStringList(setting);
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return UltimateRepairing.getInstance().getConfig().getBoolean(setting);
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return UltimateRepairing.getInstance().getConfig().getInt(setting);
|
||||
}
|
||||
|
||||
public long getLong() {
|
||||
return UltimateRepairing.getInstance().getConfig().getLong(setting);
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return UltimateRepairing.getInstance().getConfig().getString(setting);
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
return UltimateRepairing.getInstance().getConfig().getString(setting).charAt(0);
|
||||
}
|
||||
|
||||
public double getDouble() {
|
||||
return UltimateRepairing.getInstance().getConfig().getDouble(setting);
|
||||
}
|
||||
}
|
@ -1,311 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.utils.settings;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import com.songoda.ultimaterepairing.utils.ServerVersion;
|
||||
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.inventory.InventoryType;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by songoda on 6/4/2017.
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
private final UltimateRepairing plugin;
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
private Map<Player, String> current = new HashMap<>();
|
||||
|
||||
public SettingsManager(UltimateRepairing plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getView().getType() != InventoryType.CHEST) return;
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
|
||||
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|
||||
|| clickedItem == null || !clickedItem.hasItemMeta()
|
||||
|| !clickedItem.getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getView().getTitle().equals(plugin.getName() + " 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(plugin.getName() + " 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 (plugin.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
|
||||
this.plugin.getConfig().set(key, !plugin.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 = plugin.getConfig();
|
||||
if (config.isLong(value)) {
|
||||
config.set(value, Long.parseLong(event.getMessage()));
|
||||
} else 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(UltimateRepairing.getInstance(), () ->
|
||||
this.finishEditing(player), 0L);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void finishEditing(Player player) {
|
||||
this.current.remove(player);
|
||||
this.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 (plugin.getConfig().isInt(current) || plugin.getConfig().isDouble(current)) {
|
||||
player.sendMessage(Methods.formatText("&cUse only numbers."));
|
||||
}
|
||||
player.sendMessage("");
|
||||
}
|
||||
|
||||
public void openSettingsManager(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, plugin.getName() + " Settings Manager");
|
||||
ItemStack glass = Methods.getGlass();
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, glass);
|
||||
}
|
||||
|
||||
int slot = 10;
|
||||
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));
|
||||
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, plugin.getName() + " Settings Editor");
|
||||
FileConfiguration config = plugin.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("&7" + config.getString(fKey)));
|
||||
} else if (config.isInt(fKey)) {
|
||||
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&7" + config.getInt(fKey)));
|
||||
} else if (config.isLong(fKey)) {
|
||||
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&7" + config.getLong(fKey)));
|
||||
} else if (config.isDouble(fKey)) {
|
||||
item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&7" + config.getDouble(fKey)));
|
||||
}
|
||||
|
||||
Setting setting = Setting.getSetting(fKey);
|
||||
|
||||
if (setting != null && setting.getComments() != null) {
|
||||
lore.add("");
|
||||
|
||||
String comment = String.join(" ", setting.getComments());
|
||||
|
||||
int lastIndex = 0;
|
||||
for (int n = 0; n < comment.length(); n++) {
|
||||
if (n - lastIndex < 30)
|
||||
continue;
|
||||
|
||||
if (comment.charAt(n) == ' ') {
|
||||
lore.add(Methods.formatText("&8" + comment.substring(lastIndex, n).trim()));
|
||||
lastIndex = n;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastIndex - comment.length() < 30)
|
||||
lore.add(Methods.formatText("&8" + comment.substring(lastIndex).trim()));
|
||||
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inventory.setItem(slot, item);
|
||||
slot++;
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
plugin.reloadConfig();
|
||||
this.setupConfig();
|
||||
}
|
||||
|
||||
public void setupConfig() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
for (Setting setting : Setting.values()) {
|
||||
config.addDefault(setting.getSetting(), setting.getOption());
|
||||
}
|
||||
plugin.getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private void saveConfig() {
|
||||
String dump = plugin.getConfig().saveToString();
|
||||
|
||||
StringBuilder config = new StringBuilder();
|
||||
|
||||
BufferedReader bufReader = new BufferedReader(new StringReader(dump));
|
||||
|
||||
try {
|
||||
boolean first = true;
|
||||
|
||||
String line;
|
||||
int currentTab = 0;
|
||||
String category = "";
|
||||
|
||||
while ((line = bufReader.readLine()) != null) {
|
||||
if (line.trim().startsWith("#")) continue;
|
||||
|
||||
int tabChange = line.length() - line.trim().length();
|
||||
if (currentTab != tabChange) {
|
||||
category = category.contains(".") && tabChange != 0 ? category.substring(0, category.indexOf(".")) : "";
|
||||
currentTab = tabChange;
|
||||
}
|
||||
|
||||
if (line.endsWith(":")) {
|
||||
bufReader.mark(1000);
|
||||
String found = bufReader.readLine();
|
||||
bufReader.reset();
|
||||
|
||||
if (!found.trim().startsWith("-")) {
|
||||
|
||||
String newCategory = line.substring(0, line.length() - 1).trim();
|
||||
|
||||
if (category.equals(""))
|
||||
category = newCategory;
|
||||
else
|
||||
category += "." + newCategory;
|
||||
|
||||
currentTab = tabChange + 2;
|
||||
|
||||
if (!first) {
|
||||
config.append("\n\n");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
|
||||
if (!category.contains("."))
|
||||
config.append("#").append("\n");
|
||||
try {
|
||||
Category categoryObj = Category.valueOf(category.toUpperCase()
|
||||
.replace(" ", "_")
|
||||
.replace(".", "_"));
|
||||
|
||||
config.append(new String(new char[tabChange]).replace('\0', ' '));
|
||||
for (String l : categoryObj.getComments())
|
||||
config.append("# ").append(l).append("\n");
|
||||
} catch (IllegalArgumentException e) {
|
||||
config.append("# ").append(category).append("\n");
|
||||
}
|
||||
if (!category.contains("."))
|
||||
config.append("#").append("\n");
|
||||
|
||||
config.append(line).append("\n");
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (line.trim().startsWith("-")) {
|
||||
config.append(line).append("\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = category + "." + (line.split(":")[0].trim());
|
||||
for (Setting setting : Setting.values()) {
|
||||
if (!setting.getSetting().equals(key) || setting.getComments() == null) continue;
|
||||
config.append(" ").append("\n");
|
||||
for (String l : setting.getComments()) {
|
||||
config.append(new String(new char[currentTab]).replace('\0', ' '));
|
||||
config.append("# ").append(l).append("\n");
|
||||
}
|
||||
}
|
||||
config.append(line).append("\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!plugin.getDataFolder().exists())
|
||||
plugin.getDataFolder().mkdir();
|
||||
BufferedWriter writer =
|
||||
new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + File.separator + "config.yml")));
|
||||
writer.write(config.toString());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.songoda.ultimaterepairing.utils.updateModules;
|
||||
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
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();
|
||||
UltimateRepairing.getInstance().getLocale().saveLocale(in, (String) file.get("name"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user