Added an entity, weathertype, and gamemode registry.

Dieser Commit ist enthalten in:
Matthew Miller 2018-07-19 22:41:26 +10:00
Ursprung 572bf04482
Commit 663dd1f4d8
33 geänderte Dateien mit 747 neuen und 115 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,7 @@ import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
@ -105,8 +105,8 @@ class BukkitEntity implements Entity {
@Override
public <T> T getFacet(Class<? extends T> cls) {
org.bukkit.entity.Entity entity = entityRef.get();
if (entity != null && EntityType.class.isAssignableFrom(cls)) {
return (T) new BukkitEntityType(entity);
if (entity != null && EntityProperties.class.isAssignableFrom(cls)) {
return (T) new BukkitEntityProperties(entity);
} else {
return null;
}

Datei anzeigen

@ -19,7 +19,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.util.Enums;
import org.bukkit.entity.Ambient;
import org.bukkit.entity.Animals;
@ -44,14 +44,14 @@ import org.bukkit.entity.minecart.ExplosiveMinecart;
import static com.google.common.base.Preconditions.checkNotNull;
class BukkitEntityType implements EntityType {
class BukkitEntityProperties implements EntityProperties {
private static final org.bukkit.entity.EntityType armorStandType =
Enums.findByValue(org.bukkit.entity.EntityType.class, "ARMOR_STAND");
private final Entity entity;
BukkitEntityType(Entity entity) {
BukkitEntityProperties(Entity entity) {
checkNotNull(entity);
this.entity = entity;
}

Datei anzeigen

@ -31,8 +31,9 @@ import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -126,6 +127,16 @@ public class BukkitPlayer extends AbstractPlayerActor {
return new BukkitPlayerBlockBag(player);
}
@Override
public GameMode getGameMode() {
return GameModes.get(player.getGameMode().name().toLowerCase());
}
@Override
public void setGameMode(GameMode gameMode) {
player.setGameMode(org.bukkit.GameMode.valueOf(gameMode.getId().toUpperCase()));
}
@Override
public boolean hasPermission(String perm) {
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
@ -152,11 +163,6 @@ public class BukkitPlayer extends AbstractPlayerActor {
return player;
}
@Override
public boolean hasCreativeMode() {
return player.getGameMode() == GameMode.CREATIVE;
}
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.getAllowFlight()) {

Datei anzeigen

@ -38,6 +38,8 @@ import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import org.bukkit.Effect;
import org.bukkit.TreeType;
import org.bukkit.World;
@ -348,6 +350,51 @@ public class BukkitWorld extends AbstractWorld {
return true;
}
@Override
public WeatherType getWeather() {
if (getWorld().isThundering()) {
return WeatherTypes.THUNDER_STORM;
} else if (getWorld().hasStorm()) {
return WeatherTypes.RAIN;
}
return WeatherTypes.CLEAR;
}
@Override
public long getRemainingWeatherDuration() {
return getWorld().getWeatherDuration();
}
@Override
public void setWeather(WeatherType weatherType) {
if (weatherType == WeatherTypes.THUNDER_STORM) {
getWorld().setThundering(true);
} else if (weatherType == WeatherTypes.RAIN) {
getWorld().setStorm(true);
} else {
getWorld().setStorm(false);
getWorld().setThundering(false);
}
}
@Override
public void setWeather(WeatherType weatherType, long duration) {
// Who named these methods...
if (weatherType == WeatherTypes.THUNDER_STORM) {
getWorld().setThundering(true);
getWorld().setThunderDuration((int) duration);
getWorld().setWeatherDuration((int) duration);
} else if (weatherType == WeatherTypes.RAIN) {
getWorld().setStorm(true);
getWorld().setWeatherDuration((int) duration);
} else {
getWorld().setStorm(false);
getWorld().setThundering(false);
getWorld().setWeatherDuration((int) duration);
}
}
@Override
public void simulateBlockMine(Vector pt) {
getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally();

Datei anzeigen

@ -20,7 +20,7 @@
package com.sk89q.worldedit.command.util;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.EntityFunction;
@ -87,7 +87,7 @@ public class CreatureButcher {
boolean killTagged = (flags & Flags.TAGGED) != 0;
boolean killArmorStands = (flags & Flags.ARMOR_STAND) != 0;
EntityType type = entity.getFacet(EntityType.class);
EntityProperties type = entity.getFacet(EntityProperties.class);
if (type == null) {
return false;

Datei anzeigen

@ -22,7 +22,7 @@ package com.sk89q.worldedit.command.util;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.function.EntityFunction;
import java.util.regex.Pattern;
@ -37,7 +37,7 @@ public class EntityRemover {
public enum Type {
ALL("all") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
for (Type value : values()) {
if (value != this && value.matches(type)) {
return true;
@ -48,55 +48,55 @@ public class EntityRemover {
},
PROJECTILES("projectiles?|arrows?") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isProjectile();
}
},
ITEMS("items?|drops?") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isItem();
}
},
FALLING_BLOCKS("falling(blocks?|sand|gravel)") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isFallingBlock();
}
},
PAINTINGS("paintings?|art") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isPainting();
}
},
ITEM_FRAMES("(item)frames?") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isItemFrame();
}
},
BOATS("boats?") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isBoat();
}
},
MINECARTS("(mine)?carts?") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isMinecart();
}
},
TNT("tnt") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isTNT();
}
},
XP_ORBS("xp") {
@Override
boolean matches(EntityType type) {
boolean matches(EntityProperties type) {
return type.isExperienceOrb();
}
};
@ -111,7 +111,7 @@ public class EntityRemover {
return pattern.matcher(str).matches();
}
abstract boolean matches(EntityType type);
abstract boolean matches(EntityProperties type);
@Nullable
public static Type findByPattern(String str) {
@ -140,7 +140,7 @@ public class EntityRemover {
final Type type = this.type;
checkNotNull(type, "type can't be null");
return entity -> {
EntityType registryType = entity.getFacet(EntityType.class);
EntityProperties registryType = entity.getFacet(EntityProperties.class);
if (registryType != null) {
if (type.matches(registryType)) {
entity.remove();

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.entity;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.NbtValued;
import com.sk89q.worldedit.world.entity.EntityType;
import javax.annotation.Nullable;
@ -41,27 +42,27 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class BaseEntity implements NbtValued {
private String id;
private EntityType type;
private CompoundTag nbtData;
/**
* Create a new base entity.
*
* @param id the entity type ID
* @param type the entity type
* @param nbtData NBT data
*/
public BaseEntity(String id, CompoundTag nbtData) {
setTypeId(id);
public BaseEntity(EntityType type, CompoundTag nbtData) {
this(type);
setNbtData(nbtData);
}
/**
* Create a new base entity with no NBT data.
*
* @param id the entity type ID
* @param type the entity type
*/
public BaseEntity(String id) {
setTypeId(id);
public BaseEntity(EntityType type) {
this.type = type;
}
/**
@ -71,7 +72,7 @@ public class BaseEntity implements NbtValued {
*/
public BaseEntity(BaseEntity other) {
checkNotNull(other);
setTypeId(other.getTypeId());
this.type = other.getType();
setNbtData(other.getNbtData());
}
@ -92,22 +93,12 @@ public class BaseEntity implements NbtValued {
}
/**
* Get the entity that determines the type of entity.
* Get the type of entity.
*
* @return the entity ID
* @return the entity type
*/
public String getTypeId() {
return id;
}
/**
* Set the entity ID that determines the type of entity.
*
* @param id the id
*/
public void setTypeId(String id) {
checkNotNull(id);
this.id = id;
public EntityType getType() {
return this.type;
}
}

Datei anzeigen

@ -29,6 +29,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.gamemode.GameMode;
/**
* Represents a player
@ -86,11 +87,18 @@ public interface Player extends Entity, Actor {
BlockBag getInventoryBlockBag();
/**
* Return whether this actor has creative mode.
* Return this actor's game mode.
*
* @return true if creative mode is enabled
* @return the game mode
*/
boolean hasCreativeMode();
GameMode getGameMode();
/**
* Sets the player to the given game mode.
*
* @param gameMode The game mode
*/
void setGameMode(GameMode gameMode);
/**
* Find a position for the actor to stand that is not inside a block.

Datei anzeigen

@ -22,7 +22,7 @@ package com.sk89q.worldedit.entity.metadata;
/**
* Describes various classes of entities.
*/
public interface EntityType {
public interface EntityProperties {
/**
* Test whether the entity is a player-derived entity.

Datei anzeigen

@ -27,6 +27,8 @@ import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.entity.Player;
@ -474,8 +476,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
}
@Override
public boolean hasCreativeMode() {
return false;
public GameMode getGameMode() {
return GameModes.SURVIVAL;
}
@Override
public void setGameMode(GameMode gameMode) {
}
@SuppressWarnings("CloneDoesntCallSuperClone")

Datei anzeigen

@ -29,6 +29,7 @@ import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.gamemode.GameMode;
import javax.annotation.Nullable;
@ -144,4 +145,14 @@ class PlayerProxy extends AbstractPlayerActor {
public SessionKey getSessionKey() {
return basePlayer.getSessionKey();
}
@Override
public GameMode getGameMode() {
return basePlayer.getGameMode();
}
@Override
public void setGameMode(GameMode gameMode) {
basePlayer.setGameMode(gameMode);
}
}

Datei anzeigen

@ -42,6 +42,7 @@ import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SignCompatibilityHan
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.storage.NBTConversions;
import java.io.IOException;
@ -256,7 +257,7 @@ public class SchematicReader implements ClipboardReader {
Location location = NBTConversions.toLocation(clipboard, compound.getListTag("Pos"), compound.getListTag("Rotation"));
if (!id.isEmpty()) {
BaseEntity state = new BaseEntity(id, compound);
BaseEntity state = new BaseEntity(EntityTypes.get(id), compound);
clipboard.createEntity(location, state);
}
}

Datei anzeigen

@ -167,7 +167,7 @@ public class ExtentEntityCopy implements EntityFunction {
}
}
return new BaseEntity(state.getTypeId(), builder.build());
return new BaseEntity(state.getType(), builder.build());
}
}

Datei anzeigen

@ -22,7 +22,7 @@ package com.sk89q.worldedit.function.operation;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.CombinedRegionFunction;
import com.sk89q.worldedit.function.RegionFunction;
@ -261,7 +261,7 @@ public class ForwardExtentCopy implements Operation {
// Switch to entities.removeIf after Java 8 cutoff.
Iterator<? extends Entity> entityIterator = entities.iterator();
while (entityIterator.hasNext()) {
EntityType type = entityIterator.next().getFacet(EntityType.class);
EntityProperties type = entityIterator.next().getFacet(EntityProperties.class);
if (type != null && !type.isPasteable()) {
entityIterator.remove();

Datei anzeigen

@ -19,59 +19,38 @@
package com.sk89q.worldedit.registry;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
public final class NamespacedRegistry<V> implements Iterable<V> {
import javax.annotation.Nullable;
public final class NamespacedRegistry<V> extends Registry<V> {
private static final String MINECRAFT_NAMESPACE = "minecraft";
private final Map<String, V> map = new HashMap<>();
private final String name;
private final String defaultNamespace;
public NamespacedRegistry(final String name) {
this.name = name;
this(name, MINECRAFT_NAMESPACE);
}
public NamespacedRegistry(final String name, final String defaultNamespace) {
super(name);
this.defaultNamespace = defaultNamespace;
}
public @Nullable V get(final String key) {
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
return this.map.get(this.orDefaultNamespace(key));
return super.get(this.orDefaultNamespace(key));
}
public V register(final String key, final V value) {
requireNonNull(key, "key");
requireNonNull(value, "value");
checkState(key.indexOf(':') > -1, "key is not namespaced");
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
checkState(!this.map.containsKey(key), "key '%s' already has an associated %s", key, this.name);
this.map.put(key, value);
return value;
}
public Set<String> keySet() {
return Collections.unmodifiableSet(this.map.keySet());
}
public Collection<V> values() {
return Collections.unmodifiableCollection(this.map.values());
return super.register(key, value);
}
private String orDefaultNamespace(final String key) {
if (key.indexOf(':') == -1) {
return MINECRAFT_NAMESPACE + ':' + key;
return defaultNamespace + ':' + key;
}
return key;
}
@Override
public Iterator<V> iterator() {
return this.map.values().iterator();
}
}

Datei anzeigen

@ -0,0 +1,69 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* 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
* (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.
*
* 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/>.
*/
package com.sk89q.worldedit.registry;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
public class Registry<V> implements Iterable<V> {
private final Map<String, V> map = new HashMap<>();
private final String name;
public Registry(final String name) {
this.name = name;
}
public @Nullable V get(final String key) {
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
return this.map.get(key);
}
public V register(final String key, final V value) {
requireNonNull(key, "key");
requireNonNull(value, "value");
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
checkState(!this.map.containsKey(key), "key '%s' already has an associated %s", key, this.name);
this.map.put(key, value);
return value;
}
public Set<String> keySet() {
return Collections.unmodifiableSet(this.map.keySet());
}
public Collection<V> values() {
return Collections.unmodifiableCollection(this.map.values());
}
@Override
public Iterator<V> iterator() {
return this.map.values().iterator();
}
}

Datei anzeigen

@ -33,6 +33,7 @@ import com.sk89q.worldedit.session.storage.SessionStore;
import com.sk89q.worldedit.session.storage.VoidStore;
import com.sk89q.worldedit.util.concurrency.EvenMoreExecutors;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.gamemode.GameModes;
import javax.annotation.Nullable;
import java.io.File;
@ -186,7 +187,7 @@ public class SessionManager {
session.setUseInventory(config.useInventory
&& !(config.useInventoryOverride
&& (owner.hasPermission("worldedit.inventory.unrestricted")
|| (config.useInventoryCreativeOverride && (!(owner instanceof Player) || ((Player) owner).hasCreativeMode())))));
|| (config.useInventoryCreativeOverride && (!(owner instanceof Player) || ((Player) owner).getGameMode() == GameModes.CREATIVE)))));
return session;
}

Datei anzeigen

@ -36,6 +36,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.weather.WeatherType;
import java.util.Collections;
import java.util.List;
@ -101,6 +102,24 @@ public class NullWorld extends AbstractWorld {
return false;
}
@Override
public WeatherType getWeather() {
return null;
}
@Override
public long getRemainingWeatherDuration() {
return 0;
}
@Override
public void setWeather(WeatherType weatherType) {
}
@Override
public void setWeather(WeatherType weatherType, long duration) {
}
@Override
public BlockState getBlock(Vector position) {
return BlockTypes.AIR.getDefaultState();

Datei anzeigen

@ -34,6 +34,7 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.weather.WeatherType;
/**
* Represents a world (dimension).
@ -202,6 +203,35 @@ public interface World extends Extent {
*/
boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority);
/**
* Gets the weather type of the world.
*
* @return The weather
*/
WeatherType getWeather();
/**
* Gets the remaining weather duration.
*
* @return The weather duration
*/
long getRemainingWeatherDuration();
/**
* Sets the weather type of the world.
*
* @param weatherType The weather type
*/
void setWeather(WeatherType weatherType);
/**
* Sets the weather type of the world.
*
* @param weatherType The weather type
* @param duration The duration of the weather
*/
void setWeather(WeatherType weatherType, long duration);
@Override
boolean equals(Object other);

Datei anzeigen

@ -0,0 +1,61 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* 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
* (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.
*
* 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/>.
*/
package com.sk89q.worldedit.world.entity;
import com.sk89q.worldedit.registry.NamespacedRegistry;
public class EntityType {
public static final NamespacedRegistry<EntityType> REGISTRY = new NamespacedRegistry<>("entity type");
private String id;
public EntityType(String id) {
// If it has no namespace, assume minecraft.
if (!id.contains(":")) {
id = "minecraft:" + id;
}
this.id = id;
}
public String getId() {
return this.id;
}
/**
* Gets the name of this item, or the ID if the name cannot be found.
*
* @return The name, or ID
*/
public String getName() {
return getId();
}
@Override
public int hashCode() {
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof EntityType && this.id.equals(((EntityType) obj).id);
}
}

Datei anzeigen

@ -0,0 +1,137 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* 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
* (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.
*
* 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/>.
*/
package com.sk89q.worldedit.world.entity;
import javax.annotation.Nullable;
public class EntityTypes {
public static final EntityType AREA_EFFECT_CLOUD = register("minecraft:area_effect_cloud");
public static final EntityType ARMOR_STAND = register("minecraft:armor_stand");
public static final EntityType ARROW = register("minecraft:arrow");
public static final EntityType BAT = register("minecraft:bat");
public static final EntityType BLAZE = register("minecraft:blaze");
public static final EntityType BOAT = register("minecraft:boat");
public static final EntityType CAVE_SPIDER = register("minecraft:cave_spider");
public static final EntityType CHEST_MINECART = register("minecraft:chest_minecart");
public static final EntityType CHICKEN = register("minecraft:chicken");
public static final EntityType COD = register("minecraft:cod");
public static final EntityType COMMAND_BLOCK_MINECART = register("minecraft:command_block_minecart");
public static final EntityType COW = register("minecraft:cow");
public static final EntityType CREEPER = register("minecraft:creeper");
public static final EntityType DOLPHIN = register("minecraft:dolphin");
public static final EntityType DONKEY = register("minecraft:donkey");
public static final EntityType DRAGON_FIREBALL = register("minecraft:dragon_fireball");
public static final EntityType DROWNED = register("minecraft:drowned");
public static final EntityType EGG = register("minecraft:egg");
public static final EntityType ELDER_GUARDIAN = register("minecraft:elder_guardian");
public static final EntityType END_CRYSTAL = register("minecraft:end_crystal");
public static final EntityType ENDER_DRAGON = register("minecraft:ender_dragon");
public static final EntityType ENDER_PEARL = register("minecraft:ender_pearl");
public static final EntityType ENDERMAN = register("minecraft:enderman");
public static final EntityType ENDERMITE = register("minecraft:endermite");
public static final EntityType EVOKER = register("minecraft:evoker");
public static final EntityType EVOKER_FANGS = register("minecraft:evoker_fangs");
public static final EntityType EXPERIENCE_BOTTLE = register("minecraft:experience_bottle");
public static final EntityType EXPERIENCE_ORB = register("minecraft:experience_orb");
public static final EntityType EYE_OF_ENDER = register("minecraft:eye_of_ender");
public static final EntityType FALLING_BLOCK = register("minecraft:falling_block");
public static final EntityType FIREBALL = register("minecraft:fireball");
public static final EntityType FIREWORK_ROCKET = register("minecraft:firework_rocket");
public static final EntityType FISHING_BOBBER = register("minecraft:fishing_bobber");
public static final EntityType FURNACE_MINECART = register("minecraft:furnace_minecart");
public static final EntityType GHAST = register("minecraft:ghast");
public static final EntityType GIANT = register("minecraft:giant");
public static final EntityType GUARDIAN = register("minecraft:guardian");
public static final EntityType HOPPER_MINECART = register("minecraft:hopper_minecart");
public static final EntityType HORSE = register("minecraft:horse");
public static final EntityType HUSK = register("minecraft:husk");
public static final EntityType ILLUSIONER = register("minecraft:illusioner");
public static final EntityType IRON_GOLEM = register("minecraft:iron_golem");
public static final EntityType ITEM = register("minecraft:item");
public static final EntityType ITEM_FRAME = register("minecraft:item_frame");
public static final EntityType LEASH_KNOT = register("minecraft:leash_knot");
public static final EntityType LIGHTNING_BOLT = register("minecraft:lightning_bolt");
public static final EntityType LLAMA = register("minecraft:llama");
public static final EntityType LLAMA_SPIT = register("minecraft:llama_spit");
public static final EntityType MAGMA_CUBE = register("minecraft:magma_cube");
public static final EntityType MINECART = register("minecraft:minecart");
public static final EntityType MOOSHROOM = register("minecraft:mooshroom");
public static final EntityType MULE = register("minecraft:mule");
public static final EntityType OCELOT = register("minecraft:ocelot");
public static final EntityType PAINTING = register("minecraft:painting");
public static final EntityType PARROT = register("minecraft:parrot");
public static final EntityType PHANTOM = register("minecraft:phantom");
public static final EntityType PIG = register("minecraft:pig");
public static final EntityType PLAYER = register("minecraft:player");
public static final EntityType POLAR_BEAR = register("minecraft:polar_bear");
public static final EntityType POTION = register("minecraft:potion");
public static final EntityType PUFFERFISH = register("minecraft:pufferfish");
public static final EntityType RABBIT = register("minecraft:rabbit");
public static final EntityType SALMON = register("minecraft:salmon");
public static final EntityType SHEEP = register("minecraft:sheep");
public static final EntityType SHULKER = register("minecraft:shulker");
public static final EntityType SHULKER_BULLET = register("minecraft:shulker_bullet");
public static final EntityType SILVERFISH = register("minecraft:silverfish");
public static final EntityType SKELETON = register("minecraft:skeleton");
public static final EntityType SKELETON_HORSE = register("minecraft:skeleton_horse");
public static final EntityType SLIME = register("minecraft:slime");
public static final EntityType SMALL_FIREBALL = register("minecraft:small_fireball");
public static final EntityType SNOW_GOLEM = register("minecraft:snow_golem");
public static final EntityType SNOWBALL = register("minecraft:snowball");
public static final EntityType SPAWNER_MINECART = register("minecraft:spawner_minecart");
public static final EntityType SPECTRAL_ARROW = register("minecraft:spectral_arrow");
public static final EntityType SPIDER = register("minecraft:spider");
public static final EntityType SQUID = register("minecraft:squid");
public static final EntityType STRAY = register("minecraft:stray");
public static final EntityType TNT = register("minecraft:tnt");
public static final EntityType TNT_MINECART = register("minecraft:tnt_minecart");
public static final EntityType TRIDENT = register("minecraft:trident");
public static final EntityType TROPICAL_FISH = register("minecraft:tropical_fish");
public static final EntityType TURTLE = register("minecraft:turtle");
public static final EntityType VEX = register("minecraft:vex");
public static final EntityType VILLAGER = register("minecraft:villager");
public static final EntityType VINDICATOR = register("minecraft:vindicator");
public static final EntityType WITCH = register("minecraft:witch");
public static final EntityType WITHER = register("minecraft:wither");
public static final EntityType WITHER_SKELETON = register("minecraft:wither_skeleton");
public static final EntityType WITHER_SKULL = register("minecraft:wither_skull");
public static final EntityType WOLF = register("minecraft:wolf");
public static final EntityType ZOMBIE = register("minecraft:zombie");
public static final EntityType ZOMBIE_HORSE = register("minecraft:zombie_horse");
public static final EntityType ZOMBIE_PIGMAN = register("minecraft:zombie_pigman");
public static final EntityType ZOMBIE_VILLAGER = register("minecraft:zombie_villager");
private EntityTypes() {
}
private static EntityType register(final String id) {
return register(new EntityType(id));
}
public static EntityType register(final EntityType entityType) {
return EntityType.REGISTRY.register(entityType.getId(), entityType);
}
public static @Nullable EntityType get(final String id) {
return EntityType.REGISTRY.get(id);
}
}

Datei anzeigen

@ -0,0 +1,57 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* 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
* (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.
*
* 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/>.
*/
package com.sk89q.worldedit.world.gamemode;
import com.sk89q.worldedit.registry.Registry;
public class GameMode {
public static final Registry<GameMode> REGISTRY = new Registry<>("game mode");
private String id;
public GameMode(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
/**
* Gets the name of this game mode, or the ID if the name cannot be found.
*
* @return The name, or ID
*/
public String getName() {
return getId();
}
@Override
public int hashCode() {
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof GameMode && this.id.equals(((GameMode) obj).id);
}
}

Datei anzeigen

@ -0,0 +1,47 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* 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
* (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.
*
* 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/>.
*/
package com.sk89q.worldedit.world.gamemode;
import javax.annotation.Nullable;
public class GameModes {
public static final GameMode NOT_SET = register("");
public static final GameMode SURVIVAL = register("survival");
public static final GameMode CREATIVE = register("creative");
public static final GameMode ADVENTURE = register("adventure");
public static final GameMode SPECTATOR = register("spectator");
private GameModes() {
}
private static GameMode register(final String id) {
return register(new GameMode(id));
}
public static GameMode register(final GameMode gameMode) {
return GameMode.REGISTRY.register(gameMode.getId(), gameMode);
}
public static @Nullable GameMode get(final String id) {
return GameMode.REGISTRY.get(id);
}
}

Datei anzeigen

@ -0,0 +1,57 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* 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
* (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.
*
* 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/>.
*/
package com.sk89q.worldedit.world.weather;
import com.sk89q.worldedit.registry.Registry;
public class WeatherType {
public static final Registry<WeatherType> REGISTRY = new Registry<>("weather type");
private String id;
public WeatherType(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
/**
* Gets the name of this weather, or the ID if the name cannot be found.
*
* @return The name, or ID
*/
public String getName() {
return getId();
}
@Override
public int hashCode() {
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof WeatherType && this.id.equals(((WeatherType) obj).id);
}
}

Datei anzeigen

@ -0,0 +1,44 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* 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
* (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.
*
* 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/>.
*/
package com.sk89q.worldedit.world.weather;
import javax.annotation.Nullable;
public class WeatherTypes {
public static final WeatherType CLEAR = register("clear");
public static final WeatherType RAIN = register("rain");
public static final WeatherType THUNDER_STORM = register("thunder_storm");
private WeatherTypes() {
}
private static WeatherType register(final String id) {
return register(new WeatherType(id));
}
public static WeatherType register(final WeatherType weatherType) {
return WeatherType.REGISTRY.register(weatherType.getId(), weatherType);
}
public static @Nullable WeatherType get(final String id) {
return WeatherType.REGISTRY.get(id);
}
}

Datei anzeigen

@ -22,10 +22,11 @@ package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
import com.sk89q.worldedit.world.entity.EntityTypes;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.NBTTagCompound;
@ -40,7 +41,7 @@ class ForgeEntity implements Entity {
ForgeEntity(net.minecraft.entity.Entity entity) {
checkNotNull(entity);
this.entityRef = new WeakReference<net.minecraft.entity.Entity>(entity);
this.entityRef = new WeakReference<>(entity);
}
@Override
@ -51,7 +52,7 @@ class ForgeEntity implements Entity {
if (id != null) {
NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
return new BaseEntity(id, NBTConverter.fromNative(tag));
return new BaseEntity(EntityTypes.get(id), NBTConverter.fromNative(tag));
} else {
return null;
}
@ -99,8 +100,8 @@ class ForgeEntity implements Entity {
public <T> T getFacet(Class<? extends T> cls) {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
if (EntityType.class.isAssignableFrom(cls)) {
return (T) new ForgeEntityType(entity);
if (EntityProperties.class.isAssignableFrom(cls)) {
return (T) new ForgeEntityProperties(entity);
} else {
return null;
}

Datei anzeigen

@ -19,7 +19,7 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IMerchant;
@ -45,11 +45,11 @@ import net.minecraft.entity.player.EntityPlayerMP;
import static com.google.common.base.Preconditions.checkNotNull;
public class ForgeEntityType implements EntityType {
public class ForgeEntityProperties implements EntityProperties {
private final Entity entity;
public ForgeEntityType(Entity entity) {
public ForgeEntityProperties(Entity entity) {
checkNotNull(entity);
this.entity = entity;
}

Datei anzeigen

@ -47,6 +47,7 @@ import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.weather.WeatherType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockOldLeaf;
@ -350,6 +351,27 @@ public class ForgeWorld extends AbstractWorld {
return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position));
}
@Override
public WeatherType getWeather() {
// TODO Weather implementation
return null;
}
@Override
public long getRemainingWeatherDuration() {
return 0;
}
@Override
public void setWeather(WeatherType weatherType) {
}
@Override
public void setWeather(WeatherType weatherType, long duration) {
}
@Override
public BlockState getBlock(Vector position) {
World world = getWorld();
@ -421,7 +443,7 @@ public class ForgeWorld extends AbstractWorld {
@Override
public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld();
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getTypeId()), world);
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getType().getId()), world);
if (createdEntity != null) {
CompoundTag nativeTag = entity.getNbtData();
if (nativeTag != null) {

Datei anzeigen

@ -22,7 +22,7 @@ package com.sk89q.worldedit.sponge;
import com.flowpowered.math.vector.Vector3d;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
@ -90,8 +90,8 @@ class SpongeEntity implements Entity {
public <T> T getFacet(Class<? extends T> cls) {
org.spongepowered.api.entity.Entity entity = entityRef.get();
if (entity != null) {
if (EntityType.class.isAssignableFrom(cls)) {
return (T) new SpongeEntityType(entity);
if (EntityProperties.class.isAssignableFrom(cls)) {
return (T) new SpongeEntityProperties(entity);
} else {
return null;
}

Datei anzeigen

@ -21,7 +21,7 @@ package com.sk89q.worldedit.sponge;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.entity.metadata.EntityType;
import com.sk89q.worldedit.entity.metadata.EntityProperties;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.ExperienceOrb;
@ -46,11 +46,11 @@ import org.spongepowered.api.text.Text;
import java.util.Optional;
public class SpongeEntityType implements EntityType {
public class SpongeEntityProperties implements EntityProperties {
private final Entity entity;
public SpongeEntityType(Entity entity) {
public SpongeEntityProperties(Entity entity) {
checkNotNull(entity);
this.entity = entity;
}

Datei anzeigen

@ -23,6 +23,8 @@ import com.flowpowered.math.vector.Vector3d;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
@ -170,6 +172,17 @@ public class SpongePlayer extends AbstractPlayerActor {
return null;
}
@Override
public GameMode getGameMode() {
return GameModes.get(player.getGameModeData().type().get().getId());
}
@Override
public void setGameMode(GameMode gameMode) {
player.getGameModeData().type().set(Sponge.getRegistry().getType(org.spongepowered.api.entity.living.player.gamemode.GameMode.class,
gameMode.getId()).get());
}
@Override
public SessionKey getSessionKey() {
return new SessionKeyImpl(player.getUniqueId(), player.getName());

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.sponge;
import static com.google.common.base.Preconditions.checkNotNull;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import com.sk89q.worldedit.EditSession;
@ -27,15 +29,17 @@ import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockState;
@ -49,15 +53,15 @@ import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.world.BlockChangeFlags;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.weather.Weather;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* An adapter to Minecraft worlds for WorldEdit.
@ -266,7 +270,7 @@ public abstract class SpongeWorld extends AbstractWorld {
public Entity createEntity(Location location, BaseEntity entity) {
World world = getWorld();
EntityType entityType = Sponge.getRegistry().getType(EntityType.class, entity.getTypeId()).get();
EntityType entityType = Sponge.getRegistry().getType(EntityType.class, entity.getType().getId()).get();
Vector3d pos = new Vector3d(location.getX(), location.getY(), location.getZ());
org.spongepowered.api.entity.Entity newEnt = world.createEntity(entityType, pos);
@ -289,6 +293,26 @@ public abstract class SpongeWorld extends AbstractWorld {
return null;
}
@Override
public WeatherType getWeather() {
return WeatherTypes.get(getWorld().getWeather().getId());
}
@Override
public long getRemainingWeatherDuration() {
return getWorld().getRemainingDuration();
}
@Override
public void setWeather(WeatherType weatherType) {
getWorld().setWeather(Sponge.getRegistry().getType(Weather.class, weatherType.getId()).get());
}
@Override
public void setWeather(WeatherType weatherType, long duration) {
getWorld().setWeather(Sponge.getRegistry().getType(Weather.class, weatherType.getId()).get(), duration);
}
/**
* Thrown when the reference to the world is lost.
*/