RedstoneWincondition #274
@ -19,7 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
|
public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
|
||||||
|
|
||||||
@ -32,4 +39,37 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract double getPercent(FightTeam team);
|
abstract double getPercent(FightTeam team);
|
||||||
|
|
||||||
|
public class TeamPercent {
|
||||||
|
public final FightTeam team;
|
||||||
|
|
||||||
|
public int totalBlocks;
|
||||||
|
public int currentBlocks;
|
||||||
|
|
||||||
|
protected TeamPercent(FightTeam team) {
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lose() {
|
||||||
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||||
|
win(Fight.getOpposite(team));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class StateDependentTeamPercent extends StateDependent {
|
||||||
|
public final FightTeam team;
|
||||||
|
|
||||||
|
public int totalBlocks;
|
||||||
|
public int currentBlocks;
|
||||||
|
|
||||||
|
protected StateDependentTeamPercent(FightTeam team, Winconditions winconditions) {
|
||||||
|
super(winconditions, FightState.Running);
|
||||||
|
this.team = team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lose() {
|
||||||
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||||
|
win(Fight.getOpposite(team));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,10 @@
|
|||||||
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.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
@ -47,7 +45,7 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
|||||||
public void enable() {
|
public void enable() {
|
||||||
super.enable();
|
super.enable();
|
||||||
teamMap.forEach((team, percent) -> {
|
teamMap.forEach((team, percent) -> {
|
||||||
percent.destroyedBlocks = 0;
|
percent.currentBlocks = 0;
|
||||||
percent.percent = 0;
|
percent.percent = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -63,26 +61,18 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
|||||||
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDisplay(FightTeam team) {
|
|
||||||
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getPercent(FightTeam team) {
|
public double getPercent(FightTeam team) {
|
||||||
return teamMap.get(team).percent;
|
return teamMap.get(team).percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TeamPercent {
|
private class TeamPercent extends PercentWincondition.TeamPercent {
|
||||||
|
|
||||||
private final FightTeam team;
|
|
||||||
private final int volume;
|
|
||||||
private double percent;
|
private double percent;
|
||||||
private int destroyedBlocks;
|
|
||||||
|
|
||||||
private TeamPercent(FightTeam team) {
|
private TeamPercent(FightTeam team) {
|
||||||
this.team = team;
|
super(team);
|
||||||
this.volume = team.getSchemRegion().volume();
|
totalBlocks = team.getSchemRegion().volume();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void check(EntityExplodeEvent event) {
|
private void check(EntityExplodeEvent event) {
|
||||||
@ -90,11 +80,10 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyedBlocks += event.blockList().size();
|
currentBlocks += event.blockList().size();
|
||||||
percent = (double)destroyedBlocks * 100 / volume;
|
percent = (double) currentBlocks * 100 / totalBlocks;
|
||||||
if (percent >= Config.PercentWin) {
|
if (percent >= Config.PercentWin) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
lose();
|
||||||
win(Fight.getOpposite(team));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@ 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.FightTeam;
|
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.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
@ -54,28 +52,19 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
|||||||
return teamMap.get(team).getPercent();
|
return teamMap.get(team).getPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public class TeamPercent extends StateDependentTeamPercent {
|
||||||
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 BukkitTask task;
|
||||||
private int currentBlocks;
|
|
||||||
|
|
||||||
public TeamPercent(FightTeam team) {
|
public TeamPercent(FightTeam team) {
|
||||||
super(Winconditions.RELATIVE_PERCENT, FightState.Running);
|
super(team, Winconditions.RELATIVE_PERCENT);
|
||||||
this.team = team;
|
currentBlocks = 1;
|
||||||
this.currentBlocks = 1;
|
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
blockCount = currentBlocks();
|
totalBlocks = currentBlocks();
|
||||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400);
|
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,19 +80,19 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (getPercent() >= Config.PercentWin) {
|
if (getPercent() >= Config.PercentWin) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBlockCount() {
|
public int getBlockCount() {
|
||||||
return blockCount;
|
return totalBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int currentBlocks() {
|
private int currentBlocks() {
|
||||||
@ -113,8 +102,9 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
|||||||
|
|
||||||
currentBlocks = 0;
|
currentBlocks = 0;
|
||||||
team.getSchemRegion().forEach((x, y, z) -> {
|
team.getSchemRegion().forEach((x, y, z) -> {
|
||||||
if(!Config.Blocks.contains(world.getBlockAt(x,y,z).getType()))
|
if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
||||||
currentBlocks++;
|
currentBlocks++;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return currentBlocks;
|
return currentBlocks;
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,6 @@ public class WinconditionRelativeRedstonePercent extends PercentWincondition imp
|
|||||||
return teamMap.get(team).getPercent();
|
return teamMap.get(team).getPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDisplay(FightTeam team) {
|
|
||||||
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
FightPlayer fightPlayer = Fight.getFightPlayer(event.getPlayer());
|
FightPlayer fightPlayer = Fight.getFightPlayer(event.getPlayer());
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren