mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
The "spawner|mobType" syntax once again makes functional mob spawners.
Also fix block parser context not being restricted.
This commit is contained in:
parent
3173e26109
commit
334d5cfaab
@ -86,7 +86,10 @@ public class BukkitServerInterface implements MultiUserPlatform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidMobType(String type) {
|
public boolean isValidMobType(String type) {
|
||||||
final EntityType entityType = EntityType.fromName(type);
|
if (!type.startsWith("minecraft:")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final EntityType entityType = EntityType.fromName(type.substring(10));
|
||||||
return entityType != null && entityType.isAlive();
|
return entityType != null && entityType.isAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,10 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.blocks;
|
package com.sk89q.worldedit.blocks;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import com.sk89q.jnbt.IntTag;
|
||||||
import com.sk89q.jnbt.ListTag;
|
import com.sk89q.jnbt.ListTag;
|
||||||
import com.sk89q.jnbt.NBTUtils;
|
import com.sk89q.jnbt.NBTUtils;
|
||||||
import com.sk89q.jnbt.ShortTag;
|
import com.sk89q.jnbt.ShortTag;
|
||||||
@ -38,17 +41,17 @@ import java.util.Map;
|
|||||||
public class MobSpawnerBlock extends BaseBlock {
|
public class MobSpawnerBlock extends BaseBlock {
|
||||||
|
|
||||||
private String mobType;
|
private String mobType;
|
||||||
private short delay;
|
private short delay = -1;
|
||||||
|
|
||||||
// advanced mob spawner features
|
// advanced mob spawner features
|
||||||
private short spawnCount;
|
private short spawnCount = 4;
|
||||||
private short spawnRange;
|
private short spawnRange = 4;
|
||||||
private CompoundTag spawnData;
|
private CompoundTag spawnData;
|
||||||
private ListTag spawnPotentials;
|
private ListTag spawnPotentials;
|
||||||
private short minSpawnDelay;
|
private short minSpawnDelay = 200;
|
||||||
private short maxSpawnDelay;
|
private short maxSpawnDelay = 800;
|
||||||
private short maxNearbyEntities;
|
private short maxNearbyEntities = 6;
|
||||||
private short requiredPlayerRange;
|
private short requiredPlayerRange = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the mob spawner block with a specified data value.
|
* Construct the mob spawner block with a specified data value.
|
||||||
@ -119,7 +122,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
|||||||
@Override
|
@Override
|
||||||
public CompoundTag getNbtData() {
|
public CompoundTag getNbtData() {
|
||||||
Map<String, Tag> values = new HashMap<>();
|
Map<String, Tag> values = new HashMap<>();
|
||||||
values.put("EntityId", new StringTag(mobType));
|
|
||||||
values.put("Delay", new ShortTag(delay));
|
values.put("Delay", new ShortTag(delay));
|
||||||
values.put("SpawnCount", new ShortTag(spawnCount));
|
values.put("SpawnCount", new ShortTag(spawnCount));
|
||||||
values.put("SpawnRange", new ShortTag(spawnRange));
|
values.put("SpawnRange", new ShortTag(spawnRange));
|
||||||
@ -127,10 +129,16 @@ public class MobSpawnerBlock extends BaseBlock {
|
|||||||
values.put("MaxSpawnDelay", new ShortTag(maxSpawnDelay));
|
values.put("MaxSpawnDelay", new ShortTag(maxSpawnDelay));
|
||||||
values.put("MaxNearbyEntities", new ShortTag(maxNearbyEntities));
|
values.put("MaxNearbyEntities", new ShortTag(maxNearbyEntities));
|
||||||
values.put("RequiredPlayerRange", new ShortTag(requiredPlayerRange));
|
values.put("RequiredPlayerRange", new ShortTag(requiredPlayerRange));
|
||||||
if (spawnData != null) {
|
if (spawnData == null) {
|
||||||
|
values.put("SpawnData", new CompoundTag(ImmutableMap.of("id", new StringTag(mobType))));
|
||||||
|
} else {
|
||||||
values.put("SpawnData", new CompoundTag(spawnData.getValue()));
|
values.put("SpawnData", new CompoundTag(spawnData.getValue()));
|
||||||
}
|
}
|
||||||
if (spawnPotentials != null) {
|
if (spawnPotentials == null) {
|
||||||
|
values.put("SpawnPotentials", new ListTag(CompoundTag.class, ImmutableList.of(
|
||||||
|
new CompoundTag(ImmutableMap.of("Weight", new IntTag(1), "Entity",
|
||||||
|
new CompoundTag(ImmutableMap.of("id", new StringTag(mobType))))))));
|
||||||
|
} else {
|
||||||
values.put("SpawnPotentials", new ListTag(CompoundTag.class, spawnPotentials.getValue()));
|
values.put("SpawnPotentials", new ListTag(CompoundTag.class, spawnPotentials.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,18 +158,26 @@ public class MobSpawnerBlock extends BaseBlock {
|
|||||||
throw new RuntimeException("'MobSpawner' tile entity expected");
|
throw new RuntimeException("'MobSpawner' tile entity expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTag mobTypeTag;
|
CompoundTag spawnDataTag;
|
||||||
|
String mobType;
|
||||||
ShortTag delayTag;
|
ShortTag delayTag;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mobTypeTag = NBTUtils.getChildTag(values, "EntityId", StringTag.class);
|
spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
|
||||||
delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class);
|
mobType = spawnDataTag.getString("id");
|
||||||
|
if (mobType.equals("")) {
|
||||||
|
throw new InvalidFormatException("No spawn id.");
|
||||||
|
}
|
||||||
|
this.mobType = mobType;
|
||||||
} catch (InvalidFormatException ignored) {
|
} catch (InvalidFormatException ignored) {
|
||||||
throw new RuntimeException("Invalid mob spawner data: no EntityId and/or no Delay");
|
throw new RuntimeException("Invalid mob spawner data: no SpawnData and/or no Delay");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class);
|
||||||
|
this.delay = delayTag.getValue();
|
||||||
|
} catch (InvalidFormatException ignored) {
|
||||||
|
this.delay = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mobType = mobTypeTag.getValue();
|
|
||||||
this.delay = delayTag.getValue();
|
|
||||||
|
|
||||||
ShortTag spawnCountTag = null;
|
ShortTag spawnCountTag = null;
|
||||||
ShortTag spawnRangeTag = null;
|
ShortTag spawnRangeTag = null;
|
||||||
@ -170,7 +186,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
|||||||
ShortTag maxNearbyEntitiesTag = null;
|
ShortTag maxNearbyEntitiesTag = null;
|
||||||
ShortTag requiredPlayerRangeTag = null;
|
ShortTag requiredPlayerRangeTag = null;
|
||||||
ListTag spawnPotentialsTag = null;
|
ListTag spawnPotentialsTag = null;
|
||||||
CompoundTag spawnDataTag = null;
|
|
||||||
try {
|
try {
|
||||||
spawnCountTag = NBTUtils.getChildTag(values, "SpawnCount", ShortTag.class);
|
spawnCountTag = NBTUtils.getChildTag(values, "SpawnCount", ShortTag.class);
|
||||||
} catch (InvalidFormatException ignored) {
|
} catch (InvalidFormatException ignored) {
|
||||||
@ -199,10 +214,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
|||||||
spawnPotentialsTag = NBTUtils.getChildTag(values, "SpawnPotentials", ListTag.class);
|
spawnPotentialsTag = NBTUtils.getChildTag(values, "SpawnPotentials", ListTag.class);
|
||||||
} catch (InvalidFormatException ignored) {
|
} catch (InvalidFormatException ignored) {
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
|
|
||||||
} catch (InvalidFormatException ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spawnCountTag != null) {
|
if (spawnCountTag != null) {
|
||||||
this.spawnCount = spawnCountTag.getValue();
|
this.spawnCount = spawnCountTag.getValue();
|
||||||
@ -225,9 +236,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
|||||||
if (spawnPotentialsTag != null) {
|
if (spawnPotentialsTag != null) {
|
||||||
this.spawnPotentials = new ListTag(CompoundTag.class, spawnPotentialsTag.getValue());
|
this.spawnPotentials = new ListTag(CompoundTag.class, spawnPotentialsTag.getValue());
|
||||||
}
|
}
|
||||||
if (spawnDataTag != null) {
|
|
||||||
this.spawnData = new CompoundTag(spawnDataTag.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ public class FactoryConverter<T> implements ArgumentConverter<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
parserContext.setSession(session);
|
parserContext.setSession(session);
|
||||||
|
parserContext.setRestricted(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return SuccessfulConversion.fromSingle(
|
return SuccessfulConversion.fromSingle(
|
||||||
|
@ -46,6 +46,8 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||||
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
|
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -323,12 +325,11 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
|||||||
// Allow setting mob spawn type
|
// Allow setting mob spawn type
|
||||||
if (blockAndExtraData.length > 1) {
|
if (blockAndExtraData.length > 1) {
|
||||||
String mobName = blockAndExtraData[1];
|
String mobName = blockAndExtraData[1];
|
||||||
for (MobType mobType : MobType.values()) {
|
EntityType ent = EntityTypes.get(mobName.toLowerCase(Locale.ROOT));
|
||||||
if (mobType.getName().toLowerCase(Locale.ROOT).equals(mobName.toLowerCase(Locale.ROOT))) {
|
if (ent == null) {
|
||||||
mobName = mobType.getName();
|
throw new NoMatchException("Unknown entity type '" + mobName + "'");
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
mobName = ent.getId();
|
||||||
if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) {
|
if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) {
|
||||||
throw new NoMatchException("Unknown mob type '" + mobName + "'");
|
throw new NoMatchException("Unknown mob type '" + mobName + "'");
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public interface Platform {
|
|||||||
* Checks if a mob type is valid.
|
* Checks if a mob type is valid.
|
||||||
*
|
*
|
||||||
* @param type The mob type name to check
|
* @param type The mob type name to check
|
||||||
* @return Whether the name is a valid mod bype
|
* @return Whether the name is a valid mod type
|
||||||
*/
|
*/
|
||||||
boolean isValidMobType(String type);
|
boolean isValidMobType(String type);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user