From 663dd1f4d887171a27df77032732cdfdb417918c Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 19 Jul 2018 22:41:26 +1000 Subject: [PATCH] Added an entity, weathertype, and gamemode registry. --- .../sk89q/worldedit/bukkit/BukkitEntity.java | 6 +- ...yType.java => BukkitEntityProperties.java} | 6 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 18 ++- .../sk89q/worldedit/bukkit/BukkitWorld.java | 47 ++++++ .../bukkit/adapter/impl/Spigot_v1_13_R1.class | Bin 19807 -> 20082 bytes .../command/util/CreatureButcher.java | 4 +- .../worldedit/command/util/EntityRemover.java | 26 ++-- .../sk89q/worldedit/entity/BaseEntity.java | 35 ++--- .../com/sk89q/worldedit/entity/Player.java | 14 +- ...{EntityType.java => EntityProperties.java} | 2 +- .../platform/AbstractPlayerActor.java | 11 +- .../extension/platform/PlayerProxy.java | 11 ++ .../extent/clipboard/io/SchematicReader.java | 3 +- .../function/entity/ExtentEntityCopy.java | 2 +- .../function/operation/ForwardExtentCopy.java | 4 +- .../registry/NamespacedRegistry.java | 47 ++---- .../sk89q/worldedit/registry/Registry.java | 69 +++++++++ .../worldedit/session/SessionManager.java | 3 +- .../com/sk89q/worldedit/world/NullWorld.java | 19 +++ .../java/com/sk89q/worldedit/world/World.java | 30 ++++ .../worldedit/world/entity/EntityType.java | 61 ++++++++ .../worldedit/world/entity/EntityTypes.java | 137 ++++++++++++++++++ .../worldedit/world/gamemode/GameMode.java | 57 ++++++++ .../worldedit/world/gamemode/GameModes.java | 47 ++++++ .../worldedit/world/weather/WeatherType.java | 57 ++++++++ .../worldedit/world/weather/WeatherTypes.java | 44 ++++++ .../sk89q/worldedit/forge/ForgeEntity.java | 11 +- ...tyType.java => ForgeEntityProperties.java} | 6 +- .../com/sk89q/worldedit/forge/ForgeWorld.java | 24 ++- .../sk89q/worldedit/sponge/SpongeEntity.java | 6 +- ...yType.java => SpongeEntityProperties.java} | 6 +- .../sk89q/worldedit/sponge/SpongePlayer.java | 13 ++ .../sk89q/worldedit/sponge/SpongeWorld.java | 36 ++++- 33 files changed, 747 insertions(+), 115 deletions(-) rename worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/{BukkitEntityType.java => BukkitEntityProperties.java} (96%) rename worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/{EntityType.java => EntityProperties.java} (99%) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameModes.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java rename worldedit-forge/src/main/java/com/sk89q/worldedit/forge/{ForgeEntityType.java => ForgeEntityProperties.java} (95%) rename worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/{SpongeEntityType.java => SpongeEntityProperties.java} (95%) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java index 010ad55bc..085f6c8b8 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java @@ -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 getFacet(Class 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; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java similarity index 96% rename from worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java rename to worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java index 67ec4d2c8..0e20172bd 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityType.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntityProperties.java @@ -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; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index eac2dc0af..7eed49eba 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -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()) { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 12f2ca8b0..36dd574b9 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -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(); diff --git a/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class b/worldedit-bukkit/src/main/resources/com/sk89q/worldedit/bukkit/adapter/impl/Spigot_v1_13_R1.class index 3be81c1a3d8f72167fb23b2ee57a9aaf0588fcec..ccf0a882df1066b7906adcb9a49c20fd6acbe1f3 100644 GIT binary patch delta 6674 zcmZu$2YggT6Q7yA%U<4XAOr%rKtc-;QV0PA5^AJK3m`>^fDlNehZaOcIB6CTDG!h+ zC<=-NH4wN9V=0yiai4|dxYvSkd{&zM7Cwj1TW}2?@XPR^g)iWX7Bs{|8V^f< zL?}mP?j>oM;bnZq!ejWVG{@!jH49(I6BfRKZ)$u?`nRQdN1At~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K^4E&xDPzY|T2uB!} zy_n(GWpF#Y#@!tX25-H1Izw{H#ktk4+pwzIaVsbsf(2ZV_EwEfUmkJoujF!th_0MB z9R6Zt43)g*ZLKWTI0%Q~aNsKn<7@=pz&lzKyW&V3#hDnux>$&#!G&Yk0y&r?g3h$D zJgi`jW2T&pjlg>WxTM^uar_0Ssc`~h=R5>7PRz|sJr5}wC!OJQVKUDpoWehTs_?R$ z#`F@yN3&7O(qCp=?oQtirWgj7!*WKMwO}RmT8iC zcLzKfez%k3Z7U;q>1a9R6l8?q9?`wB7-Gs{RRIgE48gr&xKF679jYzV)gib)3~PkC z)}gKw>e>)I5QgHQkk>op4MJWYf(OH}QK)$ib(2u@Lhw)+9v13mhq^_mn?vwO7#qa(I%xe<}<+Wcp4=$u3qBgqy(?TcW<2K;HW-y z#o1WII64i9I0tWH(C{W#A#WMZWm&AkR)yp|o>d_^pD`TCi>E@g=OQFJ*t(ffbuI`k z&Vo12`Rl83L1J87ttdtmKWl zfmFXMj_b^RsRgkNpUdDmKrr|=H*URjtbQpR3~&wGUf_3U@P9vdT+YZxdQ@D2`*Zzk z$(Nm5ooLkOS|3EYK(Gmy{e>ay?;;MZmrtBoxR_0igkHFW=P5{l4!D$QF39J9y57c7 za#zKrV*c$szk+v1W${kn_ce#Ana4THmutL}&+QC_f{wE1ZcTX4_D%SOpoJhqg)^fQy4a@(Pqf~19G2R#5CY5 z!&1DT)93;InuBW?LV)F$0g2@dNV_rt { - EntityType registryType = entity.getFacet(EntityType.class); + EntityProperties registryType = entity.getFacet(EntityProperties.class); if (registryType != null) { if (type.matches(registryType)) { entity.remove(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java index 4b8237400..5c853a2a6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/BaseEntity.java @@ -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; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java index 690eb027a..958f811fa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java @@ -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. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityProperties.java similarity index 99% rename from worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityType.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityProperties.java index 44bf37888..6e343ba84 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/metadata/EntityProperties.java @@ -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. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index 70d989efd..f30aeaa5b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -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") diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index 7c5cd3119..8b6af45d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -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); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java index 29f2b3a1a..28918fda3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java @@ -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); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index 58663ab3c..5fbda8908 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -167,7 +167,7 @@ public class ExtentEntityCopy implements EntityFunction { } } - return new BaseEntity(state.getTypeId(), builder.build()); + return new BaseEntity(state.getType(), builder.build()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index e3c676914..c5c1b10a1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -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 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(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java index 9ac26a808..d3b151f6e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java @@ -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 implements Iterable { +import javax.annotation.Nullable; + +public final class NamespacedRegistry extends Registry { private static final String MINECRAFT_NAMESPACE = "minecraft"; - private final Map 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 keySet() { - return Collections.unmodifiableSet(this.map.keySet()); - } - - public Collection 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 iterator() { - return this.map.values().iterator(); - } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java new file mode 100644 index 000000000..7545068de --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Registry.java @@ -0,0 +1,69 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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 implements Iterable { + private final Map 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 keySet() { + return Collections.unmodifiableSet(this.map.keySet()); + } + + public Collection values() { + return Collections.unmodifiableCollection(this.map.values()); + } + + @Override + public Iterator iterator() { + return this.map.values().iterator(); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java index 887f45a3f..d59dc5eb0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java @@ -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; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java index e108aa94c..4f7098f0e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java @@ -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(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index 5e03cfcd8..cf5ad39f7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -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); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java new file mode 100644 index 000000000..1f7cb5925 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.world.entity; + +import com.sk89q.worldedit.registry.NamespacedRegistry; + +public class EntityType { + + public static final NamespacedRegistry 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); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java new file mode 100644 index 000000000..9c8d44210 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java @@ -0,0 +1,137 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java new file mode 100644 index 000000000..bb0d0d6cf --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java @@ -0,0 +1,57 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.world.gamemode; + +import com.sk89q.worldedit.registry.Registry; + +public class GameMode { + + public static final Registry 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); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameModes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameModes.java new file mode 100644 index 000000000..ab5b9fc69 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameModes.java @@ -0,0 +1,47 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java new file mode 100644 index 000000000..dac65115f --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java @@ -0,0 +1,57 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.world.weather; + +import com.sk89q.worldedit.registry.Registry; + +public class WeatherType { + + public static final Registry 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); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java new file mode 100644 index 000000000..1aa1c9f12 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherTypes.java @@ -0,0 +1,44 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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); + } +} diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java index efc32d43e..5d93dc942 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java @@ -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(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 getFacet(Class 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; } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityType.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityProperties.java similarity index 95% rename from worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityType.java rename to worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityProperties.java index 59d7c2eb3..d5e543ca9 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityType.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntityProperties.java @@ -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; } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index 7a3400b82..86f458425 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -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) { diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntity.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntity.java index 160c51c71..1ec0f3a85 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntity.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntity.java @@ -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 getFacet(Class 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; } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityType.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityProperties.java similarity index 95% rename from worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityType.java rename to worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityProperties.java index 834994bc7..2c2fb8852 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityType.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeEntityProperties.java @@ -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; } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java index 0bfaa3b6f..cc79d3e5e 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java @@ -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()); diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java index 0129d9d0e..c8bfc6366 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java @@ -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. */