3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Migrate Environment to our own type (todo javadocs for it)

Dieser Commit ist enthalten in:
Myles 2016-09-25 15:00:05 +01:00
Ursprung 05930ad791
Commit 49b602994a
9 geänderte Dateien mit 79 neuen und 47 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,6 @@
Migrate EntityUtil to be cool
Fix 1.9to1.8
Fix 1.9.3to1.9.1/2
Fix 1.9.1/2to1.9.3/4
Fix snapshot to 1.10
Fix BaseProtocol
Fix BossBar to use Generics

Datei anzeigen

@ -21,4 +21,9 @@ public class Via {
Validate.isTrue(platform != null, "ViaVersion has not loaded the Platform");
return Via.platform.getApi();
}
public static ViaVersionConfig getConfig() {
Validate.isTrue(platform != null, "ViaVersion has not loaded the Platform");
return Via.platform.getConf();
}
}

Datei anzeigen

@ -0,0 +1,32 @@
package us.myles.ViaVersion.api.minecraft;
import java.util.HashMap;
import java.util.Map;
public enum Environment {
NORMAL(0),
NETHER(-1),
END(1);
private final int id;
private static final Map<Integer, Environment> lookup = new HashMap<>();
static {
for (Environment env : values()) {
lookup.put(env.getId(), env);
}
}
Environment(int id) {
this.id = id;
}
public int getId() {
return id;
}
public static Environment getEnvironmentById(int id) {
return lookup.get(id);
}
}

Datei anzeigen

