SteamWar/FightSystem
Archiviert
13
1

RedstoneWincondition #274

Geschlossen
YoyoNow möchte 18 Commits von RedstoneWincondition nach master mergen
Nur Änderungen aus Commit 784bd88e43 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -3,6 +3,7 @@ package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem; 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.StateDependent;
@ -15,11 +16,14 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Powerable; import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.Rail; import org.bukkit.block.data.Rail;
import org.bukkit.block.data.type.TechnicalPiston; 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 org.bukkit.scheduler.BukkitTask;
import java.util.*; 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 World world = Bukkit.getWorlds().get(0);
private static final Set<Material> ignoredBlocks; private static final Set<Material> ignoredBlocks;
@ -41,6 +45,7 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT)) { if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT)) {
printableWinconditions.add(this); printableWinconditions.add(this);
percentWincondition = 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) + "%"; 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 { public static class TeamPercent extends StateDependent {
private final FightTeam team; private final FightTeam team;
@ -105,33 +121,39 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements
currentBlocks = 0; 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)) {
currentBlocks++;
}
});
return currentBlocks;
}
}
private static boolean validBlock(Block block) {
Material material = block.getType(); Material material = block.getType();
if (ignoredBlocks.contains(material)) { if (ignoredBlocks.contains(material)) {
return; return false;
} }
BlockData blockData = block.getBlockData(); BlockData blockData = block.getBlockData();
if (blockData instanceof Powerable if (blockData instanceof Powerable
|| blockData instanceof TechnicalPiston || blockData instanceof TechnicalPiston
|| blockData instanceof AnaloguePowerable || blockData instanceof AnaloguePowerable
|| blockData instanceof Rail) { || blockData instanceof Rail) {
currentBlocks++; return true;
return;
} }
switch (material) { switch (material) {
case NOTE_BLOCK: case NOTE_BLOCK:
case REDSTONE_BLOCK: case REDSTONE_BLOCK:
case REDSTONE: case REDSTONE:
case OBSERVER:
case HOPPER: case HOPPER:
case REDSTONE_LAMP: case REDSTONE_LAMP:
case REDSTONE_TORCH: case REDSTONE_TORCH:
case REDSTONE_WALL_TORCH: case REDSTONE_WALL_TORCH:
currentBlocks++; return true;
break;
default: default:
break; return false;
}
});
return currentBlocks;
} }
} }
} }