mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +01:00
More interfaces, keep ProtocolRegistry.SERVER_PROTOCOL legacy api
This commit is contained in:
parent
d4bc31d11e
commit
318c49cf30
@ -20,14 +20,14 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.platform;
|
||||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
public interface TaskId {
|
||||
/**
|
||||
* Returns the actual object represented by this TaskId
|
||||
* Null if task cannot be cancelled.
|
||||
*
|
||||
* @return Platform based Object (don't assume)
|
||||
*/
|
||||
Object getObject();
|
||||
/**
|
||||
* @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;
|
||||
}
|
@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.connection;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -65,7 +65,7 @@ public interface ProtocolInfo {
|
||||
*
|
||||
* @return username, set when entering the {@link State#PLAY} state
|
||||
*/
|
||||
@MonotonicNonNull String getUsername();
|
||||
@Nullable String getUsername();
|
||||
|
||||
void setUsername(String username);
|
||||
|
||||
@ -75,7 +75,7 @@ public interface ProtocolInfo {
|
||||
*
|
||||
* @return uuid, set when entering the {@link State#PLAY} state
|
||||
*/
|
||||
UUID getUuid();
|
||||
@Nullable UUID getUuid();
|
||||
|
||||
void setUuid(UUID uuid);
|
||||
|
||||
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2021 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.data;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class IntArrayMappings implements Mappings {
|
||||
protected final int[] oldToNew;
|
||||
|
||||
public IntArrayMappings(int[] oldToNew) {
|
||||
this.oldToNew = oldToNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps old identifiers to the new ones.
|
||||
* If an old value cannot be found in the new mappings, the diffmapping will be checked for the given entry.
|
||||
*
|
||||
* @param size set size of the underlying short array
|
||||
* @param oldMapping mappings to map from
|
||||
* @param newMapping mappings to map to
|
||||
* @param diffMapping extra mappings that will be used/scanned when an entry cannot be found
|
||||
*/
|
||||
public IntArrayMappings(int size, JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) {
|
||||
oldToNew = new int[size];
|
||||
Arrays.fill(oldToNew, -1);
|
||||
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping);
|
||||
}
|
||||
|
||||
public IntArrayMappings(JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) {
|
||||
this(oldMapping.entrySet().size(), oldMapping, newMapping, diffMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps old identifiers to the new ones.
|
||||
*
|
||||
* @param size set size of the underlying short array
|
||||
* @param oldMapping mappings to map from
|
||||
* @param newMapping mappings to map to
|
||||
*/
|
||||
public IntArrayMappings(int size, JsonObject oldMapping, JsonObject newMapping) {
|
||||
oldToNew = new int[size];
|
||||
Arrays.fill(oldToNew, -1);
|
||||
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping);
|
||||
}
|
||||
|
||||
public IntArrayMappings(JsonObject oldMapping, JsonObject newMapping) {
|
||||
this(oldMapping.entrySet().size(), oldMapping, newMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps old identifiers to the new ones.
|
||||
*
|
||||
* @param size set size of the underlying short array
|
||||
* @param oldMapping mappings to map from
|
||||
* @param newMapping mappings to map to
|
||||
* @param diffMapping extra mappings that will be used/scanned when an entry cannot be found
|
||||
* @param warnOnMissing should "No key for x" be printed if there is no matching identifier
|
||||
*/
|
||||
public IntArrayMappings(int size, JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) {
|
||||
oldToNew = new int[size];
|
||||
Arrays.fill(oldToNew, -1);
|
||||
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing);
|
||||
}
|
||||
|
||||
public IntArrayMappings(int size, JsonArray oldMapping, JsonArray newMapping, boolean warnOnMissing) {
|
||||
this(size, oldMapping, newMapping, null, warnOnMissing);
|
||||
}
|
||||
|
||||
public IntArrayMappings(JsonArray oldMapping, JsonArray newMapping, boolean warnOnMissing) {
|
||||
this(oldMapping.size(), oldMapping, newMapping, warnOnMissing);
|
||||
}
|
||||
|
||||
public IntArrayMappings(int size, JsonArray oldMapping, JsonArray newMapping) {
|
||||
this(size, oldMapping, newMapping, true);
|
||||
}
|
||||
|
||||
public IntArrayMappings(JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping) {
|
||||
this(oldMapping.size(), oldMapping, newMapping, diffMapping, true);
|
||||
}
|
||||
|
||||
public IntArrayMappings(JsonArray oldMapping, JsonArray newMapping) {
|
||||
this(oldMapping.size(), oldMapping, newMapping, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewId(int id) {
|
||||
return id >= 0 && id < oldToNew.length ? oldToNew[id] : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNewId(int id, int newId) {
|
||||
oldToNew[id] = newId;
|
||||
}
|
||||
|
||||
public int[] getOldToNew() {
|
||||
return oldToNew;
|
||||
}
|
||||
}
|
@ -22,138 +22,65 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.util.Int2IntBiMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class MappingData {
|
||||
protected final String oldVersion;
|
||||
protected final String newVersion;
|
||||
protected final boolean hasDiffFile;
|
||||
protected Int2IntBiMap itemMappings;
|
||||
protected ParticleMappings particleMappings;
|
||||
protected Mappings blockMappings;
|
||||
protected Mappings blockStateMappings;
|
||||
protected Mappings soundMappings;
|
||||
protected Mappings statisticsMappings;
|
||||
protected boolean loadItems = true;
|
||||
|
||||
public MappingData(String oldVersion, String newVersion) {
|
||||
this(oldVersion, newVersion, false);
|
||||
}
|
||||
|
||||
public MappingData(String oldVersion, String newVersion, boolean hasDiffFile) {
|
||||
this.oldVersion = oldVersion;
|
||||
this.newVersion = newVersion;
|
||||
this.hasDiffFile = hasDiffFile;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
Via.getPlatform().getLogger().info("Loading " + oldVersion + " -> " + newVersion + " mappings...");
|
||||
JsonObject diffmapping = hasDiffFile ? loadDiffFile() : null;
|
||||
JsonObject oldMappings = MappingDataLoader.loadData("mapping-" + oldVersion + ".json", true);
|
||||
JsonObject newMappings = MappingDataLoader.loadData("mapping-" + newVersion + ".json", true);
|
||||
|
||||
blockMappings = loadFromObject(oldMappings, newMappings, diffmapping, "blocks");
|
||||
blockStateMappings = loadFromObject(oldMappings, newMappings, diffmapping, "blockstates");
|
||||
soundMappings = loadFromArray(oldMappings, newMappings, diffmapping, "sounds");
|
||||
statisticsMappings = loadFromArray(oldMappings, newMappings, diffmapping, "statistics");
|
||||
|
||||
Mappings particles = loadFromArray(oldMappings, newMappings, diffmapping, "particles");
|
||||
if (particles != null) {
|
||||
particleMappings = new ParticleMappings(oldMappings.getAsJsonArray("particles"), particles);
|
||||
}
|
||||
|
||||
if (loadItems && newMappings.has("items")) {
|
||||
itemMappings = new Int2IntBiMap();
|
||||
itemMappings.defaultReturnValue(-1);
|
||||
MappingDataLoader.mapIdentifiers(itemMappings, oldMappings.getAsJsonObject("items"), newMappings.getAsJsonObject("items"),
|
||||
diffmapping != null ? diffmapping.getAsJsonObject("items") : null);
|
||||
}
|
||||
|
||||
loadExtras(oldMappings, newMappings, diffmapping);
|
||||
}
|
||||
|
||||
public int getNewBlockStateId(int id) {
|
||||
return checkValidity(id, blockStateMappings.getNewId(id), "blockstate");
|
||||
}
|
||||
|
||||
public int getNewBlockId(int id) {
|
||||
return checkValidity(id, blockMappings.getNewId(id), "block");
|
||||
}
|
||||
|
||||
public int getNewItemId(int id) {
|
||||
return checkValidity(id, itemMappings.get(id), "item");
|
||||
}
|
||||
|
||||
public int getOldItemId(int id) {
|
||||
int oldId = itemMappings.inverse().get(id);
|
||||
// Remap new items to stone
|
||||
return oldId != -1 ? oldId : 1;
|
||||
}
|
||||
|
||||
public int getNewParticleId(int id) {
|
||||
return checkValidity(id, particleMappings.getMappings().getNewId(id), "particles");
|
||||
}
|
||||
|
||||
public @Nullable Int2IntBiMap getItemMappings() {
|
||||
return itemMappings;
|
||||
}
|
||||
|
||||
public @Nullable ParticleMappings getParticleMappings() {
|
||||
return particleMappings;
|
||||
}
|
||||
|
||||
public @Nullable Mappings getBlockMappings() {
|
||||
return blockMappings;
|
||||
}
|
||||
|
||||
public @Nullable Mappings getBlockStateMappings() {
|
||||
return blockStateMappings;
|
||||
}
|
||||
|
||||
public @Nullable Mappings getSoundMappings() {
|
||||
return soundMappings;
|
||||
}
|
||||
|
||||
public @Nullable Mappings getStatisticsMappings() {
|
||||
return statisticsMappings;
|
||||
}
|
||||
|
||||
protected @Nullable Mappings loadFromArray(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
|
||||
if (!oldMappings.has(key) || !newMappings.has(key)) return null;
|
||||
|
||||
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
|
||||
return new Mappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), diff);
|
||||
}
|
||||
|
||||
protected @Nullable Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
|
||||
if (!oldMappings.has(key) || !newMappings.has(key)) return null;
|
||||
|
||||
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
|
||||
return new Mappings(oldMappings.getAsJsonObject(key), newMappings.getAsJsonObject(key), diff);
|
||||
}
|
||||
|
||||
protected JsonObject loadDiffFile() {
|
||||
return MappingDataLoader.loadData("mappingdiff-" + oldVersion + "to" + newVersion + ".json");
|
||||
}
|
||||
|
||||
protected int checkValidity(int id, int mappedId, String type) {
|
||||
if (mappedId == -1) {
|
||||
Via.getPlatform().getLogger().warning(String.format("Missing %s %s for %s %s %d", newVersion, type, oldVersion, type, id));
|
||||
return 0;
|
||||
}
|
||||
return mappedId;
|
||||
}
|
||||
public interface MappingData {
|
||||
|
||||
/**
|
||||
* To be overridden.
|
||||
*
|
||||
* @param oldMappings old mappings
|
||||
* @param newMappings new mappings
|
||||
* @param diffMappings diff mappings if present
|
||||
* Loads the mapping data.
|
||||
*/
|
||||
protected void loadExtras(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings) {
|
||||
}
|
||||
void load();
|
||||
|
||||
/**
|
||||
* Returns the mapped block state id, or -1 if unmapped.
|
||||
*
|
||||
* @param id unmapped block state id
|
||||
* @return mapped block state id, or -1 if unmapped
|
||||
*/
|
||||
int getNewBlockStateId(int id);
|
||||
|
||||
/**
|
||||
* Returns the mapped block id, or -1 if unmapped.
|
||||
*
|
||||
* @param id unmapped block id
|
||||
* @return mapped block id, or -1 if unmapped
|
||||
*/
|
||||
int getNewBlockId(int id);
|
||||
|
||||
/**
|
||||
* Returns the mapped item id, or -1 if unmapped.
|
||||
*
|
||||
* @param id unmapped item id
|
||||
* @return mapped item id, or -1 if unmapped
|
||||
*/
|
||||
int getNewItemId(int id);
|
||||
|
||||
/**
|
||||
* Returns the backwards mapped item id, or -1 if unmapped.
|
||||
*
|
||||
* @param id mapped item id
|
||||
* @return backwards mapped item id, or -1 if unmapped
|
||||
*/
|
||||
int getOldItemId(int id);
|
||||
|
||||
/**
|
||||
* Returns the mapped particle id, or -1 if unmapped.
|
||||
*
|
||||
* @param id unmapped particle id
|
||||
* @return mapped particle id, or -1 if unmapped
|
||||
*/
|
||||
int getNewParticleId(int id);
|
||||
|
||||
@Nullable Int2IntBiMap getItemMappings();
|
||||
|
||||
@Nullable ParticleMappings getParticleMappings();
|
||||
|
||||
@Nullable Mappings getBlockMappings();
|
||||
|
||||
@Nullable Mappings getBlockStateMappings();
|
||||
|
||||
@Nullable Mappings getSoundMappings();
|
||||
|
||||
@Nullable Mappings getStatisticsMappings();
|
||||
}
|
||||
|
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2021 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.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.util.Int2IntBiHashMap;
|
||||
import com.viaversion.viaversion.util.Int2IntBiMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MappingDataBase implements MappingData {
|
||||
protected final String oldVersion;
|
||||
protected final String newVersion;
|
||||
protected final boolean hasDiffFile;
|
||||
protected Int2IntBiMap itemMappings;
|
||||
protected ParticleMappings particleMappings;
|
||||
protected Mappings blockMappings;
|
||||
protected Mappings blockStateMappings;
|
||||
protected Mappings soundMappings;
|
||||
protected Mappings statisticsMappings;
|
||||
protected boolean loadItems = true;
|
||||
|
||||
public MappingDataBase(String oldVersion, String newVersion) {
|
||||
this(oldVersion, newVersion, false);
|
||||
}
|
||||
|
||||
public MappingDataBase(String oldVersion, String newVersion, boolean hasDiffFile) {
|
||||
this.oldVersion = oldVersion;
|
||||
this.newVersion = newVersion;
|
||||
this.hasDiffFile = hasDiffFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
getLogger().info("Loading " + oldVersion + " -> " + newVersion + " mappings...");
|
||||
JsonObject diffmapping = hasDiffFile ? loadDiffFile() : null;
|
||||
JsonObject oldMappings = MappingDataLoader.loadData("mapping-" + oldVersion + ".json", true);
|
||||
JsonObject newMappings = MappingDataLoader.loadData("mapping-" + newVersion + ".json", true);
|
||||
|
||||
blockMappings = loadFromObject(oldMappings, newMappings, diffmapping, "blocks");
|
||||
blockStateMappings = loadFromObject(oldMappings, newMappings, diffmapping, "blockstates");
|
||||
soundMappings = loadFromArray(oldMappings, newMappings, diffmapping, "sounds");
|
||||
statisticsMappings = loadFromArray(oldMappings, newMappings, diffmapping, "statistics");
|
||||
|
||||
Mappings particles = loadFromArray(oldMappings, newMappings, diffmapping, "particles");
|
||||
if (particles != null) {
|
||||
particleMappings = new ParticleMappings(oldMappings.getAsJsonArray("particles"), particles);
|
||||
}
|
||||
|
||||
if (loadItems && newMappings.has("items")) {
|
||||
itemMappings = new Int2IntBiHashMap();
|
||||
itemMappings.defaultReturnValue(-1);
|
||||
MappingDataLoader.mapIdentifiers(itemMappings, oldMappings.getAsJsonObject("items"), newMappings.getAsJsonObject("items"),
|
||||
diffmapping != null ? diffmapping.getAsJsonObject("items") : null);
|
||||
}
|
||||
|
||||
loadExtras(oldMappings, newMappings, diffmapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewBlockStateId(int id) {
|
||||
return checkValidity(id, blockStateMappings.getNewId(id), "blockstate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewBlockId(int id) {
|
||||
return checkValidity(id, blockMappings.getNewId(id), "block");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewItemId(int id) {
|
||||
return checkValidity(id, itemMappings.get(id), "item");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldItemId(int id) {
|
||||
int oldId = itemMappings.inverse().get(id);
|
||||
// Remap new items to stone
|
||||
return oldId != -1 ? oldId : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewParticleId(int id) {
|
||||
return checkValidity(id, particleMappings.getMappings().getNewId(id), "particles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Int2IntBiMap getItemMappings() {
|
||||
return itemMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ParticleMappings getParticleMappings() {
|
||||
return particleMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getBlockMappings() {
|
||||
return blockMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getBlockStateMappings() {
|
||||
return blockStateMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getSoundMappings() {
|
||||
return soundMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getStatisticsMappings() {
|
||||
return statisticsMappings;
|
||||
}
|
||||
|
||||
protected @Nullable Mappings loadFromArray(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
|
||||
if (!oldMappings.has(key) || !newMappings.has(key)) return null;
|
||||
|
||||
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
|
||||
return new IntArrayMappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), diff);
|
||||
}
|
||||
|
||||
protected @Nullable Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
|
||||
if (!oldMappings.has(key) || !newMappings.has(key)) return null;
|
||||
|
||||
JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null;
|
||||
return new IntArrayMappings(oldMappings.getAsJsonObject(key), newMappings.getAsJsonObject(key), diff);
|
||||
}
|
||||
|
||||
protected JsonObject loadDiffFile() {
|
||||
return MappingDataLoader.loadData("mappingdiff-" + oldVersion + "to" + newVersion + ".json");
|
||||
}
|
||||
|
||||
protected Logger getLogger() {
|
||||
return Via.getPlatform().getLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given mapped id if valid, else 0 with a warning logged to the console.
|
||||
*
|
||||
* @param id unmapped id
|
||||
* @param mappedId mapped id
|
||||
* @param type mapping type (e.g. "item")
|
||||
* @return the given mapped id if valid, else 0
|
||||
*/
|
||||
protected int checkValidity(int id, int mappedId, String type) {
|
||||
if (mappedId == -1) {
|
||||
getLogger().warning(String.format("Missing %s %s for %s %s %d", newVersion, type, oldVersion, type, id));
|
||||
return 0;
|
||||
}
|
||||
return mappedId;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be overridden.
|
||||
*
|
||||
* @param oldMappings old mappings
|
||||
* @param newMappings new mappings
|
||||
* @param diffMappings diff mappings if present
|
||||
*/
|
||||
protected void loadExtras(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings) {
|
||||
}
|
||||
}
|
@ -27,12 +27,12 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.util.Int2IntBiMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -62,8 +62,9 @@ public class MappingDataLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached mappings. Cleared after Via has been fully loaded.
|
||||
* Returns the cached mappings. Cleared after ViaVersion has been fully loaded.
|
||||
*
|
||||
* @return cached mapping file json objects
|
||||
* @see #isCacheJsonMappings()
|
||||
*/
|
||||
public static Map<String, JsonObject> getMappingsCache() {
|
||||
@ -72,6 +73,8 @@ public class MappingDataLoader {
|
||||
|
||||
/**
|
||||
* Loads the file from the plugin folder if present, else from the bundled resources.
|
||||
*
|
||||
* @return loaded json object, or null if not found or invalid
|
||||
*/
|
||||
public static @Nullable JsonObject loadFromDataDir(String name) {
|
||||
File file = new File(Via.getPlatform().getDataFolder(), name);
|
||||
@ -92,6 +95,8 @@ public class MappingDataLoader {
|
||||
|
||||
/**
|
||||
* Loads the file from the bundled resources. Uses the cache if enabled.
|
||||
*
|
||||
* @return loaded json object from bundled resources if present
|
||||
*/
|
||||
public static @Nullable JsonObject loadData(String name) {
|
||||
return loadData(name, false);
|
||||
@ -101,6 +106,7 @@ public class MappingDataLoader {
|
||||
* Loads the file from the bundled resources. Uses the cache if enabled.
|
||||
*
|
||||
* @param cacheIfEnabled whether loaded files should be cached
|
||||
* @return loaded json object from bundled resources if present
|
||||
*/
|
||||
public static @Nullable JsonObject loadData(String name, boolean cacheIfEnabled) {
|
||||
if (cacheJsonMappings) {
|
||||
@ -148,7 +154,7 @@ public class MappingDataLoader {
|
||||
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
|
||||
int value = mapIdentifierEntry(entry, newIdentifierMap, diffIdentifiers);
|
||||
if (value != -1) {
|
||||
output[Integer.parseInt(entry.getKey())] = (short) value;
|
||||
output[Integer.parseInt(entry.getKey())] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -200,7 +206,7 @@ public class MappingDataLoader {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
output[i] = (short) mappedId;
|
||||
output[i] = mappedId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,95 +22,22 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Mappings {
|
||||
protected final int[] oldToNew;
|
||||
|
||||
public Mappings(int[] oldToNew) {
|
||||
this.oldToNew = oldToNew;
|
||||
}
|
||||
public interface Mappings {
|
||||
|
||||
/**
|
||||
* Maps old identifiers to the new ones.
|
||||
* If an old value cannot be found in the new mappings, the diffmapping will be checked for the given entry.
|
||||
* Returns the mapped id from the given id, or -1 if invalid/out of bounds.
|
||||
*
|
||||
* @param size set size of the underlying short array
|
||||
* @param oldMapping mappings to map from
|
||||
* @param newMapping mappings to map to
|
||||
* @param diffMapping extra mappings that will be used/scanned when an entry cannot be found
|
||||
* @param id unmapped id
|
||||
* @return mapped id, or -1 if invalid/out of bounds
|
||||
*/
|
||||
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) {
|
||||
oldToNew = new int[size];
|
||||
Arrays.fill(oldToNew, -1);
|
||||
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping);
|
||||
}
|
||||
|
||||
public Mappings(JsonObject oldMapping, JsonObject newMapping, @Nullable JsonObject diffMapping) {
|
||||
this(oldMapping.entrySet().size(), oldMapping, newMapping, diffMapping);
|
||||
}
|
||||
int getNewId(int id);
|
||||
|
||||
/**
|
||||
* Maps old identifiers to the new ones.
|
||||
* Manually maps a specific id.
|
||||
*
|
||||
* @param size set size of the underlying short array
|
||||
* @param oldMapping mappings to map from
|
||||
* @param newMapping mappings to map to
|
||||
* @param id unmapped id
|
||||
* @param newId mapped id
|
||||
* @throws IndexOutOfBoundsException if the unmapped id is invalid
|
||||
*/
|
||||
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping) {
|
||||
oldToNew = new int[size];
|
||||
Arrays.fill(oldToNew, -1);
|
||||
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping);
|
||||
}
|
||||
|
||||
public Mappings(JsonObject oldMapping, JsonObject newMapping) {
|
||||
this(oldMapping.entrySet().size(), oldMapping, newMapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps old identifiers to the new ones.
|
||||
*
|
||||
* @param size set size of the underlying short array
|
||||
* @param oldMapping mappings to map from
|
||||
* @param newMapping mappings to map to
|
||||
* @param diffMapping extra mappings that will be used/scanned when an entry cannot be found
|
||||
* @param warnOnMissing should "No key for x" be printed if there is no matching identifier
|
||||
*/
|
||||
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) {
|
||||
oldToNew = new int[size];
|
||||
Arrays.fill(oldToNew, -1);
|
||||
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing);
|
||||
}
|
||||
|
||||
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping, boolean warnOnMissing) {
|
||||
this(size, oldMapping, newMapping, null, warnOnMissing);
|
||||
}
|
||||
|
||||
public Mappings(JsonArray oldMapping, JsonArray newMapping, boolean warnOnMissing) {
|
||||
this(oldMapping.size(), oldMapping, newMapping, warnOnMissing);
|
||||
}
|
||||
|
||||
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping) {
|
||||
this(size, oldMapping, newMapping, true);
|
||||
}
|
||||
|
||||
public Mappings(JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping) {
|
||||
this(oldMapping.size(), oldMapping, newMapping, diffMapping, true);
|
||||
}
|
||||
|
||||
public Mappings(JsonArray oldMapping, JsonArray newMapping) {
|
||||
this(oldMapping.size(), oldMapping, newMapping, true);
|
||||
}
|
||||
|
||||
public int getNewId(int old) {
|
||||
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
||||
}
|
||||
|
||||
public int[] getOldToNew() {
|
||||
return oldToNew;
|
||||
}
|
||||
void setNewId(int id, int newId);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.data;
|
||||
package com.viaversion.viaversion.api.platform;
|
||||
|
||||
public interface ExternalJoinGameListener {
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2021 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.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 cancelled.
|
||||
*
|
||||
* @return platform based object, or null if not cancellable
|
||||
*/
|
||||
@Nullable T getObject();
|
||||
|
||||
/**
|
||||
* Cancels the task.
|
||||
*
|
||||
* @throws IllegalArgumentException if the task is not cancellable
|
||||
*/
|
||||
void cancel();
|
||||
}
|
@ -85,7 +85,7 @@ public interface ViaPlatform<T> {
|
||||
* @param runnable The task to run
|
||||
* @return The Task ID
|
||||
*/
|
||||
TaskId runAsync(Runnable runnable);
|
||||
PlatformTask runAsync(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Run a task Sync
|
||||
@ -93,7 +93,7 @@ public interface ViaPlatform<T> {
|
||||
* @param runnable The task to run
|
||||
* @return The Task ID
|
||||
*/
|
||||
TaskId runSync(Runnable runnable);
|
||||
PlatformTask runSync(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Run a task Sync after a interval
|
||||
@ -103,7 +103,7 @@ public interface ViaPlatform<T> {
|
||||
* @param ticks The interval to run it after
|
||||
* @return The Task ID
|
||||
*/
|
||||
TaskId runSync(Runnable runnable, Long ticks);
|
||||
PlatformTask runSync(Runnable runnable, Long ticks);
|
||||
|
||||
/**
|
||||
* Run a task at a repeating interval.
|
||||
@ -113,14 +113,18 @@ public interface ViaPlatform<T> {
|
||||
* @param ticks The interval to run it at
|
||||
* @return The Task ID
|
||||
*/
|
||||
TaskId runRepeatingSync(Runnable runnable, Long ticks);
|
||||
PlatformTask runRepeatingSync(Runnable runnable, Long ticks);
|
||||
|
||||
/**
|
||||
* Cancel a task
|
||||
* Cancels a task.
|
||||
*
|
||||
* @param taskId The task ID to cancel
|
||||
* @param task task to cancel
|
||||
*/
|
||||
void cancelTask(TaskId taskId);
|
||||
default void cancelTask(PlatformTask task) {
|
||||
if (task.getObject() != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the online players
|
||||
|
@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.protocol.base;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2021 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.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class Int2IntBiHashMap implements Int2IntBiMap {
|
||||
|
||||
private final Int2IntMap map;
|
||||
private final Int2IntBiHashMap inverse;
|
||||
|
||||
public Int2IntBiHashMap() {
|
||||
this.map = new Int2IntOpenHashMap();
|
||||
this.inverse = new Int2IntBiHashMap(this);
|
||||
}
|
||||
|
||||
private Int2IntBiHashMap(Int2IntBiHashMap inverse) {
|
||||
this.map = new Int2IntOpenHashMap();
|
||||
this.inverse = inverse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Int2IntBiMap inverse() {
|
||||
return inverse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int put(int key, int value) {
|
||||
if (containsKey(key) && value == get(key)) return value;
|
||||
|
||||
Preconditions.checkArgument(!containsValue(value), "value already present: %s", value);
|
||||
map.put(key, value);
|
||||
inverse.map.put(value, key);
|
||||
return defaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(int key, int value) {
|
||||
map.remove(key, value);
|
||||
return inverse.map.remove(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(int key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
map.clear();
|
||||
inverse.map.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultReturnValue(int rv) {
|
||||
map.defaultReturnValue(rv);
|
||||
inverse.map.defaultReturnValue(rv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int defaultReturnValue() {
|
||||
return map.defaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<Entry> int2IntEntrySet() {
|
||||
return map.int2IntEntrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull IntSet keySet() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull IntSet values() {
|
||||
return inverse.map.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(int key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(int value) {
|
||||
return inverse.map.containsKey(value);
|
||||
}
|
||||
}
|
@ -22,42 +22,24 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Simple wrapper class for two {@link Int2IntMap}s.
|
||||
*
|
||||
* @see #inverse() to get the inversed map
|
||||
*/
|
||||
public class Int2IntBiMap implements Int2IntMap {
|
||||
|
||||
private final Int2IntMap map;
|
||||
private final Int2IntBiMap inverse;
|
||||
|
||||
public Int2IntBiMap() {
|
||||
this.map = new Int2IntOpenHashMap();
|
||||
this.inverse = new Int2IntBiMap(this);
|
||||
}
|
||||
|
||||
private Int2IntBiMap(Int2IntBiMap inverse) {
|
||||
this.map = new Int2IntOpenHashMap();
|
||||
this.inverse = inverse;
|
||||
}
|
||||
public interface Int2IntBiMap extends Int2IntMap {
|
||||
|
||||
/**
|
||||
* Returns the inverse of this bimap.
|
||||
*
|
||||
* @return the inverse of this bimap
|
||||
*/
|
||||
public Int2IntBiMap inverse() {
|
||||
return inverse;
|
||||
}
|
||||
Int2IntBiMap inverse();
|
||||
|
||||
/**
|
||||
* Puts the key and value into the maps.
|
||||
@ -68,81 +50,11 @@ public class Int2IntBiMap implements Int2IntMap {
|
||||
* @throws IllegalArgumentException if the value already exists in the map
|
||||
*/
|
||||
@Override
|
||||
public int put(int key, int value) {
|
||||
if (containsKey(key) && value == get(key)) return value;
|
||||
|
||||
Preconditions.checkArgument(!containsValue(value), "value already present: %s", value);
|
||||
map.put(key, value);
|
||||
inverse.map.put(value, key);
|
||||
return defaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(int key, int value) {
|
||||
map.remove(key, value);
|
||||
return inverse.map.remove(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(int key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
map.clear();
|
||||
inverse.map.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return map.isEmpty();
|
||||
}
|
||||
int put(int key, int value);
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void putAll(@NonNull Map<? extends Integer, ? extends Integer> m) {
|
||||
default void putAll(@NonNull Map<? extends Integer, ? extends Integer> m) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultReturnValue(int rv) {
|
||||
map.defaultReturnValue(rv);
|
||||
inverse.map.defaultReturnValue(rv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int defaultReturnValue() {
|
||||
return map.defaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<Entry> int2IntEntrySet() {
|
||||
return map.int2IntEntrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull IntSet keySet() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull IntSet values() {
|
||||
return inverse.map.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(int key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(int value) {
|
||||
return inverse.map.containsKey(value);
|
||||
}
|
||||
}
|
||||
|
@ -18,17 +18,13 @@
|
||||
package com.viaversion.viaversion;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.ViaAPI;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.bukkit.classgenerator.ClassGenerator;
|
||||
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
|
||||
@ -42,7 +38,11 @@ import com.viaversion.viaversion.bukkit.platform.BukkitViaLoader;
|
||||
import com.viaversion.viaversion.bukkit.util.NMSUtil;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -178,9 +178,9 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runAsync(Runnable runnable) {
|
||||
public PlatformTask runAsync(Runnable runnable) {
|
||||
if (isPluginEnabled()) {
|
||||
return new BukkitTaskId(getServer().getScheduler().runTaskAsynchronously(this, runnable).getTaskId());
|
||||
return new BukkitTaskId(getServer().getScheduler().runTaskAsynchronously(this, runnable));
|
||||
} else {
|
||||
asyncQueuedTasks.add(runnable);
|
||||
return new BukkitTaskId(null);
|
||||
@ -188,9 +188,9 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable) {
|
||||
public PlatformTask runSync(Runnable runnable) {
|
||||
if (isPluginEnabled()) {
|
||||
return new BukkitTaskId(getServer().getScheduler().runTask(this, runnable).getTaskId());
|
||||
return new BukkitTaskId(getServer().getScheduler().runTask(this, runnable));
|
||||
} else {
|
||||
queuedTasks.add(runnable);
|
||||
return new BukkitTaskId(null);
|
||||
@ -198,22 +198,13 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable, Long ticks) {
|
||||
return new BukkitTaskId(getServer().getScheduler().runTaskLater(this, runnable, ticks).getTaskId());
|
||||
public PlatformTask runSync(Runnable runnable, Long ticks) {
|
||||
return new BukkitTaskId(getServer().getScheduler().runTaskLater(this, runnable, ticks));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
return new BukkitTaskId(getServer().getScheduler().runTaskTimer(this, runnable, 0, ticks).getTaskId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask(TaskId taskId) {
|
||||
if (taskId == null) return;
|
||||
if (taskId.getObject() == null) return;
|
||||
if (taskId instanceof BukkitTaskId) {
|
||||
getServer().getScheduler().cancelTask((Integer) taskId.getObject());
|
||||
}
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
return new BukkitTaskId(getServer().getScheduler().runTaskTimer(this, runnable, 0, ticks));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,17 +17,26 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.bukkit.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BukkitTaskId implements TaskId {
|
||||
private final Integer object;
|
||||
public class BukkitTaskId implements PlatformTask<BukkitTask> {
|
||||
private final BukkitTask task;
|
||||
|
||||
public BukkitTaskId(Integer object) {
|
||||
this.object = object;
|
||||
public BukkitTaskId(@Nullable BukkitTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getObject() {
|
||||
return object;
|
||||
public @Nullable BukkitTask getObject() {
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
Preconditions.checkArgument(task != null, "Task cannot be cancelled");
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -18,17 +18,12 @@
|
||||
package com.viaversion.viaversion;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.ViaAPI;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.bungee.commands.BungeeCommand;
|
||||
import com.viaversion.viaversion.bungee.commands.BungeeCommandHandler;
|
||||
@ -41,6 +36,11 @@ import com.viaversion.viaversion.bungee.platform.BungeeViaLoader;
|
||||
import com.viaversion.viaversion.bungee.service.ProtocolDetectorService;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -112,32 +112,23 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runAsync(Runnable runnable) {
|
||||
return new BungeeTaskId(getProxy().getScheduler().runAsync(this, runnable).getId());
|
||||
public PlatformTask runAsync(Runnable runnable) {
|
||||
return new BungeeTaskId(getProxy().getScheduler().runAsync(this, runnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable) {
|
||||
public PlatformTask runSync(Runnable runnable) {
|
||||
return runAsync(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable, Long ticks) {
|
||||
return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, ticks * 50, TimeUnit.MILLISECONDS).getId());
|
||||
public PlatformTask runSync(Runnable runnable, Long ticks) {
|
||||
return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, ticks * 50, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, 0, ticks * 50, TimeUnit.MILLISECONDS).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask(TaskId taskId) {
|
||||
if (taskId == null) return;
|
||||
if (taskId.getObject() == null) return;
|
||||
if (taskId instanceof BungeeTaskId) {
|
||||
getProxy().getScheduler().cancel((Integer) taskId.getObject());
|
||||
}
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
return new BungeeTaskId(getProxy().getScheduler().schedule(this, runnable, 0, ticks * 50, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,7 @@ import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.ExternalJoinGameListener;
|
||||
import com.viaversion.viaversion.api.platform.ExternalJoinGameListener;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
||||
import com.viaversion.viaversion.api.protocol.base.Protocol;
|
||||
|
@ -17,17 +17,23 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.bungee.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
|
||||
public class BungeeTaskId implements TaskId {
|
||||
private final Integer object;
|
||||
public class BungeeTaskId implements PlatformTask<ScheduledTask> {
|
||||
private final ScheduledTask task;
|
||||
|
||||
public BungeeTaskId(Integer object) {
|
||||
this.object = object;
|
||||
public BungeeTaskId(ScheduledTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getObject() {
|
||||
return object;
|
||||
public ScheduledTask getObject() {
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package com.viaversion.viaversion;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.ViaManager;
|
||||
import com.viaversion.viaversion.api.connection.ConnectionManager;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
@ -55,7 +55,7 @@ public class ViaManagerImpl implements ViaManager {
|
||||
private final ViaPlatformLoader loader;
|
||||
private final Set<String> subPlatforms = new HashSet<>();
|
||||
private List<Runnable> enableListeners = new ArrayList<>();
|
||||
private TaskId mappingLoadingTask;
|
||||
private PlatformTask mappingLoadingTask;
|
||||
private boolean debug;
|
||||
|
||||
public ViaManagerImpl(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
|
||||
|
@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -78,7 +77,7 @@ public class ProtocolInfoImpl extends StoredObject implements ProtocolInfo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @MonotonicNonNull String getUsername() {
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
package com.viaversion.viaversion.data;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import com.viaversion.viaversion.api.data.ExternalJoinGameListener;
|
||||
import com.viaversion.viaversion.api.platform.ExternalJoinGameListener;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
|
@ -68,6 +68,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -318,6 +319,8 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
||||
|
||||
public void setServerProtocol(ServerProtocolVersion serverProtocolVersion) {
|
||||
this.serverProtocolVersion = serverProtocolVersion;
|
||||
//noinspection deprecation
|
||||
ProtocolRegistry.SERVER_PROTOCOL = serverProtocolVersion.lowestSupportedVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,17 +17,15 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_13_1to1_13;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.rewriter.RegistryType;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.EntityPackets;
|
||||
@ -37,10 +35,13 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import com.viaversion.viaversion.rewriter.RegistryType;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
|
||||
public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, ClientboundPackets1_13, ServerboundPackets1_13, ServerboundPackets1_13> {
|
||||
|
||||
public static final MappingData MAPPINGS = new MappingData("1.13", "1.13.2", true);
|
||||
public static final MappingData MAPPINGS = new MappingDataBase("1.13", "1.13.2", true);
|
||||
|
||||
public Protocol1_13_1To1_13() {
|
||||
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
|
||||
|
@ -24,11 +24,13 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.IntArrayMappings;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.data.Mappings;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@ -37,7 +39,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MappingData extends com.viaversion.viaversion.api.data.MappingData {
|
||||
public class MappingData extends MappingDataBase {
|
||||
private final Map<String, Integer[]> blockTags = new HashMap<>();
|
||||
private final Map<String, Integer[]> itemTags = new HashMap<>();
|
||||
private final Map<String, Integer[]> fluidTags = new HashMap<>();
|
||||
@ -58,22 +60,21 @@ public class MappingData extends com.viaversion.viaversion.api.data.MappingData
|
||||
loadTags(fluidTags, newMappings.getAsJsonObject("fluid_tags"));
|
||||
|
||||
loadEnchantments(oldEnchantmentsIds, oldMappings.getAsJsonObject("enchantments"));
|
||||
enchantmentMappings = new Mappings(72, oldMappings.getAsJsonObject("enchantments"), newMappings.getAsJsonObject("enchantments"));
|
||||
enchantmentMappings = new IntArrayMappings(72, oldMappings.getAsJsonObject("enchantments"), newMappings.getAsJsonObject("enchantments"));
|
||||
|
||||
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13
|
||||
if (Via.getConfig().isSnowCollisionFix()) {
|
||||
blockMappings.getOldToNew()[1248] = 3416;
|
||||
blockMappings.setNewId(1248, 3416);
|
||||
}
|
||||
|
||||
// Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers
|
||||
if (Via.getConfig().isInfestedBlocksFix()) {
|
||||
int[] oldToNew = blockMappings.getOldToNew();
|
||||
oldToNew[1552] = 1; // stone
|
||||
oldToNew[1553] = 14; // cobblestone
|
||||
oldToNew[1554] = 3983; // stone bricks
|
||||
oldToNew[1555] = 3984; // mossy stone bricks
|
||||
oldToNew[1556] = 3985; // cracked stone bricks
|
||||
oldToNew[1557] = 3986; // chiseled stone bricks
|
||||
blockMappings.setNewId(1552, 1); // stone
|
||||
blockMappings.setNewId(1553, 14); // cobblestone
|
||||
blockMappings.setNewId(1554, 3983); // stone bricks
|
||||
blockMappings.setNewId(1555, 3984); // mossy stone bricks
|
||||
blockMappings.setNewId(1556, 3985); // cracked stone bricks
|
||||
blockMappings.setNewId(1557, 3986); // chiseled stone bricks
|
||||
}
|
||||
|
||||
JsonObject object = MappingDataLoader.loadFromDataDir("channelmappings-1.13.json");
|
||||
@ -125,7 +126,7 @@ public class MappingData extends com.viaversion.viaversion.api.data.MappingData
|
||||
protected Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) {
|
||||
if (key.equals("blocks")) {
|
||||
// Need to use a custom size since there are larger gaps in ids
|
||||
return new Mappings(4084, oldMappings.getAsJsonObject("blocks"), newMappings.getAsJsonObject("blockstates"));
|
||||
return new IntArrayMappings(4084, oldMappings.getAsJsonObject("blocks"), newMappings.getAsJsonObject("blockstates"));
|
||||
} else {
|
||||
return super.loadFromObject(oldMappings, newMappings, diffMappings, key);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
@ -28,7 +29,7 @@ import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MappingData extends com.viaversion.viaversion.api.data.MappingData {
|
||||
public class MappingData extends MappingDataBase {
|
||||
private IntSet motionBlocking;
|
||||
private IntSet nonFullBlocks;
|
||||
|
||||
|
@ -18,10 +18,12 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.data.IntArrayMappings;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import com.viaversion.viaversion.api.data.Mappings;
|
||||
|
||||
public class MappingData extends com.viaversion.viaversion.api.data.MappingData {
|
||||
public class MappingData extends MappingDataBase {
|
||||
|
||||
public MappingData() {
|
||||
super("1.14", "1.15", true);
|
||||
@ -34,6 +36,6 @@ public class MappingData extends com.viaversion.viaversion.api.data.MappingData
|
||||
}
|
||||
|
||||
// Ignore removed sounds
|
||||
return new Mappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), false);
|
||||
return new IntArrayMappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), false);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.minecraft.nbt.BinaryTagIO;
|
||||
|
||||
@ -30,7 +31,7 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MappingData extends com.viaversion.viaversion.api.data.MappingData {
|
||||
public class MappingData extends MappingDataBase {
|
||||
private final Map<String, CompoundTag> dimensionDataMap = new HashMap<>();
|
||||
private CompoundTag dimensionRegistry;
|
||||
|
||||
|
@ -20,8 +20,9 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
|
||||
public class MappingData extends com.viaversion.viaversion.api.data.MappingData {
|
||||
public class MappingData extends MappingDataBase {
|
||||
private final BiMap<String, String> attributeMappings = HashBiMap.create();
|
||||
|
||||
public MappingData() {
|
||||
|
@ -18,16 +18,12 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_17to1_16_4;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.rewriter.MetadataRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RegistryType;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
||||
@ -37,10 +33,15 @@ import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.Inventor
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.BiomeStorage;
|
||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17;
|
||||
import com.viaversion.viaversion.rewriter.MetadataRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RegistryType;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
|
||||
public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, ClientboundPackets1_17, ServerboundPackets1_16_2, ServerboundPackets1_17> {
|
||||
|
||||
public static final MappingData MAPPINGS = new MappingData("1.16.2", "1.17", true);
|
||||
public static final MappingData MAPPINGS = new MappingDataBase("1.16.2", "1.17", true);
|
||||
private static final String[] NEW_GAME_EVENT_TAGS = {"minecraft:ignore_vibrations_sneaking", "minecraft:vibrations"};
|
||||
private TagRewriter tagRewriter;
|
||||
|
||||
|
@ -17,11 +17,11 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
|
@ -19,24 +19,14 @@ package com.viaversion.viaversion;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.config.DefaultConfig;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
|
||||
import org.spongepowered.api.event.game.state.GameInitializationEvent;
|
||||
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import com.viaversion.viaversion.sponge.commands.SpongeCommandHandler;
|
||||
import com.viaversion.viaversion.sponge.commands.SpongeCommandSender;
|
||||
import com.viaversion.viaversion.sponge.platform.SpongeTaskId;
|
||||
@ -48,7 +38,17 @@ import com.viaversion.viaversion.sponge.util.LoggerWrapper;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.util.VersionInfo;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.config.DefaultConfig;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent;
|
||||
import org.spongepowered.api.event.game.state.GameInitializationEvent;
|
||||
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -127,7 +127,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runAsync(Runnable runnable) {
|
||||
public PlatformTask runAsync(Runnable runnable) {
|
||||
return new SpongeTaskId(
|
||||
Task.builder()
|
||||
.execute(runnable)
|
||||
@ -137,7 +137,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable) {
|
||||
public PlatformTask runSync(Runnable runnable) {
|
||||
return new SpongeTaskId(
|
||||
Task.builder()
|
||||
.execute(runnable)
|
||||
@ -146,7 +146,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable, Long ticks) {
|
||||
public PlatformTask runSync(Runnable runnable, Long ticks) {
|
||||
return new SpongeTaskId(
|
||||
Task.builder()
|
||||
.execute(runnable)
|
||||
@ -156,7 +156,7 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
return new SpongeTaskId(
|
||||
Task.builder()
|
||||
.execute(runnable)
|
||||
@ -165,15 +165,6 @@ public class SpongePlugin implements ViaPlatform<Player> {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask(TaskId taskId) {
|
||||
if (taskId == null) return;
|
||||
if (taskId.getObject() == null) return;
|
||||
if (taskId instanceof SpongeTaskId) {
|
||||
((SpongeTaskId) taskId).getObject().cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
ViaCommandSender[] array = new ViaCommandSender[game.getServer().getOnlinePlayers().size()];
|
||||
|
@ -18,17 +18,22 @@
|
||||
package com.viaversion.viaversion.sponge.platform;
|
||||
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
|
||||
public class SpongeTaskId implements TaskId {
|
||||
private final Task object;
|
||||
public class SpongeTaskId implements PlatformTask<Task> {
|
||||
private final Task task;
|
||||
|
||||
public SpongeTaskId(Task object) {
|
||||
this.object = object;
|
||||
public SpongeTaskId(Task task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task getObject() {
|
||||
return object;
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import com.viaversion.viaversion.SpongePlugin;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
||||
@ -45,7 +45,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
|
||||
private final SpongePlugin plugin;
|
||||
|
||||
private final Set<Object> listeners = new HashSet<>();
|
||||
private final Set<TaskId> tasks = new HashSet<>();
|
||||
private final Set<PlatformTask> tasks = new HashSet<>();
|
||||
|
||||
public SpongeViaLoader(SpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -27,13 +27,11 @@ import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.slf4j.Logger;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.util.ChatColorUtil;
|
||||
@ -48,6 +46,8 @@ import com.viaversion.viaversion.velocity.platform.VelocityViaInjector;
|
||||
import com.viaversion.viaversion.velocity.platform.VelocityViaLoader;
|
||||
import com.viaversion.viaversion.velocity.service.ProtocolDetectorService;
|
||||
import com.viaversion.viaversion.velocity.util.LoggerWrapper;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
@ -127,17 +127,17 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runAsync(Runnable runnable) {
|
||||
public PlatformTask runAsync(Runnable runnable) {
|
||||
return runSync(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable) {
|
||||
public PlatformTask runSync(Runnable runnable) {
|
||||
return runSync(runnable, 0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runSync(Runnable runnable, Long ticks) {
|
||||
public PlatformTask runSync(Runnable runnable, Long ticks) {
|
||||
return new VelocityTaskId(
|
||||
PROXY.getScheduler()
|
||||
.buildTask(this, runnable)
|
||||
@ -146,7 +146,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskId runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
public PlatformTask runRepeatingSync(Runnable runnable, Long ticks) {
|
||||
return new VelocityTaskId(
|
||||
PROXY.getScheduler()
|
||||
.buildTask(this, runnable)
|
||||
@ -154,13 +154,6 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask(TaskId taskId) {
|
||||
if (taskId instanceof VelocityTaskId) {
|
||||
((VelocityTaskId) taskId).getObject().cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
return PROXY.getAllPlayers().stream()
|
||||
|
@ -18,17 +18,22 @@
|
||||
package com.viaversion.viaversion.velocity.platform;
|
||||
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import com.viaversion.viaversion.api.platform.TaskId;
|
||||
import com.viaversion.viaversion.api.platform.PlatformTask;
|
||||
|
||||
public class VelocityTaskId implements TaskId {
|
||||
private final ScheduledTask object;
|
||||
public class VelocityTaskId implements PlatformTask<ScheduledTask> {
|
||||
private final ScheduledTask task;
|
||||
|
||||
public VelocityTaskId(ScheduledTask object) {
|
||||
this.object = object;
|
||||
public VelocityTaskId(ScheduledTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledTask getObject() {
|
||||
return object;
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user