mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-10-23 20:19:57 +02:00
!Small cleanup
This commit is contained in:
parent
0c789c8154
commit
40894d57ad
@ -5,9 +5,6 @@ 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.Block;
|
||||||
@ -20,7 +17,10 @@ import net.Indyuce.mmocore.api.droptable.DropTable;
|
|||||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
||||||
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
|
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
|
||||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||||
|
import net.mmogroup.mmolib.UtilityMethods;
|
||||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||||
|
import net.mmogroup.mmolib.api.condition.BlockCondition;
|
||||||
|
import net.mmogroup.mmolib.api.condition.MMOCondition;
|
||||||
|
|
||||||
public class BlockInfo {
|
public class BlockInfo {
|
||||||
private final BlockType block;
|
private final BlockType block;
|
||||||
@ -62,10 +62,11 @@ 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"))
|
if (config.isList("conditions"))
|
||||||
for(String key : config.getStringList("conditions")) {
|
for (String key : config.getStringList("conditions")) {
|
||||||
MMOCondition condition = UtilityMethods.getCondition(key);
|
MMOCondition condition = UtilityMethods.getCondition(key);
|
||||||
if(condition instanceof BlockCondition) conditions.add((BlockCondition) condition);
|
if (condition instanceof BlockCondition)
|
||||||
|
conditions.add((BlockCondition) condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -123,9 +124,9 @@ public class BlockInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkConditions(Block block) {
|
public boolean checkConditions(Block block) {
|
||||||
for(BlockCondition condition : conditions)
|
for (BlockCondition condition : conditions)
|
||||||
if(!condition.check(block)) return false;
|
if (!condition.check(block))
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ package net.Indyuce.mmocore.api.event;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||||
|
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
|
||||||
import net.Indyuce.mmocore.api.experience.ExperienceInfo;
|
import net.Indyuce.mmocore.api.experience.ExperienceInfo;
|
||||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
@ -22,6 +22,7 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
|||||||
private final List<ItemStack> drops;
|
private final List<ItemStack> drops;
|
||||||
private final ExperienceInfo experience;
|
private final ExperienceInfo experience;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private boolean canBreak;
|
private boolean canBreak;
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
@ -30,9 +31,9 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
|||||||
|
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.drops = (info.hasDropTable() && player.isOnline()
|
this.drops = (info.hasDropTable() && player.isOnline() && info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer())))
|
||||||
&& info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer())))
|
? info.collectDrops(new LootBuilder(player, 0))
|
||||||
? info.collectDrops(new LootBuilder(player, 0)) : new ArrayList<>();
|
: new ArrayList<>();
|
||||||
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
||||||
this.canBreak = canBreak;
|
this.canBreak = canBreak;
|
||||||
}
|
}
|
||||||
@ -57,10 +58,12 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
|||||||
return experience;
|
return experience;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public boolean canBreak() {
|
public boolean canBreak() {
|
||||||
return canBreak;
|
return canBreak;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setCanBreak(boolean value) {
|
public void setCanBreak(boolean value) {
|
||||||
canBreak = value;
|
canBreak = value;
|
||||||
}
|
}
|
||||||
|
@ -12,21 +12,25 @@ import org.apache.commons.lang.Validate;
|
|||||||
public class ExpCurve {
|
public class ExpCurve {
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* experience needed to level up. different professions or classes can have
|
* Experience needed to level up. Different professions or classes can have
|
||||||
* different exp curves so that it is easier to balance.
|
* different exp curves so that it is easier to balance.
|
||||||
*/
|
*/
|
||||||
private final List<Integer> experience = new ArrayList<>();
|
private final List<Integer> experience = new ArrayList<>();
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* purely arbitrary but MMOCore needs a default exp curve for everything
|
* Purely arbitrary but MMOCore needs a default exp curve for everything
|
||||||
* otherwise there might be divisions by 0 when trying to update the vanilla
|
* otherwise there might be divisions by 0 when trying to update the vanilla
|
||||||
* exp bar which requires a 0.0 -> 1.0 float as parameter
|
* exp bar which requires a 0.0 -> 1.0 float as parameter
|
||||||
*/
|
*/
|
||||||
public static final ExpCurve DEFAULT = new ExpCurve("default", 100, 200, 300, 400, 500);
|
public static final ExpCurve DEFAULT = new ExpCurve("default", 100, 200, 300, 400, 500);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* read exp curve from a file, one line after the other
|
* Reads an exp curve from a text file, one line after the other. Each exp
|
||||||
|
* value has to be the only thing written on every line
|
||||||
|
*
|
||||||
|
* @param file Text file to read data from
|
||||||
|
* @throws IOException IO exception when reading file
|
||||||
*/
|
*/
|
||||||
public ExpCurve(File file) throws IOException {
|
public ExpCurve(File file) throws IOException {
|
||||||
this.id = file.getName().replace(".txt", "").toLowerCase().replace("_", "-").replace(" ", "-");
|
this.id = file.getName().replace(".txt", "").toLowerCase().replace("_", "-").replace(" ", "-");
|
||||||
@ -40,9 +44,13 @@ public class ExpCurve {
|
|||||||
Validate.isTrue(!experience.isEmpty(), "There must be at least one exp value in your exp curve");
|
Validate.isTrue(!experience.isEmpty(), "There must be at least one exp value in your exp curve");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* can be used by external plugins to register curves and it used by MMOCore
|
* Public constructor for external plugins
|
||||||
* to create the default exp curve if none is selected
|
*
|
||||||
|
* @param id Some unique identifier to let other plugin features refer
|
||||||
|
* to your exp curve.
|
||||||
|
* @param values The exp values, at to be at least one or the constructor
|
||||||
|
* will throw an error
|
||||||
*/
|
*/
|
||||||
public ExpCurve(String id, int... values) {
|
public ExpCurve(String id, int... values) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -55,10 +63,11 @@ public class ExpCurve {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* retrieves the experience needed. the level serves as index for the list
|
* @param level Level being reached by some player
|
||||||
* checkup. if the level is higher than the amount of exp inputs, just
|
* @return Experience needed to reach provided level. The level serves
|
||||||
* return the last list value
|
* an index for a list checkup. If the level is higher than
|
||||||
|
* the list size, it just returns the last value of the list
|
||||||
*/
|
*/
|
||||||
public int getExperience(int level) {
|
public int getExperience(int level) {
|
||||||
Validate.isTrue(level > 0, "Level must be stricly positive");
|
Validate.isTrue(level > 0, "Level must be stricly positive");
|
||||||
|
@ -30,6 +30,7 @@ import net.mmogroup.mmolib.UtilityMethods;
|
|||||||
public class BlockListener implements Listener {
|
public class BlockListener implements Listener {
|
||||||
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
|
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onCustomBreak(BlockBreakEvent event) {
|
public void onCustomBreak(BlockBreakEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@ -47,7 +48,8 @@ public class BlockListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the block is a temporary block, immediately cancel the break event
|
* If the block is a temporary block placed by block regen, immediately
|
||||||
|
* cancel the break event
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
@ -56,9 +58,6 @@ public class BlockListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if the block has exp or drop tables
|
|
||||||
*/
|
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -104,7 +103,6 @@ public class BlockListener implements Listener {
|
|||||||
* on block/tool broken yet simple compatibility stuff
|
* on block/tool broken yet simple compatibility stuff
|
||||||
*/
|
*/
|
||||||
if (!info.hasVanillaDrops()) {
|
if (!info.hasVanillaDrops()) {
|
||||||
// event.setDropItems(false); // May not work
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getBlock().setType(Material.AIR);
|
event.getBlock().setType(Material.AIR);
|
||||||
Bukkit.getPluginManager().callEvent(new PlayerItemDamageEvent(player, item, 1));
|
Bukkit.getPluginManager().callEvent(new PlayerItemDamageEvent(player, item, 1));
|
||||||
|
@ -10,6 +10,8 @@ import java.util.Set;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -66,7 +68,14 @@ public class CustomBlockManager extends MMOManager {
|
|||||||
map.put(regen.getBlock().generateKey(), regen);
|
map.put(regen.getBlock().generateKey(), regen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getInfo(Block block) {
|
/**
|
||||||
|
* Checks if the behaviour of a block was changed by a specific profession
|
||||||
|
* (different drop tables, block regen..)
|
||||||
|
*
|
||||||
|
* @param block Block to check
|
||||||
|
* @return The new block behaviour or null if no new behaviour
|
||||||
|
*/
|
||||||
|
public @Nullable BlockInfo getInfo(Block block) {
|
||||||
return map.getOrDefault(findBlockType(block).generateKey(), null);
|
return map.getOrDefault(findBlockType(block).generateKey(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +93,11 @@ public class CustomBlockManager extends MMOManager {
|
|||||||
* Used when a block is being broken and MMOCore needs to regen it after X
|
* Used when a block is being broken and MMOCore needs to regen it after X
|
||||||
* seconds. Also places the temporary block at the block location
|
* seconds. Also places the temporary block at the block location
|
||||||
*
|
*
|
||||||
* @param info
|
* @param info Block info
|
||||||
* Block info
|
* @param scheduleRegen If block regeneration should be scheduled or not. If
|
||||||
* @param scheduleRegen
|
* the block broken is a temporary block and is part of
|
||||||
* If block regeneration should be scheduled or not. If the block
|
* a "block chain", no regen should be scheduled as
|
||||||
* broken is a temporary block and is part of a "block chain", no
|
* there is already one
|
||||||
* regen should be scheduled as there is already one
|
|
||||||
*/
|
*/
|
||||||
public void initialize(RegeneratingBlock info, boolean scheduleRegen) {
|
public void initialize(RegeneratingBlock info, boolean scheduleRegen) {
|
||||||
if (scheduleRegen) {
|
if (scheduleRegen) {
|
||||||
@ -105,12 +113,10 @@ public class CustomBlockManager extends MMOManager {
|
|||||||
* Called when a block regens, either due to regen timer or because the
|
* Called when a block regens, either due to regen timer or because the
|
||||||
* server shuts down.
|
* server shuts down.
|
||||||
*
|
*
|
||||||
* @param info
|
* @param info Block which must be regened
|
||||||
* Block which must be regened
|
* @param shutdown Must be set to true if the server is shutting down. When
|
||||||
* @param shutdown
|
* the server shuts down, it iterates through active blocks.
|
||||||
* Must be set to true if the server is shutting down. When the
|
* This prevents any issue when editing lists being iterated
|
||||||
* server shuts down, it iterates through active blocks. This
|
|
||||||
* prevents any issue when editing lists being iterated
|
|
||||||
*/
|
*/
|
||||||
private void regen(RegeneratingBlock info, boolean shutdown) {
|
private void regen(RegeneratingBlock info, boolean shutdown) {
|
||||||
Location infoLocation = info.getLocation();
|
Location infoLocation = info.getLocation();
|
||||||
@ -133,10 +139,9 @@ public class CustomBlockManager extends MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param block
|
* @param block Potentially vanilla block being broken by a player
|
||||||
* Potentially vanilla block being broken by a player
|
* @return Returns if the block being broken is a temporary block. If
|
||||||
* @return Returns if the block being broken is a temporary block. If it is,
|
* it is, players should not be able to break it
|
||||||
* players should not be able to break it
|
|
||||||
*/
|
*/
|
||||||
public boolean isTemporaryBlock(Block block) {
|
public boolean isTemporaryBlock(Block block) {
|
||||||
Location loc = block.getLocation();
|
Location loc = block.getLocation();
|
||||||
|
Loading…
Reference in New Issue
Block a user