mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-21 17:45:36 +01:00
Start work on ViaVersion 5.0.0
Bump Java target to 17, clean up using its new language features Remove unnecessary checked exception throwing Remove deprecated code
This commit is contained in:
parent
2d41eb52a6
commit
75db1a7cdf
@ -73,6 +73,8 @@ Building
|
||||
After cloning this repository, build the project with Gradle by running `./gradlew build` and take the created jar out
|
||||
of the `build/libs` directory.
|
||||
|
||||
You need JDK 17 or newer to build ViaVersion.
|
||||
|
||||
|
||||
Mapping Files
|
||||
--------------
|
||||
|
@ -1,3 +0,0 @@
|
||||
dependencies {
|
||||
compileOnly(projects.viaversionApi)
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
import us.myles.ViaVersion.api.boss.BossBar;
|
||||
import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
|
||||
/**
|
||||
* @deprecated may be removed at some point, use {@link com.viaversion.viaversion.api.Via}
|
||||
*/
|
||||
@Deprecated
|
||||
public class Via<T> implements ViaAPI<T> {
|
||||
|
||||
private static final ViaAPI INSTANCE = new Via();
|
||||
|
||||
private Via() {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ViaAPI getAPI() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(T player) {
|
||||
return com.viaversion.viaversion.api.Via.getAPI().getPlayerVersion(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
return com.viaversion.viaversion.api.Via.getAPI().getPlayerVersion(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return com.viaversion.viaversion.api.Via.getAPI().isInjected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return com.viaversion.viaversion.api.Via.getAPI().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(T player, ByteBuf packet) {
|
||||
com.viaversion.viaversion.api.Via.getAPI().sendRawPacket(player, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) {
|
||||
com.viaversion.viaversion.api.Via.getAPI().sendRawPacket(uuid, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar createBossBar(String title, BossColor color, BossStyle style) {
|
||||
return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title,
|
||||
com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()],
|
||||
com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) {
|
||||
return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title, health,
|
||||
com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()],
|
||||
com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Integer> getSupportedVersions() {
|
||||
return com.viaversion.viaversion.api.Via.getAPI().getSupportedVersions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Integer> getFullSupportedVersions() {
|
||||
return com.viaversion.viaversion.api.Via.getAPI().getFullSupportedVersions();
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.SortedSet;
|
||||
import java.util.UUID;
|
||||
import us.myles.ViaVersion.api.boss.BossBar;
|
||||
import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
|
||||
/**
|
||||
* @deprecated may be removed at some point, use {@link Via#getAPI()}
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ViaAPI<T> {
|
||||
|
||||
int getPlayerVersion(T player);
|
||||
|
||||
int getPlayerVersion(UUID uuid);
|
||||
|
||||
default boolean isPorted(UUID playerUUID) {
|
||||
return isInjected(playerUUID);
|
||||
}
|
||||
|
||||
boolean isInjected(UUID playerUUID);
|
||||
|
||||
String getVersion();
|
||||
|
||||
void sendRawPacket(T player, ByteBuf packet);
|
||||
|
||||
void sendRawPacket(UUID uuid, ByteBuf packet);
|
||||
|
||||
BossBar createBossBar(String title, BossColor color, BossStyle style);
|
||||
|
||||
BossBar createBossBar(String title, float health, BossColor color, BossStyle style);
|
||||
|
||||
SortedSet<Integer> getSupportedVersions();
|
||||
|
||||
SortedSet<Integer> getFullSupportedVersions();
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api.boss;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Deprecated
|
||||
public class BossBar<T> {
|
||||
|
||||
private final com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar;
|
||||
|
||||
public BossBar(com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar) {
|
||||
this.bossBar = bossBar;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return bossBar.getTitle();
|
||||
}
|
||||
|
||||
public BossBar setTitle(String title) {
|
||||
bossBar.setTitle(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return bossBar.getHealth();
|
||||
}
|
||||
|
||||
public BossBar setHealth(float health) {
|
||||
bossBar.setHealth(health);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossColor getColor() {
|
||||
return BossColor.values()[bossBar.getColor().ordinal()];
|
||||
}
|
||||
|
||||
public BossBar setColor(BossColor color) {
|
||||
bossBar.setColor(com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossStyle getStyle() {
|
||||
return BossStyle.values()[bossBar.getStyle().ordinal()];
|
||||
}
|
||||
|
||||
public BossBar setStyle(BossStyle style) {
|
||||
bossBar.setStyle(com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()]);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BossBar addPlayer(T player) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossBar addPlayer(UUID player) {
|
||||
bossBar.addPlayer(player);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BossBar addPlayers(T... players) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BossBar removePlayer(T player) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossBar removePlayer(UUID uuid) {
|
||||
bossBar.removePlayer(uuid);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossBar addFlag(BossFlag flag) {
|
||||
bossBar.addFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossBar removeFlag(BossFlag flag) {
|
||||
bossBar.removeFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasFlag(BossFlag flag) {
|
||||
return bossBar.hasFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]);
|
||||
}
|
||||
|
||||
public Set<UUID> getPlayers() {
|
||||
return bossBar.getPlayers();
|
||||
}
|
||||
|
||||
public BossBar show() {
|
||||
bossBar.show();
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossBar hide() {
|
||||
bossBar.hide();
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return bossBar.isVisible();
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return bossBar.getId();
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api.boss;
|
||||
|
||||
@Deprecated
|
||||
public enum BossColor {
|
||||
|
||||
PINK(0),
|
||||
BLUE(1),
|
||||
RED(2),
|
||||
GREEN(3),
|
||||
YELLOW(4),
|
||||
PURPLE(5),
|
||||
WHITE(6);
|
||||
|
||||
private final int id;
|
||||
|
||||
BossColor(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api.boss;
|
||||
|
||||
@Deprecated
|
||||
public enum BossFlag {
|
||||
|
||||
DARKEN_SKY(1),
|
||||
PLAY_BOSS_MUSIC(2);
|
||||
|
||||
private final int id;
|
||||
|
||||
BossFlag(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api.boss;
|
||||
|
||||
@Deprecated
|
||||
public enum BossStyle {
|
||||
|
||||
SOLID(0),
|
||||
SEGMENTED_6(1),
|
||||
SEGMENTED_10(2),
|
||||
SEGMENTED_12(3),
|
||||
SEGMENTED_20(4);
|
||||
|
||||
private final int id;
|
||||
|
||||
BossStyle(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
/**
|
||||
* @deprecated may be removed at some point, use {@link com.viaversion.viaversion.api.protocol.ProtocolManager}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ProtocolRegistry {
|
||||
|
||||
@Deprecated
|
||||
public static int SERVER_PROTOCOL = -1;
|
||||
}
|
@ -1,255 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.protocol.version.SubVersionRange;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* @deprecated will no longer be updated and may be removed at some point, use {@link com.viaversion.viaversion.api.protocol.version.ProtocolVersion}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ProtocolVersion {
|
||||
private static final Int2ObjectMap<ProtocolVersion> versions = new Int2ObjectOpenHashMap<>();
|
||||
private static final List<ProtocolVersion> versionList = new ArrayList<>();
|
||||
|
||||
public static final ProtocolVersion v1_4_6 = register(51, "1.4.6/7", new SubVersionRange("1.4", 6, 7));
|
||||
public static final ProtocolVersion v1_5_1 = register(60, "1.5.1");
|
||||
public static final ProtocolVersion v1_5_2 = register(61, "1.5.2");
|
||||
public static final ProtocolVersion v_1_6_1 = register(73, "1.6.1");
|
||||
public static final ProtocolVersion v_1_6_2 = register(74, "1.6.2");
|
||||
public static final ProtocolVersion v_1_6_3 = register(77, "1.6.3");
|
||||
public static final ProtocolVersion v_1_6_4 = register(78, "1.6.4");
|
||||
public static final ProtocolVersion v1_7_1 = register(4, "1.7-1.7.5", new SubVersionRange("1.7", 0, 5));
|
||||
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new SubVersionRange("1.7", 6, 10));
|
||||
public static final ProtocolVersion v1_8 = register(47, "1.8.x");
|
||||
public static final ProtocolVersion v1_9 = register(107, "1.9");
|
||||
public static final ProtocolVersion v1_9_1 = register(108, "1.9.1");
|
||||
public static final ProtocolVersion v1_9_2 = register(109, "1.9.2");
|
||||
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/1.9.4", new SubVersionRange("1.9", 3, 4));
|
||||
public static final ProtocolVersion v1_10 = register(210, "1.10.x");
|
||||
public static final ProtocolVersion v1_11 = register(315, "1.11");
|
||||
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1/1.11.2", new SubVersionRange("1.11", 1, 2));
|
||||
public static final ProtocolVersion v1_12 = register(335, "1.12");
|
||||
public static final ProtocolVersion v1_12_1 = register(338, "1.12.1");
|
||||
public static final ProtocolVersion v1_12_2 = register(340, "1.12.2");
|
||||
public static final ProtocolVersion v1_13 = register(393, "1.13");
|
||||
public static final ProtocolVersion v1_13_1 = register(401, "1.13.1");
|
||||
public static final ProtocolVersion v1_13_2 = register(404, "1.13.2");
|
||||
public static final ProtocolVersion v1_14 = register(477, "1.14");
|
||||
public static final ProtocolVersion v1_14_1 = register(480, "1.14.1");
|
||||
public static final ProtocolVersion v1_14_2 = register(485, "1.14.2");
|
||||
public static final ProtocolVersion v1_14_3 = register(490, "1.14.3");
|
||||
public static final ProtocolVersion v1_14_4 = register(498, "1.14.4");
|
||||
public static final ProtocolVersion v1_15 = register(573, "1.15");
|
||||
public static final ProtocolVersion v1_15_1 = register(575, "1.15.1");
|
||||
public static final ProtocolVersion v1_15_2 = register(578, "1.15.2");
|
||||
public static final ProtocolVersion v1_16 = register(735, "1.16");
|
||||
public static final ProtocolVersion v1_16_1 = register(736, "1.16.1");
|
||||
public static final ProtocolVersion v1_16_2 = register(751, "1.16.2");
|
||||
public static final ProtocolVersion v1_16_3 = register(753, "1.16.3");
|
||||
public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/1.16.5", new SubVersionRange("1.16", 4, 5));
|
||||
public static final ProtocolVersion v1_17 = register(755, "1.17");
|
||||
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new SubVersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
|
||||
public static final ProtocolVersion v1_19 = register(759, "1.19");
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/1.19.2", new SubVersionRange("1.19", 1, 2));
|
||||
public static final ProtocolVersion v1_19_3 = register(761, "1.19.3");
|
||||
public static final ProtocolVersion v1_19_4 = register(762, "1.19.4");
|
||||
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new SubVersionRange("1.20", 0, 1));
|
||||
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
|
||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4));
|
||||
public static final ProtocolVersion v1_20_5 = register(766, "1.20.5");
|
||||
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
return register(version, -1, name);
|
||||
}
|
||||
|
||||
public static ProtocolVersion register(int version, int snapshotVersion, String name) {
|
||||
return register(version, snapshotVersion, name, null);
|
||||
}
|
||||
|
||||
public static ProtocolVersion register(int version, String name, @Nullable SubVersionRange versionRange) {
|
||||
return register(version, -1, name, versionRange);
|
||||
}
|
||||
|
||||
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
|
||||
ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name, versionRange);
|
||||
versionList.add(protocol);
|
||||
versions.put(protocol.getVersion(), protocol);
|
||||
if (protocol.isSnapshot()) {
|
||||
versions.put(protocol.getFullSnapshotVersion(), protocol);
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public static boolean isRegistered(int id) {
|
||||
return versions.containsKey(id);
|
||||
}
|
||||
|
||||
public static @NonNull ProtocolVersion getProtocol(int id) {
|
||||
ProtocolVersion protocolVersion = versions.get(id);
|
||||
if (protocolVersion != null) {
|
||||
return protocolVersion;
|
||||
} else {
|
||||
return new ProtocolVersion(id, "Unknown (" + id + ")");
|
||||
}
|
||||
}
|
||||
|
||||
public static int getIndex(ProtocolVersion version) {
|
||||
return versionList.indexOf(version);
|
||||
}
|
||||
|
||||
public static List<ProtocolVersion> getProtocols() {
|
||||
return Collections.unmodifiableList(new ArrayList<>(versions.values()));
|
||||
}
|
||||
|
||||
public static @Nullable ProtocolVersion getClosest(String protocol) {
|
||||
for (ProtocolVersion version : versions.values()) {
|
||||
String name = version.getName();
|
||||
if (name.equals(protocol)) {
|
||||
return version;
|
||||
}
|
||||
|
||||
if (version.isVersionWildcard()) {
|
||||
// Test against the major version with and without a minor version
|
||||
String majorVersion = name.substring(0, name.length() - 2);
|
||||
if (majorVersion.equals(protocol) || (protocol.startsWith(name.substring(0, name.length() - 1)))) {
|
||||
return version;
|
||||
}
|
||||
} else if (version.isRange()) {
|
||||
if (version.getIncludedVersions().contains(protocol)) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final int version;
|
||||
private final int snapshotVersion;
|
||||
private final String name;
|
||||
private final boolean versionWildcard;
|
||||
private final Set<String> includedVersions;
|
||||
|
||||
public ProtocolVersion(int version, String name) {
|
||||
this(version, -1, name, null);
|
||||
}
|
||||
|
||||
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
|
||||
this.version = version;
|
||||
this.snapshotVersion = snapshotVersion;
|
||||
this.name = name;
|
||||
this.versionWildcard = name.endsWith(".x");
|
||||
|
||||
Preconditions.checkArgument(!versionWildcard || versionRange == null, "A version cannot be a wildcard and a range at the same time!");
|
||||
if (versionRange != null) {
|
||||
includedVersions = new LinkedHashSet<>();
|
||||
for (int i = versionRange.rangeFrom(); i <= versionRange.rangeTo(); i++) {
|
||||
if (i == 0) {
|
||||
includedVersions.add(versionRange.baseVersion()); // Keep both the base version and with ".0" appended
|
||||
}
|
||||
|
||||
includedVersions.add(versionRange.baseVersion() + "." + i);
|
||||
}
|
||||
} else {
|
||||
includedVersions = Collections.singleton(name);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public int getSnapshotVersion() {
|
||||
Preconditions.checkArgument(isSnapshot());
|
||||
return snapshotVersion;
|
||||
}
|
||||
|
||||
public int getFullSnapshotVersion() {
|
||||
Preconditions.checkArgument(isSnapshot());
|
||||
return (1 << 30) | snapshotVersion; // Bit indicating snapshot versions
|
||||
}
|
||||
|
||||
public int getOriginalVersion() {
|
||||
return snapshotVersion == -1 ? version : ((1 << 30) | snapshotVersion);
|
||||
}
|
||||
|
||||
public boolean isKnown() {
|
||||
return version != -1;
|
||||
}
|
||||
|
||||
public boolean isRange() {
|
||||
return includedVersions.size() != 1;
|
||||
}
|
||||
|
||||
public Set<String> getIncludedVersions() {
|
||||
return Collections.unmodifiableSet(includedVersions);
|
||||
}
|
||||
|
||||
public boolean isVersionWildcard() {
|
||||
return versionWildcard;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isSnapshot() {
|
||||
return snapshotVersion != -1;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ProtocolVersion that = (ProtocolVersion) o;
|
||||
return version == that.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s (%d)", this.name, this.version);
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ public interface ViaAPI<T> {
|
||||
* @since 4.0.2
|
||||
*/
|
||||
default int majorVersion() {
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,21 +26,21 @@ import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ViaSubCommand {
|
||||
public interface ViaSubCommand {
|
||||
|
||||
/**
|
||||
* Subcommand name
|
||||
*
|
||||
* @return The commands name
|
||||
*/
|
||||
public abstract String name();
|
||||
String name();
|
||||
|
||||
/**
|
||||
* subcommand description, this'll show in /viaversion list
|
||||
*
|
||||
* @return The commands description
|
||||
*/
|
||||
public abstract String description();
|
||||
String description();
|
||||
|
||||
/**
|
||||
* Usage example:
|
||||
@ -48,7 +48,7 @@ public abstract class ViaSubCommand {
|
||||
*
|
||||
* @return The commands usage
|
||||
*/
|
||||
public String usage() {
|
||||
default String usage() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ public abstract class ViaSubCommand {
|
||||
*
|
||||
* @return The permission required to use the commands
|
||||
*/
|
||||
public String permission() {
|
||||
default String permission() {
|
||||
return "viaversion.admin." + name();
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public abstract class ViaSubCommand {
|
||||
* @param args Arguments
|
||||
* @return commands executed succesfully if false, show usage
|
||||
*/
|
||||
public abstract boolean execute(ViaCommandSender sender, String[] args);
|
||||
boolean execute(ViaCommandSender sender, String[] args);
|
||||
|
||||
/**
|
||||
* Yay, possibility to implement tab-completion
|
||||
@ -77,7 +77,7 @@ public abstract class ViaSubCommand {
|
||||
* @param args args
|
||||
* @return tab complete possibilities
|
||||
*/
|
||||
public List<String> onTabComplete(ViaCommandSender sender, String[] args) {
|
||||
default List<String> onTabComplete(ViaCommandSender sender, String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ public abstract class ViaSubCommand {
|
||||
* @param s string to replace
|
||||
* @return output String
|
||||
*/
|
||||
public static String color(String s) {
|
||||
static String color(String s) {
|
||||
return ChatColorUtil.translateAlternateColorCodes(s);
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ public abstract class ViaSubCommand {
|
||||
* @param message message
|
||||
* @param args objects to replace
|
||||
*/
|
||||
public static void sendMessage(ViaCommandSender sender, String message, Object... args) {
|
||||
default void sendMessage(ViaCommandSender sender, String message, Object... args) {
|
||||
sender.sendMessage(color(args == null ? message : String.format(message, args)));
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public interface ViaVersionCommand {
|
||||
* Register your own subcommand inside ViaVersion
|
||||
*
|
||||
* @param command Your own SubCommand instance to handle it.
|
||||
* @throws Exception throws an exception when the subcommand already exists or if it's not valid, example: spacee
|
||||
* @throws IllegalArgumentException throws an exception when the subcommand already exists or if it's not valid, example: spacee
|
||||
*/
|
||||
void registerSubCommand(ViaSubCommand command);
|
||||
|
||||
|
@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
|
||||
import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ViaVersionConfig extends Config {
|
||||
|
||||
|
@ -31,17 +31,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ProtocolInfo {
|
||||
|
||||
/**
|
||||
* Returns the protocol state the user is currently in.
|
||||
*
|
||||
* @return protocol state
|
||||
* @deprecated server and client can be in different states, use {@link #getClientState()} or {@link #getServerState()}
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default State getState() {
|
||||
return this.getServerState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol state the client is currently in.
|
||||
*
|
||||
@ -153,12 +142,4 @@ public interface ProtocolInfo {
|
||||
ProtocolPipeline getPipeline();
|
||||
|
||||
void setPipeline(ProtocolPipeline pipeline);
|
||||
|
||||
/**
|
||||
* Returns the user connection this info represents.
|
||||
*
|
||||
* @return user connection
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
UserConnection getUser();
|
||||
}
|
||||
}
|
@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketTracker;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.handler.codec.CodecException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -205,11 +205,10 @@ public interface UserConnection {
|
||||
*
|
||||
* @param buf ByteBuf with packet id and packet contents
|
||||
* @param cancelSupplier function called with original CancelException for generating the Exception when the packet is cancelled
|
||||
* @throws CancelException if the packet should be cancelled
|
||||
* @throws CodecException if the packet should be cancelled (by netty)
|
||||
* @throws InformativeException if packet transforming failed
|
||||
* @throws Exception if any other processing outside of transforming fails
|
||||
*/
|
||||
void transformClientbound(ByteBuf buf, Function<Throwable, Exception> cancelSupplier) throws Exception;
|
||||
void transformClientbound(ByteBuf buf, Function<Throwable, CodecException> cancelSupplier) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Transforms the serverbound packet contained in ByteBuf.
|
||||
@ -217,11 +216,10 @@ public interface UserConnection {
|
||||
* @param buf ByteBuf with packet id and packet contents
|
||||
* @param cancelSupplier Function called with original CancelException for generating the Exception used when
|
||||
* packet is cancelled
|
||||
* @throws CancelException if the packet should be cancelled
|
||||
* @throws CodecException if the packet should be cancelled (by netty)
|
||||
* @throws InformativeException if packet transforming failed
|
||||
* @throws Exception if any other processing outside of transforming fails
|
||||
*/
|
||||
void transformServerbound(ByteBuf buf, Function<Throwable, Exception> cancelSupplier) throws Exception;
|
||||
void transformServerbound(ByteBuf buf, Function<Throwable, CodecException> cancelSupplier) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Transforms the packet depending on whether the connection is clientside or not.
|
||||
@ -229,7 +227,7 @@ public interface UserConnection {
|
||||
* @see #transformClientbound(ByteBuf, Function)
|
||||
* @see #transformServerbound(ByteBuf, Function)
|
||||
*/
|
||||
default void transformOutgoing(ByteBuf buf, Function<Throwable, Exception> cancelSupplier) throws Exception {
|
||||
default void transformOutgoing(ByteBuf buf, Function<Throwable, CodecException> cancelSupplier) throws InformativeException {
|
||||
if (isClientSide()) {
|
||||
transformServerbound(buf, cancelSupplier);
|
||||
} else {
|
||||
@ -243,7 +241,7 @@ public interface UserConnection {
|
||||
* @see #transformClientbound(ByteBuf, Function)
|
||||
* @see #transformServerbound(ByteBuf, Function)
|
||||
*/
|
||||
default void transformIncoming(ByteBuf buf, Function<Throwable, Exception> cancelSupplier) throws Exception {
|
||||
default void transformIncoming(ByteBuf buf, Function<Throwable, CodecException> cancelSupplier) throws InformativeException {
|
||||
if (isClientSide()) {
|
||||
transformClientbound(buf, cancelSupplier);
|
||||
} else {
|
||||
@ -315,20 +313,6 @@ public interface UserConnection {
|
||||
*/
|
||||
boolean shouldApplyBlockProtocol();
|
||||
|
||||
/**
|
||||
* Returns whether the packet limiter applies to this user.
|
||||
*
|
||||
* @return whether the packet limiter applies to this user
|
||||
*/
|
||||
boolean isPacketLimiterEnabled();
|
||||
|
||||
/**
|
||||
* Sets the status of the packet limiter.
|
||||
*
|
||||
* @param packetLimiterEnabled whether the packet limiter should be enabled
|
||||
*/
|
||||
void setPacketLimiterEnabled(boolean packetLimiterEnabled);
|
||||
|
||||
/**
|
||||
* Returns a newly generated uuid that will let a packet be passed through without
|
||||
* transformig its contents if used together with {@link PacketWrapper#PASSTHROUGH_ID}.
|
||||
|
@ -22,15 +22,7 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
public class IdentityMappings implements Mappings {
|
||||
|
||||
private final int size;
|
||||
private final int mappedSize;
|
||||
|
||||
public IdentityMappings(final int size, final int mappedSize) {
|
||||
this.size = size;
|
||||
this.mappedSize = mappedSize;
|
||||
}
|
||||
public record IdentityMappings(int size, int mappedSize) implements Mappings {
|
||||
|
||||
@Override
|
||||
public int getNewId(final int id) {
|
||||
@ -42,16 +34,6 @@ public class IdentityMappings implements Mappings {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int mappedSize() {
|
||||
return mappedSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mappings inverse() {
|
||||
return new IdentityMappings(mappedSize, size);
|
||||
|
@ -29,7 +29,6 @@ import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Beta
|
||||
public interface DebugHandler {
|
||||
|
||||
/**
|
||||
@ -51,6 +50,7 @@ public interface DebugHandler {
|
||||
*
|
||||
* @param packetTypeName packet type name
|
||||
*/
|
||||
@Beta
|
||||
void addPacketTypeNameToLog(String packetTypeName);
|
||||
|
||||
/**
|
||||
@ -59,6 +59,7 @@ public interface DebugHandler {
|
||||
*
|
||||
* @param packetType packet type
|
||||
*/
|
||||
@Beta
|
||||
void addPacketTypeToLog(PacketType packetType);
|
||||
|
||||
/**
|
||||
@ -66,11 +67,13 @@ public interface DebugHandler {
|
||||
*
|
||||
* @param packetTypeName packet type name
|
||||
*/
|
||||
@Beta
|
||||
boolean removePacketTypeNameToLog(String packetTypeName);
|
||||
|
||||
/**
|
||||
* Resets packet type filters.
|
||||
*/
|
||||
@Beta
|
||||
void clearPacketTypesToLog();
|
||||
|
||||
/**
|
||||
@ -79,6 +82,7 @@ public interface DebugHandler {
|
||||
*
|
||||
* @return whether packets should be logged after being transformed
|
||||
*/
|
||||
@Beta
|
||||
boolean logPostPacketTransform();
|
||||
|
||||
/**
|
||||
@ -86,6 +90,7 @@ public interface DebugHandler {
|
||||
*
|
||||
* @param logPostPacketTransform whether packets should be logged after being transformed
|
||||
*/
|
||||
@Beta
|
||||
void setLogPostPacketTransform(boolean logPostPacketTransform);
|
||||
|
||||
/**
|
||||
@ -98,6 +103,7 @@ public interface DebugHandler {
|
||||
*/
|
||||
boolean shouldLog(PacketWrapper wrapper, Direction direction);
|
||||
|
||||
@Beta
|
||||
default void enableAndLogIds(final PacketType... packetTypes) {
|
||||
setEnabled(true);
|
||||
for (final PacketType packetType : packetTypes) {
|
||||
|
@ -34,7 +34,6 @@ public enum BlockFace {
|
||||
BOTTOM((byte) 0, (byte) -1, (byte) 0, EnumAxis.Y);
|
||||
|
||||
public static final BlockFace[] HORIZONTAL = {NORTH, SOUTH, EAST, WEST};
|
||||
|
||||
private static final Map<BlockFace, BlockFace> opposites = new EnumMap<>(BlockFace.class);
|
||||
|
||||
static {
|
||||
@ -78,26 +77,6 @@ public enum BlockFace {
|
||||
return axis;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public byte getModX() {
|
||||
return modX;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public byte getModY() {
|
||||
return modY;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public byte getModZ() {
|
||||
return modZ;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public EnumAxis getAxis() {
|
||||
return axis;
|
||||
}
|
||||
|
||||
public enum EnumAxis {
|
||||
X, Y, Z
|
||||
}
|
||||
|
@ -38,20 +38,11 @@ public enum Environment {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Environment getEnvironmentById(int id) {
|
||||
switch (id) {
|
||||
default:
|
||||
case -1:
|
||||
return NETHER;
|
||||
case 0:
|
||||
return NORMAL;
|
||||
case 1:
|
||||
return END;
|
||||
}
|
||||
return switch (id) {
|
||||
case 0 -> NORMAL;
|
||||
case 1 -> END;
|
||||
default -> NETHER; // -1 implicitly
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -22,41 +22,5 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public class EulerAngle {
|
||||
private final float x;
|
||||
private final float y;
|
||||
private final float z;
|
||||
|
||||
public EulerAngle(final float x, final float y, final float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public float x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
public record EulerAngle(float x, float y, float z) {
|
||||
}
|
||||
|
@ -25,51 +25,8 @@ package com.viaversion.viaversion.api.minecraft;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class GameProfile {
|
||||
public record GameProfile(@Nullable String name, @Nullable UUID id, Property[] properties) {
|
||||
|
||||
private final String name;
|
||||
private final UUID id;
|
||||
private final Property[] properties;
|
||||
|
||||
public GameProfile(@Nullable final String name, @Nullable final UUID id, final Property[] properties) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public @Nullable String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public @Nullable UUID id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Property[] properties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static final class Property {
|
||||
private final String name;
|
||||
private final String value;
|
||||
private final String signature;
|
||||
|
||||
public Property(final String name, final String value, @Nullable final String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public @Nullable String signature() {
|
||||
return signature;
|
||||
}
|
||||
public record Property(String name, String value, @Nullable String signature) {
|
||||
}
|
||||
}
|
||||
|
@ -37,11 +37,6 @@ public final class Particle implements IdHolder {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id() {
|
||||
return id;
|
||||
@ -106,7 +101,7 @@ public final class Particle implements IdHolder {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void write(final ByteBuf buf) throws Exception {
|
||||
public void write(final ByteBuf buf) {
|
||||
type.write(buf, value);
|
||||
}
|
||||
|
||||
|
@ -24,20 +24,5 @@ package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PlayerMessageSignature {
|
||||
private final UUID uuid;
|
||||
private final byte[] signatureBytes;
|
||||
|
||||
public PlayerMessageSignature(final UUID uuid, final byte[] signatureBytes) {
|
||||
this.uuid = uuid;
|
||||
this.signatureBytes = signatureBytes;
|
||||
}
|
||||
|
||||
public UUID uuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public byte[] signatureBytes() {
|
||||
return signatureBytes;
|
||||
}
|
||||
public record PlayerMessageSignature(UUID uuid, byte[] signatureBytes) {
|
||||
}
|
||||
|
@ -38,11 +38,6 @@ public class Position {
|
||||
this(x, (int) y, z);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public Position(Position toCopy) {
|
||||
this(toCopy.x(), toCopy.y(), toCopy.z());
|
||||
}
|
||||
|
||||
public Position getRelative(BlockFace face) {
|
||||
return new Position(x + face.modX(), (short) (y + face.modY()), z + face.modZ());
|
||||
}
|
||||
@ -63,21 +58,6 @@ public class Position {
|
||||
return new GlobalPosition(dimension, x, y, z);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -22,26 +22,5 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public class Position3d {
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
public Position3d(final double x, final double y, final double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public double x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double z() {
|
||||
return z;
|
||||
}
|
||||
public record Position3d(double x, double y, double z) {
|
||||
}
|
||||
|
@ -22,26 +22,5 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public final class ProfileKey {
|
||||
private final long expiresAt;
|
||||
private final byte[] publicKey;
|
||||
private final byte[] keySignature;
|
||||
|
||||
public ProfileKey(final long expiresAt, final byte[] publicKey, final byte[] keySignature) {
|
||||
this.expiresAt = expiresAt;
|
||||
this.publicKey = publicKey;
|
||||
this.keySignature = keySignature;
|
||||
}
|
||||
|
||||
public long expiresAt() {
|
||||
return expiresAt;
|
||||
}
|
||||
|
||||
public byte[] publicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public byte[] keySignature() {
|
||||
return keySignature;
|
||||
}
|
||||
public record ProfileKey(long expiresAt, byte[] publicKey, byte[] keySignature) {
|
||||
}
|
||||
|
@ -22,42 +22,5 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public final class Quaternion {
|
||||
private final float x;
|
||||
private final float y;
|
||||
private final float z;
|
||||
private final float w;
|
||||
|
||||
public Quaternion(final float x, final float y, final float z, final float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public float x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public float w() {
|
||||
return w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Quaternion{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", z=" + z +
|
||||
", w=" + w +
|
||||
'}';
|
||||
}
|
||||
public record Quaternion(float x, float y, float z, float w) {
|
||||
}
|
||||
|
@ -25,22 +25,7 @@ package com.viaversion.viaversion.api.minecraft;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class RegistryEntry {
|
||||
private final String key;
|
||||
private final Tag tag;
|
||||
|
||||
public RegistryEntry(String key, @Nullable Tag tag) {
|
||||
this.key = key;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public @Nullable Tag tag() {
|
||||
return tag;
|
||||
}
|
||||
public record RegistryEntry(String key, @Nullable Tag tag) {
|
||||
|
||||
public RegistryEntry withKey(final String key) {
|
||||
return new RegistryEntry(key, tag != null ? tag.copy() : null);
|
||||
|
@ -24,23 +24,7 @@ package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class SoundEvent {
|
||||
|
||||
private final String identifier;
|
||||
private final Float fixedRange;
|
||||
|
||||
public SoundEvent(final String identifier, @Nullable final Float fixedRange) {
|
||||
this.identifier = identifier;
|
||||
this.fixedRange = fixedRange;
|
||||
}
|
||||
|
||||
public String identifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public @Nullable Float fixedRange() {
|
||||
return fixedRange;
|
||||
}
|
||||
public record SoundEvent(String identifier, @Nullable Float fixedRange) {
|
||||
|
||||
public SoundEvent withIdentifier(final String identifier) {
|
||||
return new SoundEvent(identifier, this.fixedRange);
|
||||
|
@ -24,28 +24,21 @@ package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class TagData {
|
||||
private final String identifier;
|
||||
private final int[] entries;
|
||||
public record TagData(String identifier, int[] entries) {
|
||||
|
||||
public TagData(final String identifier, final int[] entries) {
|
||||
this.identifier = identifier;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public String identifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public int[] entries() {
|
||||
return entries;
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final TagData tagData = (TagData) o;
|
||||
if (!identifier.equals(tagData.identifier)) return false;
|
||||
return Arrays.equals(entries, tagData.entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TagData{" +
|
||||
"identifier='" + identifier + '\'' +
|
||||
", entries=" + Arrays.toString(entries) +
|
||||
'}';
|
||||
public int hashCode() {
|
||||
int result = identifier.hashCode();
|
||||
result = 31 * result + Arrays.hashCode(entries);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -22,56 +22,5 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public class Vector {
|
||||
private int blockX;
|
||||
private int blockY;
|
||||
private int blockZ;
|
||||
|
||||
public Vector(int blockX, int blockY, int blockZ) {
|
||||
this.blockX = blockX;
|
||||
this.blockY = blockY;
|
||||
this.blockZ = blockZ;
|
||||
}
|
||||
|
||||
public int blockX() {
|
||||
return blockX;
|
||||
}
|
||||
|
||||
public int blockY() {
|
||||
return blockY;
|
||||
}
|
||||
|
||||
public int blockZ() {
|
||||
return blockZ;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getBlockX() {
|
||||
return blockX;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getBlockY() {
|
||||
return blockY;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getBlockZ() {
|
||||
return blockZ;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public void setBlockX(int blockX) {
|
||||
this.blockX = blockX;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public void setBlockY(int blockY) {
|
||||
this.blockY = blockY;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public void setBlockZ(int blockZ) {
|
||||
this.blockZ = blockZ;
|
||||
}
|
||||
public record Vector(int blockX, int blockY, int blockZ) {
|
||||
}
|
||||
|
@ -22,26 +22,5 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public final class Vector3f {
|
||||
private final float x;
|
||||
private final float y;
|
||||
private final float z;
|
||||
|
||||
public Vector3f(final float x, final float y, final float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public float x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float z() {
|
||||
return z;
|
||||
}
|
||||
public record Vector3f(float x, float y, float z) {
|
||||
}
|
||||
|
@ -22,41 +22,5 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
public class VillagerData {
|
||||
private final int type;
|
||||
private final int profession;
|
||||
private final int level;
|
||||
|
||||
public VillagerData(final int type, final int profession, final int level) {
|
||||
this.type = type;
|
||||
this.profession = profession;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int profession() {
|
||||
return profession;
|
||||
}
|
||||
|
||||
public int level() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getProfession() {
|
||||
return profession;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
public record VillagerData(int type, int profession, int level) {
|
||||
}
|
||||
|
@ -24,34 +24,12 @@ package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public class WorldIdentifiers implements StorableObject {
|
||||
public record WorldIdentifiers(String overworld, String nether, String end) implements StorableObject {
|
||||
public static final String OVERWORLD_DEFAULT = "minecraft:overworld";
|
||||
public static final String NETHER_DEFAULT = "minecraft:the_nether";
|
||||
public static final String END_DEFAULT = "minecraft:the_end";
|
||||
|
||||
private final String overworld;
|
||||
private final String nether;
|
||||
private final String end;
|
||||
|
||||
public WorldIdentifiers(String overworld) {
|
||||
this(overworld, NETHER_DEFAULT, END_DEFAULT);
|
||||
}
|
||||
|
||||
public WorldIdentifiers(String overworld, String nether, String end) {
|
||||
this.overworld = overworld;
|
||||
this.nether = nether;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public String overworld() {
|
||||
return this.overworld;
|
||||
}
|
||||
|
||||
public String nether() {
|
||||
return this.nether;
|
||||
}
|
||||
|
||||
public String end() {
|
||||
return this.end;
|
||||
}
|
||||
}
|
||||
|
@ -24,38 +24,7 @@ package com.viaversion.viaversion.api.minecraft.blockentity;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
|
||||
public final class BlockEntityImpl implements BlockEntity {
|
||||
private final byte packedXZ;
|
||||
private final short y;
|
||||
private final int typeId;
|
||||
private final CompoundTag tag;
|
||||
|
||||
public BlockEntityImpl(final byte packedXZ, final short y, final int typeId, final CompoundTag tag) {
|
||||
this.packedXZ = packedXZ;
|
||||
this.y = y;
|
||||
this.typeId = typeId;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte packedXZ() {
|
||||
return packedXZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag tag() {
|
||||
return tag;
|
||||
}
|
||||
public record BlockEntityImpl(byte packedXZ, short y, int typeId, CompoundTag tag) implements BlockEntity {
|
||||
|
||||
@Override
|
||||
public BlockEntity withTypeId(int typeId) {
|
||||
|
@ -52,86 +52,6 @@ public interface ChunkSection {
|
||||
return idx >> 4 & 0xF;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getFlatBlock(int idx) {
|
||||
return palette(PaletteType.BLOCKS).idAt(idx);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getFlatBlock(int x, int y, int z) {
|
||||
return getFlatBlock(index(x, y, z));
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setFlatBlock(int idx, int id) {
|
||||
palette(PaletteType.BLOCKS).setIdAt(idx, id);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setFlatBlock(int x, int y, int z, int id) {
|
||||
setFlatBlock(index(x, y, z), id);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getBlockWithoutData(int x, int y, int z) {
|
||||
return getFlatBlock(x, y, z) >> 4;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getBlockData(int x, int y, int z) {
|
||||
return getFlatBlock(x, y, z) & 0xF;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setBlockWithData(int x, int y, int z, int type, int data) {
|
||||
setFlatBlock(index(x, y, z), type << 4 | (data & 0xF));
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setBlockWithData(int idx, int type, int data) {
|
||||
setFlatBlock(idx, type << 4 | (data & 0xF));
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setPaletteIndex(int idx, int index) {
|
||||
palette(PaletteType.BLOCKS).setPaletteIndexAt(idx, index);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getPaletteIndex(int idx) {
|
||||
return palette(PaletteType.BLOCKS).paletteIndexAt(idx);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getPaletteSize() {
|
||||
return palette(PaletteType.BLOCKS).size();
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default int getPaletteEntry(int index) {
|
||||
return palette(PaletteType.BLOCKS).idByIndex(index);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setPaletteEntry(int index, int id) {
|
||||
palette(PaletteType.BLOCKS).setIdByIndex(index, id);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void replacePaletteEntry(int oldId, int newId) {
|
||||
palette(PaletteType.BLOCKS).replaceId(oldId, newId);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void addPaletteEntry(int id) {
|
||||
palette(PaletteType.BLOCKS).addId(id);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void clearPalette() {
|
||||
palette(PaletteType.BLOCKS).clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of non-air blocks in this section.
|
||||
*
|
||||
|
@ -45,7 +45,7 @@ final class FilledStructuredData<T> implements StructuredData<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer) throws Exception {
|
||||
public void write(final ByteBuf buffer) {
|
||||
key.type().write(buffer, value);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public interface StructuredData<T> extends IdHolder {
|
||||
|
||||
void setValue(final T value);
|
||||
|
||||
void write(final ByteBuf buffer) throws Exception;
|
||||
void write(final ByteBuf buffer);
|
||||
|
||||
void setId(final int id);
|
||||
|
||||
|
@ -51,7 +51,7 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.util.Unit;
|
||||
|
||||
public final class StructuredDataKey<T> {
|
||||
public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
|
||||
public static final StructuredDataKey<CompoundTag> CUSTOM_DATA = new StructuredDataKey<>("custom_data", Type.COMPOUND_TAG);
|
||||
public static final StructuredDataKey<Integer> MAX_STACK_SIZE = new StructuredDataKey<>("max_stack_size", Type.VAR_INT);
|
||||
@ -110,22 +110,6 @@ public final class StructuredDataKey<T> {
|
||||
public static final StructuredDataKey<Tag> LOCK = new StructuredDataKey<>("lock", Type.TAG);
|
||||
public static final StructuredDataKey<CompoundTag> CONTAINER_LOOT = new StructuredDataKey<>("container_loot", Type.COMPOUND_TAG);
|
||||
|
||||
private final String identifier;
|
||||
private final Type<T> type;
|
||||
|
||||
public StructuredDataKey(final String identifier, final Type<T> type) {
|
||||
this.identifier = identifier;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Type<T> type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String identifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StructuredDataKey{" +
|
||||
|
@ -38,7 +38,7 @@ public class EntityTypes1_10 {
|
||||
else
|
||||
type = EntityType.findById(typeID);
|
||||
|
||||
if (!type.isPresent()) {
|
||||
if (type.isEmpty()) {
|
||||
Via.getPlatform().getLogger().severe("Could not find 1.10 type id " + typeID + " isObject=" + isObject);
|
||||
return EntityType.ENTITY; // Fall back to the basic ENTITY
|
||||
}
|
||||
@ -50,8 +50,8 @@ public class EntityTypes1_10 {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, ENTITY),
|
||||
EXPERIENCE_ORB(2, ENTITY),
|
||||
LEASH_HITCH(8, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
PAINTING(9, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata
|
||||
PAINTING(9, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata
|
||||
ARROW(10, ENTITY),
|
||||
SNOWBALL(11, ENTITY), // Actually EntityProjectile
|
||||
FIREBALL(12, ENTITY),
|
||||
@ -242,10 +242,7 @@ public class EntityTypes1_10 {
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
Optional<ObjectType> output = findById(id);
|
||||
|
||||
if (!output.isPresent())
|
||||
return Optional.empty();
|
||||
return Optional.of(output.get().type);
|
||||
return output.map(objectType -> objectType.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class EntityTypes1_11 {
|
||||
else
|
||||
type = EntityType.findById(typeID);
|
||||
|
||||
if (!type.isPresent()) {
|
||||
if (type.isEmpty()) {
|
||||
Via.getPlatform().getLogger().severe("Could not find 1.11 type id " + typeID + " isObject=" + isObject);
|
||||
return EntityType.ENTITY; // Fall back to the basic ENTITY
|
||||
}
|
||||
@ -50,8 +50,8 @@ public class EntityTypes1_11 {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, ENTITY),
|
||||
EXPERIENCE_ORB(2, ENTITY),
|
||||
LEASH_HITCH(8, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
PAINTING(9, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata
|
||||
PAINTING(9, ENTITY), // Actually entity hanging but, it doesn't make a lot of difference for metadata
|
||||
ARROW(10, ENTITY),
|
||||
SNOWBALL(11, ENTITY), // Actually EntityProjectile
|
||||
FIREBALL(12, ENTITY),
|
||||
@ -272,10 +272,7 @@ public class EntityTypes1_11 {
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
Optional<ObjectType> output = findById(id);
|
||||
|
||||
if (!output.isPresent())
|
||||
return Optional.empty();
|
||||
return Optional.of(output.get().type);
|
||||
return output.map(objectType -> objectType.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class EntityTypes1_12 {
|
||||
else
|
||||
type = EntityType.findById(typeID);
|
||||
|
||||
if (!type.isPresent()) {
|
||||
if (type.isEmpty()) {
|
||||
Via.getPlatform().getLogger().severe("Could not find 1.12 type id " + typeID + " isObject=" + isObject);
|
||||
return EntityType.ENTITY; // Fall back to the basic ENTITY
|
||||
}
|
||||
@ -51,8 +51,8 @@ public class EntityTypes1_12 {
|
||||
ENTITY(-1),
|
||||
DROPPED_ITEM(1, ENTITY),
|
||||
EXPERIENCE_ORB(2, ENTITY),
|
||||
LEASH_HITCH(8, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
PAINTING(9, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata
|
||||
LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata
|
||||
PAINTING(9, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata
|
||||
ARROW(10, ENTITY),
|
||||
SNOWBALL(11, ENTITY), // Actually EntityProjectile
|
||||
FIREBALL(12, ENTITY),
|
||||
@ -276,10 +276,7 @@ public class EntityTypes1_12 {
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
Optional<ObjectType> output = findById(id);
|
||||
|
||||
if (!output.isPresent())
|
||||
return Optional.empty();
|
||||
return Optional.of(output.get().type);
|
||||
return output.map(objectType -> objectType.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class EntityTypes1_13 {
|
||||
else
|
||||
type = EntityType.findById(typeID);
|
||||
|
||||
if (!type.isPresent()) {
|
||||
if (type.isEmpty()) {
|
||||
Via.getPlatform().getLogger().severe("Could not find 1.13 type id " + typeID + " isObject=" + isObject);
|
||||
return EntityType.ENTITY; // Fall back to the basic ENTITY
|
||||
}
|
||||
@ -326,9 +326,7 @@ public class EntityTypes1_13 {
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
Optional<ObjectType> output = findById(id);
|
||||
if (!output.isPresent())
|
||||
return Optional.empty();
|
||||
return Optional.of(output.get().type);
|
||||
return output.map(objectType -> objectType.type);
|
||||
}
|
||||
|
||||
public static Optional<ObjectType> fromEntityType(EntityType type) {
|
||||
|
@ -66,7 +66,7 @@ public class DataItem implements Item {
|
||||
|
||||
@Override
|
||||
public void setAmount(int amount) {
|
||||
if (amount > Byte.MAX_VALUE || amount < Byte.MIN_VALUE) {
|
||||
if (amount != (byte) amount) {
|
||||
throw new IllegalArgumentException("Invalid item amount: " + amount);
|
||||
}
|
||||
this.amount = (byte) amount;
|
||||
@ -116,8 +116,8 @@ public class DataItem implements Item {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = identifier;
|
||||
result = 31 * result + (int) amount;
|
||||
result = 31 * result + (int) data;
|
||||
result = 31 * result + amount;
|
||||
result = 31 * result + data;
|
||||
result = 31 * result + (tag != null ? tag.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
@ -25,36 +25,21 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class AdventureModePredicate {
|
||||
public record AdventureModePredicate(BlockPredicate[] predicates, boolean showInTooltip) {
|
||||
|
||||
public static final Type<AdventureModePredicate> TYPE = new Type<AdventureModePredicate>(AdventureModePredicate.class) {
|
||||
public static final Type<AdventureModePredicate> TYPE = new Type<>(AdventureModePredicate.class) {
|
||||
@Override
|
||||
public AdventureModePredicate read(final ByteBuf buffer) throws Exception {
|
||||
public AdventureModePredicate read(final ByteBuf buffer) {
|
||||
final BlockPredicate[] predicates = BlockPredicate.ARRAY_TYPE.read(buffer);
|
||||
final boolean showInTooltip = buffer.readBoolean();
|
||||
return new AdventureModePredicate(predicates, showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final AdventureModePredicate value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final AdventureModePredicate value) {
|
||||
BlockPredicate.ARRAY_TYPE.write(buffer, value.predicates);
|
||||
buffer.writeBoolean(value.showInTooltip);
|
||||
}
|
||||
};
|
||||
|
||||
private final BlockPredicate[] predicates;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public AdventureModePredicate(final BlockPredicate[] predicates, final boolean showInTooltip) {
|
||||
this.predicates = predicates;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public BlockPredicate[] predicates() {
|
||||
return predicates;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class ArmorTrim {
|
||||
public record ArmorTrim(Holder<ArmorTrimMaterial> material, Holder<ArmorTrimPattern> pattern, boolean showInTooltip) {
|
||||
|
||||
public static final Type<ArmorTrim> TYPE = new Type<ArmorTrim>(ArmorTrim.class) {
|
||||
public static final Type<ArmorTrim> TYPE = new Type<>(ArmorTrim.class) {
|
||||
@Override
|
||||
public ArmorTrim read(final ByteBuf buffer) throws Exception {
|
||||
public ArmorTrim read(final ByteBuf buffer) {
|
||||
final Holder<ArmorTrimMaterial> material = ArmorTrimMaterial.TYPE.read(buffer);
|
||||
final Holder<ArmorTrimPattern> pattern = ArmorTrimPattern.TYPE.read(buffer);
|
||||
final boolean showInTooltip = buffer.readBoolean();
|
||||
@ -38,32 +38,11 @@ public final class ArmorTrim {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ArmorTrim value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final ArmorTrim value) {
|
||||
ArmorTrimMaterial.TYPE.write(buffer, value.material);
|
||||
ArmorTrimPattern.TYPE.write(buffer, value.pattern);
|
||||
buffer.writeBoolean(value.showInTooltip);
|
||||
}
|
||||
};
|
||||
|
||||
private final Holder<ArmorTrimMaterial> material;
|
||||
private final Holder<ArmorTrimPattern> pattern;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public ArmorTrim(final Holder<ArmorTrimMaterial> material, final Holder<ArmorTrimPattern> pattern, final boolean showInTooltip) {
|
||||
this.material = material;
|
||||
this.pattern = pattern;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public Holder<ArmorTrimMaterial> material() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public Holder<ArmorTrimPattern> pattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,12 @@ import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public final class ArmorTrimMaterial {
|
||||
public record ArmorTrimMaterial(String assetName, int itemId, float itemModelIndex,
|
||||
Int2ObjectMap<String> overrideArmorMaterials, Tag description) {
|
||||
|
||||
public static final HolderType<ArmorTrimMaterial> TYPE = new HolderType<ArmorTrimMaterial>() {
|
||||
public static final HolderType<ArmorTrimMaterial> TYPE = new HolderType<>() {
|
||||
@Override
|
||||
public ArmorTrimMaterial readDirect(final ByteBuf buffer) throws Exception {
|
||||
public ArmorTrimMaterial readDirect(final ByteBuf buffer) {
|
||||
final String assetName = Type.STRING.read(buffer);
|
||||
final int item = Type.VAR_INT.readPrimitive(buffer);
|
||||
final float itemModelIndex = buffer.readFloat();
|
||||
@ -51,7 +52,7 @@ public final class ArmorTrimMaterial {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) throws Exception {
|
||||
public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) {
|
||||
Type.STRING.write(buffer, value.assetName());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.itemId());
|
||||
buffer.writeFloat(value.itemModelIndex());
|
||||
@ -66,37 +67,4 @@ public final class ArmorTrimMaterial {
|
||||
}
|
||||
};
|
||||
|
||||
private final String assetName;
|
||||
private final int itemId;
|
||||
private final float itemModelIndex;
|
||||
private final Int2ObjectMap<String> overrideArmorMaterials;
|
||||
private final Tag description;
|
||||
|
||||
public ArmorTrimMaterial(final String assetName, final int itemId, final float itemModelIndex, final Int2ObjectMap<String> overrideArmorMaterials, final Tag description) {
|
||||
this.assetName = assetName;
|
||||
this.itemId = itemId;
|
||||
this.itemModelIndex = itemModelIndex;
|
||||
this.overrideArmorMaterials = overrideArmorMaterials;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String assetName() {
|
||||
return assetName;
|
||||
}
|
||||
|
||||
public int itemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public float itemModelIndex() {
|
||||
return itemModelIndex;
|
||||
}
|
||||
|
||||
public Int2ObjectMap<String> overrideArmorMaterials() {
|
||||
return overrideArmorMaterials;
|
||||
}
|
||||
|
||||
public Tag description() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class ArmorTrimPattern {
|
||||
public record ArmorTrimPattern(String assetName, int itemId, Tag description, boolean decal) {
|
||||
|
||||
public static final HolderType<ArmorTrimPattern> TYPE = new HolderType<ArmorTrimPattern>() {
|
||||
public static final HolderType<ArmorTrimPattern> TYPE = new HolderType<>() {
|
||||
@Override
|
||||
public ArmorTrimPattern readDirect(final ByteBuf buffer) throws Exception {
|
||||
public ArmorTrimPattern readDirect(final ByteBuf buffer) {
|
||||
final String assetName = Type.STRING.read(buffer);
|
||||
final int itemId = Type.VAR_INT.readPrimitive(buffer);
|
||||
final Tag description = Type.TAG.read(buffer);
|
||||
@ -40,7 +40,7 @@ public final class ArmorTrimPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) throws Exception {
|
||||
public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) {
|
||||
Type.STRING.write(buffer, value.assetName());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.itemId());
|
||||
Type.TAG.write(buffer, value.description());
|
||||
@ -48,31 +48,4 @@ public final class ArmorTrimPattern {
|
||||
}
|
||||
};
|
||||
|
||||
private final String assetName;
|
||||
private final int itemId;
|
||||
private final Tag description;
|
||||
private final boolean decal;
|
||||
|
||||
public ArmorTrimPattern(final String assetName, final int itemId, final Tag description, final boolean decal) {
|
||||
this.assetName = assetName;
|
||||
this.itemId = itemId;
|
||||
this.description = description;
|
||||
this.decal = decal;
|
||||
}
|
||||
|
||||
public String assetName() {
|
||||
return assetName;
|
||||
}
|
||||
|
||||
public int itemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public Tag description() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean decal() {
|
||||
return decal;
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class AttributeModifier {
|
||||
public record AttributeModifier(int attribute, ModifierData modifier, int slotType) {
|
||||
|
||||
public static final Type<AttributeModifier> TYPE = new Type<AttributeModifier>(AttributeModifier.class) {
|
||||
public static final Type<AttributeModifier> TYPE = new Type<>(AttributeModifier.class) {
|
||||
@Override
|
||||
public AttributeModifier read(final ByteBuf buffer) throws Exception {
|
||||
public AttributeModifier read(final ByteBuf buffer) {
|
||||
final int attribute = Type.VAR_INT.readPrimitive(buffer);
|
||||
final ModifierData modifier = ModifierData.TYPE.read(buffer);
|
||||
final int slot = Type.VAR_INT.readPrimitive(buffer);
|
||||
@ -38,7 +38,7 @@ public final class AttributeModifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final AttributeModifier value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final AttributeModifier value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.attribute);
|
||||
ModifierData.TYPE.write(buffer, value.modifier);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.slotType);
|
||||
@ -46,25 +46,4 @@ public final class AttributeModifier {
|
||||
};
|
||||
public static final Type<AttributeModifier[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int attribute;
|
||||
private final ModifierData modifier;
|
||||
private final int slotType;
|
||||
|
||||
public AttributeModifier(final int attribute, final ModifierData modifier, final int slotType) {
|
||||
this.attribute = attribute;
|
||||
this.modifier = modifier;
|
||||
this.slotType = slotType;
|
||||
}
|
||||
|
||||
public int attribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
public ModifierData modifier() {
|
||||
return modifier;
|
||||
}
|
||||
|
||||
public int slotType() {
|
||||
return slotType;
|
||||
}
|
||||
}
|
||||
|
@ -25,36 +25,21 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class AttributeModifiers {
|
||||
public record AttributeModifiers(AttributeModifier[] modifiers, boolean showInTooltip) {
|
||||
|
||||
public static final Type<AttributeModifiers> TYPE = new Type<AttributeModifiers>(AttributeModifiers.class) {
|
||||
public static final Type<AttributeModifiers> TYPE = new Type<>(AttributeModifiers.class) {
|
||||
@Override
|
||||
public AttributeModifiers read(final ByteBuf buffer) throws Exception {
|
||||
public AttributeModifiers read(final ByteBuf buffer) {
|
||||
final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer);
|
||||
final boolean showInTooltip = buffer.readBoolean();
|
||||
return new AttributeModifiers(modifiers, showInTooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final AttributeModifiers value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final AttributeModifiers value) {
|
||||
AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers());
|
||||
buffer.writeBoolean(value.showInTooltip());
|
||||
}
|
||||
};
|
||||
|
||||
private final AttributeModifier[] modifiers;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public AttributeModifiers(final AttributeModifier[] modifiers, final boolean showInTooltip) {
|
||||
this.modifiers = modifiers;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public AttributeModifier[] modifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
||||
|
@ -26,36 +26,21 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class BannerPattern {
|
||||
public record BannerPattern(String assetId, String translationKey) {
|
||||
|
||||
public static final HolderType<BannerPattern> TYPE = new HolderType<BannerPattern>() {
|
||||
public static final HolderType<BannerPattern> TYPE = new HolderType<>() {
|
||||
@Override
|
||||
public BannerPattern readDirect(final ByteBuf buffer) throws Exception {
|
||||
public BannerPattern readDirect(final ByteBuf buffer) {
|
||||
final String assetId = Type.STRING.read(buffer);
|
||||
final String translationKey = Type.STRING.read(buffer);
|
||||
return new BannerPattern(assetId, translationKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final BannerPattern value) throws Exception {
|
||||
public void writeDirect(final ByteBuf buffer, final BannerPattern value) {
|
||||
Type.STRING.write(buffer, value.assetId);
|
||||
Type.STRING.write(buffer, value.translationKey);
|
||||
}
|
||||
};
|
||||
|
||||
private final String assetId;
|
||||
private final String translationKey;
|
||||
|
||||
public BannerPattern(final String assetId, final String translationKey) {
|
||||
this.assetId = assetId;
|
||||
this.translationKey = translationKey;
|
||||
}
|
||||
|
||||
public String assetId() {
|
||||
return assetId;
|
||||
}
|
||||
|
||||
public String translationKey() {
|
||||
return translationKey;
|
||||
}
|
||||
}
|
||||
|
@ -27,37 +27,22 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class BannerPatternLayer {
|
||||
public record BannerPatternLayer(Holder<BannerPattern> pattern, int dyeColor) {
|
||||
|
||||
public static final Type<BannerPatternLayer> TYPE = new Type<BannerPatternLayer>(BannerPatternLayer.class) {
|
||||
public static final Type<BannerPatternLayer> TYPE = new Type<>(BannerPatternLayer.class) {
|
||||
@Override
|
||||
public BannerPatternLayer read(final ByteBuf buffer) throws Exception {
|
||||
public BannerPatternLayer read(final ByteBuf buffer) {
|
||||
final Holder<BannerPattern> pattern = BannerPattern.TYPE.read(buffer);
|
||||
final int color = Type.VAR_INT.readPrimitive(buffer);
|
||||
return new BannerPatternLayer(pattern, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final BannerPatternLayer value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final BannerPatternLayer value) {
|
||||
BannerPattern.TYPE.write(buffer, value.pattern);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.dyeColor);
|
||||
}
|
||||
};
|
||||
public static final Type<BannerPatternLayer[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final Holder<BannerPattern> pattern;
|
||||
private final int dyeColor;
|
||||
|
||||
public BannerPatternLayer(final Holder<BannerPattern> pattern, final int dyeColor) {
|
||||
this.pattern = pattern;
|
||||
this.dyeColor = dyeColor;
|
||||
}
|
||||
|
||||
public Holder<BannerPattern> pattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public int dyeColor() {
|
||||
return dyeColor;
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Bee {
|
||||
public record Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) {
|
||||
|
||||
public static final Type<Bee> TYPE = new Type<Bee>(Bee.class) {
|
||||
public static final Type<Bee> TYPE = new Type<>(Bee.class) {
|
||||
@Override
|
||||
public Bee read(final ByteBuf buffer) throws Exception {
|
||||
public Bee read(final ByteBuf buffer) {
|
||||
final CompoundTag entityData = Type.COMPOUND_TAG.read(buffer);
|
||||
final int ticksInHive = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int minTicksInHive = Type.VAR_INT.readPrimitive(buffer);
|
||||
@ -39,7 +39,7 @@ public final class Bee {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Bee value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final Bee value) {
|
||||
Type.COMPOUND_TAG.write(buffer, value.entityData);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.ticksInHive);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.minTicksInHive);
|
||||
@ -47,25 +47,4 @@ public final class Bee {
|
||||
};
|
||||
public static final Type<Bee[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final CompoundTag entityData;
|
||||
private final int ticksInHive;
|
||||
private final int minTicksInHive;
|
||||
|
||||
public Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) {
|
||||
this.entityData = entityData;
|
||||
this.ticksInHive = ticksInHive;
|
||||
this.minTicksInHive = minTicksInHive;
|
||||
}
|
||||
|
||||
public CompoundTag entityData() {
|
||||
return entityData;
|
||||
}
|
||||
|
||||
public int ticksInHive() {
|
||||
return ticksInHive;
|
||||
}
|
||||
|
||||
public int minTicksInHive() {
|
||||
return minTicksInHive;
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,12 @@ import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class BlockPredicate {
|
||||
public record BlockPredicate(@Nullable HolderSet holderSet, StatePropertyMatcher @Nullable [] propertyMatchers,
|
||||
@Nullable CompoundTag tag) {
|
||||
|
||||
public static final Type<BlockPredicate> TYPE = new Type<BlockPredicate>(BlockPredicate.class) {
|
||||
public static final Type<BlockPredicate> TYPE = new Type<>(BlockPredicate.class) {
|
||||
@Override
|
||||
public BlockPredicate read(final ByteBuf buffer) throws Exception {
|
||||
public BlockPredicate read(final ByteBuf buffer) {
|
||||
final HolderSet holders = Type.OPTIONAL_HOLDER_SET.read(buffer);
|
||||
final StatePropertyMatcher[] propertyMatchers = buffer.readBoolean() ? StatePropertyMatcher.ARRAY_TYPE.read(buffer) : null;
|
||||
final CompoundTag tag = Type.OPTIONAL_COMPOUND_TAG.read(buffer);
|
||||
@ -41,7 +42,7 @@ public final class BlockPredicate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final BlockPredicate value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final BlockPredicate value) {
|
||||
Type.OPTIONAL_HOLDER_SET.write(buffer, value.holderSet);
|
||||
|
||||
buffer.writeBoolean(value.propertyMatchers != null);
|
||||
@ -54,25 +55,4 @@ public final class BlockPredicate {
|
||||
};
|
||||
public static final Type<BlockPredicate[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final HolderSet holderSet;
|
||||
private final StatePropertyMatcher[] propertyMatchers;
|
||||
private final CompoundTag tag;
|
||||
|
||||
public BlockPredicate(@Nullable final HolderSet holderSet, final StatePropertyMatcher @Nullable [] propertyMatchers, @Nullable final CompoundTag tag) {
|
||||
this.holderSet = holderSet;
|
||||
this.propertyMatchers = propertyMatchers;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public @Nullable HolderSet holderSet() {
|
||||
return holderSet;
|
||||
}
|
||||
|
||||
public StatePropertyMatcher @Nullable [] propertyMatchers() {
|
||||
return propertyMatchers;
|
||||
}
|
||||
|
||||
public @Nullable CompoundTag tag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class BlockStateProperties {
|
||||
public record BlockStateProperties(Map<String, String> properties) {
|
||||
|
||||
public static final Type<BlockStateProperties> TYPE = new Type<BlockStateProperties>(BlockStateProperties.class) {
|
||||
public static final Type<BlockStateProperties> TYPE = new Type<>(BlockStateProperties.class) {
|
||||
@Override
|
||||
public BlockStateProperties read(final ByteBuf buffer) throws Exception {
|
||||
public BlockStateProperties read(final ByteBuf buffer) {
|
||||
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||
final Map<String, String> properties = new Object2ObjectOpenHashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
@ -41,7 +41,7 @@ public final class BlockStateProperties {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final BlockStateProperties value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final BlockStateProperties value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.properties.size());
|
||||
for (final Map.Entry<String, String> entry : value.properties.entrySet()) {
|
||||
Type.STRING.write(buffer, entry.getKey());
|
||||
@ -50,13 +50,4 @@ public final class BlockStateProperties {
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<String, String> properties;
|
||||
|
||||
public BlockStateProperties(final Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Map<String, String> properties() {
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class DyedColor {
|
||||
public record DyedColor(int rgb, boolean showInTooltip) {
|
||||
|
||||
public static final Type<DyedColor> TYPE = new Type<DyedColor>(DyedColor.class) {
|
||||
public static final Type<DyedColor> TYPE = new Type<>(DyedColor.class) {
|
||||
@Override
|
||||
public DyedColor read(final ByteBuf buffer) {
|
||||
final int rgb = buffer.readInt();
|
||||
@ -42,19 +42,4 @@ public final class DyedColor {
|
||||
}
|
||||
};
|
||||
|
||||
private final int rgb;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public DyedColor(final int rgb, final boolean showInTooltip) {
|
||||
this.rgb = rgb;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public int rgb() {
|
||||
return this.rgb;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return this.showInTooltip;
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public final class Enchantments {
|
||||
public record Enchantments(Int2IntMap enchantments, boolean showInTooltip) {
|
||||
|
||||
public static final Type<Enchantments> TYPE = new Type<Enchantments>(Enchantments.class) {
|
||||
public static final Type<Enchantments> TYPE = new Type<>(Enchantments.class) {
|
||||
@Override
|
||||
public Enchantments read(final ByteBuf buffer) {
|
||||
final Int2IntMap enchantments = new Int2IntOpenHashMap();
|
||||
@ -54,30 +54,14 @@ public final class Enchantments {
|
||||
}
|
||||
};
|
||||
|
||||
private final Int2IntMap enchantments;
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public Enchantments(final Int2IntMap enchantments, final boolean showInTooltip) {
|
||||
this.enchantments = enchantments;
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public Enchantments(final boolean showInTooltip) {
|
||||
this(new Int2IntOpenHashMap(), showInTooltip);
|
||||
}
|
||||
|
||||
public Int2IntMap enchantments() {
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return enchantments.size();
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
|
||||
public void add(final int id, final int level) {
|
||||
enchantments.put(id, level);
|
||||
}
|
||||
|
@ -62,14 +62,14 @@ public abstract class Filterable<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public F read(final ByteBuf buffer) throws Exception {
|
||||
public F read(final ByteBuf buffer) {
|
||||
final T raw = elementType.read(buffer);
|
||||
final T filtered = optionalElementType.read(buffer);
|
||||
return create(raw, filtered);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final F value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final F value) {
|
||||
elementType.write(buffer, value.raw());
|
||||
optionalElementType.write(buffer, value.filtered());
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class FilterableComponent extends Filterable<Tag> {
|
||||
|
||||
public static final Type<FilterableComponent> TYPE = new FilterableType<Tag, FilterableComponent>(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) {
|
||||
public static final Type<FilterableComponent> TYPE = new FilterableType<>(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) {
|
||||
@Override
|
||||
protected FilterableComponent create(final Tag raw, final Tag filtered) {
|
||||
return new FilterableComponent(raw, filtered);
|
||||
|
@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class FilterableString extends Filterable<String> {
|
||||
|
||||
public static final Type<FilterableString> TYPE = new FilterableType<String, FilterableString>(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) {
|
||||
public static final Type<FilterableString> TYPE = new FilterableType<>(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) {
|
||||
@Override
|
||||
protected FilterableString create(final String raw, final String filtered) {
|
||||
return new FilterableString(raw, filtered);
|
||||
|
@ -26,10 +26,10 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class FireworkExplosion {
|
||||
public static final Type<FireworkExplosion> TYPE = new Type<FireworkExplosion>(FireworkExplosion.class) {
|
||||
public record FireworkExplosion(int shape, int[] colors, int[] fadeColors, boolean hasTrail, boolean hasTwinkle) {
|
||||
public static final Type<FireworkExplosion> TYPE = new Type<>(FireworkExplosion.class) {
|
||||
@Override
|
||||
public FireworkExplosion read(final ByteBuf buffer) throws Exception {
|
||||
public FireworkExplosion read(final ByteBuf buffer) {
|
||||
final int shape = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int[] colors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
|
||||
final int[] fadeColors = Type.INT_ARRAY_PRIMITIVE.read(buffer);
|
||||
@ -39,7 +39,7 @@ public final class FireworkExplosion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final FireworkExplosion value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final FireworkExplosion value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.shape);
|
||||
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.colors);
|
||||
Type.INT_ARRAY_PRIMITIVE.write(buffer, value.fadeColors);
|
||||
@ -49,37 +49,4 @@ public final class FireworkExplosion {
|
||||
};
|
||||
public static final Type<FireworkExplosion[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int shape;
|
||||
private final int[] colors;
|
||||
private final int[] fadeColors;
|
||||
private final boolean hasTrail;
|
||||
private final boolean hasTwinkle;
|
||||
|
||||
public FireworkExplosion(final int shape, final int[] colors, final int[] fadeColors, final boolean hasTrail, final boolean hasTwinkle) {
|
||||
this.shape = shape;
|
||||
this.colors = colors;
|
||||
this.fadeColors = fadeColors;
|
||||
this.hasTrail = hasTrail;
|
||||
this.hasTwinkle = hasTwinkle;
|
||||
}
|
||||
|
||||
public int shape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public int[] colors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public int[] fadeColors() {
|
||||
return fadeColors;
|
||||
}
|
||||
|
||||
public boolean hasTrail() {
|
||||
return hasTrail;
|
||||
}
|
||||
|
||||
public boolean hasTwinkle() {
|
||||
return hasTwinkle;
|
||||
}
|
||||
}
|
@ -25,36 +25,21 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Fireworks {
|
||||
public record Fireworks(int flightDuration, FireworkExplosion[] explosions) {
|
||||
|
||||
public static final Type<Fireworks> TYPE = new Type<Fireworks>(Fireworks.class) {
|
||||
public static final Type<Fireworks> TYPE = new Type<>(Fireworks.class) {
|
||||
@Override
|
||||
public Fireworks read(final ByteBuf buffer) throws Exception {
|
||||
public Fireworks read(final ByteBuf buffer) {
|
||||
final int flightDuration = Type.VAR_INT.readPrimitive(buffer);
|
||||
final FireworkExplosion[] explosions = FireworkExplosion.ARRAY_TYPE.read(buffer);
|
||||
return new Fireworks(flightDuration, explosions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final Fireworks value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final Fireworks value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.flightDuration);
|
||||
FireworkExplosion.ARRAY_TYPE.write(buffer, value.explosions);
|
||||
}
|
||||
};
|
||||
|
||||
private final FireworkExplosion[] explosions;
|
||||
private final int flightDuration;
|
||||
|
||||
public Fireworks(final int flightDuration, final FireworkExplosion[] explosions) {
|
||||
this.flightDuration = flightDuration;
|
||||
this.explosions = explosions;
|
||||
}
|
||||
|
||||
public int flightDuration() {
|
||||
return flightDuration;
|
||||
}
|
||||
|
||||
public FireworkExplosion[] explosions() {
|
||||
return explosions;
|
||||
}
|
||||
}
|
||||
|
@ -26,37 +26,22 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class FoodEffect {
|
||||
public record FoodEffect(PotionEffect effect, float probability) {
|
||||
|
||||
public static final Type<FoodEffect> TYPE = new Type<FoodEffect>(FoodEffect.class) {
|
||||
public static final Type<FoodEffect> TYPE = new Type<>(FoodEffect.class) {
|
||||
@Override
|
||||
public FoodEffect read(final ByteBuf buffer) throws Exception {
|
||||
public FoodEffect read(final ByteBuf buffer) {
|
||||
final PotionEffect effect = PotionEffect.TYPE.read(buffer);
|
||||
final float probability = buffer.readFloat();
|
||||
return new FoodEffect(effect, probability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final FoodEffect value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final FoodEffect value) {
|
||||
PotionEffect.TYPE.write(buffer, value.effect);
|
||||
buffer.writeFloat(value.probability);
|
||||
}
|
||||
};
|
||||
public static final Type<FoodEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final PotionEffect effect;
|
||||
private final float probability;
|
||||
|
||||
public FoodEffect(final PotionEffect effect, final float probability) {
|
||||
this.effect = effect;
|
||||
this.probability = probability;
|
||||
}
|
||||
|
||||
public PotionEffect effect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public float probability() {
|
||||
return probability;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class FoodProperties {
|
||||
public record FoodProperties(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds,
|
||||
FoodEffect[] possibleEffects) {
|
||||
|
||||
public static final Type<FoodProperties> TYPE = new Type<FoodProperties>(FoodProperties.class) {
|
||||
public static final Type<FoodProperties> TYPE = new Type<>(FoodProperties.class) {
|
||||
@Override
|
||||
public FoodProperties read(final ByteBuf buffer) throws Exception {
|
||||
public FoodProperties read(final ByteBuf buffer) {
|
||||
final int nutrition = Type.VAR_INT.readPrimitive(buffer);
|
||||
final float saturationModifier = buffer.readFloat();
|
||||
final boolean canAlwaysEat = buffer.readBoolean();
|
||||
@ -39,7 +40,7 @@ public final class FoodProperties {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final FoodProperties value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final FoodProperties value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.nutrition);
|
||||
buffer.writeFloat(value.saturationModifier);
|
||||
buffer.writeBoolean(value.canAlwaysEat);
|
||||
@ -48,37 +49,4 @@ public final class FoodProperties {
|
||||
}
|
||||
};
|
||||
|
||||
private final int nutrition;
|
||||
private final float saturationModifier;
|
||||
private final boolean canAlwaysEat;
|
||||
private final float eatSeconds;
|
||||
private final FoodEffect[] possibleEffects;
|
||||
|
||||
public FoodProperties(final int nutrition, final float saturationModifier, final boolean canAlwaysEat, final float eatSeconds, final FoodEffect[] possibleEffects) {
|
||||
this.nutrition = nutrition;
|
||||
this.saturationModifier = saturationModifier;
|
||||
this.canAlwaysEat = canAlwaysEat;
|
||||
this.eatSeconds = eatSeconds;
|
||||
this.possibleEffects = possibleEffects;
|
||||
}
|
||||
|
||||
public int nutrition() {
|
||||
return nutrition;
|
||||
}
|
||||
|
||||
public float saturationModifier() {
|
||||
return saturationModifier;
|
||||
}
|
||||
|
||||
public boolean canAlwaysEat() {
|
||||
return canAlwaysEat;
|
||||
}
|
||||
|
||||
public float eatSeconds() {
|
||||
return eatSeconds;
|
||||
}
|
||||
|
||||
public FoodEffect[] possibleEffects() {
|
||||
return possibleEffects;
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.HolderType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Instrument {
|
||||
public record Instrument(Holder<SoundEvent> soundEvent, int useDuration, float range) {
|
||||
|
||||
public static final HolderType<Instrument> TYPE = new HolderType<Instrument>() {
|
||||
public static final HolderType<Instrument> TYPE = new HolderType<>() {
|
||||
@Override
|
||||
public Instrument readDirect(final ByteBuf buffer) throws Exception {
|
||||
public Instrument readDirect(final ByteBuf buffer) {
|
||||
final Holder<SoundEvent> soundEvent = Type.SOUND_EVENT.read(buffer);
|
||||
final int useDuration = Type.VAR_INT.readPrimitive(buffer);
|
||||
final float range = buffer.readFloat();
|
||||
@ -40,32 +40,11 @@ public final class Instrument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDirect(final ByteBuf buffer, final Instrument value) throws Exception {
|
||||
public void writeDirect(final ByteBuf buffer, final Instrument value) {
|
||||
Type.SOUND_EVENT.write(buffer, value.soundEvent());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.useDuration());
|
||||
buffer.writeFloat(value.range());
|
||||
}
|
||||
};
|
||||
|
||||
private final Holder<SoundEvent> soundEvent;
|
||||
private final int useDuration;
|
||||
private final float range;
|
||||
|
||||
public Instrument(final Holder<SoundEvent> soundEvent, final int useDuration, final float range) {
|
||||
this.soundEvent = soundEvent;
|
||||
this.useDuration = useDuration;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
public Holder<SoundEvent> soundEvent() {
|
||||
return soundEvent;
|
||||
}
|
||||
|
||||
public int useDuration() {
|
||||
return useDuration;
|
||||
}
|
||||
|
||||
public float range() {
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
@ -27,36 +27,21 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class LodestoneTracker {
|
||||
public record LodestoneTracker(@Nullable GlobalPosition position, boolean tracked) {
|
||||
|
||||
public static final Type<LodestoneTracker> TYPE = new Type<LodestoneTracker>(LodestoneTracker.class) {
|
||||
public static final Type<LodestoneTracker> TYPE = new Type<>(LodestoneTracker.class) {
|
||||
@Override
|
||||
public LodestoneTracker read(final ByteBuf buffer) throws Exception {
|
||||
public LodestoneTracker read(final ByteBuf buffer) {
|
||||
final GlobalPosition position = Type.OPTIONAL_GLOBAL_POSITION.read(buffer);
|
||||
final boolean tracked = buffer.readBoolean();
|
||||
return new LodestoneTracker(position, tracked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final LodestoneTracker value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final LodestoneTracker value) {
|
||||
Type.OPTIONAL_GLOBAL_POSITION.write(buffer, value.position);
|
||||
buffer.writeBoolean(value.tracked);
|
||||
}
|
||||
};
|
||||
|
||||
private final GlobalPosition position;
|
||||
private final boolean tracked;
|
||||
|
||||
public LodestoneTracker(@Nullable final GlobalPosition position, final boolean tracked) {
|
||||
this.position = position;
|
||||
this.tracked = tracked;
|
||||
}
|
||||
|
||||
public @Nullable GlobalPosition pos() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public boolean tracked() {
|
||||
return this.tracked;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class MapDecoration {
|
||||
public record MapDecoration(String type, double x, double z, float rotation) {
|
||||
|
||||
public static final Type<MapDecoration> TYPE = new Type<MapDecoration>(MapDecoration.class) {
|
||||
public static final Type<MapDecoration> TYPE = new Type<>(MapDecoration.class) {
|
||||
@Override
|
||||
public MapDecoration read(final ByteBuf buffer) throws Exception {
|
||||
public MapDecoration read(final ByteBuf buffer) {
|
||||
final String type = Type.STRING.read(buffer);
|
||||
final double x = Type.DOUBLE.readPrimitive(buffer);
|
||||
final double z = Type.DOUBLE.readPrimitive(buffer);
|
||||
@ -38,40 +38,11 @@ public final class MapDecoration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final MapDecoration value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final MapDecoration value) {
|
||||
Type.STRING.write(buffer, value.type);
|
||||
buffer.writeDouble(value.x);
|
||||
buffer.writeDouble(value.z);
|
||||
buffer.writeFloat(value.rotation);
|
||||
}
|
||||
};
|
||||
|
||||
private final String type;
|
||||
private final double x;
|
||||
private final double z;
|
||||
private final float rotation;
|
||||
|
||||
public MapDecoration(final String type, final double x, final double z, final float rotation) {
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public String type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public double x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public float rotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class MapDecorations {
|
||||
public record MapDecorations(Map<String, MapDecoration> decorations) {
|
||||
|
||||
public static final Type<MapDecorations> TYPE = new Type<MapDecorations>(MapDecorations.class) {
|
||||
public static final Type<MapDecorations> TYPE = new Type<>(MapDecorations.class) {
|
||||
@Override
|
||||
public MapDecorations read(final ByteBuf buffer) throws Exception {
|
||||
public MapDecorations read(final ByteBuf buffer) {
|
||||
final Object2ObjectMap<String, MapDecoration> decorations = new Object2ObjectOpenHashMap<>();
|
||||
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||
for (int i = 0; i < size; i++) {
|
||||
@ -44,7 +44,7 @@ public final class MapDecorations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final MapDecorations value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final MapDecorations value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.decorations.size());
|
||||
for (final Map.Entry<String, MapDecoration> entry : value.decorations.entrySet()) {
|
||||
Type.STRING.write(buffer, entry.getKey());
|
||||
@ -52,14 +52,4 @@ public final class MapDecorations {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<String, MapDecoration> decorations;
|
||||
|
||||
public MapDecorations(final Map<String, MapDecoration> decorations) {
|
||||
this.decorations = decorations;
|
||||
}
|
||||
|
||||
public Map<String, MapDecoration> decorations() {
|
||||
return decorations;
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ModifierData {
|
||||
public record ModifierData(UUID uuid, String name, double amount, int operation) {
|
||||
|
||||
public static final Type<ModifierData> TYPE = new Type<ModifierData>(ModifierData.class) {
|
||||
public static final Type<ModifierData> TYPE = new Type<>(ModifierData.class) {
|
||||
@Override
|
||||
public ModifierData read(final ByteBuf buffer) throws Exception {
|
||||
public ModifierData read(final ByteBuf buffer) {
|
||||
final UUID uuid = Type.UUID.read(buffer);
|
||||
final String name = Type.STRING.read(buffer);
|
||||
final double amount = buffer.readDouble();
|
||||
@ -39,7 +39,7 @@ public final class ModifierData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ModifierData value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final ModifierData value) {
|
||||
Type.UUID.write(buffer, value.uuid);
|
||||
Type.STRING.write(buffer, value.name);
|
||||
buffer.writeDouble(value.amount);
|
||||
@ -47,31 +47,4 @@ public final class ModifierData {
|
||||
}
|
||||
};
|
||||
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private final double amount;
|
||||
private final int operation;
|
||||
|
||||
public ModifierData(final UUID uuid, final String name, final double amount, final int operation) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public UUID uuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public double amount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public int operation() {
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
@ -27,14 +27,14 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class PotDecorations {
|
||||
|
||||
public static final Type<PotDecorations> TYPE = new Type<PotDecorations>(PotDecorations.class) {
|
||||
public static final Type<PotDecorations> TYPE = new Type<>(PotDecorations.class) {
|
||||
@Override
|
||||
public PotDecorations read(final ByteBuf buffer) throws Exception {
|
||||
public PotDecorations read(final ByteBuf buffer) {
|
||||
return new PotDecorations(Type.VAR_INT_ARRAY_PRIMITIVE.read(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotDecorations value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final PotDecorations value) {
|
||||
Type.VAR_INT_ARRAY_PRIMITIVE.write(buffer, value.itemIds());
|
||||
}
|
||||
};
|
||||
|
@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class PotionContents {
|
||||
public record PotionContents(@Nullable Integer potion, @Nullable Integer customColor, PotionEffect[] customEffects) {
|
||||
|
||||
public static final Type<PotionContents> TYPE = new Type<PotionContents>(PotionContents.class) {
|
||||
public static final Type<PotionContents> TYPE = new Type<>(PotionContents.class) {
|
||||
@Override
|
||||
public PotionContents read(final ByteBuf buffer) throws Exception {
|
||||
public PotionContents read(final ByteBuf buffer) {
|
||||
final Integer potion = buffer.readBoolean() ? Type.VAR_INT.readPrimitive(buffer) : null;
|
||||
final Integer customColor = buffer.readBoolean() ? buffer.readInt() : null;
|
||||
final PotionEffect[] customEffects = PotionEffect.ARRAY_TYPE.read(buffer);
|
||||
@ -38,7 +38,7 @@ public final class PotionContents {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotionContents value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final PotionContents value) {
|
||||
buffer.writeBoolean(value.potion != null);
|
||||
if (value.potion != null) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.potion);
|
||||
@ -52,26 +52,4 @@ public final class PotionContents {
|
||||
PotionEffect.ARRAY_TYPE.write(buffer, value.customEffects);
|
||||
}
|
||||
};
|
||||
|
||||
private final Integer potion;
|
||||
private final Integer customColor;
|
||||
private final PotionEffect[] customEffects;
|
||||
|
||||
public PotionContents(@Nullable final Integer potion, @Nullable final Integer customColor, final PotionEffect[] customEffects) {
|
||||
this.potion = potion;
|
||||
this.customColor = customColor;
|
||||
this.customEffects = customEffects;
|
||||
}
|
||||
|
||||
public @Nullable Integer potion() {
|
||||
return potion;
|
||||
}
|
||||
|
||||
public @Nullable Integer customColor() {
|
||||
return customColor;
|
||||
}
|
||||
|
||||
public PotionEffect[] customEffects() {
|
||||
return customEffects;
|
||||
}
|
||||
}
|
||||
|
@ -26,37 +26,22 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class PotionEffect {
|
||||
public record PotionEffect(int effect, PotionEffectData effectData) {
|
||||
|
||||
public static final Type<PotionEffect> TYPE = new Type<PotionEffect>(PotionEffect.class) {
|
||||
public static final Type<PotionEffect> TYPE = new Type<>(PotionEffect.class) {
|
||||
@Override
|
||||
public PotionEffect read(final ByteBuf buffer) throws Exception {
|
||||
public PotionEffect read(final ByteBuf buffer) {
|
||||
final int effect = Type.VAR_INT.readPrimitive(buffer);
|
||||
final PotionEffectData effectData = PotionEffectData.TYPE.read(buffer);
|
||||
return new PotionEffect(effect, effectData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotionEffect value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final PotionEffect value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.effect);
|
||||
PotionEffectData.TYPE.write(buffer, value.effectData);
|
||||
}
|
||||
};
|
||||
public static final Type<PotionEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int effect;
|
||||
private final PotionEffectData effectData;
|
||||
|
||||
public PotionEffect(final int effect, final PotionEffectData effectData) {
|
||||
this.effect = effect;
|
||||
this.effectData = effectData;
|
||||
}
|
||||
|
||||
public int effect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public PotionEffectData effectData() {
|
||||
return effectData;
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,12 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class PotionEffectData {
|
||||
public record PotionEffectData(int amplifier, int duration, boolean ambient, boolean showParticles,
|
||||
boolean showIcon, @Nullable PotionEffectData hiddenEffect) {
|
||||
|
||||
public static final Type<PotionEffectData> TYPE = new Type<PotionEffectData>(PotionEffectData.class) {
|
||||
public static final Type<PotionEffectData> TYPE = new Type<>(PotionEffectData.class) {
|
||||
@Override
|
||||
public PotionEffectData read(final ByteBuf buffer) throws Exception {
|
||||
public PotionEffectData read(final ByteBuf buffer) {
|
||||
final int amplifier = Type.VAR_INT.readPrimitive(buffer);
|
||||
final int duration = Type.VAR_INT.readPrimitive(buffer);
|
||||
final boolean ambient = buffer.readBoolean();
|
||||
@ -42,7 +43,7 @@ public final class PotionEffectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final PotionEffectData value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final PotionEffectData value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.amplifier);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.duration);
|
||||
buffer.writeBoolean(value.ambient);
|
||||
@ -51,47 +52,6 @@ public final class PotionEffectData {
|
||||
OPTIONAL_TYPE.write(buffer, value.hiddenEffect);
|
||||
}
|
||||
};
|
||||
public static final Type<PotionEffectData> OPTIONAL_TYPE = new OptionalType<PotionEffectData>(TYPE) {
|
||||
public static final Type<PotionEffectData> OPTIONAL_TYPE = new OptionalType<>(TYPE) {
|
||||
};
|
||||
|
||||
private final int amplifier;
|
||||
private final int duration;
|
||||
private final boolean ambient;
|
||||
private final boolean showParticles;
|
||||
private final boolean showIcon;
|
||||
private final PotionEffectData hiddenEffect;
|
||||
|
||||
public PotionEffectData(final int amplifier, final int duration, final boolean ambient, final boolean showParticles,
|
||||
final boolean showIcon, @Nullable final PotionEffectData hiddenEffect) {
|
||||
this.amplifier = amplifier;
|
||||
this.duration = duration;
|
||||
this.ambient = ambient;
|
||||
this.showParticles = showParticles;
|
||||
this.showIcon = showIcon;
|
||||
this.hiddenEffect = hiddenEffect;
|
||||
}
|
||||
|
||||
public int amplifier() {
|
||||
return amplifier;
|
||||
}
|
||||
|
||||
public int duration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public boolean ambient() {
|
||||
return ambient;
|
||||
}
|
||||
|
||||
public boolean showParticles() {
|
||||
return showParticles;
|
||||
}
|
||||
|
||||
public boolean showIcon() {
|
||||
return showIcon;
|
||||
}
|
||||
|
||||
public @Nullable PotionEffectData hiddenEffect() {
|
||||
return hiddenEffect;
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,12 @@ import com.viaversion.viaversion.util.Either;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class StatePropertyMatcher {
|
||||
public record StatePropertyMatcher(String name, Either<String, RangedMatcher> matcher) {
|
||||
|
||||
// TODO Abstract Either reading
|
||||
public static final Type<StatePropertyMatcher> TYPE = new Type<StatePropertyMatcher>(StatePropertyMatcher.class) {
|
||||
public static final Type<StatePropertyMatcher> TYPE = new Type<>(StatePropertyMatcher.class) {
|
||||
@Override
|
||||
public StatePropertyMatcher read(final ByteBuf buffer) throws Exception {
|
||||
public StatePropertyMatcher read(final ByteBuf buffer) {
|
||||
final String name = Type.STRING.read(buffer);
|
||||
if (buffer.readBoolean()) {
|
||||
final String value = Type.STRING.read(buffer);
|
||||
@ -46,7 +46,7 @@ public final class StatePropertyMatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final StatePropertyMatcher value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final StatePropertyMatcher value) {
|
||||
Type.STRING.write(buffer, value.name);
|
||||
if (value.matcher.isLeft()) {
|
||||
buffer.writeBoolean(true);
|
||||
@ -60,37 +60,6 @@ public final class StatePropertyMatcher {
|
||||
};
|
||||
public static final Type<StatePropertyMatcher[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final String name;
|
||||
private final Either<String, RangedMatcher> matcher;
|
||||
|
||||
public StatePropertyMatcher(final String name, final Either<String, RangedMatcher> matcher) {
|
||||
this.name = name;
|
||||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Either<String, RangedMatcher> matcher() {
|
||||
return matcher;
|
||||
}
|
||||
|
||||
public static final class RangedMatcher {
|
||||
private final String minValue;
|
||||
private final String maxValue;
|
||||
|
||||
public RangedMatcher(@Nullable final String minValue, @Nullable final String maxValue) {
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public @Nullable String minValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public @Nullable String maxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
public record RangedMatcher(@Nullable String minValue, @Nullable String maxValue) {
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class SuspiciousStewEffect {
|
||||
public record SuspiciousStewEffect(int mobEffect, int duration) {
|
||||
|
||||
public static final Type<SuspiciousStewEffect> TYPE = new Type<SuspiciousStewEffect>(SuspiciousStewEffect.class) {
|
||||
public static final Type<SuspiciousStewEffect> TYPE = new Type<>(SuspiciousStewEffect.class) {
|
||||
@Override
|
||||
public SuspiciousStewEffect read(final ByteBuf buffer) {
|
||||
final int effect = Type.VAR_INT.readPrimitive(buffer);
|
||||
@ -38,25 +38,10 @@ public final class SuspiciousStewEffect {
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final SuspiciousStewEffect value) {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.effect);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.mobEffect);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.duration);
|
||||
}
|
||||
};
|
||||
public static final Type<SuspiciousStewEffect[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final int effect;
|
||||
private final int duration;
|
||||
|
||||
public SuspiciousStewEffect(final int effect, final int duration) {
|
||||
this.effect = effect;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public int mobEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public int duration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class ToolProperties {
|
||||
public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int damagePerBlock) {
|
||||
|
||||
public static final Type<ToolProperties> TYPE = new Type<ToolProperties>(ToolProperties.class) {
|
||||
public static final Type<ToolProperties> TYPE = new Type<>(ToolProperties.class) {
|
||||
@Override
|
||||
public ToolProperties read(final ByteBuf buffer) throws Exception {
|
||||
public ToolProperties read(final ByteBuf buffer) {
|
||||
final ToolRule[] rules = ToolRule.ARRAY_TYPE.read(buffer);
|
||||
final float defaultMiningSpeed = buffer.readFloat();
|
||||
final int damagePerBlock = Type.VAR_INT.readPrimitive(buffer);
|
||||
@ -37,32 +37,11 @@ public final class ToolProperties {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ToolProperties value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final ToolProperties value) {
|
||||
ToolRule.ARRAY_TYPE.write(buffer, value.rules());
|
||||
buffer.writeFloat(value.defaultMiningSpeed());
|
||||
Type.VAR_INT.writePrimitive(buffer, value.damagePerBlock());
|
||||
}
|
||||
};
|
||||
|
||||
private final ToolRule[] rules;
|
||||
private final float defaultMiningSpeed;
|
||||
private final int damagePerBlock;
|
||||
|
||||
public ToolProperties(final ToolRule[] rules, final float defaultMiningSpeed, final int damagePerBlock) {
|
||||
this.rules = rules;
|
||||
this.defaultMiningSpeed = defaultMiningSpeed;
|
||||
this.damagePerBlock = damagePerBlock;
|
||||
}
|
||||
|
||||
public ToolRule[] rules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public float defaultMiningSpeed() {
|
||||
return defaultMiningSpeed;
|
||||
}
|
||||
|
||||
public int damagePerBlock() {
|
||||
return damagePerBlock;
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class ToolRule {
|
||||
public record ToolRule(HolderSet blocks, @Nullable Float speed, @Nullable Boolean correctForDrops) {
|
||||
|
||||
public static final Type<ToolRule> TYPE = new Type<ToolRule>(ToolRule.class) {
|
||||
public static final Type<ToolRule> TYPE = new Type<>(ToolRule.class) {
|
||||
@Override
|
||||
public ToolRule read(final ByteBuf buffer) throws Exception {
|
||||
public ToolRule read(final ByteBuf buffer) {
|
||||
final HolderSet blocks = Type.HOLDER_SET.read(buffer);
|
||||
final Float speed = Type.OPTIONAL_FLOAT.read(buffer);
|
||||
final Boolean correctForDrops = Type.OPTIONAL_BOOLEAN.read(buffer);
|
||||
@ -40,7 +40,7 @@ public final class ToolRule {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final ToolRule value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final ToolRule value) {
|
||||
Type.HOLDER_SET.write(buffer, value.blocks);
|
||||
Type.OPTIONAL_FLOAT.write(buffer, value.speed);
|
||||
Type.OPTIONAL_BOOLEAN.write(buffer, value.correctForDrops);
|
||||
@ -48,25 +48,4 @@ public final class ToolRule {
|
||||
};
|
||||
public static final Type<ToolRule[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||
|
||||
private final HolderSet blocks;
|
||||
private final Float speed;
|
||||
private final Boolean correctForDrops;
|
||||
|
||||
public ToolRule(final HolderSet blocks, @Nullable final Float speed, @Nullable final Boolean correctForDrops) {
|
||||
this.blocks = blocks;
|
||||
this.speed = speed;
|
||||
this.correctForDrops = correctForDrops;
|
||||
}
|
||||
|
||||
public HolderSet blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public @Nullable Float speed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public @Nullable Boolean correctForDrops() {
|
||||
return correctForDrops;
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class Unbreakable {
|
||||
public record Unbreakable(boolean showInTooltip) {
|
||||
|
||||
public static final Type<Unbreakable> TYPE = new Type<Unbreakable>(Unbreakable.class) {
|
||||
public static final Type<Unbreakable> TYPE = new Type<>(Unbreakable.class) {
|
||||
@Override
|
||||
public Unbreakable read(final ByteBuf buffer) {
|
||||
return new Unbreakable(buffer.readBoolean());
|
||||
@ -39,13 +39,4 @@ public final class Unbreakable {
|
||||
}
|
||||
};
|
||||
|
||||
private final boolean showInTooltip;
|
||||
|
||||
public Unbreakable(final boolean showInTooltip) {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public boolean showInTooltip() {
|
||||
return showInTooltip;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public final class WrittenBook {
|
||||
public record WrittenBook(FilterableString title, String author, int generation, FilterableComponent[] pages,
|
||||
boolean resolved) {
|
||||
|
||||
public static final Type<WrittenBook> TYPE = new Type<WrittenBook>(WrittenBook.class) {
|
||||
public static final Type<WrittenBook> TYPE = new Type<>(WrittenBook.class) {
|
||||
@Override
|
||||
public WrittenBook read(final ByteBuf buffer) throws Exception {
|
||||
public WrittenBook read(final ByteBuf buffer) {
|
||||
final FilterableString title = FilterableString.TYPE.read(buffer);
|
||||
final String author = Type.STRING.read(buffer);
|
||||
final int generation = Type.VAR_INT.readPrimitive(buffer);
|
||||
@ -39,7 +40,7 @@ public final class WrittenBook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final WrittenBook value) throws Exception {
|
||||
public void write(final ByteBuf buffer, final WrittenBook value) {
|
||||
FilterableString.TYPE.write(buffer, value.title);
|
||||
Type.STRING.write(buffer, value.author);
|
||||
Type.VAR_INT.writePrimitive(buffer, value.generation);
|
||||
@ -48,37 +49,4 @@ public final class WrittenBook {
|
||||
}
|
||||
};
|
||||
|
||||
private final FilterableString title;
|
||||
private final String author;
|
||||
private final int generation;
|
||||
private final FilterableComponent[] pages;
|
||||
private final boolean resolved;
|
||||
|
||||
public WrittenBook(final FilterableString title, final String author, final int generation, final FilterableComponent[] pages, final boolean resolved) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.generation = generation;
|
||||
this.pages = pages;
|
||||
this.resolved = resolved;
|
||||
}
|
||||
|
||||
public FilterableString title() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String author() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public int generation() {
|
||||
return generation;
|
||||
}
|
||||
|
||||
public FilterableComponent[] pages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public boolean resolved() {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
|
@ -22,22 +22,11 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.platform;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* @param <T> task type
|
||||
*/
|
||||
public interface PlatformTask<T> {
|
||||
|
||||
/**
|
||||
* Returns the actual object represented by this task/task id.
|
||||
* Null if task cannot be instantly tracked.
|
||||
*
|
||||
* @return platform based object, or null if not tracked/cancellable
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
@Nullable T getObject();
|
||||
|
||||
/**
|
||||
* Cancels the task.
|
||||
*
|
||||
|
@ -181,11 +181,6 @@ public interface ViaPlatform<T> {
|
||||
*/
|
||||
ViaVersionConfig getConf();
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default ConfigurationProvider getConfigurationProvider() {
|
||||
return Via.getManager().getConfigurationProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ViaVersions's data folder.
|
||||
*
|
||||
|
@ -383,7 +383,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws InformativeException, CancelException {
|
||||
PacketMappings mappings = direction == Direction.CLIENTBOUND ? clientboundMappings : serverboundMappings;
|
||||
int unmappedId = packetWrapper.getId();
|
||||
PacketMapping packetMapping = mappings.mappedPacket(state, unmappedId);
|
||||
@ -397,8 +397,6 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
if (handler != null) {
|
||||
try {
|
||||
handler.handle(packetWrapper);
|
||||
} catch (CancelException e) {
|
||||
throw e; // Pass through CancelExceptions
|
||||
} catch (InformativeException e) {
|
||||
e.addSource(handler.getClass());
|
||||
printRemapError(direction, state, unmappedId, packetWrapper.getId(), e);
|
||||
|
@ -33,11 +33,12 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
@ -62,11 +63,6 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
registerServerbound(state, packetType.getId(), packetType.getId(), handler, false);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
|
||||
}
|
||||
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
|
||||
}
|
||||
@ -85,11 +81,6 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
|
||||
void cancelServerbound(State state, int mappedPacketId);
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId) {
|
||||
registerClientbound(state, unmappedPacketId, mappedPacketId, (PacketHandler) null);
|
||||
}
|
||||
|
||||
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, @Nullable PacketHandler handler) {
|
||||
registerClientbound(state, unmappedPacketId, mappedPacketId, handler, false);
|
||||
}
|
||||
@ -126,7 +117,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
* @param mappedPacketType clientbound packet type after transforming for the client
|
||||
*/
|
||||
default void registerClientbound(CU packetType, @Nullable CM mappedPacketType) {
|
||||
registerClientbound(packetType, mappedPacketType, (PacketHandler) null);
|
||||
registerClientbound(packetType, mappedPacketType, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,7 +156,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
* @param mappedPacketType serverbound packet type after transforming for the client
|
||||
*/
|
||||
default void registerServerbound(SU packetType, @Nullable SM mappedPacketType) {
|
||||
registerServerbound(packetType, mappedPacketType, (PacketHandler) null);
|
||||
registerServerbound(packetType, mappedPacketType, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -270,9 +261,8 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
* @param direction The direction the packet is going in
|
||||
* @param state The current protocol state
|
||||
* @param packetWrapper The packet wrapper to transform
|
||||
* @throws Exception Throws exception if it fails to transform
|
||||
*/
|
||||
void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception;
|
||||
void transform(Direction direction, State state, PacketWrapper packetWrapper) throws InformativeException, CancelException;
|
||||
|
||||
/**
|
||||
* Returns a packet type provider for this protocol to get packet types by id.
|
||||
@ -392,72 +382,4 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
default boolean isBaseProtocol() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #cancelServerbound(State, int)}
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void cancelServerbound(State state, int unmappedPacketId, int mappedPacketId) {
|
||||
cancelServerbound(state, unmappedPacketId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #cancelClientbound(State, int)}
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void cancelClientbound(State state, int unmappedPacketId, int mappedPacketId) {
|
||||
cancelClientbound(state, unmappedPacketId);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketRemapper packetRemapper) {
|
||||
registerClientbound(state, unmappedPacketId, mappedPacketId, packetRemapper.asPacketHandler(), false);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerClientbound(State state, int unmappedPacketId, int mappedPacketId, PacketRemapper packetRemapper, boolean override) {
|
||||
registerClientbound(state, unmappedPacketId, mappedPacketId, packetRemapper.asPacketHandler(), override);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerClientbound(CU packetType, @Nullable PacketRemapper packetRemapper) {
|
||||
registerClientbound(packetType, packetRemapper.asPacketHandler());
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketRemapper packetRemapper) {
|
||||
registerClientbound(packetType, mappedPacketType, packetRemapper.asPacketHandler(), false);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerClientbound(CU packetType, @Nullable CM mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override) {
|
||||
registerClientbound(packetType, mappedPacketType, packetRemapper.asPacketHandler(), override);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketRemapper packetRemapper) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, packetRemapper.asPacketHandler(), false);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerServerbound(State state, int unmappedPacketId, int mappedPacketId, PacketRemapper packetRemapper, boolean override) {
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, packetRemapper.asPacketHandler(), override);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerServerbound(SU packetType, @Nullable PacketRemapper packetRemapper) {
|
||||
registerServerbound(packetType, packetRemapper.asPacketHandler());
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketRemapper packetRemapper) {
|
||||
registerServerbound(packetType, mappedPacketType, packetRemapper.asPacketHandler(), false);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void registerServerbound(SU packetType, @Nullable SM mappedPacketType, @Nullable PacketRemapper packetRemapper, boolean override) {
|
||||
registerServerbound(packetType, mappedPacketType, packetRemapper.asPacketHandler(), override);
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public interface ProtocolManager {
|
||||
/**
|
||||
* @deprecated use Protocol#isBaseProtocol()
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default boolean isBaseProtocol(Protocol protocol) {
|
||||
return protocol.isBaseProtocol();
|
||||
}
|
||||
@ -180,7 +180,6 @@ public interface ProtocolManager {
|
||||
* If set to -1, no distance checks will be applied (1→20→10 is ok).
|
||||
*
|
||||
* @param maxPathDeltaIncrease the max delta the path calculation allows the distance to the target protocol version to increase
|
||||
* @see #onlyCheckLoweringPathEntries()
|
||||
*/
|
||||
void setMaxPathDeltaIncrease(int maxPathDeltaIncrease);
|
||||
|
||||
@ -207,16 +206,6 @@ public interface ProtocolManager {
|
||||
*/
|
||||
int getMaxPathDeltaIncrease();
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setOnlyCheckLoweringPathEntries(final boolean onlyCheckLoweringPathEntries) {
|
||||
setMaxPathDeltaIncrease(onlyCheckLoweringPathEntries ? 0 : -1);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default boolean onlyCheckLoweringPathEntries() {
|
||||
return getMaxPathDeltaIncrease() != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum protocol path size applied to {@link #getProtocolPath(ProtocolVersion, ProtocolVersion)}.
|
||||
*
|
||||
@ -251,7 +240,7 @@ public interface ProtocolManager {
|
||||
*
|
||||
* @param protocolClass protocol class
|
||||
*/
|
||||
void completeMappingDataLoading(Class<? extends Protocol> protocolClass) throws Exception;
|
||||
void completeMappingDataLoading(Class<? extends Protocol> protocolClass);
|
||||
|
||||
/**
|
||||
* Shuts down the executor and uncaches mappings if all futures have been completed.
|
||||
|
@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.protocol.packet;
|
||||
/**
|
||||
* Interface to be implemented by server outgoing packet types.
|
||||
*/
|
||||
public interface ClientboundPacketType extends PacketType {
|
||||
public non-sealed interface ClientboundPacketType extends PacketType {
|
||||
|
||||
@Override
|
||||
default Direction direction() {
|
||||
|
@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public class PacketTracker {
|
||||
private final UserConnection connection;
|
||||
private boolean packetLimiterEnabled = true;
|
||||
private long sentPackets;
|
||||
private long receivedPackets;
|
||||
// Used for tracking pps
|
||||
@ -162,4 +163,12 @@ public class PacketTracker {
|
||||
public void setWarnings(int warnings) {
|
||||
this.warnings = warnings;
|
||||
}
|
||||
|
||||
public boolean isPacketLimiterEnabled() {
|
||||
return packetLimiterEnabled;
|
||||
}
|
||||
|
||||
public void setPacketLimiterEnabled(boolean packetLimiterEnabled) {
|
||||
this.packetLimiterEnabled = packetLimiterEnabled;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package com.viaversion.viaversion.api.protocol.packet;
|
||||
* @see ClientboundPacketType
|
||||
* @see ServerboundPacketType
|
||||
*/
|
||||
public interface PacketType {
|
||||
public sealed interface PacketType permits ClientboundPacketType, ServerboundPacketType {
|
||||
|
||||
/**
|
||||
* Returns the packet id for the implemented protocol.
|
||||
|
@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
@ -83,7 +84,7 @@ public interface PacketWrapper {
|
||||
* @return The requested type or throws ArrayIndexOutOfBounds
|
||||
* @throws InformativeException If it fails to find it, an exception will be thrown.
|
||||
*/
|
||||
<T> T get(Type<T> type, int index) throws Exception;
|
||||
<T> T get(Type<T> type, int index) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Check if a type is at an index
|
||||
@ -113,7 +114,7 @@ public interface PacketWrapper {
|
||||
* @param value The value of the part you wish to set it to.
|
||||
* @throws InformativeException If it fails to set it, an exception will be thrown.
|
||||
*/
|
||||
<T> void set(Type<T> type, int index, T value) throws Exception;
|
||||
<T> void set(Type<T> type, int index, @Nullable T value) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Read a type from the input.
|
||||
@ -123,7 +124,7 @@ public interface PacketWrapper {
|
||||
* @return The requested type
|
||||
* @throws InformativeException If it fails to read
|
||||
*/
|
||||
<T> T read(Type<T> type) throws Exception;
|
||||
<T> T read(Type<T> type) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Write a type to the output.
|
||||
@ -132,7 +133,7 @@ public interface PacketWrapper {
|
||||
* @param <T> The return type of the type you wish to write.
|
||||
* @param value The value of the type to write.
|
||||
*/
|
||||
<T> void write(Type<T> type, T value);
|
||||
<T> void write(Type<T> type, @Nullable T value);
|
||||
|
||||
/**
|
||||
* Take a value from the input and write to the output.
|
||||
@ -140,16 +141,16 @@ public interface PacketWrapper {
|
||||
* @param type The type to read and write.
|
||||
* @param <T> The return type of the type you wish to pass through.
|
||||
* @return The type which was read/written.
|
||||
* @throws Exception If it failed to read or write
|
||||
* @throws InformativeException If it failed to read or write
|
||||
*/
|
||||
<T> T passthrough(Type<T> type) throws Exception;
|
||||
<T> T passthrough(Type<T> type) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Take all the inputs and write them to the output.
|
||||
*
|
||||
* @throws Exception If it failed to read or write
|
||||
* @throws InformativeException If it failed to read or write
|
||||
*/
|
||||
void passthroughAll() throws Exception;
|
||||
void passthroughAll() throws InformativeException;
|
||||
|
||||
/**
|
||||
* Write the current output to a buffer.
|
||||
@ -157,7 +158,7 @@ public interface PacketWrapper {
|
||||
* @param buffer The buffer to write to.
|
||||
* @throws InformativeException Throws an exception if it fails to write a value.
|
||||
*/
|
||||
void writeToBuffer(ByteBuf buffer) throws Exception;
|
||||
void writeToBuffer(ByteBuf buffer) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Clear the input buffer / readable objects
|
||||
@ -173,9 +174,9 @@ public interface PacketWrapper {
|
||||
* Send this packet to the connection on the current thread, skipping the current protocol.
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
default void send(Class<? extends Protocol> protocol) throws Exception {
|
||||
default void send(Class<? extends Protocol> protocol) throws InformativeException {
|
||||
send(protocol, true);
|
||||
}
|
||||
|
||||
@ -184,17 +185,17 @@ public interface PacketWrapper {
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
void send(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
|
||||
void send(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Send this packet to the connection, submitted to netty's event loop and skipping the current protocol.
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
default void scheduleSend(Class<? extends Protocol> protocol) throws Exception {
|
||||
default void scheduleSend(Class<? extends Protocol> protocol) throws InformativeException {
|
||||
scheduleSend(protocol, true);
|
||||
}
|
||||
|
||||
@ -203,45 +204,33 @@ public interface PacketWrapper {
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
|
||||
* @throws Exception if it fails to write
|
||||
*/
|
||||
void scheduleSend(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
|
||||
void scheduleSend(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Send this packet to the associated user.
|
||||
* Be careful not to send packets twice.
|
||||
* (Sends it after current)
|
||||
* Also returns the packets ChannelFuture
|
||||
* Sends this packet to the associated user.
|
||||
* The ChannelFuture fails exceptionally if the packet is cancelled during construction.
|
||||
*
|
||||
* @param protocolClass the protocol class to start from in the pipeline
|
||||
* @return new ChannelFuture for the write operation
|
||||
* @throws Exception if it fails to write
|
||||
*/
|
||||
ChannelFuture sendFuture(Class<? extends Protocol> protocolClass) throws Exception;
|
||||
|
||||
/**
|
||||
* @deprecated misleading; use {@link #sendRaw()}. This method will be removed in 5.0.0
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void send() throws Exception {
|
||||
sendRaw();
|
||||
}
|
||||
ChannelFuture sendFuture(Class<? extends Protocol> protocolClass) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Sends this packet to the connection.
|
||||
* <b>Unlike {@link #send(Class)}, this method does not handle the pipeline with packet id and data changes.</b>
|
||||
*
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
void sendRaw() throws Exception;
|
||||
void sendRaw() throws InformativeException;
|
||||
|
||||
/**
|
||||
* Sends this packet to the associated user, submitted to netty's event loop.
|
||||
* <b>Unlike {@link #send(Class)}, this method does not handle the pipeline with packet id and data changes.</b>
|
||||
*
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
void scheduleSendRaw() throws Exception;
|
||||
void scheduleSendRaw() throws InformativeException;
|
||||
|
||||
/**
|
||||
* Creates a new packet for the target of this packet.
|
||||
@ -259,9 +248,8 @@ public interface PacketWrapper {
|
||||
* @param packetType packet type of the new packet
|
||||
* @param handler handler to write to the packet
|
||||
* @return newly created packet wrapper
|
||||
* @throws Exception if it failed to write the values from the ValueCreator
|
||||
*/
|
||||
default PacketWrapper create(PacketType packetType, PacketHandler handler) throws Exception {
|
||||
default PacketWrapper create(PacketType packetType, PacketHandler handler) throws InformativeException {
|
||||
return create(packetType.getId(), handler);
|
||||
}
|
||||
|
||||
@ -279,9 +267,8 @@ public interface PacketWrapper {
|
||||
* @param packetId id of the packet
|
||||
* @param handler handler to write to the packet
|
||||
* @return newly created packet wrapper
|
||||
* @throws Exception if it failed to write the values from the ValueCreator
|
||||
*/
|
||||
PacketWrapper create(int packetId, PacketHandler handler) throws Exception;
|
||||
PacketWrapper create(int packetId, PacketHandler handler) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Applies a pipeline from an index to the wrapper.
|
||||
@ -289,23 +276,8 @@ public interface PacketWrapper {
|
||||
* @param direction protocol direction
|
||||
* @param state protocol state
|
||||
* @param pipeline protocol pipeline
|
||||
* @throws Exception If it fails to transform a packet, exception will be thrown
|
||||
*/
|
||||
void apply(Direction direction, State state, List<Protocol> pipeline) throws Exception;
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #apply(Direction, State, List)}
|
||||
*/
|
||||
@Deprecated
|
||||
PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline, boolean reverse) throws Exception;
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #apply(Direction, State, List)}
|
||||
*/
|
||||
@Deprecated
|
||||
default PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception {
|
||||
return apply(direction, state, index, pipeline, false);
|
||||
}
|
||||
void apply(Direction direction, State state, List<Protocol> pipeline) throws InformativeException, CancelException;
|
||||
|
||||
/**
|
||||
* Check if this packet is cancelled.
|
||||
@ -340,41 +312,29 @@ public interface PacketWrapper {
|
||||
*/
|
||||
void resetReader();
|
||||
|
||||
/**
|
||||
* Send the current packet to the server.
|
||||
* (Ensure the ID is suitable for viaversion)
|
||||
*
|
||||
* @throws Exception If it failed to write
|
||||
* @deprecated misleading; use {@link #sendToServerRaw()}. This method will be removed in 5.0.0
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void sendToServer() throws Exception {
|
||||
sendToServerRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this packet to the server.
|
||||
* <b>Unlike {@link #sendToServer(Class)}, this method does not handle the pipeline with packet id and data changes.</b>
|
||||
*
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
void sendToServerRaw() throws Exception;
|
||||
void sendToServerRaw() throws InformativeException;
|
||||
|
||||
/**
|
||||
* Sends this packet to the server, submitted to netty's event loop.
|
||||
* <b>Unlike {@link #sendToServer(Class)}, this method does not handle the pipeline with packet id and data changes.</b>
|
||||
*
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
void scheduleSendToServerRaw() throws Exception;
|
||||
void scheduleSendToServerRaw() throws InformativeException;
|
||||
|
||||
/**
|
||||
* Send this packet to the server on the current thread, skipping the current protocol.
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
default void sendToServer(Class<? extends Protocol> protocol) throws Exception {
|
||||
default void sendToServer(Class<? extends Protocol> protocol) throws InformativeException {
|
||||
sendToServer(protocol, true);
|
||||
}
|
||||
|
||||
@ -383,17 +343,17 @@ public interface PacketWrapper {
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
void sendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
|
||||
void sendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Send this packet to the server, submitted to netty's event loop and skipping the current protocol.
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
default void scheduleSendToServer(Class<? extends Protocol> protocol) throws Exception {
|
||||
default void scheduleSendToServer(Class<? extends Protocol> protocol) throws InformativeException {
|
||||
scheduleSendToServer(protocol, true);
|
||||
}
|
||||
|
||||
@ -402,13 +362,12 @@ public interface PacketWrapper {
|
||||
*
|
||||
* @param protocol protocol to be sent through
|
||||
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
|
||||
* @throws Exception if it fails to write
|
||||
* @throws InformativeException if it fails to write
|
||||
*/
|
||||
void scheduleSendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
|
||||
void scheduleSendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Returns the packet type.
|
||||
* Currently only non-null for manually constructed packets before transformation.
|
||||
* Returns the packet type, or null if not transformed or manually unset.
|
||||
*
|
||||
* @return packet type if set
|
||||
*/
|
||||
@ -429,17 +388,6 @@ public interface PacketWrapper {
|
||||
*/
|
||||
int getId();
|
||||
|
||||
/**
|
||||
* Sets the packet type.
|
||||
*
|
||||
* @param packetType packet type
|
||||
* @deprecated use {@link #setPacketType(PacketType)}. This method will be removed in 5.0.0
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default void setId(PacketType packetType) {
|
||||
setPacketType(packetType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the packet id. If set to -1, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}.
|
||||
*
|
||||
|
@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.protocol.packet;
|
||||
/**
|
||||
* Interface to be implemented by server incoming packet types.
|
||||
*/
|
||||
public interface ServerboundPacketType extends PacketType {
|
||||
public non-sealed interface ServerboundPacketType extends PacketType {
|
||||
|
||||
@Override
|
||||
default Direction direction() {
|
||||
|
@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.protocol.packet;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import java.util.function.Consumer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@ -43,19 +44,19 @@ public interface VersionedPacketTransformer<C extends ClientboundPacketType, S e
|
||||
* @throws IllegalArgumentException if the packet type is not of the expected clientbound or serverbound packets class
|
||||
* @throws IllegalArgumentException if {@link PacketWrapper#user()} returns null
|
||||
* @throws RuntimeException if no path from the input version to the required client version exists
|
||||
* @throws Exception if an error occurred while transforming or sending the packet
|
||||
* @throws InformativeException if an error occurred while transforming or sending the packet
|
||||
*/
|
||||
boolean send(PacketWrapper packet) throws Exception;
|
||||
boolean send(PacketWrapper packet) throws InformativeException;
|
||||
|
||||
/**
|
||||
* @see #send(PacketWrapper)
|
||||
*/
|
||||
boolean send(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
|
||||
boolean send(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws InformativeException;
|
||||
|
||||
/**
|
||||
* @see #send(PacketWrapper)
|
||||
*/
|
||||
boolean send(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
|
||||
boolean send(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Sends a packet to the user or server, depending on the packet type given by {@link PacketWrapper#getPacketType()}, submitted to the netty event loop.
|
||||
@ -66,19 +67,19 @@ public interface VersionedPacketTransformer<C extends ClientboundPacketType, S e
|
||||
* @throws IllegalArgumentException if the packet type is not of the expected clientbound or serverbound packets class
|
||||
* @throws IllegalArgumentException if {@link PacketWrapper#user()} returns null
|
||||
* @throws RuntimeException if no path from the input version to the required client version exists
|
||||
* @throws Exception if an error occurred while transforming or sending the packet
|
||||
* @throws InformativeException if an error occurred while transforming or sending the packet
|
||||
*/
|
||||
boolean scheduleSend(PacketWrapper packet) throws Exception;
|
||||
boolean scheduleSend(PacketWrapper packet) throws InformativeException;
|
||||
|
||||
/**
|
||||
* @see #scheduleSend(PacketWrapper)
|
||||
*/
|
||||
boolean scheduleSend(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
|
||||
boolean scheduleSend(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws InformativeException;
|
||||
|
||||
/**
|
||||
* @see #scheduleSend(PacketWrapper)
|
||||
*/
|
||||
boolean scheduleSend(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
|
||||
boolean scheduleSend(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Transforms a packet to the protocol version of the given connection or server, or null if cancelled at some point.
|
||||
@ -89,17 +90,17 @@ public interface VersionedPacketTransformer<C extends ClientboundPacketType, S e
|
||||
* @throws IllegalArgumentException if the packet type is not of the expected clientbound or serverbound packets class
|
||||
* @throws IllegalArgumentException if {@link PacketWrapper#user()} returns null
|
||||
* @throws RuntimeException if no path from the input version to the required client version exists
|
||||
* @throws Exception if an error occurred while transforming the packet
|
||||
* @throws InformativeException if an error occurred while transforming the packet
|
||||
*/
|
||||
@Nullable PacketWrapper transform(PacketWrapper packet) throws Exception;
|
||||
@Nullable PacketWrapper transform(PacketWrapper packet) throws InformativeException;
|
||||
|
||||
/**
|
||||
* @see #transform(PacketWrapper)
|
||||
*/
|
||||
@Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
|
||||
@Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer<PacketWrapper> packetWriter) throws InformativeException;
|
||||
|
||||
/**
|
||||
* @see #transform(PacketWrapper)
|
||||
*/
|
||||
@Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws Exception;
|
||||
@Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer<PacketWrapper> packetWriter) throws InformativeException;
|
||||
}
|
||||
|
@ -27,41 +27,10 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import java.util.Map;
|
||||
|
||||
public final class SimplePacketTypesProvider<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType> implements PacketTypesProvider<CU, CM, SM, SU> {
|
||||
private final Map<State, PacketTypeMap<CU>> unmappedClientboundPacketTypes;
|
||||
private final Map<State, PacketTypeMap<CM>> mappedClientboundPacketTypes;
|
||||
private final Map<State, PacketTypeMap<SM>> mappedServerboundPacketTypes;
|
||||
private final Map<State, PacketTypeMap<SU>> unmappedServerboundPacketTypes;
|
||||
|
||||
public SimplePacketTypesProvider(
|
||||
Map<State, PacketTypeMap<CU>> unmappedClientboundPacketTypes,
|
||||
Map<State, PacketTypeMap<CM>> mappedClientboundPacketTypes,
|
||||
Map<State, PacketTypeMap<SM>> mappedServerboundPacketTypes,
|
||||
Map<State, PacketTypeMap<SU>> unmappedServerboundPacketTypes
|
||||
) {
|
||||
this.unmappedClientboundPacketTypes = unmappedClientboundPacketTypes;
|
||||
this.mappedClientboundPacketTypes = mappedClientboundPacketTypes;
|
||||
this.mappedServerboundPacketTypes = mappedServerboundPacketTypes;
|
||||
this.unmappedServerboundPacketTypes = unmappedServerboundPacketTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<State, PacketTypeMap<CU>> unmappedClientboundPacketTypes() {
|
||||
return unmappedClientboundPacketTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<State, PacketTypeMap<CM>> mappedClientboundPacketTypes() {
|
||||
return mappedClientboundPacketTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<State, PacketTypeMap<SM>> mappedServerboundPacketTypes() {
|
||||
return mappedServerboundPacketTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<State, PacketTypeMap<SU>> unmappedServerboundPacketTypes() {
|
||||
return unmappedServerboundPacketTypes;
|
||||
}
|
||||
public record SimplePacketTypesProvider<CU extends ClientboundPacketType, CM extends ClientboundPacketType, SM extends ServerboundPacketType, SU extends ServerboundPacketType>(
|
||||
Map<State, PacketTypeMap<CU>> unmappedClientboundPacketTypes,
|
||||
Map<State, PacketTypeMap<CM>> mappedClientboundPacketTypes,
|
||||
Map<State, PacketTypeMap<SM>> mappedServerboundPacketTypes,
|
||||
Map<State, PacketTypeMap<SU>> unmappedServerboundPacketTypes
|
||||
) implements PacketTypesProvider<CU, CM, SM, SU> {
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PacketHandler {
|
||||
@ -31,9 +32,8 @@ public interface PacketHandler {
|
||||
* Handles a packet.
|
||||
*
|
||||
* @param wrapper packet wrapper
|
||||
* @throws Exception if an error occurs during the packet handling
|
||||
*/
|
||||
void handle(PacketWrapper wrapper) throws Exception;
|
||||
void handle(PacketWrapper wrapper) throws InformativeException;
|
||||
|
||||
/**
|
||||
* Returns a new packet handler that runs the provided handler after this one.
|
||||
|
@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.protocol.remapper;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
@ -76,7 +77,7 @@ public abstract class PacketHandlers implements PacketHandler {
|
||||
* @param transformer transformer to produce the new type
|
||||
*/
|
||||
public <T1, T2> void map(Type<T1> oldType, Type<T2> newType, Function<T1, T2> transformer) {
|
||||
map(oldType, new ValueTransformer<T1, T2>(newType) {
|
||||
map(oldType, new ValueTransformer<>(newType) {
|
||||
@Override
|
||||
public T2 transform(PacketWrapper wrapper, T1 inputValue) {
|
||||
return transformer.apply(inputValue);
|
||||
@ -173,7 +174,7 @@ public abstract class PacketHandlers implements PacketHandler {
|
||||
protected abstract void register();
|
||||
|
||||
@Override
|
||||
public final void handle(PacketWrapper wrapper) throws Exception {
|
||||
public final void handle(PacketWrapper wrapper) throws InformativeException {
|
||||
for (PacketHandler handler : packetHandlers) {
|
||||
handler.handle(wrapper);
|
||||
}
|
||||
|
@ -1,181 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @deprecated use {@link PacketHandlers} or directly implement {@link PacketHandler}
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public abstract class PacketRemapper {
|
||||
private final List<PacketHandler> valueRemappers = new ArrayList<>();
|
||||
|
||||
protected PacketRemapper() {
|
||||
registerMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads and writes the given type.
|
||||
*
|
||||
* @param type type to map
|
||||
*/
|
||||
public void map(Type type) {
|
||||
handler(wrapper -> wrapper.write(type, wrapper.read(type)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the first given type and writes the second given type.
|
||||
*
|
||||
* @param oldType old type
|
||||
* @param newType new type
|
||||
*/
|
||||
public void map(Type oldType, Type newType) {
|
||||
handler(wrapper -> wrapper.write(newType, wrapper.read(oldType)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a type from an old type to a transformed new type.
|
||||
*
|
||||
* @param <T1> old value type
|
||||
* @param <T2> new value type
|
||||
* @param oldType old type
|
||||
* @param newType new type
|
||||
* @param transformer transformer to produce the new type
|
||||
*/
|
||||
public <T1, T2> void map(Type<T1> oldType, Type<T2> newType, Function<T1, T2> transformer) {
|
||||
map(oldType, new ValueTransformer<T1, T2>(newType) {
|
||||
@Override
|
||||
public T2 transform(PacketWrapper wrapper, T1 inputValue) throws Exception {
|
||||
return transformer.apply(inputValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a type from an old type to a transformed new type based on their input type.
|
||||
*
|
||||
* @param <T1> old value type
|
||||
* @param <T2> new value type
|
||||
* @param transformer transformer to produce the new type
|
||||
*/
|
||||
public <T1, T2> void map(ValueTransformer<T1, T2> transformer) {
|
||||
if (transformer.getInputType() == null) {
|
||||
throw new IllegalArgumentException("Use map(Type<T1>, ValueTransformer<T1, T2>) for value transformers without specified input type!");
|
||||
}
|
||||
map(transformer.getInputType(), transformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a type from an old type to a transformed new type.
|
||||
*
|
||||
* @param <T1> old value type
|
||||
* @param <T2> new value type
|
||||
* @param oldType old type
|
||||
* @param transformer transformer to produce the new type
|
||||
*/
|
||||
public <T1, T2> void map(Type<T1> oldType, ValueTransformer<T1, T2> transformer) {
|
||||
map(new TypeRemapper<>(oldType), transformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a type using a basic ValueReader to a ValueWriter.
|
||||
*
|
||||
* @param inputReader reader to read with
|
||||
* @param outputWriter writer to write with
|
||||
* @param <T> read/write type
|
||||
*/
|
||||
public <T> void map(ValueReader<T> inputReader, ValueWriter<T> outputWriter) {
|
||||
handler(wrapper -> outputWriter.write(wrapper, inputReader.read(wrapper)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a packet handler.
|
||||
*
|
||||
* @param handler packet handler
|
||||
*/
|
||||
public void handler(PacketHandler handler) {
|
||||
valueRemappers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a value.
|
||||
*
|
||||
* @param type type to write
|
||||
* @param value value to write
|
||||
*/
|
||||
public <T> void create(Type<T> type, T value) {
|
||||
handler(wrapper -> wrapper.write(type, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads (and thus removes) the given type.
|
||||
*
|
||||
* @param type type to read
|
||||
*/
|
||||
public void read(Type type) {
|
||||
handler(wrapper -> wrapper.read(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the handlers for this packet.
|
||||
*/
|
||||
public abstract void registerMap();
|
||||
|
||||
public PacketHandler asPacketHandler() {
|
||||
return PacketHandlers.fromRemapper(this.valueRemappers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a packet wrapper.
|
||||
*
|
||||
* @param packetWrapper packet wrapper to remap
|
||||
* @throws InformativeException if packet reading or writing fails
|
||||
* @throws CancelException if the packet should be cancelled
|
||||
*/
|
||||
@Deprecated
|
||||
public void remap(PacketWrapper packetWrapper) throws Exception {
|
||||
try {
|
||||
for (PacketHandler handler : valueRemappers) {
|
||||
handler.handle(packetWrapper);
|
||||
}
|
||||
} catch (CancelException e) {
|
||||
// Pass through CancelExceptions
|
||||
throw e;
|
||||
} catch (InformativeException e) {
|
||||
e.addSource(this.getClass());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// Wrap other exceptions during packet handling
|
||||
InformativeException ex = new InformativeException(e);
|
||||
ex.addSource(this.getClass());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,21 +24,17 @@ package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
|
||||
public class TypeRemapper<T> implements ValueReader<T>, ValueWriter<T> {
|
||||
private final Type<T> type;
|
||||
|
||||
public TypeRemapper(Type<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
public record TypeRemapper<T>(Type<T> type) implements ValueReader<T>, ValueWriter<T> {
|
||||
|
||||
@Override
|
||||
public T read(PacketWrapper wrapper) throws Exception {
|
||||
public T read(PacketWrapper wrapper) throws InformativeException {
|
||||
return wrapper.read(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketWrapper output, T inputValue) {
|
||||
public void write(PacketWrapper output, T inputValue) throws InformativeException {
|
||||
output.write(type, inputValue);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ValueReader<T> {
|
||||
@ -32,7 +33,6 @@ public interface ValueReader<T> {
|
||||
*
|
||||
* @param wrapper The wrapper to read from
|
||||
* @return Returns the desired type
|
||||
* @throws Exception Throws exception if it fails to read
|
||||
*/
|
||||
T read(PacketWrapper wrapper) throws Exception;
|
||||
T read(PacketWrapper wrapper) throws InformativeException;
|
||||
}
|
||||
|
@ -46,12 +46,11 @@ public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
|
||||
* @param wrapper The current packet
|
||||
* @param inputValue The input value
|
||||
* @return The value to write to the wrapper
|
||||
* @throws Exception Throws exception if it fails to transform a value
|
||||
*/
|
||||
public abstract T2 transform(PacketWrapper wrapper, T1 inputValue) throws Exception;
|
||||
public abstract T2 transform(PacketWrapper wrapper, T1 inputValue) throws InformativeException;
|
||||
|
||||
@Override
|
||||
public void write(PacketWrapper writer, T1 inputValue) throws Exception {
|
||||
public void write(PacketWrapper writer, T1 inputValue) throws InformativeException {
|
||||
try {
|
||||
writer.write(outputType, transform(writer, inputValue));
|
||||
} catch (InformativeException e) {
|
||||
|
@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ValueWriter<T> {
|
||||
@ -32,7 +33,6 @@ public interface ValueWriter<T> {
|
||||
*
|
||||
* @param wrapper The packet wrapper to write to
|
||||
* @param inputValue The value to write
|
||||
* @throws Exception Throws exception if it fails to write
|
||||
*/
|
||||
void write(PacketWrapper wrapper, T inputValue) throws Exception;
|
||||
void write(PacketWrapper wrapper, T inputValue) throws InformativeException;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
private static final List<ProtocolVersion> VERSION_LIST = new ArrayList<>();
|
||||
|
||||
public static final ProtocolVersion v1_7_2 = register(4, "1.7.2-1.7.5", new SubVersionRange("1.7", 2, 5));
|
||||
@Deprecated/*(forRemoval=true)*/ public static final ProtocolVersion v1_7_1 = v1_7_2;
|
||||
@Deprecated(forRemoval=true) public static final ProtocolVersion v1_7_1 = v1_7_2;
|
||||
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new SubVersionRange("1.7", 6, 10));
|
||||
public static final ProtocolVersion v1_8 = register(47, "1.8.x", new SubVersionRange("1.8", 0, 9));
|
||||
public static final ProtocolVersion v1_9 = register(107, "1.9");
|
||||
@ -163,7 +163,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
* @return internal index of the stored protocol version
|
||||
* @deprecated comparison should be done via the comparison methods
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static int getIndex(ProtocolVersion version) {
|
||||
return VERSION_LIST.indexOf(version);
|
||||
}
|
||||
@ -201,20 +201,6 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
private final String name;
|
||||
private final Set<String> includedVersions;
|
||||
|
||||
/**
|
||||
* @param version protocol version
|
||||
* @param name version name
|
||||
*/
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public ProtocolVersion(int version, String name) {
|
||||
this(version, -1, name, null);
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) {
|
||||
this(VersionType.RELEASE, version, snapshotVersion, name, versionRange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ProtocolVersion instance.
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user