Fixed a null pointer. Merged in a bunch of CLI stuff.

This commit is contained in:
MattBDev
2019-09-02 15:22:43 -04:00
parent aa4c443358
commit c20f4c6b7f
28 changed files with 240 additions and 352 deletions

View File

@ -12,6 +12,7 @@ repositories {
maven { url = uri("https://repo.codemc.org/repository/maven-public") }
maven { url = uri("https://papermc.io/repo/repository/maven-public/") }
maven { url = uri("http://empcraft.com/maven2") }
maven { url = uri("https://maven.enginehub.org/repo/") }
maven { url = uri("http://ci.frostcast.net/plugin/repository/everything") }
maven { url = uri("http://dl.bintray.com/tastybento/maven-repo") }
maven { url = uri("http://ci.emc.gs/nexus/content/groups/aikar/") }
@ -38,10 +39,15 @@ dependencies {
"implementation"("io.papermc:paperlib:1.0.2")
"compileOnly"("com.sk89q:dummypermscompat:1.10")
"implementation"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
"implementation"("org.bstats:bstats-bukkit:1.5")
"testCompile"("org.mockito:mockito-core:1.9.0-rc1")
"implementation"("com.sk89q.worldguard:worldguard-core:7.0.0-20190215.210421-39") { isTransitive = false }
"implementation"("com.sk89q.worldguard:worldguard-legacy:7.0.0-20190215.210421-39") { isTransitive = false }
"testCompile"("org.mockito:mockito-core:1.9.0-rc1") {
exclude("junit", "junit")
}
"compileOnly"("com.sk89q.worldguard:worldguard-bukkit:7.0.0") {
exclude("com.sk89q.worldedit", "worldedit-bukkit")
exclude("com.sk89q.worldedit", "worldedit-core")
exclude("com.sk89q.worldedit.worldedit-libs", "bukkit")
exclude("com.sk89q.worldedit.worldedit-libs", "core")
}
"implementation"("com.massivecraft:factions:2.8.0") { isTransitive = false }
"implementation"("com.drtshock:factions:1.6.9.5") { isTransitive = false }
"implementation"("com.factionsone:FactionsOne:1.2.2") { isTransitive = false }

View File

@ -1,273 +0,0 @@
package com.boydti.fawe.bukkit.chat;
import com.google.common.base.Preconditions;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
/**
* Represents a textual component of a message part.
* This can be used to not only represent string literals in a JSON message,
* but also to represent localized strings and other text values.
* <p>Different instances of this class can be created with static constructor methods.</p>
*/
public abstract class TextualComponent implements Cloneable {
static {
ConfigurationSerialization.registerClass(ArbitraryTextTypeComponent.class);
ConfigurationSerialization.registerClass(ComplexTextTypeComponent.class);
}
static TextualComponent deserialize(Map<String, Object> map) {
if (map.containsKey("key") && map.size() == 2 && map.containsKey("value")) {
// Arbitrary text component
return ArbitraryTextTypeComponent.deserialize(map);
} else if (map.size() >= 2 && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
// Complex JSON object
return ComplexTextTypeComponent.deserialize(map);
}
return null;
}
static boolean isTextKey(String key) {
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
}
static boolean isTranslatableText(TextualComponent component) {
return component instanceof ComplexTextTypeComponent && component.getKey().equals("translate");
}
/**
* Create a textual component representing a string literal.
*
* <p>This is the default type of textual component when a single string
* literal is given to a method.
*
* @param textValue The text which will be represented.
* @return The text component representing the specified literal text.
*/
public static TextualComponent rawText(String textValue) {
return new ArbitraryTextTypeComponent("text", textValue);
}
/**
* Create a textual component representing a localized string.
* The client will see this text component as their localized version of the specified string <em>key</em>, which can be overridden by a
* resource pack.
* <p>
* If the specified translation key is not present on the client resource pack, the translation key will be displayed as a string literal to
* the client.
* </p>
*
* @param translateKey The string key which maps to localized text.
* @return The text component representing the specified localized text.
*/
public static TextualComponent localizedText(String translateKey) {
return new ArbitraryTextTypeComponent("translate", translateKey);
}
private static void throwUnsupportedSnapshot() {
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
}
/**
* Create a textual component representing a player name, retrievable by using a standard minecraft selector.
* The client will see the players or entities captured by the specified selector as the text represented by this component.
* <p>
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
* </p>
*
* @param selector The minecraft player or entity selector which will capture the entities whose string representations will be displayed in
* the place of this text component.
* @return The text component representing the name of the entities captured by the selector.
*/
public static TextualComponent selector(String selector) {
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
// OVERLOADS documentation accordingly
return new ArbitraryTextTypeComponent("selector", selector);
}
@Override
public String toString() {
return getReadableString();
}
/**
* @return The JSON key used to represent text components of this type.
*/
public abstract String getKey();
/**
* @return A readable String
*/
public abstract String getReadableString();
/**
* Clones a textual component instance.
* The returned object should not reference this textual component instance, but should maintain the same key and value.
*/
@Override
public abstract TextualComponent clone() throws CloneNotSupportedException;
/**
* Writes the text data represented by this textual component to the specified JSON writer object.
* A new object within the writer is not started.
*
* @param writer The object to which to write the JSON data.
* @throws IOException If an error occurs while writing to the stream.
*/
public abstract void writeJson(JsonWriter writer) throws IOException;
/**
* Internal class used to represent all types of text components.
* Exception validating done is on keys and values.
*/
private static final class ArbitraryTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
private String key;
private String value;
public ArbitraryTextTypeComponent(String key, String value) {
setKey(key);
setValue(value);
}
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
}
@Override
public String getKey() {
return key;
}
public void setKey(String key) {
Preconditions.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
Preconditions.checkArgument(value != null, "The value must be specified.");
this.value = value;
}
@Override
public TextualComponent clone() throws CloneNotSupportedException {
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
return new ArbitraryTextTypeComponent(getKey(), getValue());
}
@Override
public void writeJson(JsonWriter writer) throws IOException {
writer.name(getKey()).value(getValue());
}
@Override
@SuppressWarnings("serial")
public Map<String, Object> serialize() {
return new HashMap<String, Object>() {
{
put("key", getKey());
put("value", getValue());
}
};
}
@Override
public String getReadableString() {
return getValue();
}
}
/**
* Internal class used to represent a text component with a nested JSON
* value.
*
* <p>Exception validating done is on keys and values.
*/
private static final class ComplexTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
private String key;
private Map<String, String> value;
public ComplexTextTypeComponent(String key, Map<String, String> values) {
setKey(key);
setValue(values);
}
public static ComplexTextTypeComponent deserialize(Map<String, Object> map) {
String key = null;
Map<String, String> value = new HashMap<>();
for (Map.Entry<String, Object> valEntry : map.entrySet()) {
if (valEntry.getKey().equals("key")) {
key = (String) valEntry.getValue();
} else if (valEntry.getKey().startsWith("value.")) {
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
}
}
return new ComplexTextTypeComponent(key, value);
}
@Override
public String getKey() {
return key;
}
public void setKey(String key) {
Preconditions.checkArgument(key != null && !key.isEmpty(), "The key must be specified.");
this.key = key;
}
public Map<String, String> getValue() {
return value;
}
public void setValue(Map<String, String> value) {
Preconditions.checkArgument(value != null, "The value must be specified.");
this.value = value;
}
@Override
public TextualComponent clone() {
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
return new ComplexTextTypeComponent(getKey(), getValue());
}
@Override
public void writeJson(JsonWriter writer) throws IOException {
writer.name(getKey());
writer.beginObject();
for (Map.Entry<String, String> jsonPair : value.entrySet()) {
writer.name(jsonPair.getKey()).value(jsonPair.getValue());
}
writer.endObject();
}
@Override
@SuppressWarnings("serial")
public Map<String, Object> serialize() {
return new HashMap<String, Object>() {
{
put("key", getKey());
for (Entry<String, String> valEntry : getValue().entrySet()) {
put("value." + valEntry.getKey(), valEntry.getValue());
}
}
};
}
@Override
public String getReadableString() {
return getKey();
}
}
}

