-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
283 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,4 @@ object ArgParserColor : LookupArgParser { | |
|
||
return "color:#${Integer.toHexString(meta.color.asRGB())}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 10 additions & 24 deletions
34
eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/items/ArgParserName.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,30 @@ | ||
package com.willfp.eco.internal.items | ||
|
||
import com.willfp.eco.core.items.args.LookupArgParser | ||
import com.willfp.eco.internal.items.templates.ValueArgParser | ||
import com.willfp.eco.util.StringUtils | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.inventory.meta.ItemMeta | ||
import java.util.function.Predicate | ||
|
||
object ArgParserName : LookupArgParser { | ||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? { | ||
var name: String? = null | ||
|
||
for (arg in args) { | ||
if (!arg.lowercase().startsWith("name:")) { | ||
continue | ||
} | ||
name = arg.substring(5, arg.length) | ||
} | ||
|
||
name ?: return null | ||
object ArgParserName : ValueArgParser<String>("name") { | ||
override fun parse(arg: String): String { | ||
return arg | ||
} | ||
|
||
val formatted = StringUtils.format(name) | ||
override fun apply(meta: ItemMeta, value: String) { | ||
val formatted = StringUtils.format(value) | ||
|
||
// I don't know why it says it's redundant, the compiler yells at me | ||
@Suppress("UsePropertyAccessSyntax", "RedundantSuppression", "DEPRECATION") | ||
meta.setDisplayName(formatted) | ||
|
||
return Predicate { | ||
val testMeta = it.itemMeta ?: return@Predicate false | ||
|
||
@Suppress("DEPRECATION") | ||
testMeta.displayName == formatted | ||
} | ||
} | ||
|
||
override fun serializeBack(meta: ItemMeta): String? { | ||
override fun test(meta: ItemMeta): String? { | ||
if (!meta.hasDisplayName()) { | ||
return null | ||
} | ||
|
||
@Suppress("DEPRECATION") | ||
return "name:\"${meta.displayName}\"" | ||
return meta.displayName | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,4 @@ object ArgParserTexture : LookupArgParser { | |
|
||
return "texture:${SkullUtils.getSkullTexture(meta)}" | ||
} | ||
} | ||
} |
36 changes: 6 additions & 30 deletions
36
eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/items/ArgParserUnbreakable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,14 @@ | ||
package com.willfp.eco.internal.items | ||
|
||
import com.willfp.eco.core.items.args.LookupArgParser | ||
import org.bukkit.inventory.ItemStack | ||
import com.willfp.eco.internal.items.templates.FlagArgParser | ||
import org.bukkit.inventory.meta.ItemMeta | ||
import java.util.function.Predicate | ||
|
||
object ArgParserUnbreakable : LookupArgParser { | ||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? { | ||
var unbreakable = false | ||
|
||
for (arg in args) { | ||
if (arg.equals("unbreakable", true)) { | ||
unbreakable = true | ||
} | ||
} | ||
|
||
if (!unbreakable) { | ||
return null | ||
} | ||
|
||
object ArgParserUnbreakable : FlagArgParser("unbreakable") { | ||
override fun apply(meta: ItemMeta) { | ||
meta.isUnbreakable = true | ||
|
||
return Predicate { | ||
val testMeta = it.itemMeta ?: return@Predicate false | ||
|
||
testMeta.isUnbreakable | ||
} | ||
} | ||
|
||
override fun serializeBack(meta: ItemMeta): String? { | ||
if (!meta.isUnbreakable) { | ||
return null | ||
} | ||
|
||
return "unbreakable" | ||
override fun test(meta: ItemMeta): Boolean { | ||
return meta.isUnbreakable | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...re-backend/src/main/kotlin/com/willfp/eco/internal/items/modern/ArgParserFireResistant.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.willfp.eco.internal.items.modern | ||
|
||
import com.willfp.eco.internal.items.templates.FlagArgParser | ||
import org.bukkit.inventory.meta.ItemMeta | ||
|
||
object ArgParserFireResistant : FlagArgParser("fire_resistant") { | ||
override fun apply(meta: ItemMeta) { | ||
meta.isFireResistant = true | ||
} | ||
|
||
override fun test(meta: ItemMeta): Boolean { | ||
return meta.isFireResistant | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/items/modern/ArgParserGlint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.willfp.eco.internal.items.modern | ||
|
||
import com.willfp.eco.internal.items.templates.FlagArgParser | ||
import org.bukkit.inventory.meta.ItemMeta | ||
|
||
object ArgParserGlint : FlagArgParser("glint") { | ||
override fun apply(meta: ItemMeta) { | ||
meta.setEnchantmentGlintOverride(true) | ||
} | ||
|
||
override fun test(meta: ItemMeta): Boolean { | ||
return meta.hasEnchantmentGlintOverride() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...re/core-backend/src/main/kotlin/com/willfp/eco/internal/items/modern/ArgParserItemName.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.willfp.eco.internal.items.modern | ||
|
||
import com.willfp.eco.internal.items.templates.ValueArgParser | ||
import com.willfp.eco.util.StringUtils | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.minimessage.MiniMessage | ||
import org.bukkit.inventory.meta.ItemMeta | ||
|
||
object ArgParserItemName : ValueArgParser<Component>("item_name") { | ||
override fun parse(arg: String): Component { | ||
return StringUtils.formatToComponent(arg) | ||
} | ||
|
||
override fun apply(meta: ItemMeta, value: Component) { | ||
meta.itemName(value) | ||
} | ||
|
||
override fun test(meta: ItemMeta): String? { | ||
if (!meta.hasItemName()) { | ||
return null | ||
} | ||
|
||
val name = MiniMessage.miniMessage().serialize(meta.itemName()) | ||
|
||
return name | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...e/core-backend/src/main/kotlin/com/willfp/eco/internal/items/modern/ArgParserMaxDamage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.willfp.eco.internal.items.modern | ||
|
||
import com.willfp.eco.internal.items.templates.ValueArgParser | ||
import com.willfp.eco.util.StringUtils | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.minimessage.MiniMessage | ||
import org.bukkit.inventory.meta.Damageable | ||
import org.bukkit.inventory.meta.ItemMeta | ||
import org.checkerframework.checker.units.qual.m | ||
|
||
object ArgParserMaxDamage : ValueArgParser<Int>("max_damage") { | ||
override fun parse(arg: String): Int? { | ||
return arg.toIntOrNull() | ||
} | ||
|
||
override fun apply(meta: ItemMeta, value: Int) { | ||
if (meta !is Damageable) { | ||
return | ||
} | ||
|
||
meta.setMaxDamage(value) | ||
} | ||
|
||
override fun test(meta: ItemMeta): String? { | ||
if (meta !is Damageable) { | ||
return null | ||
} | ||
|
||
if (!meta.hasMaxDamage()) { | ||
return null | ||
} | ||
|
||
return meta.maxDamage.toString() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ore-backend/src/main/kotlin/com/willfp/eco/internal/items/modern/ArgParserMaxStackSize.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.willfp.eco.internal.items.modern | ||
|
||
import com.willfp.eco.internal.items.templates.ValueArgParser | ||
import com.willfp.eco.util.StringUtils | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.minimessage.MiniMessage | ||
import org.bukkit.inventory.meta.Damageable | ||
import org.bukkit.inventory.meta.ItemMeta | ||
import org.checkerframework.checker.units.qual.m | ||
|
||
object ArgParserMaxStackSize : ValueArgParser<Int>("max_stack_size") { | ||
override fun parse(arg: String): Int? { | ||
return arg.toIntOrNull() | ||
} | ||
|
||
override fun apply(meta: ItemMeta, value: Int) { | ||
meta.setMaxStackSize(value) | ||
} | ||
|
||
override fun test(meta: ItemMeta): String? { | ||
if (!meta.hasMaxStackSize()) { | ||
return null | ||
} | ||
|
||
return meta.maxStackSize.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ore/core-backend/src/main/kotlin/com/willfp/eco/internal/items/templates/FlagArgParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.willfp.eco.internal.items.templates | ||
|
||
import com.willfp.eco.core.items.args.LookupArgParser | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.inventory.meta.ItemMeta | ||
import java.util.function.Predicate | ||
|
||
abstract class FlagArgParser( | ||
protected val flag: String | ||
) : LookupArgParser { | ||
abstract fun apply(meta: ItemMeta) | ||
|
||
abstract fun test(meta: ItemMeta): Boolean | ||
|
||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? { | ||
var has = false | ||
|
||
for (arg in args) { | ||
if (arg.equals(flag, true)) { | ||
has = true | ||
} | ||
} | ||
|
||
if (!has) { | ||
return null | ||
} | ||
|
||
apply(meta) | ||
|
||
return Predicate { | ||
val testMeta = it.itemMeta ?: return@Predicate false | ||
|
||
test(testMeta) | ||
} | ||
} | ||
|
||
override fun serializeBack(meta: ItemMeta): String? { | ||
if (!test(meta)) { | ||
return null | ||
} | ||
|
||
return flag | ||
} | ||
} |
Oops, something went wrong.