mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Upstream merge of TranslationManager and ResourceLoader
This commit is contained in:
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
@ -27,6 +27,7 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.util.io.ResourceLoader;
|
||||
@ -56,6 +57,7 @@ public final class BundledBlockData {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BundledBlockData.class);
|
||||
private static BundledBlockData INSTANCE;
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
private final Map<String, BlockEntry> idMap = new HashMap<>();
|
||||
|
||||
@ -63,6 +65,8 @@ public final class BundledBlockData {
|
||||
* Create a new instance.
|
||||
*/
|
||||
private BundledBlockData() {
|
||||
this.resourceLoader = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.CONFIGURATION).getResourceLoader();
|
||||
|
||||
try {
|
||||
loadFromResource();
|
||||
} catch (Throwable e) {
|
||||
@ -82,7 +86,9 @@ public final class BundledBlockData {
|
||||
JsonPrimitive primitive = (JsonPrimitive) json;
|
||||
if (primitive.isString()) {
|
||||
String value = primitive.getAsString();
|
||||
if (value.charAt(0) == '#') return Integer.parseInt(value.substring(1), 16);
|
||||
if (value.charAt(0) == '#') {
|
||||
return Integer.parseInt(value.substring(1), 16);
|
||||
}
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
return primitive.getAsInt();
|
||||
@ -90,15 +96,15 @@ public final class BundledBlockData {
|
||||
Gson gson = gsonBuilder.create();
|
||||
URL url = null;
|
||||
final int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataVersion();
|
||||
if (dataVersion > 2577) { // > MC 1.15
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "blocks.116.json");
|
||||
} else if (dataVersion > 2224) { // > MC 1.14
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "blocks.115.json");
|
||||
} else if (dataVersion > 1900) { // > MC 1.13
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "blocks.114.json");
|
||||
if (dataVersion >= Constants.DATA_VERSION_MC_1_16) {
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "blocks.116.json");
|
||||
} else if (dataVersion >= Constants.DATA_VERSION_MC_1_15) {
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "blocks.115.json");
|
||||
} else if (dataVersion >= Constants.DATA_VERSION_MC_1_14) {
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "blocks.114.json");
|
||||
}
|
||||
if (url == null) {
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "blocks.json");
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "blocks.json");
|
||||
}
|
||||
if (url == null) {
|
||||
throw new IOException("Could not find blocks.json");
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
@ -25,6 +25,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.util.io.ResourceLoader;
|
||||
@ -54,6 +55,7 @@ public final class BundledItemData {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BundledItemData.class);
|
||||
private static BundledItemData INSTANCE;
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
private final Map<String, ItemEntry> idMap = new HashMap<>();
|
||||
|
||||
@ -61,6 +63,8 @@ public final class BundledItemData {
|
||||
* Create a new instance.
|
||||
*/
|
||||
private BundledItemData() {
|
||||
this.resourceLoader = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.CONFIGURATION).getResourceLoader();
|
||||
|
||||
try {
|
||||
loadFromResource();
|
||||
} catch (Throwable e) {
|
||||
@ -79,15 +83,15 @@ public final class BundledItemData {
|
||||
Gson gson = gsonBuilder.create();
|
||||
URL url = null;
|
||||
final int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataVersion();
|
||||
if (dataVersion > 2577) { // > MC 1.15
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "items.116.json");
|
||||
} else if (dataVersion > 2224) { // > MC 1.14
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "items.115.json");
|
||||
} else if (dataVersion > 1900) { // > MC 1.13
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "items.114.json");
|
||||
if (dataVersion >= Constants.DATA_VERSION_MC_1_16) {
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "items.116.json");
|
||||
} else if (dataVersion >= Constants.DATA_VERSION_MC_1_15) {
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "items.115.json");
|
||||
} else if (dataVersion >= Constants.DATA_VERSION_MC_1_14) {
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "items.114.json");
|
||||
}
|
||||
if (url == null) {
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "items.json");
|
||||
url = resourceLoader.getResource(BundledBlockData.class, "items.json");
|
||||
}
|
||||
if (url == null) {
|
||||
throw new IOException("Could not find items.json");
|
||||
|
@ -3,22 +3,26 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.translation.TranslationManager;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -33,8 +37,26 @@ public class BundledItemRegistry implements ItemRegistry {
|
||||
return BundledItemData.getInstance().findById(itemType.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getRichName(ItemType itemType) {
|
||||
BundledItemData.ItemEntry itemEntry = getEntryById(itemType);
|
||||
if (itemEntry != null && !itemEntry.localizedName.equals("Air")) {
|
||||
// This is more likely to be "right", but not translated
|
||||
// Some vanilla MC items have overrides so we need this name here
|
||||
// Most platforms should be overriding this anyways, so it likely doesn't matter
|
||||
// too much!
|
||||
return TextComponent.of(itemEntry.localizedName);
|
||||
}
|
||||
return TranslatableComponent.of(
|
||||
TranslationManager.makeTranslationKey("item", itemType.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Deprecated
|
||||
// dumb_intellij.jpg
|
||||
@SuppressWarnings("deprecation")
|
||||
public String getName(ItemType itemType) {
|
||||
BundledItemData.ItemEntry itemEntry = getEntryById(itemType);
|
||||
if (itemEntry != null) {
|
||||
|
@ -3,22 +3,24 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -27,15 +29,36 @@ import javax.annotation.Nullable;
|
||||
|
||||
public interface ItemRegistry {
|
||||
|
||||
/**
|
||||
* Gets the name for the given item.
|
||||
*
|
||||
* @param itemType the item
|
||||
* @return The name
|
||||
*/
|
||||
Component getRichName(ItemType itemType);
|
||||
|
||||
/**
|
||||
* Gets the name for the given item stack.
|
||||
*
|
||||
* @param itemStack the item stack
|
||||
* @return The name
|
||||
*/
|
||||
default Component getRichName(BaseItemStack itemStack) {
|
||||
return getRichName(itemStack.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name for the given item.
|
||||
*
|
||||
* @param itemType the item
|
||||
* @return The name, or null if it's unknown
|
||||
* @deprecated Names are now translatable, use {@link #getRichName(ItemType)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
String getName(ItemType itemType);
|
||||
default String getName(ItemType itemType) {
|
||||
return getRichName(itemType).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the material for the given item.
|
||||
@ -47,7 +70,7 @@ public interface ItemRegistry {
|
||||
ItemMaterial getMaterial(ItemType itemType);
|
||||
|
||||
/**
|
||||
* Register all items
|
||||
* Register all items.
|
||||
*/
|
||||
default Collection<String> values() {
|
||||
return Collections.emptyList();
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
@ -32,6 +32,7 @@ import com.sk89q.worldedit.extension.factory.BlockFactory;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
@ -57,21 +58,24 @@ public final class LegacyMapper {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(LegacyMapper.class);
|
||||
private static LegacyMapper INSTANCE;
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
private final Int2ObjectArrayMap<Integer> blockStateToLegacyId4Data = new Int2ObjectArrayMap<>();
|
||||
private final Int2ObjectArrayMap<Integer> extraId4DataToStateId = new Int2ObjectArrayMap<>();
|
||||
private final int[] blockArr = new int[4096];
|
||||
private final BiMap<Integer, ItemType> itemMap = HashBiMap.create();
|
||||
private Map<String, String> blockEntries = new HashMap<>();
|
||||
private Map<String, BlockState> stringToBlockMap = new HashMap<>();
|
||||
private Multimap<BlockState, String> blockToStringMap = HashMultimap.create();
|
||||
private Map<String, ItemType> stringToItemMap = new HashMap<>();
|
||||
private Multimap<ItemType, String> itemToStringMap = HashMultimap.create();
|
||||
private final Map<String, BlockState> stringToBlockMap = new HashMap<>();
|
||||
private final Multimap<BlockState, String> blockToStringMap = HashMultimap.create();
|
||||
private final Map<String, ItemType> stringToItemMap = new HashMap<>();
|
||||
private final Multimap<ItemType, String> itemToStringMap = HashMultimap.create();
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
private LegacyMapper() {
|
||||
this.resourceLoader = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.CONFIGURATION).getResourceLoader();
|
||||
|
||||
try {
|
||||
loadFromResource();
|
||||
} catch (Throwable e) {
|
||||
@ -88,7 +92,7 @@ public final class LegacyMapper {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
Gson gson = gsonBuilder.disableHtmlEscaping().create();
|
||||
URL url = ResourceLoader.getResource(LegacyMapper.class, "legacy.json");
|
||||
URL url = resourceLoader.getResource(LegacyMapper.class, "legacy.json");
|
||||
if (url == null) {
|
||||
throw new IOException("Could not find legacy.json");
|
||||
}
|
||||
@ -122,7 +126,7 @@ public final class LegacyMapper {
|
||||
try {
|
||||
String newEntry = fixer.fixUp(DataFixer.FixTypes.BLOCK_STATE, value, 1631);
|
||||
state = blockFactory.parseFromInput(newEntry, parserContext).toImmutableState();
|
||||
} catch (InputParseException e) {
|
||||
} catch (InputParseException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +134,7 @@ public final class LegacyMapper {
|
||||
if (state == null) {
|
||||
try {
|
||||
state = blockFactory.parseFromInput(value, parserContext).toImmutableState();
|
||||
} catch (InputParseException e) {
|
||||
} catch (InputParseException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +168,7 @@ public final class LegacyMapper {
|
||||
String value = itemEntry.getValue();
|
||||
ItemType type = ItemTypes.get(value);
|
||||
if (type == null && fixer != null) {
|
||||
value = fixer.fixUp(DataFixer.FixTypes.ITEM_TYPE, value, 1631);
|
||||
value = fixer.fixUp(DataFixer.FixTypes.ITEM_TYPE, value, Constants.DATA_VERSION_MC_1_13_2);
|
||||
type = ItemTypes.get(value);
|
||||
}
|
||||
if (type == null) {
|
||||
|
Reference in New Issue
Block a user