cleanup code, avoid some deprecated methods, fix dedicated server packet sending and class not found

This commit is contained in:
creeper123123321 2019-03-16 17:16:13 -03:00
parent 407d66b313
commit e25b39e3f3
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
26 changed files with 567 additions and 672 deletions

View File

@ -42,11 +42,13 @@ dependencies {
shade("de.gerrygames:viarewind-core:1.4.0") { transitive = false }
shade("nl.matsv:viabackwards-core:3.0.0-19w11b") { transitive = false }
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
minecraft "com.mojang:minecraft:19w11b"
mappings "net.fabricmc:yarn:19w11b.2"
mappings "net.fabricmc:yarn:19w11b.4"
modCompile "net.fabricmc:fabric-loader:0.3.7.109"
modCompile "net.fabricmc:fabric:0.2.3.110"
modCompile "net.fabricmc:fabric:0.2.3.111"
}
jar {

View File

@ -39,7 +39,7 @@ import io.netty.channel.EventLoop;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.loader.FabricLoader;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.command.CommandSource;
import org.apache.logging.log4j.LogManager;
import us.myles.ViaVersion.ViaManager;
@ -66,10 +66,21 @@ public class ViaFabric implements ModInitializer {
}
public static String getVersion() {
return FabricLoader.INSTANCE.getModContainer("viafabric")
return FabricLoader.getInstance().getModContainer("viafabric")
.get().getMetadata().getVersion().getFriendlyString();
}
private static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
return LiteralArgumentBuilder.<S>literal(commandName)
.then(
RequiredArgumentBuilder
.<S, String>argument("args", StringArgumentType.greedyString())
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
.suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
)
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
}
@Override
public void onInitialize() {
Via.init(ViaManager.builder()
@ -83,7 +94,7 @@ public class ViaFabric implements ModInitializer {
new VRRewindPlatform().init();
new VRBackwardsPlatform().init();
if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
try {
Class.forName("io.github.cottonmc.clientcommands.ClientCommands")
.getMethod("registerCommand", Consumer.class)
@ -105,15 +116,4 @@ public class ViaFabric implements ModInitializer {
Via.getPlatform().getLogger().warning("Fabric API isn't installed");
}
}
private static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
return LiteralArgumentBuilder.<S>literal(commandName)
.then(
RequiredArgumentBuilder
.<S, String>argument("args", StringArgumentType.greedyString())
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
.suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
)
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
}
}

View File

@ -25,7 +25,8 @@
package com.github.creeper123123321.viafabric.commands;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.FabricLoader;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.server.command.CommandSource;
@ -53,8 +54,8 @@ public class NMSCommandSender implements ViaCommandSender {
public void sendMessage(String s) {
if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(s)), false);
} else if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
FabricLoader.INSTANCE.getEnvironmentHandler().getClientPlayer()
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
MinecraftClient.getInstance().player
.appendCommandFeedback(TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(s)));
}
}
@ -64,8 +65,8 @@ public class NMSCommandSender implements ViaCommandSender {
if (source instanceof ServerCommandSource) {
Entity entity = ((ServerCommandSource) source).getEntity();
if (entity != null) return entity.getUuid();
} else if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
return FabricLoader.INSTANCE.getEnvironmentHandler().getClientPlayer().getUuid();
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
return MinecraftClient.getInstance().player.getUuid();
}
return UUID.fromString(getName());
}
@ -74,8 +75,8 @@ public class NMSCommandSender implements ViaCommandSender {
public String getName() {
if (source instanceof ServerCommandSource) {
return ((ServerCommandSource) source).getName();
} else if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
return FabricLoader.INSTANCE.getEnvironmentHandler().getClientPlayer().getEntityName();
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
return MinecraftClient.getInstance().player.getEntityName();
}
return "?";
}

View File

