Skip to content

Commit

Permalink
🐛 Fix bugs and Finished test on 1.13.2
Browse files Browse the repository at this point in the history
known problem: Eggs_Gun still works abnormal but no exception
  • Loading branch information
way-zer committed Mar 1, 2020
1 parent aa08152 commit 545208c
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 66 deletions.
1 change: 0 additions & 1 deletion Scripts/Mythicmobs_Support.superitem.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ listen<MythicDropLoadEvent>{
val name = (it.dropName as String).toUpperCase()
if(!name.startsWith("SI_"))return@listen
val item = ItemManager.getItem(name.substring(3))
//if(item==null)it.register(NothingDrop(it.config.line,it.config))
if(item!=null)it.register(ItemDrop(it.config.line,it.config,BukkitItemStack(item.get<ItemInfo>().newItemStack())))
}

21 changes: 17 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
plugins {
id 'com.github.johnrengelman.shadow' version '5.0.0'
id 'java'
id 'org.jetbrains.kotlin.jvm' version "1.3.41"
id 'org.jetbrains.kotlin.jvm' version "1.3.61"
id 'me.qoomon.git-versioning' version '1.2.1'
}
ext{
kotlin_version ="1.3.41"
kotlin_version ="1.3.61"
mc_version = '1.14-R0.1-SNAPSHOT'
bc_version ='1.12-SNAPSHOT'
}

