mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
More annotations and refactoring
This commit is contained in:
parent
dd9962d3e2
commit
26f9e5f7c6
@ -13,6 +13,9 @@ import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -44,6 +47,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
private T throwable;
|
||||
private File file;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public ErrorReport(T throwable, SlimefunAddon addon, Consumer<PrintStream> printer) {
|
||||
this.throwable = throwable;
|
||||
this.addon = addon;
|
||||
@ -51,6 +55,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
Slimefun.runSync(() -> print(printer));
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public ErrorReport(T throwable, Location l, SlimefunItem item) {
|
||||
this(throwable, item.getAddon(), stream -> {
|
||||
stream.println("Block Info:");
|
||||
@ -83,6 +88,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
});
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public ErrorReport(T throwable, SlimefunItem item) {
|
||||
this(throwable, item.getAddon(), stream -> {
|
||||
stream.println("SlimefunItem:");
|
||||
@ -97,6 +103,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
*
|
||||
* @return The {@link File} for this {@link ErrorReport}
|
||||
*/
|
||||
@Nonnull
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
@ -106,6 +113,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
*
|
||||
* @return The {@link Throwable}
|
||||
*/
|
||||
@Nonnull
|
||||
public T getThrown() {
|
||||
return throwable;
|
||||
}
|
||||
@ -119,7 +127,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
return count;
|
||||
}
|
||||
|
||||
private void print(Consumer<PrintStream> printer) {
|
||||
private void print(@Nonnull Consumer<PrintStream> printer) {
|
||||
this.file = getNewFile();
|
||||
count++;
|
||||
|
||||
@ -180,7 +188,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
}
|
||||
}
|
||||
|
||||
private static void scanPlugins(List<String> plugins, List<String> addons) {
|
||||
private static void scanPlugins(@Nonnull List<String> plugins, @Nonnull List<String> addons) {
|
||||
String dependency = "Slimefun";
|
||||
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
@ -201,6 +209,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static File getNewFile() {
|
||||
String path = "plugins/Slimefun/error-reports/" + dateFormat.format(LocalDateTime.now());
|
||||
File newFile = new File(path + ".err");
|
||||
@ -215,7 +224,7 @@ public class ErrorReport<T extends Throwable> {
|
||||
return newFile;
|
||||
}
|
||||
|
||||
public static void tryCatch(Function<Exception, ErrorReport<Exception>> function, Runnable runnable) {
|
||||
public static void tryCatch(@Nonnull Function<Exception, ErrorReport<Exception>> function, @Nonnull Runnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
}
|
||||
|
@ -5,6 +5,10 @@ import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
@ -35,6 +39,7 @@ public interface SlimefunAddon {
|
||||
*
|
||||
* @return The instance of your {@link JavaPlugin}
|
||||
*/
|
||||
@Nonnull
|
||||
JavaPlugin getJavaPlugin();
|
||||
|
||||
/**
|
||||
@ -42,6 +47,7 @@ public interface SlimefunAddon {
|
||||
*
|
||||
* @return The URL for this Plugin's Bug Tracker, or null
|
||||
*/
|
||||
@Nullable
|
||||
String getBugTrackerURL();
|
||||
|
||||
/**
|
||||
@ -50,6 +56,7 @@ public interface SlimefunAddon {
|
||||
*
|
||||
* @return The Name of this {@link SlimefunAddon}
|
||||
*/
|
||||
@Nonnull
|
||||
default String getName() {
|
||||
return getJavaPlugin().getName();
|
||||
}
|
||||
@ -60,6 +67,7 @@ public interface SlimefunAddon {
|
||||
*
|
||||
* @return The version of this {@link SlimefunAddon}
|
||||
*/
|
||||
@Nonnull
|
||||
default String getPluginVersion() {
|
||||
return getJavaPlugin().getDescription().getVersion();
|
||||
}
|
||||
@ -70,6 +78,7 @@ public interface SlimefunAddon {
|
||||
*
|
||||
* @return The {@link Logger} of this {@link SlimefunAddon}
|
||||
*/
|
||||
@Nonnull
|
||||
default Logger getLogger() {
|
||||
return getJavaPlugin().getLogger();
|
||||
}
|
||||
@ -85,7 +94,9 @@ public interface SlimefunAddon {
|
||||
*
|
||||
* @return Whether this {@link SlimefunAddon} depends on the given {@link Plugin}
|
||||
*/
|
||||
default boolean hasDependency(String dependency) {
|
||||
default boolean hasDependency(@Nonnull String dependency) {
|
||||
Validate.notNull(dependency, "The dependency cannot be null");
|
||||
|
||||
// Well... it cannot depend on itself but you get the idea.
|
||||
if (getJavaPlugin().getName().equalsIgnoreCase(dependency)) {
|
||||
return true;
|
||||
@ -101,6 +112,7 @@ public interface SlimefunAddon {
|
||||
*
|
||||
* @return A {@link Collection} of every {@link Category} from this addon
|
||||
*/
|
||||
@Nonnull
|
||||
default Collection<Category> getCategories() {
|
||||
String namespace = getJavaPlugin().getName().toLowerCase(Locale.ROOT);
|
||||
return SlimefunPlugin.getRegistry().getCategories().stream().filter(cat -> cat.getKey().getNamespace().equals(namespace)).collect(Collectors.toList());
|
||||
|
@ -1,5 +1,9 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
|
||||
/**
|
||||
@ -40,7 +44,8 @@ public enum SlimefunBranch {
|
||||
private final String name;
|
||||
private final boolean official;
|
||||
|
||||
SlimefunBranch(String name, boolean official) {
|
||||
SlimefunBranch(@Nonnull String name, boolean official) {
|
||||
Validate.notNull(name, "The branch name cannot be null");
|
||||
this.name = name;
|
||||
this.official = official;
|
||||
|
||||
@ -55,6 +60,7 @@ public enum SlimefunBranch {
|
||||
*
|
||||
* @return The name of this {@link SlimefunBranch}
|
||||
*/
|
||||
@Nonnull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
/**
|
||||
@ -21,6 +23,7 @@ public class IdConflictException extends RuntimeException {
|
||||
* @param item2
|
||||
* The second {@link SlimefunItem} with this id
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public IdConflictException(SlimefunItem item1, SlimefunItem item2) {
|
||||
super("Two items have conflicting ids: " + item1.toString() + " and " + item2.toString());
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
|
||||
@ -35,6 +37,7 @@ public class IncompatibleItemHandlerException extends RuntimeException {
|
||||
* @param handler
|
||||
* The {@link ItemHandler} which someone tried to add
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public IncompatibleItemHandlerException(String message, SlimefunItem item, ItemHandler handler) {
|
||||
super("The item handler type: \"" + handler.getIdentifier().getSimpleName() + "\" is not compatible with " + item + " (" + message + ')');
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||
|
||||
/**
|
||||
@ -24,6 +26,7 @@ public class MissingDependencyException extends RuntimeException {
|
||||
* @param dependency
|
||||
* The dependency that is required ("Slimefun")
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public MissingDependencyException(SlimefunAddon addon, String dependency) {
|
||||
super("Slimefun Addon \"" + addon.getName() + "\" forgot to define \"" + dependency + "\" as a depend or softdepend inside the plugin.yml file");
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||
|
||||
/**
|
||||
@ -20,6 +22,7 @@ public class PrematureCodeException extends RuntimeException {
|
||||
* @param message
|
||||
* An error message to display
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public PrematureCodeException(String message) {
|
||||
super("Slimefun code was invoked before Slimefun finished loading: " + message);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
@ -25,6 +27,7 @@ public class UnregisteredItemException extends RuntimeException {
|
||||
* @param item
|
||||
* The {@link SlimefunItem} that was affected by this
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public UnregisteredItemException(SlimefunItem item) {
|
||||
super(item.toString() + " has not been registered yet.");
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.api.exceptions;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
|
||||
@ -29,6 +31,7 @@ public class WrongItemStackException extends RuntimeException {
|
||||
* @param message
|
||||
* An error message to display
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public WrongItemStackException(String message) {
|
||||
super("You probably wanted to alter a different ItemStack: " + message);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import java.util.Locale;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -26,7 +28,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
|
||||
@ -46,7 +47,7 @@ public class ResourceManager {
|
||||
private final int[] backgroundSlots = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 48, 49, 50, 52, 53 };
|
||||
private final Config config;
|
||||
|
||||
public ResourceManager(SlimefunPlugin plugin) {
|
||||
public ResourceManager(@Nonnull SlimefunPlugin plugin) {
|
||||
config = new Config(plugin, "resources.yml");
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ public class ResourceManager {
|
||||
* @param resource
|
||||
* The {@link GEOResource} to register
|
||||
*/
|
||||
void register(GEOResource resource) {
|
||||
void register(@Nonnull GEOResource resource) {
|
||||
Validate.notNull(resource, "Cannot register null as a GEO-Resource");
|
||||
Validate.notNull(resource.getKey(), "GEO-Resources must have a NamespacedKey which is not null");
|
||||
|
||||
@ -94,7 +95,7 @@ public class ResourceManager {
|
||||
*
|
||||
* @return An {@link OptionalInt}, either empty or containing the amount of the given {@link GEOResource}
|
||||
*/
|
||||
public OptionalInt getSupplies(GEOResource resource, World world, int x, int z) {
|
||||
public OptionalInt getSupplies(@Nonnull GEOResource resource, @Nonnull World world, int x, int z) {
|
||||
Validate.notNull(resource, "Cannot get supplies for null");
|
||||
Validate.notNull(world, "World must not be null");
|
||||
|
||||
@ -109,7 +110,7 @@ public class ResourceManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void setSupplies(GEOResource resource, World world, int x, int z, int value) {
|
||||
public void setSupplies(@Nonnull GEOResource resource, @Nonnull World world, int x, int z, int value) {
|
||||
Validate.notNull(resource, "Cannot set supplies for null");
|
||||
Validate.notNull(world, "World cannot be null");
|
||||
|
||||
@ -117,7 +118,7 @@ public class ResourceManager {
|
||||
BlockStorage.setChunkInfo(world, x, z, key, String.valueOf(value));
|
||||
}
|
||||
|
||||
private int generate(GEOResource resource, World world, int x, int z) {
|
||||
private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x, int z) {
|
||||
Validate.notNull(resource, "Cannot generate resources for null");
|
||||
Validate.notNull(world, "World cannot be null");
|
||||
|
||||
@ -157,7 +158,7 @@ public class ResourceManager {
|
||||
* @param page
|
||||
* The page to display
|
||||
*/
|
||||
public void scan(Player p, Block block, int page) {
|
||||
public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
|
||||
if (SlimefunPlugin.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) {
|
||||
SlimefunPlugin.getLocalization().sendMessages(p, "gps.insufficient-complexity", true, msg -> msg.replace("%complexity%", "600"));
|
||||
return;
|
||||
@ -172,7 +173,7 @@ public class ResourceManager {
|
||||
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
|
||||
}
|
||||
|
||||
menu.addItem(4, new CustomItem(SlimefunUtils.getCustomHead(HeadTexture.MINECRAFT_CHUNK.getTexture()), ChatColor.YELLOW + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.chunk"), "", "&8\u21E8 &7" + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.world") + ": " + block.getWorld().getName(), "&8\u21E8 &7X: " + x + " Z: " + z), ChestMenuUtils.getEmptyClickHandler());
|
||||
menu.addItem(4, new CustomItem(HeadTexture.MINECRAFT_CHUNK.getAsItemStack(), ChatColor.YELLOW + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.chunk"), "", "&8\u21E8 &7" + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.world") + ": " + block.getWorld().getName(), "&8\u21E8 &7X: " + x + " Z: " + z), ChestMenuUtils.getEmptyClickHandler());
|
||||
List<GEOResource> resources = new ArrayList<>(SlimefunPlugin.getRegistry().getGEOResources().values());
|
||||
Collections.sort(resources, (a, b) -> a.getName(p).toLowerCase(Locale.ROOT).compareTo(b.getName(p).toLowerCase(Locale.ROOT)));
|
||||
|
||||
|
@ -7,6 +7,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -66,7 +69,7 @@ public class GPSNetwork {
|
||||
* @param online
|
||||
* Whether that {@link GPSTransmitter} is online
|
||||
*/
|
||||
public void updateTransmitter(Location l, UUID uuid, boolean online) {
|
||||
public void updateTransmitter(@Nonnull Location l, @Nonnull UUID uuid, boolean online) {
|
||||
Set<Location> set = transmitters.computeIfAbsent(uuid, id -> new HashSet<>());
|
||||
|
||||
if (online) {
|
||||
@ -87,7 +90,7 @@ public class GPSNetwork {
|
||||
*
|
||||
* @return The network complexity for that {@link UUID}
|
||||
*/
|
||||
public int getNetworkComplexity(UUID uuid) {
|
||||
public int getNetworkComplexity(@Nonnull UUID uuid) {
|
||||
if (!transmitters.containsKey(uuid)) {
|
||||
return 0;
|
||||
}
|
||||
@ -113,7 +116,7 @@ public class GPSNetwork {
|
||||
*
|
||||
* @return The amount of transmitters
|
||||
*/
|
||||
public int countTransmitters(UUID uuid) {
|
||||
public int countTransmitters(@Nonnull UUID uuid) {
|
||||
if (!transmitters.containsKey(uuid)) {
|
||||
return 0;
|
||||
}
|
||||
@ -122,7 +125,7 @@ public class GPSNetwork {
|
||||
}
|
||||
}
|
||||
|
||||
public void openTransmitterControlPanel(Player p) {
|
||||
public void openTransmitterControlPanel(@Nonnull Player p) {
|
||||
ChestMenu menu = new ChestMenu(ChatColor.BLUE + SlimefunPlugin.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title"));
|
||||
|
||||
for (int slot : border) {
|
||||
@ -179,7 +182,8 @@ public class GPSNetwork {
|
||||
*
|
||||
* @return An icon for this waypoint
|
||||
*/
|
||||
public ItemStack getIcon(String name, Environment environment) {
|
||||
@Nonnull
|
||||
public ItemStack getIcon(@Nonnull String name, @Nonnull Environment environment) {
|
||||
if (name.startsWith("player:death ")) {
|
||||
return HeadTexture.DEATHPOINT.getAsItemStack();
|
||||
}
|
||||
@ -194,7 +198,7 @@ public class GPSNetwork {
|
||||
}
|
||||
}
|
||||
|
||||
public void openWaypointControlPanel(Player p) {
|
||||
public void openWaypointControlPanel(@Nonnull Player p) {
|
||||
PlayerProfile.get(p, profile -> {
|
||||
ChestMenu menu = new ChestMenu(ChatColor.BLUE + SlimefunPlugin.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.title"));
|
||||
|
||||
@ -246,7 +250,10 @@ public class GPSNetwork {
|
||||
* @param l
|
||||
* The {@link Location} of the new waypoint
|
||||
*/
|
||||
public void createWaypoint(Player p, Location l) {
|
||||
public void createWaypoint(@Nonnull Player p, @Nonnull Location l) {
|
||||
Validate.notNull(p, "Player cannot be null!");
|
||||
Validate.notNull(l, "Waypoint Location cannot be null!");
|
||||
|
||||
PlayerProfile.get(p, profile -> {
|
||||
if ((profile.getWaypoints().size() + 2) > inventory.length) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "gps.waypoint.max", true);
|
||||
@ -270,7 +277,11 @@ public class GPSNetwork {
|
||||
* @param l
|
||||
* The {@link Location} of this waypoint
|
||||
*/
|
||||
public void addWaypoint(Player p, String name, Location l) {
|
||||
public void addWaypoint(@Nonnull Player p, @Nonnull String name, @Nonnull Location l) {
|
||||
Validate.notNull(p, "Player cannot be null!");
|
||||
Validate.notNull(name, "Waypoint name cannot be null!");
|
||||
Validate.notNull(l, "Waypoint Location cannot be null!");
|
||||
|
||||
PlayerProfile.get(p, profile -> {
|
||||
if ((profile.getWaypoints().size() + 2) > inventory.length) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "gps.waypoint.max", true);
|
||||
@ -309,7 +320,8 @@ public class GPSNetwork {
|
||||
*
|
||||
* @return A {@link Set} with all {@link Location Locations} of transmitters for this {@link UUID}
|
||||
*/
|
||||
public Set<Location> getTransmitters(UUID uuid) {
|
||||
@Nonnull
|
||||
public Set<Location> getTransmitters(@Nonnull UUID uuid) {
|
||||
return transmitters.getOrDefault(uuid, new HashSet<>());
|
||||
}
|
||||
|
||||
@ -319,6 +331,7 @@ public class GPSNetwork {
|
||||
*
|
||||
* @return The {@link TeleportationManager} for this {@link GPSNetwork}
|
||||
*/
|
||||
@Nonnull
|
||||
public TeleportationManager getTeleportationManager() {
|
||||
return teleportation;
|
||||
}
|
||||
@ -329,6 +342,7 @@ public class GPSNetwork {
|
||||
*
|
||||
* @return The {@link ResourceManager} for this {@link GPSNetwork}
|
||||
*/
|
||||
@Nonnull
|
||||
public ResourceManager getResourceManager() {
|
||||
return resourceManager;
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -31,6 +35,7 @@ public final class TeleportationManager {
|
||||
private final int[] teleporterBorder = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
|
||||
private final int[] teleporterInventory = { 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43 };
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public void openTeleporterGUI(Player p, UUID uuid, Block b, int complexity) {
|
||||
if (teleporterUsers.contains(p.getUniqueId())) {
|
||||
return;
|
||||
@ -78,6 +83,7 @@ public final class TeleportationManager {
|
||||
});
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public void teleport(UUID uuid, int complexity, Location source, Location destination, boolean resistance) {
|
||||
teleporterUsers.add(uuid);
|
||||
|
||||
@ -85,6 +91,7 @@ public final class TeleportationManager {
|
||||
updateProgress(uuid, Math.max(1, 100 / time), 0, source, destination, resistance);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public int getTeleportationTime(int complexity, Location source, Location destination) {
|
||||
if (complexity < 100) return 100;
|
||||
|
||||
@ -92,6 +99,7 @@ public final class TeleportationManager {
|
||||
return 1 + Math.min(4 * distanceSquared(source, destination) / speed, 40);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private int distanceSquared(Location source, Location destination) {
|
||||
if (source.getWorld().getUID().equals(destination.getWorld().getUID())) {
|
||||
int distance = (int) source.distanceSquared(destination);
|
||||
@ -102,11 +110,11 @@ public final class TeleportationManager {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValid(Player p, Location source) {
|
||||
private boolean isValid(@Nullable Player p, @Nonnull Location source) {
|
||||
return p != null && p.isValid() && p.getWorld().getUID().equals(source.getWorld().getUID()) && p.getLocation().distanceSquared(source) < 2.0;
|
||||
}
|
||||
|
||||
private void cancel(UUID uuid, Player p) {
|
||||
private void cancel(@Nonnull UUID uuid, @Nullable Player p) {
|
||||
teleporterUsers.remove(uuid);
|
||||
|
||||
if (p != null) {
|
||||
@ -114,6 +122,7 @@ public final class TeleportationManager {
|
||||
}
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void updateProgress(UUID uuid, int speed, int progress, Location source, Location destination, boolean resistance) {
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
|
||||
|
@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.api.gps;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -31,6 +34,7 @@ public class Waypoint {
|
||||
private final String name;
|
||||
private final Location location;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public Waypoint(PlayerProfile profile, String id, Location l, String name) {
|
||||
Validate.notNull(profile, "Profile must never be null!");
|
||||
Validate.notNull(id, "id must never be null!");
|
||||
@ -43,18 +47,22 @@ public class Waypoint {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public PlayerProfile getOwner() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
@ -63,6 +71,7 @@ public class Waypoint {
|
||||
return name.startsWith("player:death ");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ItemStack getIcon() {
|
||||
return SlimefunPlugin.getGPSNetwork().getIcon(name, location.getWorld().getEnvironment());
|
||||
}
|
||||
@ -79,7 +88,6 @@ public class Waypoint {
|
||||
}
|
||||
|
||||
Waypoint waypoint = (Waypoint) obj;
|
||||
|
||||
return profile.getUUID().equals(waypoint.getOwner().getUUID()) && id.equals(waypoint.getId()) && location.equals(waypoint.getLocation()) && name.equals(waypoint.getName());
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.api.items;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -48,7 +51,7 @@ public final class HashedArmorpiece {
|
||||
* @param item
|
||||
* The {@link SlimefunItem} corresponding to the provided {@link ItemStack}, may be null
|
||||
*/
|
||||
public void update(ItemStack stack, SlimefunItem item) {
|
||||
public void update(@Nullable ItemStack stack, @Nullable SlimefunItem item) {
|
||||
if (stack == null || stack.getType() == Material.AIR) {
|
||||
this.hash = 0;
|
||||
}
|
||||
@ -76,7 +79,7 @@ public final class HashedArmorpiece {
|
||||
* The {@link ItemStack} to compare
|
||||
* @return Whether the {@link HashedArmorpiece} and the given {@link ItemStack} mismatch
|
||||
*/
|
||||
public boolean hasDiverged(ItemStack stack) {
|
||||
public boolean hasDiverged(@Nullable ItemStack stack) {
|
||||
if (stack == null || stack.getType() == Material.AIR) {
|
||||
return hash != 0;
|
||||
}
|
||||
@ -95,13 +98,14 @@ public final class HashedArmorpiece {
|
||||
*
|
||||
* @return An {@link Optional} describing the result
|
||||
*/
|
||||
@Nonnull
|
||||
public Optional<SlimefunArmorPiece> getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HashedArmorpiece {hash=" + hash + ",item=" + item.map(SlimefunItem::getID).orElse(null) + '}';
|
||||
return "HashedArmorpiece {hash=" + hash + ",item=" + item.map(SlimefunItem::getID).orElse("null") + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.api.items;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
@ -33,6 +36,7 @@ public class ItemSetting<T> {
|
||||
* @param defaultValue
|
||||
* The default value for this {@link ItemSetting}
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public ItemSetting(String key, T defaultValue) {
|
||||
Validate.notNull(key, "The key of an ItemSetting is not allowed to be null!");
|
||||
Validate.notNull(defaultValue, "The default value of an ItemSetting is not allowed to be null!");
|
||||
@ -62,7 +66,7 @@ public class ItemSetting<T> {
|
||||
* @param newValue
|
||||
* The new value for this {@link ItemSetting}
|
||||
*/
|
||||
public void update(T newValue) {
|
||||
public void update(@Nonnull T newValue) {
|
||||
if (validateInput(newValue)) {
|
||||
this.value = newValue;
|
||||
}
|
||||
@ -78,6 +82,7 @@ public class ItemSetting<T> {
|
||||
*
|
||||
* @return The key under which this setting is stored (relative to the {@link SlimefunItem})
|
||||
*/
|
||||
@Nonnull
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
@ -87,6 +92,7 @@ public class ItemSetting<T> {
|
||||
*
|
||||
* @return The current value
|
||||
*/
|
||||
@Nonnull
|
||||
public T getValue() {
|
||||
Validate.notNull(value, "An ItemSetting was invoked but was not initialized yet.");
|
||||
|
||||
@ -98,6 +104,7 @@ public class ItemSetting<T> {
|
||||
*
|
||||
* @return The default value
|
||||
*/
|
||||
@Nonnull
|
||||
public T getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
@ -109,7 +116,7 @@ public class ItemSetting<T> {
|
||||
* The class of data type you want to compare
|
||||
* @return Whether this {@link ItemSetting} stores the given type
|
||||
*/
|
||||
public boolean isType(Class<?> c) {
|
||||
public boolean isType(@Nonnull Class<?> c) {
|
||||
return c.isInstance(defaultValue);
|
||||
}
|
||||
|
||||
@ -121,7 +128,7 @@ public class ItemSetting<T> {
|
||||
* The {@link SlimefunItem} who called this method
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void load(SlimefunItem item) {
|
||||
public void load(@Nonnull SlimefunItem item) {
|
||||
SlimefunPlugin.getItemCfg().setDefaultValue(item.getID() + '.' + getKey(), getDefaultValue());
|
||||
Object configuredValue = SlimefunPlugin.getItemCfg().getValue(item.getID() + '.' + getKey());
|
||||
|
||||
|
@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.api.player;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -41,7 +43,7 @@ public class PlayerBackpack {
|
||||
* @param id
|
||||
* The id of this Backpack
|
||||
*/
|
||||
public PlayerBackpack(PlayerProfile profile, int id) {
|
||||
public PlayerBackpack(@Nonnull PlayerProfile profile, int id) {
|
||||
this(profile, id, profile.getConfig().getInt("backpacks." + id + ".size"));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
@ -59,7 +61,7 @@ public class PlayerBackpack {
|
||||
* @param size
|
||||
* The size of this Backpack
|
||||
*/
|
||||
public PlayerBackpack(PlayerProfile profile, int id, int size) {
|
||||
public PlayerBackpack(@Nonnull PlayerProfile profile, int id, int size) {
|
||||
if (size < 9 || size > 54 || size % 9 != 0) {
|
||||
throw new IllegalArgumentException("Invalid size! Size must be one of: [9, 18, 27, 36, 45, 54]");
|
||||
}
|
||||
@ -89,6 +91,7 @@ public class PlayerBackpack {
|
||||
*
|
||||
* @return The owning {@link PlayerProfile}
|
||||
*/
|
||||
@Nonnull
|
||||
public PlayerProfile getOwner() {
|
||||
return profile;
|
||||
}
|
||||
@ -107,6 +110,7 @@ public class PlayerBackpack {
|
||||
*
|
||||
* @return The {@link Inventory} of this {@link PlayerBackpack}
|
||||
*/
|
||||
@Nonnull
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
@ -15,6 +15,9 @@ import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -72,7 +75,7 @@ public final class PlayerProfile {
|
||||
|
||||
private final HashedArmorpiece[] armor = { new HashedArmorpiece(), new HashedArmorpiece(), new HashedArmorpiece(), new HashedArmorpiece() };
|
||||
|
||||
private PlayerProfile(OfflinePlayer p) {
|
||||
private PlayerProfile(@Nonnull OfflinePlayer p) {
|
||||
this.uuid = p.getUniqueId();
|
||||
this.name = p.getName();
|
||||
|
||||
@ -105,6 +108,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return The cached armor for this {@link Player}
|
||||
*/
|
||||
@Nonnull
|
||||
public HashedArmorpiece[] getArmor() {
|
||||
return armor;
|
||||
}
|
||||
@ -115,6 +119,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return The {@link Config} associated with this {@link PlayerProfile}
|
||||
*/
|
||||
@Nonnull
|
||||
public Config getConfig() {
|
||||
return configFile;
|
||||
}
|
||||
@ -124,6 +129,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return The {@link UUID} of our {@link PlayerProfile}
|
||||
*/
|
||||
@Nonnull
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
@ -169,7 +175,7 @@ public final class PlayerProfile {
|
||||
* @param unlock
|
||||
* Whether the {@link Research} should be unlocked or locked
|
||||
*/
|
||||
public void setResearched(Research research, boolean unlock) {
|
||||
public void setResearched(@Nonnull Research research, boolean unlock) {
|
||||
Validate.notNull(research, "Research must not be null!");
|
||||
dirty = true;
|
||||
|
||||
@ -190,7 +196,7 @@ public final class PlayerProfile {
|
||||
* The {@link Research} that is being queried
|
||||
* @return Whether this {@link Research} has been unlocked
|
||||
*/
|
||||
public boolean hasUnlocked(Research research) {
|
||||
public boolean hasUnlocked(@Nullable Research research) {
|
||||
if (research == null) {
|
||||
// No Research, no restriction
|
||||
return true;
|
||||
@ -204,6 +210,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return A {@code Hashset<Research>} of all Researches this {@link Player} has unlocked
|
||||
*/
|
||||
@Nonnull
|
||||
public Set<Research> getResearches() {
|
||||
return ImmutableSet.copyOf(researches);
|
||||
}
|
||||
@ -214,6 +221,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return A {@link List} containing every {@link Waypoint}
|
||||
*/
|
||||
@Nonnull
|
||||
public List<Waypoint> getWaypoints() {
|
||||
return ImmutableList.copyOf(waypoints);
|
||||
}
|
||||
@ -225,7 +233,7 @@ public final class PlayerProfile {
|
||||
* @param waypoint
|
||||
* The {@link Waypoint} to add
|
||||
*/
|
||||
public void addWaypoint(Waypoint waypoint) {
|
||||
public void addWaypoint(@Nonnull Waypoint waypoint) {
|
||||
Validate.notNull(waypoint, "Cannot add a 'null' waypoint!");
|
||||
|
||||
for (Waypoint wp : waypoints) {
|
||||
@ -250,7 +258,7 @@ public final class PlayerProfile {
|
||||
* @param waypoint
|
||||
* The {@link Waypoint} to remove
|
||||
*/
|
||||
public void removeWaypoint(Waypoint waypoint) {
|
||||
public void removeWaypoint(@Nonnull Waypoint waypoint) {
|
||||
Validate.notNull(waypoint, "Cannot remove a 'null' waypoint!");
|
||||
|
||||
if (waypoints.remove(waypoint)) {
|
||||
@ -274,6 +282,7 @@ public final class PlayerProfile {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public PlayerBackpack createBackpack(int size) {
|
||||
IntStream stream = IntStream.iterate(0, i -> i + 1).filter(i -> !configFile.contains("backpacks." + i + ".size"));
|
||||
int id = stream.findFirst().getAsInt();
|
||||
@ -284,6 +293,7 @@ public final class PlayerProfile {
|
||||
return backpack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Optional<PlayerBackpack> getBackpack(int id) {
|
||||
if (id < 0) {
|
||||
throw new IllegalArgumentException("Backpacks cannot have negative ids!");
|
||||
@ -303,6 +313,7 @@ public final class PlayerProfile {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getTitle() {
|
||||
List<String> titles = SlimefunPlugin.getRegistry().getResearchRanks();
|
||||
|
||||
@ -312,7 +323,7 @@ public final class PlayerProfile {
|
||||
return titles.get(index);
|
||||
}
|
||||
|
||||
public void sendStats(CommandSender sender) {
|
||||
public void sendStats(@Nonnull CommandSender sender) {
|
||||
Set<Research> unlockedResearches = getResearches();
|
||||
int levels = unlockedResearches.stream().mapToInt(Research::getCost).sum();
|
||||
int allResearches = SlimefunPlugin.getRegistry().getResearches().size();
|
||||
@ -333,6 +344,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return The {@link Player} of this {@link PlayerProfile} or null
|
||||
*/
|
||||
@Nullable
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(getUUID());
|
||||
}
|
||||
@ -343,11 +355,12 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return The {@link GuideHistory} of this {@link Player}
|
||||
*/
|
||||
@Nonnull
|
||||
public GuideHistory getGuideHistory() {
|
||||
return guideHistory;
|
||||
}
|
||||
|
||||
public static boolean fromUUID(UUID uuid, Consumer<PlayerProfile> callback) {
|
||||
public static boolean fromUUID(@Nonnull UUID uuid, @Nonnull Consumer<PlayerProfile> callback) {
|
||||
return get(Bukkit.getOfflinePlayer(uuid), callback);
|
||||
}
|
||||
|
||||
@ -361,7 +374,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return If the {@link OfflinePlayer} was cached or not.
|
||||
*/
|
||||
public static boolean get(OfflinePlayer p, Consumer<PlayerProfile> callback) {
|
||||
public static boolean get(@Nonnull OfflinePlayer p, @Nonnull Consumer<PlayerProfile> callback) {
|
||||
Validate.notNull(p, "Cannot get a PlayerProfile for: null!");
|
||||
|
||||
UUID uuid = p.getUniqueId();
|
||||
@ -390,7 +403,7 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return Whether the {@link PlayerProfile} was already loaded
|
||||
*/
|
||||
public static boolean request(OfflinePlayer p) {
|
||||
public static boolean request(@Nonnull OfflinePlayer p) {
|
||||
if (!SlimefunPlugin.getRegistry().getPlayerProfiles().containsKey(p.getUniqueId())) {
|
||||
// Should probably prevent multiple requests for the same profile in the future
|
||||
Bukkit.getScheduler().runTaskAsynchronously(SlimefunPlugin.instance(), () -> {
|
||||
@ -414,15 +427,17 @@ public final class PlayerProfile {
|
||||
*
|
||||
* @return An {@link Optional} describing the result
|
||||
*/
|
||||
public static Optional<PlayerProfile> find(OfflinePlayer p) {
|
||||
@Nonnull
|
||||
public static Optional<PlayerProfile> find(@Nonnull OfflinePlayer p) {
|
||||
return Optional.ofNullable(SlimefunPlugin.getRegistry().getPlayerProfiles().get(p.getUniqueId()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static Iterator<PlayerProfile> iterator() {
|
||||
return SlimefunPlugin.getRegistry().getPlayerProfiles().values().iterator();
|
||||
}
|
||||
|
||||
public static void getBackpack(ItemStack item, Consumer<PlayerBackpack> callback) {
|
||||
public static void getBackpack(@Nullable ItemStack item, @Nonnull Consumer<PlayerBackpack> callback) {
|
||||
if (item == null || !item.hasItemMeta() || !item.getItemMeta().hasLore()) {
|
||||
return;
|
||||
}
|
||||
@ -451,9 +466,8 @@ public final class PlayerProfile {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFullProtectionAgainst(ProtectionType type) {
|
||||
public boolean hasFullProtectionAgainst(@Nonnull ProtectionType type) {
|
||||
int armorCount = 0;
|
||||
|
||||
NamespacedKey setId = null;
|
||||
|
||||
for (HashedArmorpiece armorpiece : armor) {
|
||||
@ -461,10 +475,8 @@ public final class PlayerProfile {
|
||||
|
||||
if (!armorPiece.isPresent()) {
|
||||
setId = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (armorPiece.get() instanceof ProtectiveArmor) {
|
||||
else if (armorPiece.get() instanceof ProtectiveArmor) {
|
||||
ProtectiveArmor protectedArmor = (ProtectiveArmor) armorPiece.get();
|
||||
|
||||
if (setId == null && protectedArmor.isFullSetRequired()) {
|
||||
|
@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.core.categories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -23,10 +26,12 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
*/
|
||||
public abstract class FlexCategory extends Category {
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public FlexCategory(NamespacedKey key, ItemStack item) {
|
||||
this(key, item, 3);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public FlexCategory(NamespacedKey key, ItemStack item, int tier) {
|
||||
super(key, item, tier);
|
||||
}
|
||||
@ -44,6 +49,7 @@ public abstract class FlexCategory extends Category {
|
||||
*
|
||||
* @return Whether to display this {@link FlexCategory}
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public abstract boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideLayout layout);
|
||||
|
||||
/**
|
||||
@ -61,7 +67,7 @@ public abstract class FlexCategory extends Category {
|
||||
public abstract void open(Player p, PlayerProfile profile, SlimefunGuideLayout layout);
|
||||
|
||||
@Override
|
||||
public final boolean isHidden(Player p) {
|
||||
public final boolean isHidden(@Nonnull Player p) {
|
||||
// We can stop this method right here.
|
||||
// We provide a custom method with more parameters for this. See isVisible(...)
|
||||
return false;
|
||||
|
@ -6,6 +6,9 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -46,6 +49,7 @@ public class LockedCategory extends Category {
|
||||
* The parent categories for this category
|
||||
*
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public LockedCategory(NamespacedKey key, ItemStack item, NamespacedKey... parents) {
|
||||
this(key, item, 3, parents);
|
||||
}
|
||||
@ -63,6 +67,7 @@ public class LockedCategory extends Category {
|
||||
* The parent categories for this category
|
||||
*
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public LockedCategory(NamespacedKey key, ItemStack item, int tier, NamespacedKey... parents) {
|
||||
super(key, item, tier);
|
||||
Validate.noNullElements(parents, "A LockedCategory must not have any 'null' parents!");
|
||||
@ -101,6 +106,7 @@ public class LockedCategory extends Category {
|
||||
* @see #addParent(Category)
|
||||
* @see #removeParent(Category)
|
||||
*/
|
||||
@Nonnull
|
||||
public Set<Category> getParents() {
|
||||
return parents;
|
||||
}
|
||||
@ -131,7 +137,7 @@ public class LockedCategory extends Category {
|
||||
* @see #getParents()
|
||||
* @see #addParent(Category)
|
||||
*/
|
||||
public void removeParent(Category category) {
|
||||
public void removeParent(@Nonnull Category category) {
|
||||
parents.remove(category);
|
||||
}
|
||||
|
||||
@ -144,7 +150,7 @@ public class LockedCategory extends Category {
|
||||
* The {@link PlayerProfile} that belongs to the given {@link Player}
|
||||
* @return Whether the {@link Player} has fully completed all parent categories, otherwise false
|
||||
*/
|
||||
public boolean hasUnlocked(Player p, PlayerProfile profile) {
|
||||
public boolean hasUnlocked(@Nonnull Player p, @Nonnull PlayerProfile profile) {
|
||||
for (Category category : parents) {
|
||||
for (SlimefunItem item : category.getItems()) {
|
||||
// Should probably be replaced with Slimefun.hasUnlocked(...)
|
||||
|
@ -3,6 +3,10 @@ package io.github.thebusybiscuit.slimefun4.core.categories;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -34,8 +38,10 @@ public class SeasonalCategory extends Category {
|
||||
* @param item
|
||||
* The display item for this category
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public SeasonalCategory(NamespacedKey key, Month month, int tier, ItemStack item) {
|
||||
super(key, item, tier);
|
||||
Validate.notNull(month, "The Month cannot be null");
|
||||
|
||||
this.month = month;
|
||||
}
|
||||
@ -45,12 +51,13 @@ public class SeasonalCategory extends Category {
|
||||
*
|
||||
* @return the {@link Month} in which this {@link SeasonalCategory} appears
|
||||
*/
|
||||
@Nonnull
|
||||
public Month getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden(Player p) {
|
||||
public boolean isHidden(@Nonnull Player p) {
|
||||
// Hide this Category if the month differs
|
||||
if (month != LocalDate.now().getMonth()) {
|
||||
return true;
|
||||
|
@ -8,6 +8,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -27,6 +28,7 @@ class SlimefunTabCompleter implements TabCompleter {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args.length == 1) {
|
||||
|
@ -6,6 +6,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import kong.unirest.JsonNode;
|
||||
import kong.unirest.json.JSONArray;
|
||||
import kong.unirest.json.JSONObject;
|
||||
@ -38,6 +41,7 @@ class ContributionsConnector extends GitHubConnector {
|
||||
|
||||
private boolean finished = false;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
ContributionsConnector(GitHubService github, String prefix, int page, String repository, String role) {
|
||||
super(github, repository);
|
||||
|
||||
@ -58,6 +62,7 @@ class ContributionsConnector extends GitHubConnector {
|
||||
@Override
|
||||
public void onSuccess(JsonNode element) {
|
||||
finished = true;
|
||||
|
||||
if (element.isArray()) {
|
||||
computeContributors(element.getArray());
|
||||
}
|
||||
@ -81,7 +86,7 @@ class ContributionsConnector extends GitHubConnector {
|
||||
return "/contributors?per_page=100&page=" + page;
|
||||
}
|
||||
|
||||
private void computeContributors(JSONArray array) {
|
||||
private void computeContributors(@Nonnull JSONArray array) {
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class Contributor {
|
||||
|
||||
public Contributor(@Nonnull String username, @Nonnull String profile) {
|
||||
Validate.notNull(username, "Username must never be null!");
|
||||
Validate.notNull(profile, "The profile link must never be null!");
|
||||
Validate.notNull(profile, "The profile cannot be null!");
|
||||
|
||||
githubUsername = profile.substring(profile.lastIndexOf('/') + 1);
|
||||
minecraftUsername = username;
|
||||
@ -70,6 +70,7 @@ public class Contributor {
|
||||
*
|
||||
* @return the name of this contributor
|
||||
*/
|
||||
@Nonnull
|
||||
public String getName() {
|
||||
return githubUsername;
|
||||
}
|
||||
@ -80,6 +81,7 @@ public class Contributor {
|
||||
*
|
||||
* @return The MC username of this contributor.
|
||||
*/
|
||||
@Nonnull
|
||||
public String getMinecraftName() {
|
||||
return minecraftUsername;
|
||||
}
|
||||
@ -89,10 +91,12 @@ public class Contributor {
|
||||
*
|
||||
* @return The GitHub profile of this {@link Contributor}
|
||||
*/
|
||||
@Nullable
|
||||
public String getProfile() {
|
||||
return profileLink;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<Map.Entry<String, Integer>> getContributions() {
|
||||
List<Map.Entry<String, Integer>> list = new ArrayList<>(contributions.entrySet());
|
||||
list.sort(Comparator.comparingInt(entry -> -entry.getValue()));
|
||||
@ -107,7 +111,7 @@ public class Contributor {
|
||||
* The role for which to count the contributions.
|
||||
* @return The amount of contributions this {@link Contributor} submitted as the given role
|
||||
*/
|
||||
public int getContributions(String role) {
|
||||
public int getContributions(@Nonnull String role) {
|
||||
return contributions.getOrDefault(role, 0);
|
||||
}
|
||||
|
||||
@ -127,6 +131,7 @@ public class Contributor {
|
||||
*
|
||||
* @return The {@link UUID} of this {@link Contributor}
|
||||
*/
|
||||
@Nonnull
|
||||
public Optional<UUID> getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
@ -138,6 +143,7 @@ public class Contributor {
|
||||
*
|
||||
* @return A Base64-Head Texture
|
||||
*/
|
||||
@Nonnull
|
||||
public String getTexture() {
|
||||
if (!headTexture.isComputed() || !headTexture.isPresent()) {
|
||||
GitHubService github = SlimefunPlugin.getGitHubService();
|
||||
|
@ -10,6 +10,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import kong.unirest.HttpResponse;
|
||||
import kong.unirest.JsonNode;
|
||||
@ -26,6 +27,7 @@ abstract class GitHubConnector {
|
||||
protected String repository;
|
||||
protected final GitHubService github;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public GitHubConnector(GitHubService github, String repository) {
|
||||
this.github = github;
|
||||
this.repository = repository;
|
||||
|
@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.services.github;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import kong.unirest.JsonNode;
|
||||
import kong.unirest.json.JSONArray;
|
||||
import kong.unirest.json.JSONObject;
|
||||
@ -11,6 +13,7 @@ class GitHubIssuesTracker extends GitHubConnector {
|
||||
|
||||
private final IssuesTrackerConsumer callback;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
GitHubIssuesTracker(GitHubService github, String repository, IssuesTrackerConsumer callback) {
|
||||
super(github, repository);
|
||||
this.callback = callback;
|
||||
|
@ -10,6 +10,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.localization.Translators;
|
||||
@ -77,6 +78,7 @@ public class GitHubService {
|
||||
contributors.put(name, contributor);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Contributor addContributor(@Nonnull String minecraftName, @Nonnull String profileURL, @Nonnull String role, int commits) {
|
||||
String username = profileURL.substring(profileURL.lastIndexOf('/') + 1);
|
||||
|
||||
@ -128,6 +130,7 @@ public class GitHubService {
|
||||
});
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
protected Set<GitHubConnector> getConnectors() {
|
||||
return connectors;
|
||||
}
|
||||
@ -141,6 +144,7 @@ public class GitHubService {
|
||||
*
|
||||
* @return A {@link ConcurrentMap} containing all {@link Contributor Contributors}
|
||||
*/
|
||||
@Nonnull
|
||||
public ConcurrentMap<String, Contributor> getContributors() {
|
||||
return contributors;
|
||||
}
|
||||
@ -177,6 +181,7 @@ public class GitHubService {
|
||||
*
|
||||
* @return The id of our GitHub Repository
|
||||
*/
|
||||
@Nonnull
|
||||
public String getRepository() {
|
||||
return repository;
|
||||
}
|
||||
@ -195,6 +200,7 @@ public class GitHubService {
|
||||
*
|
||||
* @return A {@link LocalDateTime} object representing the date and time of the latest commit
|
||||
*/
|
||||
@Nonnull
|
||||
public LocalDateTime getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
@ -222,6 +228,7 @@ public class GitHubService {
|
||||
texturesCache.save();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getCachedTexture(@Nonnull String name) {
|
||||
return texturesCache.getString(name);
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.core.services.localization;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -42,7 +45,7 @@ public final class Language {
|
||||
* @param hash
|
||||
* The hash of the skull texture to use
|
||||
*/
|
||||
public Language(String id, String hash) {
|
||||
public Language(@Nonnull String id, @Nonnull String hash) {
|
||||
Validate.notNull(id, "A Language must have an id that is not null!");
|
||||
Validate.notNull(hash, "A Language must have a texture that is not null!");
|
||||
|
||||
@ -57,6 +60,7 @@ public final class Language {
|
||||
*
|
||||
* @return The identifier of this {@link Language}
|
||||
*/
|
||||
@Nonnull
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -81,51 +85,56 @@ public final class Language {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
FileConfiguration getMessagesFile() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
FileConfiguration getResearchesFile() {
|
||||
return researches;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
FileConfiguration getResourcesFile() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
FileConfiguration getCategoriesFile() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
FileConfiguration getRecipeTypesFile() {
|
||||
return recipeTypes;
|
||||
}
|
||||
|
||||
public void setMessagesFile(FileConfiguration config) {
|
||||
public void setMessagesFile(@Nonnull FileConfiguration config) {
|
||||
Validate.notNull(config);
|
||||
|
||||
this.messages = config;
|
||||
}
|
||||
|
||||
public void setResearchesFile(FileConfiguration config) {
|
||||
public void setResearchesFile(@Nonnull FileConfiguration config) {
|
||||
Validate.notNull(config);
|
||||
|
||||
this.researches = config;
|
||||
}
|
||||
|
||||
public void setResourcesFile(FileConfiguration config) {
|
||||
public void setResourcesFile(@Nonnull FileConfiguration config) {
|
||||
Validate.notNull(config);
|
||||
|
||||
this.resources = config;
|
||||
}
|
||||
|
||||
public void setCategoriesFile(FileConfiguration config) {
|
||||
public void setCategoriesFile(@Nonnull FileConfiguration config) {
|
||||
Validate.notNull(config);
|
||||
|
||||
this.categories = config;
|
||||
}
|
||||
|
||||
public void setRecipeTypesFile(FileConfiguration config) {
|
||||
public void setRecipeTypesFile(@Nonnull FileConfiguration config) {
|
||||
Validate.notNull(config);
|
||||
|
||||
this.recipeTypes = config;
|
||||
@ -137,6 +146,7 @@ public final class Language {
|
||||
*
|
||||
* @return The {@link ItemStack} used to display this {@link Language}
|
||||
*/
|
||||
@Nonnull
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
@ -149,7 +159,8 @@ public final class Language {
|
||||
* The {@link Player} to localize the name for
|
||||
* @return The localized name of this {@link Language}
|
||||
*/
|
||||
public String getName(Player p) {
|
||||
@Nonnull
|
||||
public String getName(@Nonnull Player p) {
|
||||
String name = SlimefunPlugin.getLocalization().getMessage(p, "languages." + id);
|
||||
return name != null ? name : toString();
|
||||
}
|
||||
@ -169,6 +180,7 @@ public final class Language {
|
||||
return "Language {id= " + id + ", default=" + isDefault() + " }";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public FileConfiguration[] getFiles() {
|
||||
return new FileConfiguration[] { getMessagesFile(), getCategoriesFile(), getResearchesFile(), getResourcesFile() };
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Keyed;
|
||||
@ -47,8 +48,10 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
||||
*
|
||||
* @param id
|
||||
* The language code
|
||||
*
|
||||
* @return A {@link Language} with the given id or null
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Language getLanguage(@Nonnull String id);
|
||||
|
||||
/**
|
||||
@ -56,6 +59,7 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
||||
*
|
||||
* @param p
|
||||
* The {@link Player} to query
|
||||
*
|
||||
* @return The {@link Language} that was selected by the given {@link Player}
|
||||
*/
|
||||
public abstract Language getLanguage(@Nonnull Player p);
|
||||
@ -75,6 +79,7 @@ public abstract class SlimefunLocalization extends Localization implements Keyed
|
||||
*
|
||||
* @return A {@link Collection} that contains every installed {@link Language}
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract Collection<Language> getLanguages();
|
||||
|
||||
protected abstract void addLanguage(@Nonnull String id, @Nonnull String texture);
|
||||
|
@ -1,5 +1,8 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.localization;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
@ -59,12 +62,14 @@ enum SupportedLanguage {
|
||||
private final boolean releaseReady;
|
||||
private final String textureHash;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
SupportedLanguage(String id, boolean releaseReady, String textureHash) {
|
||||
this.id = id;
|
||||
this.releaseReady = releaseReady;
|
||||
this.textureHash = textureHash;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getLanguageId() {
|
||||
return id;
|
||||
}
|
||||
@ -73,6 +78,7 @@ enum SupportedLanguage {
|
||||
return releaseReady;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getTexture() {
|
||||
return textureHash;
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.localization;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.github.Contributor;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService;
|
||||
|
||||
@ -17,7 +20,7 @@ public class Translators {
|
||||
private final GitHubService github;
|
||||
|
||||
// We maybe should switch to a json file in our resources folder at some point.
|
||||
public Translators(GitHubService github) {
|
||||
public Translators(@Nonnull GitHubService github) {
|
||||
this.github = github;
|
||||
|
||||
// Translators - German
|
||||
@ -164,10 +167,12 @@ public class Translators {
|
||||
addTranslator("FaolanMalcadh", SupportedLanguage.PORTUGUESE_BRAZIL, true);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void addTranslator(String name, SupportedLanguage lang, boolean lock) {
|
||||
addTranslator(name, name, lang, lock);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void addTranslator(String username, String minecraftName, SupportedLanguage lang, boolean lock) {
|
||||
Contributor contributor = github.addContributor(minecraftName, "https://github.com/" + username, "translator," + lang.getLanguageId(), 0);
|
||||
|
||||
|
@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.services.plugins;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -13,7 +15,7 @@ import me.minebuilders.clearlag.events.EntityRemoveEvent;
|
||||
|
||||
class ClearLagHook implements Listener {
|
||||
|
||||
ClearLagHook(SlimefunPlugin plugin) {
|
||||
ClearLagHook(@Nonnull SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.services.plugins;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,7 +14,7 @@ import me.mrCookieSlime.EmeraldEnchants.EnchantmentGuide;
|
||||
|
||||
class EmeraldEnchantsCategory extends FlexCategory {
|
||||
|
||||
public EmeraldEnchantsCategory(NamespacedKey key) {
|
||||
public EmeraldEnchantsCategory(@Nonnull NamespacedKey key) {
|
||||
super(key, new CustomItem(Material.ENCHANTED_BOOK, "&2EmeraldEnchants &a(Enchantment Guide)"), 2);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -17,7 +19,7 @@ class PlaceholderAPIHook extends PlaceholderExpansion {
|
||||
private final String version;
|
||||
private final String author;
|
||||
|
||||
public PlaceholderAPIHook(SlimefunPlugin plugin) {
|
||||
public PlaceholderAPIHook(@Nonnull SlimefunPlugin plugin) {
|
||||
this.version = plugin.getDescription().getVersion();
|
||||
this.author = plugin.getDescription().getAuthors().toString();
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -90,6 +91,7 @@ class PerformanceSummary {
|
||||
});
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void summarizeTimings(int count, String name, CommandSender sender, Map<String, Long> map, Function<Map.Entry<String, Long>, String> formatter) {
|
||||
Stream<Map.Entry<String, Long>> stream = map.entrySet().stream();
|
||||
List<Entry<String, Long>> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
@ -105,6 +107,8 @@ class PerformanceSummary {
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ParametersAreNonnullByDefault
|
||||
private TextComponent summarizeAsTextComponent(int count, String prefix, List<Map.Entry<String, Long>> results, Function<Entry<String, Long>, String> formatter) {
|
||||
TextComponent component = new TextComponent(prefix);
|
||||
component.setColor(ChatColor.YELLOW);
|
||||
@ -140,6 +144,8 @@ class PerformanceSummary {
|
||||
return component;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ParametersAreNonnullByDefault
|
||||
private String summarizeAsString(int count, String prefix, List<Entry<String, Long>> results, Function<Entry<String, Long>, String> formatter) {
|
||||
int shownEntries = 0;
|
||||
int hiddenEntries = 0;
|
||||
@ -169,6 +175,7 @@ class PerformanceSummary {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private String getPerformanceRating() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(NumberUtils.getColorFromPercentage(100 - Math.min(percentage, 100)));
|
||||
|
@ -6,6 +6,9 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -57,6 +60,7 @@ public class ElevatorPlate extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
};
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Set<UUID> getUsers() {
|
||||
return users;
|
||||
}
|
||||
@ -72,7 +76,8 @@ public class ElevatorPlate extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
};
|
||||
}
|
||||
|
||||
public List<Block> getFloors(Block b) {
|
||||
@Nonnull
|
||||
public List<Block> getFloors(@Nonnull Block b) {
|
||||
List<Block> floors = new LinkedList<>();
|
||||
|
||||
for (int y = b.getWorld().getMaxHeight(); y > 0; y--) {
|
||||
@ -91,19 +96,26 @@ public class ElevatorPlate extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
return floors;
|
||||
}
|
||||
|
||||
public void open(Player p, Block b) {
|
||||
@ParametersAreNonnullByDefault
|
||||
public void openInterface(Player p, Block b) {
|
||||
if (users.remove(p.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance());
|
||||
ChatComponent page = null;
|
||||
|
||||
List<Block> floors = getFloors(b);
|
||||
|
||||
if (floors.size() < 2) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "machines.ELEVATOR.no-destinations", true);
|
||||
}
|
||||
else {
|
||||
openFloorSelector(b, floors, p);
|
||||
}
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void openFloorSelector(Block b, List<Block> floors, Player p) {
|
||||
CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance());
|
||||
ChatComponent page = null;
|
||||
|
||||
for (int i = 0; i < floors.size(); i++) {
|
||||
if (i % 10 == 0) {
|
||||
@ -125,23 +137,7 @@ public class ElevatorPlate extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
else {
|
||||
line = new ChatComponent("\n" + ChatColor.GRAY + (floors.size() - i) + ". " + ChatColor.BLACK + floor);
|
||||
line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport")), "", ChatColor.WHITE + floor, ""));
|
||||
line.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance(), DATA_KEY + i), player -> Slimefun.runSync(() -> {
|
||||
users.add(player.getUniqueId());
|
||||
|
||||
float yaw = player.getEyeLocation().getYaw() + 180;
|
||||
|
||||
if (yaw > 180) {
|
||||
yaw = -180 + (yaw - 180);
|
||||
}
|
||||
|
||||
Location destination = new Location(player.getWorld(), block.getX() + 0.5, block.getY() + 0.4, block.getZ() + 0.5, yaw, player.getEyeLocation().getPitch());
|
||||
|
||||
PaperLib.teleportAsync(player, destination).thenAccept(teleported -> {
|
||||
if (teleported.booleanValue()) {
|
||||
player.sendTitle(ChatColor.WHITE + ChatColors.color(floor), null, 20, 60, 20);
|
||||
}
|
||||
});
|
||||
})));
|
||||
line.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance(), DATA_KEY + i), player -> teleport(player, floor, block)));
|
||||
}
|
||||
|
||||
page.append(line);
|
||||
@ -154,6 +150,28 @@ public class ElevatorPlate extends SimpleSlimefunItem<BlockUseHandler> {
|
||||
book.open(p);
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private void teleport(Player player, String floorName, Block target) {
|
||||
Slimefun.runSync(() -> {
|
||||
users.add(player.getUniqueId());
|
||||
|
||||
float yaw = player.getEyeLocation().getYaw() + 180;
|
||||
|
||||
if (yaw > 180) {
|
||||
yaw = -180 + (yaw - 180);
|
||||
}
|
||||
|
||||
Location destination = new Location(player.getWorld(), target.getX() + 0.5, target.getY() + 0.4, target.getZ() + 0.5, yaw, player.getEyeLocation().getPitch());
|
||||
|
||||
PaperLib.teleportAsync(player, destination).thenAccept(teleported -> {
|
||||
if (teleported.booleanValue()) {
|
||||
player.sendTitle(ChatColor.WHITE + ChatColors.color(floorName), null, 20, 60, 20);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public void openEditor(Player p, Block b) {
|
||||
ChestMenu menu = new ChestMenu("Elevator Settings");
|
||||
|
||||
|
@ -294,28 +294,33 @@ class ActiveMiner implements Runnable {
|
||||
|
||||
if (state instanceof Chest) {
|
||||
Inventory inv = ((Chest) state).getBlockInventory();
|
||||
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
for (MachineFuel fuelType : miner.fuelTypes) {
|
||||
ItemStack item = inv.getContents()[i];
|
||||
|
||||
if (fuelType.test(item)) {
|
||||
ItemUtils.consumeItem(item, false);
|
||||
|
||||
if (miner instanceof AdvancedIndustrialMiner) {
|
||||
inv.addItem(new ItemStack(Material.BUCKET));
|
||||
}
|
||||
|
||||
return fuelType.getTicks();
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumeFuel(inv);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int consumeFuel(Inventory inv) {
|
||||
for (int i = 0; i < inv.getSize(); i++) {
|
||||
for (MachineFuel fuelType : miner.fuelTypes) {
|
||||
ItemStack item = inv.getContents()[i];
|
||||
|
||||
if (fuelType.test(item)) {
|
||||
ItemUtils.consumeItem(item, false);
|
||||
|
||||
if (miner instanceof AdvancedIndustrialMiner) {
|
||||
inv.addItem(new ItemStack(Material.BUCKET));
|
||||
}
|
||||
|
||||
return fuelType.getTicks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void setPistonState(Block block, boolean extended) {
|
||||
if (!running) {
|
||||
return;
|
||||
|
@ -49,7 +49,8 @@ public class TeleporterListener implements Listener {
|
||||
}
|
||||
}
|
||||
else if (id.equals(SlimefunItems.ELEVATOR_PLATE.getItemId())) {
|
||||
((ElevatorPlate) SlimefunItems.ELEVATOR_PLATE.getItem()).open(e.getPlayer(), e.getClickedBlock());
|
||||
ElevatorPlate elevator = ((ElevatorPlate) SlimefunItems.ELEVATOR_PLATE.getItem());
|
||||
elevator.openInterface(e.getPlayer(), e.getClickedBlock());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.utils.itemstack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -28,7 +30,7 @@ public final class ItemStackWrapper extends ItemStack {
|
||||
private final int amount;
|
||||
private final boolean hasItemMeta;
|
||||
|
||||
public ItemStackWrapper(ItemStack item) {
|
||||
public ItemStackWrapper(@Nonnull ItemStack item) {
|
||||
super(item.getType());
|
||||
amount = item.getAmount();
|
||||
hasItemMeta = item.hasItemMeta();
|
||||
@ -108,7 +110,8 @@ public final class ItemStackWrapper extends ItemStack {
|
||||
*
|
||||
* @return An {@link ItemStackWrapper} array
|
||||
*/
|
||||
public static ItemStackWrapper[] wrapArray(ItemStack[] items) {
|
||||
@Nonnull
|
||||
public static ItemStackWrapper[] wrapArray(@Nonnull ItemStack[] items) {
|
||||
Validate.notNull(items, "The array must not be null!");
|
||||
ItemStackWrapper[] array = new ItemStackWrapper[items.length];
|
||||
|
||||
@ -129,7 +132,8 @@ public final class ItemStackWrapper extends ItemStack {
|
||||
*
|
||||
* @return An {@link ItemStackWrapper} array
|
||||
*/
|
||||
public static List<ItemStackWrapper> wrapList(List<ItemStack> items) {
|
||||
@Nonnull
|
||||
public static List<ItemStackWrapper> wrapList(@Nonnull List<ItemStack> items) {
|
||||
Validate.notNull(items, "The list must not be null!");
|
||||
List<ItemStackWrapper> list = new ArrayList<>(items.size());
|
||||
|
||||
|
@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.utils.itemstack;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -24,15 +26,13 @@ import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefu
|
||||
*/
|
||||
public class SlimefunGuideItem extends ItemStack {
|
||||
|
||||
public SlimefunGuideItem(SlimefunGuideImplementation implementation, String name) {
|
||||
public SlimefunGuideItem(@Nonnull SlimefunGuideImplementation implementation, @Nonnull String name) {
|
||||
super(Material.ENCHANTED_BOOK);
|
||||
|
||||
ItemMeta meta = getItemMeta();
|
||||
|
||||
meta.setDisplayName(ChatColors.color(name));
|
||||
|
||||
List<String> lore = new LinkedList<>();
|
||||
|
||||
lore.add(implementation instanceof CheatSheetSlimefunGuide ? "&4&lOnly openable by Admins" : "");
|
||||
lore.add(ChatColors.color("&eRight Click &8\u21E8 &7Browse Items"));
|
||||
lore.add(ChatColors.color("&eShift + Right Click &8\u21E8 &7Open Settings / Credits"));
|
||||
|
Loading…
Reference in New Issue
Block a user