Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArmagan committed Jan 28, 2025
1 parent 7691758 commit 5d6bd06
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>rest.armagan</groupId>
<artifactId>PAPIConditionExpansion</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
38 changes: 35 additions & 3 deletions src/main/kotlin/rest/armagan/papiexpansions/ConditionExpansion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConditionExpansion : PlaceholderExpansion() {
}

override fun getVersion(): String {
return "0.0.1"
return "0.0.2"
}

override fun onPlaceholderRequest(player: Player?, identifier: String): String {
Expand Down Expand Up @@ -165,8 +165,10 @@ class ConditionExpansion : PlaceholderExpansion() {
"stripColors" -> value = ChatColor.stripColor(value).toString()
"substring" -> {
var a = getValue(values, "${key}!substringStart").toInt()
if (a > value.length) a = value.length - 1
if (a < 0) a = value.length - a;
var b = getValue(values, "${key}!substringEnd").toInt()
if (b > value.length) b = value.length - 1
if (b < 0) b = value.length - b;
value = value.substring(a, b)
}
Expand All @@ -190,6 +192,21 @@ class ConditionExpansion : PlaceholderExpansion() {
val a = getValue(values, "${key}!repeatTimes")
value = value.repeat(a.toInt())
}
"marquee" -> {
val marqueeLength = getValue(values, "${key}!marqueeVisibleLength").toInt();
val spaceLength = getValue(values, "${key}!marqueeSpaceLength").toInt();
var direction = getValue(values, "${key}!marqueeDirection");
if (direction.isEmpty()) direction = "left";
val position = getValue(values, "${key}!marqueePosition").toInt();

value = Utils.marqueeAnimation(
value,
marqueeLength,
spaceLength,
direction,
position
);
}
}
}

Expand All @@ -201,9 +218,24 @@ class ConditionExpansion : PlaceholderExpansion() {
val map = mutableMapOf<String, String>()
for (part in parts) {
val key = part.substring(0, part.indexOf(":"))
val value = part.substring(part.indexOf(":") + 1)
map[key] = value
var value = part.substring(part.indexOf(":") + 1)
value = mapReplace(
mapOf(
"<colon>" to ":",
"<underscore>" to "_",
"<exclamation>" to "!",
"<comma>" to ","
),
value
);
map[key] = value;
}
return map
}

private fun mapReplace(map: Map<String, String>, text: String): String {
var result = text
map.forEach { (k, v) -> result = result.replace(k, v) }
return result
}
}
31 changes: 31 additions & 0 deletions src/main/kotlin/rest/armagan/papiexpansions/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package rest.armagan.papiexpansions

class Utils {
companion object {
fun marqueeAnimation(
inputString: String,
visibleLength: Int,
spaceLength: Int,
direction: String,
position: Int
): String {
val space = " ".repeat(spaceLength)
val marqueeString = inputString + space
val totalLength = marqueeString.length

val normalizedPosition = position % totalLength

val normalizedVisibleLength = if (visibleLength > totalLength) totalLength else visibleLength

val adjustedPosition = when (direction.lowercase()) {
"left" -> normalizedPosition
"right" -> (totalLength - normalizedPosition) % totalLength
else -> throw IllegalArgumentException("Direction must be 'left' or 'right'")
}

val scrolledString = marqueeString.substring(adjustedPosition) + marqueeString.substring(0, adjustedPosition)

return scrolledString.take(normalizedVisibleLength).padEnd(normalizedVisibleLength, ' ')
}
}
}
2 changes: 1 addition & 1 deletion target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
artifactId=PAPIConditionExpansion
groupId=rest.armagan
version=0.0.1
version=0.0.2

0 comments on commit 5d6bd06

Please sign in to comment.