mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 16:35:57 +02:00
Compare commits
No commits in common. "16e4f0a9239585d23e21479513c57d62495c8e32" and "c062684a3cea5a5b98b5113ce8fc49685f126281" have entirely different histories.
16e4f0a923
...
c062684a3c
36 changed files with 106 additions and 231 deletions
|
|
@ -39,8 +39,7 @@ ca.bypass.level: Allow player to bypass every level limit (no custom limit)
|
||||||
|
|
||||||
# Command permissions
|
# Command permissions
|
||||||
ca.command.reload: Allow administrator to reload the plugin's configs
|
ca.command.reload: Allow administrator to reload the plugin's configs
|
||||||
ca.command.diagnostic: Get debug information about the plugin and server
|
ca.command.diagnostic: Allow adminastator to diagnistic some simple problem with the plugin
|
||||||
ca.command.enchantment: Allows to set enchantment to holden item
|
|
||||||
ca.config.edit: Allow administrator to edit the plugin's config in game
|
ca.config.edit: Allow administrator to edit the plugin's config in game
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "xyz.alexcrea"
|
group = "xyz.alexcrea"
|
||||||
version = "1.18.0"
|
version = "1.17.7"
|
||||||
|
|
||||||
val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null
|
val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null
|
||||||
val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true"
|
val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
@ -160,6 +160,13 @@ restriction_sweeping_edge:
|
||||||
enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ]
|
enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ]
|
||||||
notAffectedGroups: [ enchanted_book, swords ]
|
notAffectedGroups: [ enchanted_book, swords ]
|
||||||
|
|
||||||
|
# Do not exist in 1.18, that mean useInFuture will be set to true
|
||||||
|
# useInFuture set to true also mean it will not warn if there is an issue
|
||||||
|
restriction_swift_sneak:
|
||||||
|
useInFuture: true
|
||||||
|
enchantments: [ minecraft:swift_sneak ]
|
||||||
|
notAffectedGroups: [ enchanted_book, leggings ]
|
||||||
|
|
||||||
restriction_thorns:
|
restriction_thorns:
|
||||||
enchantments: [ minecraft:thorns ]
|
enchantments: [ minecraft:thorns ]
|
||||||
notAffectedGroups: [ enchanted_book, armors ]
|
notAffectedGroups: [ enchanted_book, armors ]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
@ -275,7 +275,10 @@ restriction_sweeping_edge:
|
||||||
- enchanted_book
|
- enchanted_book
|
||||||
- swords
|
- swords
|
||||||
|
|
||||||
|
# Do not exist in 1.18, that mean useInFuture will be set to true
|
||||||
|
# useInFuture set to true also mean it will not warn if there is an issue
|
||||||
restriction_swift_sneak:
|
restriction_swift_sneak:
|
||||||
|
useInFuture: true
|
||||||
enchantments:
|
enchantments:
|
||||||
- minecraft:swift_sneak
|
- minecraft:swift_sneak
|
||||||
notAffectedGroups:
|
notAffectedGroups:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
@ -272,7 +272,10 @@ restriction_sweeping_edge:
|
||||||
- enchanted_book
|
- enchanted_book
|
||||||
- swords
|
- swords
|
||||||
|
|
||||||
|
# Do not exist in 1.18, that mean useInFuture will be set to true
|
||||||
|
# useInFuture set to true also mean it will not warn if there is an issue
|
||||||
restriction_swift_sneak:
|
restriction_swift_sneak:
|
||||||
|
useInFuture: true
|
||||||
enchantments:
|
enchantments:
|
||||||
- minecraft:swift_sneak
|
- minecraft:swift_sneak
|
||||||
notAffectedGroups:
|
notAffectedGroups:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package xyz.alexcrea.cuanvil.util
|
package xyz.alexcrea.cuanvil.util
|
||||||
|
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.inventory.meta.Damageable
|
import org.bukkit.inventory.meta.Damageable
|
||||||
|
|
||||||
// I LOVE support of old versions and needing to do modules like that
|
// I LOVE support of old versions and needing to do modules like that
|
||||||
|
|
@ -11,8 +10,8 @@ object MaxDamageCheckerUtil {
|
||||||
/**
|
/**
|
||||||
* @return max damage or int max if not set
|
* @return max damage or int max if not set
|
||||||
*/
|
*/
|
||||||
fun getMaxDamage(type: Material, meta: Damageable): Int {
|
fun getMaxDamage(meta: Damageable): Int {
|
||||||
if(!meta.hasMaxDamage()) return type.maxDurability.toInt()
|
if(!meta.hasMaxDamage()) return Integer.MAX_VALUE
|
||||||
return meta.maxDamage
|
return meta.maxDamage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,10 @@ public class UpdateHandler {
|
||||||
new Version(1, 11, 0), PUpdate_1_11_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,
|
new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate,
|
||||||
new Version(1, 18, 0), PUpdate_1_18::handleUpdate
|
new Version(1, 17, 7), PUpdate_1_17_7::handleUpdate
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final List<MCUpdate> mcUpdateMap = List.of(
|
private static final List<MCUpdate> mcUpdateMap = List.of(
|
||||||
new Update_1_19(),
|
|
||||||
new Update_1_20_5(),
|
new Update_1_20_5(),
|
||||||
new Update_1_21(),
|
new Update_1_21(),
|
||||||
new Update_1_21_9(),
|
new Update_1_21_9(),
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.update.minecraft;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
|
||||||
import xyz.alexcrea.cuanvil.update.Version;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
|
||||||
|
|
||||||
public class Update_1_19 extends MCUpdate {
|
|
||||||
|
|
||||||
public Update_1_19() {
|
|
||||||
super(new Version(1, 19));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doUpdate() {
|
|
||||||
var tosave = new HashSet<ConfigHolder>();
|
|
||||||
updateName(tosave);
|
|
||||||
|
|
||||||
for (ConfigHolder holder : tosave) {
|
|
||||||
holder.saveToDisk(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateName(@NotNull Set<ConfigHolder> tosave) {
|
|
||||||
var conflict = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
|
||||||
|
|
||||||
addAbsentToList(conflict, "restriction_swift_sneak.enchantments", "minecraft:swift_sneak");
|
|
||||||
addAbsentToList(conflict, "restriction_swift_sneak.notAffectedGroups", "leggings", "enchanted_book");
|
|
||||||
|
|
||||||
ConfigHolder.ITEM_GROUP_HOLDER.reload();
|
|
||||||
|
|
||||||
tosave.add(ConfigHolder.DEFAULT_CONFIG);
|
|
||||||
tosave.add(ConfigHolder.CONFLICT_HOLDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -3,20 +3,19 @@ package xyz.alexcrea.cuanvil.update.plugin;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.update.UpdateUtils;
|
import xyz.alexcrea.cuanvil.update.UpdateUtils;
|
||||||
import xyz.alexcrea.cuanvil.update.Version;
|
import xyz.alexcrea.cuanvil.update.Version;
|
||||||
import xyz.alexcrea.cuanvil.update.minecraft.Update_1_19;
|
|
||||||
import xyz.alexcrea.cuanvil.update.minecraft.Update_1_20_5;
|
import xyz.alexcrea.cuanvil.update.minecraft.Update_1_20_5;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class PUpdate_1_18 {
|
public class PUpdate_1_17_7 {
|
||||||
|
|
||||||
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
||||||
|
// fix only needed for 1.20.5 and above
|
||||||
Version current = UpdateUtils.currentMinecraftVersion();
|
Version current = UpdateUtils.currentMinecraftVersion();
|
||||||
if (new Version(1, 19, 0).greaterThan(current)) return;
|
|
||||||
Update_1_19.updateName(toSave);
|
|
||||||
|
|
||||||
if (new Version(1, 20, 5).greaterThan(current)) return;
|
if (new Version(1, 20, 5).greaterThan(current)) return;
|
||||||
|
|
||||||
Update_1_20_5.updateName(toSave);
|
Update_1_20_5.updateName(toSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -57,8 +57,6 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
// Permission string required to edit the plugin's config
|
// Permission string required to edit the plugin's config
|
||||||
const val editConfigPermission = "ca.config.edit"
|
const val editConfigPermission = "ca.config.edit"
|
||||||
|
|
||||||
// Permission string required to edit the plugin's config
|
|
||||||
const val giveEnchantmentPermission = "ca.command.enchantment"
|
|
||||||
|
|
||||||
// Command Name to reload the config
|
// Command Name to reload the config
|
||||||
const val commandReloadName = "anvilconfigreload"
|
const val commandReloadName = "anvilconfigreload"
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package io.delilaheve.util
|
package io.delilaheve.util
|
||||||
|
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.Material.ENCHANTED_BOOK
|
import org.bukkit.Material.ENCHANTED_BOOK
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.Damageable
|
import org.bukkit.inventory.meta.Damageable
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
||||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
||||||
import xyz.alexcrea.cuanvil.util.MaxDamageCheckerUtil
|
import xyz.alexcrea.cuanvil.util.MaxDamageCheckerUtil
|
||||||
|
|
@ -21,11 +21,11 @@ object ItemUtil {
|
||||||
*/
|
*/
|
||||||
fun ItemStack.isEnchantedBook() = type == ENCHANTED_BOOK
|
fun ItemStack.isEnchantedBook() = type == ENCHANTED_BOOK
|
||||||
|
|
||||||
private fun maxDamage(type: Material, damageable: Damageable): Int {
|
private fun maxDamage(damageable: Damageable): Int {
|
||||||
val ver = UpdateUtils.currentMinecraftVersion()
|
val ver = UpdateUtils.currentMinecraftVersion()
|
||||||
if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return type.maxDurability.toInt()
|
if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return Integer.MAX_VALUE
|
||||||
|
|
||||||
return MaxDamageCheckerUtil.getMaxDamage(type, damageable)
|
return MaxDamageCheckerUtil.getMaxDamage(damageable)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,22 +37,23 @@ object ItemUtil {
|
||||||
first: ItemStack,
|
first: ItemStack,
|
||||||
second: ItemStack
|
second: ItemStack
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val meta = itemMeta
|
(itemMeta as? Damageable)?.let {
|
||||||
if(meta !is Damageable) return false
|
val durability = type.maxDurability.toInt()
|
||||||
|
val firstDamage = (first.itemMeta as? Damageable)?.damage ?: 0
|
||||||
|
if (firstDamage == 0) return false
|
||||||
|
|
||||||
val maxDamage = maxDamage(type, meta)
|
val firstDurability = durability - firstDamage
|
||||||
val damage = (first.itemMeta as? Damageable)?.damage ?: 0
|
val secondDamage = (second.itemMeta as? Damageable)?.damage ?: 0
|
||||||
if (damage == 0) return false
|
val secondDurability = durability - secondDamage
|
||||||
|
val combinedDurability = firstDurability + secondDurability
|
||||||
|
val newDurability = min(combinedDurability, durability)
|
||||||
|
|
||||||
val firstDurability = maxDamage - damage
|
val maxDamage = maxDamage(it)
|
||||||
val secondDamage = (second.itemMeta as? Damageable)?.damage ?: 0
|
it.damage = min(durability - newDurability, maxDamage)
|
||||||
val secondDurability = maxDamage - secondDamage
|
itemMeta = it
|
||||||
val combinedDurability = firstDurability + secondDurability
|
return true
|
||||||
val newDurability = min(combinedDurability, maxDamage)
|
}
|
||||||
|
return false
|
||||||
meta.damage = min(maxDamage - newDurability, maxDamage)
|
|
||||||
this.itemMeta = meta
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ItemStack.unitRepair(
|
fun ItemStack.unitRepair(
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import org.bukkit.ChatColor
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
|
||||||
|
|
||||||
abstract class CASubCommand: CommandExecutor {
|
abstract class CASubCommand: CommandExecutor {
|
||||||
|
|
||||||
|
|
@ -44,14 +43,4 @@ abstract class CASubCommand: CommandExecutor {
|
||||||
return "no description"
|
return "no description"
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun allEnchantmentsByName(): Collection<String> {
|
|
||||||
val names = mutableSetOf<String>()
|
|
||||||
for (enchantment in CAEnchantmentRegistry.getInstance().values()) {
|
|
||||||
names.add(enchantment.name)
|
|
||||||
names.add(enchantment.key.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
return names
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.command.TabCompleter
|
import org.bukkit.command.TabCompleter
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
|
@ -17,14 +18,13 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
private val editConfigCommand = EditConfigExecutor()
|
private val editConfigCommand = EditConfigExecutor()
|
||||||
private val helpCommand = HelpExecutor()
|
private val helpCommand = HelpExecutor()
|
||||||
private val commands: ImmutableMap<String, CASubCommand> = ImmutableMap.of(
|
private val commands = ImmutableMap.of(
|
||||||
"gui", editConfigCommand,
|
"gui", editConfigCommand,
|
||||||
"config", editConfigCommand,
|
"config", editConfigCommand,
|
||||||
"reload", ReloadExecutor(),
|
"reload", ReloadExecutor(),
|
||||||
"diagnostic", DiagnosticExecutor(),
|
"diagnostic", DiagnosticExecutor(),
|
||||||
"debug", DebugToggleExecutor(),
|
"debug", DebugToggleExecutor(),
|
||||||
"help", helpCommand,
|
"help", helpCommand,
|
||||||
"enchant", EnchantExecutor(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
@ -95,11 +95,9 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
}
|
}
|
||||||
|
|
||||||
//assumed all provided tab completed string are lowercase
|
//assumed all provided tab completed string are lowercase
|
||||||
val prefix = args[args.size - 1]
|
|
||||||
return result.stream()
|
return result.stream()
|
||||||
.filter { it.startsWith(prefix) }
|
.filter { it.startsWith(args[args.size - 1]) }
|
||||||
.sorted()
|
.sorted()
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import org.bukkit.entity.HumanEntity
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
|
||||||
|
|
@ -102,6 +103,16 @@ class EditConfigExecutor : CASubCommand() {
|
||||||
// Tab completer
|
// Tab completer
|
||||||
// ---------------
|
// ---------------
|
||||||
|
|
||||||
|
private fun allEnchantmentsByName(): Collection<String> {
|
||||||
|
val names = mutableSetOf<String>()
|
||||||
|
for (enchantment in CAEnchantmentRegistry.getInstance().values()) {
|
||||||
|
names.add(enchantment.name)
|
||||||
|
names.add(enchantment.key.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
||||||
list.addAll(
|
list.addAll(
|
||||||
when (args.size) {
|
when (args.size) {
|
||||||
|
|
@ -116,6 +127,7 @@ class EditConfigExecutor : CASubCommand() {
|
||||||
else -> listOf()
|
else -> listOf()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.command
|
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
|
||||||
import io.delilaheve.util.ConfigOptions
|
|
||||||
import org.bukkit.command.Command
|
|
||||||
import org.bukkit.command.CommandSender
|
|
||||||
import org.bukkit.entity.HumanEntity
|
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
|
||||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
|
||||||
|
|
||||||
class EnchantExecutor : CASubCommand() {
|
|
||||||
|
|
||||||
|
|
||||||
override fun allowed(sender: CommandSender): Boolean {
|
|
||||||
return sender.hasPermission(CustomAnvil.giveEnchantmentPermission)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun description(): String {
|
|
||||||
return "Allows to set enchantment to holden item"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun executeCommand(
|
|
||||||
sender: CommandSender,
|
|
||||||
cmd: Command,
|
|
||||||
cmdstr: String,
|
|
||||||
args: Array<out String>
|
|
||||||
): Boolean {
|
|
||||||
if (sender !is HumanEntity) return true
|
|
||||||
|
|
||||||
if (!allowed(sender)) {
|
|
||||||
sender.sendMessage("No permission to execute this command")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
when (args.size) {
|
|
||||||
0 -> {
|
|
||||||
sender.sendMessage("Missing enchantment parameter")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
1 -> {
|
|
||||||
sender.sendMessage("Missing level parameter")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val enchants = EnchantmentApi.getListByName(args[0].lowercase())
|
|
||||||
if (enchants.isEmpty()) {
|
|
||||||
sender.sendMessage("Enchantment not found: ${args[0]}")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
val enchant = enchants.iterator().next()
|
|
||||||
|
|
||||||
val level = args[1].toIntOrNull()?.coerceIn(0, ConfigOptions.ENCHANT_LIMIT)
|
|
||||||
if (level == null) {
|
|
||||||
sender.sendMessage("Invalid number: ${args[1]}")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
val inHand = sender.inventory.itemInMainHand
|
|
||||||
if (inHand.isAir) {
|
|
||||||
sender.sendMessage("Cannot enchant this item")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level == 0) {
|
|
||||||
enchant.removeFrom(inHand)
|
|
||||||
sender.sendMessage("${enchant.prettyName} removed")
|
|
||||||
} else {
|
|
||||||
enchant.addEnchantmentUnsafe(inHand, level)
|
|
||||||
sender.sendMessage("${enchant.prettyName} set to level $level")
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
|
||||||
if (sender !is HumanEntity) return
|
|
||||||
|
|
||||||
list.addAll(
|
|
||||||
when (args.size) {
|
|
||||||
1 -> allEnchantmentsByName()
|
|
||||||
2 -> findEnchantmentLevels(sender, args[0])
|
|
||||||
|
|
||||||
else -> listOf()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findEnchantmentLevels(
|
|
||||||
sender: HumanEntity,
|
|
||||||
name: String
|
|
||||||
): Collection<String> {
|
|
||||||
val enchants = EnchantmentApi.getListByName(name.lowercase())
|
|
||||||
if (enchants.isEmpty()) return listOf()
|
|
||||||
|
|
||||||
val enchant = enchants.iterator().next()
|
|
||||||
val limit = ConfigOptions.enchantLimit(enchant)
|
|
||||||
val result = mutableListOf<String>()
|
|
||||||
|
|
||||||
for (i in 1 until limit + 1) {
|
|
||||||
result.add(i.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
val inHand = sender.inventory.itemInMainHand
|
|
||||||
if (enchant.isEnchantmentPresent(inHand))
|
|
||||||
result.add("0")
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -3,6 +3,7 @@ package xyz.alexcrea.cuanvil.command
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package xyz.alexcrea.cuanvil.group
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.configuration.ConfigurationSection
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
|
import org.bukkit.enchantments.Enchantment
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment
|
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment
|
||||||
|
|
@ -32,6 +33,10 @@ class EnchantConflictManager {
|
||||||
// Path for the maximum number of enchantment before validating the conflict
|
// Path for the maximum number of enchantment before validating the conflict
|
||||||
const val ENCH_MAX_PATH = "maxEnchantmentBeforeConflict"
|
const val ENCH_MAX_PATH = "maxEnchantmentBeforeConflict"
|
||||||
|
|
||||||
|
// Path for a flag: if the enchantment will be used in the last supported version
|
||||||
|
// TODO maybe replace this system by a list of "future" enchantment.
|
||||||
|
private const val FUTURE_USE_PATH = "useInFuture"
|
||||||
|
|
||||||
// Default name for a joining group
|
// Default name for a joining group
|
||||||
const val DEFAULT_GROUP_NAME = "joinedGroup"
|
const val DEFAULT_GROUP_NAME = "joinedGroup"
|
||||||
}
|
}
|
||||||
|
|
@ -96,6 +101,8 @@ class EnchantConflictManager {
|
||||||
itemManager: ItemGroupManager,
|
itemManager: ItemGroupManager,
|
||||||
conflictName: String
|
conflictName: String
|
||||||
): EnchantConflictGroup {
|
): EnchantConflictGroup {
|
||||||
|
// Is it planed for the future
|
||||||
|
val futureUse = section.getBoolean(FUTURE_USE_PATH, false)
|
||||||
// Create conflict
|
// Create conflict
|
||||||
val conflict = createConflictObject(section, itemManager, conflictName)
|
val conflict = createConflictObject(section, itemManager, conflictName)
|
||||||
// Read and add enchantment to conflict
|
// Read and add enchantment to conflict
|
||||||
|
|
@ -103,13 +110,17 @@ class EnchantConflictManager {
|
||||||
for (enchantName in enchantList) {
|
for (enchantName in enchantList) {
|
||||||
val enchants = getEnchantByIdentifier(enchantName)
|
val enchants = getEnchantByIdentifier(enchantName)
|
||||||
if (enchants.isEmpty()) {
|
if (enchants.isEmpty()) {
|
||||||
CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName")
|
if (!futureUse) { //TODO future use will be deprecated once the new update system is finished
|
||||||
|
CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName")
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
conflict.addEnchantments(enchants)
|
conflict.addEnchantments(enchants)
|
||||||
}
|
}
|
||||||
if (conflict.getEnchants().isEmpty()) {
|
if (conflict.getEnchants().isEmpty()) {
|
||||||
CustomAnvil.instance.logger.warning("Conflict $conflictName do not have valid enchantment, it will not do anything")
|
if (!futureUse) { //TODO future use will be deprecated once the new update system is finished
|
||||||
|
CustomAnvil.instance.logger.warning("Conflict $conflictName do not have valid enchantment, it will not do anything")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val conflictsAfterLevel = section.getConfigurationSection(CONFLICT_AFTER_LEVEL_LIST_PATH)
|
val conflictsAfterLevel = section.getConfigurationSection(CONFLICT_AFTER_LEVEL_LIST_PATH)
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,16 @@ import io.delilaheve.util.ConfigOptions
|
||||||
object AnvilUseTypeUtil {
|
object AnvilUseTypeUtil {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
By kotlin not having static function outside of companion object I need to do another util class only for 1 function:
|
By stupidity of kotlin not allowing static function outside of companion object I need to do another util class only for 1 function:
|
||||||
Companion object on enum class seems to get initialized AFTER the enum itself
|
Companion object on enum class seems to get initialized AFTER the enum itself
|
||||||
that mean. if you want to call a static function on enum construction YOU CAN'T. you need to do this stupid thing,
|
that mean. if you want to call a static function on the enum class itself YOU CAN'T. you need to do this stupid thing
|
||||||
or you can make a stupid top level function or object that at least as bad as this
|
or you can make a stupid top level function OR object that even worse because of global scope pollution
|
||||||
I mean, this is still an unnecessary class that should not exist but as a class is better than a random function in my opinion
|
(btw was gpt ""solution"". fortunately I do not "vibe code" so I do what I know instead of stupid AI solution & code)
|
||||||
|
I mean, this is still global scope pollution bc of a USELESS class that SHOULD not exist but as a class is better than a random *ss function
|
||||||
|
|
||||||
|
sorry for the rent but this made me frustrated
|
||||||
|
|
||||||
|
Note: I still like a lot of part of kotlin compared to java but this part is one that I hate
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Get config path for normal anvil use
|
* Get config path for normal anvil use
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit most of these config.
|
# It is recommended that you use /configanvil to edit most of these config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
@ -160,6 +160,13 @@ restriction_sweeping_edge:
|
||||||
enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ]
|
enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ]
|
||||||
notAffectedGroups: [ enchanted_book, swords ]
|
notAffectedGroups: [ enchanted_book, swords ]
|
||||||
|
|
||||||
|
# Do not exist in 1.18, that mean useInFuture will be set to true
|
||||||
|
# useInFuture set to true also mean it will not warn if there is an issue
|
||||||
|
restriction_swift_sneak:
|
||||||
|
useInFuture: true
|
||||||
|
enchantments: [ minecraft:swift_sneak ]
|
||||||
|
notAffectedGroups: [ enchanted_book, leggings ]
|
||||||
|
|
||||||
restriction_thorns:
|
restriction_thorns:
|
||||||
enchantments: [ minecraft:thorns ]
|
enchantments: [ minecraft:thorns ]
|
||||||
notAffectedGroups: [ enchanted_book, armors ]
|
notAffectedGroups: [ enchanted_book, armors ]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,6 @@ permissions:
|
||||||
ca.command.diagnostic:
|
ca.command.diagnostic:
|
||||||
default: op
|
default: op
|
||||||
description: Get debug information about the plugin and server
|
description: Get debug information about the plugin and server
|
||||||
ca.command.enchantment:
|
|
||||||
default: op
|
|
||||||
description: Allows to set enchantment to holden item
|
|
||||||
ca.config.edit:
|
ca.config.edit:
|
||||||
default: op
|
default: op
|
||||||
description: Allow administrator to edit the plugin's config in game
|
description: Allow administrator to edit the plugin's config in game
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /ca config to edit theses config.
|
# It is recommended that you use /configanvil to edit theses config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue