add Spotless plugin: enforce code formatting
This commit is contained in:
1 parent
dce7804fed
commit
7063d27fb4
72 files changed
+1335
-816
No files matched your search
@@ -3,6 +3,9 @@ package eu.mhsl.minecraft.pixelpics.survival;
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
import eu.mhsl.minecraft.pixelpics.Main;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
@@ -17,10 +20,6 @@ import org.bukkit.inventory.meta.components.EquippableComponent;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Factory and identity helpers for the survival items: the camera and the film roll are custom-skinned
|
||||
* {@code PLAYER_HEAD}s (the texture renders client-side without a resource pack), the photo is the
|
||||
@@ -35,8 +34,10 @@ public final class CameraItems {
|
||||
private static final int CAMERA_MODEL_DATA = 1001;
|
||||
private static final int FILM_MODEL_DATA = 1002;
|
||||
|
||||
static final String CAMERA_TEXTURE_B64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDlkMmNiZjAyZDMwOGI2MDY1YTZmZThjNjU3MWI2MzU2NjMzZjQxOTJlOGVjNzEyMTNjNzcwNzgwZTNkZTRlMiJ9fX0=";
|
||||
static final String FILM_TEXTURE_B64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTVkMGY0OGJlNzNkYmIwZDJjYjE1NTRjMmUzODZiNWNjM2FiMjFhNGRjYWU4ZmYzOGI3NzRhZDNkMDFkMGE1OSJ9fX0=";
|
||||
static final String CAMERA_TEXTURE_B64 =
|
||||
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDlkMmNiZjAyZDMwOGI2MDY1YTZmZThjNjU3MWI2MzU2NjMzZjQxOTJlOGVjNzEyMTNjNzcwNzgwZTNkZTRlMiJ9fX0=";
|
||||
static final String FILM_TEXTURE_B64 =
|
||||
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTVkMGY0OGJlNzNkYmIwZDJjYjE1NTRjMmUzODZiNWNjM2FiMjFhNGRjYWU4ZmYzOGI3NzRhZDNkMDFkMGE1OSJ9fX0=";
|
||||
|
||||
private CameraItems() {}
|
||||
|
||||
@@ -48,8 +49,7 @@ public final class CameraItems {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
applyHead(meta, "pixelpics:camera", CAMERA_TEXTURE_B64);
|
||||
meta.displayName(Component.text("Kamera", NamedTextColor.AQUA)
|
||||
.decoration(TextDecoration.ITALIC, false));
|
||||
meta.displayName(Component.text("Kamera", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false));
|
||||
meta.setCustomModelData(CAMERA_MODEL_DATA);
|
||||
meta.getPersistentDataContainer().set(Main.getInstance().cameraMarker, PersistentDataType.BYTE, (byte) 1);
|
||||
meta.getPersistentDataContainer().set(Main.getInstance().filmCountKey, PersistentDataType.INTEGER, count);
|
||||
@@ -64,11 +64,10 @@ public final class CameraItems {
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
applyHead(meta, "pixelpics:film", FILM_TEXTURE_B64);
|
||||
meta.displayName(Component.text("Filmrolle", NamedTextColor.GREEN)
|
||||
.decoration(TextDecoration.ITALIC, false));
|
||||
meta.displayName(Component.text("Filmrolle", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC, false));
|
||||
meta.setCustomModelData(FILM_MODEL_DATA);
|
||||
meta.lore(List.of(Component.text("Lädt eine Kamera auf.", NamedTextColor.GRAY)
|
||||
.decoration(TextDecoration.ITALIC, false)));
|
||||
meta.lore(List.of(
|
||||
Component.text("Lädt eine Kamera auf.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)));
|
||||
meta.getPersistentDataContainer().set(Main.getInstance().filmMarker, PersistentDataType.BYTE, (byte) 1);
|
||||
makeUnwearable(meta);
|
||||
item.setItemMeta(meta);
|
||||
@@ -99,15 +98,17 @@ public final class CameraItems {
|
||||
/** A photo is a filled map carrying our picture id. */
|
||||
public static boolean isPhoto(ItemStack item) {
|
||||
if (item == null || item.getType() != Material.FILLED_MAP || !item.hasItemMeta()) return false;
|
||||
return item.getItemMeta().getPersistentDataContainer()
|
||||
.has(Main.getInstance().pictureIdFlag, PersistentDataType.STRING);
|
||||
return item.getItemMeta()
|
||||
.getPersistentDataContainer()
|
||||
.has(Main.getInstance().pictureIdFlag, PersistentDataType.STRING);
|
||||
}
|
||||
|
||||
/** Loaded film on a camera, or 0 if the item is not a camera. */
|
||||
public static int getFilmCount(ItemStack item) {
|
||||
if (!isCamera(item)) return 0;
|
||||
Integer v = item.getItemMeta().getPersistentDataContainer()
|
||||
.get(Main.getInstance().filmCountKey, PersistentDataType.INTEGER);
|
||||
Integer v = item.getItemMeta()
|
||||
.getPersistentDataContainer()
|
||||
.get(Main.getInstance().filmCountKey, PersistentDataType.INTEGER);
|
||||
return v == null ? 0 : v;
|
||||
}
|
||||
|
||||
@@ -121,11 +122,12 @@ public final class CameraItems {
|
||||
|
||||
private static void applyCameraLore(ItemMeta meta, int count) {
|
||||
meta.lore(List.of(
|
||||
Component.text("Film: " + count + " / " + MAX_FILM,
|
||||
count > 0 ? NamedTextColor.YELLOW : NamedTextColor.RED).decoration(TextDecoration.ITALIC, false),
|
||||
Component.text("Rechtsklick: Foto aufnehmen", NamedTextColor.DARK_GRAY)
|
||||
.decoration(TextDecoration.ITALIC, false)
|
||||
));
|
||||
Component.text(
|
||||
"Film: " + count + " / " + MAX_FILM,
|
||||
count > 0 ? NamedTextColor.YELLOW : NamedTextColor.RED)
|
||||
.decoration(TextDecoration.ITALIC, false),
|
||||
Component.text("Rechtsklick: Foto aufnehmen", NamedTextColor.DARK_GRAY)
|
||||
.decoration(TextDecoration.ITALIC, false)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package eu.mhsl.minecraft.pixelpics.survival;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Sound;
|
||||
@@ -11,10 +14,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Takes a photo when a player right-clicks while holding a camera. Consumes one loaded film per shot;
|
||||
* with no film loaded it gives a short fail feedback. Guards against the well-known double-fire of
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.mhsl.minecraft.pixelpics.survival;
|
||||
|
||||
import eu.mhsl.minecraft.pixelpics.Main;
|
||||
import java.util.function.Predicate;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -19,8 +20,6 @@ import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.meta.MapMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Drives the two dynamic recipes whose inputs carry variable NBT: <em>load film</em>
|
||||
* (camera + film → camera+1) and <em>copy photo</em> (photo + film → 2 photos sharing the same map).
|
||||
@@ -31,7 +30,11 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
public class CraftingListener implements Listener {
|
||||
|
||||
private enum Kind { LOAD, COPY, NONE }
|
||||
private enum Kind {
|
||||
LOAD,
|
||||
COPY,
|
||||
NONE
|
||||
}
|
||||
|
||||
/** Scanned crafting grid: the relevant items and whether any of our marked items are present. */
|
||||
private record Scan(Kind kind, ItemStack camera, ItemStack film, ItemStack photo, boolean hasOurItems) {}
|
||||
@@ -44,9 +47,8 @@ public class CraftingListener implements Listener {
|
||||
switch (scan.kind()) {
|
||||
case LOAD -> {
|
||||
int count = CameraItems.getFilmCount(scan.camera());
|
||||
inv.setResult(count >= CameraItems.MAX_FILM
|
||||
? null
|
||||
: CameraItems.withFilmCount(scan.camera(), count + 1));
|
||||
inv.setResult(
|
||||
count >= CameraItems.MAX_FILM ? null : CameraItems.withFilmCount(scan.camera(), count + 1));
|
||||
}
|
||||
case COPY -> inv.setResult(buildPhotoCopy(scan.photo()));
|
||||
case NONE -> {
|
||||
@@ -109,10 +111,16 @@ public class CraftingListener implements Listener {
|
||||
ItemStack camera = null, film = null, photo = null;
|
||||
for (ItemStack it : matrix) {
|
||||
if (it == null || it.getType().isAir()) continue;
|
||||
if (CameraItems.isCamera(it)) { cameras++; camera = it; }
|
||||
else if (CameraItems.isFilm(it)) { films++; film = it; }
|
||||
else if (CameraItems.isPhoto(it)) { photos++; photo = it; }
|
||||
else others++;
|
||||
if (CameraItems.isCamera(it)) {
|
||||
cameras++;
|
||||
camera = it;
|
||||
} else if (CameraItems.isFilm(it)) {
|
||||
films++;
|
||||
film = it;
|
||||
} else if (CameraItems.isPhoto(it)) {
|
||||
photos++;
|
||||
photo = it;
|
||||
} else others++;
|
||||
}
|
||||
boolean ours = cameras + films + photos > 0;
|
||||
Kind kind = Kind.NONE;
|
||||
@@ -136,11 +144,9 @@ public class CraftingListener implements Listener {
|
||||
ItemStack copy = new ItemStack(Material.FILLED_MAP);
|
||||
MapMeta dst = (MapMeta) copy.getItemMeta();
|
||||
dst.setMapView(src.getMapView());
|
||||
String pid = src.getPersistentDataContainer()
|
||||
.get(Main.getInstance().pictureIdFlag, PersistentDataType.STRING);
|
||||
String pid = src.getPersistentDataContainer().get(Main.getInstance().pictureIdFlag, PersistentDataType.STRING);
|
||||
if (pid != null) {
|
||||
dst.getPersistentDataContainer()
|
||||
.set(Main.getInstance().pictureIdFlag, PersistentDataType.STRING, pid);
|
||||
dst.getPersistentDataContainer().set(Main.getInstance().pictureIdFlag, PersistentDataType.STRING, pid);
|
||||
}
|
||||
copy.setItemMeta(dst);
|
||||
return copy;
|
||||
@@ -152,7 +158,10 @@ public class CraftingListener implements Listener {
|
||||
if (it != null && !it.getType().isAir() && pred.test(it)) {
|
||||
int amt = it.getAmount();
|
||||
if (amt <= 1) matrix[i] = null;
|
||||
else { it.setAmount(amt - 1); matrix[i] = it; }
|
||||
else {
|
||||
it.setAmount(amt - 1);
|
||||
matrix[i] = it;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -163,8 +172,8 @@ public class CraftingListener implements Listener {
|
||||
if (cursor.getType().isAir()) {
|
||||
player.setItemOnCursor(item);
|
||||
} else {
|
||||
player.getInventory().addItem(item).values()
|
||||
.forEach(left -> player.getWorld().dropItemNaturally(player.getLocation(), left));
|
||||
player.getInventory().addItem(item).values().forEach(left -> player.getWorld()
|
||||
.dropItemNaturally(player.getLocation(), left));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import eu.mhsl.minecraft.pixelpics.render.render.Resolution;
|
||||
import eu.mhsl.minecraft.pixelpics.utils.ImageMapRenderer;
|
||||
import eu.mhsl.minecraft.pixelpics.utils.MapImageDither;
|
||||
import eu.mhsl.minecraft.pixelpics.utils.MapManager;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -22,9 +24,6 @@ import org.bukkit.map.MapView;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Renders a photo of a player's current view and delivers it as a developing {@code FILLED_MAP},
|
||||
* with a shutter sound + flash particles on capture and a chime when the picture finishes developing.
|
||||
@@ -47,8 +46,8 @@ public final class PhotoService {
|
||||
Main plugin = Main.getInstance();
|
||||
DefaultScreenRenderer renderer = plugin.getScreenRenderer();
|
||||
if (renderer == null) {
|
||||
player.sendActionBar(Component.text("PixelPics ist nicht einsatzbereit (kein Resource-Pack).",
|
||||
NamedTextColor.RED));
|
||||
player.sendActionBar(
|
||||
Component.text("PixelPics ist nicht einsatzbereit (kein Resource-Pack).", NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,9 +55,11 @@ public final class PhotoService {
|
||||
UUID user = player.getUniqueId();
|
||||
RenderManager.Outcome outcome = manager.tryReserve(user);
|
||||
if (outcome != RenderManager.Outcome.ACCEPTED) {
|
||||
player.sendActionBar(Component.text(outcome == RenderManager.Outcome.USER_BUSY
|
||||
? "Deine letzte Aufnahme wird noch entwickelt …"
|
||||
: "Zu viele Aufnahmen gerade — versuch es gleich erneut.", NamedTextColor.RED));
|
||||
player.sendActionBar(Component.text(
|
||||
outcome == RenderManager.Outcome.USER_BUSY
|
||||
? "Deine letzte Aufnahme wird noch entwickelt …"
|
||||
: "Zu viele Aufnahmen gerade — versuch es gleich erneut.",
|
||||
NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -77,8 +78,11 @@ public final class PhotoService {
|
||||
|
||||
ItemStack map = new ItemStack(Material.FILLED_MAP, 1);
|
||||
MapMeta meta = (MapMeta) map.getItemMeta();
|
||||
meta.getPersistentDataContainer().set(plugin.pictureIdFlag,
|
||||
PersistentDataType.STRING, UUID.randomUUID().toString());
|
||||
meta.getPersistentDataContainer()
|
||||
.set(
|
||||
plugin.pictureIdFlag,
|
||||
PersistentDataType.STRING,
|
||||
UUID.randomUUID().toString());
|
||||
meta.setMapView(mapView);
|
||||
map.setItemMeta(meta);
|
||||
player.getInventory().addItem(map);
|
||||
@@ -88,19 +92,20 @@ public final class PhotoService {
|
||||
|
||||
// Trace + dither off-thread (queued), then develop on the main thread. The cancel token is
|
||||
// tripped by the watchdog on timeout; we bail out before the (now pointless) dithering.
|
||||
manager.dispatch(user,
|
||||
cancelled -> {
|
||||
BufferedImage image = renderer.execute(job, cancelled);
|
||||
if (cancelled.get()) return null;
|
||||
return new RenderOutput(image, MapImageDither.dither(image));
|
||||
},
|
||||
out -> {
|
||||
MapManager.saveImage(out.image(), id);
|
||||
MapManager.saveIndices(out.indices(), id);
|
||||
mapRenderer.develop(out.indices());
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.8f, 1.2f);
|
||||
},
|
||||
() -> player.sendActionBar(Component.text("Rendern fehlgeschlagen.", NamedTextColor.RED)));
|
||||
manager.dispatch(
|
||||
user,
|
||||
cancelled -> {
|
||||
BufferedImage image = renderer.execute(job, cancelled);
|
||||
if (cancelled.get()) return null;
|
||||
return new RenderOutput(image, MapImageDither.dither(image));
|
||||
},
|
||||
out -> {
|
||||
MapManager.saveImage(out.image(), id);
|
||||
MapManager.saveIndices(out.indices(), id);
|
||||
mapRenderer.develop(out.indices());
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.8f, 1.2f);
|
||||
},
|
||||
() -> player.sendActionBar(Component.text("Rendern fehlgeschlagen.", NamedTextColor.RED)));
|
||||
dispatched = true;
|
||||
} finally {
|
||||
// prepare()/map setup threw before handing off — free the reserved slot.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.mhsl.minecraft.pixelpics.survival;
|
||||
|
||||
import eu.mhsl.minecraft.pixelpics.Main;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -9,8 +10,6 @@ import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Registers the four survival recipes and makes them discoverable in the recipe book. Camera and
|
||||
* film have fixed results; load-film and copy-photo use {@code MaterialChoice} ingredients (their
|
||||
|
||||
Reference in new issue
Block a user