Skip to content

Commit

Permalink
update to 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Jul 28, 2024
1 parent ccff0d0 commit 3195381
Show file tree
Hide file tree
Showing 29 changed files with 198 additions and 167 deletions.
16 changes: 10 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ buildscript {
gradlePluginPortal()
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0")
}
19 changes: 8 additions & 11 deletions src/main/java/com/github/mori01231/lifecore/LifeCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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")
Expand All @@ -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")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/github/mori01231/lifecore/block/CustomBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
""
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -207,7 +209,7 @@ class LifeCoreUtilCommand(val plugin: LifeCore) : TabExecutor {
GetTag {
override fun execute(plugin: LifeCore, player: CommandSender, args: Array<String>) {
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()) {
Expand All @@ -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<String>) {
if (args.isEmpty()) {
player.sendMessage("${ChatColor.RED}Usage: /lifecoreutil $commandName <value>")
player.sendMessage(Component.text("Usage: /lifecoreutil $commandName <value>", 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<String>) {
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))
Expand Down Expand Up @@ -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()))
))
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
Loading

0 comments on commit 3195381

Please sign in to comment.