mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Merge branch 'v1.x.x' into v2.x.x
# Conflicts: # build.gradle.kts # settings.gradle.kts # src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GuiTesterSelector.kt # src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt
This commit is contained in:
commit
b8c91496cd
22 changed files with 1457 additions and 59 deletions
|
|
@ -1,42 +1,37 @@
|
|||
package xyz.alexcrea.cuanvil.update;
|
||||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
|
||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
||||
|
||||
// This is a temporary class that aim to handle 1.21 update.
|
||||
// It will be replaced by a better system later.
|
||||
public class Update_1_21 {
|
||||
|
||||
private static final Version V1_21 = new Version(1, 21);
|
||||
|
||||
public static void handleUpdate(){
|
||||
// Assume if version path is not null then it's 1.21
|
||||
public static boolean handleUpdate(Version current){
|
||||
// Test if we are running in 1.21 or better
|
||||
if(V1_21.greaterThan(current))
|
||||
return false;
|
||||
|
||||
// if version path is not null then check if its it's before 1.21
|
||||
String oldVersion = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(UpdateUtils.MINECRAFT_VERSION_PATH);
|
||||
if(oldVersion != null){
|
||||
Version version = Version.fromString(oldVersion);
|
||||
|
||||
// Test 1.21
|
||||
if(V1_21.greaterEqual(version)) return;
|
||||
}
|
||||
Version current = UpdateUtils.currentMinecraftVersion();
|
||||
|
||||
// Test 1.21
|
||||
if(current.greaterEqual(V1_21)){
|
||||
doUpdate();
|
||||
var version = Version.fromString(oldVersion);
|
||||
if(V1_21.lesserEqual(version)) return false;
|
||||
}
|
||||
|
||||
doUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void doUpdate() {
|
||||
CustomAnvil.instance.getLogger().info("Updating config to support 1.21 ...");
|
||||
|
||||
FileConfiguration baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||
FileConfiguration groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
||||
FileConfiguration conflictConfig = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||
FileConfiguration unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||
var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
||||
var conflictConfig = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
|
||||
// Add mace to groups
|
||||
groupConfig.set("mace.type", "include");
|
||||
|
|
@ -81,7 +76,7 @@ public class Update_1_21 {
|
|||
unitConfig.set("breeze_rod.mace", 0.25);
|
||||
|
||||
// Set version string as 1.21
|
||||
baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, "1.21");
|
||||
baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, V1_21.toString());
|
||||
|
||||
// Save
|
||||
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
||||
|
|
@ -92,9 +87,6 @@ public class Update_1_21 {
|
|||
// imply reload of CONFLICT_HOLDER
|
||||
// We also do not need to reload base config as there is no object related to it.
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.reload();
|
||||
|
||||
CustomAnvil.instance.getLogger().info("Updating Done !");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
58
src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21_9.java
Normal file
58
src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21_9.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package xyz.alexcrea.cuanvil.update;
|
||||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
|
||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
||||
|
||||
public class Update_1_21_9 {
|
||||
|
||||
private static final Version V1_21_9 = new Version(1, 21, 9);
|
||||
|
||||
public static boolean handleUpdate(Version current){
|
||||
// Test if we are running in 1.21.9 or better
|
||||
if(V1_21_9.greaterThan(current))
|
||||
return false;
|
||||
|
||||
// if version path is not null then check if its it's before 1.21.9
|
||||
String oldVersion = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(UpdateUtils.MINECRAFT_VERSION_PATH);
|
||||
if(oldVersion != null){
|
||||
var version = Version.fromString(oldVersion);
|
||||
if(V1_21_9.lesserEqual(version)) return false;
|
||||
}
|
||||
|
||||
doUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void doUpdate() {
|
||||
CustomAnvil.instance.getLogger().info("Updating config to support 1.21.9 ...");
|
||||
|
||||
var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||
var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
||||
|
||||
// Add mace to groups
|
||||
addAbsentToList(groupConfig, "helmets.items", "copper_helmet");
|
||||
addAbsentToList(groupConfig, "chestplate.items", "copper_chestplate");
|
||||
addAbsentToList(groupConfig, "leggings.items", "copper_leggings");
|
||||
addAbsentToList(groupConfig, "boots.items", "copper_boots");
|
||||
|
||||
addAbsentToList(groupConfig, "pickaxes.items", "copper_pickaxe");
|
||||
addAbsentToList(groupConfig, "shovels.items", "copper_shovel");
|
||||
addAbsentToList(groupConfig, "hoes.items", "copper_hoe");
|
||||
addAbsentToList(groupConfig, "axes.items", "copper_axe");
|
||||
addAbsentToList(groupConfig, "swords.items", "copper_sword");
|
||||
|
||||
// Set version string as 1.21
|
||||
baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, V1_21_9.toString());
|
||||
|
||||
// Save
|
||||
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.saveToDisk(true);
|
||||
|
||||
// imply reload of CONFLICT_HOLDER
|
||||
// We also do not need to reload base config as there is no object related to it.
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.reload();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.update;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
|
@ -48,6 +50,7 @@ public record Version(int major, int minor, int patch) {
|
|||
this.patch <= other.patch)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return major + "." + minor + "." + patch;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ package xyz.alexcrea.cuanvil.update.plugin;
|
|||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils;
|
||||
import xyz.alexcrea.cuanvil.update.Update_1_21;
|
||||
import xyz.alexcrea.cuanvil.update.Update_1_21_9;
|
||||
import xyz.alexcrea.cuanvil.update.Version;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
|
@ -12,26 +15,37 @@ public class PluginUpdates {
|
|||
|
||||
private static final String CONFIG_VERSION_PATH = "configVersion";
|
||||
|
||||
public static void handlePluginUpdate() {
|
||||
// Handle mc version update then plugin version update
|
||||
public static void handleUpdates() {
|
||||
handleMCVersionUpdate();
|
||||
handlePluginUpdate();
|
||||
}
|
||||
|
||||
private static final Version V1_6_2 = new Version(1, 6, 2);
|
||||
private static final Version V1_6_7 = new Version(1, 6, 7);
|
||||
private static final Version V1_8_0 = new Version(1, 8, 0);
|
||||
private static final Version V1_11_0 = new Version(1, 11, 0);
|
||||
|
||||
// Handle only plugin update
|
||||
private static void handlePluginUpdate() {
|
||||
String versionString = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(CONFIG_VERSION_PATH);
|
||||
Version current = versionString == null ? new Version(0) : Version.fromString(versionString);
|
||||
|
||||
Set<ConfigHolder> toSave = new HashSet<>();
|
||||
|
||||
if (new Version(1, 6, 2).greaterThan(current)) {
|
||||
if (V1_6_2.greaterThan(current)) {
|
||||
PUpdate_1_6_2.handleUpdate(toSave);
|
||||
// We assume 1.6.7 will run. TODO a better system instead of that I guess
|
||||
}
|
||||
if (new Version(1, 6, 7).greaterThan(current)) {
|
||||
if (V1_6_7.greaterThan(current)) {
|
||||
PUpdate_1_6_7.handleUpdate(toSave);
|
||||
// We assume 1.8.0 will run.
|
||||
}
|
||||
if (new Version(1, 8, 0).greaterThan(current)) {
|
||||
if (V1_8_0.greaterThan(current)) {
|
||||
PUpdate_1_8_0.handleUpdate(toSave);
|
||||
// We assume 1.11.0 will run.
|
||||
}
|
||||
|
||||
if (new Version(1, 11, 0).greaterThan(current)) {
|
||||
if (V1_11_0.greaterThan(current)) {
|
||||
PUpdate_1_11_0.handleUpdate(toSave);
|
||||
|
||||
finishConfiguration("1.11.0", toSave);
|
||||
|
|
@ -39,6 +53,19 @@ public class PluginUpdates {
|
|||
|
||||
}
|
||||
|
||||
// Handle minecraft version update (not plugin version update)
|
||||
public static void handleMCVersionUpdate(){
|
||||
Version current = UpdateUtils.currentMinecraftVersion();
|
||||
|
||||
boolean hadUpdate = false;
|
||||
hadUpdate |= Update_1_21.handleUpdate(current);
|
||||
hadUpdate |= Update_1_21_9.handleUpdate(current);
|
||||
|
||||
if(hadUpdate){
|
||||
CustomAnvil.instance.getLogger().info("Updating Done !");
|
||||
}
|
||||
}
|
||||
|
||||
private static void finishConfiguration(@Nonnull String newVersion, @Nonnull Set<ConfigHolder> toSave) {
|
||||
CustomAnvil.instance.getLogger().info("Configuration file updated to " + newVersion);
|
||||
ConfigHolder.DEFAULT_CONFIG.getConfig().set(CONFIG_VERSION_PATH, newVersion);
|
||||
|
|
|
|||
|
|
@ -139,11 +139,8 @@ open class CustomAnvil : JavaPlugin() {
|
|||
return
|
||||
}
|
||||
|
||||
// temporary: handle 1.21 update
|
||||
Update_1_21.handleUpdate()
|
||||
|
||||
// plugin configuration updates
|
||||
PluginUpdates.handlePluginUpdate()
|
||||
// Handle minecraft and plugin updates
|
||||
PluginUpdates.handleUpdates()
|
||||
|
||||
// Register enchantment of compatible plugin and load configuration change.
|
||||
DependencyManager.handleCompatibilityConfig()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
|||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.*
|
||||
import xyz.alexcrea.cuanvil.update.Update_1_21
|
||||
import xyz.alexcrea.cuanvil.update.plugin.PluginUpdates
|
||||
|
||||
class ReloadExecutor : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
||||
|
|
@ -48,8 +48,8 @@ class ReloadExecutor : CommandExecutor {
|
|||
UnitRepairConfigGui.getCurrentInstance()?.reloadValues()
|
||||
CustomRecipeConfigGui.getCurrentInstance()?.reloadValues()
|
||||
|
||||
// temporary: handle 1.21 update
|
||||
Update_1_21.handleUpdate()
|
||||
// handle minecraft version update
|
||||
PluginUpdates.handleMCVersionUpdate()
|
||||
|
||||
// Handle dependency reload
|
||||
DependencyManager.handleConfigReload()
|
||||
|
|
|
|||
|
|
@ -103,6 +103,9 @@ object DependencyManager {
|
|||
if (pluginManager.isPluginEnabled("ToolStats"))
|
||||
genericDependencies.add(ToolStatsDependency(pluginManager.getPlugin("ToolStats")!!))
|
||||
|
||||
if (pluginManager.isPluginEnabled("ItemsAdder"))
|
||||
genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!))
|
||||
|
||||
for (dependency in genericDependencies)
|
||||
dependency.redirectListeners()
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.jankominek.disenchantment.events.DisenchantClickEvent
|
|||
import com.jankominek.disenchantment.events.DisenchantEvent
|
||||
import com.jankominek.disenchantment.events.ShatterClickEvent
|
||||
import com.jankominek.disenchantment.events.ShatterEvent
|
||||
import com.jankominek.disenchantment.listeners.DisenchantClickListener
|
||||
import com.jankominek.disenchantment.listeners.ShatterClickListener
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.entity.HumanEntity
|
||||
|
|
@ -32,7 +33,7 @@ class DisenchantmentDependency {
|
|||
// This is to avoid the disenchantment gui breaking
|
||||
try {
|
||||
unregisterStaticDisenchantmentListener(ShatterClickListener::class)
|
||||
unregisterStaticDisenchantmentListener(InventoryClickEvent::class)
|
||||
unregisterStaticDisenchantmentListener(DisenchantClickListener::class)
|
||||
} catch (e: Exception) {
|
||||
CustomAnvil.instance.logger.log(
|
||||
Level.SEVERE, "Could not initialize disenchantment support" +
|
||||
|
|
|
|||
|
|
@ -5,20 +5,14 @@ import org.bukkit.event.inventory.PrepareAnvilEvent
|
|||
import org.bukkit.plugin.Plugin
|
||||
import org.bukkit.plugin.RegisteredListener
|
||||
|
||||
abstract class GenericPluginDependency(protected val plugin: Plugin) {
|
||||
open class GenericPluginDependency(protected val plugin: Plugin) {
|
||||
|
||||
protected val preAnvil = ArrayList<RegisteredListener>()
|
||||
protected val postAnvil = ArrayList<RegisteredListener>()
|
||||
private val preAnvil = ArrayList<RegisteredListener>()
|
||||
private val postAnvil = ArrayList<RegisteredListener>()
|
||||
|
||||
open fun redirectListeners() {
|
||||
// get PreAnvil and PostAnvil listeners
|
||||
for (registeredListener in PrepareAnvilEvent.getHandlerList().registeredListeners) {
|
||||
|
||||
if (registeredListener.plugin != plugin) continue
|
||||
preAnvil.add(registeredListener)
|
||||
}
|
||||
|
||||
postAnvil.addAll(postAnvilEvents())
|
||||
fillPreAnvil(preAnvil)
|
||||
fillPostAnvil(postAnvil, preAnvil)
|
||||
|
||||
// get required PrepareAnvilEvent listener
|
||||
for (listener in preAnvil) {
|
||||
|
|
@ -28,10 +22,22 @@ abstract class GenericPluginDependency(protected val plugin: Plugin) {
|
|||
for (listener in postAnvil) {
|
||||
InventoryClickEvent.getHandlerList().unregister(listener)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract fun postAnvilEvents(): Collection<RegisteredListener>
|
||||
open fun fillPreAnvil(preAnvil: ArrayList<RegisteredListener>){
|
||||
// get PreAnvil and PostAnvil listeners
|
||||
for (registeredListener in PrepareAnvilEvent.getHandlerList().registeredListeners) {
|
||||
|
||||
if (registeredListener.plugin != plugin) continue
|
||||
preAnvil.add(registeredListener)
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun fillPostAnvil(
|
||||
postAnvil: ArrayList<RegisteredListener>,
|
||||
preAnvil: ArrayList<RegisteredListener>) {
|
||||
|
||||
}
|
||||
|
||||
open fun testPrepareAnvil(event: PrepareAnvilEvent): Boolean {
|
||||
val previousResult = event.result
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import java.lang.reflect.Method
|
|||
|
||||
class ToolStatsDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
||||
|
||||
// Sadly, getTokens function is private, so I need to do that
|
||||
// Sadly, getTokens function is private, so I need to do some reflectino
|
||||
private val getTokenMethod: Method =
|
||||
ItemChecker::class.java.getDeclaredMethod("getTokens", ItemStack::class.java)
|
||||
|
||||
|
|
@ -19,10 +19,6 @@ class ToolStatsDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
|||
getTokenMethod.trySetAccessible()
|
||||
}
|
||||
|
||||
override fun postAnvilEvents(): Collection<RegisteredListener> {
|
||||
return listOf()
|
||||
}
|
||||
|
||||
private fun ItemChecker.getTokenSafe(item: ItemStack?): Array<String> {
|
||||
if (item == null) return arrayOf()
|
||||
return getTokenMethod.invoke(this, item) as Array<String>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue