Skip to content

Commit

Permalink
menreiki fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kidofcubes committed Mar 8, 2024
1 parent fa87ae4 commit c0103a0
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ adapters/TeraCoreAdapter/
# Flutter web resource
/plugin/src/main/resources/web/
plugin/qodana.yaml

adapters/CitizensAdapter/libs/
1 change: 1 addition & 0 deletions adapters/CitizensAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dependencies {
compileOnly("net.citizensnpcs:citizens-main:2.0.33-SNAPSHOT") {
exclude(group = "*", module = "*")
}
compileOnly(files("libs/megegg2.jar"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import org.bukkit.Bukkit
import org.bukkit.command.CommandMap
import org.bukkit.command.CommandSender
import org.bukkit.command.defaults.BukkitCommand
import org.bukkit.entity.Player
import java.lang.reflect.Field
import java.util.*
import java.util.regex.Pattern

@Deprecated("Use the EntityAdapter instead")
//@Deprecated("Use the EntityAdapter instead")
@Adapter("Citizens", "For the Citizens plugin", App.VERSION)
/**
* The Citizens adapter allows you to create custom interactions with NPCs.
Expand All @@ -41,7 +42,7 @@ object CitizensAdapter : TypewriteAdapter() {
commandMapField.get(server) as CommandMap
}

private val toReplace = Pattern.compile("%[\\d]+%");
private val toReplace = Pattern.compile("%[\\d]+%")
override fun initialize() {
if (!plugin.server.pluginManager.isPluginEnabled("Citizens")) {
logger.warning("Citizens plugin not found, try installing it or disabling the Citizens adapter")
Expand All @@ -50,22 +51,40 @@ object CitizensAdapter : TypewriteAdapter() {

CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(TypewriterTrait::class.java))
tmpRegistry = CitizensAPI.createNamedNPCRegistry("typewriter",MemoryNPCDataStore(23500))
commandMap.register("typewriter_custom", object : BukkitCommand("instancedwrapper") {
commandMap.register("menreiki1", object : BukkitCommand("playerinstancedwrapper") {
override fun execute(sender: CommandSender, commandLabel: String, args: Array<out String>): Boolean {
if(args.size<3){
sender.sendMessage("Not enough arguments");
return false;
sender.sendMessage("Not enough arguments")
return false
}

val wrappedCommand = Arrays.copyOfRange(args,1,args.size).joinToString(" ");
val sb = StringBuilder();
val matcher = toReplace.matcher(wrappedCommand);
val wrappedCommand = Arrays.copyOfRange(args,1,args.size).joinToString(" ")
val sb = StringBuilder()
val matcher = toReplace.matcher(wrappedCommand)
while(matcher.find()){
matcher.appendReplacement(sb, temporaryNpcMap.get(Pair.of(Bukkit.getPlayerUniqueId(args[0]), Integer.parseInt(matcher.group().replace("%","")))).toString());
matcher.appendReplacement(sb, temporaryNpcMap.get(Pair.of(Bukkit.getPlayerUniqueId(args[0]), Integer.parseInt(matcher.group().replace("%","")))).toString())
}
matcher.appendTail(sb)
return Bukkit.dispatchCommand(sender, sb.toString())
}
})
commandMap.register("menreiki2", object : BukkitCommand("instancedwrapper") {
override fun execute(sender: CommandSender, commandLabel: String, args: Array<out String>): Boolean {
if(!(sender is Player)) return false
if(args.size<2){
sender.sendMessage("Not enough arguments")
return false
}
matcher.appendTail(sb);
return Bukkit.dispatchCommand(sender, sb.toString());

val wrappedCommand = args.joinToString(" ")
val sb = StringBuilder()
val matcher = toReplace.matcher(wrappedCommand)

while(matcher.find()){
matcher.appendReplacement(sb, temporaryNpcMap.get(Pair.of(sender.uniqueId , Integer.parseInt(matcher.group().replace("%","")))).toString())
}
matcher.appendTail(sb)
return Bukkit.dispatchCommand(sender, sb.toString())
}
})
syncCommands()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.bukkit.Location
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.PlayerInventory

@Deprecated("Use the EntityAdapter instead")
//@Deprecated("Use the EntityAdapter instead")
@Entry("npc_movement_artifact", "Movement data for an npc", Colors.PINK, "fa6-solid:person-walking")
@Tags("npc_movement_artifact")
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package me.gabber235.typewriter.citizens.entries.cinematic

import com.ticxo.modelengine.api.utils.data.io.SavedData
import com.ticxo.modelengine.core.citizens.ModelTrait
import it.unimi.dsi.fastutil.Pair
import me.gabber235.typewriter.capture.capturers.ArmSwing
import me.gabber235.typewriter.citizens.CitizensAdapter.temporaryNpcMap
import me.gabber235.typewriter.citizens.CitizensAdapter.temporaryRegistry
import me.gabber235.typewriter.utils.ThreadType
import net.citizensnpcs.api.CitizensAPI
Expand All @@ -9,6 +13,8 @@ import net.citizensnpcs.api.trait.trait.Equipment
import net.citizensnpcs.api.trait.trait.Equipment.EquipmentSlot.*
import net.citizensnpcs.api.trait.trait.MobType
import net.citizensnpcs.api.trait.trait.PlayerFilter
import net.citizensnpcs.api.util.DataKey
import net.citizensnpcs.api.util.MemoryDataKey
import net.citizensnpcs.trait.HologramTrait
import net.citizensnpcs.trait.SkinTrait
import net.citizensnpcs.trait.SneakTrait
Expand Down Expand Up @@ -93,6 +99,18 @@ data class ReferenceNpcData(val id: Int) : CitizensNpcData {

val type = original.getOrAddTrait(MobType::class.java).type
val npc = temporaryRegistry.createNPC(type, original.name)
temporaryNpcMap.put(Pair.of(player.uniqueId,id),npc.id);
npc.getOrAddTrait(ModelTrait::class.java)
if(original.hasTrait(ModelTrait::class.java)){
val originalModelTrait : ModelTrait = original.getTraitNullable(ModelTrait::class.java)
val modeledEntity = originalModelTrait.modeledEntity;
npc.getOrAddTrait(ModelTrait::class.java)
modeledEntity?.save()?.ifPresent { data: SavedData ->
val key: DataKey = MemoryDataKey();
key.setString("model_data",data.toString());
npc.getOrAddTrait(ModelTrait::class.java).load(key);
}
}

if (original.hasTrait(SkinTrait::class.java)) {
val originalSkin = original.getOrAddTrait(SkinTrait::class.java)
Expand Down Expand Up @@ -140,11 +158,15 @@ data class ReferenceNpcData(val id: Int) : CitizensNpcData {
}

override fun teardown(player: Player, npc: NPC) {
if(npc.hasTrait(ModelTrait::class.java)){
npc.getTraitNullable(ModelTrait::class.java).onDespawn()
}
super.teardown(player, npc)

val original =
CitizensAPI.getNPCRegistry().getById(id) ?: throw IllegalArgumentException("NPC with id $id not found.")
val filter = original.getOrAddTrait(PlayerFilter::class.java)
temporaryNpcMap.inverse().remove(npc.id);
if (filter.isAllowlist) {
filter.addPlayer(player.uniqueId)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import me.gabber235.typewriter.entry.emptyRef
import me.gabber235.typewriter.entry.entries.CinematicAction
import org.bukkit.entity.Player

@Deprecated("Use the EntityAdapter instead")
//@Deprecated("Use the EntityAdapter instead")
@Entry(
"reference_npc_cinematic",
"A reference to an existing npc specifically for cinematic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import me.gabber235.typewriter.entry.Criteria
import me.gabber235.typewriter.entry.entries.CinematicAction
import org.bukkit.entity.Player

@Deprecated("Use the EntityAdapter instead")
//@Deprecated("Use the EntityAdapter instead")
@Entry("self_npc_cinematic", "The player itself as an cinematic npc", Colors.PINK, "heroicons:user-16-solid")
/**
* The `Self NPC Cinematic` entry that plays a recorded animation back on the player with an NPC with the player's skin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.citizensnpcs.api.CitizensAPI
import kotlin.jvm.optionals.getOrDefault
import net.kyori.adventure.sound.Sound as AdventureSound

@Deprecated("Use the EntityAdapter instead")
//@Deprecated("Use the EntityAdapter instead")
@Tags("reference_npc")
@Entry("reference_npc", "When the npc is not managed by TypeWriter", Colors.ORANGE, "fa-solid:user-tie")
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.citizensnpcs.api.event.NPCLeftClickEvent
import net.citizensnpcs.api.event.NPCRightClickEvent
import org.bukkit.entity.Player

@Deprecated("Use the EntityAdapter instead")
//@Deprecated("Use the EntityAdapter instead")
@Entry("on_npc_interact", "When a player clicks on an NPC", Colors.YELLOW, "fa6-solid:people-robbery")
/**
* The `NPC Interact Event` is fired when a player interacts with an NPC.
Expand Down

0 comments on commit c0103a0

Please sign in to comment.