allprojects{
group = 'cf.wayzer'
repositories {
maven{ url "http://maven.aliyun.com/nexus/content/groups/public/"}
jcenter()
mavenCentral()
maven {
Expand All @@ -28,14 +29,18 @@ shadowJar {
// minimize()
configurations = [project.configurations.shadow]
relocate("me.dpohvar.powernbt.api","cf.wayzer.util.nbt")
relocate("me.dpohvar.powernbt.nbt","cf.wayzer.util.nbt.nbt")
relocate("me.dpohvar.powernbt.utils","cf.wayzer.util.nbt.utils")
relocate("me.dpohvar.powernbt.exception","cf.wayzer.util.nbt.exception")
// exclude("me/**")
// exclude("example/**")
// exclude("(?!plugin).yml")
include("*.jar")
//for NBT
include("me/dpohvar/powernbt/api/**")
include("me/dpohvar/powernbt/utils/**")
include("me/dpohvar/powernbt/nbt/**")
include("me/dpohvar/powernbt/exception/**")

include("cf/wayzer/**")
include("*.kts")
Expand All @@ -47,7 +52,7 @@ shadowJar {
//start

dependencies{
shadow 'cf.wayzer:LibraryManager:1.2'
shadow 'cf.wayzer:LibraryManager:1.3'
shadow(files("$rootDir/lib/PowerNBT.jar"))
compile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-scripting-jvm-host:$kotlin_version"
Expand All @@ -74,7 +79,7 @@ processResources{
}
}
}
def items = subprojects[0] as Project
def items = subprojects.first()
task buildArtifact(type: Zip){
dependsOn items.getTasksByName("classes",false)
dependsOn shadowJar
Expand All @@ -93,3 +98,11 @@ task buildArtifact(type: Zip){
archiveFileName = "SuperItem-${rootProject.version}.zip"
destinationDirectory =file("$rootDir/artifacts/")
}

task develCopy(type: Copy){
dependsOn shadowJar
from(shadowJar.getArchiveFile()){
rename("-all","")
}
into "F:\\minecraft\\RogInkTestServer\\plugins"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 9 additions & 9 deletions items/src/main/kotlin/Eggs_Gun.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.bukkit.DyeColor
import org.bukkit.Material
import org.bukkit.Sound
import org.bukkit.block.Block
import org.bukkit.block.data.BlockData
import org.bukkit.entity.EntityType
import org.bukkit.entity.Monster
import org.bukkit.entity.Player
Expand All @@ -23,6 +22,7 @@ import org.bukkit.event.entity.ProjectileHitEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.server.PluginDisableEvent
import org.bukkit.material.Colorable
import org.bukkit.material.MaterialData
import org.bukkit.scheduler.BukkitRunnable
import java.util.*

Expand All @@ -36,17 +36,17 @@ class Eggs_Gun : Item() {
internal var time: Byte = 0

init {
val data = block.blockData as Colorable
val data = block.state.data as Colorable
old_color = data.color?:DyeColor.WHITE
time = 20
data.color = DyeColor.RED
block.blockData = data as BlockData
block.state.data = data as MaterialData
}

fun setback() {
val data = block.blockData as Colorable
val data = block.state.data as Colorable
data.color = old_color
block.blockData = data as BlockData
block.state.data = data as MaterialData
}
}

Expand Down Expand Up @@ -104,16 +104,16 @@ class Eggs_Gun : Item() {
@EventHandler
fun onHit(e: ProjectileHitEvent) {
if (e.entityType == EntityType.SNOWBALL && "§7雪球来复枪" == e.entity.customName
&& e.entity.shooter is Player) {
val snow = e.entity
val loc = snow.location.block.location
&& e.entity.shooter is Player && e.hitBlock !=null) {
// val snow = e.entity
val loc = e.hitBlock!!.location
for (i in -1..1)
for (i1 in -1..1)
for (i11 in -1..1)
if (i == 0 || i1 == 0 || i11 == 0) {
val b = loc.world!!.getBlockAt(loc.blockX + i, loc.blockY + i1,
loc.blockZ + i11)
if(b.blockData is Colorable && (b.blockData as Colorable).color != DyeColor.RED){
if(b.state.data is Colorable && (b.state.data as Colorable).color != DyeColor.RED){
blocks.add(BlockInfo(b))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/cf/wayzer/SuperItem/Commander.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Commander : CommandExecutor {
var i = pages * 10 - 10
while (i < list.size && i < pages * 10) {
s.sendMessage(String.format("§e%03d §a|§e %-20s §a|§e %s",
i, list[i].name, list[i].get<ItemInfo>().newItemStack().itemMeta.displayName))
i, list[i].name, list[i].get<ItemInfo>().newItemStack().itemMeta?.displayName))
i++
}
s.sendMessage("§a================ §7$pages/$maxpages §a================")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/cf/wayzer/SuperItem/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ object ConfigManager{
get() = map.getOrPut(this){ readFile(configFile) }

private val Item.configFile:File
get() = File(rootDir, "$packageName ${File.pathSeparator} $name.json")
get() = File(rootDir, "$packageName/$name.json")
}
33 changes: 3 additions & 30 deletions src/main/kotlin/cf/wayzer/SuperItem/Item.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cf.wayzer.SuperItem

import cf.wayzer.SuperItem.features.CoolDown
import cf.wayzer.SuperItem.features.ItemInfo
import cf.wayzer.SuperItem.features.Permission
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.entity.Player
Expand Down Expand Up @@ -37,23 +35,11 @@ abstract class Item : Listener {

val features : MutableMap<Class<*>,MutableList<Feature<*>>> = mutableMapOf()

@Deprecated("保证扩展和安全,请使用get,1.3版本弃用",ReplaceWith("get<ItemInfo>().newItemStack()"))
val item
get() = get<ItemInfo>().newItemStack()

@Deprecated("保证扩展和安全,请使用get,1.3版本弃用",ReplaceWith("get<Permission>()"))
val permission
get() = get<Permission>()

@Deprecated("保证扩展和安全,请使用get,1.3版本弃用",ReplaceWith("get<CoolDown>()"))
val coolDown
get() = get<CoolDown>()

open val name: String
get() = javaClass.simpleName
get() = javaClass.simpleName.toUpperCase()

open val packageName: String
get() = javaClass.`package`.name
get() = javaClass.`package`?.name?:"ROOT"


/**
Expand Down Expand Up @@ -103,7 +89,7 @@ abstract class Item : Listener {
}

fun drop(location: Location,player: Player?=null){
location.world.dropItem(location,get<ItemInfo>().newItemStack(player))
location.world?.dropItem(location,get<ItemInfo>().newItemStack(player))
}

/**
Expand Down Expand Up @@ -135,19 +121,6 @@ abstract class Item : Listener {
*/
val pluginMain = Main.main as JavaPlugin


@Deprecated("不建议直接使用,1.3版本弃用", ReplaceWith("get<Permission>().hasPermission(p)"))
fun Item.hasPermission(p: Player) =
get<Permission>().hasPermission(p)

@Deprecated("不建议直接使用,1.3版本弃用", ReplaceWith("get<CoolDown>().isCoolDownOK(p)"))
fun Item.isCoolDownOK(p: Player) =
get<CoolDown>().isCoolDownOK(p)

@Deprecated("不建议直接使用,1.3版本弃用", ReplaceWith("get<CoolDown>().add(p)"))
fun Item.addCoolDown(p: Player) =
get<CoolDown>().add(p)

/**
* 消耗玩家指定物品
* @param item 需要消耗的物品
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/cf/wayzer/SuperItem/ItemManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ object ItemManager {
ucl = URLClassLoader.newInstance(arrayOf(rootDir.toURI().toURL()),
ItemManager::class.java.classLoader)
loadDir(rootDir,"")
Main.main.saveConfig()
}

private fun loadDir(dir:File,prefix:String){
Expand Down Expand Up @@ -129,7 +128,7 @@ object ItemManager {
* 通过 Item.class.simpleName 查询Item
*/
fun getItem(className: String): Item? {
return items[className]
return items[className.toUpperCase()]
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/cf/wayzer/SuperItem/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class Main : JavaPlugin() {
}

companion object {
const val kotlinVersion = "1.3.41"
const val kotlinVersion = "1.3.61"
lateinit var main: Main
private set
init {
LibraryManager(Paths.get("./libs/")).apply {
addMavenCentral()
addAliYunMirror()
require(Dependency("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"))
require(Dependency("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1"))
require(Dependency("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"))
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/cf/wayzer/SuperItem/features/ItemInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class ItemInfo(
val itemStack = itemStackTemplate.clone()
itemStackHandlers.forEach { it(itemStack,p) }
main.server.pluginManager.callEvent(ItemStackHandleEvent(itemStack,p))
itemStack.itemMeta = itemStack.itemMeta.apply {
displayName = displayName.replace("&","§")
lore = lore.map { it.replace("&","§") }
itemStack.itemMeta = itemStack.itemMeta?.apply {
setDisplayName(displayName.replace("&","§"))
lore = lore?.map { it.replace("&","§") }
}
return itemStack
}
Expand All @@ -63,8 +63,7 @@ class ItemInfo(
fun registerHandler(handler: ItemStackHandler)=itemStackHandlers.add(handler)

override fun onPostLoad(main: Main) {
@Suppress("DEPRECATION")
val itemStack = ItemStack(data.material, 1, 0,data.data.toByte())
val itemStack = ItemStack(data.material, 1)

val im = itemStack.itemMeta!!
im.setDisplayName(data.name)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/cf/wayzer/SuperItem/features/NBT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cf.wayzer.SuperItem.features

import cf.wayzer.SuperItem.Feature
import cf.wayzer.SuperItem.Main
import me.dpohvar.powernbt.PowerNBT
import me.dpohvar.powernbt.api.NBTCompound
import me.dpohvar.powernbt.api.NBTManager
import java.util.logging.Level

/**
Expand Down Expand Up @@ -71,6 +71,6 @@ class NBT(override vararg val defaultData: AttributeModifier) : Feature<Array<ou
}

companion object {
val api = PowerNBT.getApi()!!
val api = NBTManager.getInstance()
}
}
}
10 changes: 5 additions & 5 deletions src/main/kotlin/cf/wayzer/SuperItem/scripts/ScriptLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class ScriptLoader {
var item:Item?=null
val result = load0(file)
result.onSuccess {
val res = result.resultOrNull()!!.returnValue
if(res is ResultValue.Value && res.value is Item) {
item = (res.value as Item)
val res = result.valueOrThrow().returnValue
if(res.scriptInstance is Item) {
item = (res.scriptInstance as Item)
result.reports.filterNot { it.severity== ScriptDiagnostic.Severity.DEBUG }.forEachIndexed { index, rep ->
logger.log(Level.WARNING,"##$index##"+rep.message,rep.exception)
}
return@onSuccess ResultWithDiagnostics.Success(ResultValue.Unit)
return@onSuccess ResultWithDiagnostics.Success(res)
} else {
return@onSuccess ResultWithDiagnostics.Failure(ScriptDiagnostic("非物品Kts: ${file.name}"))
}
Expand All @@ -55,4 +55,4 @@ class ScriptLoader {
constructorArgs(f.name.split(".")[0].toUpperCase())
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object ScriptSupporter {
fun init(logger:Logger){
if(inited)return
LibraryManager(Paths.get("./libs/")).apply {
addMavenCentral()
addAliYunMirror()
require(Dependency("org.jetbrains.kotlin:kotlin-script-runtime:${Main.kotlinVersion}"))
require(Dependency("org.jetbrains.kotlin:kotlin-scripting-common:${Main.kotlinVersion}"))
require(Dependency("org.jetbrains.intellij.deps:trove4j:1.0.20181211"))
Expand All @@ -36,4 +36,4 @@ object ScriptSupporter {
if(!inited)throw IllegalStateException("Must init first!!")
return loader.load(file)
}
}
}
Empty file.

0 comments on commit 545208c

Please sign in to comment.