@ -30,7 +30,6 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandSource;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.commands.ViaCommandHandler;
import java.util.concurrent.CompletableFuture;
@ -50,9 +49,7 @@ public class VRCommandHandler extends ViaCommandHandler {
args = StringArgumentType.getString(ctx, "args").split(" ");
} catch (IllegalArgumentException ignored) {
}
Via.getManager()
.getCommandHandler()
.onCommand(
onCommand(
new NMSCommandSender(ctx.getSource()),
args
);

View File

@ -37,7 +37,6 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
public class VRDecodeHandler extends ByteToMessageDecoder {
@ -100,13 +99,11 @@ public class VRDecodeHandler extends ByteToMessageDecoder {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
super.channelRead(ctx, msg);
//}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
public void channelInactive(ChannelHandlerContext ctx) {
ProtocolInfo info = user.get(ProtocolInfo.class);
if (info.getUuid() != null) {
Via.getManager().removePortedClient(info.getUuid());

View File

@ -37,7 +37,6 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
public class VREncodeHandler extends MessageToByteEncoder {
private UserConnection user;
@ -110,8 +109,6 @@ public class VREncodeHandler extends MessageToByteEncoder {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
//try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
super.write(ctx, msg, promise);
//}
}
}

View File

@ -113,7 +113,7 @@ public class FabricDecodeHandler extends ByteToMessageDecoder {
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
public void channelInactive(ChannelHandlerContext ctx) {
ProtocolInfo pi = info.get(ProtocolInfo.class);
if (pi.getUuid() != null) {
Via.getManager().removePortedClient(pi.getUuid());

View File

@ -28,7 +28,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException;

View File

@ -29,7 +29,6 @@ import com.github.creeper123123321.viafabric.util.VersionFormatFilter;
import net.minecraft.client.gui.Screen;
import net.minecraft.client.gui.menu.MultiplayerScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.resource.language.I18n;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;

View File

@ -45,11 +45,11 @@ public class VRInjector implements ViaInjector {
@Override
public String getEncoderName() {
throw new UnsupportedOperationException();
return "encoder";
}
@Override
public String getDecoderName() {
throw new UnsupportedOperationException();
return "decoder";
}
}

View File

@ -29,8 +29,11 @@ import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
import com.github.creeper123123321.viafabric.commands.UserCommandSender;
import com.github.creeper123123321.viafabric.protocol.ClientSideReference;
import com.github.creeper123123321.viafabric.util.FutureTaskId;
import net.fabricmc.loader.FabricLoader;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.ModContainer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
@ -53,6 +56,7 @@ import us.myles.ViaVersion.sponge.VersionInfo;
import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.gson.JsonObject;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -63,7 +67,21 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
public class VRPlatform implements ViaPlatform {
private VRViaConfig config = new VRViaConfig(FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viaversion.yml").toFile());
private VRViaConfig config = new VRViaConfig(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric").resolve("viaversion.yml").toFile());
@Nullable
public static MinecraftServer getServer() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getIntegratedServer();
}
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
@Environment(EnvType.CLIENT)
@Nullable
private static MinecraftServer getIntegratedServer() {
return MinecraftClient.getInstance().getServer();
}
@Override
public Logger getLogger() {
@ -106,7 +124,7 @@ public class VRPlatform implements ViaPlatform {
// Kick task needs to be on main thread
Executor executor = ViaFabric.EVENT_LOOP;
boolean alreadyLogged;
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
MinecraftServer server = getServer();
if (server != null) {
alreadyLogged = true;
executor = server;
@ -161,7 +179,7 @@ public class VRPlatform implements ViaPlatform {
@Override
public ViaCommandSender[] getOnlinePlayers() {
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
MinecraftServer server = getServer();
if (server != null && server.method_18854()) {
// Not thread safe
return server.getPlayerManager().getPlayerList().stream()
@ -190,7 +208,7 @@ public class VRPlatform implements ViaPlatform {
}
} else {
runSync(() -> {
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
MinecraftServer server = getServer();
if (server == null) return;
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return;
@ -212,7 +230,7 @@ public class VRPlatform implements ViaPlatform {
e.printStackTrace();
}
} else {
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
MinecraftServer server = getServer();
if (server != null && server.method_18854()) {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false;
@ -251,7 +269,7 @@ public class VRPlatform implements ViaPlatform {
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();
List<PluginInfo> mods = new ArrayList<>();
for (ModContainer mod : FabricLoader.INSTANCE.getModContainers()) {
for (ModContainer mod : net.fabricmc.loader.FabricLoader.INSTANCE.getModContainers()) {
mods.add(new PluginInfo(true,
mod.getMetadata().getName(),
mod.getMetadata().getVersion().getFriendlyString(),
@ -270,5 +288,4 @@ public class VRPlatform implements ViaPlatform {
public boolean isOldClientsAllowed() {
return true;
}
}

View File

@ -28,12 +28,12 @@ import com.github.creeper123123321.viafabric.ViaFabric;
import de.gerrygames.viarewind.api.ViaRewindConfig;
import de.gerrygames.viarewind.api.ViaRewindConfigImpl;
import de.gerrygames.viarewind.api.ViaRewindPlatform;
import net.fabricmc.loader.FabricLoader;
import net.fabricmc.loader.api.FabricLoader;
import java.util.logging.Logger;
public class VRRewindPlatform implements ViaRewindPlatform {
private static ViaRewindConfig config = new ViaRewindConfigImpl(FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viarewind.yml").toFile());
private static ViaRewindConfig config = new ViaRewindConfigImpl(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric").resolve("viarewind.yml").toFile());
public void init() {
init(config);

View File

@ -46,15 +46,16 @@ public class VRViaAPI implements ViaAPI<Void> {
@Override
public int getPlayerVersion(UUID uuid) {
if (!isPorted(uuid)) {
UserConnection con = Via.getManager().getPortedPlayers().get(uuid);
if (con != null) {
return con.get(ProtocolInfo.class).getProtocolVersion();
}
try {
return Via.getManager().getInjector().getServerProtocolVersion();
} catch (Exception e) {
e.printStackTrace();
throw new AssertionError(e);
}
}
return Via.getManager().getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
}
@Override
@Deprecated

View File

@ -66,7 +66,7 @@ public class Protocol1_7_6_10to1_7_1_5 extends Protocol {
map(Type.STRING);
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.VAR_INT, 0);
}
});

View File

@ -57,12 +57,48 @@ import java.util.UUID;
// Based on https://github.com/Gerrygames/ClientViaVersion
public class Protocol1_8TO1_7_6_10 extends Protocol {
private static ValueReader xyzToPosition = (ValueReader<Position>) packetWrapper -> {
private static ValueReader<Position> xyzToPosition = packetWrapper -> {
long x = packetWrapper.read(Type.INT);
long y = packetWrapper.read(Type.INT);
long z = packetWrapper.read(Type.INT);
return new Position(x, y, z);
};
private static ArrayList<Integer> placeable = new ArrayList<>();
static {
placeable.add(6);
placeable.add(27);
placeable.add(28);
placeable.add(30);
placeable.add(31);
placeable.add(32);
placeable.add(37);
placeable.add(38);
placeable.add(39);
placeable.add(40);
placeable.add(50);
placeable.add(65);
placeable.add(66);
placeable.add(69);
placeable.add(70);
placeable.add(72);
placeable.add(76);
placeable.add(77);
placeable.add(96);
placeable.add(106);
placeable.add(111);
placeable.add(131);
placeable.add(143);
placeable.add(147);
placeable.add(148);
placeable.add(157);
placeable.add(167);
placeable.add(175);
for (int i = 256; i <= 378; i++) placeable.add(i);
for (int i = 381; i <= 396; i++) placeable.add(i);
for (int i = 398; i <= 452; i++) placeable.add(i);
for (int i = 2256; i <= 2267; i++) placeable.add(i);
}
@Override
protected void registerPackets() {
@ -86,7 +122,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.STRING); //Level Type
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BOOLEAN, false); //Reduced Debug Info
}
});
@ -100,7 +136,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.STRING); //Chat Message
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BYTE, (byte) 0); //Position (chat box)
}
});
@ -519,7 +555,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.BYTE); //z
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BOOLEAN, true); //OnGround
}
});
@ -535,7 +571,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.BYTE); //pitch
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BOOLEAN, true); //OnGround
}
});
@ -554,7 +590,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.BYTE); //pitch
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BOOLEAN, true); //OnGround
}
});
@ -573,7 +609,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.BYTE); //pitch
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BOOLEAN, true); //OnGround
}
});
@ -622,7 +658,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.SHORT, Type.VAR_INT); //Duration
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BOOLEAN, false);
}
}); //Hide Particles
@ -911,7 +947,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
items = new Item[old.length + 1];
items[0] = old[0];
System.arraycopy(old, 1, items, 2, old.length - 1);
items[1] = new Item((short) 351, (byte) 3, (short) 4, null);
items[1] = new Item(351, (byte) 3, (short) 4, null);
}
packetWrapper.write(Type.ITEM_ARRAY, items); //Items
}
@ -1309,7 +1345,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
Item item = packetWrapper.read(Type.ITEM);
packetWrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, item);
if (isPlayerInsideBlock(x, y, z, direction) && !isPlaceable(item.getId()))
if (isPlayerInsideBlock(x, y, z, direction) && !isPlaceable(item.getIdentifier()))
packetWrapper.cancel();
for (int i = 0; i < 3; i++) {
@ -1331,7 +1367,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
public void registerMap() {
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.INT, 0); //Entity Id, hopefully 0 is ok
packetWrapper.write(Type.BYTE, (byte) 1); //Animation
}
@ -1452,7 +1488,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
map(Type.BOOLEAN);
create(new ValueCreator() {
@Override
public void write(PacketWrapper packetWrapper) throws Exception {
public void write(PacketWrapper packetWrapper) {
packetWrapper.write(Type.BYTE, (byte) 0);
}
});
@ -1564,43 +1600,6 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
return false;
}
private static ArrayList<Integer> placeable = new ArrayList<>();
static {
placeable.add(6);
placeable.add(27);
placeable.add(28);
placeable.add(30);
placeable.add(31);
placeable.add(32);
placeable.add(37);
placeable.add(38);
placeable.add(39);
placeable.add(40);
placeable.add(50);
placeable.add(65);
placeable.add(66);
placeable.add(69);
placeable.add(70);
placeable.add(72);
placeable.add(76);
placeable.add(77);
placeable.add(96);
placeable.add(106);
placeable.add(111);
placeable.add(131);
placeable.add(143);
placeable.add(147);
placeable.add(148);
placeable.add(157);
placeable.add(167);
placeable.add(175);
for (int i = 256; i <= 378; i++) placeable.add(i);
for (int i = 381; i <= 396; i++) placeable.add(i);
for (int i = 398; i <= 452; i++) placeable.add(i);
for (int i = 2256; i <= 2267; i++) placeable.add(i);
}
private boolean isPlaceable(int id) {
return placeable.contains(id);
}
@ -1680,9 +1679,20 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
ITEM_TAKE("take"),
MOB_APPEARANCE("mobappearance");
private static final HashMap<String, Particle> particleMap = new HashMap<>();
static {
Particle[] particles = values();
int var1 = particles.length;
for (Particle particle : particles) {
particleMap.put(particle.name, particle);
}
}
public final String name;
public final int extra;
private static final HashMap<String, Particle> particleMap = new HashMap<>();
Particle(String name) {
this(name, 0);
@ -1696,15 +1706,5 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
public static Particle find(String part) {
return particleMap.get(part);
}
static {
Particle[] particles = values();
int var1 = particles.length;
for (Particle particle : particles) {
particleMap.put(particle.name, particle);
}
}
}
}