View File

@ -19,6 +19,7 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
public class AsyncBlockState implements BlockState {
@ -99,6 +100,7 @@ public class AsyncBlockState implements BlockState {
return block.getLocation(loc);
}
@NotNull
@Override
public Chunk getChunk() {
return block.getChunk();

View File

@ -32,6 +32,7 @@ import java.io.File;
public class BukkitConfiguration extends YAMLConfiguration {
public boolean noOpPermissions = false;
public boolean commandBlockSupport = false;
@Unreported private final WorldEditPlugin plugin;
public BukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) {
@ -43,6 +44,7 @@ public class BukkitConfiguration extends YAMLConfiguration {
public void load() {
super.load();
noOpPermissions = config.getBoolean("no-op-permissions", false);
commandBlockSupport = config.getBoolean("command-block-support", false);
migrateLegacyFolders();
}

View File

@ -34,7 +34,6 @@ class BukkitRegistries extends BundledRegistries {
private static final BukkitRegistries INSTANCE = new BukkitRegistries();
private final BlockRegistry blockRegistry = new BukkitBlockRegistry();
private final ItemRegistry itemRegistry = new BukkitItemRegistry();
private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry();
private final EntityRegistry entityRegistry = new BukkitEntityRegistry();
private final BlockCategoryRegistry blockCategoryRegistry = new BukkitBlockCategoryRegistry();
@ -56,11 +55,6 @@ class BukkitRegistries extends BundledRegistries {
return biomeRegistry;
}
@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}
@Override
public BlockCategoryRegistry getBlockCategoryRegistry() {
return blockCategoryRegistry;

View File

@ -23,9 +23,11 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.FaweBukkit;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -33,6 +35,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import java.util.OptionalInt;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
@ -154,7 +157,30 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
*/
void sendFakeOP(Player player);
/**
* Simulates a player using an item.
*
* @param world the world
* @param position the location
* @param item the item to be used
* @param face the direction in which to "face" when using the item
* @return whether the usage was successful
*/
default boolean simulateItemUse(World world, BlockVector3 position, BaseItem item, Direction face) {
return false;
}
default @org.jetbrains.annotations.Nullable World createWorld(WorldCreator creator) {
return ((FaweBukkit) Fawe.imp()).createWorldUnloaded(creator::createWorld);
}
/**
* Retrieve the internal ID for a given state, if possible.
*
* @param state The block state
* @return the internal ID of the state
*/
default OptionalInt getInternalBlockStateId(BlockState state) {
return OptionalInt.empty();
}
}