forked from SteamWar/SteamWar
Add general Melting of Blocks
This commit is contained in:
@@ -35,7 +35,8 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class WorldConfig {
|
public class WorldConfig {
|
||||||
@@ -54,7 +55,7 @@ public class WorldConfig {
|
|||||||
public static final int MAP_MIN_Z;
|
public static final int MAP_MIN_Z;
|
||||||
public static final int MAP_MAX_X;
|
public static final int MAP_MAX_X;
|
||||||
public static final int MAP_MAX_Z;
|
public static final int MAP_MAX_Z;
|
||||||
public static final Map<Material, Integer> MELTING_TIMES;
|
public static final boolean MELTING;
|
||||||
public static final TowerGeneratorConfig TOWER_GENERATOR_CONFIG;
|
public static final TowerGeneratorConfig TOWER_GENERATOR_CONFIG;
|
||||||
|
|
||||||
public static final List<WinCondition> WINCONDITIONS = new ArrayList<>();
|
public static final List<WinCondition> WINCONDITIONS = new ArrayList<>();
|
||||||
@@ -161,16 +162,7 @@ public class WorldConfig {
|
|||||||
MAP_MAX_X = config.getInt("maxX");
|
MAP_MAX_X = config.getInt("maxX");
|
||||||
MAP_MAX_Z = config.getInt("maxZ");
|
MAP_MAX_Z = config.getInt("maxZ");
|
||||||
|
|
||||||
ConfigurationSection meltingBlocksSection = tower.getConfigurationSection("meltingBlocks");
|
MELTING = tower.getBoolean("melting") || tower.contains("meltingBlocks"); // Backwards compatibility with meltingBlocks key!
|
||||||
if (meltingBlocksSection != null) {
|
|
||||||
Map<Material, Integer> meltingTimes = new HashMap<>();
|
|
||||||
meltingBlocksSection.getKeys(false).forEach(s -> {
|
|
||||||
meltingTimes.put(Material.valueOf(s), meltingBlocksSection.getInt(s));
|
|
||||||
});
|
|
||||||
MELTING_TIMES = Collections.unmodifiableMap(meltingTimes);
|
|
||||||
} else {
|
|
||||||
MELTING_TIMES = Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
ACTIVE_WINCONDITIONS = config.getStringList("winconditions");
|
ACTIVE_WINCONDITIONS = config.getStringList("winconditions");
|
||||||
WINCONDITIONS.stream().filter(winCondition -> ACTIVE_WINCONDITIONS.contains(winCondition.getName())).forEach(winCondition -> winCondition.setActive(true));
|
WINCONDITIONS.stream().filter(winCondition -> ACTIVE_WINCONDITIONS.contains(winCondition.getName())).forEach(winCondition -> winCondition.setActive(true));
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class IngameListener extends GameStateBukkitListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
blocks.forEach(block -> {
|
blocks.forEach(block -> {
|
||||||
if (!WorldConfig.MELTING_TIMES.containsKey(block.getType())) return;
|
if (block.getType() == Material.AIR || block.getType() == Material.LAVA) return;
|
||||||
block.setType(Material.AIR);
|
block.setType(Material.AIR);
|
||||||
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.1F, 1);
|
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.1F, 1);
|
||||||
});
|
});
|
||||||
@@ -189,6 +189,9 @@ public class IngameListener extends GameStateBukkitListener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
|
if (!WorldConfig.MELTING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.getSourceBlock().getType() != Material.LAVA) {
|
if (event.getSourceBlock().getType() != Material.LAVA) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -202,11 +205,9 @@ public class IngameListener extends GameStateBukkitListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void shouldMelt(Block block) {
|
private void shouldMelt(Block block) {
|
||||||
int meltingTime = WorldConfig.MELTING_TIMES.getOrDefault(block.getType(), -1);
|
if (block.getType().isBurnable()) return;
|
||||||
if (meltingTime == -1) {
|
int meltingTime = (int) (block.getType().getHardness() * 48 * 20);
|
||||||
return;
|
blocksToMelt.computeIfAbsent(time + meltingTime, integer -> new ArrayList<>()).add(block);
|
||||||
}
|
|
||||||
blocksToMelt.computeIfAbsent(time + meltingTime * 20, integer -> new ArrayList<>()).add(block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|||||||
Reference in New Issue
Block a user