added scores and translations
This commit is contained in:
@@ -2,7 +2,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.NoScore;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import io.github.togar2.pvp.events.FinalAttackEvent;
|
||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
@@ -16,10 +16,9 @@ import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BlockBattle extends StatelessGame {
|
||||
private final Team teamBlue = new Team(new Pos(0,101,20).add(0.5), Team.Color.BLUE);
|
||||
@@ -28,7 +27,7 @@ public class BlockBattle extends StatelessGame {
|
||||
private final Map<Player, Team> teams = new WeakHashMap<>();
|
||||
|
||||
public BlockBattle() {
|
||||
super(Dimension.THE_END.key, "Block Battle", new NoScore());
|
||||
super(Dimension.THE_END.key, "Block Battle", new FirstWinsScore());
|
||||
|
||||
this.eventNode().addChild(
|
||||
CombatFeatures.empty()
|
||||
@@ -55,10 +54,7 @@ public class BlockBattle extends StatelessGame {
|
||||
Pos posGoldBlock = new Pos(playerBlockPlaceEvent.getBlockPosition()).sub(0, 1, 0);
|
||||
Block goldBlock = playerBlockPlaceEvent.getInstance().getBlock(posGoldBlock);
|
||||
|
||||
if(goldBlock == Block.GOLD_BLOCK)
|
||||
playerBlockPlaceEvent.setCancelled(false);
|
||||
else
|
||||
playerBlockPlaceEvent.setCancelled(true);
|
||||
playerBlockPlaceEvent.setCancelled(goldBlock != Block.GOLD_BLOCK);
|
||||
|
||||
playerBlockPlaceEvent.getInstance().scheduler().scheduleNextTick(() -> {
|
||||
Pos middle = new Pos(0, 101, 0);
|
||||
@@ -87,15 +83,15 @@ public class BlockBattle extends StatelessGame {
|
||||
break;
|
||||
}
|
||||
|
||||
if(validBlue) {
|
||||
super.stop();
|
||||
System.out.println("blau");
|
||||
}
|
||||
if(!validBlue && !validRed) return;
|
||||
var winningTeam = validBlue ? Team.Color.BLUE : Team.Color.RED;
|
||||
var winningPlayers = this.teams.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().getColor().equals(winningTeam))
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if(validRed) {
|
||||
super.stop();
|
||||
System.out.println("rot");
|
||||
}
|
||||
this.getScore().insertMultiple(winningPlayers);
|
||||
super.stop();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -111,8 +107,8 @@ public class BlockBattle extends StatelessGame {
|
||||
Block.RED_CONCRETE,
|
||||
Block.RED_STAINED_GLASS
|
||||
};
|
||||
for(int i = 0; i < blockCantBreakList.length; i++) {
|
||||
if(playerBlockBreakEvent.getBlock().equals(blockCantBreakList[i]))
|
||||
for(Block block : blockCantBreakList) {
|
||||
if(playerBlockBreakEvent.getBlock().equals(block))
|
||||
playerBlockBreakEvent.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -198,7 +194,8 @@ public class BlockBattle extends StatelessGame {
|
||||
}
|
||||
|
||||
private void setTeams() {
|
||||
List<Player> players = this.getPlayers().stream().toList();
|
||||
List<Player> players = new ArrayList<>(this.getPlayers());
|
||||
Collections.shuffle(players);
|
||||
int halfPlayers = players.size()/2;
|
||||
players.subList(0, halfPlayers).forEach(player -> this.teams.put(player, this.teamBlue));
|
||||
players.subList(halfPlayers, players.size()).forEach(player -> this.teams.put(player, this.teamRed));
|
||||
|
||||
@@ -30,6 +30,11 @@ public abstract class Score {
|
||||
throw new NotImplementedException("This Score type is not able to process points");
|
||||
}
|
||||
|
||||
public void insertMultiple(Set<Player> p) {
|
||||
p.forEach(player -> this.insertResultProcessor(player, () -> {}));
|
||||
this.insertResultImplementation(p);
|
||||
}
|
||||
|
||||
public void insertResult(Player p) {
|
||||
this.insertResultProcessor(p, () -> this.insertResultImplementation(Set.of(p)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user