diff --git a/build.gradle.kts b/build.gradle.kts index 66534f9..bd5abe0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,18 +1,20 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration import org.apache.tools.ant.filters.ReplaceTokens plugins { kotlin("jvm") version "1.9.22" kotlin("plugin.serialization") version "1.9.22" - id("com.github.johnrengelman.shadow") version "7.0.0" + id("io.github.goooler.shadow") version "8.1.8" + id("io.papermc.paperweight.userdev") version "1.7.1" java `maven-publish` } group = "net.azisaba" -version = "1.15.2+6.16.3" +version = "1.20.2+6.16.3" java { - toolchain.languageVersion.set(JavaLanguageVersion.of(8)) + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) withJavadocJar() withSourcesJar() @@ -68,20 +70,22 @@ dependencies { compileOnly("net.azisaba:RyuZUPluginChat:4.2.0") compileOnly("net.azisaba.rarity:api:1.0.1-SNAPSHOT") compileOnly("net.azisaba:ItemStash:1.0.0-SNAPSHOT") - //noinspection VulnerableLibrariesLocal - compileOnly("com.destroystokyo.paper:paper-api:1.15.2-R0.1-SNAPSHOT") - compileOnly("org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT") compileOnly("io.lumine:Mythic-Dist:4.13.0") compileOnly("com.github.MilkBowl:VaultAPI:1.7") compileOnly("com.github.MyPetORG.MyPet:mypet-api:5c8ceeac6a") compileOnly("de.keyle:knbt:0.0.5") compileOnly("com.github.Staartvin:Autorank-2:4.5.1") + //compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT") compileOnly("com.github.Staartvin:Statz:v1.5.5") { exclude("nl.lolmewn.stats", "Stats") exclude("me.staartvin", "PluginLibrary") } + paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") } +paperweight.reobfArtifactConfiguration.set(ReobfArtifactConfiguration.REOBF_PRODUCTION) + publishing { repositories { maven { diff --git a/settings.gradle.kts b/settings.gradle.kts index 1ae12d9..9205142 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,3 +6,7 @@ buildscript { gradlePluginPortal() } } + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") +} diff --git a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt index 1e1bcd7..904da6e 100644 --- a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt +++ b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt @@ -20,14 +20,12 @@ import org.bukkit.Bukkit import org.bukkit.command.CommandExecutor import org.bukkit.entity.ItemFrame import org.bukkit.plugin.java.JavaPlugin -import org.bukkit.plugin.java.PluginClassLoader import java.io.File import java.io.IOException import java.net.InetSocketAddress -import java.nio.file.Files import java.util.concurrent.Executor import java.util.concurrent.Executors -import java.util.stream.Collectors +import java.util.logging.Level class LifeCore : JavaPlugin() { val gcListener = GCListener(this) @@ -38,7 +36,7 @@ class LifeCore : JavaPlugin() { val asyncExecutor = Executor { Bukkit.getScheduler().runTaskAsynchronously(this, it) } val lifeCoreConfig = LifeCoreConfig.load(this) val playerRegionManager = PlayerRegionManager() - val dataLoader = DataLoader(slF4JLogger, getAsFileSystem().getPath("/data")) + val dataLoader = DataLoader(logger, getAsFileSystem().getPath("/data")) private var databaseConfig: DatabaseConfig? = null lateinit var voteConfig: VoteConfig private set @@ -175,7 +173,7 @@ class LifeCore : JavaPlugin() { PlayerUtil.getChannel(player).pipeline() .addBefore("packet_handler", "lifecore", PacketHandler(player)) } catch (e: Exception) { - slF4JLogger.warn("Failed to inject channel handler to player " + player.name, e) + logger.log(Level.WARNING, "Failed to inject channel handler to player " + player.name, e) } } @@ -321,13 +319,13 @@ class LifeCore : JavaPlugin() { Class.forName("de.Keyle.MyPet.MyPetApi") pm.registerEvents(CancelPetClickListener(), this) } catch (e: ClassNotFoundException) { - slF4JLogger.warn("MyPet not detected, skipping event listener registration") + logger.warning("MyPet not detected, skipping event listener registration") } try { Class.forName("com.vexsoftware.votifier.model.VotifierEvent") pm.registerEvents(VoteListener(this), this) } catch (e: ClassNotFoundException) { - slF4JLogger.warn("Votifier not detected, skipping event listener registration") + logger.warning("Votifier not detected, skipping event listener registration") } try { Class.forName("com.palmergames.bukkit.towny.TownyAPI") @@ -336,21 +334,20 @@ class LifeCore : JavaPlugin() { .apply { startTask() } .apply { pm.registerEvents(this, this@LifeCore) } } catch (e: ClassNotFoundException) { - slF4JLogger.warn("Towny not detected, skipping event listener registration") - e.printStackTrace() + logger.log(Level.WARNING, "Towny not detected, skipping event listener registration", e) } try { Class.forName("net.azisaba.ryuzupluginchat.event.AsyncGlobalMessageEvent") pm.registerEvents(FilterNgWordsListener(this), this) } catch (e: ClassNotFoundException) { - slF4JLogger.warn("RyuZUPluginChat not detected, skipping event listener registration") + logger.warning("RyuZUPluginChat not detected, skipping event listener registration") } try { Class.forName("net.azisaba.rarity.api.RarityAPI") Class.forName("net.azisaba.itemstash.ItemStash") pm.registerEvents(DropProtectListener(this), this) } catch (e: ClassNotFoundException) { - slF4JLogger.warn("Rarity and/or ItemStash not detected, skipping event listener registration") + logger.warning("Rarity and/or ItemStash not detected, skipping event listener registration") } } diff --git a/src/main/java/com/github/mori01231/lifecore/TrashInventory.kt b/src/main/java/com/github/mori01231/lifecore/TrashInventory.kt index 7af33fc..e38c1fb 100644 --- a/src/main/java/com/github/mori01231/lifecore/TrashInventory.kt +++ b/src/main/java/com/github/mori01231/lifecore/TrashInventory.kt @@ -6,7 +6,6 @@ import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.inventory.Inventory import org.bukkit.inventory.InventoryHolder -import org.bukkit.inventory.ItemStack class TrashInventory : InventoryHolder { companion object { diff --git a/src/main/java/com/github/mori01231/lifecore/block/CustomBlock.kt b/src/main/java/com/github/mori01231/lifecore/block/CustomBlock.kt index eb8dd7d..897823b 100644 --- a/src/main/java/com/github/mori01231/lifecore/block/CustomBlock.kt +++ b/src/main/java/com/github/mori01231/lifecore/block/CustomBlock.kt @@ -4,9 +4,10 @@ import com.github.mori01231.lifecore.util.AxisX import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement -import net.minecraft.server.v1_15_R1.NBTTagCompound +import net.kyori.adventure.text.Component +import net.minecraft.nbt.CompoundTag import org.bukkit.Material -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack import org.bukkit.event.Listener import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.event.player.PlayerInteractEvent @@ -44,7 +45,7 @@ abstract class CustomBlock( open fun onPlace(e: BlockPlaceEvent): CustomBlockState { val nms = CraftItemStack.asNMSCopy(e.itemInHand) - val tagString = if (nms.hasTag() && nms.tag!!.hasKey("BlockState")) { + val tagString = if (nms.hasTag() && nms.tag!!.contains("BlockState")) { nms.tag!!.getCompound("BlockState").getString("tag") } else { "" @@ -63,14 +64,16 @@ abstract class CustomBlock( val item = ItemStack(material) item.itemMeta = item.itemMeta?.apply { setCustomModelData(this@CustomBlock.customModelData) - setDisplayName(this@CustomBlock.displayName) + if (this@CustomBlock.displayName != null) { + displayName(Component.text(this@CustomBlock.displayName)) + } lore = this@CustomBlock.lore } val nms = CraftItemStack.asNMSCopy(item) - nms.orCreateTag.set("BlockState", NBTTagCompound().apply { - setString("blockName", this@CustomBlock.name) + nms.orCreateTag.put("BlockState", CompoundTag().apply { + putString("blockName", this@CustomBlock.name) if (state != null) { - setString("tag", Json.encodeToString(state.tag)) + putString("tag", Json.encodeToString(state.tag)) } }) return CraftItemStack.asCraftMirror(nms) diff --git a/src/main/java/com/github/mori01231/lifecore/command/LifeCoreUtilCommand.kt b/src/main/java/com/github/mori01231/lifecore/command/LifeCoreUtilCommand.kt index db8ae35..9a4c38c 100644 --- a/src/main/java/com/github/mori01231/lifecore/command/LifeCoreUtilCommand.kt +++ b/src/main/java/com/github/mori01231/lifecore/command/LifeCoreUtilCommand.kt @@ -6,19 +6,21 @@ import com.github.mori01231.lifecore.util.EncodeUtil import com.github.mori01231.lifecore.util.ItemUtil import com.github.mori01231.lifecore.util.MapUtil import com.github.mori01231.lifecore.util.MapUtil.getCanvases -import net.minecraft.server.v1_15_R1.MojangsonParser -import net.minecraft.server.v1_15_R1.NBTTagByteArray -import net.minecraft.server.v1_15_R1.NBTTagCompound +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import net.minecraft.nbt.ByteArrayTag +import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.TagParser import org.bukkit.Bukkit import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.command.TabExecutor -import org.bukkit.craftbukkit.v1_15_R1.CraftServer -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapRenderer -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapView +import org.bukkit.craftbukkit.v1_20_R2.CraftServer +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapRenderer +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapView import org.bukkit.entity.Player import org.bukkit.inventory.meta.MapMeta import org.bukkit.util.Vector @@ -207,7 +209,7 @@ class LifeCoreUtilCommand(val plugin: LifeCore) : TabExecutor { GetTag { override fun execute(plugin: LifeCore, player: CommandSender, args: Array) { var tag = CraftItemStack.asNMSCopy((player as Player).inventory.itemInMainHand).tag ?: run { - player.sendMessage("${ChatColor.RED}Item has no tag.") + player.sendMessage(Component.text("Item has no tag.", NamedTextColor.RED)) return } if (args.isEmpty()) { @@ -231,31 +233,31 @@ class LifeCoreUtilCommand(val plugin: LifeCore) : TabExecutor { return } val item = CraftItemStack.asNMSCopy((player as Player).inventory.itemInMainHand) - val tag = item.tag ?: NBTTagCompound() - tag.a(MojangsonParser.parse(args.joinToString(" "))) - (player as Player).inventory.setItemInMainHand(CraftItemStack.asBukkitCopy(item)) + val tag = item.tag ?: CompoundTag() + tag.merge(TagParser.parseTag(args.joinToString(" "))) + player.inventory.setItemInMainHand(CraftItemStack.asBukkitCopy(item)) } }, SetTag { override fun execute(plugin: LifeCore, player: CommandSender, args: Array) { if (args.isEmpty()) { - player.sendMessage("${ChatColor.RED}Usage: /lifecoreutil $commandName ") + player.sendMessage(Component.text("Usage: /lifecoreutil $commandName ", NamedTextColor.RED)) return } val item = CraftItemStack.asNMSCopy((player as Player).inventory.itemInMainHand) - item.tag = MojangsonParser.parse(args.joinToString(" ")) - (player as Player).inventory.setItemInMainHand(CraftItemStack.asBukkitCopy(item)) + item.tag = TagParser.parseTag(args.joinToString(" ")) + player.inventory.setItemInMainHand(CraftItemStack.asBukkitCopy(item)) } }, GetBlock { override fun execute(plugin: LifeCore, player: CommandSender, args: Array) { if (args.isEmpty()) { - player.sendMessage("${ChatColor.RED}ブロック名を指定してください。") + player.sendMessage(Component.text("ブロック名を指定してください。", NamedTextColor.RED)) return } val block = plugin.customBlockManager.findBlockByName(args[0]) if (block == null) { - player.sendMessage("${ChatColor.RED}ブロックが見つかりませんでした。") + player.sendMessage(Component.text("ブロックが見つかりませんでした。", NamedTextColor.RED)) return } (player as Player).inventory.addItem(block.getItemStack(null)) @@ -429,7 +431,7 @@ class LifeCoreUtilCommand(val plugin: LifeCore) : TabExecutor { player.inventory.setItemInMainHand(ItemUtil.setTag( player.inventory.itemInMainHand, "SerializedMapData", - NBTTagByteArray(EncodeUtil.encodeBase64AndGzip(data.toByteArray())) + ByteArrayTag(EncodeUtil.encodeBase64AndGzip(data.toByteArray())) )) } }, diff --git a/src/main/java/com/github/mori01231/lifecore/data/DataLoader.kt b/src/main/java/com/github/mori01231/lifecore/data/DataLoader.kt index f51613e..c710054 100644 --- a/src/main/java/com/github/mori01231/lifecore/data/DataLoader.kt +++ b/src/main/java/com/github/mori01231/lifecore/data/DataLoader.kt @@ -2,9 +2,9 @@ package com.github.mori01231.lifecore.data import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json -import org.slf4j.Logger import java.nio.file.Files import java.nio.file.Path +import java.util.logging.Logger import kotlin.io.path.isDirectory import kotlin.io.path.readText import kotlin.io.path.relativeTo diff --git a/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEntityEvent.java b/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEntityEvent.java index bea4733..2509486 100644 --- a/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEntityEvent.java +++ b/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEntityEvent.java @@ -1,40 +1,42 @@ package com.github.mori01231.lifecore.event; -import net.minecraft.server.v1_15_R1.Entity; -import net.minecraft.server.v1_15_R1.PacketPlayInUseEntity; +import net.minecraft.world.entity.Entity; +import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.Objects; import java.util.UUID; -public class AsyncPlayerPreInteractEntityEvent extends PlayerEvent implements Cancellable { +public class AsyncPlayerPreInteractEntityEvent extends CallableEvent implements Cancellable { private static final HandlerList HANDLER_LIST = new HandlerList(); - private final PacketPlayInUseEntity.EnumEntityUseAction action; - private final Entity interactedEntity; + private final Player player; + private final int interactedEntity; private boolean cancelled = false; - public AsyncPlayerPreInteractEntityEvent(@NotNull Player player, @NotNull PacketPlayInUseEntity.EnumEntityUseAction action, @NotNull Entity interactedEntity) { - super(player, true); - this.action = action; + public AsyncPlayerPreInteractEntityEvent(@NotNull Player player, int interactedEntity) { + super(true); + this.player = player; this.interactedEntity = interactedEntity; } - @NotNull - public PacketPlayInUseEntity.EnumEntityUseAction getAction() { - return action; + public @NotNull Player getPlayer() { + return player; } - @NotNull - public Entity getInteractedEntity() { + public int getInteractedEntityId() { return interactedEntity; } - @NotNull - public UUID getEntityUniqueID() { - return interactedEntity.getUniqueID(); + public @NotNull Entity getInteractedEntity() { + return Objects.requireNonNull(((CraftWorld) player.getWorld()).getHandle().getEntity(interactedEntity), "entity no longer exists or never existed"); + } + + public @Nullable UUID getEntityUniqueID() { + return getInteractedEntity().getBukkitEntity().getUniqueId(); } @Override diff --git a/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEvent.java b/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEvent.java index 36f0ca8..d77d3a2 100644 --- a/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEvent.java +++ b/src/main/java/com/github/mori01231/lifecore/event/AsyncPlayerPreInteractEvent.java @@ -1,36 +1,32 @@ package com.github.mori01231.lifecore.event; -import net.minecraft.server.v1_15_R1.Entity; -import net.minecraft.server.v1_15_R1.PacketPlayInUseEntity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerEvent; import org.jetbrains.annotations.NotNull; /** * @deprecated misspelled */ @Deprecated -public class AsyncPlayerPreInteractEvent extends PlayerEvent implements Cancellable { +public class AsyncPlayerPreInteractEvent extends CallableEvent implements Cancellable { private static final HandlerList HANDLER_LIST = new HandlerList(); - private final PacketPlayInUseEntity.EnumEntityUseAction action; - private final Entity interactedEntity; + private final Player player; + private final int interactedEntity; private boolean cancelled = false; - public AsyncPlayerPreInteractEvent(@NotNull Player player, @NotNull PacketPlayInUseEntity.EnumEntityUseAction action, @NotNull Entity interactedEntity) { - super(player, true); - this.action = action; + public AsyncPlayerPreInteractEvent(@NotNull Player player, int interactedEntity) { + super(true); + this.player = player; this.interactedEntity = interactedEntity; } @NotNull - public PacketPlayInUseEntity.EnumEntityUseAction getAction() { - return action; + public Player getPlayer() { + return player; } - @NotNull - public Entity getInteractedEntity() { + public int getInteractedEntity() { return interactedEntity; } diff --git a/src/main/java/com/github/mori01231/lifecore/event/AsyncPreSignChangeEvent.kt b/src/main/java/com/github/mori01231/lifecore/event/AsyncPreSignChangeEvent.kt index 57803c3..5a933c7 100644 --- a/src/main/java/com/github/mori01231/lifecore/event/AsyncPreSignChangeEvent.kt +++ b/src/main/java/com/github/mori01231/lifecore/event/AsyncPreSignChangeEvent.kt @@ -1,6 +1,5 @@ package com.github.mori01231.lifecore.event -import net.minecraft.server.v1_15_R1.BlockPosition import org.bukkit.Location import org.bukkit.entity.Player import org.bukkit.event.Cancellable @@ -17,7 +16,7 @@ data class AsyncPreSignChangeEvent( val player: Player, val pos: Location, val lines: List, -) : Event(true), Cancellable { +) : CallableEvent(true), Cancellable { private var cancelled = false override fun getHandlers() = handlerList diff --git a/src/main/java/com/github/mori01231/lifecore/event/CallableEvent.java b/src/main/java/com/github/mori01231/lifecore/event/CallableEvent.java new file mode 100644 index 0000000..35bbca8 --- /dev/null +++ b/src/main/java/com/github/mori01231/lifecore/event/CallableEvent.java @@ -0,0 +1,24 @@ +package com.github.mori01231.lifecore.event; + +import org.bukkit.Bukkit; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; + +public abstract class CallableEvent extends Event { + public CallableEvent(boolean async) { + super(async); + } + + public CallableEvent() { + this(false); + } + + /** + * Call the event. If the event is cancellable and is cancelled, it will return true. Otherwise, it will return false. + * @return true if the event is cancelled, false otherwise + */ + public boolean callEvent() { + Bukkit.getPluginManager().callEvent(this); + return this instanceof Cancellable && ((Cancellable) this).isCancelled(); + } +} diff --git a/src/main/java/com/github/mori01231/lifecore/listener/CancelPetClickListener.java b/src/main/java/com/github/mori01231/lifecore/listener/CancelPetClickListener.java index 883fef1..6a80442 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/CancelPetClickListener.java +++ b/src/main/java/com/github/mori01231/lifecore/listener/CancelPetClickListener.java @@ -22,8 +22,8 @@ public void onClickEntity(AsyncPlayerPreInteractEntityEvent e) { if (!opt.isPresent()) { continue; } - if (opt.get().getUniqueId().equals(e.getInteractedEntity().getUniqueID()) || - opt.get().getHandle().getUniqueID().equals(e.getInteractedEntity().getUniqueID())) { + if (opt.get().getUniqueId().equals(e.getEntityUniqueID()) || + opt.get().getHandle().getUniqueID().equals(e.getEntityUniqueID())) { matched = true; break; } diff --git a/src/main/java/com/github/mori01231/lifecore/listener/CustomBlockListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/CustomBlockListener.kt index 0a17726..4b3a809 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/CustomBlockListener.kt +++ b/src/main/java/com/github/mori01231/lifecore/listener/CustomBlockListener.kt @@ -1,11 +1,12 @@ package com.github.mori01231.lifecore.listener import com.github.mori01231.lifecore.LifeCore +import net.kyori.adventure.text.Component import org.bukkit.GameMode import org.bukkit.Location import org.bukkit.Material import org.bukkit.Sound -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack import org.bukkit.entity.Arrow import org.bukkit.entity.Player import org.bukkit.event.EventHandler @@ -30,7 +31,7 @@ class CustomBlockListener(val plugin: LifeCore) : Listener { destroyAt(e.player, e.clickedBlock!!.location) } else { if (!e.player.hasPermission("lifecore.customblock.interact.${state.blockName}")) { - e.player.sendActionBar("このブロックを使用する権限がありません。") + e.player.sendActionBar(Component.text("このブロックを使用する権限がありません。")) return } state.getBlock().handleInteract(e, state) @@ -43,14 +44,14 @@ class CustomBlockListener(val plugin: LifeCore) : Listener { if (!nms.hasTag()) { return } - if (!nms.tag!!.hasKey("BlockState")) { + if (!nms.tag!!.contains("BlockState")) { return } val blockState = nms.tag!!.getCompound("BlockState") val blockName = blockState.getString("blockName") val block = plugin.customBlockManager.findBlockByName(blockName) ?: return if (!e.player.hasPermission("lifecore.customblock.place.$blockName")) { - e.player.sendActionBar("このブロックを設置する権限がありません。") + e.player.sendActionBar(Component.text("このブロックを設置する権限がありません。")) return } val state = block.onPlace(e) @@ -63,7 +64,7 @@ class CustomBlockListener(val plugin: LifeCore) : Listener { val state = plugin.customBlockManager.getState(e.block.location) ?: return e.isCancelled = true if (!e.player.hasPermission("lifecore.customblock.destroy.${state.blockName}")) { - e.player.sendActionBar("このブロックを破壊する権限がありません。") + e.player.sendActionBar(Component.text("このブロックを破壊する権限がありません。")) return } if (e.player.gameMode != GameMode.CREATIVE && !state.getBlock().canDestroy(state, false)) { @@ -131,7 +132,7 @@ class CustomBlockListener(val plugin: LifeCore) : Listener { } if (!state.getBlock().canDestroy(state, true)) return if (!player.hasPermission("lifecore.customblock.destroy.${state.blockName}")) { - player.sendActionBar("このブロックを破壊する権限がありません。") + player.sendActionBar(Component.text("このブロックを破壊する権限がありません。")) return } val drop = state.getBlock().preDestroy(state) diff --git a/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java b/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java index e281db1..4dba6a8 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java +++ b/src/main/java/com/github/mori01231/lifecore/listener/DropProtectListener.java @@ -5,11 +5,11 @@ import net.azisaba.rarity.api.Rarity; import net.azisaba.rarity.api.RarityAPI; import net.azisaba.rarity.api.RarityAPIProvider; -import net.minecraft.server.v1_15_R1.DataWatcherObject; -import net.minecraft.server.v1_15_R1.EntityItem; -import net.minecraft.server.v1_15_R1.Items; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.Items; import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftItem; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftItem; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerDropItemEvent; @@ -47,17 +47,17 @@ public void onDrop(PlayerDropItemEvent e) { // set item to air via reflection and data watcher e.getItemDrop().remove(); - EntityItem entityItem = (EntityItem) ((CraftItem) e.getItemDrop()).getHandle(); - DataWatcherObject itemStackDataWatcherObject; + ItemEntity entityItem = (ItemEntity) ((CraftItem) e.getItemDrop()).getHandle(); + EntityDataAccessor itemStackDataWatcherObject; try { - Field f = EntityItem.class.getDeclaredField("ITEM"); + Field f = ItemEntity.class.getDeclaredField("DATA_ITEM"); f.setAccessible(true); - itemStackDataWatcherObject = (DataWatcherObject) f.get(null); + itemStackDataWatcherObject = (EntityDataAccessor) f.get(null); } catch (ReflectiveOperationException ex) { return; } - entityItem.getDataWatcher().set(itemStackDataWatcherObject, new net.minecraft.server.v1_15_R1.ItemStack(Items.AIR)); - entityItem.getDataWatcher().markDirty(itemStackDataWatcherObject); + entityItem.getEntityData().set(itemStackDataWatcherObject, new net.minecraft.world.item.ItemStack(Items.AIR)); + entityItem.getEntityData().markDirty(itemStackDataWatcherObject); e.getPlayer().sendMessage(ChatColor.RED + "このレア度のアイテムはドロップできません。"); e.getPlayer().sendMessage(ChatColor.AQUA + "/dropprotect" + ChatColor.GOLD + "で設定を変更できます。"); diff --git a/src/main/java/com/github/mori01231/lifecore/listener/EscapeLobbyListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/EscapeLobbyListener.kt index 5b62075..032e6be 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/EscapeLobbyListener.kt +++ b/src/main/java/com/github/mori01231/lifecore/listener/EscapeLobbyListener.kt @@ -38,8 +38,9 @@ class EscapeLobbyListener(private val plugin: LifeCore) : Listener { if (e.player.hasPermission("lifecore.lobby-bypass")) return val lobby = plugin.lifeCoreConfig.lobbyRegion if (lobby.isIncomplete()) return - if (e.to.world.name != lobby?.world) return - if (lobby.contains(e.to)) return + val to = e.to ?: return + if (to.world!!.name != lobby?.world) return + if (lobby.contains(to)) return e.isCancelled = true } } diff --git a/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt index a40e811..3bca806 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt +++ b/src/main/java/com/github/mori01231/lifecore/listener/TrashListener.kt @@ -52,6 +52,7 @@ class TrashListener(private val plugin: LifeCore) : Listener { var moneyMultiplier = trashMoneyPerItem val items: MutableList = ArrayList() for (item in e.inventory.contents) { + item ?: continue try { if (item.amount > 0) { for (line in plugin.config.getStringList("Trash.Items")) { diff --git a/src/main/java/com/github/mori01231/lifecore/listener/UnableCraftListener.java b/src/main/java/com/github/mori01231/lifecore/listener/UnableCraftListener.java index 115316f..cbb6d5c 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/UnableCraftListener.java +++ b/src/main/java/com/github/mori01231/lifecore/listener/UnableCraftListener.java @@ -18,8 +18,8 @@ public class UnableCraftListener implements Listener { public void onCraft(PrepareGrindstoneEvent e) { if ( e.getView().getPlayer().hasPermission("lifecore.bypasscraft") ) return; - if ( checkItemStack(e.getInventory().getLowerItem()) ) e.setResult(null); - if ( checkItemStack(e.getInventory().getUpperItem()) ) e.setResult(null); + if ( checkItemStack(e.getInventory().getItem(0)) ) e.setResult(null); + if ( checkItemStack(e.getInventory().getItem(1)) ) e.setResult(null); } @EventHandler @@ -27,8 +27,8 @@ public void onAnvil(PrepareAnvilEvent e) { if ( e.getView().getPlayer().hasPermission("lifecore.bypasscraft") ) return; - if ( checkItemStack(e.getInventory().getFirstItem()) ) e.setResult(null); - if ( checkItemStack(e.getInventory().getSecondItem()) ) e.setResult(null); + if ( checkItemStack(e.getInventory().getItem(0)) ) e.setResult(null); + if ( checkItemStack(e.getInventory().getItem(1)) ) e.setResult(null); } @@ -39,7 +39,7 @@ public static boolean checkItemStack(ItemStack item) { ItemMeta meta = item.getItemMeta(); if ( item.getType().isAir() ) return false; - if ( !meta.hasDisplayName() ) return false; + if ( meta == null || !meta.hasDisplayName() ) return false; if ( meta.hasLore() ) return true; for ( String c: LIST ) { diff --git a/src/main/java/com/github/mori01231/lifecore/listener/VoidListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/VoidListener.kt index cae4ee4..9a4dede 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/VoidListener.kt +++ b/src/main/java/com/github/mori01231/lifecore/listener/VoidListener.kt @@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerMoveEvent object VoidListener : Listener { @EventHandler fun onPlayerMove(e: PlayerMoveEvent) { - if ((e.player.gameMode == GameMode.SURVIVAL || e.player.gameMode == GameMode.ADVENTURE) && e.to.y < 0) { + if ((e.player.gameMode == GameMode.SURVIVAL || e.player.gameMode == GameMode.ADVENTURE) && e.from.y < 0) { e.player.lastDamageCause = EntityDamageEvent(e.player, EntityDamageEvent.DamageCause.VOID, 99999999.0) e.player.damage(99999999.0) e.player.health = 0.0 diff --git a/src/main/java/com/github/mori01231/lifecore/listener/VoteListener.java b/src/main/java/com/github/mori01231/lifecore/listener/VoteListener.java index 6e2391b..d36c07e 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/VoteListener.java +++ b/src/main/java/com/github/mori01231/lifecore/listener/VoteListener.java @@ -15,11 +15,11 @@ public class VoteListener implements Listener { private final LifeCore plugin; - + public VoteListener(@NotNull LifeCore plugin) { this.plugin = plugin; } - + @EventHandler public void onVote(@NotNull VotifierEvent e) { processVotePacket(plugin, e.getVote().getUsername(), e.getVote().getServiceName()); @@ -33,11 +33,11 @@ public static synchronized void processVotePacket(@NotNull LifeCore plugin, @Not if (player == null) { PlayerUtil.resolveUUIDAsync(plugin, username).thenAcceptAsync(uuid -> { if (uuid == null) { - plugin.getSLF4JLogger().warn("Could not resolve UUID for player " + username); + plugin.getLogger().warning("Could not resolve UUID for player " + username); return; } VotesFile.increase(uuid.toString()); - plugin.getSLF4JLogger().info("Queued vote from {} (UUID: {}, service name: {})", username, uuid, serviceName); + plugin.getLogger().info("Queued vote from " + username + " (UUID: " + uuid + ", service name: " + serviceName + ")"); }, plugin.asyncExecutor); return; } diff --git a/src/main/java/com/github/mori01231/lifecore/listener/item/PicksawItemListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/item/PicksawItemListener.kt index 161e0cd..489b8ab 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/item/PicksawItemListener.kt +++ b/src/main/java/com/github/mori01231/lifecore/listener/item/PicksawItemListener.kt @@ -3,7 +3,7 @@ package com.github.mori01231.lifecore.listener.item import com.github.mori01231.lifecore.data.DataLoader import com.github.mori01231.lifecore.util.ItemUtil import org.bukkit.Material -import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData +import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.block.Action @@ -21,7 +21,7 @@ class PicksawItemListener(private val dataLoader: DataLoader) : Listener { if (e.action != Action.LEFT_CLICK_BLOCK) return val item = e.player.inventory.itemInMainHand if (ItemUtil.getStringTag(item, "LifeItemId") != ITEM_ID) return - val minecraftName = "minecraft:" + ((e.clickedBlock ?: return).blockData as CraftBlockData).state.block.item.toString() + val minecraftName = "minecraft:" + ((e.clickedBlock ?: return).blockData as CraftBlockData).state.block.asItem().toString() if (dataLoader.findTag("minecraft:mineable/axe")?.resolve()?.contains(minecraftName) == true) { item.type = Material.valueOf(item.type.name.substring(0, item.type.name.lastIndexOf('_')) + "_AXE") e.player.inventory.setItemInMainHand(item) @@ -36,4 +36,4 @@ class PicksawItemListener(private val dataLoader: DataLoader) : Listener { e.player.inventory.setItemInMainHand(item) } } -} \ No newline at end of file +} diff --git a/src/main/java/com/github/mori01231/lifecore/map/SerializedMapCanvas.kt b/src/main/java/com/github/mori01231/lifecore/map/SerializedMapCanvas.kt index 57b5d5c..e7a3cb5 100644 --- a/src/main/java/com/github/mori01231/lifecore/map/SerializedMapCanvas.kt +++ b/src/main/java/com/github/mori01231/lifecore/map/SerializedMapCanvas.kt @@ -1,7 +1,7 @@ package com.github.mori01231.lifecore.map import kotlinx.serialization.Serializable -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapCanvas +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapCanvas @Serializable data class SerializedMapCanvas(val buffer: ByteArray, val base: ByteArray) { @@ -43,4 +43,4 @@ data class SerializedMapCanvas(val buffer: ByteArray, val base: ByteArray) { result = 31 * result + base.contentHashCode() return result } -} \ No newline at end of file +} diff --git a/src/main/java/com/github/mori01231/lifecore/map/SerializedMapDataRenderer.kt b/src/main/java/com/github/mori01231/lifecore/map/SerializedMapDataRenderer.kt index c7b18ec..5bf47fb 100644 --- a/src/main/java/com/github/mori01231/lifecore/map/SerializedMapDataRenderer.kt +++ b/src/main/java/com/github/mori01231/lifecore/map/SerializedMapDataRenderer.kt @@ -1,8 +1,8 @@ package com.github.mori01231.lifecore.map -import net.minecraft.server.v1_15_R1.WorldMap -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapCanvas -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapView +import net.minecraft.world.level.saveddata.maps.MapItemSavedData +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapCanvas +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapView import org.bukkit.entity.Player import org.bukkit.map.MapCanvas import org.bukkit.map.MapRenderer @@ -17,13 +17,15 @@ class SerializedMapDataRenderer(private val canvas: SerializedMapCanvas) : MapRe for (i in 0 until canvas.cursors.size()) { canvas.cursors.removeCursor(canvas.cursors.getCursor(i)) } - val worldMap = CraftMapView::class.java.getDeclaredField("worldMap").apply { isAccessible = true }[view] as WorldMap + val worldMap = CraftMapView::class.java.getDeclaredField("worldMap").apply { isAccessible = true }[view] as MapItemSavedData + worldMap.decorations.clear() + worldMap.setDecorationsDirty() for (x in 0..127) { for (y in 0..127) { - worldMap.decorations.clear() - worldMap.flagDirty(x, y) + worldMap.setColorsDirty(x, y) } } + worldMap.setDirty() init = true } -} \ No newline at end of file +} diff --git a/src/main/java/com/github/mori01231/lifecore/network/PacketHandler.java b/src/main/java/com/github/mori01231/lifecore/network/PacketHandler.java index a7aa2be..ae0c057 100644 --- a/src/main/java/com/github/mori01231/lifecore/network/PacketHandler.java +++ b/src/main/java/com/github/mori01231/lifecore/network/PacketHandler.java @@ -5,13 +5,12 @@ import com.github.mori01231.lifecore.event.AsyncPreSignChangeEvent; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; -import net.minecraft.server.v1_15_R1.Entity; -import net.minecraft.server.v1_15_R1.EntityPlayer; -import net.minecraft.server.v1_15_R1.PacketPlayInUpdateSign; -import net.minecraft.server.v1_15_R1.PacketPlayInUseEntity; +import net.minecraft.network.protocol.game.ServerboundInteractPacket; +import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; +import net.minecraft.server.level.ServerPlayer; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -20,7 +19,7 @@ public class PacketHandler extends ChannelDuplexHandler { private final Player player; - private final EntityPlayer entityPlayer; + private final ServerPlayer entityPlayer; public PacketHandler(@NotNull Player player) { this.player = player; @@ -29,22 +28,20 @@ public PacketHandler(@NotNull Player player) { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - if (msg instanceof PacketPlayInUseEntity) { - PacketPlayInUseEntity packet = (PacketPlayInUseEntity) msg; - Entity entity = packet.a(entityPlayer.world); - if (entity != null) { - if (new AsyncPlayerPreInteractEvent(player, packet.b(), entity).callEvent() && - new AsyncPlayerPreInteractEntityEvent(player, packet.b(), entity).callEvent()) { - super.channelRead(ctx, msg); - } - return; + if (msg instanceof ServerboundInteractPacket packet) { + int entityId = packet.getEntityId(); + if (new AsyncPlayerPreInteractEvent(player, entityId).callEvent() && + new AsyncPlayerPreInteractEntityEvent(player, entityId).callEvent()) { + super.channelRead(ctx, msg); } } - if (msg instanceof PacketPlayInUpdateSign) { - PacketPlayInUpdateSign packet = (PacketPlayInUpdateSign) msg; - Location location = new Location(player.getWorld(), packet.b().getX(), packet.b().getY(), packet.b().getZ()); - List lines = Arrays.asList(packet.c()); - if (new AsyncPreSignChangeEvent(player, location, lines).callEvent()) { + if (msg instanceof ServerboundSignUpdatePacket packet) { + var pos = packet.getPos(); + var location = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ()); + var lines = Arrays.asList(packet.getLines()); + var event = new AsyncPreSignChangeEvent(player, location, lines); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { super.channelRead(ctx, msg); } return; diff --git a/src/main/java/com/github/mori01231/lifecore/region/CuboidRegion.kt b/src/main/java/com/github/mori01231/lifecore/region/CuboidRegion.kt index 4252581..ecfbfef 100644 --- a/src/main/java/com/github/mori01231/lifecore/region/CuboidRegion.kt +++ b/src/main/java/com/github/mori01231/lifecore/region/CuboidRegion.kt @@ -63,7 +63,7 @@ data class CuboidRegion( if (pos2 == null) { error("This CuboidRegion is incomplete (pos2 is null)") } - if (location.world.name != world) { + if (location.world?.name != world) { return false } return contains(location.blockX, location.blockY, location.blockZ) diff --git a/src/main/java/com/github/mori01231/lifecore/region/WorldLocation.kt b/src/main/java/com/github/mori01231/lifecore/region/WorldLocation.kt index 7edcfd3..eb36289 100644 --- a/src/main/java/com/github/mori01231/lifecore/region/WorldLocation.kt +++ b/src/main/java/com/github/mori01231/lifecore/region/WorldLocation.kt @@ -12,7 +12,7 @@ data class WorldLocation( val z: Int, ) { constructor(location: Location) : this( - location.world.name, + location.world?.name ?: error("World is null"), location.blockX, location.blockY, location.blockZ, diff --git a/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java b/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java index cd6af3d..cbd2d82 100644 --- a/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java +++ b/src/main/java/com/github/mori01231/lifecore/util/ItemUtil.java @@ -1,11 +1,11 @@ package com.github.mori01231.lifecore.util; import net.azisaba.itemstash.ItemStash; -import net.minecraft.server.v1_15_R1.NBTBase; -import net.minecraft.server.v1_15_R1.NBTTagCompound; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; import org.bukkit.Material; import org.bukkit.attribute.Attribute; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -37,17 +37,17 @@ public static boolean isProbablyAdminSword(@Nullable ItemStack stack) { @Contract("null -> null") public static @Nullable String getMythicType(@Nullable ItemStack stack) { if (stack == null || stack.getType().isAir()) return null; - NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).getTag(); + CompoundTag tag = CraftItemStack.asNMSCopy(stack).getTag(); if (tag == null) return null; String type = tag.getString("MYTHIC_TYPE"); - if (type == null || type.isEmpty()) return null; + if (type.isEmpty()) return null; return type; } @Contract("null, _ -> null") public static @Nullable String getStringTag(@Nullable ItemStack stack, @NotNull String key) { if (stack == null || stack.getType().isAir()) return null; - NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).getTag(); + CompoundTag tag = CraftItemStack.asNMSCopy(stack).getTag(); if (tag == null) return null; return tag.getString(key); } @@ -55,24 +55,24 @@ public static boolean isProbablyAdminSword(@Nullable ItemStack stack) { @Contract("null, _ -> null") public static @Nullable byte[] getByteArrayTag(@Nullable ItemStack stack, @NotNull String key) { if (stack == null || stack.getType().isAir()) return null; - NBTTagCompound tag = CraftItemStack.asNMSCopy(stack).getTag(); + CompoundTag tag = CraftItemStack.asNMSCopy(stack).getTag(); if (tag == null) return null; return tag.getByteArray(key); } public static @NotNull ItemStack setStringTag(@Nullable ItemStack stack, @NotNull String key, @NotNull String value) { if (stack == null || stack.getType().isAir()) return new ItemStack(Material.AIR); - net.minecraft.server.v1_15_R1.ItemStack nms = CraftItemStack.asNMSCopy(stack); - NBTTagCompound tag = nms.getOrCreateTag(); - tag.setString(key, value); + net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(stack); + CompoundTag tag = nms.getOrCreateTag(); + tag.putString(key, value); return CraftItemStack.asBukkitCopy(nms); } - public static @NotNull ItemStack setTag(@Nullable ItemStack stack, @NotNull String key, @NotNull NBTBase nbt) { + public static @NotNull ItemStack setTag(@Nullable ItemStack stack, @NotNull String key, @NotNull Tag nbt) { if (stack == null || stack.getType().isAir()) return new ItemStack(Material.AIR); - net.minecraft.server.v1_15_R1.ItemStack nms = CraftItemStack.asNMSCopy(stack); - NBTTagCompound tag = nms.getOrCreateTag(); - tag.set(key, nbt); + net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(stack); + CompoundTag tag = nms.getOrCreateTag(); + tag.put(key, nbt); return CraftItemStack.asBukkitCopy(nms); } diff --git a/src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt b/src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt index 909fd38..5ebdf0c 100644 --- a/src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt +++ b/src/main/java/com/github/mori01231/lifecore/util/MapUtil.kt @@ -8,10 +8,10 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.encodeToJsonElement import org.bukkit.Material -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapCanvas -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapRenderer -import org.bukkit.craftbukkit.v1_15_R1.map.CraftMapView +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapCanvas +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapRenderer +import org.bukkit.craftbukkit.v1_20_R2.map.CraftMapView import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.MapMeta diff --git a/src/main/java/com/github/mori01231/lifecore/util/PlayerUtil.java b/src/main/java/com/github/mori01231/lifecore/util/PlayerUtil.java index 0b9822e..520c61e 100644 --- a/src/main/java/com/github/mori01231/lifecore/util/PlayerUtil.java +++ b/src/main/java/com/github/mori01231/lifecore/util/PlayerUtil.java @@ -6,7 +6,7 @@ import com.github.mori01231.lifecore.TableKey; import io.netty.channel.Channel; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -72,6 +72,6 @@ public static UUID fetchUUID(@NotNull DatabaseConfig databaseConfig, @NotNull St @NotNull public static Channel getChannel(@NotNull Player player) { // channel field is set to non-null value after #channelActive is called - return Objects.requireNonNull(((CraftPlayer) player).getHandle().playerConnection.networkManager.channel, "inactive channel"); + return Objects.requireNonNull(((CraftPlayer) player).getHandle().connection.connection.channel, "inactive channel"); } } diff --git a/src/main/java/com/github/mori01231/lifecore/util/PromptSign.kt b/src/main/java/com/github/mori01231/lifecore/util/PromptSign.kt index 4363548..7619e5f 100644 --- a/src/main/java/com/github/mori01231/lifecore/util/PromptSign.kt +++ b/src/main/java/com/github/mori01231/lifecore/util/PromptSign.kt @@ -1,12 +1,11 @@ package com.github.mori01231.lifecore.util import com.github.mori01231.lifecore.LifeCore -import net.minecraft.server.v1_15_R1.BlockPosition -import net.minecraft.server.v1_15_R1.CancelledPacketHandleException -import net.minecraft.server.v1_15_R1.PacketPlayOutOpenSignEditor +import net.minecraft.core.BlockPos +import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket import org.bukkit.Bukkit import org.bukkit.Material -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer +import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin import java.util.* @@ -27,8 +26,8 @@ object PromptSign { player.sendBlockChange(loc0, origBlockData) action.accept(it) } - (player as CraftPlayer).handle.playerConnection - .sendPacket(PacketPlayOutOpenSignEditor(BlockPosition(loc0.blockX, loc0.blockY, loc0.blockZ))) + (player as CraftPlayer).handle.connection + .send(ClientboundOpenSignEditorPacket(BlockPos(loc0.blockX, loc0.blockY, loc0.blockZ), true)) }) } -} \ No newline at end of file +}