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