RedstoneWincondition #274
@ -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);
|
||||||
Material material = block.getType();
|
if (validBlock(block)) {
|
||||||
if (ignoredBlocks.contains(material)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BlockData blockData = block.getBlockData();
|
|
||||||
if (blockData instanceof Powerable
|
|
||||||
|| blockData instanceof TechnicalPiston
|
|
||||||
|| blockData instanceof AnaloguePowerable
|
|
||||||
|| blockData instanceof Rail) {
|
|
||||||
currentBlocks++;
|
currentBlocks++;
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (material) {
|
|
||||||
case NOTE_BLOCK:
|
|
||||||
case REDSTONE_BLOCK:
|
|
||||||
case REDSTONE:
|
|
||||||
case HOPPER:
|
|
||||||
case REDSTONE_LAMP:
|
|
||||||
case REDSTONE_TORCH:
|
|
||||||
case REDSTONE_WALL_TORCH:
|
|
||||||
currentBlocks++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return currentBlocks;
|
return currentBlocks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean validBlock(Block block) {
|
||||||
|
Material material = block.getType();
|
||||||
|
if (ignoredBlocks.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