Various code simplification/fixes and a lot of typo/grammar fixes (may brake some stuff)
This commit is contained in:
@@ -6,11 +6,12 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("CanBeFinal")
|
||||
public class PaperBackupConfig {
|
||||
public boolean worldBackupEnabled = true;
|
||||
public boolean workdirBackupEnabled = true;
|
||||
public boolean logsBackupEnabled = true;
|
||||
public String scheduling = "0 2 * * *"; // cron format, here is everyday at 2am
|
||||
public String scheduling = "0 2 * * *"; // cron format, here is every day at 2am
|
||||
public File backupDirectory = null;
|
||||
public BackupCleaner worldBackupCleaner = BackupCleaner.KEEPING_1_EVERY_N_MONTH(3).merge(BackupCleaner.KEEPING_N_LAST(5));
|
||||
public BackupCleaner workdirBackupCleaner = BackupCleaner.KEEPING_1_EVERY_N_MONTH(3).merge(BackupCleaner.KEEPING_N_LAST(5));
|
||||
|
@@ -1,10 +1,6 @@
|
||||
package fr.pandacube.lib.paper.backup;
|
||||
|
||||
import fr.pandacube.lib.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class PaperWorkdirProcess extends PaperBackupProcess {
|
||||
@@ -15,17 +11,14 @@ public class PaperWorkdirProcess extends PaperBackupProcess {
|
||||
|
||||
|
||||
public BiPredicate<File, String> getFilenameFilter() {
|
||||
return new BiPredicate<File, String>() {
|
||||
@Override
|
||||
public boolean test(File file, String path) {
|
||||
if (file.isDirectory() && new File(file, "level.dat").exists())
|
||||
return false;
|
||||
if (new File(getSourceDir(), "logs").equals(file))
|
||||
return false;
|
||||
if (file.isFile() && file.getName().endsWith(".lck"))
|
||||
return false;
|
||||
return PaperWorkdirProcess.super.getFilenameFilter().test(file, path);
|
||||
}
|
||||
return (file, path) -> {
|
||||
if (file.isDirectory() && new File(file, "level.dat").exists())
|
||||
return false;
|
||||
if (new File(getSourceDir(), "logs").equals(file))
|
||||
return false;
|
||||
if (file.isFile() && file.getName().endsWith(".lck"))
|
||||
return false;
|
||||
return PaperWorkdirProcess.super.getFilenameFilter().test(file, path);
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,6 @@ import org.bukkit.World;
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
public class PaperWorldProcess extends PaperBackupProcess {
|
||||
private final String worldName;
|
||||
|
@@ -77,7 +77,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a plugin command that overrides a vanilla command, so the vanilla command functionnalities are fully
|
||||
* Removes a plugin command that overrides a vanilla command, so the vanilla command functionalities are fully
|
||||
* restored (so, not only the usage, but also the suggestions and the command structure sent to the client).
|
||||
* @param name the name of the command to restore.
|
||||
*/
|
||||
@@ -137,7 +137,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
private Set<String> registeredAliases;
|
||||
|
||||
/**
|
||||
* Instanciate this command instance.
|
||||
* Instantiate this command instance.
|
||||
*
|
||||
* @param pl the plugin instance.
|
||||
* @param regPolicy the registration policy for this command.
|
||||
@@ -155,7 +155,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
}
|
||||
|
||||
/**
|
||||
* Instanciate this command isntance with a registration policy of {@link RegistrationPolicy#ONLY_BASE_COMMAND}.
|
||||
* Instantiate this command instance with a registration policy of {@link RegistrationPolicy#ONLY_BASE_COMMAND}.
|
||||
* @param pl the plugin instance.
|
||||
*/
|
||||
public PaperBrigadierCommand(Plugin pl) {
|
||||
@@ -206,10 +206,10 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
|
||||
// nmsDispatcher integration and conflit resolution
|
||||
boolean nmsRegister = false, nmsRegistered = false;
|
||||
CommandNode<BukkitBrigadierCommandSource> nmsConflited = root.getChild(name);
|
||||
if (nmsConflited != null) {
|
||||
CommandNode<BukkitBrigadierCommandSource> nmsConflicted = root.getChild(name);
|
||||
if (nmsConflicted != null) {
|
||||
|
||||
if (isFromThisCommand(nmsConflited)) {
|
||||
if (isFromThisCommand(nmsConflicted)) {
|
||||
// this command is already registered in NMS. Don’t need to register again
|
||||
nmsRegistered = true;
|
||||
}
|
||||
@@ -221,7 +221,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
Log.severe("/" + name + " already in NMS Brigadier instance."
|
||||
+ " Wont replace it because registration is not forced for prefixed or initial name of a command.");
|
||||
}
|
||||
else { // conflict, wont replace, not forced but only an alias anyway
|
||||
else { // conflict, won't replace, not forced but only an alias anyway
|
||||
Log.info("/" + name + " already in NMS Brigadier instance."
|
||||
+ " Wont replace it because registration is not forced for a non-prefixed alias.");
|
||||
}
|
||||
@@ -418,7 +418,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
|
||||
|
||||
/**
|
||||
* A suggestions supplier that suggests the names of the currently connected players (that the command sender can see).
|
||||
* A suggestion supplier that suggests the names of the currently connected players (that the command sender can see).
|
||||
*/
|
||||
public static final SuggestionsSupplier<CommandSender> TAB_PLAYER_CURRENT_SERVER = (sender, ti, token, a) -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -432,7 +432,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
};
|
||||
|
||||
/**
|
||||
* A suggestions supplier that suggests the names of the worlds currently loaded on this server.
|
||||
* A suggestion supplier that suggests the names of the worlds currently loaded on this server.
|
||||
*/
|
||||
public static final SuggestionsSupplier<CommandSender> TAB_WORLDS = SuggestionsSupplier.fromStreamSupplier(() -> Bukkit.getWorlds().stream().map(World::getName));
|
||||
|
||||
@@ -477,7 +477,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
|
||||
|
||||
/*
|
||||
* Minecraft argument type
|
||||
* Minecraft's argument type
|
||||
*/
|
||||
|
||||
|
||||
@@ -577,13 +577,13 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
* Gets the value of the provided argument of type {@code minecraft:block_pos}, from the provided context.
|
||||
* @param context the command execution context.
|
||||
* @param argument the argument name.
|
||||
* @param deflt a defualt value if the argument is not found.
|
||||
* @param deflt a default value if the argument is not found.
|
||||
* @return the value of the argument.
|
||||
*/
|
||||
public BlockVector tryGetMinecraftBlockPositionArgument(CommandContext<BukkitBrigadierCommandSource> context,
|
||||
String argument, BlockVector deflt) {
|
||||
return tryGetArgument(context, argument, Coordinates.MAPPING.runtimeClass(), nmsCoord -> {
|
||||
BlockPos bp = ReflectWrapper.wrap(nmsCoord, Coordinates.class).getBlockPos(context.getSource());
|
||||
return tryGetArgument(context, argument, Coordinates.MAPPING.runtimeClass(), nmsCoordinate -> {
|
||||
BlockPos bp = ReflectWrapper.wrap(nmsCoordinate, Coordinates.class).getBlockPos(context.getSource());
|
||||
return new BlockVector(bp.getX(), bp.getY(), bp.getZ());
|
||||
}, deflt);
|
||||
}
|
||||
@@ -603,14 +603,14 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
* Gets the value of the provided argument of type {@code minecraft:vec3}, from the provided context.
|
||||
* @param context the command execution context.
|
||||
* @param argument the argument name.
|
||||
* @param deflt a defualt value if the argument is not found.
|
||||
* @param deflt a default value if the argument is not found.
|
||||
* @return the value of the argument.
|
||||
*/
|
||||
public Vector tryGetMinecraftVec3Argument(CommandContext<BukkitBrigadierCommandSource> context, String argument,
|
||||
Vector deflt) {
|
||||
return tryGetArgument(context, argument, Coordinates.MAPPING.runtimeClass(),
|
||||
nmsCoord -> CraftVector.toBukkit(
|
||||
ReflectWrapper.wrap(nmsCoord, Coordinates.class).getPosition(context.getSource())
|
||||
nmsCoordinate -> CraftVector.toBukkit(
|
||||
ReflectWrapper.wrap(nmsCoordinate, Coordinates.class).getPosition(context.getSource())
|
||||
),
|
||||
deflt);
|
||||
}
|
||||
@@ -630,7 +630,7 @@ public abstract class PaperBrigadierCommand extends BrigadierCommand<BukkitBriga
|
||||
* Gets the value of the provided argument of type {@code minecraft:component}, from the provided context.
|
||||
* @param context the command execution context.
|
||||
* @param argument the argument name.
|
||||
* @param deflt a defualt value if the argument is not found.
|
||||
* @param deflt a default value if the argument is not found.
|
||||
* @return the value of the argument.
|
||||
*/
|
||||
public Component tryGetMinecraftChatComponentArgument(CommandContext<BukkitBrigadierCommandSource> context,
|
||||
|
@@ -24,36 +24,36 @@ import fr.pandacube.lib.util.Log;
|
||||
import fr.pandacube.lib.paper.util.BukkitEvent;
|
||||
|
||||
/**
|
||||
* Managed a « lobby » type hotbar menu/inventory. It represents items in the player inventory on which you can right click on it.
|
||||
* Managed a "lobby" type hot bar menu/inventory. It represents items in the
|
||||
* player inventory on which you can right-click on it.
|
||||
* The player can't move or drop these items.
|
||||
*
|
||||
*/
|
||||
public class GUIHotBar implements Listener {
|
||||
|
||||
private final Map<ItemStack, BiConsumer<PlayerInventory, ItemStack>> itemsAndSetters = new HashMap<>();
|
||||
|
||||
private final Map<ItemStack, Consumer<Player>> itemsAndRunnables = new HashMap<>();
|
||||
private final Map<ItemStack, Consumer<Player>> itemsAndClickListeners = new HashMap<>();
|
||||
|
||||
private final int defltSlot;
|
||||
private final int defaultSlot;
|
||||
|
||||
private final List<Player> currentPlayers = new ArrayList<>();
|
||||
|
||||
public GUIHotBar(int defaultSlot) {
|
||||
defltSlot = Math.max(0, Math.min(8, defaultSlot));
|
||||
this.defaultSlot = Math.max(0, Math.min(8, defaultSlot));
|
||||
|
||||
BukkitEvent.register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the item to this hotbar menu. if there is already players hooked to this hotbar, the item will be directly added to
|
||||
* Add the item to this hot bar menu. if there is already players hooked to this hot bar, the item will be directly added to
|
||||
* their inventories.
|
||||
* @param i the item stack
|
||||
* @param setter code executed to put the item in the inventory. Additionally check for permission before doing the addition.
|
||||
* @param run the Runnable to run when the user right click on the item in the hotbar.
|
||||
* @param setter code executed to put the item in the inventory. Additionally, check for permission before doing the addition.
|
||||
* @param run the Runnable to run when the user right-click on the item in the hot bar.
|
||||
*/
|
||||
public GUIHotBar addItem(ItemStack i, BiConsumer<PlayerInventory, ItemStack> setter, Consumer<Player> run) {
|
||||
itemsAndSetters.put(i, setter);
|
||||
itemsAndRunnables.put(i, run);
|
||||
itemsAndClickListeners.put(i, run);
|
||||
|
||||
for (Player p : currentPlayers)
|
||||
addItemToPlayer(p, i);
|
||||
@@ -62,9 +62,9 @@ public class GUIHotBar implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the hotbar elements to this player.
|
||||
* Add the hot bar elements to this player.
|
||||
*
|
||||
* The players is automatically removed when they quit. You can remove it before by calling {@link #removePlayer(Player)}.
|
||||
* The player is automatically removed when they quit. You can remove it before by calling {@link #removePlayer(Player)}.
|
||||
*/
|
||||
public void addPlayer(Player p) {
|
||||
if (!currentPlayers.contains(p))
|
||||
@@ -74,11 +74,11 @@ public class GUIHotBar implements Listener {
|
||||
addItemToPlayer(p, is);
|
||||
}
|
||||
|
||||
p.getInventory().setHeldItemSlot(defltSlot);
|
||||
p.getInventory().setHeldItemSlot(defaultSlot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach this player from this hotbar manager and removes the managed items from the players inventory.
|
||||
* Detach this player from this hot bar manager and removes the managed items from the players inventory.
|
||||
*/
|
||||
public void removePlayer(Player p) {
|
||||
if (!currentPlayers.contains(p))
|
||||
@@ -110,9 +110,9 @@ public class GUIHotBar implements Listener {
|
||||
|
||||
public void addItemToPlayer(Player p, ItemStack is) {
|
||||
if (!itemsAndSetters.containsKey(is))
|
||||
throw new IllegalArgumentException("The provided ItemStack is not registered in this HotbarMenu");
|
||||
throw new IllegalArgumentException("The provided ItemStack is not registered in this GUIHotBar");
|
||||
if (!currentPlayers.contains(p))
|
||||
throw new IllegalArgumentException("The provided Player is not registered in this HotbarMenu");
|
||||
throw new IllegalArgumentException("The provided Player is not registered in this GUIHotBar");
|
||||
itemsAndSetters.get(is).accept(p.getInventory(), is.clone());
|
||||
}
|
||||
|
||||
@@ -153,10 +153,10 @@ public class GUIHotBar implements Listener {
|
||||
|
||||
Player p = event.getPlayer();
|
||||
|
||||
for (ItemStack is : itemsAndRunnables.keySet()) {
|
||||
for (ItemStack is : itemsAndClickListeners.keySet()) {
|
||||
if (item.isSimilar(is)) {
|
||||
try {
|
||||
itemsAndRunnables.get(is).accept(p);
|
||||
itemsAndClickListeners.get(is).accept(p);
|
||||
} catch (Exception e) {
|
||||
Log.severe(e);
|
||||
}
|
||||
@@ -181,7 +181,7 @@ public class GUIHotBar implements Listener {
|
||||
for (ItemStack is : itemsAndSetters.keySet()) {
|
||||
if (item != null && item.isSimilar(is)) {
|
||||
try {
|
||||
itemsAndRunnables.get(is).accept((Player) inv.getHolder());
|
||||
itemsAndClickListeners.get(is).accept((Player) inv.getHolder());
|
||||
} catch (Exception e) {
|
||||
Log.severe(e);
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ public class GUIInventory implements Listener {
|
||||
|
||||
/**
|
||||
* Used as parameter of {@link #buildButton(ItemStack, Integer, ComponentLike, List, Map)} to indicate that a button should
|
||||
* shine like an enchanted object, without showing enchant informations in the hover text.
|
||||
* shine like an enchanted object, without showing enchant information in the hover text.
|
||||
*/
|
||||
public static final Map<Enchantment, Integer> FAKE_ENCHANT = ImmutableMap.of(Enchantment.DURABILITY, 1);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class GUIInventory implements Listener {
|
||||
/**
|
||||
* Create a new inventory based GUI.
|
||||
* @param p the player for which to create the GUI.
|
||||
* @param nbLines the number of invotory lines for the interface.
|
||||
* @param nbLines the number of inventory lines for the interface.
|
||||
* @param title the title of the GUI (title of the inventory)
|
||||
* @param closeEventAction the action to perform when the player closes the GUI inventory
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ public class GUIInventory implements Listener {
|
||||
* @param p the slot index.
|
||||
* @param iStack the item to put in the slot.
|
||||
* @param clickEventActions the action to perform when the user clicks that button. The event passed as a parameter
|
||||
* is already cancelled. It is possible to uncancel it if needed.
|
||||
* is already cancelled. It is possible to un-cancel it if needed.
|
||||
*/
|
||||
public void setButtonIfEmpty(int p, ItemStack iStack, Consumer<InventoryClickEvent> clickEventActions) {
|
||||
if (inv.getItem(p) == null)
|
||||
@@ -85,7 +85,7 @@ public class GUIInventory implements Listener {
|
||||
* @param p the slot index.
|
||||
* @param iStack the item to put in the slot.
|
||||
* @param clickEventActions the action to perform when the user clicks that button. The event passed as a parameter
|
||||
* is already cancelled. It is possible to uncancel it if needed.
|
||||
* is already cancelled. It is possible to un-cancel it if needed.
|
||||
*/
|
||||
public void setButton(int p, ItemStack iStack, Consumer<InventoryClickEvent> clickEventActions) {
|
||||
inv.setItem(p, iStack);
|
||||
@@ -96,7 +96,7 @@ public class GUIInventory implements Listener {
|
||||
* Update/replace the action to perform for a specific slot.
|
||||
* @param p the slot index.
|
||||
* @param clickEventActions the action to perform when the user clicks that button. The event passed as a parameter
|
||||
* is already cancelled. It is possible to uncancel it if needed.
|
||||
* is already cancelled. It is possible to un-cancel it if needed.
|
||||
*/
|
||||
public void changeClickEventAction(int p, Consumer<InventoryClickEvent> clickEventActions) {
|
||||
onClickEvents.put(p, clickEventActions);
|
||||
@@ -122,7 +122,7 @@ public class GUIInventory implements Listener {
|
||||
|
||||
/**
|
||||
* Force this GUI to be closes, without the intervention of the player.
|
||||
* The bukkit API will call the {@link InventoryCloseEvent}, trigerring eventual actions associated with this event.
|
||||
* The bukkit API will call the {@link InventoryCloseEvent}, triggering eventual actions associated with this event.
|
||||
*/
|
||||
public void forceClose() {
|
||||
if (!isOpened) return;
|
||||
|
@@ -28,10 +28,11 @@ import java.util.Map;
|
||||
Map<String, Object> deserializedMap = context.deserialize(json, MAP_STR_OBJ_TYPE.getType());
|
||||
int itemStackVersion = deserializedMap.containsKey("v") ? ((Number)deserializedMap.get("v")).intValue() : -1;
|
||||
if (itemStackVersion >= 0) {
|
||||
@SuppressWarnings("deprecation")
|
||||
int currentDataVersion = Bukkit.getUnsafe().getDataVersion();
|
||||
if (itemStackVersion > currentDataVersion) {
|
||||
/* The itemStack we are deserializing is from a newer MC version, so Bukkit will refuse it.
|
||||
* We decide to ignore the provided version and consider that the received itemstack is from current
|
||||
* We decide to ignore the provided version and consider that the received item stack is from current
|
||||
* version. We let Bukkit handles the deserialization with the data it can interpret, throwing an error
|
||||
* only if it can't.
|
||||
*/
|
||||
|
@@ -28,7 +28,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@@ -57,7 +56,7 @@ public class PerformanceAnalysisManager implements Listener {
|
||||
}
|
||||
|
||||
|
||||
private static final int NB_TICK_HISTORY = 20 * 60 * 60; // 60 secondes;
|
||||
private static final int NB_TICK_HISTORY = 20 * 60 * 60; // 60 secondes ;
|
||||
|
||||
private final Plugin plugin = PandaLibPaper.getPlugin();
|
||||
private long firstRecord = 0;
|
||||
@@ -292,7 +291,7 @@ public class PerformanceAnalysisManager implements Listener {
|
||||
}
|
||||
else {
|
||||
|
||||
String tps1sDisp = Double.isNaN(tps1s) ? "N/A" : (Math.round(tps1s)) + "";
|
||||
String tps1sDisplay = Double.isNaN(tps1s) ? "N/A" : (Math.round(tps1s)) + "";
|
||||
|
||||
|
||||
int[] tpsHistory = getTPSHistory();
|
||||
@@ -319,7 +318,7 @@ public class PerformanceAnalysisManager implements Listener {
|
||||
// we have a lag spike, so we need to display the time since lagging
|
||||
long lagDurationSec = System.nanoTime() - tickEndNanoTime;
|
||||
timings = text("(")
|
||||
.thenFailure("lag:" + dispRound10(lagDurationSec / (double) 1_000_000_000) + "s")
|
||||
.thenFailure("lag:" + displayRound10(lagDurationSec / (double) 1_000_000_000) + "s")
|
||||
.thenText(")");
|
||||
}
|
||||
else {
|
||||
@@ -359,7 +358,7 @@ public class PerformanceAnalysisManager implements Listener {
|
||||
title = infoText("TPS [")
|
||||
.thenLegacyText(s.toString())
|
||||
.thenText("] ")
|
||||
.then(text(tps1sDisp+"/20 ").color(tps1sGradient.pickColorAt(tps1s)))
|
||||
.then(text(tps1sDisplay+"/20 ").color(tps1sGradient.pickColorAt(tps1s)))
|
||||
.then(timings);
|
||||
}
|
||||
|
||||
@@ -469,7 +468,7 @@ public class PerformanceAnalysisManager implements Listener {
|
||||
Log.info(finalMessage.getLegacyText());
|
||||
}
|
||||
|
||||
public static String dispRound10(double val) {
|
||||
public static String displayRound10(double val) {
|
||||
long v = (long) Math.ceil(val * 10);
|
||||
return "" + (v / 10f);
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package fr.pandacube.lib.paper.players;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import fr.pandacube.lib.paper.reflect.util.PrimaryWorlds;
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer;
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.dataconverter.MCDataConverter;
|
||||
@@ -21,6 +20,7 @@ import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
* @return the display name of the player.
|
||||
*
|
||||
* @implNote This default implementation gets the display name from bukkit (if the player is online).
|
||||
* If its different to the player name, it returns it. Otherwise, it tries to generate the team displayname with {@link #getTeamDisplayName()}.
|
||||
* If it's different to the player name, it returns it. Otherwise, it tries to generate the team display name with {@link #getTeamDisplayName()}.
|
||||
* If the player is not in a team, then the player name is used.
|
||||
*/
|
||||
@Override
|
||||
@@ -84,16 +84,16 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
String name = getName();
|
||||
Player p = getBukkitPlayer();
|
||||
@SuppressWarnings("deprecation")
|
||||
String bukkitDispName = p != null ? p.getDisplayName() : name;
|
||||
if (!name.equals(bukkitDispName))
|
||||
return bukkitDispName;
|
||||
String teamDispName = getTeamDisplayName();
|
||||
return teamDispName == null ? name : teamDispName;
|
||||
String bukkitDisplayName = p != null ? p.getDisplayName() : name;
|
||||
if (!name.equals(bukkitDisplayName))
|
||||
return bukkitDisplayName;
|
||||
String teamDisplayName = getTeamDisplayName();
|
||||
return teamDisplayName == null ? name : teamDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the the name of the player with the prefix, suffix and color of the team the player is in.
|
||||
* @return The legacy formated player display name, if he is in a {@link Team}, or null otherwise.
|
||||
* Computes and returns the name of the player with the prefix, suffix and color of the team the player is in.
|
||||
* @return The legacy formatted player display name, if he is in a {@link Team}, or null otherwise.
|
||||
*/
|
||||
default String getTeamDisplayName() {
|
||||
String name = getName();
|
||||
@@ -151,10 +151,10 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the NBT data from the playerdata file.
|
||||
* Gets the NBT data from the player-data file.
|
||||
* It will not work if the player is online, because the data on the file are not synchronized with real-time values.
|
||||
* @param convertTag true to convert the data to the current MC version, false to keep the saved version
|
||||
* @return the NBT data from the playerdata file.
|
||||
* @return the NBT data from the player-data file.
|
||||
* @throws IllegalStateException if the player is online.
|
||||
*/
|
||||
default CompoundTag getPlayerData(boolean convertTag) {
|
||||
@@ -173,9 +173,9 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a wrapper for the NBT data from the playerdata file.
|
||||
* Gets a wrapper for the NBT data from the player-data file.
|
||||
* It will not work if the player is online, because the data on the file are not synchronized with real-time values.
|
||||
* @return the NBT data from the playerdata file.
|
||||
* @return the NBT data from the player-data file.
|
||||
* @throws IllegalStateException if the player is online.
|
||||
*/
|
||||
default PlayerDataWrapper getPlayerDataWrapper() {
|
||||
@@ -183,7 +183,7 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the provided NBT data to the playerdata file.
|
||||
* Saves the provided NBT data to the player-data file.
|
||||
* It will not work if the player is online, because the provided data will be lost when the player disconnects.
|
||||
* @param data the data to save.
|
||||
* @throws IllegalStateException if the player is online.
|
||||
@@ -195,14 +195,14 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
File file = getPlayerDataFile(false);
|
||||
File old = getPlayerDataFile(true);
|
||||
old.delete();
|
||||
Files.move(file, old);
|
||||
Files.move(file.toPath(), old.toPath());
|
||||
NbtIo.writeCompressed(data.data, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file where the playerdata is stored.
|
||||
* Gets the file where the player-data is stored.
|
||||
* @param old true to return the path of old data, false to return the actual file.
|
||||
* @return the file where the playerdata is stored.
|
||||
* @return the file where the player-data is stored.
|
||||
*/
|
||||
default File getPlayerDataFile(boolean old) {
|
||||
File playerDataDir = new File(WorldUtil.worldDir(PrimaryWorlds.PRIMARY_WORLDS.get(0)), "playerdata");
|
||||
|
@@ -97,7 +97,7 @@ public interface PaperOnlinePlayer extends PaperOffPlayer, AbstractOnlinePlayer
|
||||
* Play a sound on this player’s client, sourced at this player’s location.
|
||||
* @param sound the sound to play
|
||||
* @param volume the volume of the sound.
|
||||
* @param pitch the pich in which the sound is played.
|
||||
* @param pitch the pitch in which the sound is played.
|
||||
*/
|
||||
default void playSound(Sound sound, float volume, float pitch) {
|
||||
playSound(sound, getBukkitPlayer().getLocation(), volume, pitch);
|
||||
@@ -108,7 +108,7 @@ public interface PaperOnlinePlayer extends PaperOffPlayer, AbstractOnlinePlayer
|
||||
* @param sound the sound to play
|
||||
* @param location the source location of the sound.
|
||||
* @param volume the volume of the sound.
|
||||
* @param pitch the pich in which the sound is played.
|
||||
* @param pitch the pitch in which the sound is played.
|
||||
*/
|
||||
default void playSound(Sound sound, Location location, float volume, float pitch) {
|
||||
getBukkitPlayer().playSound(location, sound, volume, pitch);
|
||||
|
@@ -18,12 +18,12 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class PaperPlayerConfigStorage {
|
||||
|
||||
static File storageFile = new File(PandaLibPaper.getPlugin().getDataFolder(), "playerdata.yml");
|
||||
static final File storageFile = new File(PandaLibPaper.getPlugin().getDataFolder(), "playerdata.yml");
|
||||
static boolean initialized = false;
|
||||
|
||||
static LinkedHashMap<ConfigKey, ConfigEntry> data = new LinkedHashMap<>();
|
||||
static LinkedHashMap<UUID, LinkedHashSet<ConfigEntry>> playerSortedData = new LinkedHashMap<>();
|
||||
static LinkedHashMap<String, LinkedHashSet<ConfigEntry>> keySortedData = new LinkedHashMap<>();
|
||||
static final LinkedHashMap<ConfigKey, ConfigEntry> data = new LinkedHashMap<>();
|
||||
static final LinkedHashMap<UUID, LinkedHashSet<ConfigEntry>> playerSortedData = new LinkedHashMap<>();
|
||||
static final LinkedHashMap<String, LinkedHashSet<ConfigEntry>> keySortedData = new LinkedHashMap<>();
|
||||
static boolean changed = false;
|
||||
|
||||
|
||||
@@ -196,10 +196,6 @@ public class PaperPlayerConfigStorage {
|
||||
return value;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(playerId, key);
|
||||
|
@@ -79,7 +79,7 @@ public class PlayerNonPersistentConfig {
|
||||
}
|
||||
|
||||
public static class ExpiresTick extends Expiration {
|
||||
long expirationTick;
|
||||
final long expirationTick;
|
||||
|
||||
public ExpiresTick(long expirationDelayTick) {
|
||||
expirationTick = tick + expirationDelayTick;
|
||||
|
@@ -68,7 +68,7 @@ public class NMSReflect {
|
||||
OBF_NAMESPACE = (String) obfHelperClass.field("SPIGOT_NAMESPACE").getStaticValue();
|
||||
MOJ_NAMESPACE = (String) obfHelperClass.field("MOJANG_PLUS_YARN_NAMESPACE").getStaticValue();
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ReflectiveOperationException("Unable to find the Paper ofbuscation mapping class or class members.", e);
|
||||
throw new ReflectiveOperationException("Unable to find the Paper obfuscation mapping class or class members.", e);
|
||||
}
|
||||
|
||||
List<ClassMapping> mappings = loadMappings(obfHelperClass);
|
||||
@@ -165,7 +165,7 @@ public class NMSReflect {
|
||||
private static List<ClassMapping> loadMappings(ReflectClass<?> obfHelperClass) throws IOException {
|
||||
try (final InputStream mappingsInputStream = obfHelperClass.get().getClassLoader().getResourceAsStream("META-INF/mappings/reobf.tiny")) {
|
||||
if (mappingsInputStream == null) {
|
||||
throw new RuntimeException("Unable to find the ofbuscation mapping file in the Paper jar.");
|
||||
throw new RuntimeException("Unable to find the obfuscation mapping file in the Paper jar.");
|
||||
}
|
||||
|
||||
MemoryMappingTree tree = new MemoryMappingTree();
|
||||
@@ -290,7 +290,7 @@ public class NMSReflect {
|
||||
|
||||
|
||||
/**
|
||||
* Represents the mapping between the obfuscated and mojang names of a class and all its members.
|
||||
* Represents the mapping between the obfuscated and Mojang names of a class and all its members.
|
||||
*/
|
||||
public static class ClassMapping {
|
||||
private static int nextID = 0;
|
||||
@@ -463,9 +463,9 @@ public class NMSReflect {
|
||||
private List<NMSTypeWrapper> superInterfaces(boolean obf) {
|
||||
Class<?>[] interfaces = runtimeClass().getInterfaces();
|
||||
List<NMSTypeWrapper> types = new ArrayList<>(interfaces.length);
|
||||
for (Class<?> interfce : interfaces) {
|
||||
ClassMapping cm = (IS_SERVER_OBFUSCATED ? CLASSES_BY_OBF : CLASSES_BY_MOJ).get(interfce.getName());
|
||||
types.add((cm != null) ? cm.toType(obf) : NMSTypeWrapper.of(interfce));
|
||||
for (Class<?> i : interfaces) {
|
||||
ClassMapping cm = (IS_SERVER_OBFUSCATED ? CLASSES_BY_OBF : CLASSES_BY_MOJ).get(i.getName());
|
||||
types.add((cm != null) ? cm.toType(obf) : NMSTypeWrapper.of(i));
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ public class OBCReflect {
|
||||
|
||||
/**
|
||||
* Returns the OBC class that has the provided name, wrapped into a {@link ReflectClass}.
|
||||
* @param obcClass the name of the class, including the subpackage in whitch the requested class is. This parameter
|
||||
* @param obcClass the name of the class, including the subpackage in which the requested class is. This parameter
|
||||
* will be prefixed with the {@code OBC} package and the current package version.
|
||||
* @return the OBC class that has the provided name, wrapped into a {@link ReflectClass}.
|
||||
* @throws ClassNotFoundException if the provided class was not found in {@code OBC} package.
|
||||
|
@@ -79,14 +79,14 @@ import fr.pandacube.lib.util.ThrowableAccumulator;
|
||||
import static fr.pandacube.lib.reflect.wrapper.WrapperRegistry.initWrapper;
|
||||
|
||||
/**
|
||||
* Initializer for all the reflect tools in {@code pandalib-paper-reflect} module.
|
||||
* Initializer for all the reflection tools in {@code pandalib-paper-reflect} module.
|
||||
*/
|
||||
public class PandalibPaperReflect {
|
||||
|
||||
private static boolean isInit = false;
|
||||
|
||||
/**
|
||||
* Initializes the reflect tools in {@code pandalib-paper-reflect} module.
|
||||
* Initializes the reflection tools in {@code pandalib-paper-reflect} module.
|
||||
* @throws Exception if a problem occurs when initializing wrapper classes.
|
||||
*/
|
||||
public static void init() throws Exception {
|
||||
@@ -117,7 +117,7 @@ public class PandalibPaperReflect {
|
||||
thAcc.catchThrowable(() -> initWrapper(RenderData.class, RenderData.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(VanillaCommandWrapper.class, VanillaCommandWrapper.REFLECT.get()));
|
||||
|
||||
// dataconverter
|
||||
// data-converter
|
||||
thAcc.catchThrowable(() -> initWrapper(MCDataConverter.class, MCDataConverter.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(MCDataType.class, MCDataType.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(MCTypeRegistry.class, MCTypeRegistry.REFLECT.get()));
|
||||
@@ -204,7 +204,7 @@ public class PandalibPaperReflect {
|
||||
thAcc.catchThrowable(() -> initWrapper(QueuedChangesMapLong2Object.class, QueuedChangesMapLong2Object.REFLECT.get()));
|
||||
|
||||
|
||||
thAcc.throwCatched();
|
||||
thAcc.throwCaught();
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ public final class BedrockBambooCollisionFixer implements Listener {
|
||||
// Make the bamboo block have zero collision.
|
||||
try {
|
||||
BambooStalkBlock.COLLISION_SHAPE(new AABBVoxelShape(new AABB(0.5, 0, 0.5, 0.5, 0, 0.5)));
|
||||
Log.info("Bamboo block collision box removed succesfully.");
|
||||
Log.info("Bamboo block collision box removed successfully.");
|
||||
} catch (Exception e) {
|
||||
Log.severe("Unable to remove the collision box of the Bamboo block.", e);
|
||||
return;
|
||||
|
@@ -2,14 +2,10 @@ package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
|
||||
|
||||
import fr.pandacube.lib.paper.reflect.OBCReflect;
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.MapItemSavedData;
|
||||
import fr.pandacube.lib.reflect.ReflectClass;
|
||||
import fr.pandacube.lib.reflect.ReflectField;
|
||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperTyped;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||
|
@@ -19,12 +19,12 @@ import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||
|
||||
public class VanillaCommandWrapper extends ReflectWrapperTyped<BukkitCommand> {
|
||||
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("command.VanillaCommandWrapper"));
|
||||
public static final ReflectConstructor<?> CONSTRUTOR = wrapEx(() -> REFLECT.constructor(Commands.MAPPING.runtimeClass(), CommandNode.class));
|
||||
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> REFLECT.constructor(Commands.MAPPING.runtimeClass(), CommandNode.class));
|
||||
public static final ReflectField<?> vanillaCommand = wrapEx(() -> REFLECT.field("vanillaCommand"));
|
||||
public static final ReflectMethod<?> getListener = wrapEx(() -> REFLECT.method("getListener", CommandSender.class));
|
||||
|
||||
public VanillaCommandWrapper(Commands dispatcher, CommandNode<BukkitBrigadierCommandSource> vanillaCommand) {
|
||||
this(wrapReflectEx(() -> CONSTRUTOR.instanciate(unwrap(dispatcher), vanillaCommand)));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(dispatcher), vanillaCommand)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package fr.pandacube.lib.paper.reflect.wrapper.dataconverter;
|
||||
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.network.chat.Component;
|
||||
import fr.pandacube.lib.reflect.Reflect;
|
||||
import fr.pandacube.lib.reflect.ReflectClass;
|
||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||
|
@@ -57,7 +57,7 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
||||
private static final ReflectMethod<?> containsStringInt = wrapEx(() -> MAPPING.mojMethod("contains", String.class, int.class));
|
||||
|
||||
public CompoundTag() {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate()));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate()));
|
||||
}
|
||||
|
||||
protected CompoundTag(Object nms) {
|
||||
@@ -167,7 +167,7 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, ?> entries() {
|
||||
// we cannot easily wrap every value of the map without being able to synch the returned map with the wrapped map
|
||||
// we cannot easily wrap every value of the map without being able to synchronize the returned map with the wrapped map
|
||||
return (Map<String, ?>) wrapReflectEx(() -> entries.invoke(__getRuntimeInstance()));
|
||||
}
|
||||
public int size() {
|
||||
|
@@ -4,7 +4,6 @@ import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
||||
import fr.pandacube.lib.reflect.ReflectConstructor;
|
||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||
@@ -19,7 +18,7 @@ public class ListTag extends CollectionTag {
|
||||
}
|
||||
|
||||
public ListTag() {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate()));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate()));
|
||||
}
|
||||
|
||||
protected ListTag(Object nms) {
|
||||
|
@@ -14,7 +14,7 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
private static final ReflectMethod<?> writeUtf = wrapEx(() -> MAPPING.mojMethod("writeUtf", String.class));
|
||||
|
||||
public FriendlyByteBuf(ByteBuf parent) {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(parent))));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(parent))));
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeUtf(String string) {
|
||||
|
@@ -24,6 +24,6 @@ public class ClientboundCustomPayloadPacket extends ReflectWrapper implements Pa
|
||||
}
|
||||
|
||||
public ClientboundCustomPayloadPacket(ResourceLocation res, FriendlyByteBuf buff) {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(res), unwrap(buff))));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(res), unwrap(buff))));
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ public class ClientboundGameEventPacket extends ReflectWrapper implements Packet
|
||||
}
|
||||
|
||||
public ClientboundGameEventPacket(Type type, float value) {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(type), value)));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(type), value)));
|
||||
}
|
||||
|
||||
protected ClientboundGameEventPacket(Object obj) {
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
|
||||
|
||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||
|
||||
|
@@ -12,7 +12,7 @@ public class AABB extends ReflectWrapper {
|
||||
private static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(double.class, double.class, double.class, double.class, double.class, double.class));
|
||||
|
||||
public AABB(double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(x1, y1, z1, x2, y2, z2)));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(x1, y1, z1, x2, y2, z2)));
|
||||
}
|
||||
|
||||
protected AABB(Object obj) {
|
||||
|
@@ -12,7 +12,7 @@ public class ChunkPos extends ReflectWrapper {
|
||||
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor(int.class, int.class));
|
||||
|
||||
public ChunkPos(int x, int z) {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(x, z)));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(x, z)));
|
||||
}
|
||||
|
||||
protected ChunkPos(Object obj) {
|
||||
|
@@ -2,10 +2,8 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
||||
|
||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||
import fr.pandacube.lib.reflect.ReflectField;
|
||||
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||
|
||||
public class DamageSource extends ReflectWrapper {
|
||||
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.damagesource.DamageSource"));
|
||||
|
@@ -1,11 +1,9 @@
|
||||
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
||||
|
||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||
import fr.pandacube.lib.reflect.ReflectField;
|
||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||
|
||||
public class DamageSources extends ReflectWrapper {
|
||||
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.damagesource.DamageSources"));
|
||||
|
@@ -2,8 +2,6 @@ package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
||||
|
||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.WorldConfiguration;
|
||||
import fr.pandacube.lib.reflect.ReflectField;
|
||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||
|
||||
|
@@ -14,7 +14,7 @@ public class AABBVoxelShape extends VoxelShape {
|
||||
private static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> REFLECT.constructor(AABB.MAPPING.runtimeClass()));
|
||||
|
||||
public AABBVoxelShape(AABB aabb) {
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate(unwrap(aabb))));
|
||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate(unwrap(aabb))));
|
||||
}
|
||||
|
||||
protected AABBVoxelShape(Object obj) {
|
||||
|
@@ -1,15 +1,11 @@
|
||||
package fr.pandacube.lib.paper.scheduler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import fr.pandacube.lib.paper.PandaLibPaper;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.pandacube.lib.paper.PandaLibPaper;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* An extension of {@link BukkitRunnable} that already integrates a reference to the Bukkit plugin.
|
||||
@@ -21,13 +17,13 @@ public class PandalibRunnable extends BukkitRunnable {
|
||||
|
||||
|
||||
/**
|
||||
* Instanciate a {@link PandalibRunnable}, whose {@link #run()} method will be called by the server scheduler.
|
||||
* When using this default constructor, the {@link #run()} method must be override to provides code to run.
|
||||
* Instantiate a {@link PandalibRunnable}, whose {@link #run()} method will be called by the server scheduler.
|
||||
* When using this default constructor, the {@link #run()} method must be overridden to provide code to run.
|
||||
*/
|
||||
protected PandalibRunnable() { }
|
||||
|
||||
/**
|
||||
* Instanciate a {@link PandalibRunnable}, with an {@code updater} that will be called by the server scheduler.
|
||||
* Instantiate a {@link PandalibRunnable}, with an {@code updater} that will be called by the server scheduler.
|
||||
* @param updater the updater to run when this task is executed.
|
||||
*/
|
||||
public PandalibRunnable(Runnable updater) {
|
||||
|
@@ -16,7 +16,7 @@ public class SchedulerUtil {
|
||||
* Ensure that the provided runnable is run on the server thread.
|
||||
* If the current thread is the server thread, then the task is run right now, then this method returns.
|
||||
* If the current thread is another thread, it passes over the runnable to the Bukkit scheduler, then returns
|
||||
* imediately.
|
||||
* immediately.
|
||||
* @param task the task to run on the main thread.
|
||||
*/
|
||||
public static void runOnServerThread(Runnable task) {
|
||||
|
@@ -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