-
Notifications
You must be signed in to change notification settings - Fork 1
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
9 changed files
with
347 additions
and
18 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
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
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,48 @@ | ||
import io.papermc.paperweight.userdev.ReobfArtifactConfiguration | ||
|
||
plugins { | ||
id("com.mineinabyss.conventions.kotlin.jvm") | ||
id("com.mineinabyss.conventions.autoversion") | ||
id("io.papermc.paperweight.userdev") version "1.7.4" | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
maven("https://repo.mineinabyss.com/releases") | ||
maven("https://repo.mineinabyss.com/snapshots") | ||
maven("https://repo.papermc.io/repository/maven-public/") | ||
google() | ||
} | ||
|
||
paperweight.reobfArtifactConfiguration.set(ReobfArtifactConfiguration.MOJANG_PRODUCTION) | ||
|
||
dependencies { | ||
// MineInAbyss platform | ||
compileOnly(idofrontLibs.kotlinx.serialization.json) | ||
compileOnly(idofrontLibs.kotlinx.serialization.kaml) | ||
compileOnly(idofrontLibs.kotlinx.coroutines) | ||
compileOnly(idofrontLibs.minecraft.mccoroutine) | ||
|
||
// Shaded | ||
implementation(idofrontLibs.bundles.idofront.core) | ||
implementation(project(":core")) | ||
paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT") //NMS | ||
} | ||
|
||
tasks { | ||
|
||
build { | ||
dependsOn(reobfJar) | ||
} | ||
|
||
compileJava { | ||
options.encoding = Charsets.UTF_8.name() | ||
options.release.set(21) | ||
} | ||
javadoc { | ||
options.encoding = Charsets.UTF_8.name() | ||
} | ||
processResources { | ||
filteringCharset = Charsets.UTF_8.name() | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
v1_21_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_21_R2/EmojyListener.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,101 @@ | ||
package com.mineinabyss.emojy.nms.v1_21_R2 | ||
|
||
import com.github.shynixn.mccoroutine.bukkit.launch | ||
import com.github.shynixn.mccoroutine.bukkit.ticks | ||
import com.jeff_media.morepersistentdatatypes.DataType | ||
import com.mineinabyss.emojy.* | ||
import com.mineinabyss.idofront.items.editItemMeta | ||
import com.mineinabyss.idofront.textcomponents.miniMsg | ||
import com.mineinabyss.idofront.textcomponents.serialize | ||
import io.papermc.paper.event.player.AsyncChatDecorateEvent | ||
import io.papermc.paper.event.player.PlayerOpenSignEvent | ||
import kotlinx.coroutines.delay | ||
import net.minecraft.core.BlockPos | ||
import net.minecraft.world.level.block.entity.BlockEntityType | ||
import org.bukkit.block.Sign | ||
import org.bukkit.block.sign.Side | ||
import org.bukkit.craftbukkit.entity.CraftPlayer | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.EventPriority | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.block.SignChangeEvent | ||
import org.bukkit.event.inventory.PrepareAnvilEvent | ||
import org.bukkit.event.player.PlayerEditBookEvent | ||
|
||
@Suppress("UnstableApiUsage") | ||
class EmojyListener : Listener { | ||
|
||
// Replace with result not original message to avoid borking other chat formatting | ||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) | ||
fun AsyncChatDecorateEvent.onPlayerChat() { | ||
result(result().escapeEmoteIDs(player())) | ||
} | ||
|
||
@EventHandler | ||
fun SignChangeEvent.onSign() { | ||
val state = (block.state as Sign) | ||
val type = DataType.asList(DataType.STRING) | ||
val sideLines = lines().map { it.serialize() }.toList() | ||
val frontLines = if (side == Side.FRONT) sideLines else state.persistentDataContainer.getOrDefault( | ||
ORIGINAL_SIGN_FRONT_LINES, | ||
type, | ||
mutableListOf("", "", "", "") | ||
) | ||
val backLines = if (side == Side.BACK) sideLines else state.persistentDataContainer.getOrDefault( | ||
ORIGINAL_SIGN_BACK_LINES, | ||
type, | ||
mutableListOf("", "", "", "") | ||
) | ||
|
||
state.persistentDataContainer.set(ORIGINAL_SIGN_FRONT_LINES, type, frontLines) | ||
state.persistentDataContainer.set(ORIGINAL_SIGN_BACK_LINES, type, backLines) | ||
state.update(true) | ||
|
||
lines().forEachIndexed { index, s -> | ||
line(index, s?.escapeEmoteIDs(player)?.transformEmotes()) | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
fun PlayerOpenSignEvent.onSignEdit() { | ||
if (cause == PlayerOpenSignEvent.Cause.PLACE) return | ||
|
||
sign.persistentDataContainer.get( | ||
when (sign.getInteractableSideFor(player)) { | ||
Side.FRONT -> ORIGINAL_SIGN_FRONT_LINES | ||
Side.BACK -> ORIGINAL_SIGN_BACK_LINES | ||
}, DataType.asList(DataType.STRING) | ||
)?.forEachIndexed { index, s -> | ||
sign.getSide(side).line(index, s.miniMsg()) | ||
} | ||
sign.update(true) | ||
isCancelled = true | ||
emojy.plugin.launch { | ||
delay(2.ticks) | ||
(player as CraftPlayer).handle.level() | ||
.getBlockEntity(BlockPos(sign.x, sign.y, sign.z), BlockEntityType.SIGN).ifPresent { | ||
it.setAllowedPlayerEditor(player.uniqueId) | ||
(player as CraftPlayer).handle.openTextEdit(it, side == Side.FRONT) | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
fun PrepareAnvilEvent.onAnvil() { | ||
result = result?.editItemMeta { | ||
if (view.renameText == null || result?.itemMeta?.hasDisplayName() != true) { | ||
persistentDataContainer.remove(ORIGINAL_ITEM_RENAME_TEXT) | ||
} else persistentDataContainer.set(ORIGINAL_ITEM_RENAME_TEXT, DataType.STRING, view.renameText!!) | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
fun PlayerEditBookEvent.onBookEdit() { | ||
if (isSigning) newBookMeta = newBookMeta.apply { | ||
pages(pages().map { | ||
it.escapeEmoteIDs(player).transformEmotes().unescapeEmoteIds() | ||
}) | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.