remove LegacyResourceLocation

Co-authored-by: MrGeoTech <themrgeotech@gmail.com>
This commit is contained in:
Bixilon 2023-01-03 11:25:10 +01:00
parent 5873611b9c
commit a3ec99f55a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 15 additions and 51 deletions

View File

@ -1,34 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries
class LegacyResourceLocation(resourceLocation: String) : ResourceLocation("", resourceLocation) {
override val full: String = path
override fun hashCode(): Int {
return this.path.hashCode()
}
override fun equals(other: Any?): Boolean {
if (other === this) {
return true
}
if (hashCode() != other.hashCode()) {
return false
}
if (other !is ResourceLocation) {
return false
}
return path == other.path
}
}

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -31,7 +31,7 @@ data class PluginChannel(
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): PluginChannel { override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): PluginChannel {
return PluginChannel( return PluginChannel(
resourceLocation = resourceLocation, resourceLocation = resourceLocation,
name = LegacyResourceLocation(data["name"].unsafeCast()) name = ResourceLocation(data["name"].unsafeCast())
) )
} }
} }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -12,7 +12,6 @@
*/ */
package de.bixilon.minosoft.data.registries package de.bixilon.minosoft.data.registries
import de.bixilon.kutil.string.StringUtil.isLowercase
import de.bixilon.minosoft.data.language.translate.Translatable import de.bixilon.minosoft.data.language.translate.Translatable
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import java.util.* import java.util.*
@ -41,9 +40,6 @@ open class ResourceLocation(
if (hashCode() != other.hashCode()) { if (hashCode() != other.hashCode()) {
return false return false
} }
if (other is LegacyResourceLocation) {
return path == other.path
}
if (other !is ResourceLocation) { if (other !is ResourceLocation) {
return false return false
} }
@ -81,13 +77,7 @@ open class ResourceLocation(
} }
fun getResourceLocation(resourceLocation: String): ResourceLocation { fun getResourceLocation(resourceLocation: String): ResourceLocation {
// if (!ProtocolDefinition.RESOURCE_LOCATION_PATTERN.matcher(resourceLocation).matches()) { return ResourceLocation(resourceLocation)
// throw new IllegalArgumentException(String.format("%s in not a valid resource location!", resourceLocation));
// }
return if (!resourceLocation.isLowercase()) {
// just a string but wrapped into a resourceLocation (like old plugin channels MC|BRAND or ...)
LegacyResourceLocation(resourceLocation)
} else ResourceLocation(resourceLocation)
} }
fun getPathResourceLocation(resourceLocation: String): ResourceLocation { fun getPathResourceLocation(resourceLocation: String): ResourceLocation {

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -31,7 +31,7 @@ class ChannelC2SP(
constructor(channel: ResourceLocation, buffer: OutByteBuffer) : this(channel, buffer.toArray()) constructor(channel: ResourceLocation, buffer: OutByteBuffer) : this(channel, buffer.toArray())
override fun write(buffer: PlayOutByteBuffer) { override fun write(buffer: PlayOutByteBuffer) {
buffer.writeResourceLocation(channel) buffer.writeLegacyResourceLocation(channel)
if (buffer.versionId < ProtocolVersions.V_14W29A) { if (buffer.versionId < ProtocolVersions.V_14W29A) {
buffer.writeShort(data.size) buffer.writeShort(data.size)
} else if (buffer.versionId < ProtocolVersions.V_14W31A) { } else if (buffer.versionId < ProtocolVersions.V_14W31A) {

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -285,6 +285,14 @@ open class OutByteBuffer() {
buffer.put(toArray()) buffer.put(toArray())
} }
fun writeLegacyResourceLocation(resourceLocation: ResourceLocation) {
if (resourceLocation.namespace == ProtocolDefinition.DEFAULT_NAMESPACE) {
writeString(resourceLocation.path)
return
}
writeResourceLocation(resourceLocation)
}
fun writeResourceLocation(resourceLocation: ResourceLocation) { fun writeResourceLocation(resourceLocation: ResourceLocation) {
writeString(resourceLocation.full) writeString(resourceLocation.full)
} }