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-merging
# Conflicts: # build.gradle.kts # nms/nms-common/build.gradle.kts # nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/ExternGuiTester.kt # nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt # nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/scheduler/FoliaScheduler.kt # nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/scheduler/FoliaScheduler.kt # nms/v1_21R6/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_21R6_PacketManager.kt # settings.gradle.kts # src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GuiTesterSelector.kt # src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManager.kt # src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt # src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PaperPacketManager.kt # src/main/kotlin/xyz/alexcrea/cuanvil/dependency/scheduler/FoliaScheduler.kt
This commit is contained in:
commit
ff4be622f8
19 changed files with 1523 additions and 33 deletions
|
|
@ -31,7 +31,8 @@ public class UpdateHandler {
|
|||
new Version(1, 6, 7), PUpdate_1_6_7::handleUpdate,
|
||||
new Version(1, 8, 0), PUpdate_1_8_0::handleUpdate,
|
||||
new Version(1, 11, 0), PUpdate_1_11_0::handleUpdate,
|
||||
new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate
|
||||
new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate,
|
||||
new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate
|
||||
);
|
||||
|
||||
private static final List<MCUpdate> mcUpdateMap = List.of(
|
||||
|
|
@ -70,7 +71,7 @@ public class UpdateHandler {
|
|||
|
||||
boolean hadUpdate = false;
|
||||
for (MCUpdate mcUpdate : mcUpdateMap) {
|
||||
hadUpdate |= mcUpdate.handleUpdate(current);
|
||||
hadUpdate |= mcUpdate.handleUpdate(current, hadUpdate);
|
||||
}
|
||||
|
||||
if (hadUpdate) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public abstract class MCUpdate {
|
|||
this.version = version;
|
||||
}
|
||||
|
||||
public boolean handleUpdate(Version current){
|
||||
public boolean handleUpdate(Version current, boolean hadUpdate){
|
||||
// Test if we are running in this update version or better
|
||||
if(version.greaterThan(current))
|
||||
return false;
|
||||
|
|
@ -25,7 +25,9 @@ public abstract class MCUpdate {
|
|||
if(this.version.lesserEqual(version)) return false;
|
||||
}
|
||||
|
||||
CustomAnvil.instance.getLogger().info("Updating config to support " + version +" ...");
|
||||
if(!hadUpdate){
|
||||
CustomAnvil.instance.getLogger().info("Updating config to support minecraft " + current +" ...");
|
||||
}
|
||||
doUpdate();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public class Update_1_21_11 extends MCUpdate{
|
|||
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();
|
||||
|
||||
// Create spear group
|
||||
groupConfig.set("spears.type", "include");
|
||||
|
|
@ -36,6 +37,28 @@ public class Update_1_21_11 extends MCUpdate{
|
|||
addAbsentToList(conflictConfig, "restriction_knockback.notAffectedGroups", "spears");
|
||||
addAbsentToList(conflictConfig, "restriction_fire_aspect.notAffectedGroups", "spears");
|
||||
|
||||
// Unit repair for spears
|
||||
unitConfig.set("gold_ingot.golden_spear", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_spear", 0.25);
|
||||
unitConfig.set("iron_ingot.iron_spear", 0.25);
|
||||
unitConfig.set("diamond.diamond_spear", 0.25);
|
||||
unitConfig.set("netherite_ingot.netherite_spear", 0.25);
|
||||
|
||||
unitConfig.set("cobblestone.stone_spear", 0.25);
|
||||
unitConfig.set("cobbled_deepslate.stone_spear", 0.25);
|
||||
|
||||
unitConfig.set("oak_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("spruce_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("birch_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("jungle_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("acacia_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("dark_oak_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("mangrove_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("cherry_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("bamboo_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("crimson_planks.wooden_spear", 0.25);
|
||||
unitConfig.set("warped_planks.wooden_spear", 0.25);
|
||||
|
||||
// Create lunge enchant value and group
|
||||
baseConfig.set("enchant_limits.minecraft:lunge", 3);
|
||||
baseConfig.set("enchant_values.minecraft:lunge.item", 2);
|
||||
|
|
@ -51,6 +74,7 @@ public class Update_1_21_11 extends MCUpdate{
|
|||
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.saveToDisk(true);
|
||||
ConfigHolder.CONFLICT_HOLDER.saveToDisk(true);
|
||||
ConfigHolder.UNIT_REPAIR_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.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.update.minecraft;
|
||||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils;
|
||||
import xyz.alexcrea.cuanvil.update.Version;
|
||||
|
|
@ -17,6 +17,7 @@ public class Update_1_21_9 extends MCUpdate{
|
|||
protected void doUpdate() {
|
||||
var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||
var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
||||
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
|
||||
// Add cooper items to groups
|
||||
addAbsentToList(groupConfig, "helmets.items", "copper_helmet");
|
||||
|
|
@ -30,16 +31,34 @@ public class Update_1_21_9 extends MCUpdate{
|
|||
addAbsentToList(groupConfig, "axes.items", "copper_axe");
|
||||
addAbsentToList(groupConfig, "swords.items", "copper_sword");
|
||||
|
||||
// Add unit repair
|
||||
addCopperUnitRepair(unitConfig);
|
||||
|
||||
// Set version string as current
|
||||
baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, version.toString());
|
||||
|
||||
// Save
|
||||
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.saveToDisk(true);
|
||||
ConfigHolder.UNIT_REPAIR_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();
|
||||
}
|
||||
|
||||
public static void addCopperUnitRepair(FileConfiguration unitConfig) {
|
||||
// Add unit repair
|
||||
unitConfig.set("copper_ingot.copper_helmet", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_chestplate", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_leggings", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_boots", 0.25);
|
||||
|
||||
unitConfig.set("copper_ingot.copper_pickaxe", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_shovel", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_hoe", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_axe", 0.25);
|
||||
unitConfig.set("copper_ingot.copper_sword", 0.25);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package xyz.alexcrea.cuanvil.update.plugin;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils;
|
||||
import xyz.alexcrea.cuanvil.update.Version;
|
||||
import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_9;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
public class PUpdate_1_15_6 {
|
||||
|
||||
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
||||
// fix only needed for 1.21.9 and above
|
||||
Version current = UpdateUtils.currentMinecraftVersion();
|
||||
if (new Version(1, 21, 9).greaterThan(current)) return;
|
||||
|
||||
FileConfiguration unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
|
||||
// Add unit repair
|
||||
Update_1_21_9.addCopperUnitRepair(unitConfig);
|
||||
|
||||
toSave.add(ConfigHolder.UNIT_REPAIR_HOLDER);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package xyz.alexcrea.cuanvil.dependency
|
||||
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
||||
|
||||
object MinecraftVersionUtil {
|
||||
|
||||
val craftbukkitVersion: String?
|
||||
get() {
|
||||
val versionParts = UpdateUtils.currentMinecraftVersionArray()
|
||||
if (versionParts[0] != 1) return null
|
||||
|
||||
return when (versionParts[1]) {
|
||||
17 -> when (versionParts[2]) {
|
||||
0, 1 -> "1_17R1"
|
||||
else -> null
|
||||
}
|
||||
|
||||
18 -> when (versionParts[2]) {
|
||||
0, 1 -> "1_18R1"
|
||||
2 -> "1_18R2"
|
||||
else -> null
|
||||
}
|
||||
|
||||
19 -> when (versionParts[2]) {
|
||||
0, 1, 2 -> "1_19R1"
|
||||
3 -> "1_19R2"
|
||||
4 -> "1_19R3"
|
||||
else -> null
|
||||
}
|
||||
|
||||
20 -> when (versionParts[2]) {
|
||||
0, 1 -> "1_20R1"
|
||||
2 -> "1_20R2"
|
||||
3, 4 -> "1_20R3"
|
||||
5, 6 -> "1_20R4"
|
||||
else -> null
|
||||
}
|
||||
|
||||
21 -> when (versionParts[2]) {
|
||||
0, 1 -> "1_21R1"
|
||||
2, 3 -> "1_21R2"
|
||||
4 -> "1_21R3"
|
||||
5 -> "1_21R4"
|
||||
6, 7, 8 -> "1_21R5"
|
||||
9, 10 -> "1_21R6"
|
||||
11 -> "1_21R7"
|
||||
else -> null
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.gui
|
||||
|
||||
import org.bukkit.inventory.InventoryView
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class GenericExternGuiTester: ExternGuiTester {
|
||||
|
||||
companion object {
|
||||
private const val ANVIL_CLASS_NAME = "org.bukkit.craftbukkit.inventory.view.CraftAnvilView"
|
||||
private const val INV_CLASS_NAME = "org.bukkit.craftbukkit.inventory.CraftInventoryView"
|
||||
private const val HANDLE_METHOD_NAME = "getHandle"
|
||||
}
|
||||
|
||||
var testExist = false
|
||||
var inTesting = false
|
||||
|
||||
var testedClass: String? = null
|
||||
lateinit var getHandleMethod: Method
|
||||
|
||||
override fun getContainerClass(view: InventoryView): Class<Any>? {
|
||||
// In case we are in a test environment
|
||||
if(!testExist) testClassExist()
|
||||
if(inTesting) return view.javaClass //TEMPORARY
|
||||
|
||||
if(!testedClass.contentEquals(view.javaClass.name))
|
||||
return null
|
||||
|
||||
val container = getHandleMethod.invoke(view)
|
||||
return container.javaClass
|
||||
}
|
||||
|
||||
fun tryFromClass(className: String) {
|
||||
val clazz = Class.forName(className)
|
||||
testedClass = className
|
||||
|
||||
getHandleMethod = clazz.getMethod(HANDLE_METHOD_NAME)
|
||||
}
|
||||
|
||||
fun testClassExist() {
|
||||
testExist = true
|
||||
|
||||
// We first try to get craft anvil interface,
|
||||
// but is absent on old version so we try craft inventory view before
|
||||
try {
|
||||
tryFromClass(ANVIL_CLASS_NAME)
|
||||
return
|
||||
}
|
||||
catch (_: ClassNotFoundException) {}
|
||||
catch (_: NoSuchMethodException) {}
|
||||
|
||||
try {
|
||||
tryFromClass(INV_CLASS_NAME)
|
||||
return
|
||||
}
|
||||
catch (_: ClassNotFoundException) {}
|
||||
catch (_: NoSuchMethodException) {}
|
||||
|
||||
inTesting = true
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,20 +4,12 @@ import xyz.alexcrea.cuanvil.update.UpdateUtils
|
|||
|
||||
object GuiTesterSelector {
|
||||
|
||||
val spigotVersionString: String?
|
||||
val selectGuiTester: ExternGuiTester?
|
||||
get() {
|
||||
val versionParts = UpdateUtils.currentMinecraftVersionArray()
|
||||
if (versionParts[0] != 1) return null
|
||||
|
||||
return when (versionParts[1]) {
|
||||
21 -> when (versionParts[2]) {
|
||||
8 -> "1_21_R5"
|
||||
9, 10 -> "1_21_R6"
|
||||
else -> null
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
return GenericExternGuiTester()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -213,7 +213,8 @@ class PrepareAnvilListener : Listener {
|
|||
else if (useColor) it.displayName
|
||||
else ChatColor.stripColor(it.displayName)
|
||||
|
||||
if (!displayName.contentEquals(renameText)) {
|
||||
|
||||
if (!displayName.contentEquals(renameText) && !(displayName == null && renameText == "")) {
|
||||
it.setDisplayName(renameText)
|
||||
resultItem.itemMeta = it
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue