mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-12-11 03:44:15 +01:00
Subsumable items in forbiddenItems req; resolves #926
This commit is contained in:
parent
ca1acf26c1
commit
c87b6a0253
@ -38,7 +38,7 @@ public class StatusCommand extends DCommand {
|
|||||||
public static final String TRUE = ChatColor.GREEN + "\u2714";
|
public static final String TRUE = ChatColor.GREEN + "\u2714";
|
||||||
public static final String FALSE = ChatColor.DARK_RED + "\u2718";
|
public static final String FALSE = ChatColor.DARK_RED + "\u2718";
|
||||||
|
|
||||||
public static final String LATEST_IXL = "0.6.4";
|
public static final String LATEST_IXL = "0.6.5";
|
||||||
|
|
||||||
public StatusCommand(DungeonsXL plugin) {
|
public StatusCommand(DungeonsXL plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
@ -118,7 +118,7 @@ public class StatusCommand extends DCommand {
|
|||||||
String custommobsVersionCorrect = getSymbol(custommobsVersion.startsWith("4."));
|
String custommobsVersionCorrect = getSymbol(custommobsVersion.startsWith("4."));
|
||||||
String insanemobsVersionCorrect = getSymbol(insanemobsVersion.startsWith("3."));
|
String insanemobsVersionCorrect = getSymbol(insanemobsVersion.startsWith("3."));
|
||||||
String mythicmobsVersionCorrect = getSymbol(mythicmobsVersion.startsWith("4."));
|
String mythicmobsVersionCorrect = getSymbol(mythicmobsVersion.startsWith("4."));
|
||||||
String holographicdisplaysVersionCorrect = getSymbol(holographicdisplaysVersion.startsWith("2.3"));
|
String holographicdisplaysVersionCorrect = getSymbol(holographicdisplaysVersion.startsWith("2.4"));
|
||||||
|
|
||||||
MessageUtil.sendMessage(sender, ChatColor.GRAY + "Dependency info:");
|
MessageUtil.sendMessage(sender, ChatColor.GRAY + "Dependency info:");
|
||||||
MessageUtil.sendMessage(sender, "= Vault: " + vaultVersion + " " + vaultVersionCorrect);
|
MessageUtil.sendMessage(sender, "= Vault: " + vaultVersion + " " + vaultVersionCorrect);
|
||||||
|
@ -21,8 +21,10 @@ import de.erethon.caliburn.item.ExItem;
|
|||||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||||
import de.erethon.dungeonsxl.api.Requirement;
|
import de.erethon.dungeonsxl.api.Requirement;
|
||||||
import de.erethon.dungeonsxl.config.DMessage;
|
import de.erethon.dungeonsxl.config.DMessage;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
@ -38,7 +40,7 @@ public class ForbiddenItemsRequirement implements Requirement {
|
|||||||
|
|
||||||
private CaliburnAPI caliburn;
|
private CaliburnAPI caliburn;
|
||||||
|
|
||||||
private List<ExItem> forbiddenItems;
|
private Map<ExItem, Boolean> forbiddenItems = new HashMap<>();
|
||||||
|
|
||||||
public ForbiddenItemsRequirement(DungeonsAPI api) {
|
public ForbiddenItemsRequirement(DungeonsAPI api) {
|
||||||
caliburn = api.getCaliburn();
|
caliburn = api.getCaliburn();
|
||||||
@ -46,16 +48,26 @@ public class ForbiddenItemsRequirement implements Requirement {
|
|||||||
|
|
||||||
/* Getters and setters */
|
/* Getters and setters */
|
||||||
/**
|
/**
|
||||||
* @return the forbidden items
|
* @return the forbidden items (key) and if the check is deep (value)
|
||||||
*/
|
*/
|
||||||
public List<ExItem> getForbiddenItems() {
|
public Map<ExItem, Boolean> getForbiddenItems() {
|
||||||
return forbiddenItems;
|
return forbiddenItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
@Override
|
@Override
|
||||||
public void setup(ConfigurationSection config) {
|
public void setup(ConfigurationSection config) {
|
||||||
forbiddenItems = caliburn.deserializeExItemList(config, "forbiddenItems");
|
for (String entry : config.getStringList("forbiddenItems")) {
|
||||||
|
if (entry == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
boolean star = !entry.contains("*");
|
||||||
|
entry = entry.replace("*", "");
|
||||||
|
ExItem item = caliburn.getExItem(entry);
|
||||||
|
if (item != null) {
|
||||||
|
forbiddenItems.put(item, star);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -65,9 +77,17 @@ public class ForbiddenItemsRequirement implements Requirement {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ExItem exItem = caliburn.getExItem(item);
|
ExItem exItem = caliburn.getExItem(item);
|
||||||
if (forbiddenItems.contains(exItem)) {
|
for (Entry<ExItem, Boolean> entry : forbiddenItems.entrySet()) {
|
||||||
|
if (entry.getValue()) {
|
||||||
|
if (exItem.isSubsumableUnder(entry.getKey())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (exItem.equals(entry.getKey())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -84,19 +104,29 @@ public class ForbiddenItemsRequirement implements Requirement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (ExItem forbiddenItem : forbiddenItems) {
|
for (Entry<ExItem, Boolean> entry : forbiddenItems.entrySet()) {
|
||||||
ChatColor color = exInventory.contains(forbiddenItem) ? ChatColor.DARK_RED : ChatColor.GREEN;
|
boolean contains = containsItem(exInventory, entry.getKey(), entry.getValue());
|
||||||
|
ChatColor color = contains ? ChatColor.DARK_RED : ChatColor.GREEN;
|
||||||
if (!first) {
|
if (!first) {
|
||||||
builder.append(", ").color(ChatColor.WHITE);
|
builder.append(", ").color(ChatColor.WHITE);
|
||||||
} else {
|
} else {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
builder.append(forbiddenItem.getName()).color(color);
|
builder.append(entry.getKey().getName()).color(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean containsItem(Set<ExItem> exInventory, ExItem forbiddenItem, boolean deepCheck) {
|
||||||
|
for (ExItem item : exInventory) {
|
||||||
|
if ((deepCheck && item.isSubsumableUnder(forbiddenItem)) || (!deepCheck && item.equals(forbiddenItem))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void demand(Player player) {
|
public void demand(Player player) {
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -27,7 +27,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.erethon</groupId>
|
<groupId>de.erethon</groupId>
|
||||||
<artifactId>caliburn</artifactId>
|
<artifactId>caliburn</artifactId>
|
||||||
<version>1.0-RC-04</version>
|
<version>1.0-RC-05</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
Loading…
Reference in New Issue
Block a user