mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
base xp cost + work penalty
This commit is contained in:
parent
d2fdaace80
commit
2f30e19573
13 changed files with 222 additions and 154 deletions
|
|
@ -282,10 +282,10 @@ lore_edit:
|
|||
fixed_cost: 1
|
||||
# Cost used for every lore line added
|
||||
per_line_cost: 0
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
# If adding the lore consume the book & quil
|
||||
do_consume: false
|
||||
|
||||
|
|
@ -296,18 +296,19 @@ lore_edit:
|
|||
fixed_cost: 1
|
||||
# Cost used for every lore line removed
|
||||
per_line_cost: 0
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
|
||||
# Allow using color code and hexadecimal color when editing lore via book & quil
|
||||
#
|
||||
# Color code are prefixed by "&" and hexadecimal color by "#"
|
||||
# Color code will not be applied if it colors nothing. "&&" can be used to write "&"
|
||||
color:
|
||||
allow_color_code: false
|
||||
allow_hexadecimal_color: false
|
||||
allow_color_code: true
|
||||
allow_hexadecimal_color: true
|
||||
use_cost: 0
|
||||
|
||||
paper:
|
||||
# Permission is ca.lore_edit.paper
|
||||
|
|
@ -320,10 +321,10 @@ lore_edit:
|
|||
enabled: false
|
||||
# Cost used every time
|
||||
fixed_cost: 1
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
# If adding the lore line consume the paper
|
||||
do_consume: false
|
||||
|
||||
|
|
@ -332,18 +333,19 @@ lore_edit:
|
|||
enabled: false
|
||||
# Cost used every time
|
||||
fixed_cost: 1
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
|
||||
# Allow using color code and hexadecimal color when editing lore via book & quil
|
||||
#
|
||||
# Color code are prefixed by "&" and hexadecimal color by "#"
|
||||
# Color code will not be applied if it colors nothing. "&&" can be used to write "&"
|
||||
color:
|
||||
allow_color_code: false
|
||||
allow_hexadecimal_color: false
|
||||
allow_color_code: true
|
||||
allow_hexadecimal_color: true
|
||||
use_cost: 0
|
||||
|
||||
# Whether to show debug logging
|
||||
debug_log: false
|
||||
|
|
|
|||
|
|
@ -282,10 +282,10 @@ lore_edit:
|
|||
fixed_cost: 1
|
||||
# Cost used for every lore line added
|
||||
per_line_cost: 0
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
# If adding the lore consume the book & quil
|
||||
do_consume: false
|
||||
|
||||
|
|
@ -296,18 +296,19 @@ lore_edit:
|
|||
fixed_cost: 1
|
||||
# Cost used for every lore line removed
|
||||
per_line_cost: 0
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
|
||||
# Allow using color code and hexadecimal color when editing lore via book & quil
|
||||
#
|
||||
# Color code are prefixed by "&" and hexadecimal color by "#"
|
||||
# Color code will not be applied if it colors nothing. "&&" can be used to write "&"
|
||||
color:
|
||||
allow_color_code: false
|
||||
allow_hexadecimal_color: false
|
||||
allow_color_code: true
|
||||
allow_hexadecimal_color: true
|
||||
use_cost: 0
|
||||
|
||||
paper:
|
||||
# Permission is ca.lore_edit.paper
|
||||
|
|
@ -320,10 +321,10 @@ lore_edit:
|
|||
enabled: false
|
||||
# Cost used every time
|
||||
fixed_cost: 1
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
# If adding the lore line consume the paper
|
||||
do_consume: false
|
||||
|
||||
|
|
@ -332,18 +333,19 @@ lore_edit:
|
|||
enabled: false
|
||||
# Cost used every time
|
||||
fixed_cost: 1
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
|
||||
# Allow using color code and hexadecimal color when editing lore via book & quil
|
||||
#
|
||||
# Color code are prefixed by "&" and hexadecimal color by "#"
|
||||
# Color code will not be applied if it colors nothing. "&&" can be used to write "&"
|
||||
color:
|
||||
allow_color_code: false
|
||||
allow_hexadecimal_color: false
|
||||
allow_color_code: true
|
||||
allow_hexadecimal_color: true
|
||||
use_cost: 0
|
||||
|
||||
# Whether to show debug logging
|
||||
debug_log: false
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
this.currentType = ConfigOptions.INSTANCE.getWorkPenaltyType();
|
||||
this.items = new EnumMap<>(this.currentType.getPartMap());
|
||||
|
||||
for (AnvilUseType type : AnvilUseType.getEntries()) {
|
||||
for (AnvilUseType type : useTypes.keySet()) {
|
||||
updateGuiForType(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -80,6 +80,14 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
}, CustomAnvil.instance);
|
||||
}
|
||||
|
||||
private static final Map<AnvilUseType, String> useTypes =
|
||||
Map.of(
|
||||
AnvilUseType.RENAME_ONLY, "a1z9Z",
|
||||
AnvilUseType.MERGE, "b2y8Y",
|
||||
AnvilUseType.UNIT_REPAIR, "c3x7X",
|
||||
AnvilUseType.CUSTOM_CRAFT, "d4w6W"
|
||||
);
|
||||
|
||||
@Override
|
||||
protected Pattern getGuiPattern() {
|
||||
return new Pattern( // Yeah that a mess
|
||||
|
|
@ -92,13 +100,14 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
|
|||
|
||||
public void updateGuiForType(AnvilUseType type) {
|
||||
PatternPane pane = getPane();
|
||||
int ordinal = type.ordinal();
|
||||
|
||||
int display = 'z' - ordinal;
|
||||
int increment = 'a' + ordinal;
|
||||
int additive = '1' + ordinal;
|
||||
int exclusiveIncrement = 'Z' - ordinal;
|
||||
int exclusiveAdditive = '9' - ordinal;
|
||||
String typeVals = useTypes.get(type);
|
||||
|
||||
char increment = typeVals.charAt(0);
|
||||
char additive = typeVals.charAt(1);
|
||||
char display = typeVals.charAt(2);
|
||||
char exclusiveIncrement = typeVals.charAt(3);
|
||||
char exclusiveAdditive = typeVals.charAt(4);
|
||||
|
||||
WorkPenaltyType.WorkPenaltyPart part = items.get(type);
|
||||
String increasingStr = (part.penaltyIncrease() ? "§a" : "§c") + "Increasing";
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ public class PluginSetDefault {
|
|||
nbSet+= trySetDefault(config, path + IS_ENABLED, DEFAULT_IS_ENABLED);
|
||||
nbSet+= trySetDefault(config, path + FIXED_COST, DEFAULT_FIXED_COST);
|
||||
nbSet+= trySetDefault(config, path + PER_LINE_COST, DEFAULT_PER_LINE_COST);
|
||||
nbSet+= trySetDefault(config, path + USE_COST_PENALTY, DEFAULT_USE_COST_PENALTY);
|
||||
nbSet+= trySetDefault(config, path + INCREASE_COST_PENALTY, DEFAULT_INCREASE_COST_PENALTY);
|
||||
if(value.isAppend()){
|
||||
nbSet+= trySetDefault(config, path + DO_CONSUME, DEFAULT_DO_CONSUME);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,11 +289,10 @@ object ConfigOptions {
|
|||
*/
|
||||
fun workPenaltyPart(type: AnvilUseType): WorkPenaltyPart {
|
||||
val config = ConfigHolder.DEFAULT_CONFIG.config
|
||||
val path = WORK_PENALTY_ROOT + "." + type.typeName
|
||||
|
||||
// Find values
|
||||
val defaultPenalty = type.defaultPenalty
|
||||
val section = config.getConfigurationSection(path) ?: return defaultPenalty
|
||||
val section = config.getConfigurationSection(type.path) ?: return defaultPenalty
|
||||
|
||||
val penaltyIncrease = section.getBoolean(WORK_PENALTY_INCREASE, defaultPenalty.penaltyIncrease)
|
||||
val penaltyAdditive = section.getBoolean(WORK_PENALTY_ADDITIVE, defaultPenalty.penaltyAdditive)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
|||
import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil
|
||||
import xyz.alexcrea.cuanvil.util.config.LoreEditType
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.math.min
|
||||
|
||||
class AnvilResultListener : Listener {
|
||||
|
|
@ -321,8 +322,9 @@ class AnvilResultListener : Listener {
|
|||
|
||||
val editType = AnvilLoreEditUtil.bookLoreEditIsAppend(leftItem, rightItem) ?: return false
|
||||
|
||||
val xpCost = AtomicInteger()
|
||||
if (editType) {
|
||||
if (output != AnvilLoreEditUtil.handleLoreAppendByBook(player, leftItem, bookMeta)) return false
|
||||
if (output != AnvilLoreEditUtil.handleLoreAppendByBook(player, leftItem, bookMeta, xpCost)) return false
|
||||
|
||||
// Remove pages to book
|
||||
val bookCopy: ItemStack?
|
||||
|
|
@ -338,10 +340,10 @@ class AnvilResultListener : Listener {
|
|||
event, player, inventory,
|
||||
leftItem, 1,
|
||||
bookCopy, 0,
|
||||
output, 0
|
||||
) //TODO DO REPAIR COST
|
||||
output, xpCost.get()
|
||||
)
|
||||
} else {
|
||||
if (output != AnvilLoreEditUtil.handleLoreRemoveByBook(player, leftItem)) return false
|
||||
if (output != AnvilLoreEditUtil.handleLoreRemoveByBook(player, leftItem, xpCost)) return false
|
||||
|
||||
// fill book meta
|
||||
val meta = leftItem.itemMeta
|
||||
|
|
@ -367,8 +369,8 @@ class AnvilResultListener : Listener {
|
|||
event, player, inventory,
|
||||
leftItem, 1,
|
||||
rightCopy, 0,
|
||||
output, 0
|
||||
) //TODO DO REPAIR COST
|
||||
output, xpCost.get()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -385,8 +387,9 @@ class AnvilResultListener : Listener {
|
|||
|
||||
val editType = AnvilLoreEditUtil.paperLoreEditIsAppend(leftItem, rightItem) ?: return false
|
||||
|
||||
val xpCost = AtomicInteger()
|
||||
if (editType) {
|
||||
if (output != AnvilLoreEditUtil.handleLoreAppendByPaper(player, leftItem, rightItem)) return false
|
||||
if (output != AnvilLoreEditUtil.handleLoreAppendByPaper(player, leftItem, rightItem, xpCost)) return false
|
||||
|
||||
val paperCopy: ItemStack?
|
||||
if (LoreEditType.APPEND_PAPER.doConsume) {
|
||||
|
|
@ -404,18 +407,18 @@ class AnvilResultListener : Listener {
|
|||
event, player, inventory,
|
||||
paperCopy, 0,
|
||||
rightItem, 1,
|
||||
output, 0
|
||||
) //TODO DO REPAIR COST
|
||||
output, xpCost.get()
|
||||
)
|
||||
} else {
|
||||
extractAnvilResult(
|
||||
event, player, inventory,
|
||||
null, 0,
|
||||
paperCopy, 0,
|
||||
output, 0
|
||||
) //TODO DO REPAIR COST
|
||||
output, xpCost.get()
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if (output != AnvilLoreEditUtil.handleLoreRemoveByPaper(player, leftItem)) return false
|
||||
if (output != AnvilLoreEditUtil.handleLoreRemoveByPaper(player, leftItem, xpCost)) return false
|
||||
|
||||
val leftMeta = leftItem.itemMeta
|
||||
if (leftMeta == null || !leftMeta.hasLore()) return false
|
||||
|
|
@ -440,15 +443,15 @@ class AnvilResultListener : Listener {
|
|||
event, player, inventory,
|
||||
rightClone, 0,
|
||||
rightItem, 1,
|
||||
output, 0
|
||||
) //TODO DO REPAIR COST
|
||||
output, xpCost.get()
|
||||
)
|
||||
} else {
|
||||
extractAnvilResult(
|
||||
event, player, inventory,
|
||||
null, 0,
|
||||
rightClone, 0,
|
||||
output, 0
|
||||
) //TODO DO REPAIR COST
|
||||
output, xpCost.get()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import io.delilaheve.util.ItemUtil.setEnchantmentsUnsafe
|
|||
import io.delilaheve.util.ItemUtil.unitRepair
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.AbstractVillager
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
|
|
@ -20,10 +19,11 @@ import org.bukkit.event.Listener
|
|||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
import org.bukkit.inventory.AnvilInventory
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.BookMeta
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.util.*
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Listener for anvil events
|
||||
*/
|
||||
|
|
@ -230,11 +230,12 @@ class PrepareAnvilListener : Listener {
|
|||
val type = second.type
|
||||
var result: ItemStack? = null
|
||||
|
||||
val xpCost = AtomicInteger()
|
||||
if(Material.WRITABLE_BOOK == type) {
|
||||
result = AnvilLoreEditUtil.tryLoreEditByBook(player, first, second)
|
||||
result = AnvilLoreEditUtil.tryLoreEditByBook(player, first, second, xpCost)
|
||||
}
|
||||
else if(Material.PAPER == type) {
|
||||
result = AnvilLoreEditUtil.tryLoreEditByPaper(player, first, second)
|
||||
result = AnvilLoreEditUtil.tryLoreEditByPaper(player, first, second, xpCost)
|
||||
}
|
||||
|
||||
if(result == null || first == result) {
|
||||
|
|
@ -244,10 +245,7 @@ class PrepareAnvilListener : Listener {
|
|||
}
|
||||
|
||||
event.result = result
|
||||
|
||||
// TODO forgot about xp config & logic
|
||||
AnvilXpUtil.setAnvilInvXp(inventory, event.view, player, 1)
|
||||
|
||||
AnvilXpUtil.setAnvilInvXp(inventory, event.view, player, xpCost.get())
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import org.bukkit.inventory.meta.BookMeta
|
|||
import org.bukkit.permissions.Permissible
|
||||
import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil
|
||||
import xyz.alexcrea.cuanvil.util.config.LoreEditType
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
object AnvilLoreEditUtil {
|
||||
|
||||
|
|
@ -20,7 +21,12 @@ object AnvilLoreEditUtil {
|
|||
return LoreEditConfigUtil.paperLoreEditNeedPermission && player.hasPermission(LORE_BY_PAPER)
|
||||
}
|
||||
|
||||
fun handleLoreAppendByBook(player: Permissible, first: ItemStack, book: BookMeta): ItemStack? {
|
||||
fun handleLoreAppendByBook(
|
||||
player: Permissible,
|
||||
first: ItemStack,
|
||||
book: BookMeta,
|
||||
xpCost: AtomicInteger
|
||||
): ItemStack? {
|
||||
if (!hasLoreEditByBookPermission(player)) return null
|
||||
|
||||
val result = first.clone()
|
||||
|
|
@ -35,10 +41,13 @@ object AnvilLoreEditUtil {
|
|||
meta?.lore = lore
|
||||
result.itemMeta = meta
|
||||
|
||||
// Handle other xp
|
||||
xpCost.addAndGet(baseEditLoreXpCost(first, result, LoreEditType.APPEND_BOOK))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun handleLoreRemoveByBook(player: Permissible, first: ItemStack): ItemStack? {
|
||||
fun handleLoreRemoveByBook(player: Permissible, first: ItemStack, xpCost: AtomicInteger): ItemStack? {
|
||||
if (!hasLoreEditByBookPermission(player)) return null
|
||||
|
||||
// remove lore
|
||||
|
|
@ -47,6 +56,9 @@ object AnvilLoreEditUtil {
|
|||
leftMeta.lore = null
|
||||
result.itemMeta = leftMeta
|
||||
|
||||
// Handle other xp
|
||||
xpCost.addAndGet(baseEditLoreXpCost(first, result, LoreEditType.REMOVE_BOOK))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
@ -81,12 +93,12 @@ object AnvilLoreEditUtil {
|
|||
return null
|
||||
}
|
||||
|
||||
fun tryLoreEditByBook(player: HumanEntity, first: ItemStack, second: ItemStack): ItemStack? {
|
||||
fun tryLoreEditByBook(player: HumanEntity, first: ItemStack, second: ItemStack, xpCost: AtomicInteger): ItemStack? {
|
||||
val bookType = bookLoreEditIsAppend(first, second) ?: return null
|
||||
|
||||
val meta = second.itemMeta as BookMeta
|
||||
return if (bookType) handleLoreAppendByBook(player, first, meta)
|
||||
else handleLoreRemoveByBook(player, first)
|
||||
return if (bookType) handleLoreAppendByBook(player, first, meta, xpCost)
|
||||
else handleLoreRemoveByBook(player, first, xpCost)
|
||||
}
|
||||
|
||||
// Return true if append, false if remove, null if neither
|
||||
|
|
@ -108,7 +120,12 @@ object AnvilLoreEditUtil {
|
|||
return null
|
||||
}
|
||||
|
||||
fun handleLoreAppendByPaper(player: Permissible, first: ItemStack, second: ItemStack): ItemStack? {
|
||||
fun handleLoreAppendByPaper(
|
||||
player: Permissible,
|
||||
first: ItemStack,
|
||||
second: ItemStack,
|
||||
xpCost: AtomicInteger
|
||||
): ItemStack? {
|
||||
if (!hasLoreEditByPaperPermission(player)) return null
|
||||
|
||||
val result = first.clone()
|
||||
|
|
@ -121,7 +138,7 @@ object AnvilLoreEditUtil {
|
|||
|
||||
//TODO check color if color if enabled
|
||||
val line = second.itemMeta!!.displayName
|
||||
if(appendEnd)
|
||||
if (appendEnd)
|
||||
lore.add(line)
|
||||
else
|
||||
lore.add(0, line)
|
||||
|
|
@ -129,10 +146,13 @@ object AnvilLoreEditUtil {
|
|||
meta?.lore = lore
|
||||
result.itemMeta = meta
|
||||
|
||||
// Handle other xp
|
||||
xpCost.addAndGet(baseEditLoreXpCost(first, result, LoreEditType.APPEND_PAPER))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun handleLoreRemoveByPaper(player: Permissible, first: ItemStack): ItemStack? {
|
||||
fun handleLoreRemoveByPaper(player: Permissible, first: ItemStack, xpCost: AtomicInteger): ItemStack? {
|
||||
if (!hasLoreEditByPaperPermission(player)) return null
|
||||
|
||||
// remove lore line
|
||||
|
|
@ -142,20 +162,39 @@ object AnvilLoreEditUtil {
|
|||
val removeEnd = LoreEditConfigUtil.paperLoreOrderIsEnd
|
||||
val lore: ArrayList<String> = ArrayList(meta.lore!!)
|
||||
|
||||
if(removeEnd) lore.removeAt(lore.size - 1)
|
||||
if (removeEnd) lore.removeAt(lore.size - 1)
|
||||
else lore.removeAt(0)
|
||||
|
||||
meta.lore = if(lore.isEmpty()) null else lore
|
||||
meta.lore = if (lore.isEmpty()) null else lore
|
||||
result.itemMeta = meta
|
||||
|
||||
// Handle other xp
|
||||
xpCost.addAndGet(baseEditLoreXpCost(first, result, LoreEditType.REMOVE_PAPER))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun tryLoreEditByPaper(player: HumanEntity, first: ItemStack, second: ItemStack): ItemStack? {
|
||||
fun tryLoreEditByPaper(
|
||||
player: HumanEntity,
|
||||
first: ItemStack,
|
||||
second: ItemStack,
|
||||
xpCost: AtomicInteger
|
||||
): ItemStack? {
|
||||
val bookType = paperLoreEditIsAppend(first, second) ?: return null
|
||||
|
||||
return if (bookType) handleLoreAppendByPaper(player, first, second)
|
||||
else handleLoreRemoveByPaper(player, first)
|
||||
return if (bookType) handleLoreAppendByPaper(player, first, second, xpCost)
|
||||
else handleLoreRemoveByPaper(player, first, xpCost)
|
||||
}
|
||||
|
||||
private fun baseEditLoreXpCost(
|
||||
first: ItemStack,
|
||||
result: ItemStack,
|
||||
editType: LoreEditType
|
||||
): Int {
|
||||
var xpCost = editType.fixedCost
|
||||
|
||||
xpCost += AnvilXpUtil.calculatePenalty(first, null, result, editType.useType)
|
||||
return xpCost
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,29 +1,73 @@
|
|||
package xyz.alexcrea.cuanvil.util
|
||||
|
||||
import io.delilaheve.util.ConfigOptions
|
||||
import org.bukkit.Material
|
||||
import xyz.alexcrea.cuanvil.config.WorkPenaltyType.WorkPenaltyPart
|
||||
|
||||
enum class AnvilUseType(val typeName: String,
|
||||
enum class AnvilUseType(
|
||||
val typeName: String, val path: String,
|
||||
val defaultPenalty: WorkPenaltyPart,
|
||||
val displayName: String, val displayMat: Material
|
||||
) {
|
||||
) {
|
||||
|
||||
RENAME_ONLY("rename_only",
|
||||
RENAME_ONLY(
|
||||
"rename_only",
|
||||
WorkPenaltyPart(false, true),
|
||||
"Rename Only", Material.NAME_TAG
|
||||
),
|
||||
MERGE("merge",
|
||||
MERGE(
|
||||
"merge",
|
||||
WorkPenaltyPart(true, true),
|
||||
"Merge", Material.ANVIL
|
||||
),
|
||||
UNIT_REPAIR("unit_repair",
|
||||
UNIT_REPAIR(
|
||||
"unit_repair",
|
||||
WorkPenaltyPart(true, true),
|
||||
"Unit Repair", Material.DIAMOND
|
||||
),
|
||||
CUSTOM_CRAFT("custom_craft",
|
||||
CUSTOM_CRAFT(
|
||||
"custom_craft",
|
||||
WorkPenaltyPart(false, false),
|
||||
"Custom Craft", Material.CRAFTING_TABLE
|
||||
),
|
||||
LORE_EDIT_BOOK_APPEND(
|
||||
"lore_edit_book_append", "lore_edit.book_and_quil.append",
|
||||
WorkPenaltyPart(false, false),
|
||||
"Book Add", Material.WRITABLE_BOOK
|
||||
),
|
||||
LORE_EDIT_BOOK_REMOVE(
|
||||
"lore_edit_book_remove", "lore_edit.book_and_quil.remove",
|
||||
WorkPenaltyPart(false, false),
|
||||
"Book Remove", Material.WRITABLE_BOOK
|
||||
),
|
||||
LORE_EDIT_PAPER_APPEND(
|
||||
"lore_edit_paper_append", "lore_edit.paper.append",
|
||||
WorkPenaltyPart(false, false),
|
||||
"Paper Add", Material.WRITABLE_BOOK
|
||||
),
|
||||
LORE_EDIT_PAPER_REMOVE(
|
||||
"lore_edit_paper_remove", "lore_edit.paper.remove",
|
||||
WorkPenaltyPart(false, false),
|
||||
"Paper Remove", Material.WRITABLE_BOOK
|
||||
),
|
||||
;
|
||||
|
||||
companion object {
|
||||
private fun defaultPath(typeName: String): String {
|
||||
return "${ConfigOptions.WORK_PENALTY_ROOT}.$typeName"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constructor(
|
||||
typeName: String,
|
||||
defaultPenalty: WorkPenaltyPart,
|
||||
displayName: String, displayMat: Material
|
||||
) :
|
||||
this(
|
||||
typeName, defaultPath(typeName),
|
||||
defaultPenalty,
|
||||
displayName, displayMat
|
||||
)
|
||||
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ import org.bukkit.entity.HumanEntity
|
|||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.AnvilInventory
|
||||
import org.bukkit.inventory.InventoryView
|
||||
import org.bukkit.inventory.InventoryView.Property.REPAIR_COST
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.Repairable
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
|
|
@ -129,13 +128,16 @@ object AnvilXpUtil {
|
|||
return resultSum
|
||||
}
|
||||
|
||||
private fun exclusivePenaltyKey(useType: AnvilUseType): NamespacedKey {
|
||||
return NamespacedKey(CustomAnvil.instance, "${EXCLUSIVE_PENALTY_PREFIX}_${useType.typeName}")
|
||||
}
|
||||
|
||||
private fun setExclusivePenalty(
|
||||
result: ItemStack,
|
||||
resultPenalty: Int,
|
||||
useType: AnvilUseType
|
||||
) {
|
||||
val tagPath = EXCLUSIVE_PENALTY_PREFIX + "_" + useType.typeName
|
||||
val key = NamespacedKey(CustomAnvil.instance, tagPath)
|
||||
val key = exclusivePenaltyKey(useType)
|
||||
|
||||
val meta = result.itemMeta!!
|
||||
meta.persistentDataContainer.set(key, PersistentDataType.INTEGER, resultPenalty)
|
||||
|
|
@ -143,14 +145,13 @@ object AnvilXpUtil {
|
|||
}
|
||||
|
||||
private fun findExclusivePenalty(
|
||||
left: ItemStack?,
|
||||
item: ItemStack?,
|
||||
useType: AnvilUseType
|
||||
): Int {
|
||||
if (left == null) return 0
|
||||
val tagPath = EXCLUSIVE_PENALTY_PREFIX + "_" + useType.typeName
|
||||
val key = NamespacedKey(CustomAnvil.instance, tagPath)
|
||||
if (item == null || !item.hasItemMeta()) return 0
|
||||
val key = exclusivePenaltyKey(useType)
|
||||
|
||||
val meta = left.itemMeta!!
|
||||
val meta = item.itemMeta!!
|
||||
return meta.persistentDataContainer.get(key, PersistentDataType.INTEGER) ?: return 0
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ object LoreEditConfigUtil {
|
|||
const val DEFAULT_IS_ENABLED = false
|
||||
const val DEFAULT_FIXED_COST = 1
|
||||
const val DEFAULT_PER_LINE_COST = 0
|
||||
const val DEFAULT_USE_COST_PENALTY = false
|
||||
const val DEFAULT_INCREASE_COST_PENALTY = false
|
||||
const val DEFAULT_DO_CONSUME = false
|
||||
|
||||
// Permission configs defaults
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
package xyz.alexcrea.cuanvil.util.config
|
||||
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder.DEFAULT_CONFIG as CONFIG
|
||||
|
||||
enum class LoreEditType(
|
||||
val rootPath: String,
|
||||
val useType: AnvilUseType,
|
||||
val isAppend: Boolean,
|
||||
) {
|
||||
APPEND_BOOK("lore_edit.book_and_quil.append", true),
|
||||
REMOVE_BOOK("lore_edit.book_and_quil.remove", false),
|
||||
APPEND_PAPER("lore_edit.paper.append", true),
|
||||
REMOVE_PAPER("lore_edit.paper.remove", false),
|
||||
APPEND_BOOK("lore_edit.book_and_quil.append", AnvilUseType.LORE_EDIT_BOOK_APPEND, true),
|
||||
REMOVE_BOOK("lore_edit.book_and_quil.remove", AnvilUseType.LORE_EDIT_BOOK_REMOVE,false),
|
||||
APPEND_PAPER("lore_edit.paper.append", AnvilUseType.LORE_EDIT_PAPER_APPEND,true),
|
||||
REMOVE_PAPER("lore_edit.paper.remove", AnvilUseType.LORE_EDIT_PAPER_REMOVE,false),
|
||||
;
|
||||
|
||||
/**
|
||||
|
|
@ -46,33 +48,6 @@ enum class LoreEditType(
|
|||
?: LoreEditConfigUtil.DEFAULT_PER_LINE_COST
|
||||
}
|
||||
|
||||
/**
|
||||
* If the edit should use the item's cost penalty
|
||||
*/
|
||||
val useCostPenalty: Boolean
|
||||
get() {
|
||||
return CONFIG
|
||||
.config
|
||||
.getBoolean(
|
||||
"${rootPath}.${LoreEditConfigUtil.USE_COST_PENALTY}",
|
||||
LoreEditConfigUtil.DEFAULT_USE_COST_PENALTY
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* If the edit should increase the items cost penalty
|
||||
*/
|
||||
val increaseCostPenalty: Boolean
|
||||
get() {
|
||||
|
||||
return CONFIG
|
||||
.config
|
||||
.getBoolean(
|
||||
"${rootPath}.${LoreEditConfigUtil.INCREASE_COST_PENALTY}",
|
||||
LoreEditConfigUtil.DEFAULT_INCREASE_COST_PENALTY
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* If the edit should consume the provided material
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -282,10 +282,10 @@ lore_edit:
|
|||
fixed_cost: 1
|
||||
# Cost used for every lore line added
|
||||
per_line_cost: 0
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
# If adding the lore consume the book & quil
|
||||
do_consume: false
|
||||
|
||||
|
|
@ -296,10 +296,10 @@ lore_edit:
|
|||
fixed_cost: 1
|
||||
# Cost used for every lore line removed
|
||||
per_line_cost: 0
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
|
||||
# Allow using color code and hexadecimal color when editing lore via book & quil
|
||||
#
|
||||
|
|
@ -321,10 +321,10 @@ lore_edit:
|
|||
enabled: false
|
||||
# Cost used every time
|
||||
fixed_cost: 1
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
# If adding the lore line consume the paper
|
||||
do_consume: false
|
||||
|
||||
|
|
@ -333,10 +333,10 @@ lore_edit:
|
|||
enabled: false
|
||||
# Cost used every time
|
||||
fixed_cost: 1
|
||||
# Use left item cost penalty if any
|
||||
use_cost_penalty: false
|
||||
# Increase left item cost penalty
|
||||
increase_cost_penalty: false
|
||||
# Use left item vanilla cost penalty if any
|
||||
shared_increase: false
|
||||
# Increase shared left item cost penalty
|
||||
shared_additive: false
|
||||
|
||||
# Allow using color code and hexadecimal color when editing lore via book & quil
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue