mirror of
https://github.com/songoda/UltimateRepairing.git
synced 2025-02-18 05:21:51 +01:00
Merged legacy into master.
This commit is contained in:
parent
b734c66d71
commit
a30ec83c6a
2
pom.xml
2
pom.xml
@ -61,7 +61,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.14</version>
|
||||
<version>1.14.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
|
@ -12,13 +12,11 @@ import com.songoda.ultimaterepairing.handlers.ParticleHandler;
|
||||
import com.songoda.ultimaterepairing.handlers.RepairHandler;
|
||||
import com.songoda.ultimaterepairing.hologram.Hologram;
|
||||
import com.songoda.ultimaterepairing.hologram.HologramHolographicDisplays;
|
||||
import com.songoda.ultimaterepairing.utils.ConfigWrapper;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import com.songoda.ultimaterepairing.utils.SettingsManager;
|
||||
import com.songoda.ultimaterepairing.utils.*;
|
||||
import com.songoda.ultimaterepairing.utils.updateModules.LocaleModule;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -36,6 +34,8 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
|
||||
|
||||
public References references = null;
|
||||
|
||||
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
||||
|
||||
private Locale locale;
|
||||
|
||||
private RepairHandler repairHandler;
|
||||
@ -51,29 +51,10 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private boolean checkVersion() {
|
||||
int workingVersion = 13;
|
||||
int currentVersion = Integer.parseInt(Bukkit.getServer().getClass()
|
||||
.getPackage().getName().split("\\.")[3].split("_")[1]);
|
||||
|
||||
if (currentVersion < workingVersion) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You installed the 1." + workingVersion + "+ only version of " + this.getDescription().getName() + " on a 1." + currentVersion + " server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using " + this.getDescription().getName() + ".");
|
||||
Bukkit.getConsoleSender().sendMessage("");
|
||||
}, 20L);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
|
||||
// Check to make sure the Bukkit version is compatible.
|
||||
if (!checkVersion()) return;
|
||||
|
||||
console.sendMessage(Methods.formatText("&a============================="));
|
||||
console.sendMessage(Methods.formatText("&7UltimateRepairing " + this.getDescription().getVersion() + " by &5Brianna <3!"));
|
||||
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
||||
@ -140,6 +121,22 @@ public final class UltimateRepairing extends JavaPlugin implements Listener {
|
||||
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();
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves registered kits to file.
|
||||
*/
|
||||
|
@ -3,6 +3,7 @@ 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;
|
||||
@ -58,7 +59,7 @@ public class Editor {
|
||||
|
||||
inventory.setItem(13, Methods.createButton(Material.BEACON, "&5&lToggle Infinity", anvil.isInfinity() ? "&7Currently: &aEnabled&7." : "&7Currently &cDisabled&7."));
|
||||
|
||||
inventory.setItem(15, Methods.createButton(Material.FIREWORK_ROCKET, "&9&lToggle Particles", anvil.isParticles() ? "&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);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.songoda.ultimaterepairing.events;
|
||||
import com.songoda.ultimaterepairing.UltimateRepairing;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
|
||||
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;
|
||||
@ -52,7 +53,7 @@ public class InventoryListeners implements Listener {
|
||||
instance.getRepairHandler().finish(false, p);
|
||||
p.closeInventory();
|
||||
}
|
||||
} else if (event.getView().getTitle().equals(instance.getLocale().getMessage("interface.repair.title"))) {
|
||||
} else if (event.getView().getTitle().equals(Methods.formatTitle(instance.getLocale().getMessage("interface.repair.title")))) {
|
||||
event.setCancelled(true);
|
||||
Location loc = instance.getRepairHandler().getDataFor(p).getLocation();
|
||||
if (event.getSlot() == 11) {
|
||||
|
@ -3,7 +3,9 @@ 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;
|
||||
@ -35,7 +37,11 @@ public class ParticleHandler implements Listener {
|
||||
}
|
||||
Location location = anvil.getLocation();
|
||||
location.add(.5, 0, .5);
|
||||
anvil.getWorld().spawnParticle(org.bukkit.Particle.valueOf(type), location, amt, 0.25, 0.25, 0.25);
|
||||
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);
|
||||
|
@ -5,6 +5,7 @@ import com.songoda.ultimaterepairing.anvil.PlayerAnvilData;
|
||||
import com.songoda.ultimaterepairing.anvil.PlayerAnvilData.RepairType;
|
||||
import com.songoda.ultimaterepairing.utils.Debugger;
|
||||
import com.songoda.ultimaterepairing.utils.Methods;
|
||||
import com.songoda.ultimaterepairing.utils.ServerVersion;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Item;
|
||||
@ -40,7 +41,7 @@ public class RepairHandler {
|
||||
yesNo(p, getDataFor(p).getType(), getDataFor(p).getToBeRepaired());
|
||||
return;
|
||||
}
|
||||
Inventory i = Bukkit.createInventory(null, 27, instance.getLocale().getMessage("interface.repair.title"));
|
||||
Inventory i = Bukkit.createInventory(null, 27, Methods.formatText(instance.getLocale().getMessage("interface.repair.title")));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
@ -202,7 +203,7 @@ public class RepairHandler {
|
||||
else if (type == RepairType.ITEM)
|
||||
cost = price + " " + name;
|
||||
|
||||
Inventory i = Bukkit.createInventory(null, 27, instance.getLocale().getMessage("interface.yesno.title", cost));
|
||||
Inventory i = Bukkit.createInventory(null, 27, Methods.formatTitle(instance.getLocale().getMessage("interface.yesno.title", cost)));
|
||||
|
||||
int nu = 0;
|
||||
while (nu != 27) {
|
||||
@ -303,7 +304,7 @@ public class RepairHandler {
|
||||
} else if (typeStr.contains("STONE")) {
|
||||
blockType = Material.STONE;
|
||||
} else if (typeStr.contains("WOOD")) {
|
||||
blockType = Material.OAK_PLANKS;
|
||||
blockType = instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_PLANKS : Material.valueOf("WOOD");
|
||||
}
|
||||
|
||||
final Material blockTypeFinal = blockType;
|
||||
|
@ -19,35 +19,27 @@ import java.util.*;
|
||||
public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
try {
|
||||
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"));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return null;
|
||||
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) {
|
||||
try {
|
||||
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"));
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
}
|
||||
return null;
|
||||
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(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum);
|
||||
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(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type);
|
||||
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");
|
||||
@ -244,6 +236,19 @@ 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 "";
|
||||
|
@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -23,8 +23,8 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class SettingsManager implements Listener {
|
||||
|
||||
|
||||
private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
|
||||
private static ConfigWrapper defs;
|
||||
private final UltimateRepairing instance;
|
||||
private String pluginName = "UltimateRepairing";
|
||||
private Map<Player, String> cat = new HashMap<>();
|
||||
@ -32,10 +32,6 @@ public class SettingsManager implements Listener {
|
||||
|
||||
public SettingsManager(UltimateRepairing plugin) {
|
||||
this.instance = plugin;
|
||||
|
||||
plugin.saveResource("SettingDefinitions.yml", true);
|
||||
defs = new ConfigWrapper(plugin, "", "SettingDefinitions.yml");
|
||||
defs.createNewFile("Loading data file", pluginName + " SettingDefinitions file");
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@ -49,14 +45,14 @@ public class SettingsManager implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getView().getTitle().equals(pluginName + " Settings Manager")) {
|
||||
if (event.getView().getTitle().equals(Methods.formatTitle(pluginName + " Settings Manager"))) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
this.cat.put((Player) event.getWhoClicked(), type);
|
||||
this.openEditor((Player) event.getWhoClicked());
|
||||
} else if (event.getView().getTitle().equals(pluginName + " Settings Editor")) {
|
||||
} else if (event.getView().getTitle().equals(Methods.formatTitle(pluginName + " Settings Editor"))) {
|
||||
event.setCancelled(true);
|
||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
||||
|
||||
@ -88,20 +84,19 @@ public class SettingsManager implements Listener {
|
||||
config.set(value, event.getMessage());
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateRepairing.getInstance(), () ->
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () ->
|
||||
this.finishEditing(player), 0L);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void finishEditing(Player player) {
|
||||
private void finishEditing(Player player) {
|
||||
this.current.remove(player);
|
||||
this.instance.saveConfig();
|
||||
this.openEditor(player);
|
||||
}
|
||||
|
||||
|
||||
public void editObject(Player player, String current) {
|
||||
private void editObject(Player player, String current) {
|
||||
this.current.put(player, ChatColor.stripColor(current));
|
||||
|
||||
player.closeInventory();
|
||||
@ -114,7 +109,7 @@ public class SettingsManager implements Listener {
|
||||
}
|
||||
|
||||
public void openSettingsManager(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, Methods.formatTitle(pluginName + " Settings Manager"));
|
||||
ItemStack glass = Methods.getGlass();
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, glass);
|
||||
@ -122,7 +117,7 @@ public class SettingsManager implements Listener {
|
||||
|
||||
int slot = 10;
|
||||
for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
|
||||
ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
|
||||
ItemStack item = new ItemStack(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
|
||||
meta.setDisplayName(Methods.formatText("&f&l" + key));
|
||||
@ -134,8 +129,8 @@ public class SettingsManager implements Listener {
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public void openEditor(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
|
||||
private void openEditor(Player player) {
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, Methods.formatTitle(pluginName + " Settings Editor"));
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
int slot = 0;
|
||||
@ -153,20 +148,10 @@ public class SettingsManager implements Listener {
|
||||
item.setType(Material.PAPER);
|
||||
lore.add(Methods.formatText("&9" + config.getString(fKey)));
|
||||
} else if (config.isInt(fKey)) {
|
||||
item.setType(Material.CLOCK);
|
||||
item.setType(instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
||||
lore.add(Methods.formatText("&5" + config.getInt(fKey)));
|
||||
}
|
||||
|
||||
if (defs.getConfig().contains(fKey)) {
|
||||
String text = defs.getConfig().getString(key);
|
||||
|
||||
Matcher m = SETTINGS_PATTERN.matcher(text);
|
||||
while (m.find()) {
|
||||
if (m.end() != text.length() || m.group().length() != 0)
|
||||
lore.add(Methods.formatText("&7" + m.group()));
|
||||
}
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
@ -181,12 +166,7 @@ public class SettingsManager implements Listener {
|
||||
FileConfiguration config = instance.getConfig();
|
||||
|
||||
for (Setting setting : Setting.values()) {
|
||||
if (config.contains("settings." + setting.oldSetting)) {
|
||||
config.addDefault(setting.setting, instance.getConfig().get("settings." + setting.oldSetting));
|
||||
config.set("settings." + setting.oldSetting, null);
|
||||
} else {
|
||||
config.addDefault(setting.setting, setting.option);
|
||||
}
|
||||
config.addDefault(setting.setting, setting.option);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user