mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
added condition comp for all drop tables
added level condition: - 'level{profession=PROFESSION_NAME_HERE;amount=LEVEL_HERE}' for main level: - 'level{amount=LEVEL_HERE}'
This commit is contained in:
parent
8300726fcd
commit
a4b28597af
@ -5,6 +5,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -18,6 +20,7 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
public class DropTable extends PostLoadObject {
|
||||
private final String id;
|
||||
private final Set<DropItem> drops = new LinkedHashSet<>();
|
||||
private final Set<Condition> conditions = new LinkedHashSet<>();
|
||||
|
||||
public DropTable(ConfigurationSection config) {
|
||||
super(config);
|
||||
@ -37,16 +40,24 @@ public class DropTable extends PostLoadObject {
|
||||
*/
|
||||
@Override
|
||||
protected void whenPostLoaded(ConfigurationSection config) {
|
||||
List<String> list = config.getStringList("items");
|
||||
Validate.notNull(list, "Could not find drop item list");
|
||||
List<String> itemsList = config.getStringList("items");
|
||||
List<String> conditionsList = config.getStringList("conditions");
|
||||
Validate.notNull(itemsList, "Could not find drop item list");
|
||||
|
||||
for (String key : list)
|
||||
for (String key : itemsList)
|
||||
try {
|
||||
drops.add(MMOCore.plugin.loadManager.loadDropItem(new MMOLineConfig(key)));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING,
|
||||
"Could not load drop item '" + key + "' from table '" + id + "': " + exception.getMessage());
|
||||
}
|
||||
for (String key : conditionsList)
|
||||
try {
|
||||
conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key)));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING,
|
||||
"Could not load condition '" + key + "' from table '" + id + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@ -69,4 +80,17 @@ public class DropTable extends PostLoadObject {
|
||||
|
||||
return builder.getLoot();
|
||||
}
|
||||
|
||||
public Set<Condition> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public boolean areConditionsMet(ConditionInstance entity) {
|
||||
for (Condition condition : this.getConditions()) {
|
||||
if (!condition.isMet(entity)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package net.Indyuce.mmocore.api.droptable.condition;
|
||||
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
import net.mmogroup.mmolib.api.player.MMOPlayerData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class LevelCondition extends Condition {
|
||||
private final int amount;
|
||||
|
||||
private final String profession;
|
||||
|
||||
public LevelCondition(MMOLineConfig config) {
|
||||
super(config);
|
||||
|
||||
config.validate("amount");
|
||||
|
||||
amount = config.getInt("amount");
|
||||
profession = config.contains("profession") ? config.getString("profession") : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMet(ConditionInstance entity) {
|
||||
if (entity.getEntity() instanceof Player) {
|
||||
int level = (profession != null) ? MMOPlayerData.get((Player) entity.getEntity()).getMMOCore().getCollectionSkills().getLevel(profession)
|
||||
: MMOPlayerData.get((Player) entity.getEntity()).getMMOCore().getLevel();
|
||||
return level >= amount;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package net.Indyuce.mmocore.api.droptable.dropitem;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.Condition;
|
||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
@ -22,7 +24,8 @@ public class DropTableDropItem extends DropItem {
|
||||
|
||||
@Override
|
||||
public void collect(LootBuilder builder) {
|
||||
for (int j = 0; j < rollAmount(); j++)
|
||||
builder.addLoot(dropTable.collect(builder));
|
||||
if (dropTable.areConditionsMet(new ConditionInstance(builder.getEntity().getPlayer())))
|
||||
for (int j = 0; j < rollAmount(); j++)
|
||||
builder.addLoot(dropTable.collect(builder));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.Indyuce.mmocore.api.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -27,7 +29,8 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
||||
|
||||
this.block = block;
|
||||
this.info = info;
|
||||
this.drops = info.collectDrops(new LootBuilder(player, 0));
|
||||
this.drops = (info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer())))
|
||||
? info.collectDrops(new LootBuilder(player, 0)) : new ArrayList<>();
|
||||
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.api.load;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.condition.LevelCondition;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import net.Indyuce.mmocore.api.block.BlockType;
|
||||
@ -113,6 +114,9 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
if (config.getKey().equals("biome"))
|
||||
return new BiomeCondition(config);
|
||||
|
||||
if (config.getKey().equals("level"))
|
||||
return new LevelCondition(config);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user