Various code simplification/fixes and a lot of typo/grammar fixes (may brake some stuff)
This commit is contained in:
@@ -14,7 +14,7 @@ import fr.pandacube.lib.util.RandomUtil;
|
||||
|
||||
/**
|
||||
* Checkpoint represented as a 3D Axis and Block Aligned Bounding Box (sort of AABB).
|
||||
* Represent the littelest cuboid selection of blocks that contains the bounding box
|
||||
* Represent the littlest cuboid selection of blocks that contains the bounding box
|
||||
* passed to the constructor.
|
||||
*/
|
||||
public class AABBBlock implements Iterable<BlockVector>, Cloneable {
|
||||
@@ -26,10 +26,10 @@ public class AABBBlock implements Iterable<BlockVector>, Cloneable {
|
||||
private final long volume;
|
||||
|
||||
private AABBBlock(AABBBlock original, int shiftX, int shiftY, int shiftZ) {
|
||||
Vector shiftVect = new Vector(shiftX, shiftY, shiftZ);
|
||||
pos1 = original.pos1.clone().add(shiftVect);
|
||||
pos2 = original.pos2.clone().add(shiftVect);
|
||||
center = original.center.clone().add(shiftVect);
|
||||
Vector shiftVec = new Vector(shiftX, shiftY, shiftZ);
|
||||
pos1 = original.pos1.clone().add(shiftVec);
|
||||
pos2 = original.pos2.clone().add(shiftVec);
|
||||
center = original.center.clone().add(shiftVec);
|
||||
volume = original.volume;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AABBBlock implements Iterable<BlockVector>, Cloneable {
|
||||
|
||||
public AABBBlock(int p1x, int p1y, int p1z, int p2x, int p2y, int p2z) {
|
||||
/*
|
||||
* Prends les points extérieurs permettant de former un bouding box englobant
|
||||
* Prends les points extérieurs permettant de former un bounding box englobant
|
||||
* celui représenté par v1 et v2, et étant aligné au quadrillage des blocs.
|
||||
*/
|
||||
int p1x_ = Math.min(p1x, p2x);
|
||||
@@ -70,7 +70,7 @@ public class AABBBlock implements Iterable<BlockVector>, Cloneable {
|
||||
|
||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||
@Override
|
||||
public AABBBlock clone() throws CloneNotSupportedException {
|
||||
public AABBBlock clone() {
|
||||
return new AABBBlock(this, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
@@ -41,7 +41,7 @@ public class AutoUpdatedBossBar implements Listener {
|
||||
|
||||
|
||||
/**
|
||||
* Schedule the update of this bossbar with synchronisation with the system clock.
|
||||
* Schedule the update of this boss bar with synchronisation with the system clock.
|
||||
* The underlying method called is {@link Timer#schedule(TimerTask, long, long)}.
|
||||
* The updater is executed in a separate Thread.
|
||||
* @param msDelay ms before running the first update of this bossbar
|
||||
@@ -49,7 +49,7 @@ public class AutoUpdatedBossBar implements Listener {
|
||||
*/
|
||||
public synchronized void scheduleUpdateTimeSyncThreadAsync(long msDelay, long msPeriod) {
|
||||
if (scheduled)
|
||||
throw new IllegalStateException("Can't schedule an already scheduled bossbar update");
|
||||
throw new IllegalStateException("Can't schedule an already scheduled boss bar update");
|
||||
|
||||
scheduled = true;
|
||||
timer = new Timer("Panda BossBarUpdater - " + Chat.chatComponent(bar.name()).getPlainText());
|
||||
@@ -66,16 +66,16 @@ public class AutoUpdatedBossBar implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the update of this bossbar with synchronisation with the main Thread of the
|
||||
* Schedule the update of this boss bar with synchronisation with the main Thread of the
|
||||
* current Minecraft server (follow the tick count progress).
|
||||
* The underlying method called is {@link BukkitScheduler#runTaskTimer(org.bukkit.plugin.Plugin, Runnable, long, long)}.
|
||||
* The updater is executed by the Server Thread.
|
||||
* @param tickDelay number of server tick before running the first update of this bossbar
|
||||
* @param tickDelay number of server tick before running the first update of this boss bar
|
||||
* @param tickPeriod number of server tick between each call of the updater
|
||||
*/
|
||||
public synchronized void scheduleUpdateTickSyncThreadSync(long tickDelay, long tickPeriod) {
|
||||
if (scheduled)
|
||||
throw new IllegalStateException("Can't schedule an already scheduled bossbar update");
|
||||
throw new IllegalStateException("Can't schedule an already scheduled boss bar update");
|
||||
|
||||
scheduled = true;
|
||||
bukkitTask = Bukkit.getServer().getScheduler()
|
||||
@@ -164,7 +164,7 @@ public class AutoUpdatedBossBar implements Listener {
|
||||
|
||||
|
||||
/**
|
||||
* Utility method to update the title of the bossbar without unnecessary packet.
|
||||
* Utility method to update the title of the boss bar without unnecessary packet.
|
||||
*/
|
||||
public void setTitle(Chat title) {
|
||||
synchronized (bar) {
|
||||
@@ -173,7 +173,7 @@ public class AutoUpdatedBossBar implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to update the color of the bossbar without unnecessary packet.
|
||||
* Utility method to update the color of the boss bar without unnecessary packet.
|
||||
*/
|
||||
public void setColor(Color color) {
|
||||
synchronized (bar) {
|
||||
@@ -182,7 +182,7 @@ public class AutoUpdatedBossBar implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to update the progress of the bossbar without unnecessary packet.
|
||||
* Utility method to update the progress of the boss bar without unnecessary packet.
|
||||
*/
|
||||
public void setProgress(double progress) {
|
||||
synchronized (bar) {
|
||||
|
@@ -19,11 +19,11 @@ public class BukkitChatColorUtil {
|
||||
* @return the closest chat color from {@code dye}
|
||||
*/
|
||||
public static TextColor fromDyeToSignColor(DyeColor dye) {
|
||||
// following code invalid due to text color on sign does not use rgb value of dye color.
|
||||
//org.bukkit.Color col = dye.getColor();
|
||||
//return ChatColor.of(new Color(col.asRGB()));
|
||||
// hmmm this is not that simple, of course
|
||||
|
||||
// black
|
||||
|
||||
// the color values are extracted from IG screenshot of dyed text signs.
|
||||
return switch (dye) {
|
||||
case BLACK -> TextColor.fromHexString("#000000");
|
||||
case RED -> TextColor.fromHexString("#650000");
|
||||
|
@@ -96,7 +96,7 @@ public class BukkitEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract implementation of {@link EventListener} that ensure as best as it can,
|
||||
* Abstract implementation of {@link EventListener} that ensure as good as it can,
|
||||
* that it is the last listener called to handle the event.
|
||||
*
|
||||
* @param <E> the type of the event
|
||||
|
@@ -4,22 +4,19 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/**
|
||||
* Permet de gérer les entités qui se transportent les uns les autres
|
||||
*
|
||||
* Ce groupement d'entité est appelé une "pile d'entité".
|
||||
*
|
||||
* Par exemple, un cheval et son monteur représente à eux deux une pile
|
||||
* d'entité, dont
|
||||
* l'élement tout en bas est le cheval
|
||||
* Utility class to handle stacks of entities. A stack an entity is when an entity is mounting onto another one.
|
||||
* For instance, a player mounting a horse. We also say that the horse is the vehicle of the player.
|
||||
*/
|
||||
public class EntityStackUtil {
|
||||
|
||||
/**
|
||||
* Déplace une pile d'entité vers l'endroit défini
|
||||
* Teleport a stack of entity, all at once.
|
||||
*
|
||||
* @param e Une entité faisant parti de la pile d'entité à téléporter
|
||||
* @param l La position vers lequel envoyer toute la pile
|
||||
* @param e An entity that is part of the stack to teleport.
|
||||
* @param l The location where to send the entity stack.
|
||||
* @deprecated This method has not been tested since a long time ago.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void teleportStack(Entity e, Location l) {
|
||||
|
||||
// on se place sur l'entité tout en bas de la pile
|
||||
@@ -27,7 +24,7 @@ public class EntityStackUtil {
|
||||
while (entTemp.getVehicle() != null)
|
||||
entTemp = entTemp.getVehicle();
|
||||
|
||||
/* la possibilité d'avoir plusieurs passagers sur un entité rend le code
|
||||
/* La possibilité d'avoir plusieurs passagers sur une entité rend le code
|
||||
* commenté qui suit invalide. On le remplace temporairement (voire
|
||||
* définitivement si ça suffit) par le code encore en dessous
|
||||
List<Entity> stack = new ArrayList<>();
|
||||
|
@@ -83,6 +83,9 @@ public class GameWorldUtils implements Listener {
|
||||
new File(destDir, "uid.dat").delete();
|
||||
|
||||
World w = Bukkit.createWorld(new WorldCreator(copiedName).environment(Environment.NORMAL));
|
||||
if (w == null) {
|
||||
throw new RuntimeException("Unable to create the world " + copiedName + ": Bukkit.createWorld(...) returned null value.");
|
||||
}
|
||||
w.setAutoSave(false);
|
||||
gameWorld.put(world, w);
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mvm set hidden true "+copiedName);
|
||||
|
@@ -33,7 +33,7 @@ public class GeometryUtil {
|
||||
/**
|
||||
* The visual height of a Minecraft player skin, when he is standing up and not sneaking,
|
||||
* from the ground where the player is standing on, to the above of the first layer of the head skin.
|
||||
* It doesn't correspond to the player hitbox height.<br/>
|
||||
* It doesn't correspond to the player hit box height.<br/>
|
||||
* <br/>
|
||||
* The value is provided in Minecraft Wiki.
|
||||
*/
|
||||
@@ -45,9 +45,9 @@ public class GeometryUtil {
|
||||
/**
|
||||
* The visual height of a Minecraft player skin, when he is standing up and sneaking,
|
||||
* from the ground where the player is standing on, to the above of the first layer of the head skin.
|
||||
* It may not correspond to the player hitbox height.<br/>
|
||||
* It may not correspond to the player hit box height.<br/>
|
||||
* <br/>
|
||||
* The current value is the height of the player's hitbox when sneaking. Even if this
|
||||
* The current value is the height of the player's hit box when sneaking. Even if this
|
||||
* is close to the real value (tested in game), this is not the exact value.
|
||||
*/
|
||||
public static final double PLAYER_SKIN_HEIGHT_SNEAK = 1.50;
|
||||
@@ -76,7 +76,7 @@ public class GeometryUtil {
|
||||
/**
|
||||
* Get the {@link Location}s of the 8 vertex of the player head<br/>
|
||||
* This method only work if the player is standing up
|
||||
* (not dead, not glyding, not sleeping).
|
||||
* (not dead, not gliding, not sleeping).
|
||||
* @param playerLocation the location of the player, generally provided by {@link Player#getLocation()}
|
||||
* @param isSneaking if the player is sneaking. Generally {@link Player#isSneaking()}
|
||||
* @return an array of 8 {@link Location}s with x, y, and z values filled (yaw and pitch are ignored).
|
||||
@@ -140,32 +140,15 @@ public class GeometryUtil {
|
||||
ad.setX(Math.abs(ad.getX()));
|
||||
ad.setY(Math.abs(ad.getY()));
|
||||
ad.setZ(Math.abs(ad.getZ()));
|
||||
|
||||
if (Math.abs(c.getX()) > e.getX() + ad.getX()){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Math.abs(c.getY()) > e.getY() + ad.getY()){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Math.abs(c.getZ()) > e.getX() + ad.getZ()){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Math.abs(d.getY() * c.getZ() - d.getZ() * c.getY()) > e.getY() * ad.getZ() + e.getZ() * ad.getY() + epsilon){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Math.abs(d.getZ() * c.getX() - d.getX() * c.getZ()) > e.getZ() * ad.getX() + e.getX() * ad.getZ() + epsilon){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Math.abs(d.getX() * c.getY() - d.getY() * c.getX()) > e.getX() * ad.getY() + e.getY() * ad.getX() + epsilon){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !(
|
||||
Math.abs(c.getX()) > e.getX() + ad.getX()
|
||||
|| Math.abs(c.getY()) > e.getY() + ad.getY()
|
||||
|| Math.abs(c.getZ()) > e.getX() + ad.getZ()
|
||||
|| Math.abs(d.getY() * c.getZ() - d.getZ() * c.getY()) > e.getY() * ad.getZ() + e.getZ() * ad.getY() + epsilon
|
||||
|| Math.abs(d.getZ() * c.getX() - d.getX() * c.getZ()) > e.getZ() * ad.getX() + e.getX() * ad.getZ() + epsilon
|
||||
|| Math.abs(d.getX() * c.getY() - d.getY() * c.getX()) > e.getX() * ad.getY() + e.getY() * ad.getX() + epsilon
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +164,7 @@ public class GeometryUtil {
|
||||
|
||||
|
||||
/**
|
||||
* This vector consider Minecraft X Y Z axis orientation,
|
||||
* This vector considers Minecraft X Y Z axis orientation,
|
||||
* but consider standard (not Minecraft) radian values for yaw and pitch.<br/>
|
||||
* The length of this Vector (based on {@link #x}, {@link #y} and {@link #z} values)
|
||||
* Is always 1.
|
||||
@@ -199,25 +182,25 @@ public class GeometryUtil {
|
||||
public static class DirectionalVector {
|
||||
/**
|
||||
* The X cartesian coordinate of this {@link DirectionalVector}.
|
||||
* It correspond to the X (west to east) axis in a Minecraft world.
|
||||
* It corresponds to the X (west to east) axis in a Minecraft world.
|
||||
*/
|
||||
public final double x;
|
||||
|
||||
/**
|
||||
* The Y cartesian coordinate of this {@link DirectionalVector}.
|
||||
* It correspond to the Y (bottom to top) axis in a Minecraft world.
|
||||
* It corresponds to the Y (bottom to top) axis in a Minecraft world.
|
||||
*/
|
||||
public final double y;
|
||||
|
||||
/**
|
||||
* The Z cartesian coordinate of this {@link DirectionalVector}.
|
||||
* It correspond to the Z (north to south) axis in a Minecraft world.
|
||||
* It corresponds to the Z (north to south) axis in a Minecraft world.
|
||||
*/
|
||||
public final double z;
|
||||
|
||||
/**
|
||||
* The azimuthal angle φ (phi) of this {@link DirectionalVector}, in radian.
|
||||
* It correspond with Minecraft world as follow :
|
||||
* It corresponds with Minecraft world as follows :
|
||||
* <pre>Yaw :
|
||||
* North (-z) = -PI/2
|
||||
* East (+x) = 0
|
||||
@@ -228,7 +211,7 @@ public class GeometryUtil {
|
||||
|
||||
/**
|
||||
* The polar angle θ (theta) of this {@link DirectionalVector}, in radian.
|
||||
* It correspond with Minecraft world as follow :
|
||||
* It corresponds with Minecraft world as follows :
|
||||
* <pre>Pitch :
|
||||
* Down (-y) = -PI/2
|
||||
* Up (+y) = PI/2</pre>
|
||||
@@ -258,7 +241,7 @@ public class GeometryUtil {
|
||||
|
||||
/**
|
||||
* @param v the vector representing the direction. If v.getX() and v.getZ() are 0,
|
||||
* the yaw will be 0. This may have inconsistence if the vector is calculated
|
||||
* the yaw will be 0. This may have inconsistency if the vector is calculated
|
||||
* from a {@link Location}'s yaw and pitch. In this case, prefer using
|
||||
* {@link #DirectionalVector(Location)}. The {@link Vector} is
|
||||
* normalized if necessary (does not modify the provided {@link Vector}).
|
||||
@@ -271,10 +254,10 @@ public class GeometryUtil {
|
||||
|
||||
|
||||
private DirectionalVector(double x, double y, double z) {
|
||||
double vectSize = Math.sqrt(x*x + y*y + z*z);
|
||||
this.x = x/vectSize;
|
||||
this.y = y/vectSize;
|
||||
this.z = z/vectSize;
|
||||
double vecSize = Math.sqrt(x*x + y*y + z*z);
|
||||
this.x = x/vecSize;
|
||||
this.y = y/vecSize;
|
||||
this.z = z/vecSize;
|
||||
|
||||
if (x == 0.0 && z == 0.0) {
|
||||
pitch = y > 0.0 ? PId2 : -PId2;
|
||||
|
@@ -37,7 +37,7 @@ public class ItemStackBuilder {
|
||||
|
||||
/**
|
||||
* Create a builder of a new ItemStack with the specified Material.
|
||||
* @param mat the material of the new builded ItemStack
|
||||
* @param mat the material of the new built ItemStack
|
||||
* @return the builder
|
||||
*/
|
||||
public static ItemStackBuilder of(Material mat) {
|
||||
@@ -50,8 +50,8 @@ public class ItemStackBuilder {
|
||||
* The {@link #build()} method of the returned builder will return the same instance
|
||||
* of ItemStack as the parameter of this method.
|
||||
* <p>
|
||||
* To create a builder that doesn’t modify the provided ItemStack, use {@link #of(ItemStack)}.
|
||||
* @param stack the wrapped itemstack.
|
||||
* To create a builder that doesn't modify the provided ItemStack, use {@link #of(ItemStack)}.
|
||||
* @param stack the wrapped item stack.
|
||||
* @return the builder
|
||||
*/
|
||||
public static ItemStackBuilder wrap(ItemStack stack) {
|
||||
@@ -149,8 +149,8 @@ public class ItemStackBuilder {
|
||||
return addLoreAfter(Arrays.asList(lores));
|
||||
}
|
||||
|
||||
public ItemStackBuilder enchant(Enchantment ench, int level) {
|
||||
return meta(m -> m.addEnchant(ench, level, true));
|
||||
public ItemStackBuilder enchant(Enchantment enchantment, int level) {
|
||||
return meta(m -> m.addEnchant(enchantment, level, true));
|
||||
}
|
||||
|
||||
public ItemStackBuilder flags(ItemFlag... flags) {
|
||||
|
@@ -77,13 +77,9 @@ public class LocationUtil {
|
||||
return;
|
||||
|
||||
if (extraSecureCheck != null && !extraSecureCheck.test(ret))
|
||||
return; // extra checks didn’t validate the location
|
||||
|
||||
//if (checkCubo && PandacubePaper.getPlugin().cuboManager != null)
|
||||
// if (PandacubePaper.getPlugin().cuboManager.getCuboFromLocation(ret) != null)
|
||||
// return; // il y a un cubo à l'endroit aléatoire sélectionnée
|
||||
return; // extra checks didn't validate the location
|
||||
|
||||
// tout est bon
|
||||
// all good
|
||||
future.complete(ret);
|
||||
t.get().cancel();
|
||||
|
||||
@@ -103,11 +99,11 @@ public class LocationUtil {
|
||||
* @return a secure location with the same X and Z coordinate as the
|
||||
* provided location, but Y modified to ensure security for player
|
||||
* who will be teleported to this location.
|
||||
* May return null if it is impossible to securize find a secure location.
|
||||
* May return null if it is impossible to find a secure location.
|
||||
*/
|
||||
public static Location getSecureLocationOrNull(Location l) {
|
||||
l = l.clone();
|
||||
l.setY(l.getWorld().getEnvironment() == Environment.NETHER ? 126 : 256);
|
||||
l.setY(l.getWorld().getEnvironment() == Environment.NETHER ? 126 : l.getWorld().getMaxHeight());
|
||||
Block b = l.getBlock();
|
||||
|
||||
while (b.getY() >= 0 && !currPosSafe(b))
|
||||
@@ -147,7 +143,7 @@ public class LocationUtil {
|
||||
|
||||
|
||||
/**
|
||||
* Check if the {@link Location} l is inside the cuboïd formed by the 2 others
|
||||
* Check if the {@link Location} l is inside the cuboid formed by the 2 others
|
||||
* Locations min and max.
|
||||
* @return true if l is inside the cuboid min-max
|
||||
*/
|
||||
@@ -164,7 +160,7 @@ public class LocationUtil {
|
||||
|
||||
/**
|
||||
* Return a new location based on the linear interpolation between p0 and p1, according to the value c.
|
||||
* @param c between 0 and 1. If 0, it returns p0 and if 1, returns p1. Other finite numbers are allowed, but the returned location wont be part of the {@code [p0;p1]} segment.
|
||||
* @param c between 0 and 1. If 0, it returns p0 and if 1, returns p1. Other finite numbers are allowed, but the returned location won't be part of the {@code [p0;p1]} segment.
|
||||
* @return The location, linearly interpolated between p0 and p1 with the value c. The yaw and pitch in the returned location are those of p0.
|
||||
* @throws IllegalArgumentException if the provided locations are not in the same world.
|
||||
*/
|
||||
|
@@ -26,8 +26,15 @@ import java.util.function.IntUnaryOperator;
|
||||
*/
|
||||
public class PlayerDataWrapper {
|
||||
|
||||
/**
|
||||
* The data as they are stored in the player file.
|
||||
*/
|
||||
public final CompoundTag data;
|
||||
|
||||
/**
|
||||
* Creates a new wrapper for the provided player data.
|
||||
* @param data the data to wrap.
|
||||
*/
|
||||
public PlayerDataWrapper(CompoundTag data) {
|
||||
this.data = data == null ? new CompoundTag() : data;
|
||||
}
|
||||
@@ -44,10 +51,10 @@ public class PlayerDataWrapper {
|
||||
}
|
||||
|
||||
private int fromNBTtoBukkitInventorySlot(int nbtSlot) {
|
||||
// cat nbEl NBTslot bukkitSlot NBT->Bukkit
|
||||
// items 36el 0-35 ==
|
||||
// armor 4el start 100 36-39 -100 + 36
|
||||
// offhnd 1el start 150 40 -150 + 40
|
||||
// cat nbEl NBTSlot bukkitSlot NBT->Bukkit
|
||||
// items 36 0-35 ==
|
||||
// armor 4 starts at 100 36-39 -100 + 36
|
||||
// offhand 1 starts at 150 40 -150 + 40
|
||||
if (nbtSlot >= 0 && nbtSlot < 36) { // regular inventory slots
|
||||
return nbtSlot;
|
||||
}
|
||||
@@ -92,7 +99,7 @@ public class PlayerDataWrapper {
|
||||
|
||||
|
||||
private Inventory getBukkitInventory(String nbtKey, InventoryType bukkitType, IntUnaryOperator nbtToBukkitSlotConverter) {
|
||||
Map<Integer, ItemStack> stacks = getRawInvontoryContent(nbtKey);
|
||||
Map<Integer, ItemStack> stacks = getRawInventoryContent(nbtKey);
|
||||
Inventory inv = Bukkit.createInventory(null, bukkitType);
|
||||
if (stacks.isEmpty())
|
||||
return inv;
|
||||
@@ -102,7 +109,7 @@ public class PlayerDataWrapper {
|
||||
return inv;
|
||||
}
|
||||
|
||||
private Map<Integer, ItemStack> getRawInvontoryContent(String key) {
|
||||
private Map<Integer, ItemStack> getRawInventoryContent(String key) {
|
||||
if (!data.contains(key, 9)) // type 9 is list
|
||||
return Map.of();
|
||||
ListTag list = data.getList(key, 10); // type of list element 10 is CompoundTag
|
||||
@@ -125,16 +132,17 @@ public class PlayerDataWrapper {
|
||||
|
||||
|
||||
|
||||
private void setBukkitInventory(String nbtKey, Inventory inv, IntUnaryOperator bukkitToNBTSlotconverter) {
|
||||
private void setBukkitInventory(String nbtKey, Inventory inv, IntUnaryOperator bukkitToNBTSlotConverter) {
|
||||
Map<Integer, ItemStack> stacks = new TreeMap<>();
|
||||
if (inv == null) {
|
||||
setRawInventoryContent(nbtKey, stacks);
|
||||
return;
|
||||
}
|
||||
for (int bukkitSlot = 0; bukkitSlot < inv.getSize(); bukkitSlot++) {
|
||||
ItemStack is = filterStack(inv.getItem(bukkitSlot));
|
||||
if (is == null)
|
||||
continue;
|
||||
int nbtSlot = bukkitToNBTSlotconverter.applyAsInt(bukkitSlot);
|
||||
int nbtSlot = bukkitToNBTSlotConverter.applyAsInt(bukkitSlot);
|
||||
stacks.put(nbtSlot, is);
|
||||
}
|
||||
setRawInventoryContent(nbtKey, stacks);
|
||||
@@ -309,33 +317,18 @@ public class PlayerDataWrapper {
|
||||
Preconditions.checkArgument(slot != null, "slot must not be null");
|
||||
|
||||
switch (slot) {
|
||||
case HAND:
|
||||
this.setItemInMainHand(item);
|
||||
break;
|
||||
case OFF_HAND:
|
||||
this.setItemInOffHand(item);
|
||||
break;
|
||||
case FEET:
|
||||
this.setBoots(item);
|
||||
break;
|
||||
case LEGS:
|
||||
this.setLeggings(item);
|
||||
break;
|
||||
case CHEST:
|
||||
this.setChestplate(item);
|
||||
break;
|
||||
case HEAD:
|
||||
this.setHelmet(item);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Not implemented. This is a bug");
|
||||
case HAND -> this.setItemInMainHand(item);
|
||||
case OFF_HAND -> this.setItemInOffHand(item);
|
||||
case FEET -> this.setBoots(item);
|
||||
case LEGS -> this.setLeggings(item);
|
||||
case CHEST -> this.setChestplate(item);
|
||||
case HEAD -> this.setHelmet(item);
|
||||
default -> throw new IllegalArgumentException("Not implemented. This is a bug");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(EquipmentSlot slot) {
|
||||
Preconditions.checkArgument(slot != null, "slot must not be null");
|
||||
|
||||
public @NotNull ItemStack getItem(@NotNull EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HAND -> this.getItemInMainHand();
|
||||
case OFF_HAND -> this.getItemInOffHand();
|
||||
@@ -348,7 +341,7 @@ public class PlayerDataWrapper {
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack getItemInMainHand() {
|
||||
return getItem(heldItemSlot);
|
||||
return Objects.requireNonNullElse(getItem(heldItemSlot), new ItemStack(Material.AIR));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -358,7 +351,7 @@ public class PlayerDataWrapper {
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack getItemInOffHand() {
|
||||
return getItem(40);
|
||||
return Objects.requireNonNullElse(getItem(40), new ItemStack(Material.AIR));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,17 +1,20 @@
|
||||
package fr.pandacube.lib.paper.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.pandacube.lib.chat.Chat;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.scoreboard.Criteria;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import fr.pandacube.lib.chat.Chat;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility class to manipulate scoreboards.
|
||||
*/
|
||||
public class ScoreboardUtil {
|
||||
|
||||
|
||||
@@ -29,7 +32,7 @@ public class ScoreboardUtil {
|
||||
public static void updateScoreboardSidebar(Scoreboard scBrd, Component title, Component[] lines) {
|
||||
|
||||
Objective obj = scBrd.getObjective("sidebar_autogen");
|
||||
if (obj != null && !obj.getCriteria().equalsIgnoreCase("dummy")) {
|
||||
if (obj != null && !obj.getTrackedCriteria().equals(Criteria.DUMMY)) {
|
||||
// objective present but with wrong criteria, removing it
|
||||
obj.unregister();
|
||||
obj = null;
|
||||
@@ -37,7 +40,7 @@ public class ScoreboardUtil {
|
||||
|
||||
|
||||
if (obj == null) {
|
||||
obj = scBrd.registerNewObjective("sidebar_autogen", "dummy", title);
|
||||
obj = scBrd.registerNewObjective("sidebar_autogen", Criteria.DUMMY, title);
|
||||
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
}
|
||||
else {
|
||||
|
@@ -69,7 +69,7 @@ public enum Skull {
|
||||
/**
|
||||
* Return the item based on this Skull enum.
|
||||
*
|
||||
* @return itemstack
|
||||
* @return item stack
|
||||
*/
|
||||
public ItemStack get() {
|
||||
return get(null, null);
|
||||
@@ -77,29 +77,29 @@ public enum Skull {
|
||||
/**
|
||||
* Return the item based on this Skull enum, with the provided display name and lore.
|
||||
*
|
||||
* @return itemstack
|
||||
* @return item stack
|
||||
*/
|
||||
public ItemStack get(Chat dispName, List<Chat> lore) {
|
||||
return getFromPlayerName(name, dispName, lore);
|
||||
public ItemStack get(Chat displayName, List<Chat> lore) {
|
||||
return getFromPlayerName(name, displayName, lore);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return a skull of a player based on his name.
|
||||
* Return a skull of a player based on their name.
|
||||
*
|
||||
* @param name player's name
|
||||
* @return itemstack
|
||||
* @return item stack
|
||||
*/
|
||||
public static ItemStack getFromPlayerName(String name, Chat dispName, List<Chat> lore) {
|
||||
public static ItemStack getFromPlayerName(String name, Chat displayName, List<Chat> lore) {
|
||||
ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD, 1);
|
||||
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
|
||||
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
boolean b = meta.setOwner(name);
|
||||
|
||||
if (dispName != null)
|
||||
meta.displayName(dispName.getAdv());
|
||||
if (displayName != null)
|
||||
meta.displayName(displayName.getAdv());
|
||||
|
||||
if (lore != null)
|
||||
meta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList()));
|
||||
@@ -122,7 +122,7 @@ public enum Skull {
|
||||
* Return a skull that has a custom texture specified by url.
|
||||
*
|
||||
* @param url skin url
|
||||
* @return itemstack
|
||||
* @return item stack
|
||||
*/
|
||||
public static ItemStack getFromSkinURL(String url) {
|
||||
return getFromSkinURL(url, null, null);
|
||||
@@ -132,7 +132,7 @@ public enum Skull {
|
||||
* Return a skull that has a custom texture specified by url.
|
||||
*
|
||||
* @param url the skin full url
|
||||
* @return itemstack
|
||||
* @return item stack
|
||||
*/
|
||||
public static ItemStack getFromSkinURL(String url, Chat name, List<Chat> lore) {
|
||||
return getFromBase64String(Base64.getEncoder().encodeToString(String.format("{\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}", url).getBytes()), name, lore);
|
||||
@@ -148,8 +148,8 @@ public enum Skull {
|
||||
/**
|
||||
* Return a skull that has a custom texture specified by a base64 String.
|
||||
*
|
||||
* @param str the base64 string from gameprofile informations
|
||||
* @return itemstack
|
||||
* @param str the base64 string from game profile information
|
||||
* @return item stack
|
||||
*/
|
||||
public static ItemStack getFromBase64String(String str) {
|
||||
return getFromBase64String(str, null, null);
|
||||
@@ -159,10 +159,10 @@ public enum Skull {
|
||||
/**
|
||||
* Return a skull that has a custom texture specified by a base64 String.
|
||||
*
|
||||
* @param str the base64 string from gameprofile informations
|
||||
* @return itemstack
|
||||
* @param str the base64 string from game profile information
|
||||
* @return item stack
|
||||
*/
|
||||
public static ItemStack getFromBase64String(String str, Chat dispName, List<Chat> lore) {
|
||||
public static ItemStack getFromBase64String(String str, Chat displayName, List<Chat> lore) {
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
|
||||
|
||||
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
|
||||
@@ -171,8 +171,8 @@ public enum Skull {
|
||||
profile.setProperty(new ProfileProperty("textures", str));
|
||||
headMeta.setPlayerProfile(profile);
|
||||
|
||||
if (dispName != null)
|
||||
headMeta.displayName(dispName.getAdv());
|
||||
if (displayName != null)
|
||||
headMeta.displayName(displayName.getAdv());
|
||||
|
||||
if (lore != null)
|
||||
headMeta.lore(lore.stream().map(Chat::getAdv).collect(Collectors.toList()));
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package fr.pandacube.lib.paper.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
|
||||
import java.io.File;
|
||||
@@ -14,8 +15,9 @@ public class WorldUtil {
|
||||
|
||||
|
||||
public static Environment determineEnvironment(String world) {
|
||||
if (Bukkit.getWorld(world) != null) {
|
||||
return Bukkit.getWorld(world).getEnvironment();
|
||||
World bWorld = Bukkit.getWorld(world);
|
||||
if (bWorld != null) {
|
||||
return bWorld.getEnvironment();
|
||||
}
|
||||
|
||||
File worldFolder = worldDir(world);
|
||||
@@ -43,7 +45,7 @@ public class WorldUtil {
|
||||
private static final List<String> REGION_DATA_FILES = Arrays.asList("entities", "poi", "region", "DIM-1", "DIM1");
|
||||
|
||||
public static List<File> regionDataFiles(String world) {
|
||||
return onlyExistents(worldDir(world), REGION_DATA_FILES);
|
||||
return onlyExisting(worldDir(world), REGION_DATA_FILES);
|
||||
}
|
||||
|
||||
public static List<File> mapFiles(String world) {
|
||||
@@ -51,7 +53,7 @@ public class WorldUtil {
|
||||
return List.of(dataDir(world).listFiles((dir, name) -> mapFilePattern.matcher(name).find() || "idcounts.dat".equals(name)));
|
||||
}
|
||||
|
||||
private static List<File> onlyExistents(File worldDir, List<String> searchList) {
|
||||
private static List<File> onlyExisting(File worldDir, List<String> searchList) {
|
||||
return searchList.stream()
|
||||
.map(f -> new File(worldDir, f))
|
||||
.filter(File::exists)
|
||||
|
Reference in New Issue
Block a user