View File

@ -76,6 +76,10 @@ public class ExtendedBlockStorage {
return this.blockLSBArray;
}
public void setBlockLSBArray(byte[] paramArrayOfByte) {
this.blockLSBArray = paramArrayOfByte;
}
public boolean isEmpty() {
return this.blockMSBArray == null;
}
@ -88,6 +92,10 @@ public class ExtendedBlockStorage {
return this.blockMSBArray;
}
public void setBlockMSBArray(NibbleArray paramNibbleArray) {
this.blockMSBArray = paramNibbleArray;
}
public NibbleArray getMetadataArray() {
return this.blockMetadataArray;
}
@ -96,30 +104,22 @@ public class ExtendedBlockStorage {
return this.blocklightArray;
}
public NibbleArray getSkylightArray() {
return this.skylightArray;
}
public void setBlockLSBArray(byte[] paramArrayOfByte) {
this.blockLSBArray = paramArrayOfByte;
}
public void setBlockMSBArray(NibbleArray paramNibbleArray) {
this.blockMSBArray = paramNibbleArray;
}
public void setBlockMetadataArray(NibbleArray paramNibbleArray) {
this.blockMetadataArray = paramNibbleArray;
}
public void setBlocklightArray(NibbleArray paramNibbleArray) {
this.blocklightArray = paramNibbleArray;
}
public NibbleArray getSkylightArray() {
return this.skylightArray;
}
public void setSkylightArray(NibbleArray paramNibbleArray) {
this.skylightArray = paramNibbleArray;
}
public void setBlockMetadataArray(NibbleArray paramNibbleArray) {
this.blockMetadataArray = paramNibbleArray;
}
public NibbleArray createBlockMSBArray() {
this.blockMSBArray = new NibbleArray(this.blockLSBArray.length);
return this.blockMSBArray;

View File

@ -39,6 +39,10 @@ public class Tablist extends StoredObject {
super(user);
}
public static boolean shouldUpdateDisplayName(String oldName, String newName) {
return oldName == null && newName != null || oldName != null && newName == null || oldName != null && !oldName.equals(newName);
}
public TabListEntry getTabListEntry(String name) {
for (TabListEntry entry : tablist) if (name.equals(entry.name)) return entry;
return null;
@ -57,10 +61,6 @@ public class Tablist extends StoredObject {
tablist.add(entry);
}
public static boolean shouldUpdateDisplayName(String oldName, String newName) {
return oldName == null && newName != null || oldName != null && newName == null || oldName != null && !oldName.equals(newName);
}
public static class TabListEntry {
public String name;
public String displayName;

View File

@ -1,115 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 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.github.creeper123123321.viafabric.util;
import com.google.common.base.Joiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// Based on ViaVersion's Version
public class Version implements Comparable<Version> {
private static final Pattern semVer = Pattern.compile("(?<a>0|[1-9]\\d*)\\.(?<b>0|[1-9]\\d*)(?:\\.(?<c>0|[1-9]\\d*))?(?:-(?<tag>[A-z0-9.-]*))?");
private final int[] parts = new int[3];
private String tag;
public Version(String value) {
if (value == null) {
throw new IllegalArgumentException("Version can not be null");
} else {
Matcher matcher = semVer.matcher(value);
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid version format");
} else {
this.parts[0] = Integer.parseInt(matcher.group("a"));
this.parts[1] = Integer.parseInt(matcher.group("b"));
this.parts[2] = matcher.group("c") == null ? 0 : Integer.parseInt(matcher.group("c"));
this.tag = matcher.group("tag") == null ? "" : matcher.group("tag");
}
}
}
public static int compare(Version verA, Version verB) {
if (verA == verB) {
return 0;
} else if (verA == null) {
return -1;
} else if (verB == null) {
return 1;
} else {
int max = Math.max(verA.parts.length, verB.parts.length);
for(int i = 0; i < max; ++i) {
int partA = i < verA.parts.length ? verA.parts[i] : 0;
int partB = i < verB.parts.length ? verB.parts[i] : 0;
if (partA < partB) {
return -1;
}
if (partA > partB) {
return 1;
}
}
// ViaFabric
if (verA.tag.isEmpty() && verB.tag.isEmpty()) {
return 0;
}
if (verA.tag.isEmpty()) {
return 1;
}
if (verB.tag.isEmpty()) {
return -1;
}
return verA.tag.compareTo(verB.tag);
}
}
public static boolean equals(Version verA, Version verB) {
return verA == verB || verA != null && verB != null && compare(verA, verB) == 0;
}
public String toString() {
String[] split = new String[this.parts.length];
for(int i = 0; i < this.parts.length; ++i) {
split[i] = String.valueOf(this.parts[i]);
}
return Joiner.on(".").join(split) + (this.tag.length() != 0 ? "-" + this.tag : "");
}
public int compareTo(Version that) {
return compare(this, that);
}
public boolean equals(Object that) {
return that instanceof Version && equals(this, (Version)that);
}
public String getTag() {
return this.tag;
}
}