Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-07 12:00:07 +01:00
The "spawner|mobType" syntax once again makes functional mob spawners.
Also fix block parser context not being restricted.
Dieser Commit ist enthalten in:
Ursprung
3173e26109
Commit
334d5cfaab
@ -86,7 +86,10 @@ public class BukkitServerInterface implements MultiUserPlatform {
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,10 @@
|
||||
|
||||
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.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
@ -38,17 +41,17 @@ import java.util.Map;
|
||||
public class MobSpawnerBlock extends BaseBlock {
|
||||
|
||||
private String mobType;
|
||||
private short delay;
|
||||
private short delay = -1;
|
||||
|
||||
// advanced mob spawner features
|
||||
private short spawnCount;
|
||||
private short spawnRange;
|
||||
private short spawnCount = 4;
|
||||
private short spawnRange = 4;
|
||||
private CompoundTag spawnData;
|
||||
private ListTag spawnPotentials;
|
||||
private short minSpawnDelay;
|
||||
private short maxSpawnDelay;
|
||||
private short maxNearbyEntities;
|
||||
private short requiredPlayerRange;
|
||||
private short minSpawnDelay = 200;
|
||||
private short maxSpawnDelay = 800;
|
||||
private short maxNearbyEntities = 6;
|
||||
private short requiredPlayerRange = 16;
|
||||
|
||||
/**
|
||||
* Construct the mob spawner block with a specified data value.
|
||||
@ -119,7 +122,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
Map<String, Tag> values = new HashMap<>();
|
||||
values.put("EntityId", new StringTag(mobType));
|
||||
values.put("Delay", new ShortTag(delay));
|
||||
values.put("SpawnCount", new ShortTag(spawnCount));
|
||||
values.put("SpawnRange", new ShortTag(spawnRange));
|
||||
@ -127,10 +129,16 @@ public class MobSpawnerBlock extends BaseBlock {
|
||||
values.put("MaxSpawnDelay", new ShortTag(maxSpawnDelay));
|
||||
values.put("MaxNearbyEntities", new ShortTag(maxNearbyEntities));
|
||||
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()));
|
||||
}
|
||||
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()));
|
||||
}
|
||||
|
||||
@ -150,18 +158,26 @@ public class MobSpawnerBlock extends BaseBlock {
|
||||
throw new RuntimeException("'MobSpawner' tile entity expected");
|
||||
}
|
||||
|
||||
StringTag mobTypeTag;
|
||||
CompoundTag spawnDataTag;
|
||||
String mobType;
|
||||
ShortTag delayTag;
|
||||
|
||||
try {
|
||||
mobTypeTag = NBTUtils.getChildTag(values, "EntityId", StringTag.class);
|
||||
delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class);
|
||||
spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
|
||||
mobType = spawnDataTag.getString("id");
|
||||
if (mobType.equals("")) {
|
||||
throw new InvalidFormatException("No spawn id.");
|
||||
}
|
||||
this.mobType = mobType;
|
||||
} 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 spawnRangeTag = null;
|
||||
@ -170,7 +186,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
||||
ShortTag maxNearbyEntitiesTag = null;
|
||||
ShortTag requiredPlayerRangeTag = null;
|
||||
ListTag spawnPotentialsTag = null;
|
||||
CompoundTag spawnDataTag = null;
|
||||
try {
|
||||
spawnCountTag = NBTUtils.getChildTag(values, "SpawnCount", ShortTag.class);
|
||||
} catch (InvalidFormatException ignored) {
|
||||
@ -199,10 +214,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
||||
spawnPotentialsTag = NBTUtils.getChildTag(values, "SpawnPotentials", ListTag.class);
|
||||
} catch (InvalidFormatException ignored) {
|
||||
}
|
||||
try {
|
||||
spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
|
||||
} catch (InvalidFormatException ignored) {
|
||||
}
|
||||
|
||||
if (spawnCountTag != null) {
|
||||
this.spawnCount = spawnCountTag.getValue();
|
||||
@ -225,9 +236,6 @@ public class MobSpawnerBlock extends BaseBlock {
|
||||
if (spawnPotentialsTag != null) {
|
||||
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.setRestricted(true);
|
||||
|
||||
try {
|
||||
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.BlockTypes;
|
||||
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 java.util.HashMap;
|
||||
@ -323,12 +325,11 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
// Allow setting mob spawn type
|
||||
if (blockAndExtraData.length > 1) {
|
||||
String mobName = blockAndExtraData[1];
|
||||
for (MobType mobType : MobType.values()) {
|
||||
if (mobType.getName().toLowerCase(Locale.ROOT).equals(mobName.toLowerCase(Locale.ROOT))) {
|
||||
mobName = mobType.getName();
|
||||
break;
|
||||
}
|
||||
EntityType ent = EntityTypes.get(mobName.toLowerCase(Locale.ROOT));
|
||||
if (ent == null) {
|
||||
throw new NoMatchException("Unknown entity type '" + mobName + "'");
|
||||
}
|
||||
mobName = ent.getId();
|
||||
if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) {
|
||||
throw new NoMatchException("Unknown mob type '" + mobName + "'");
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public interface Platform {
|
||||
* Checks if a mob type is valid.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren