forked from Upstream/mmocore
UNSTABLE - Added conditions to MMOCore custom mining blocks so you can configure certain blocks per region.
Requires MMOLib 1.7.4
This commit is contained in:
parent
decc75a5b0
commit
0396eaaef8
BIN
lib/MMOLib.jar
BIN
lib/MMOLib.jar
Binary file not shown.
@ -5,8 +5,12 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import net.mmogroup.mmolib.UtilityMethods;
|
||||||
|
import net.mmogroup.mmolib.api.condition.BlockCondition;
|
||||||
|
import net.mmogroup.mmolib.api.condition.MMOCondition;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -24,6 +28,7 @@ public class BlockInfo {
|
|||||||
private final boolean vanillaDrops;
|
private final boolean vanillaDrops;
|
||||||
private final List<Trigger> triggers = new ArrayList<>();
|
private final List<Trigger> triggers = new ArrayList<>();
|
||||||
private final RegenInfo regen;
|
private final RegenInfo regen;
|
||||||
|
private final List<BlockCondition> conditions = new ArrayList<>();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* saved separately because MMOCore needs to display the experience gained,
|
* saved separately because MMOCore needs to display the experience gained,
|
||||||
@ -56,6 +61,13 @@ public class BlockInfo {
|
|||||||
|
|
||||||
Optional<Trigger> opt = triggers.stream().filter(trigger -> (trigger instanceof ExperienceTrigger)).findFirst();
|
Optional<Trigger> opt = triggers.stream().filter(trigger -> (trigger instanceof ExperienceTrigger)).findFirst();
|
||||||
experience = (ExperienceTrigger) opt.orElse(null);
|
experience = (ExperienceTrigger) opt.orElse(null);
|
||||||
|
|
||||||
|
if(config.isList("conditions"))
|
||||||
|
for(String key : config.getStringList("conditions")) {
|
||||||
|
MMOCondition condition = UtilityMethods.getCondition(key);
|
||||||
|
if(condition instanceof BlockCondition) conditions.add((BlockCondition) condition);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasVanillaDrops() {
|
public boolean hasVanillaDrops() {
|
||||||
@ -110,6 +122,13 @@ public class BlockInfo {
|
|||||||
return triggers;
|
return triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkConditions(Block block) {
|
||||||
|
for(BlockCondition condition : conditions)
|
||||||
|
if(!condition.check(block)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static class RegeneratingBlock {
|
public static class RegeneratingBlock {
|
||||||
private final BlockData data;
|
private final BlockData data;
|
||||||
private final Location loc;
|
private final Location loc;
|
||||||
|
@ -49,7 +49,7 @@ public class BlockListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block);
|
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block);
|
||||||
boolean temporaryBlock = MMOCore.plugin.mineManager.isTemporaryBlock(block);
|
boolean temporaryBlock = MMOCore.plugin.mineManager.isTemporaryBlock(block);
|
||||||
if (temporaryBlock && info == null) {
|
if ((temporaryBlock && info == null) || !info.checkConditions(block)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user