mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Fixed many bugs
This commit is contained in:
parent
5c9ca84e3f
commit
bea49ad2e7
@ -10,7 +10,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand implements CommandExecutor {
|
||||
private static AbstractCommand instance;
|
||||
protected static AbstractCommand instance;
|
||||
|
||||
private final String name;
|
||||
private final String permission;
|
||||
@ -43,8 +43,4 @@ public abstract class AbstractCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
public abstract void onExecute(CommandSender sender, List<String> args);
|
||||
|
||||
public static AbstractCommand getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,8 @@ package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -40,4 +37,11 @@ public final class CommandEcodebug extends AbstractCommand {
|
||||
|
||||
Bukkit.getLogger().info("--------------- END DEBUG ----------------");
|
||||
}
|
||||
|
||||
public static AbstractCommand getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new CommandEcodebug();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.EnchantmentTarget;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
@ -44,4 +41,11 @@ public final class CommandEcoreload extends AbstractCommand {
|
||||
}, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
public static AbstractCommand getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new CommandEcoreload();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package com.willfp.ecoenchants.command.commands;
|
||||
import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -35,4 +33,11 @@ public final class CommandEcoskip extends AbstractCommand {
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public static AbstractCommand getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new CommandEcoskip();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
@ -137,4 +136,11 @@ public final class CommandEnchantinfo extends AbstractCommand {
|
||||
sender.sendMessage(string);
|
||||
}));
|
||||
}
|
||||
|
||||
public static AbstractCommand getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new CommandEnchantinfo();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -5,41 +5,75 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public abstract class YamlConfig {
|
||||
public abstract class AbstractConfig {
|
||||
private static AbstractConfig instance;
|
||||
|
||||
private final String name;
|
||||
public YamlConfiguration config;
|
||||
private File configFile;
|
||||
private final File directory;
|
||||
private final double latestVersion;
|
||||
private final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
|
||||
private final Class<?> sourceClass;
|
||||
|
||||
public YamlConfig(String name) {
|
||||
protected final File configFile;
|
||||
protected final YamlConfiguration config;
|
||||
|
||||
protected AbstractConfig(String name, File directory, Class<?> sourceClass, double latestVersion) {
|
||||
this.name = name;
|
||||
this.directory = directory;
|
||||
this.sourceClass = sourceClass;
|
||||
this.latestVersion = latestVersion;
|
||||
|
||||
init();
|
||||
}
|
||||
if(!directory.exists()) directory.mkdirs();
|
||||
|
||||
private void init() {
|
||||
if (!new File(EcoEnchantsPlugin.getInstance().getDataFolder(), name + ".yml").exists()) {
|
||||
this.configFile = new File(directory, name + ".yml");
|
||||
|
||||
if(!this.configFile.exists()) {
|
||||
createFile();
|
||||
}
|
||||
|
||||
this.configFile = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), name + ".yml");
|
||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
instance = this;
|
||||
|
||||
checkVersion();
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
EcoEnchantsPlugin.getInstance().saveResource(name + ".yml", false);
|
||||
private void saveResource(boolean replace) {
|
||||
String resourcePath = configFile.getPath().replace(PLUGIN.getDataFolder().getPath(), "");
|
||||
|
||||
InputStream in = sourceClass.getResourceAsStream(resourcePath);
|
||||
|
||||
File outFile = new File(PLUGIN.getDataFolder(), resourcePath);
|
||||
int lastIndex = resourcePath.lastIndexOf('/');
|
||||
File outDir = new File(PLUGIN.getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
|
||||
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!outFile.exists() || replace) {
|
||||
OutputStream out = new FileOutputStream(outFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
saveResource(false);
|
||||
}
|
||||
private void replaceFile() {
|
||||
EcoEnchantsPlugin.getInstance().saveResource(name + ".yml", true);
|
||||
saveResource(true);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
@ -52,7 +86,6 @@ public abstract class YamlConfig {
|
||||
}
|
||||
|
||||
private void checkVersion() {
|
||||
double latestVersion = ConfigManager.configVersions.get(this.name);
|
||||
if (latestVersion != config.getDouble("config-version")) {
|
||||
Bukkit.getLogger().warning("EcoEnchants detected an older or invalid " + name + ".yml. Replacing it with the default config...");
|
||||
Bukkit.getLogger().warning("If you've edited the config, copy over your changes!");
|
||||
@ -66,11 +99,11 @@ public abstract class YamlConfig {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String dateTime = dtf.format(now);
|
||||
try {
|
||||
File backupDir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "backup/");
|
||||
File backupDir = new File(PLUGIN.getDataFolder(), "backup/");
|
||||
if(!backupDir.exists()) backupDir.mkdirs();
|
||||
File oldConf = new File(backupDir, name + "_" + dateTime + ".yml");
|
||||
oldConf.createNewFile();
|
||||
FileInputStream fis = new FileInputStream(EcoEnchantsPlugin.getInstance().getDataFolder() + "/" + name + ".yml");
|
||||
FileInputStream fis = new FileInputStream(directory + "/" + name + ".yml");
|
||||
FileOutputStream fos = new FileOutputStream(oldConf);
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
@ -85,4 +118,8 @@ public abstract class YamlConfig {
|
||||
Bukkit.getLogger().severe("§cCould not update config. Try reinstalling EcoEnchants");
|
||||
}
|
||||
}
|
||||
|
||||
public static AbstractConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RootConfig extends AbstractConfig {
|
||||
protected RootConfig(String name) {
|
||||
super(name, EcoEnchantsPlugin.getInstance().getDataFolder(), EcoEnchantsPlugin.class, ConfigManager.configVersions.get(name));
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(String path) {
|
||||
return config.getItemStack(path);
|
||||
}
|
||||
}
|
@ -1,55 +1,12 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.YamlConfig;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import com.willfp.ecoenchants.config.RootConfig;
|
||||
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Config extends YamlConfig {
|
||||
public class Config extends RootConfig {
|
||||
public Config() {
|
||||
super("config");
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(String path) {
|
||||
return config.getItemStack(path);
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,16 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.YamlConfig;
|
||||
import com.willfp.ecoenchants.config.RootConfig;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper for lang.yml
|
||||
*/
|
||||
public class Lang extends YamlConfig {
|
||||
public class Lang extends RootConfig {
|
||||
public Lang() {
|
||||
super("lang");
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
|
||||
public String getPrefix() {
|
||||
return ChatColor.translateAlternateColorCodes('&', config.getString("messages.prefix"));
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.YamlConfig;
|
||||
import com.willfp.ecoenchants.config.RootConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Rarity extends YamlConfig {
|
||||
public class Rarity extends RootConfig {
|
||||
public Rarity() {
|
||||
super("rarity");
|
||||
}
|
||||
@ -16,40 +15,4 @@ public class Rarity extends YamlConfig {
|
||||
public Set<String> getRarities() {
|
||||
return config.getConfigurationSection("rarities").getKeys(false);
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.YamlConfig;
|
||||
import com.willfp.ecoenchants.config.RootConfig;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -9,7 +9,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Target extends YamlConfig {
|
||||
public class Target extends RootConfig {
|
||||
public Target() {
|
||||
super("target");
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
private static AbstractPacketAdapter instance;
|
||||
protected static AbstractPacketAdapter instance;
|
||||
|
||||
private final PacketType type;
|
||||
|
||||
@ -46,10 +46,6 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
onSend(event.getPacket());
|
||||
}
|
||||
|
||||
public static AbstractPacketAdapter getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public final void register() {
|
||||
if(!EcoEnchantsPlugin.getInstance().protocolManager.getPacketListeners().contains(this)) {
|
||||
EcoEnchantsPlugin.getInstance().protocolManager.addPacketListener(this);
|
||||
|
@ -18,11 +18,7 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* All methods and fields pertaining to showing players the enchantments on their items.
|
||||
|
@ -38,4 +38,11 @@ public final class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
|
||||
packet.getMerchantRecipeLists().writeSafely(0, newList);
|
||||
}
|
||||
|
||||
public static AbstractPacketAdapter getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new PacketOpenWindowMerchant();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,11 @@ public final class PacketSetCreativeSlot extends AbstractPacketAdapter {
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
public static AbstractPacketAdapter getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new PacketSetCreativeSlot();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,11 @@ public final class PacketSetSlot extends AbstractPacketAdapter {
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
public static AbstractPacketAdapter getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new PacketSetSlot();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,11 @@ public final class PacketWindowItems extends AbstractPacketAdapter {
|
||||
return itemStacks;
|
||||
});
|
||||
}
|
||||
|
||||
public static AbstractPacketAdapter getInstance() {
|
||||
if(instance == null) {
|
||||
instance = new PacketWindowItems();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package com.willfp.ecoenchants.enchantments;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.util.NumberUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Material;
|
||||
|
@ -5,13 +5,12 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.checks.EnchantChecks;
|
||||
import com.willfp.ecoenchants.events.entitydeathbyentity.EntityDeathByEntityEvent;
|
||||
import com.willfp.ecoenchants.nms.TridentStack;
|
||||
import com.willfp.ecoenchants.queue.DropQueue;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -3,9 +3,6 @@ package com.willfp.ecoenchants.grindstone;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.willfp.ecoenchants.util;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class NumberUtils {
|
||||
|
Loading…
Reference in New Issue
Block a user