mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-29 14:16:09 +01:00
New stay within region condition, fixes #1083
This commit is contained in:
parent
d8fc1e14ea
commit
b7183db984
@ -958,11 +958,36 @@ public class Quest {
|
||||
/**
|
||||
* Checks if quester is in WorldGuard region start
|
||||
*
|
||||
* @deprecated Use {@link #isInRegion(Quester)}
|
||||
* @param quester The quester to check
|
||||
* @return true if quester is in region
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isInRegion(final Quester quester) {
|
||||
return isInRegion(quester.getPlayer());
|
||||
return isInRegionStart(quester);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player is in WorldGuard region start
|
||||
*
|
||||
* @deprecated Use {@link #isInRegionStart(Player)}
|
||||
* @param player The player to check
|
||||
* @return true if player is in region
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
private boolean isInRegion(final Player player) {
|
||||
return isInRegionStart(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if quester is in WorldGuard region start
|
||||
*
|
||||
* @param quester The quester to check
|
||||
* @return true if quester is in region
|
||||
*/
|
||||
public boolean isInRegionStart(final Quester quester) {
|
||||
return isInRegionStart(quester.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -971,7 +996,7 @@ public class Quest {
|
||||
* @param player The player to check
|
||||
* @return true if player is in region
|
||||
*/
|
||||
private boolean isInRegion(final Player player) {
|
||||
private boolean isInRegionStart(final Player player) {
|
||||
if (regionStart == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -627,6 +627,12 @@ public class Quester {
|
||||
msg += ChatColor.AQUA + "\n \u2515 " + MiscUtil.snakeCaseToUpperCamelCase(b);
|
||||
}
|
||||
p.sendMessage(ChatColor.YELLOW + msg);
|
||||
} else if (!c.getRegionsWhileStayingWithin().isEmpty()) {
|
||||
String msg = "- " + Lang.get("conditionEditorStayWithinRegion");
|
||||
for (final String r : c.getRegionsWhileStayingWithin()) {
|
||||
msg += ChatColor.AQUA + "\n \u2515 " + r;
|
||||
}
|
||||
p.sendMessage(ChatColor.YELLOW + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4126,7 +4132,7 @@ public class Quester {
|
||||
}
|
||||
return false;
|
||||
} else if (quest.getRegionStart() != null) {
|
||||
if (!quest.isInRegion(this)) {
|
||||
if (!quest.isInRegionStart(this)) {
|
||||
if (giveReason) {
|
||||
String msg = Lang.get(getPlayer(), "questInvalidLocation");
|
||||
msg = msg.replace("<quest>", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW);
|
||||
@ -4170,4 +4176,15 @@ public class Quester {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInRegion(final String regionID) {
|
||||
if (getPlayer() == null) {
|
||||
return false;
|
||||
}
|
||||
if (plugin.getDependencies().getWorldGuardApi()
|
||||
.getApplicableRegionsIDs(getPlayer().getWorld(), getPlayer().getLocation()).contains(regionID)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -3439,6 +3439,29 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
throw new ConditionFormatException("stay-within-biome is not a list of biomes", conditionKey);
|
||||
}
|
||||
}
|
||||
if (data.contains(conditionKey + "stay-within-region")) {
|
||||
if (ConfigUtil.checkList(data.getList(conditionKey + "stay-within-region"), String.class)) {
|
||||
final LinkedList<String> regions = new LinkedList<String>();
|
||||
for (final String s : data.getStringList(conditionKey + "stay-within-region")) {
|
||||
boolean exists = false;
|
||||
for (final World world : getServer().getWorlds()) {
|
||||
if (getDependencies().getWorldGuardApi().getRegionManager(world) != null) {
|
||||
if (getDependencies().getWorldGuardApi().getRegionManager(world).hasRegion(s)) {
|
||||
regions.add(s);
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
throw new ConditionFormatException("region has invalid WorldGuard region name", conditionKey);
|
||||
}
|
||||
}
|
||||
condition.setRegionsWhileStayingWithin(regions);
|
||||
} else {
|
||||
throw new ConditionFormatException("stay-within-region is not a list of regions", conditionKey);
|
||||
}
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ public class Condition {
|
||||
private LinkedList<ItemStack> itemsWhileHoldingMainHand = new LinkedList<ItemStack>();
|
||||
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<String>();
|
||||
private LinkedList<String> biomesWhileStayingWithin = new LinkedList<String>();
|
||||
private LinkedList<String> regionsWhileStayingWithin = new LinkedList<String>();
|
||||
|
||||
public Condition(final Quests plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -94,6 +95,14 @@ public class Condition {
|
||||
this.biomesWhileStayingWithin = biomesWhileStayingWithin;
|
||||
}
|
||||
|
||||
public LinkedList<String> getRegionsWhileStayingWithin() {
|
||||
return regionsWhileStayingWithin;
|
||||
}
|
||||
|
||||
public void setRegionsWhileStayingWithin(final LinkedList<String> biomesWhileStayingWithin) {
|
||||
this.regionsWhileStayingWithin = biomesWhileStayingWithin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean check(final Quester quester, final Quest quest) {
|
||||
final Player player = quester.getPlayer();
|
||||
@ -144,6 +153,14 @@ public class Condition {
|
||||
+ MiscUtil.getProperBiome(b));
|
||||
}
|
||||
}
|
||||
} else if (!regionsWhileStayingWithin.isEmpty()) {
|
||||
for (final String r : regionsWhileStayingWithin) {
|
||||
if (quester.isInRegion(r)) {
|
||||
return true;
|
||||
} else if (plugin.getSettings().getConsoleLogging() > 2) {
|
||||
plugin.getLogger().info("DEBUG: Condition region mismatch for " + player.getName() + ": " + r);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -109,6 +109,12 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
||||
biomes.addAll(condition.getBiomesWhileStayingWithin());
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_BIOME, biomes);
|
||||
}
|
||||
if (condition.getRegionsWhileStayingWithin() != null
|
||||
&& condition.getRegionsWhileStayingWithin().isEmpty() == false) {
|
||||
final LinkedList<String> regions = new LinkedList<String>();
|
||||
regions.addAll(condition.getRegionsWhileStayingWithin());
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_REGION, regions);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearData(final ConversationContext context) {
|
||||
@ -120,6 +126,7 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
||||
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);
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_REGION, null);
|
||||
}
|
||||
|
||||
public void deleteCondition(final ConversationContext context) {
|
||||
@ -220,6 +227,10 @@ public class ConditionFactory implements ConversationAbandonedListener {
|
||||
section.set("stay-within-biome",
|
||||
context.getSessionData(CK.C_WHILE_WITHIN_BIOME));
|
||||
}
|
||||
if (context.getSessionData(CK.C_WHILE_WITHIN_REGION) != null) {
|
||||
section.set("stay-within-region",
|
||||
context.getSessionData(CK.C_WHILE_WITHIN_REGION));
|
||||
}
|
||||
try {
|
||||
data.save(conditionsFile);
|
||||
} catch (final IOException e) {
|
||||
|
@ -24,22 +24,29 @@ import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
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;
|
||||
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
|
||||
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent;
|
||||
import me.blackvein.quests.reflect.worldguard.WorldGuardAPI;
|
||||
import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
|
||||
public class WorldPrompt extends QuestsEditorNumericPrompt {
|
||||
|
||||
private final Quests plugin;
|
||||
|
||||
public WorldPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
this.plugin = (Quests)context.getPlugin();
|
||||
}
|
||||
|
||||
private final int size = 3;
|
||||
private final int size = 4;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
@ -56,8 +63,9 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
|
||||
switch (number) {
|
||||
case 1:
|
||||
case 2:
|
||||
return ChatColor.BLUE;
|
||||
case 3:
|
||||
return ChatColor.BLUE;
|
||||
case 4:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
@ -72,6 +80,12 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
|
||||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorStayWithinBiome");
|
||||
case 3:
|
||||
if (plugin.getDependencies().getWorldGuardApi() != null) {
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorStayWithinRegion");
|
||||
} else {
|
||||
return ChatColor.GRAY + Lang.get("conditionEditorStayWithinRegion");
|
||||
}
|
||||
case 4:
|
||||
return ChatColor.GREEN + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
@ -103,6 +117,20 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
|
||||
return text;
|
||||
}
|
||||
case 3:
|
||||
if (plugin.getDependencies().getWorldGuardApi() != null) {
|
||||
if (context.getSessionData(CK.C_WHILE_WITHIN_REGION) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
for (final String s: (List<String>) context.getSessionData(CK.C_WHILE_WITHIN_REGION)) {
|
||||
text += ChatColor.GRAY + " - " + ChatColor.BLUE + s + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
} else {
|
||||
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
|
||||
}
|
||||
case 4:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
@ -130,6 +158,8 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
|
||||
case 2:
|
||||
return new BiomesPrompt(context);
|
||||
case 3:
|
||||
return new RegionsPrompt(context);
|
||||
case 4:
|
||||
try {
|
||||
return new ConditionMainPrompt(context);
|
||||
} catch (final Exception e) {
|
||||
@ -245,4 +275,79 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
|
||||
return new WorldPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
public class RegionsPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public RegionsPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("conditionEditorRegionsTitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("conditionEditorRegionsPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
String regions = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n";
|
||||
boolean any = false;
|
||||
for (final World world : plugin.getServer().getWorlds()) {
|
||||
final WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi();
|
||||
final RegionManager rm = api.getRegionManager(world);
|
||||
for (final String region : rm.getRegions().keySet()) {
|
||||
any = true;
|
||||
regions += ChatColor.GREEN + region + ", ";
|
||||
}
|
||||
}
|
||||
if (any) {
|
||||
regions = regions.substring(0, regions.length() - 2);
|
||||
regions += "\n\n";
|
||||
} else {
|
||||
regions += ChatColor.GRAY + "(" + Lang.get("none") + ")\n\n";
|
||||
}
|
||||
return regions + ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
final Player player = (Player) context.getForWhom();
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
final LinkedList<String> regions = new LinkedList<String>();
|
||||
for (final String r : input.split(" ")) {
|
||||
boolean found = false;
|
||||
for (final World world : plugin.getServer().getWorlds()) {
|
||||
final WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi();
|
||||
final RegionManager rm = api.getRegionManager(world);
|
||||
for (final String region : rm.getRegions().keySet()) {
|
||||
if (region.equalsIgnoreCase(r)) {
|
||||
regions.add(region);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found = false) {
|
||||
String error = Lang.get("questWGInvalidRegion");
|
||||
error = error.replace("<region>", ChatColor.RED + r + ChatColor.YELLOW);
|
||||
player.sendMessage(ChatColor.YELLOW + error);
|
||||
return new RegionsPrompt(context);
|
||||
}
|
||||
}
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_REGION, regions);
|
||||
}
|
||||
return new WorldPrompt(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,9 +124,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
|
||||
case 3:
|
||||
return ChatColor.YELLOW + Lang.get("questEditorFinishMessage");
|
||||
case 4:
|
||||
if (context.getSessionData(CK.Q_START_NPC) == null && plugin.getDependencies().getCitizens() != null) {
|
||||
return ChatColor.YELLOW + Lang.get("questEditorNPCStart");
|
||||
} else if (plugin.getDependencies().getCitizens() != null) {
|
||||
if (context.getSessionData(CK.Q_START_NPC) == null || plugin.getDependencies().getCitizens() != null) {
|
||||
return ChatColor.YELLOW + Lang.get("questEditorNPCStart");
|
||||
} else {
|
||||
return ChatColor.GRAY + Lang.get("questEditorNPCStart");
|
||||
@ -135,11 +133,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
|
||||
return ChatColor.YELLOW + Lang.get("questEditorBlockStart");
|
||||
case 6:
|
||||
if (plugin.getDependencies().getWorldGuardApi() != null) {
|
||||
if (context.getSessionData(CK.Q_REGION) == null) {
|
||||
return ChatColor.YELLOW + Lang.get("questWGSetRegion");
|
||||
} else {
|
||||
return ChatColor.YELLOW + Lang.get("questWGSetRegion");
|
||||
}
|
||||
} else {
|
||||
return ChatColor.GRAY + Lang.get("questWGSetRegion");
|
||||
}
|
||||
@ -147,11 +141,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
|
||||
return ChatColor.YELLOW + Lang.get("questEditorInitialEvent");
|
||||
case 8:
|
||||
if (plugin.getDependencies().getCitizens() != null) {
|
||||
if (context.getSessionData(CK.Q_GUIDISPLAY) == null) {
|
||||
return ChatColor.YELLOW + Lang.get("questEditorSetGUI");
|
||||
} else {
|
||||
return ChatColor.YELLOW + Lang.get("questEditorSetGUI");
|
||||
}
|
||||
} else {
|
||||
return ChatColor.GRAY + Lang.get("questEditorSetGUI");
|
||||
}
|
||||
|
@ -186,4 +186,5 @@ public class CK {
|
||||
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";
|
||||
public static final String C_WHILE_WITHIN_REGION = "conWithinRegion";
|
||||
}
|
||||
|
@ -423,6 +423,10 @@ conditionEditorBiomesTitle: "- Biomes -"
|
||||
conditionEditorBiomesPrompt: "Enter biome names, <space>, <cancel>"
|
||||
conditionEditorStayWithinBiome: "Stay within biome"
|
||||
conditionEditorInvalidBiome: "is not a valid biome name!"
|
||||
conditionEditorRegionsTitle: "- Regions -"
|
||||
conditionEditorRegionsPrompt: "Enter region names, <space>, <cancel>"
|
||||
conditionEditorStayWithinRegion: "Stay within region"
|
||||
conditionEditorInvalidRegion: "is not a valid region name!"
|
||||
reqSetMoney: "Set money requirement"
|
||||
reqSetQuestPoints: "Set <points> requirement"
|
||||
reqSetItem: "Set item requirements"
|
||||
|
Loading…
Reference in New Issue
Block a user