Update WinconditionRelativeRedstonePercent
Dieser Commit ist enthalten in:
Ursprung
cd3ec80f43
Commit
a3c073e04d
@ -1,26 +1,16 @@
|
|||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependent;
|
|
||||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
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.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -58,99 +48,53 @@ public class WinconditionRelativeRedstonePercent extends PercentWincondition imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
FightPlayer fightPlayer = Fight.getFightPlayer(event.getPlayer());
|
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
||||||
if (fightPlayer == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (validBlock(event.getBlockPlaced())) {
|
|
||||||
teamMap.get(fightPlayer.getTeam()).blockCount--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TeamPercent extends StateDependent {
|
private static boolean validBlock(Block block) {
|
||||||
private final FightTeam team;
|
return Config.Blocks.contains(block.getType());
|
||||||
|
}
|
||||||
|
|
||||||
private int blockCount;
|
public class TeamPercent extends PercentWincondition.TeamPercent {
|
||||||
private BukkitTask task;
|
|
||||||
private int currentBlocks;
|
|
||||||
|
|
||||||
public TeamPercent(FightTeam team) {
|
public TeamPercent(FightTeam team) {
|
||||||
super(Winconditions.RELATIVE_REDSTONE_PERCENT, FightState.Running);
|
super(team);
|
||||||
this.team = team;
|
totalBlocks = currentBlocks();
|
||||||
this.currentBlocks = 1;
|
currentBlocks = totalBlocks;
|
||||||
register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void check(EntityExplodeEvent event) {
|
||||||
public void enable() {
|
if (!team.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||||
blockCount = currentBlocks();
|
|
||||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 100, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
task.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void check() {
|
|
||||||
currentBlocks();
|
|
||||||
|
|
||||||
if (!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT))
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.blockList().forEach(block -> {
|
||||||
|
if (validBlock(block)) {
|
||||||
|
currentBlocks--;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (getPercent() >= Config.PercentWin) {
|
if (getPercent() >= Config.PercentWin) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Redstone verloren!");
|
lose();
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPercent() {
|
public double getPercent() {
|
||||||
if (currentBlocks > blockCount)
|
if (currentBlocks > totalBlocks)
|
||||||
return 0;
|
return 0;
|
||||||
return (blockCount - currentBlocks) * 100 / (double) blockCount;
|
return (totalBlocks - currentBlocks) * 100 / (double) totalBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int currentBlocks() {
|
private int currentBlocks() {
|
||||||
// Entern active
|
totalBlocks = 0;
|
||||||
if (!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft())
|
|
||||||
return currentBlocks;
|
|
||||||
|
|
||||||
currentBlocks = 0;
|
|
||||||
team.getSchemRegion().forEach((x, y, z) -> {
|
team.getSchemRegion().forEach((x, y, z) -> {
|
||||||
Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
if (validBlock(block)) {
|
if (validBlock(block)) {
|
||||||
currentBlocks++;
|
totalBlocks++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return currentBlocks;
|
return totalBlocks;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean validBlock(Block block) {
|
|
||||||
Material material = block.getType();
|
|
||||||
if (Config.Blocks.contains(material)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
BlockData blockData = block.getBlockData();
|
|
||||||
if (blockData instanceof Powerable
|
|
||||||
|| blockData instanceof TechnicalPiston
|
|
||||||
|| blockData instanceof AnaloguePowerable
|
|
||||||
|| blockData instanceof Rail) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch (material) {
|
|
||||||
case NOTE_BLOCK:
|
|
||||||
case REDSTONE_BLOCK:
|
|
||||||
case REDSTONE:
|
|
||||||
case OBSERVER:
|
|
||||||
case HOPPER:
|
|
||||||
case REDSTONE_LAMP:
|
|
||||||
case REDSTONE_TORCH:
|
|
||||||
case REDSTONE_WALL_TORCH:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren