Add WinconditionRelativeRedstonePercent
Dieser Commit ist enthalten in:
Ursprung
5ed30e9123
Commit
43f4d3bb66
@ -26,6 +26,7 @@ public enum Winconditions {
|
||||
ALL_DEAD,
|
||||
CAPTAIN_DEAD,
|
||||
PERCENT_SYSTEM,
|
||||
RELATIVE_REDSTONE_PERCENT,
|
||||
RELATIVE_PERCENT,
|
||||
POINTS,
|
||||
TIME_TECH_KO,
|
||||
|
@ -98,6 +98,9 @@ public class FightSystem extends JavaPlugin {
|
||||
new WinconditionWaterTechKO();
|
||||
new WinconditionPercentSystem();
|
||||
new WinconditionRelativePercent();
|
||||
if (Core.getVersion() >= 15) {
|
||||
new WinconditionRelativeRedstonePercent();
|
||||
}
|
||||
new WinconditionPoints();
|
||||
new WinconditionTimeout();
|
||||
new WinconditionHeartRatioTimeout();
|
||||
|
@ -0,0 +1,145 @@
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.AnaloguePowerable;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.block.data.Rail;
|
||||
import org.bukkit.block.data.type.TechnicalPiston;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class WinconditionRelativeRedstonePercent extends Wincondition implements PrintableWincondition, PercentWincondition {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
private static final Set<Material> ignoredBlocks;
|
||||
|
||||
static {
|
||||
Set<Material> ignored = new HashSet<>();
|
||||
for (String s : Config.IgnoredBlocks)
|
||||
ignored.add(Material.valueOf(s));
|
||||
ignoredBlocks = Collections.unmodifiableSet(ignored);
|
||||
}
|
||||
|
||||
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||
|
||||
public WinconditionRelativeRedstonePercent() {
|
||||
super("RelativeRedstonePercent");
|
||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
||||
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPercent(FightTeam team) {
|
||||
return teamMap.get(team).getPercent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay(FightTeam team) {
|
||||
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
||||
}
|
||||
|
||||
public static class TeamPercent extends StateDependent {
|
||||
private final FightTeam team;
|
||||
|
||||
private int blockCount;
|
||||
private BukkitTask task;
|
||||
private int currentBlocks;
|
||||
|
||||
public TeamPercent(FightTeam team) {
|
||||
super(Winconditions.RELATIVE_PERCENT, FightState.Running);
|
||||
this.team = team;
|
||||
this.currentBlocks = 1;
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
blockCount = currentBlocks();
|
||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
private void check() {
|
||||
currentBlocks();
|
||||
|
||||
if (!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT))
|
||||
return;
|
||||
|
||||
if (getPercent() >= Config.PercentWin) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Redstone verloren!");
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent");
|
||||
}
|
||||
}
|
||||
|
||||
public double getPercent() {
|
||||
if (currentBlocks > blockCount)
|
||||
return 0;
|
||||
return (blockCount - currentBlocks) * 100 / (double) blockCount;
|
||||
}
|
||||
|
||||
public int getBlockCount() {
|
||||
return blockCount;
|
||||
}
|
||||
|
||||
private int currentBlocks() {
|
||||
// Entern active
|
||||
if (!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft())
|
||||
return currentBlocks;
|
||||
|
||||
currentBlocks = 0;
|
||||
team.getSchemRegion().forEach((x, y, z) -> {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
Material material = block.getType();
|
||||
if (ignoredBlocks.contains(material)) {
|
||||
return;
|
||||
}
|
||||
BlockData blockData = block.getBlockData();
|
||||
if (blockData instanceof Powerable
|
||||
|| blockData instanceof TechnicalPiston
|
||||
|| blockData instanceof AnaloguePowerable
|
||||
|| blockData instanceof Rail) {
|
||||
currentBlocks++;
|
||||
return;
|
||||
}
|
||||
switch (material) {
|
||||
case NOTE_BLOCK:
|
||||
case REDSTONE_BLOCK:
|
||||
case REDSTONE:
|
||||
case REPEATER:
|
||||
case COMPARATOR:
|
||||
case OBSERVER:
|
||||
case HOPPER:
|
||||
case REDSTONE_LAMP:
|
||||
case REDSTONE_TORCH:
|
||||
case REDSTONE_WALL_TORCH:
|
||||
case REDSTONE_WIRE:
|
||||
currentBlocks++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
return currentBlocks;
|
||||
}
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren