This commit is contained in:
LunarAkai 2024-03-23 23:20:33 +01:00
commit a8cd7272f5
6 changed files with 98 additions and 42 deletions

View file

@ -121,8 +121,6 @@ public class MinecleanerArena {
BlockData block0 = Material.NETHER_BRICKS.createBlockData(); BlockData block0 = Material.NETHER_BRICKS.createBlockData();
BlockData block1 = Material.BRICKS.createBlockData(); BlockData block1 = Material.BRICKS.createBlockData();
// todo: larger grids
for (int fx = -1 - widthIndex; fx < 2 ; fx++) { for (int fx = -1 - widthIndex; fx < 2 ; fx++) {
for (int fy = -1; fy < 2 + widthIndex; fy++) { for (int fy = -1; fy < 2 + widthIndex; fy++) {
@ -133,7 +131,6 @@ public class MinecleanerArena {
} }
} }
/* /*
* Bei Größen WidthIndex 1 + 2 -> Mitte = ein Block nach Links unten versetzt * Bei Größen WidthIndex 1 + 2 -> Mitte = ein Block nach Links unten versetzt
*/ */
@ -171,8 +168,6 @@ public class MinecleanerArena {
eastWestGapFixZ = 0.5725; eastWestGapFixZ = 0.5725;
} }
float rotation = rotation0; float rotation = rotation0;
int d0x = orientation.getModX(); int d0x = orientation.getModX();
@ -181,19 +176,17 @@ public class MinecleanerArena {
int d1z = d0x; int d1z = d0x;
Location loc = location.clone(); Location loc = location.clone();
// todo: felder bisschen dichter an die wand
for(int fx = 0; fx < size; fx++) { for(int fx = 0; fx < size; fx++) {
final int fxf = fx; final int fxf = fx;
for(int fz = 0; fz < size; fz++) { for(int fz = 0; fz < size; fz++) {
final int fzf = fz; final int fzf = fz;
// Todo not correctly alligned at different orientations (other than NORTH)
//loc.set(location.getX() + 0.11 - (d1x * fz) / 3.0 + d0x * 0.501 + d1x * 1.847, location.getY() - 0.9725 + fxf / 3.0, location.getZ() + 0.45 - (d1z * fz) / 3.0 + d0z * 0.501 + d1z * 1.847);
loc.set(location.getX() - 0.016 + eastWestGapFixX + southGapFixX - (d1x * fz) / 3.0 + d0x * 0.55 + d1x * 1.847, loc.set(location.getX() - 0.016 + eastWestGapFixX + southGapFixX - (d1x * fz) / 3.0 + d0x * 0.55 + d1x * 1.847,
location.getY() - 0.8225 + fxf / 3.0, location.getY() - 0.8225 + fxf / 3.0,
location.getZ() + 0.45 + eastWestGapFixZ + southGapFixZ - (d1z * fz) / 3.0 + d0z * 0.55 + d1z * 1.847); location.getZ() + 0.45 + eastWestGapFixZ + southGapFixZ - (d1z * fz) / 3.0 + d0z * 0.55 + d1z * 1.847);
// Todo: Z-Fighting on Unknown Tile Heads && Flags(Front)
// Todo: Z-Fighting on the Sides for all Tiles
Display blockDisplay = world.spawn(loc, ItemDisplay.class, blockdisplay -> { Display blockDisplay = world.spawn(loc, ItemDisplay.class, blockdisplay -> {
Transformation transformation = blockdisplay.getTransformation(); Transformation transformation = blockdisplay.getTransformation();
Transformation newTransform; Transformation newTransform;
@ -230,6 +223,7 @@ public class MinecleanerArena {
// textdisplay.setTransformation(newTransformation); // textdisplay.setTransformation(newTransformation);
// textdisplay.setRotation(rotation, 0); // textdisplay.setRotation(rotation, 0);
// billboardmode = fixed
// textdisplay.setVisibleByDefault(true); // textdisplay.setVisibleByDefault(true);
// textdisplay.setDisplayHeight(3); // textdisplay.setDisplayHeight(3);
// textdisplay.setDisplayWidth(9); // textdisplay.setDisplayWidth(9);
@ -318,29 +312,20 @@ public class MinecleanerArena {
if(currentMinecleanerGame != null && !currentMinecleanerGame.gameover) { if(currentMinecleanerGame != null && !currentMinecleanerGame.gameover) {
Cell cell = currentMinecleanerGame.getCell(x, y); Cell cell = currentMinecleanerGame.getCell(x, y);
if(!cell.isRevealed()) { if(!cell.isRevealed()) {
Player player = this.currentPlayer; Player player = this.currentPlayer;
currentMinecleanerGame.flag(x, y); currentMinecleanerGame.flag(x, y);
if(currentMinecleanerGame.gameover) { if(currentMinecleanerGame.gameover) {
plugin.getManager().handleGameover(player, this, true); plugin.getManager().handleGameover(player, this, true);
} }
//plugin.getLogger().log(Level.SEVERE, " Is Flagged (before first if): " + cell.isFlagged());
if(cell.isFlagged() == true) { if(cell.isFlagged() == true) {
//plugin.getLogger().log(Level.SEVERE, "Flagged Cell: [" + cell.position.x + "," + cell.position.y + "]");
flagsPlaced = flagsPlaced + 1; flagsPlaced = flagsPlaced + 1;
sendActionBarMessage(player); sendActionBarMessage(player);
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_FLAG); setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_FLAG);
} }
//plugin.getLogger().log(Level.SEVERE, " Is Flagged (before second if): " + cell.isFlagged());
if(cell.isFlagged() == false) { if(cell.isFlagged() == false) {
//plugin.getLogger().log(Level.SEVERE, "Unflagged Cell: [" + cell.position.x + "," + cell.position.y + "]");
flagsPlaced = flagsPlaced - 1; flagsPlaced = flagsPlaced - 1;
sendActionBarMessage(player); sendActionBarMessage(player);
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN); setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN);
@ -353,8 +338,7 @@ public class MinecleanerArena {
public void revealCell(int x, int y) { public void revealCell(int x, int y) {
if(currentMinecleanerGame != null && !currentMinecleanerGame.gameover) { if(currentMinecleanerGame != null && !currentMinecleanerGame.gameover) {
Cell cell = currentMinecleanerGame.getCell(x, y); Cell cell = currentMinecleanerGame.getCell(x, y);
if(!cell.isFlagged()) { if(!cell.isFlagged()) {
//int id = x + y * 9;
Player player = this.currentPlayer; Player player = this.currentPlayer;
currentMinecleanerGame.reveal(x, y); currentMinecleanerGame.reveal(x, y);
@ -450,7 +434,6 @@ public class MinecleanerArena {
} else { } else {
setDiplayBlock(x, y, MinecleanerHeads.TNT); setDiplayBlock(x, y, MinecleanerHeads.TNT);
} }
break; break;
} }
default: { default: {
@ -470,13 +453,12 @@ public class MinecleanerArena {
Location loc = location.clone(); Location loc = location.clone();
for(int fx = -2 - widthIndex; fx < 1 ; fx++) { for(int fx = -1 - widthIndex; fx < 2; fx++) {
for(int fy = -1; fy < 2 + widthIndex; fy++) { for(int fy = -1; fy < 2 + widthIndex; fy++) {
loc.set(location.getX() + d1x + fx, location.getY() + fy, location.getZ() + d1z * fx); loc.set(location.getX() + d1x * fx, location.getY() + fy, location.getZ() + d1z * fx);
blocks.add(loc.clone()); blocks.add(loc.clone());
} }
} }
return blocks; return blocks;
} }
@ -486,6 +468,15 @@ public class MinecleanerArena {
} }
player.getLocation(tempLoc); player.getLocation(tempLoc);
double dist = tempLoc.distanceSquared(centerLocation); double dist = tempLoc.distanceSquared(centerLocation);
// todo: larger for bigger boards
switch (widthIndex) {
case 0:
return dist > 64.0;
case 1:
return dist > 96.0;
case 2:
return dist > 128.0;
}
return dist > 64.0; return dist > 64.0;
} }

View file

@ -31,6 +31,7 @@ public class MinecleanerListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent e) { public void onPlayerInteract(PlayerInteractEvent e) {
// wenn (e.getHand != MainHand) return;
if((e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK)) { if((e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
Block block = e.getClickedBlock(); Block block = e.getClickedBlock();
MinecleanerArena arena = plugin.getArenaList().getPlayerArena(e.getPlayer()); MinecleanerArena arena = plugin.getArenaList().getPlayerArena(e.getPlayer());

View file

@ -1,7 +1,9 @@
package de.lunarakai.minecleaner; package de.lunarakai.minecleaner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -23,20 +25,31 @@ import de.iani.cubesidestats.api.StatisticsQueryKey;
import de.iani.cubesidestats.api.TimeFrame; import de.iani.cubesidestats.api.TimeFrame;
import de.iani.cubesideutils.bukkit.items.ItemStacks; import de.iani.cubesideutils.bukkit.items.ItemStacks;
import de.iani.playerUUIDCache.CachedPlayer; import de.iani.playerUUIDCache.CachedPlayer;
import de.lunarakai.minecleaner.game.BoardSize;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
public class MinecleanerManager { public class MinecleanerManager {
private final MinecleanerPlugin plugin; private final MinecleanerPlugin plugin;
private final Inventory confirmPlayingInventory; private final Inventory confirmPlayingInventory;
private final HashMap<Integer, String> sizes;
// Statistics // Statistics
private final StatisticKey statisticsGamesTotal; private final StatisticKey statisticsGamesTotal;
private final StatisticKey statisticsPointsAcquired; private final StatisticKey statisticsPointsAcquired;
// <BoardSize, StatisticKey>
private final HashMap<Integer, StatisticKey> statisticsGames;
private int prevTick = 0; private int prevTick = 0;
public MinecleanerManager(MinecleanerPlugin plugin) { public MinecleanerManager(MinecleanerPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.sizes = new HashMap<>();
this.sizes.put(0, "klein");
this.sizes.put(1, "mittel");
this.sizes.put(2, "groß");
// Deprecated // Deprecated
this.confirmPlayingInventory = plugin.getServer().createInventory(null, InventoryType.HOPPER, "Minecleaner starten?"); this.confirmPlayingInventory = plugin.getServer().createInventory(null, InventoryType.HOPPER, "Minecleaner starten?");
@ -54,6 +67,18 @@ public class MinecleanerManager {
statisticsPointsAcquired.setIsMonthlyStats(true); statisticsPointsAcquired.setIsMonthlyStats(true);
statisticsPointsAcquired.setDisplayName("Punkte erspielt"); statisticsPointsAcquired.setDisplayName("Punkte erspielt");
statisticsGames = new HashMap<>();
for(Entry<Integer, String> e : this.sizes.entrySet()) {
String sizeDisplay = e.getValue();
StatisticKey s = plugin.getCubesideStatistics().getStatisticKey("minecleaner.games.boardsize." + e.getKey());
s.setIsMonthlyStats(true);
s.setDisplayName("Runden gespielt auf Spielfeldgröße " + sizeDisplay + " gespielt");
statisticsGames.put(e.getKey(), s);
}
}
public HashMap<Integer, String> getSizes() {
return sizes;
} }
public void joinArena(Player player, MinecleanerArena arena) { public void joinArena(Player player, MinecleanerArena arena) {
@ -88,6 +113,7 @@ public class MinecleanerManager {
public void handleGameover(Player player, MinecleanerArena arena, boolean isSuccessfullyCleared) { public void handleGameover(Player player, MinecleanerArena arena, boolean isSuccessfullyCleared) {
World world = player.getWorld(); World world = player.getWorld();
if(!isSuccessfullyCleared) { if(!isSuccessfullyCleared) {
// angefangene Spiele zählen
world.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.5f, 0.5f); world.playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.5f, 0.5f);
player.sendMessage(ChatColor.YELLOW + "Game Over! Du konntest das Feld nicht erfolgreich lösen!"); player.sendMessage(ChatColor.YELLOW + "Game Over! Du konntest das Feld nicht erfolgreich lösen!");
arena.showMines(); arena.showMines();
@ -136,7 +162,6 @@ public class MinecleanerManager {
} else { } else {
leaveArena(player, false); leaveArena(player, false);
} }
leaveArena(player, false);
}, 100L); }, 100L);
} }
@ -184,6 +209,24 @@ public class MinecleanerManager {
PlayerStatisticsQueryKey kMatchesPlayedMonth; PlayerStatisticsQueryKey kMatchesPlayedMonth;
keys.add(kMatchesPlayedMonth = new PlayerStatisticsQueryKey(pStatistics, statisticsGamesTotal, QueryType.SCORE, TimeFrame.MONTH)); keys.add(kMatchesPlayedMonth = new PlayerStatisticsQueryKey(pStatistics, statisticsGamesTotal, QueryType.SCORE, TimeFrame.MONTH));
HashMap<Integer, PlayerStatisticsQueryKey> kgamesPlayedSize = new HashMap<>();
HashMap<Integer, PlayerStatisticsQueryKey> kgamesPlayedSizeMonth = new HashMap<>();
for (int i = 0; i < BoardSize.boardSizes.length; i++) {
PlayerStatisticsQueryKey qk;
StatisticKey statisticKeyGames = statisticsGames.get(i);
keys.add(qk = new PlayerStatisticsQueryKey(pStatistics, statisticKeyGames, QueryType.SCORE));
kgamesPlayedSize.put(i, qk);
keys.add(qk = new PlayerStatisticsQueryKey(pStatistics, statisticKeyGames, QueryType.SCORE, TimeFrame.MONTH));
kgamesPlayedSizeMonth.put(i, qk);
// todo:
// PlayerTime
}
PlayerStatisticsQueryKey kPointsAcquired; PlayerStatisticsQueryKey kPointsAcquired;
keys.add(kPointsAcquired = new PlayerStatisticsQueryKey(pStatistics, statisticsPointsAcquired, QueryType.SCORE)); keys.add(kPointsAcquired = new PlayerStatisticsQueryKey(pStatistics, statisticsPointsAcquired, QueryType.SCORE));
PlayerStatisticsQueryKey kPointsAcquiredMonth; PlayerStatisticsQueryKey kPointsAcquiredMonth;
@ -195,7 +238,16 @@ public class MinecleanerManager {
int pointsAcquiredTotal = c.getOrDefault(kPointsAcquired, 0); int pointsAcquiredTotal = c.getOrDefault(kPointsAcquired, 0);
int pointsAcquiredMonth = c.getOrDefault(kPointsAcquiredMonth, 0); int pointsAcquiredMonth = c.getOrDefault(kPointsAcquiredMonth, 0);
HashMap<Integer, Integer> sizeGames = new HashMap<>();
HashMap<Integer, Integer> sizeGamesMonth = new HashMap<>();
for(int i = 0; i < BoardSize.boardSizes.length; i++) {
sizeGames.put(i, c.getOrDefault(kgamesPlayedSize.get(i), 0));
sizeGames.put(i, c.getOrDefault(kgamesPlayedSizeMonth.get(i), 0));
}
callback.accept(new PlayerStatisticsData(player.getUniqueId(), player.getName(), matchesPlayed, matchesPlayedMonth, callback.accept(new PlayerStatisticsData(player.getUniqueId(), player.getName(), matchesPlayed, matchesPlayedMonth,
sizeGames, sizeGamesMonth,
pointsAcquiredTotal, pointsAcquiredMonth)); pointsAcquiredTotal, pointsAcquiredMonth));
}); });
} }

View file

@ -1,5 +1,6 @@
package de.lunarakai.minecleaner; package de.lunarakai.minecleaner;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class PlayerStatisticsData { public class PlayerStatisticsData {
@ -7,12 +8,13 @@ public class PlayerStatisticsData {
private String playerName; private String playerName;
private int gamesPlayed; private int gamesPlayed;
private int gamesPlayedThisMonth; private int gamesPlayedThisMonth;
// private HashMap<Integer, Integer> gamesPlayedSize; private HashMap<Integer, Integer> gamesPlayedSize;
// private HashMap<Integer, Integer> gamesPlayedSizeThisMonth; private HashMap<Integer, Integer> gamesPlayedSizeThisMonth;
private int pointsAcquiredTotal; private int pointsAcquiredTotal;
private int pointsAcquiredMonth; private int pointsAcquiredMonth;
public PlayerStatisticsData(UUID playerUUID, String playerName, int gamesPlayed, int gamesPlayedThisMonth, public PlayerStatisticsData(UUID playerUUID, String playerName, int gamesPlayed, int gamesPlayedThisMonth,
HashMap<Integer, Integer> gamesPlayedSize, HashMap<Integer, Integer> gamesPlayedSizeThisMonth,
int pointsAcquiredTotal, int pointsAcquiredMonth) { int pointsAcquiredTotal, int pointsAcquiredMonth) {
this.playerUUID = playerUUID; this.playerUUID = playerUUID;
this.playerName = playerName; this.playerName = playerName;
@ -20,8 +22,8 @@ public class PlayerStatisticsData {
this.gamesPlayed = gamesPlayed; this.gamesPlayed = gamesPlayed;
this.gamesPlayedThisMonth = gamesPlayedThisMonth; this.gamesPlayedThisMonth = gamesPlayedThisMonth;
// this.gamesPlayedSize = gamesPlayedSize; this.gamesPlayedSize = gamesPlayedSize;
// this.gamesPlayedSizeThisMonth = gamesPlayedSizeThisMonth; this.gamesPlayedSizeThisMonth = gamesPlayedSizeThisMonth;
this.pointsAcquiredTotal = pointsAcquiredTotal; this.pointsAcquiredTotal = pointsAcquiredTotal;
this.pointsAcquiredMonth = pointsAcquiredMonth; this.pointsAcquiredMonth = pointsAcquiredMonth;
@ -43,15 +45,15 @@ public class PlayerStatisticsData {
return gamesPlayedThisMonth; return gamesPlayedThisMonth;
} }
// public int getGamesPlayedSize(Integer widthIndex) { public int getGamesPlayedSize(Integer widthIndex) {
// Integer value = gamesPlayedSize.get(widthIndex); Integer value = gamesPlayedSize.get(widthIndex);
// return value == null ? 0 : value; return value == null ? 0 : value;
// } }
// public int getGamesPlayedSizeThisMonth(Integer widthIndex) { public int getGamesPlayedSizeThisMonth(Integer widthIndex) {
// Integer value = gamesPlayedSizeThisMonth.get(widthIndex); Integer value = gamesPlayedSizeThisMonth.get(widthIndex);
// return value == null ? 0 : value; return value == null ? 0 : value;
// } }
public int getPointsAcquiredTotal() { public int getPointsAcquiredTotal() {
return pointsAcquiredTotal; return pointsAcquiredTotal;

View file

@ -111,9 +111,9 @@ public class CreateCommand extends SubCommand {
sender.sendMessage(ChatColor.DARK_RED + "An dieser Stelle befindet sich bereits eine Arena."); sender.sendMessage(ChatColor.DARK_RED + "An dieser Stelle befindet sich bereits eine Arena.");
return true; return true;
} }
newArena.generateBlockDisplays(); // Todo newArena.generateBlockDisplays();
if(!noblocks) { if(!noblocks) {
newArena.generateBackgroundBlocks(); // Todo; newArena.generateBackgroundBlocks();
} }
plugin.getArenaList().addArena(newArena); plugin.getArenaList().addArena(newArena);
sender.sendMessage(ChatColor.GREEN + "Die Arena wurde erfolgreich angelegt."); sender.sendMessage(ChatColor.GREEN + "Die Arena wurde erfolgreich angelegt.");

View file

@ -1,9 +1,12 @@
package de.lunarakai.minecleaner.commands; package de.lunarakai.minecleaner.commands;
import java.util.Map.Entry;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import de.iani.cubesideutils.StringUtil;
import de.iani.cubesideutils.bukkit.commands.SubCommand; import de.iani.cubesideutils.bukkit.commands.SubCommand;
import de.iani.cubesideutils.bukkit.commands.exceptions.DisallowsCommandBlockException; import de.iani.cubesideutils.bukkit.commands.exceptions.DisallowsCommandBlockException;
import de.iani.cubesideutils.bukkit.commands.exceptions.IllegalSyntaxException; import de.iani.cubesideutils.bukkit.commands.exceptions.IllegalSyntaxException;
@ -13,7 +16,6 @@ import de.iani.cubesideutils.bukkit.commands.exceptions.RequiresPlayerException;
import de.iani.cubesideutils.commands.ArgsParser; import de.iani.cubesideutils.commands.ArgsParser;
import de.lunarakai.minecleaner.MinecleanerPlugin; import de.lunarakai.minecleaner.MinecleanerPlugin;
import de.lunarakai.minecleaner.PlayerStatisticsData; import de.lunarakai.minecleaner.PlayerStatisticsData;
import net.md_5.bungee.api.ChatColor;
public class StatsCommand extends SubCommand { public class StatsCommand extends SubCommand {
private final MinecleanerPlugin plugin; private final MinecleanerPlugin plugin;
@ -53,8 +55,16 @@ public class StatsCommand extends SubCommand {
} else { } else {
sender.sendMessage(ChatColor.GREEN + "Minecleaner-Statitik von " + data.getPlayerName() + ":"); sender.sendMessage(ChatColor.GREEN + "Minecleaner-Statitik von " + data.getPlayerName() + ":");
} }
sender.sendMessage(ChatColor.BLUE + " Runden gespielt: " + ChatColor.GREEN + data.getGamesPlayed() + " (Dieser Monat: " + data.getGamesPlayedThisMonth() + ")");
sender.sendMessage(ChatColor.BLUE + " Punkte erspielt: " + ChatColor.GREEN + data.getPointsAcquiredTotal() + " (Dieser Monat: " + data.getPointsAquiredMonth() + ")"); sender.sendMessage(ChatColor.BLUE + " Punkte erspielt: " + ChatColor.GREEN + data.getPointsAcquiredTotal() + " (Dieser Monat: " + data.getPointsAquiredMonth() + ")");
sender.sendMessage(ChatColor.BLUE + " Runden gespielt: " + ChatColor.GREEN + data.getGamesPlayed() + " (Dieser Monat: " + data.getGamesPlayedThisMonth() + ")");
for(Entry<Integer, String> e : plugin.getManager().getSizes().entrySet()) {
int totalSize = data.getGamesPlayedSize(e.getKey());
if(totalSize > 0) {
String sizeName = StringUtil.capitalizeFirstLetter(e.getValue(), false);
sender.sendMessage(ChatColor.GREEN + " " + sizeName + ":");
sender.sendMessage(ChatColor.BLUE + " Runden gespielt: " + ChatColor.GREEN + totalSize + " (Dieser Monat: " + data.getGamesPlayedSizeThisMonth(e.getKey()) + ")");
}
}
} }
}; };