mirror of
https://github.com/PikaMug/Quests.git
synced 2024-06-26 06:35:01 +02:00
NEW while riding Citizens NPC condition
This commit is contained in:
parent
ae63ad1780
commit
6b7bcc207f
|
@ -72,6 +72,7 @@ import me.blackvein.quests.util.Lang;
|
|||
import me.blackvein.quests.util.MiscUtil;
|
||||
import me.blackvein.quests.util.RomanNumeral;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
public class Quester implements Comparable<Quester> {
|
||||
|
@ -612,6 +613,17 @@ public class Quester implements Comparable<Quester> {
|
|||
msg += ChatColor.AQUA + "\n \u2515 " + e;
|
||||
}
|
||||
sendMessage(ChatColor.YELLOW + msg);
|
||||
} else if (!c.getNpcsWhileRiding().isEmpty()) {
|
||||
String msg = "- " + Lang.get("conditionEditorRideNPC");
|
||||
for (final int i : c.getNpcsWhileRiding()) {
|
||||
if (plugin.getDependencies().getCitizens() != null) {
|
||||
msg += ChatColor.AQUA + "\n \u2515 " + CitizensAPI.getNPCRegistry().getById(i)
|
||||
.getName();
|
||||
} else {
|
||||
msg += ChatColor.AQUA + "\n \u2515 " + i;
|
||||
}
|
||||
}
|
||||
sendMessage(ChatColor.YELLOW + msg);
|
||||
} else if (!c.getPermissions().isEmpty()) {
|
||||
String msg = "- " + Lang.get("conditionEditorPermissions");
|
||||
for (final String e : c.getPermissions()) {
|
||||
|
|
|
@ -3640,6 +3640,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||
throw new ConditionFormatException("ride-entity is not a list of entity types", conditionKey);
|
||||
}
|
||||
}
|
||||
if (data.contains(conditionKey + "ride-npc")) {
|
||||
if (ConfigUtil.checkList(data.getList(conditionKey + "ride-npc"), Integer.class)) {
|
||||
final LinkedList<Integer> npcs = new LinkedList<Integer>();
|
||||
for (final int i : data.getIntegerList(conditionKey + "ride-npc")) {
|
||||
if (i < 0) {
|
||||
throw new ConditionFormatException("ride-npc is not a valid NPC ID",
|
||||
conditionKey);
|
||||
}
|
||||
npcs.add(i);
|
||||
}
|
||||
condition.setNpcsWhileRiding(npcs);
|
||||
} else {
|
||||
throw new ConditionFormatException("ride-npc is not a list of NPC IDs", conditionKey);
|
||||
}
|
||||
}
|
||||
if (data.contains(conditionKey + "permission")) {
|
||||
if (ConfigUtil.checkList(data.getList(conditionKey + "permission"), String.class)) {
|
||||
final LinkedList<String> permissions = new LinkedList<String>();
|
||||
|
|
|
@ -30,6 +30,7 @@ public class Condition {
|
|||
private String name = "";
|
||||
private boolean failQuest = false;
|
||||
private LinkedList<String> entitiesWhileRiding = new LinkedList<String>();
|
||||
private LinkedList<Integer> npcsWhileRiding = new LinkedList<Integer>();
|
||||
private LinkedList<String> permissions = new LinkedList<String>();
|
||||
private LinkedList<ItemStack> itemsWhileHoldingMainHand = new LinkedList<ItemStack>();
|
||||
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<String>();
|
||||
|
@ -66,6 +67,14 @@ public class Condition {
|
|||
this.entitiesWhileRiding = entitiesWhileRiding;
|
||||
}
|
||||
|
||||
public LinkedList<Integer> getNpcsWhileRiding() {
|
||||
return npcsWhileRiding;
|
||||
}
|
||||
|
||||
public void setNpcsWhileRiding(final LinkedList<Integer> npcsWhileRiding) {
|
||||
this.npcsWhileRiding = npcsWhileRiding;
|
||||
}
|
||||
|
||||
public LinkedList<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
@ -133,6 +142,17 @@ public class Condition {
|
|||
plugin.getLogger().info("DEBUG: Condition entity mismatch for " + player.getName() + ": " + e);
|
||||
}
|
||||
}
|
||||
} else if (!npcsWhileRiding.isEmpty()) {
|
||||
for (final int n : npcsWhileRiding) {
|
||||
if (plugin.getDependencies().getCitizens() != null) {
|
||||
if (player.isInsideVehicle() && player.getVehicle()
|
||||
.equals(plugin.getDependencies().getCitizens().getNPCRegistry().getById(n).getEntity())) {
|
||||
return true;
|
||||
} else if (plugin.getSettings().getConsoleLogging() > 2) {
|
||||
plugin.getLogger().info("DEBUG: Condition NPC mismatch for " + player.getName() + ": ID " + n);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!permissions.isEmpty()) {
|
||||
for (final String p : permissions) {
|
||||
if (plugin.getDependencies().isPluginAvailable("Vault")) {
|
||||
|
|
|
@ -92,6 +92,12 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
|||
entities.addAll(condition.getEntitiesWhileRiding());
|
||||
context.setSessionData(CK.C_WHILE_RIDING_ENTITY, entities);
|
||||
}
|
||||
if (condition.getNpcsWhileRiding() != null
|
||||
&& condition.getNpcsWhileRiding().isEmpty() == false) {
|
||||
final LinkedList<Integer> npcs = new LinkedList<Integer>();
|
||||
npcs.addAll(condition.getNpcsWhileRiding());
|
||||
context.setSessionData(CK.C_WHILE_RIDING_NPC, npcs);
|
||||
}
|
||||
if (condition.getPermissions() != null
|
||||
&& condition.getPermissions().isEmpty() == false) {
|
||||
final LinkedList<String> permissions = new LinkedList<String>();
|
||||
|
@ -141,6 +147,7 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
|||
context.setSessionData(CK.C_NAME, null);
|
||||
context.setSessionData(CK.C_FAIL_QUEST, null);
|
||||
context.setSessionData(CK.C_WHILE_RIDING_ENTITY, null);
|
||||
context.setSessionData(CK.C_WHILE_RIDING_NPC, null);
|
||||
context.setSessionData(CK.C_WHILE_PERMISSION, null);
|
||||
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, null);
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, null);
|
||||
|
@ -232,6 +239,10 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
|||
section.set("ride-entity",
|
||||
context.getSessionData(CK.C_WHILE_RIDING_ENTITY));
|
||||
}
|
||||
if (context.getSessionData(CK.C_WHILE_RIDING_NPC) != null) {
|
||||
section.set("ride-npc",
|
||||
context.getSessionData(CK.C_WHILE_RIDING_NPC));
|
||||
}
|
||||
if (context.getSessionData(CK.C_WHILE_PERMISSION) != null) {
|
||||
section.set("permission",
|
||||
context.getSessionData(CK.C_WHILE_PERMISSION));
|
||||
|
|
|
@ -14,13 +14,17 @@ package me.blackvein.quests.convo.conditions.tasks;
|
|||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.convo.conditions.main.ConditionMainPrompt;
|
||||
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
|
||||
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
|
||||
|
@ -29,14 +33,18 @@ import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPrompt
|
|||
import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
|
||||
public class EntityPrompt extends QuestsEditorNumericPrompt {
|
||||
|
||||
private final Quests plugin;
|
||||
|
||||
public EntityPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
this.plugin = (Quests)context.getPlugin();
|
||||
}
|
||||
|
||||
private final int size = 2;
|
||||
private final int size = 3;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
|
@ -54,6 +62,8 @@ public class EntityPrompt extends QuestsEditorNumericPrompt {
|
|||
case 1:
|
||||
return ChatColor.BLUE;
|
||||
case 2:
|
||||
return ChatColor.BLUE;
|
||||
case 3:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
|
@ -66,6 +76,8 @@ public class EntityPrompt extends QuestsEditorNumericPrompt {
|
|||
case 1:
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorRideEntity");
|
||||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorRideNPC");
|
||||
case 3:
|
||||
return ChatColor.GREEN + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
|
@ -87,6 +99,21 @@ public class EntityPrompt extends QuestsEditorNumericPrompt {
|
|||
return text;
|
||||
}
|
||||
case 2:
|
||||
if (plugin.getDependencies().getCitizens() != null) {
|
||||
if (context.getSessionData(CK.C_WHILE_RIDING_NPC) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
for (final int i : (List<Integer>) context.getSessionData(CK.C_WHILE_RIDING_NPC)) {
|
||||
text += ChatColor.GRAY + " - " + ChatColor.BLUE + CitizensAPI.getNPCRegistry().getById(i)
|
||||
.getName() + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
} else {
|
||||
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
|
||||
}
|
||||
case 3:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
|
@ -112,6 +139,8 @@ public class EntityPrompt extends QuestsEditorNumericPrompt {
|
|||
case 1:
|
||||
return new EntitiesPrompt(context);
|
||||
case 2:
|
||||
return new ConditionNpcsPrompt(context);
|
||||
case 3:
|
||||
try {
|
||||
return new ConditionMainPrompt(context);
|
||||
} catch (final Exception e) {
|
||||
|
@ -182,4 +211,70 @@ public class EntityPrompt extends QuestsEditorNumericPrompt {
|
|||
return new EntityPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConditionNpcsPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public ConditionNpcsPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("conditionEditorNpcsTitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("conditionEditorNpcsPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (context.getForWhom() instanceof Player) {
|
||||
final Set<UUID> selectingNpcs = plugin.getQuestFactory().getSelectingNpcs();
|
||||
selectingNpcs.add(((Player) context.getForWhom()).getUniqueId());
|
||||
plugin.getQuestFactory().setSelectingNpcs(selectingNpcs);
|
||||
return ChatColor.YELLOW + getQueryText(context) + "\n"
|
||||
+ ChatColor.GOLD + Lang.get("npcHint");
|
||||
} else {
|
||||
return ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
final LinkedList<Integer> npcIds = new LinkedList<Integer>();
|
||||
try {
|
||||
for (final String s : input.split(" ")) {
|
||||
final int i = Integer.parseInt(s);
|
||||
if (i > -1) {
|
||||
if (CitizensAPI.getNPCRegistry().getById(i) == null) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidNPC"));
|
||||
return new ConditionNpcsPrompt(context);
|
||||
}
|
||||
npcIds.add(i);
|
||||
context.setSessionData(CK.C_WHILE_RIDING_NPC, npcIds);
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidNPC"));
|
||||
return new ConditionNpcsPrompt(context);
|
||||
}
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED
|
||||
+ Lang.get("reqNotANumber").replace("<input>", input));
|
||||
return new ConditionNpcsPrompt(context);
|
||||
}
|
||||
}
|
||||
if (context.getForWhom() instanceof Player) {
|
||||
final Set<UUID> selectingNpcs = plugin.getQuestFactory().getSelectingNpcs();
|
||||
selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId());
|
||||
plugin.getQuestFactory().setSelectingNpcs(selectingNpcs);
|
||||
}
|
||||
return new EntityPrompt(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -459,6 +459,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
|
|||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (context.getForWhom() instanceof Player) {
|
||||
final Set<UUID> selectingNpcs = plugin.getQuestFactory().getSelectingNpcs();
|
||||
selectingNpcs.add(((Player) context.getForWhom()).getUniqueId());
|
||||
|
|
|
@ -183,6 +183,7 @@ public class CK {
|
|||
public static final String C_NAME = "conName";
|
||||
public static final String C_FAIL_QUEST = "conFailQuest";
|
||||
public static final String C_WHILE_RIDING_ENTITY = "conRidingEntity";
|
||||
public static final String C_WHILE_RIDING_NPC = "conRidingNpc";
|
||||
public static final String C_WHILE_PERMISSION = "conPermission";
|
||||
public static final String C_WHILE_HOLDING_MAIN_HAND = "conHoldingMainHand";
|
||||
public static final String C_WHILE_WITHIN_WORLD = "conWithinWorld";
|
||||
|
|
|
@ -404,8 +404,11 @@ conditionEditorCheckPlaceholder: "Check placeholder"
|
|||
conditionEditorFailQuest: "Fail the quest"
|
||||
conditionEditorConditionCleared: "Condition cleared."
|
||||
conditionEditorRideEntity: "Ride entity"
|
||||
conditionEditorRideNPC: "Ride NPC"
|
||||
conditionEditorEntitiesTitle: "- Entities -"
|
||||
conditionEditorEntitiesPrompt: "Enter entity names, <space>, <cancel>"
|
||||
conditionEditorNpcsTitle: "- Npcs -"
|
||||
conditionEditorNpcsPrompt: "Enter NPC IDs, <space>, <cancel>"
|
||||
conditionEditorPermissions: "Own permission"
|
||||
conditionEditorPermissionsPrompt: "Enter permission nodes, <space>, <cancel>"
|
||||
conditionEditorItemsInMainHand: "Hold in main hand"
|
||||
|
|
Loading…
Reference in New Issue
Block a user