3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-04 23:30:24 +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 Migrate EntityUtil to be cool
Fix 1.9to1.8 Fix 1.9to1.8
Fix 1.9.3to1.9.1/2 Fix 1.9.3to1.9.1/2
Fix 1.9.1/2to1.9.3/4
Fix snapshot to 1.10 Fix snapshot to 1.10
Fix BaseProtocol Fix BaseProtocol
Fix BossBar to use Generics Fix BossBar to use Generics

Datei anzeigen

@ -21,4 +21,9 @@ public class Via {
Validate.isTrue(platform != null, "ViaVersion has not loaded the Platform"); Validate.isTrue(platform != null, "ViaVersion has not loaded the Platform");
return Via.platform.getApi(); 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; 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.channel.ChannelFuture;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; 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.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair; 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.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
@ -32,6 +32,7 @@ import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
public class BaseProtocol extends Protocol { public class BaseProtocol extends Protocol {
private static Gson gson = new GsonBuilder().create(); // TODO: Possibly global gson provider?
@Override @Override
protected void registerPackets() { protected void registerPackets() {
@ -48,30 +49,32 @@ public class BaseProtocol extends Protocol {
ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); ProtocolInfo info = wrapper.user().get(ProtocolInfo.class);
String originalStatus = wrapper.get(Type.STRING, 0); String originalStatus = wrapper.get(Type.STRING, 0);
try { try {
JSONObject json = (JSONObject) new JSONParser().parse(originalStatus); JsonObject json = gson.fromJson(originalStatus, JsonObject.class);
JSONObject version = (JSONObject) json.get("version"); JsonObject version = json.get("version").getAsJsonObject();
int protocolVersion = ((Long) version.get("protocol")).intValue(); int protocolVersion = ((Long) version.get("protocol").getAsLong()).intValue();
if (ViaVersion.getConfig().isSendSupportedVersions()) //Send supported versions if (Via.getConfig().isSendSupportedVersions()) //Send supported versions
version.put("supportedVersions", ViaVersion.getInstance().getSupportedVersions()); version.add("supportedVersions", gson.toJsonTree(Via.getAPI().getSupportedVersions()));
if (ProtocolRegistry.SERVER_PROTOCOL == -1) // Set the Server protocol if the detection on startup failed if (ProtocolRegistry.SERVER_PROTOCOL == -1) // Set the Server protocol if the detection on startup failed
ProtocolRegistry.SERVER_PROTOCOL = protocolVersion; ProtocolRegistry.SERVER_PROTOCOL = protocolVersion;
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), ProtocolRegistry.SERVER_PROTOCOL); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), ProtocolRegistry.SERVER_PROTOCOL);
if (protocols != null) { if (protocols != null) {
if (protocolVersion != 9999) //Fix ServerListPlus if (protocolVersion != 9999) {
version.put("protocol", info.getProtocolVersion()); //Fix ServerListPlus
version.addProperty("protocol", info.getProtocolVersion());
}
} else { } else {
// not compatible :(, *plays very sad violin* // not compatible :(, *plays very sad violin*
wrapper.user().setActive(false); wrapper.user().setActive(false);
} }
if (ViaVersion.getConfig().getBlockedProtocols().contains(info.getProtocolVersion())) if (Via.getConfig().getBlockedProtocols().contains(info.getProtocolVersion()))
version.put("protocol", -1); // Show blocked versions as outdated version.addProperty("protocol", -1); // Show blocked versions as outdated
wrapper.set(Type.STRING, 0, json.toJSONString()); // Update value wrapper.set(Type.STRING, 0, gson.toJson(json)); // Update value
} catch (ParseException e) { } catch (JsonParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -100,14 +103,14 @@ public class BaseProtocol extends Protocol {
info.setUuid(uuid); info.setUuid(uuid);
info.setUsername(wrapper.get(Type.STRING, 1)); info.setUsername(wrapper.get(Type.STRING, 1));
// Add to ported clients // 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 if (info.getPipeline().pipes().size() == 1 && info.getPipeline().pipes().get(0).getClass() == BaseProtocol.class) // Only base protocol
wrapper.user().setActive(false); wrapper.user().setActive(false);
if (ViaVersion.getInstance().isDebug()) { if (Via.getManager().isDebug()) {
// Print out the route to console // 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[]{ new Object[]{
wrapper.get(Type.STRING, 1), wrapper.get(Type.STRING, 1),
info.getProtocolVersion(), info.getProtocolVersion(),
@ -171,11 +174,11 @@ public class BaseProtocol extends Protocol {
@Override @Override
public void handle(final PacketWrapper wrapper) throws Exception { public void handle(final PacketWrapper wrapper) throws Exception {
int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion(); 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; if (!wrapper.user().getChannel().isOpen()) return;
PacketWrapper disconnectPacket = new PacketWrapper(0x00, null, wrapper.user()); // Disconnect Packet 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 wrapper.cancel(); // cancel current
// Send and close // 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 lombok.Getter;
import org.spacehq.opennbt.tag.builtin.CompoundTag; import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.PacketWrapper; 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.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -51,7 +51,7 @@ public class BlockEntity {
updateBlockEntity(pos, (short) newId, tag, connection); updateBlockEntity(pos, (short) newId, tag, connection);
} catch (Exception e) { } catch (Exception e) {
if (ViaVersion.getInstance().isDebug()) { if (Via.getManager().isDebug()) {
System.out.println("Block Entity: " + e.getMessage() + ": " + tag); 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.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import org.bukkit.World;
import org.spacehq.opennbt.tag.builtin.CompoundTag; 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.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.type.PartialType; import us.myles.ViaVersion.api.type.PartialType;
@ -48,7 +48,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
sections[i] = section; sections[i] = section;
section.readBlocks(input); section.readBlocks(input);
section.readBlockLight(input); section.readBlockLight(input);
if (world.getEnvironment() == World.Environment.NORMAL) { if (world.getEnvironment() == Environment.NORMAL) {
section.readSkyLight(input); section.readSkyLight(input);
} }
} }

Datei anzeigen

@ -1,13 +1,13 @@
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage; package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage;
import lombok.Getter; import lombok.Getter;
import org.bukkit.World;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Environment;
@Getter @Getter
public class ClientWorld extends StoredObject { public class ClientWorld extends StoredObject {
private World.Environment environment; private Environment environment;
public ClientWorld(UserConnection user) { public ClientWorld(UserConnection user) {
super(user); super(user);
@ -17,17 +17,9 @@ public class ClientWorld extends StoredObject {
this.environment = getEnvFromId(environmentId); this.environment = getEnvFromId(environmentId);
} }
private World.Environment getEnvFromId(int id) { private Environment getEnvFromId(int id) {
switch(id) { Environment output = Environment.getEnvironmentById(id);
case -1: if (output == null) return Environment.NETHER;
return World.Environment.NETHER; return output;
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);
}
} }
} }

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.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import org.bukkit.World;
import org.spacehq.opennbt.tag.builtin.CompoundTag; 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.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.type.PartialType; import us.myles.ViaVersion.api.type.PartialType;
@ -27,8 +27,8 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
@Override @Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception { 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(); boolean replacePistons = world.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
int replacementId = ViaVersion.getConfig().getPistonReplacementId(); int replacementId = Via.getConfig().getPistonReplacementId();
int chunkX = input.readInt(); int chunkX = input.readInt();
int chunkZ = input.readInt(); int chunkZ = input.readInt();
@ -53,7 +53,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
sections[i] = section; sections[i] = section;
section.readBlocks(input); section.readBlocks(input);
section.readBlockLight(input); section.readBlockLight(input);
if (world.getEnvironment() == World.Environment.NORMAL) { if (world.getEnvironment() == Environment.NORMAL) {
section.readSkyLight(input); section.readSkyLight(input);
} }
if (replacePistons) { 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.entity.EntityType;
import org.bukkit.util.EulerAngle; import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
@ -140,7 +141,7 @@ public class MetadataRewriter {
} }
} catch (Exception e) { } catch (Exception e) {
list.remove(entry); 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!"); System.out.println("INCLUDE THIS IN YOUR ERROR LOG!");
if (type != null) if (type != null)
System.out.println("An error occurred with entity meta data for " + type + " OldID: " + entry.getId()); System.out.println("An error occurred with entity meta data for " + type + " OldID: " + entry.getId());