Non-living vehicles may be specified as ride Condition, fixes #1640

This commit is contained in:
PikaMug 2021-03-12 21:31:23 -05:00
parent 55fb85bd30
commit c59599d77c
2 changed files with 20 additions and 10 deletions

View File

@ -12,6 +12,8 @@
package me.blackvein.quests.convo.conditions.tasks; package me.blackvein.quests.convo.conditions.tasks;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -173,17 +175,25 @@ public class EntityPrompt extends QuestsEditorNumericPrompt {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event); context.getPlugin().getServer().getPluginManager().callEvent(event);
String entities = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"; String mobs = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n";
final EntityType[] mobArr = EntityType.values(); final List<EntityType> mobArr = new LinkedList<>(Arrays.asList(EntityType.values()));
for (int i = 0; i < mobArr.length; i++) { final List<EntityType> toRemove = new LinkedList<EntityType>();
final EntityType type = mobArr[i]; for (int i = 0; i < mobArr.size(); i++) {
final EntityType type = mobArr.get(i);
if (type.getEntityClass() == null || !Vehicle.class.isAssignableFrom(type.getEntityClass())) { if (type.getEntityClass() == null || !Vehicle.class.isAssignableFrom(type.getEntityClass())) {
continue; toRemove.add(type);
} }
entities += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + ", ";
} }
entities = entities.substring(0, entities.length() - 2) + "\n"; mobArr.removeAll(toRemove);
return entities + ChatColor.YELLOW + getQueryText(context); mobArr.sort(Comparator.comparing(EntityType::name));
for (int i = 0; i < mobArr.size(); i++) {
mobs += ChatColor.AQUA + MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name());
if (i < (mobArr.size() - 1)) {
mobs += ChatColor.GRAY + ", ";
}
}
mobs += "\n" + ChatColor.YELLOW + getQueryText(context);
return mobs;
} }
@Override @Override

View File

@ -152,7 +152,7 @@ public class MiscUtil {
} }
/** /**
* Gets living EntityType from name * Gets EntityType from name
* *
* @param properName Name to get type from * @param properName Name to get type from
* @return EntityType or null if invalid * @return EntityType or null if invalid
@ -160,7 +160,7 @@ public class MiscUtil {
public static EntityType getProperMobType(String properName) { public static EntityType getProperMobType(String properName) {
properName = properName.replace("_", "").replace(" ", "").toUpperCase(); properName = properName.replace("_", "").replace(" ", "").toUpperCase();
for (final EntityType et : EntityType.values()) { for (final EntityType et : EntityType.values()) {
if (et.isAlive() && et.name().replace("_", "").equalsIgnoreCase(properName)) { if (et.name().replace("_", "").equalsIgnoreCase(properName)) {
return et; return et;
} }
} }