@ -1,21 +1,21 @@
package us.myles.ViaVersion.protocols.base;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import io.netty.channel.ChannelFuture;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
@ -32,6 +32,7 @@ import java.util.UUID;
import java.util.logging.Level;
public class BaseProtocol extends Protocol {
private static Gson gson = new GsonBuilder().create(); // TODO: Possibly global gson provider?
@Override
protected void registerPackets() {
@ -48,30 +49,32 @@ public class BaseProtocol extends Protocol {
ProtocolInfo info = wrapper.user().get(ProtocolInfo.class);
String originalStatus = wrapper.get(Type.STRING, 0);
try {
JSONObject json = (JSONObject) new JSONParser().parse(originalStatus);
JSONObject version = (JSONObject) json.get("version");
int protocolVersion = ((Long) version.get("protocol")).intValue();
JsonObject json = gson.fromJson(originalStatus, JsonObject.class);
JsonObject version = json.get("version").getAsJsonObject();
int protocolVersion = ((Long) version.get("protocol").getAsLong()).intValue();
if (ViaVersion.getConfig().isSendSupportedVersions()) //Send supported versions
version.put("supportedVersions", ViaVersion.getInstance().getSupportedVersions());
if (Via.getConfig().isSendSupportedVersions()) //Send supported versions
version.add("supportedVersions", gson.toJsonTree(Via.getAPI().getSupportedVersions()));
if (ProtocolRegistry.SERVER_PROTOCOL == -1) // Set the Server protocol if the detection on startup failed
ProtocolRegistry.SERVER_PROTOCOL = protocolVersion;
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), ProtocolRegistry.SERVER_PROTOCOL);
if (protocols != null) {
if (protocolVersion != 9999) //Fix ServerListPlus
version.put("protocol", info.getProtocolVersion());
if (protocolVersion != 9999) {
//Fix ServerListPlus
version.addProperty("protocol", info.getProtocolVersion());
}
} else {
// not compatible :(, *plays very sad violin*
wrapper.user().setActive(false);
}
if (ViaVersion.getConfig().getBlockedProtocols().contains(info.getProtocolVersion()))
version.put("protocol", -1); // Show blocked versions as outdated
if (Via.getConfig().getBlockedProtocols().contains(info.getProtocolVersion()))
version.addProperty("protocol", -1); // Show blocked versions as outdated
wrapper.set(Type.STRING, 0, json.toJSONString()); // Update value
} catch (ParseException e) {
wrapper.set(Type.STRING, 0, gson.toJson(json)); // Update value
} catch (JsonParseException e) {
e.printStackTrace();
}
}
@ -100,14 +103,14 @@ public class BaseProtocol extends Protocol {
info.setUuid(uuid);
info.setUsername(wrapper.get(Type.STRING, 1));
// Add to ported clients
((ViaVersionPlugin) ViaVersion.getInstance()).addPortedClient(wrapper.user());
Via.getManager().addPortedClient(wrapper.user());
if (info.getPipeline().pipes().size() == 1 && info.getPipeline().pipes().get(0).getClass() == BaseProtocol.class) // Only base protocol
wrapper.user().setActive(false);
if (ViaVersion.getInstance().isDebug()) {
if (Via.getManager().isDebug()) {
// Print out the route to console
((ViaVersionPlugin) ViaVersion.getInstance()).getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}",
Via.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}",
new Object[]{
wrapper.get(Type.STRING, 1),
info.getProtocolVersion(),
@ -171,11 +174,11 @@ public class BaseProtocol extends Protocol {
@Override
public void handle(final PacketWrapper wrapper) throws Exception {
int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion();
if (ViaVersion.getConfig().getBlockedProtocols().contains(protocol)) {
if (Via.getConfig().getBlockedProtocols().contains(protocol)) {
if (!wrapper.user().getChannel().isOpen()) return;
PacketWrapper disconnectPacket = new PacketWrapper(0x00, null, wrapper.user()); // Disconnect Packet
Protocol1_9TO1_8.FIX_JSON.write(disconnectPacket, ChatColor.translateAlternateColorCodes('&', ViaVersion.getConfig().getBlockedDisconnectMsg()));
Protocol1_9TO1_8.FIX_JSON.write(disconnectPacket, ChatColor.translateAlternateColorCodes('&', Via.getConfig().getBlockedDisconnectMsg()));
wrapper.cancel(); // cancel current
// Send and close

Datei anzeigen

@ -3,7 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks;
import lombok.Getter;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.type.Type;
@ -51,7 +51,7 @@ public class BlockEntity {
updateBlockEntity(pos, (short) newId, tag, connection);
} catch (Exception e) {
if (ViaVersion.getInstance().isDebug()) {
if (Via.getManager().isDebug()) {
System.out.println("Block Entity: " + e.getMessage() + ": " + tag);
}
}

Datei anzeigen

@ -2,8 +2,8 @@ package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.bukkit.World;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.type.PartialType;
@ -48,7 +48,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
sections[i] = section;
section.readBlocks(input);
section.readBlockLight(input);
if (world.getEnvironment() == World.Environment.NORMAL) {
if (world.getEnvironment() == Environment.NORMAL) {
section.readSkyLight(input);
}
}

Datei anzeigen

@ -1,13 +1,13 @@
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage;
import lombok.Getter;
import org.bukkit.World;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Environment;
@Getter
public class ClientWorld extends StoredObject {
private World.Environment environment;
private Environment environment;
public ClientWorld(UserConnection user) {
super(user);
@ -17,17 +17,9 @@ public class ClientWorld extends StoredObject {
this.environment = getEnvFromId(environmentId);
}
private World.Environment getEnvFromId(int id) {
switch(id) {
case -1:
return World.Environment.NETHER;
case 0:
return World.Environment.NORMAL;
case 1:
return World.Environment.THE_END;
default:
return World.Environment.NETHER;
//throw new IllegalArgumentException("Invalid environment id:" + id);
}
private Environment getEnvFromId(int id) {
Environment output = Environment.getEnvironmentById(id);
if (output == null) return Environment.NETHER;
return output;
}
}

Datei anzeigen

@ -2,9 +2,9 @@ package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.types;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.bukkit.World;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.Environment;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.type.PartialType;
@ -27,8 +27,8 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
boolean replacePistons = world.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && ViaVersion.getConfig().isReplacePistons();
int replacementId = ViaVersion.getConfig().getPistonReplacementId();
boolean replacePistons = world.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
int replacementId = Via.getConfig().getPistonReplacementId();
int chunkX = input.readInt();
int chunkZ = input.readInt();
@ -53,7 +53,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
sections[i] = section;
section.readBlocks(input);
section.readBlockLight(input);
if (world.getEnvironment() == World.Environment.NORMAL) {
if (world.getEnvironment() == Environment.NORMAL) {
section.readSkyLight(input);
}
if (replacePistons) {

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import org.bukkit.entity.EntityType;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
@ -140,7 +141,7 @@ public class MetadataRewriter {
}
} catch (Exception e) {
list.remove(entry);
if (!ViaVersion.getConfig().isSuppressMetadataErrors() || ViaVersion.getInstance().isDebug()) {
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
System.out.println("INCLUDE THIS IN YOUR ERROR LOG!");
if (type != null)
System.out.println("An error occurred with entity meta data for " + type + " OldID: " + entry.getId());