mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-08 08:31:19 +01:00
New own a permission condition, fixes #1245
This commit is contained in:
parent
05d4990ed0
commit
536b24376a
@ -604,6 +604,12 @@ public class Quester {
|
||||
msg += ChatColor.AQUA + "\n \u2515 " + e;
|
||||
}
|
||||
p.sendMessage(ChatColor.YELLOW + msg);
|
||||
} else if (!c.getPermissions().isEmpty()) {
|
||||
String msg = "- " + Lang.get("conditionEditorPermissions");
|
||||
for (final String e : c.getPermissions()) {
|
||||
msg += ChatColor.AQUA + "\n \u2515 " + e;
|
||||
}
|
||||
p.sendMessage(ChatColor.YELLOW + msg);
|
||||
} else if (!c.getItemsWhileHoldingMainHand().isEmpty()) {
|
||||
String msg = "- " + Lang.get("conditionEditorItemsInMainHand");
|
||||
for (final ItemStack is : c.getItemsWhileHoldingMainHand()) {
|
||||
|
@ -3381,6 +3381,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
throw new ConditionFormatException("ride-entity is not a list of entity types", conditionKey);
|
||||
}
|
||||
}
|
||||
if (data.contains(conditionKey + "permission")) {
|
||||
if (ConfigUtil.checkList(data.getList(conditionKey + "permission"), String.class)) {
|
||||
final LinkedList<String> permissions = new LinkedList<String>();
|
||||
permissions.addAll(data.getStringList(conditionKey + "permission"));
|
||||
condition.setPermissions(permissions);
|
||||
} else {
|
||||
throw new ConditionFormatException("permission is not a list of permissions", conditionKey);
|
||||
}
|
||||
}
|
||||
if (data.contains(conditionKey + "hold-main-hand")) {
|
||||
final LinkedList<ItemStack> temp = new LinkedList<ItemStack>();
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -25,11 +25,11 @@ import me.blackvein.quests.util.MiscUtil;
|
||||
|
||||
public class Condition {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Quests plugin;
|
||||
private String name = "";
|
||||
private boolean failQuest = false;
|
||||
private LinkedList<String> entitiesWhileRiding = new LinkedList<String>();
|
||||
private LinkedList<String> permissions = new LinkedList<String>();
|
||||
private LinkedList<ItemStack> itemsWhileHoldingMainHand = new LinkedList<ItemStack>();
|
||||
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<String>();
|
||||
private LinkedList<String> biomesWhileStayingWithin = new LinkedList<String>();
|
||||
@ -61,6 +61,14 @@ public class Condition {
|
||||
public void setEntitiesWhileRiding(final LinkedList<String> entitiesWhileRiding) {
|
||||
this.entitiesWhileRiding = entitiesWhileRiding;
|
||||
}
|
||||
|
||||
public LinkedList<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(final LinkedList<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public LinkedList<ItemStack> getItemsWhileHoldingMainHand() {
|
||||
return itemsWhileHoldingMainHand;
|
||||
@ -94,7 +102,19 @@ public class Condition {
|
||||
if (player.isInsideVehicle() && player.getVehicle().getType().equals(MiscUtil.getProperMobType(e))) {
|
||||
return true;
|
||||
} else if (plugin.getSettings().getConsoleLogging() > 2) {
|
||||
plugin.getLogger().info("DEBUG: Condition entity does not match for= " + e);
|
||||
plugin.getLogger().info("DEBUG: Condition entity mismatch for " + player.getName() + ": " + e);
|
||||
}
|
||||
}
|
||||
} else if (!permissions.isEmpty()) {
|
||||
for (final String p : permissions) {
|
||||
if (plugin.getDependencies().isPluginAvailable("Vault")) {
|
||||
if (plugin.getDependencies().getVaultPermission().has(player, p)) {
|
||||
return plugin.getDependencies().getVaultPermission().has(player, p);
|
||||
} else if (plugin.getSettings().getConsoleLogging() > 2) {
|
||||
plugin.getLogger().info("DEBUG: Condition permission mismatch for " + player.getName() + ": " + p);
|
||||
}
|
||||
} else {
|
||||
plugin.getLogger().warning("Vault must be installed for condition permission checks: " + p);
|
||||
}
|
||||
}
|
||||
} else if (!itemsWhileHoldingMainHand.isEmpty()) {
|
||||
@ -102,7 +122,7 @@ public class Condition {
|
||||
if (ItemUtil.compareItems(player.getItemInHand(), is, true, true) == 0) {
|
||||
return true;
|
||||
} else if (plugin.getSettings().getConsoleLogging() > 2) {
|
||||
plugin.getLogger().info("DEBUG: Condition item does not match with code= "
|
||||
plugin.getLogger().info("DEBUG: Condition item mismatch for " + player.getName() + ": code "
|
||||
+ ItemUtil.compareItems(player.getItemInHand(), is, true, true));
|
||||
}
|
||||
}
|
||||
@ -111,7 +131,7 @@ public class Condition {
|
||||
if (player.getWorld().getName().equalsIgnoreCase(w)) {
|
||||
return true;
|
||||
} else if (plugin.getSettings().getConsoleLogging() > 2) {
|
||||
plugin.getLogger().info("DEBUG: Condition world does not match for= " + w);
|
||||
plugin.getLogger().info("DEBUG: Condition world mismatch for " + player.getName() + ": " + w);
|
||||
}
|
||||
}
|
||||
} else if (!biomesWhileStayingWithin.isEmpty()) {
|
||||
@ -120,7 +140,8 @@ public class Condition {
|
||||
.name().equalsIgnoreCase(MiscUtil.getProperBiome(b).name())) {
|
||||
return true;
|
||||
} else if (plugin.getSettings().getConsoleLogging() > 2) {
|
||||
plugin.getLogger().info("DEBUG: Condition biome does not match for= " + MiscUtil.getProperBiome(b));
|
||||
plugin.getLogger().info("DEBUG: Condition biome mismatch for " + player.getName() + ": "
|
||||
+ MiscUtil.getProperBiome(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,12 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
||||
entities.addAll(condition.getEntitiesWhileRiding());
|
||||
context.setSessionData(CK.C_WHILE_RIDING_ENTITY, entities);
|
||||
}
|
||||
if (condition.getPermissions() != null
|
||||
&& condition.getPermissions().isEmpty() == false) {
|
||||
final LinkedList<String> permissions = new LinkedList<String>();
|
||||
permissions.addAll(condition.getPermissions());
|
||||
context.setSessionData(CK.C_WHILE_PERMISSION, permissions);
|
||||
}
|
||||
if (condition.getItemsWhileHoldingMainHand() != null
|
||||
&& condition.getItemsWhileHoldingMainHand().isEmpty() == false) {
|
||||
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
|
||||
@ -110,6 +116,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_PERMISSION, null);
|
||||
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, null);
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, null);
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_BIOME, null);
|
||||
@ -197,6 +204,10 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
||||
section.set("ride-entity",
|
||||
context.getSessionData(CK.C_WHILE_RIDING_ENTITY));
|
||||
}
|
||||
if (context.getSessionData(CK.C_WHILE_PERMISSION) != null) {
|
||||
section.set("permission",
|
||||
context.getSessionData(CK.C_WHILE_PERMISSION));
|
||||
}
|
||||
if (context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND) != null) {
|
||||
section.set("hold-main-hand",
|
||||
context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND));
|
||||
|
@ -23,7 +23,9 @@ import org.bukkit.inventory.ItemStack;
|
||||
import me.blackvein.quests.convo.conditions.main.ConditionMainPrompt;
|
||||
import me.blackvein.quests.convo.generic.ItemStackPrompt;
|
||||
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
|
||||
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
|
||||
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
|
||||
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent;
|
||||
import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
@ -34,7 +36,7 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private final int size = 2;
|
||||
private final int size = 3;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
@ -50,8 +52,9 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
||||
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
return ChatColor.BLUE;
|
||||
case 2:
|
||||
return ChatColor.BLUE;
|
||||
case 3:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
@ -62,8 +65,10 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
||||
public String getSelectionText(final ConversationContext context, final int number) {
|
||||
switch(number) {
|
||||
case 1:
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorItemsInMainHand");
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorPermissions");
|
||||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorItemsInMainHand");
|
||||
case 3:
|
||||
return ChatColor.GREEN + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
@ -75,18 +80,30 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
||||
public String getAdditionalText(final ConversationContext context, final int number) {
|
||||
switch(number) {
|
||||
case 1:
|
||||
if (context.getSessionData(CK.C_WHILE_PERMISSION) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
for (final String s: (List<String>) context.getSessionData(CK.C_WHILE_PERMISSION)) {
|
||||
// We replace the standard period character to prevent clickable links
|
||||
text += ChatColor.GRAY + " - " + ChatColor.BLUE + s.replace(".", "\uFF0E") + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
case 2:
|
||||
if (context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND);
|
||||
final LinkedList<ItemStack> items
|
||||
= (LinkedList<ItemStack>) context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND);
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i))
|
||||
+ ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
@ -122,8 +139,10 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
||||
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
|
||||
switch(input.intValue()) {
|
||||
case 1:
|
||||
return new ItemsInMainHandListPrompt(context);
|
||||
return new PermissionsPrompt(context);
|
||||
case 2:
|
||||
return new ItemsInMainHandListPrompt(context);
|
||||
case 3:
|
||||
try {
|
||||
return new ConditionMainPrompt(context);
|
||||
} catch (final Exception e) {
|
||||
@ -135,6 +154,44 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
}
|
||||
|
||||
public class PermissionsPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public PermissionsPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("conditionEditorPermissionsPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event
|
||||
= new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
final LinkedList<String> permissions = new LinkedList<String>();
|
||||
for (final String s : input.split(" ")) {
|
||||
permissions.add(s.trim());
|
||||
}
|
||||
context.setSessionData(CK.C_WHILE_PERMISSION, permissions);
|
||||
}
|
||||
return new PlayerPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemsInMainHandListPrompt extends QuestsEditorNumericPrompt {
|
||||
|
||||
public ItemsInMainHandListPrompt(final ConversationContext context) {
|
||||
|
@ -166,9 +166,9 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
|
||||
final List<World> worldArr = Bukkit.getWorlds();
|
||||
for (int i = 0; i < worldArr.size(); i++) {
|
||||
if (i < (worldArr.size() - 1)) {
|
||||
worlds += MiscUtil.snakeCaseToUpperCamelCase(worldArr.get(i).getName()) + ", ";
|
||||
worlds += worldArr.get(i).getName() + ", ";
|
||||
} else {
|
||||
worlds += MiscUtil.snakeCaseToUpperCamelCase(worldArr.get(i).getName()) + "\n";
|
||||
worlds += worldArr.get(i).getName() + "\n";
|
||||
}
|
||||
}
|
||||
return worlds + ChatColor.YELLOW + getQueryText(context);
|
||||
|
@ -181,6 +181,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_PERMISSION = "conPermission";
|
||||
public static final String C_WHILE_HOLDING_MAIN_HAND = "conHoldingMainHand";
|
||||
public static final String C_WHILE_WITHIN_WORLD = "conWithinWorld";
|
||||
public static final String C_WHILE_WITHIN_BIOME = "conWithinBiome";
|
||||
|
@ -410,9 +410,11 @@ conditionEditorConditionCleared: "Condition cleared."
|
||||
conditionEditorRideEntity: "Ride entity"
|
||||
conditionEditorEntitiesTitle: "- Entities -"
|
||||
conditionEditorEntitiesPrompt: "Enter entity names, <space>, <cancel>"
|
||||
conditionEditorPermissions: "Own permission"
|
||||
conditionEditorPermissionsPrompt: "Enter permission nodes, <space>, <cancel>"
|
||||
conditionEditorItemsInMainHand: "Hold in main hand"
|
||||
conditionEditorStayWithinWorld: "Stay within world"
|
||||
conditionEditorInvalidWorld: "is not a valid world name!"
|
||||
conditionEditorItemsInMainHand: "Hold in main hand"
|
||||
conditionEditorWorldsTitle: "- Worlds -"
|
||||
conditionEditorWorldsPrompt: "Enter world names, <space>, <cancel>"
|
||||
conditionEditorStayWithinWorld: "Stay within world"
|
||||
|
Loading…
Reference in New Issue
Block a user