SteamWar/FightSystem
Archiviert
13
1

Add WinconditionRelativeRedstonePercent

Dieser Commit ist enthalten in:
yoyosource 2021-05-09 15:36:43 +02:00
Ursprung 08ef10a3d8
Commit 784bd88e43

Datei anzeigen

@ -3,6 +3,7 @@ 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.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
@ -15,11 +16,14 @@ 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.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.scheduler.BukkitTask;
import java.util.*;
public class WinconditionRelativeRedstonePercent extends Wincondition implements PrintableWincondition, PercentWincondition {
public class WinconditionRelativeRedstonePercent extends Wincondition implements PrintableWincondition, PercentWincondition, Listener {
private static final World world = Bukkit.getWorlds().get(0);
private static final Set<Material> ignoredBlocks;
@ -41,6 +45,7 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT)) {
printableWinconditions.add(this);
percentWincondition = this;
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
}
}
@ -54,6 +59,17 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
FightPlayer fightPlayer = Fight.getFightPlayer(event.getPlayer());
if (fightPlayer == null) {
return;
}
if (validBlock(event.getBlockPlaced())) {
teamMap.get(fightPlayer.getTeam()).blockCount--;
}
}
public static class TeamPercent extends StateDependent {
private final FightTeam team;
@ -105,33 +121,39 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements
currentBlocks = 0;
team.getSchemRegion().forEach((x, y, z) -> {
Block block = world.getBlockAt(x, y, z);
if (validBlock(block)) {
currentBlocks++;
}
});
return currentBlocks;
}
}
private static boolean validBlock(Block block) {
Material material = block.getType();
if (ignoredBlocks.contains(material)) {
return;
return false;
}
BlockData blockData = block.getBlockData();
if (blockData instanceof Powerable
|| blockData instanceof TechnicalPiston
|| blockData instanceof AnaloguePowerable
|| blockData instanceof Rail) {
currentBlocks++;
return;
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:
currentBlocks++;
break;
return true;
default:
break;
}
});
return currentBlocks;
return false;
}
}
}