mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
convert more stuff to kotlin
This commit is contained in:
parent
bbe5079257
commit
c4c69d8e33
@ -1,43 +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;
|
||||
|
||||
public class PlayerPropertyData {
|
||||
private final String name;
|
||||
private final String value;
|
||||
private final String signature;
|
||||
|
||||
public PlayerPropertyData(String name, String value, String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s=%s", getName(), getValue());
|
||||
}
|
||||
}
|
@ -18,8 +18,6 @@ import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.locale.minecraft.Translator
|
||||
import de.bixilon.minosoft.data.text.RGBColor.Companion.asColor
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||
import glm_.vec2.Vec2i
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.scene.Node
|
||||
import java.text.CharacterIterator
|
||||
|
@ -1,52 +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.text;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
public class ClickEvent {
|
||||
private final ClickEventActions action;
|
||||
private final Object value;
|
||||
|
||||
public ClickEvent(JsonObject json) {
|
||||
this.action = ClickEventActions.valueOf(json.get("action").getAsString().toUpperCase());
|
||||
JsonPrimitive primitive = json.get("value").getAsJsonPrimitive();
|
||||
if (primitive.isNumber()) {
|
||||
this.value = primitive.getAsNumber();
|
||||
} else {
|
||||
this.value = primitive.getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
public ClickEvent(ClickEventActions action, Object value) {
|
||||
this.action = action;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public ClickEventActions getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public enum ClickEventActions {
|
||||
OPEN_URL,
|
||||
RUN_COMMAND,
|
||||
SUGGEST_COMMAND,
|
||||
CHANGE_PAGE
|
||||
}
|
||||
}
|
@ -1,106 +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.text;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.util.Util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class HoverEvent {
|
||||
private final HoverEventActions action;
|
||||
private final Object value; // TextComponent, NBT, Entity, Achievement Id
|
||||
|
||||
public HoverEvent(JsonObject json) {
|
||||
this.action = HoverEventActions.valueOf(json.get("action").getAsString().toUpperCase());
|
||||
JsonElement data = null;
|
||||
if (json.has("value")) {
|
||||
data = json.get("value");
|
||||
}
|
||||
if (json.has("contents")) {
|
||||
data = json.get("contents");
|
||||
}
|
||||
json.get("value");
|
||||
this.value = switch (this.action) { // ToDo
|
||||
case SHOW_TEXT -> ChatComponent.Companion.of(data);
|
||||
case SHOW_ENTITY -> EntityHoverData.deserialize(data);
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
public HoverEvent(HoverEventActions action, Object value) {
|
||||
this.action = action;
|
||||
if (!(value instanceof ChatComponent) && !(value instanceof EntityHoverData)) {
|
||||
throw new IllegalArgumentException(String.format("%s is not a valid value hier", value.getClass().getSimpleName()));
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public enum HoverEventActions {
|
||||
SHOW_TEXT,
|
||||
SHOW_ITEM,
|
||||
SHOW_ENTITY,
|
||||
SHOW_ACHIEVEMENT
|
||||
}
|
||||
|
||||
public static final class EntityHoverData {
|
||||
private final UUID uuid;
|
||||
private final ResourceLocation resourceLocation;
|
||||
private final ChatComponent name;
|
||||
|
||||
public EntityHoverData(UUID uuid, ResourceLocation resourceLocation, ChatComponent name) {
|
||||
this.uuid = uuid;
|
||||
this.resourceLocation = resourceLocation;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static EntityHoverData deserialize(JsonElement data) {
|
||||
JsonObject json;
|
||||
if (data instanceof JsonPrimitive) {
|
||||
json = JsonParser.parseString(data.getAsString()).getAsJsonObject();
|
||||
} else {
|
||||
json = (JsonObject) data;
|
||||
}
|
||||
if (json.has("text")) {
|
||||
// 1.14.3.... lol
|
||||
json = JsonParser.parseString(json.get("text").getAsString()).getAsJsonObject();
|
||||
}
|
||||
ResourceLocation type = null;
|
||||
if (json.has("type")) {
|
||||
type = new ResourceLocation(json.get("type").getAsString());
|
||||
}
|
||||
return new EntityHoverData(Util.getUUIDFromString(json.get("id").getAsString()), type, ChatComponent.Companion.of(json.get("name")));
|
||||
}
|
||||
|
||||
public UUID uuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public ResourceLocation resourceLocation() {
|
||||
return this.resourceLocation;
|
||||
}
|
||||
|
||||
public ChatComponent name() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,9 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.data.text
|
||||
|
||||
import de.bixilon.minosoft.data.text.events.ClickEvent
|
||||
import de.bixilon.minosoft.data.text.events.HoverEvent
|
||||
|
||||
class MultiChatComponent(
|
||||
message: String = "",
|
||||
color: RGBColor? = null,
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.text.events
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.enum.ValuesEnum
|
||||
|
||||
class ClickEvent {
|
||||
val action: ClickEventActions
|
||||
val value: Any
|
||||
|
||||
constructor(json: JsonObject) {
|
||||
action = ClickEventActions[json["action"].asString.lowercase()]
|
||||
val primitive = json["value"].asJsonPrimitive
|
||||
value = if (primitive.isNumber) {
|
||||
primitive.asNumber
|
||||
} else {
|
||||
primitive.asString
|
||||
}
|
||||
}
|
||||
|
||||
constructor(action: ClickEventActions, value: Any) {
|
||||
this.action = action
|
||||
this.value = value
|
||||
}
|
||||
|
||||
enum class ClickEventActions {
|
||||
OPEN_URL,
|
||||
RUN_COMMAND,
|
||||
SUGGEST_COMMAND,
|
||||
CHANGE_PAGE,
|
||||
;
|
||||
|
||||
companion object : ValuesEnum<ClickEventActions> {
|
||||
override val VALUES: Array<ClickEventActions> = values()
|
||||
override val NAME_MAP: Map<String, ClickEventActions> = KUtil.getEnumValues(VALUES)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.text.events
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.data.text.events.data.EntityHoverData
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.enum.ValuesEnum
|
||||
import java.util.*
|
||||
|
||||
class HoverEvent {
|
||||
val action: HoverEventActions
|
||||
val value: Any
|
||||
|
||||
constructor(json: JsonObject) {
|
||||
action = HoverEventActions.valueOf(json["action"].asString.uppercase(Locale.getDefault()))
|
||||
var data: JsonElement = json
|
||||
json["value"]?.let {
|
||||
data = it
|
||||
}
|
||||
json["contents"]?.let {
|
||||
data = it
|
||||
}
|
||||
this.value = when (action) {
|
||||
HoverEventActions.SHOW_TEXT -> ChatComponent.of(data)
|
||||
HoverEventActions.SHOW_ENTITY -> EntityHoverData.deserialize(data)
|
||||
else -> TODO("Don't know what todo with $action: $data")
|
||||
}
|
||||
}
|
||||
|
||||
constructor(action: HoverEventActions, value: Any) {
|
||||
this.action = action
|
||||
this.value = value
|
||||
}
|
||||
|
||||
enum class HoverEventActions {
|
||||
SHOW_TEXT,
|
||||
SHOW_ITEM,
|
||||
SHOW_ENTITY,
|
||||
SHOW_ACHIEVEMENT,
|
||||
;
|
||||
|
||||
companion object : ValuesEnum<HoverEventActions> {
|
||||
override val VALUES: Array<HoverEventActions> = values()
|
||||
override val NAME_MAP: Map<String, HoverEventActions> = KUtil.getEnumValues(VALUES)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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.text.events.data
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import com.google.gson.JsonPrimitive
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.asUUID
|
||||
import java.util.*
|
||||
|
||||
class EntityHoverData(
|
||||
val uuid: UUID,
|
||||
val resourceLocation: ResourceLocation?,
|
||||
val name: ChatComponent,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
fun deserialize(data: JsonElement): EntityHoverData {
|
||||
var json = if (data is JsonPrimitive) {
|
||||
JsonParser.parseString(data.getAsString()).asJsonObject
|
||||
} else {
|
||||
data as JsonObject
|
||||
}
|
||||
json["text"]?.let {
|
||||
// 1.14.3.... lol
|
||||
json = JsonParser.parseString(json["text"].asString).asJsonObject
|
||||
}
|
||||
var type: ResourceLocation? = null
|
||||
json["type"]?.asString?.let {
|
||||
type = it.asResourceLocation()
|
||||
}
|
||||
|
||||
return EntityHoverData(json["id"].asString.asUUID(), type, ChatComponent.of(json["name"]))
|
||||
}
|
||||
}
|
||||
}
|
@ -13,11 +13,11 @@
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.config.StaticConfiguration
|
||||
import de.bixilon.minosoft.data.PlayerPropertyData
|
||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
|
||||
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
|
||||
import de.bixilon.minosoft.data.entities.meta.EntityMetaData
|
||||
import de.bixilon.minosoft.data.player.PlayerProperty
|
||||
import de.bixilon.minosoft.modding.event.events.EntitySpawnEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
@ -39,13 +39,14 @@ class PlayerEntitySpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
entityId = buffer.readVarInt()
|
||||
var name = "TBA"
|
||||
|
||||
val properties: MutableSet<PlayerPropertyData?> = mutableSetOf()
|
||||
val properties: MutableMap<String, PlayerProperty> = mutableMapOf()
|
||||
if (buffer.versionId < ProtocolVersions.V_14W21A) {
|
||||
name = buffer.readString()
|
||||
entityUUID = Util.getUUIDFromString(buffer.readString())
|
||||
val length = buffer.readVarInt()
|
||||
for (i in 0 until length) {
|
||||
properties.add(PlayerPropertyData(buffer.readString(), buffer.readString(), buffer.readString()))
|
||||
val property = PlayerProperty(buffer.readString(), buffer.readString(), buffer.readString())
|
||||
properties[property.key] = property
|
||||
}
|
||||
} else {
|
||||
entityUUID = buffer.readUUID()
|
||||
@ -73,7 +74,7 @@ class PlayerEntitySpawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
position = position,
|
||||
rotation = EntityRotation(yaw.toFloat(), pitch.toFloat(), 0.0f),
|
||||
name = name,
|
||||
// ToDo: properties = properties,
|
||||
properties = properties,
|
||||
)
|
||||
|
||||
if (metaData != null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user