!Fixed custom block chains

This commit is contained in:
Indyuce 2020-10-04 16:03:53 +02:00
parent 8cf6f057d2
commit d55c0affe2
3 changed files with 215 additions and 209 deletions

View File

@ -46,7 +46,9 @@ public class BlockListener implements Listener {
/* /*
* If the block is a temporary block, immediately cancel the break event * If the block is a temporary block, immediately cancel the break event
*/ */
if (MMOCore.plugin.mineManager.isTemporaryBlock(block)) { BlockInfo info = MMOCore.plugin.mineManager.getInfo(block);
boolean temporaryBlock = MMOCore.plugin.mineManager.isTemporaryBlock(block);
if (temporaryBlock && info == null) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -54,7 +56,6 @@ public class BlockListener implements Listener {
/* /*
* Check if the block has exp or drop tables * Check if the block has exp or drop tables
*/ */
BlockInfo info = MMOCore.plugin.mineManager.getInfo(block);
if (info == null) { if (info == null) {
/* /*
@ -109,15 +110,6 @@ public class BlockListener implements Listener {
if (info.hasTriggers() && !block.hasMetadata("player_placed")) { if (info.hasTriggers() && !block.hasMetadata("player_placed")) {
PlayerData playerData = PlayerData.get(player); PlayerData playerData = PlayerData.get(player);
info.getTriggers().forEach(trigger -> trigger.apply(playerData)); info.getTriggers().forEach(trigger -> trigger.apply(playerData));
/**
* if (!block.hasMetadata("player_placed") && info.hasExperience()
* && MMOCore.plugin.hasHolograms())
* MMOCore.plugin.hologramSupport.displayIndicator(block.getLocation().add(.5,
* 1.5, .5),
* MMOCore.plugin.configManager.getSimpleMessage("exp-hologram",
* "exp", "" + called.getGainedExperience().getValue()).message(),
* player);
*/
} }
/* /*
@ -135,7 +127,7 @@ public class BlockListener implements Listener {
* Finally enable block regen. * Finally enable block regen.
*/ */
if (info.hasRegen()) if (info.hasRegen())
MMOCore.plugin.mineManager.initialize(info.startRegeneration(Bukkit.createBlockData(savedData), block.getLocation())); MMOCore.plugin.mineManager.initialize(info.startRegeneration(Bukkit.createBlockData(savedData), block.getLocation()), !temporaryBlock);
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)

View File

@ -30,22 +30,24 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
public class CustomBlockManager extends MMOManager { public class CustomBlockManager extends MMOManager {
/* /**
* registered block infos * Registered block infos
*/ */
private final Map<String, BlockInfo> map = new HashMap<>(); private final Map<String, BlockInfo> map = new HashMap<>();
/* /**
* blocks that are regenerating and that must be refreshed whenever the * Blocks that are regenerating and that must be refreshed whenever the
* server reloads or shuts down not to hurt the world map * server reloads or shuts down not to hurt the world map
*/ */
private final Set<RegeneratingBlock> active = new HashSet<>(); private final Set<RegeneratingBlock> active = new HashSet<>();
/* list in which both block regen and block permissions are enabled. */ /**
* Stores conditions which must be met to apply custom mining
*/
private final List<Condition> customMineConditions = new ArrayList<>(); private final List<Condition> customMineConditions = new ArrayList<>();
/* /**
* list of functions which let MMOCore recognize what block a player is * List of functions which let MMOCore recognize what block a player is
* currently breaking * currently breaking
*/ */
private final List<Function<Block, Optional<BlockType>>> blockTypes = new ArrayList<>(); private final List<Function<Block, Optional<BlockType>>> blockTypes = new ArrayList<>();
@ -78,11 +80,23 @@ public class CustomBlockManager extends MMOManager {
return new VanillaBlockType(block); return new VanillaBlockType(block);
} }
public void initialize(RegeneratingBlock info) { /**
// if (schedule) { * Used when a block is being broken and MMOCore needs to regen it after X
active.add(info); * seconds. Also places the temporary block at the block location
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> regen(info, false), info.getRegeneratingBlock().getRegenerationInfo().getTime()); *
// } * @param info
* Block info
* @param scheduleRegen
* If block regeneration should be scheduled or not. If the block
* broken is a temporary block and is part of a "block chain", no
* regen should be scheduled as there is already one
*/
public void initialize(RegeneratingBlock info, boolean scheduleRegen) {
if (scheduleRegen) {
active.add(info);
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> regen(info, false), info.getRegeneratingBlock().getRegenerationInfo().getTime());
}
if (info.getRegeneratingBlock().getRegenerationInfo().hasTemporaryBlock()) if (info.getRegeneratingBlock().getRegenerationInfo().hasTemporaryBlock())
info.getRegeneratingBlock().getRegenerationInfo().getTemporaryBlock().place(info.getLocation(), info); info.getRegeneratingBlock().getRegenerationInfo().getTemporaryBlock().place(info.getLocation(), info);
} }