Added Water Remover
Signed-off-by: Yaruma3341 <yaruma3341@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
5fdfa6e598
Commit
ed14b52948
@ -34,6 +34,7 @@ public class FightSystem extends JavaPlugin {
|
|||||||
private FightManager fightManager;
|
private FightManager fightManager;
|
||||||
private Scoreboard scoreboard;
|
private Scoreboard scoreboard;
|
||||||
private KitManager kitManager;
|
private KitManager kitManager;
|
||||||
|
private WaterRemover waterRemover;
|
||||||
|
|
||||||
private FightState fightState;
|
private FightState fightState;
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ public class FightSystem extends JavaPlugin {
|
|||||||
this.fightManager = new FightManager();
|
this.fightManager = new FightManager();
|
||||||
this.scoreboard = new Scoreboard(plugin);
|
this.scoreboard = new Scoreboard(plugin);
|
||||||
this.kitManager = new KitManager();
|
this.kitManager = new KitManager();
|
||||||
|
this.waterRemover = new WaterRemover();
|
||||||
|
|
||||||
Fight.getRedTeam().setName(fileManager.getStringFromConfig("Output.TeamRedName"));
|
Fight.getRedTeam().setName(fileManager.getStringFromConfig("Output.TeamRedName"));
|
||||||
Fight.getRedTeam().setPrefix(fileManager.getStringFromConfig("Output.TeamRedColor"));
|
Fight.getRedTeam().setPrefix(fileManager.getStringFromConfig("Output.TeamRedColor"));
|
||||||
@ -245,6 +247,10 @@ public class FightSystem extends JavaPlugin {
|
|||||||
return kitManager;
|
return kitManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WaterRemover getWaterRemover() {
|
||||||
|
return waterRemover;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSetupState() {
|
public void setSetupState() {
|
||||||
if(this.fightState == null) {
|
if(this.fightState == null) {
|
||||||
this.fightState = FightState.SETUP;
|
this.fightState = FightState.SETUP;
|
||||||
@ -286,6 +292,8 @@ public class FightSystem extends JavaPlugin {
|
|||||||
this.fightState = FightState.RUNNING;
|
this.fightState = FightState.RUNNING;
|
||||||
Countdown.cancelAllTimers();
|
Countdown.cancelAllTimers();
|
||||||
|
|
||||||
|
getWaterRemover().start();
|
||||||
|
|
||||||
setAllPlayersGM(GameMode.SURVIVAL);
|
setAllPlayersGM(GameMode.SURVIVAL);
|
||||||
|
|
||||||
if(fileManager.getBooleanFromConfig("WinConditions.Timeout")) {
|
if(fileManager.getBooleanFromConfig("WinConditions.Timeout")) {
|
||||||
|
106
src/me/yaruma/fightsystem/fight/WaterRemover.java
Normale Datei
106
src/me/yaruma/fightsystem/fight/WaterRemover.java
Normale Datei
@ -0,0 +1,106 @@
|
|||||||
|
package me.yaruma.fightsystem.fight;
|
||||||
|
|
||||||
|
import me.yaruma.fightsystem.FightSystem;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WaterRemover {
|
||||||
|
|
||||||
|
private List<AbstractMap.SimpleEntry<Location, Integer>> explodedBlocks = new ArrayList<AbstractMap.SimpleEntry<Location, Integer>>();
|
||||||
|
private List<Block> waterList = new ArrayList<Block>();
|
||||||
|
private BukkitTask task;
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
this.stop();
|
||||||
|
this.explodedBlocks = new ArrayList<AbstractMap.SimpleEntry<Location, Integer>>();
|
||||||
|
this.waterList = new ArrayList<Block>();
|
||||||
|
this.task = Bukkit.getScheduler().runTaskTimerAsynchronously((Plugin)FightSystem.getPlugin(), new Runnable(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
WaterRemover.this.wateredCheck();
|
||||||
|
WaterRemover.this.removeWater();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
if (this.task != null) {
|
||||||
|
this.task.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Location loc) {
|
||||||
|
this.explodedBlocks.add(new AbstractMap.SimpleEntry<Location, Integer>(loc, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void wateredCheck() {
|
||||||
|
for (int i = 0; i < this.explodedBlocks.size(); ++i) {
|
||||||
|
if (this.explodedBlocks.get(i).getValue() >= 15) {
|
||||||
|
Block b = this.explodedBlocks.get(i).getKey().getBlock();
|
||||||
|
if (b.getType() == Material.WATER || b.getType() == Material.STATIONARY_WATER) {
|
||||||
|
this.waterList.add(b);
|
||||||
|
}
|
||||||
|
this.explodedBlocks.remove(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this.explodedBlocks.get(i).setValue(this.explodedBlocks.get(i).getValue() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeWater() {
|
||||||
|
ArrayList<Block> blocksToRemove = new ArrayList<Block>();
|
||||||
|
for (int i = this.waterList.size() - 1; i > -1; --i) {
|
||||||
|
Block current = this.waterList.get(i);
|
||||||
|
for (Block removeBlock : this.getSourceBlocksOfWater(current)) {
|
||||||
|
blocksToRemove.add(removeBlock);
|
||||||
|
}
|
||||||
|
if (current.getType() != Material.AIR) continue;
|
||||||
|
this.waterList.remove(i);
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTask((Plugin)FightSystem.getPlugin(), () -> {
|
||||||
|
for (Block block : blocksToRemove) {
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Block> getSourceBlocksOfWater(Block startBlock) {
|
||||||
|
ArrayList<Block> water = new ArrayList<Block>();
|
||||||
|
this.collectBlocks(startBlock, water, new ArrayList<Block>());
|
||||||
|
return water;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void collectBlocks(Block anchor, List<Block> collected, List<Block> visitedBlocks) {
|
||||||
|
if (anchor.getType() != Material.WATER && anchor.getType() != Material.STATIONARY_WATER) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (visitedBlocks.contains((Object)anchor)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
visitedBlocks.add(anchor);
|
||||||
|
if (anchor.getType() == Material.STATIONARY_WATER) {
|
||||||
|
collected.add(anchor);
|
||||||
|
}
|
||||||
|
this.collectBlocks(anchor.getRelative(BlockFace.UP), collected, visitedBlocks);
|
||||||
|
this.collectBlocks(anchor.getRelative(BlockFace.NORTH), collected, visitedBlocks);
|
||||||
|
this.collectBlocks(anchor.getRelative(BlockFace.EAST), collected, visitedBlocks);
|
||||||
|
this.collectBlocks(anchor.getRelative(BlockFace.SOUTH), collected, visitedBlocks);
|
||||||
|
this.collectBlocks(anchor.getRelative(BlockFace.WEST), collected, visitedBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren