flags placed & total mines are shown above the field now + a little bit of cleaning up
This commit is contained in:
parent
fbd5f81e13
commit
625af3dfcb
4 changed files with 307 additions and 203 deletions
117
.gitignore
vendored
117
.gitignore
vendored
|
|
@ -1,5 +1,116 @@
|
|||
# Project exclude paths
|
||||
/target/
|
||||
/.vscode
|
||||
.vscode/
|
||||
|
||||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
Minecleaner.iml
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
target/
|
||||
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.flattened-pom.xml
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
|
|
|
|||
2
pom.xml
2
pom.xml
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>de.lunarakai</groupId>
|
||||
<artifactId>Minecleaner</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<version>1.0.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Minecleaner</name>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
|
@ -15,6 +16,7 @@ import org.bukkit.entity.Display.Brightness;
|
|||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TextDisplay;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Transformation;
|
||||
import org.joml.Vector2i;
|
||||
|
|
@ -37,49 +39,20 @@ public class MinecleanerArena {
|
|||
private final BlockFace orientation;
|
||||
private ArenaStatus arenaStatus = ArenaStatus.INACTIVE;
|
||||
private UUID[] blockDisplays;
|
||||
// private UUID[] textDisplays;
|
||||
private TextDisplay textDisplay;
|
||||
private boolean hasMadeFirstClick = false;
|
||||
|
||||
private int flagsPlaced = 0;
|
||||
|
||||
private Player currentPlayer;
|
||||
private long currentGameStartTime;
|
||||
private Game currentMinecleanerGame;
|
||||
|
||||
private final Location tempLoc = new Location(null, 0, 0, 0);
|
||||
|
||||
public static final MinecleanerHeads[] MINECLEANER_HEADS = {
|
||||
MinecleanerHeads.MINESWEEPER_TILE_0,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_1,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_2,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_3,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_4,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_5,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_6,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_7,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_8,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_FLAG,
|
||||
MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN,
|
||||
MinecleanerHeads.TNT,
|
||||
MinecleanerHeads.EXPLODED,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_M,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_I,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_N,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_E,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_S,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_W,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_P,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_R,
|
||||
MinecleanerHeads.MINESWEEPER_LETTER_MINUS,
|
||||
};
|
||||
|
||||
public MinecleanerArena(MinecleanerPlugin plugin, ConfigurationSection arenaSection) {
|
||||
this.plugin = plugin;
|
||||
this.name = Preconditions.checkNotNull(arenaSection.getString("name"));
|
||||
this.location = Preconditions.checkNotNull(arenaSection.getLocation("location"));
|
||||
this.widthIndex = Preconditions.checkNotNull(arenaSection.getInt("fieldwidth"));
|
||||
this.blockDisplays = new UUID[BoardSize.boardSizesWidth[widthIndex] * BoardSize.boardSizesHeight[widthIndex]];
|
||||
// this.textDisplays = new UUID[1];
|
||||
|
||||
BlockFace orientation = BlockFace.NORTH;
|
||||
try {
|
||||
|
|
@ -98,14 +71,6 @@ public class MinecleanerArena {
|
|||
blockDisplays[i] = UUID.fromString(blockDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
// List<String> textList = arenaSection.getStringList("textdisplay");
|
||||
// for(int i = 0; i < textList.size(); i++) {
|
||||
// String textString = list.get(i);
|
||||
// if(textString != null) {
|
||||
// textDisplays[0] = UUID.fromString(textString);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public MinecleanerArena(MinecleanerPlugin plugin, String name, Location location, int widthIndex, BlockFace orientation) {
|
||||
|
|
@ -114,7 +79,6 @@ public class MinecleanerArena {
|
|||
this.location = Preconditions.checkNotNull(location, "location");
|
||||
this.widthIndex = Preconditions.checkNotNull(widthIndex, ("fieldwidth"));
|
||||
this.blockDisplays = new UUID[BoardSize.boardSizesWidth[widthIndex] * BoardSize.boardSizesHeight[widthIndex]];
|
||||
//this.textDisplays = new UUID[1];
|
||||
|
||||
Preconditions.checkArgument(Math.abs(orientation.getModX()) + Math.abs(orientation.getModZ()) == 1, "no cardinal direction");
|
||||
this.orientation = orientation;
|
||||
|
|
@ -146,7 +110,7 @@ public class MinecleanerArena {
|
|||
}
|
||||
|
||||
/*
|
||||
* Bei Größen WidthIndex 1 + 2 -> Mitte = ein Block nach Links unten versetzt
|
||||
* "Mitte" = Block (1,1)
|
||||
*/
|
||||
public void generateBlockDisplays() {
|
||||
int sizeWidth = BoardSize.boardSizesWidth[widthIndex];
|
||||
|
|
@ -169,20 +133,19 @@ public class MinecleanerArena {
|
|||
|
||||
double southGapFixX = 0.0;
|
||||
double southGapFixZ = 0.0;
|
||||
|
||||
if (orientation == BlockFace.EAST) {
|
||||
rotation0 = 90;
|
||||
eastWestGapFixX = 0.5;
|
||||
eastWestGapFixZ = -0.55;
|
||||
} else if (orientation == BlockFace.SOUTH) {
|
||||
rotation0 = 180;
|
||||
southGapFixX = 1.02;
|
||||
southGapFixZ = -0.05;
|
||||
} else if (orientation == BlockFace.WEST) {
|
||||
rotation0 = 270;
|
||||
eastWestGapFixX = 0.55;
|
||||
eastWestGapFixZ = 0.5;
|
||||
}
|
||||
|
||||
rotation0 = getRotationYaw();
|
||||
float rotation = rotation0;
|
||||
|
||||
int d0x = orientation.getModX();
|
||||
|
|
@ -218,39 +181,11 @@ public class MinecleanerArena {
|
|||
blockdisplay.setItemStack(MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN.getHead());
|
||||
});
|
||||
|
||||
|
||||
if (blockDisplay != null) {
|
||||
blockDisplays[fxf * sizeWidth + fzf] = blockDisplay.getUniqueId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Location textLocation = location.clone();
|
||||
// TextDisplay textDisplay = world.spawn(textLocation.add(-1, 2 + widthIndex, -0.25), TextDisplay.class, textdisplay -> {
|
||||
// Transformation transformation = textdisplay.getTransformation();
|
||||
// Transformation newTransformation;
|
||||
// newTransformation = new Transformation(
|
||||
// transformation.getTranslation(),
|
||||
// transformation.getLeftRotation(),
|
||||
// transformation.getTranslation(),
|
||||
// transformation.getRightRotation());
|
||||
|
||||
// textdisplay.setTransformation(newTransformation);
|
||||
// textdisplay.setRotation(rotation, 0);
|
||||
|
||||
// billboardmode = fixed
|
||||
// textdisplay.setVisibleByDefault(true);
|
||||
// textdisplay.setDisplayHeight(3);
|
||||
// textdisplay.setDisplayWidth(9);
|
||||
// textdisplay.setText("Minecleaner");
|
||||
// });
|
||||
|
||||
// if(textDisplay != null) {
|
||||
// textDisplays[0] = textDisplay.getUniqueId();
|
||||
// }
|
||||
|
||||
// show Displays
|
||||
|
||||
showStartHeads();
|
||||
}
|
||||
|
||||
|
|
@ -264,11 +199,6 @@ public class MinecleanerArena {
|
|||
blockDisplays.add(uuid == null ? null : uuid.toString());
|
||||
}
|
||||
arenaSection.set("blockdisplays", blockDisplays);
|
||||
// List<String> textd = new ArrayList<>();
|
||||
// for(UUID uuid : this.textDisplays) {
|
||||
// textd.add(uuid == null ? null : uuid.toString());
|
||||
// }
|
||||
// arenaSection.set("textdisplay", textd);
|
||||
}
|
||||
|
||||
private void setDiplayBlock(int x, int y, MinecleanerHeads head, boolean applyUsualRotation) {
|
||||
|
|
@ -291,20 +221,12 @@ public class MinecleanerArena {
|
|||
public void startNewGame() {
|
||||
currentMinecleanerGame = new Game(plugin, BoardSize.boardSizesWidth[widthIndex], BoardSize.boardSizesHeight[widthIndex], BoardSize.mineCounter[widthIndex]);
|
||||
currentMinecleanerGame.start();
|
||||
showTextDisplay();
|
||||
removeStartHeads();
|
||||
flagsPlaced = 0;
|
||||
hasMadeFirstClick = false;
|
||||
arenaStatus = ArenaStatus.PLAYING;
|
||||
currentGameStartTime = System.currentTimeMillis();
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(arenaStatus == ArenaStatus.PLAYING && currentPlayer != null) {
|
||||
sendActionBarMessage(currentPlayer);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 20L, 20L);
|
||||
}
|
||||
|
||||
public void addJoiningPlayer(Player player) {
|
||||
|
|
@ -328,6 +250,7 @@ public class MinecleanerArena {
|
|||
}
|
||||
}
|
||||
showStartHeads();
|
||||
removeTextDisplay();
|
||||
}
|
||||
|
||||
public void showStartHeads() {
|
||||
|
|
@ -356,7 +279,6 @@ public class MinecleanerArena {
|
|||
int width = BoardSize.boardSizesWidth[widthIndex];
|
||||
int height = BoardSize.boardSizesHeight[widthIndex];
|
||||
|
||||
// MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN
|
||||
// MINE -
|
||||
setDiplayBlock(width / 2 - 2 + 0, height / 2 + 1, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN, true);
|
||||
setDiplayBlock(width / 2 - 2 + 1, height / 2 + 1, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN, true);
|
||||
|
|
@ -374,6 +296,78 @@ public class MinecleanerArena {
|
|||
setDiplayBlock(width / 2 - 3 + 6, height / 2 - 1, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN, true);
|
||||
}
|
||||
|
||||
private void showTextDisplay() {
|
||||
Player player = this.getCurrentPlayer();
|
||||
World world = player.getWorld();
|
||||
|
||||
double textCenterX = centerLocation.getX();
|
||||
double textCenterY = centerLocation.getY() + ((double) BoardSize.boardSizesHeight[widthIndex] / 3 - 2.75 - widthIndex);
|
||||
double textCenterZ = centerLocation.getZ();
|
||||
|
||||
int rotation = getRotationYaw() - 180;
|
||||
|
||||
switch (orientation) {
|
||||
case NORTH: {
|
||||
textCenterX = centerLocation.getX() - (((double) BoardSize.boardSizesWidth[widthIndex] / 3) / 2.0) + 2.51;
|
||||
textCenterZ = textCenterZ - 0.30;
|
||||
break;
|
||||
}
|
||||
case EAST: {
|
||||
textCenterX = textCenterX + 1.55;
|
||||
textCenterZ = centerLocation.getZ() - (((double) BoardSize.boardSizesWidth[widthIndex] / 3) / 2.0) + 1.775;
|
||||
break;
|
||||
}
|
||||
case SOUTH: {
|
||||
textCenterX = centerLocation.getX() + (((double) BoardSize.boardSizesWidth[widthIndex] / 3) / 2.0) - 0.5275;
|
||||
textCenterZ = textCenterZ + 0.80;
|
||||
break;
|
||||
}
|
||||
case WEST: {
|
||||
textCenterX = textCenterX + 0.45;
|
||||
textCenterZ = centerLocation.getZ() + (((double) BoardSize.boardSizesWidth[widthIndex] / 3) / 2.0) - 1.275;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Location textDisplayLocation = new Location(player.getWorld(), textCenterX, textCenterY, textCenterZ);
|
||||
|
||||
textDisplay = world.spawn(textDisplayLocation.add(-1, 2 + widthIndex, -0.25), TextDisplay.class, textdisplay -> {
|
||||
Transformation transformation = textdisplay.getTransformation();
|
||||
Vector3f newTranslationScale = new Vector3f(1.0f, 1.0f, 1.0f);
|
||||
Transformation newTransformation;
|
||||
newTransformation = new Transformation(
|
||||
transformation.getTranslation(),
|
||||
transformation.getLeftRotation(),
|
||||
newTranslationScale,
|
||||
transformation.getRightRotation());
|
||||
|
||||
textdisplay.setTransformation(newTransformation);
|
||||
textdisplay.setRotation(rotation, 0);
|
||||
|
||||
textdisplay.setBillboard(Display.Billboard.FIXED);
|
||||
textdisplay.setBrightness(new Brightness(15, 15));
|
||||
textdisplay.setVisibleByDefault(true);
|
||||
textdisplay.setDisplayHeight(3);
|
||||
textdisplay.setDisplayWidth((float) BoardSize.boardSizesWidth[widthIndex] / 3);
|
||||
textdisplay.text(Component.text(ChatColor.GOLD + "Minesweeper"));
|
||||
});
|
||||
}
|
||||
|
||||
private void updateTextDisplay() {
|
||||
if (textDisplay != null) {
|
||||
textDisplay.text(Component.text(ChatColor.GREEN + "-- Flaggen gesetzt: " + flagsPlaced + " --" + "\n" + ChatColor.RED + "-- Minen insgesamt: " + BoardSize.mineCounter[widthIndex] + " --"));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTextDisplay() {
|
||||
if (textDisplay != null) {
|
||||
textDisplay.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeBlockDisplays() {
|
||||
int sizeWidth = BoardSize.boardSizesWidth[widthIndex];
|
||||
int sizeHeight = BoardSize.boardSizesHeight[widthIndex];
|
||||
|
|
@ -400,20 +394,17 @@ public class MinecleanerArena {
|
|||
if (currentMinecleanerGame.gameover) {
|
||||
plugin.getManager().handleGameover(player, this, true);
|
||||
}
|
||||
|
||||
if (cell.isFlagged() == true) {
|
||||
flagsPlaced = flagsPlaced + 1;
|
||||
sendActionBarMessage(player);
|
||||
updateTextDisplay();
|
||||
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_FLAG, true);
|
||||
}
|
||||
|
||||
if (cell.isFlagged() == false) {
|
||||
flagsPlaced = flagsPlaced - 1;
|
||||
sendActionBarMessage(player);
|
||||
updateTextDisplay();
|
||||
setDiplayBlock(x, y, MinecleanerHeads.MINESWEEPER_TILE_UNKNOWN, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -434,7 +425,7 @@ public class MinecleanerArena {
|
|||
if (currentMinecleanerGame.gameover) {
|
||||
plugin.getManager().handleGameover(player, this, !(cell.isRevealed() && cell.isExploded()));
|
||||
} else {
|
||||
sendActionBarMessage(player);
|
||||
updateTextDisplay();
|
||||
}
|
||||
|
||||
ArrayList<Cell> floodedCells = currentMinecleanerGame.getfloodedCells();
|
||||
|
|
@ -449,12 +440,6 @@ public class MinecleanerArena {
|
|||
}
|
||||
}
|
||||
|
||||
private void sendActionBarMessage(Player player) {
|
||||
TextComponent textComponent = new TextComponent("Flaggen gesetzt: " + flagsPlaced + " Minen insgesamt: " + BoardSize.mineCounter[widthIndex]);
|
||||
textComponent.setColor(ChatColor.GOLD);
|
||||
player.sendMessage(ChatMessageType.ACTION_BAR, textComponent);
|
||||
}
|
||||
|
||||
public void showMines() {
|
||||
ArrayList<Cell> explodedCells = currentMinecleanerGame.getExplodedCells();
|
||||
if (explodedCells != null) {
|
||||
|
|
@ -463,7 +448,6 @@ public class MinecleanerArena {
|
|||
setBlockForCellType(pos.x, pos.y, explodedCells.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setBlockForCellType(int x, int y, Cell cell) {
|
||||
|
|
@ -570,7 +554,6 @@ public class MinecleanerArena {
|
|||
centerZ = centerLocation.getZ() - ((BoardSize.boardSizesWidth[widthIndex] / 3) / 2.0) + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case SOUTH: {
|
||||
centerX = centerLocation.getX() + ((BoardSize.boardSizesWidth[widthIndex] / 3) / 2.0) - 1;
|
||||
break;
|
||||
|
|
@ -586,7 +569,6 @@ public class MinecleanerArena {
|
|||
|
||||
Location trueCenterLocation = new Location(player.getWorld(), centerX, centerY, centerZ);
|
||||
double dist = tempLoc.distanceSquared(trueCenterLocation);
|
||||
player.sendMessage(ChatColor.GOLD + "Dist: " + dist);
|
||||
|
||||
return dist > Math.pow((BoardSize.boardSizesWidth[widthIndex] / 4.5) + 6, 2);
|
||||
}
|
||||
|
|
@ -630,4 +612,13 @@ public class MinecleanerArena {
|
|||
public int getWidthIndex() {
|
||||
return widthIndex;
|
||||
}
|
||||
|
||||
private int getRotationYaw() {
|
||||
return switch (orientation) {
|
||||
case EAST -> 90;
|
||||
case SOUTH -> 180;
|
||||
case WEST -> 270;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue