1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Fixed /sf timings --verbose not working correctly (+refactoring)

This commit is contained in:
TheBusyBiscuit 2021-01-10 13:38:07 +01:00
parent 9ed1b3b651
commit 22b5421118
10 changed files with 179 additions and 93 deletions

View File

@ -43,6 +43,7 @@
* Fixed #2647
* Fixed #2664
* Fixed #2655
* Fixed /sf timings --verbose not working correctly
## Release Candidate 18 (03 Dec 2020)

View File

@ -397,6 +397,13 @@
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
</exclusion>
<exclusion>
<!-- We do not want to use the wrong TextComponents by -->
<!-- accident. If we use adventure, then we will add -->
<!-- it ourselves. -->
<groupId>net.kyori</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View File

@ -23,7 +23,6 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.api.events.WaypointCreateEvent;
import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource;
import io.github.thebusybiscuit.slimefun4.api.geo.ResourceManager;
@ -34,6 +33,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitte
import io.github.thebusybiscuit.slimefun4.implementation.items.gps.Teleporter;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
@ -157,7 +157,7 @@ public class GPSNetwork {
if (sfi instanceof GPSTransmitter) {
int slot = inventory[index];
menu.addItem(slot, new CustomItem(SlimefunItems.GPS_TRANSMITTER, "&bGPS Transmitter", "&8\u21E8 &7World: &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "", "&8\u21E8 &7Signal Strength: &f" + ((GPSTransmitter) sfi).getMultiplier(l.getBlockY()), "&8\u21E8 &7Ping: &f" + DoubleHandler.fixDouble(1000D / l.getY()) + "ms"));
menu.addItem(slot, new CustomItem(SlimefunItems.GPS_TRANSMITTER, "&bGPS Transmitter", "&8\u21E8 &7World: &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "", "&8\u21E8 &7Signal Strength: &f" + ((GPSTransmitter) sfi).getMultiplier(l.getBlockY()), "&8\u21E8 &7Ping: &f" + NumberUtils.roundDecimalNumber(1000D / l.getY()) + "ms"));
menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler());
index++;

View File

@ -20,11 +20,11 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
@ -64,7 +64,7 @@ public final class TeleportationManager {
int slot = teleporterInventory[index];
Location l = waypoint.getLocation();
double time = DoubleHandler.fixDouble(0.5 * getTeleportationTime(complexity, source, l));
double time = NumberUtils.reparseDouble(0.5 * getTeleportationTime(complexity, source, l));
String[] lore = { "", "&8\u21E8 &7" + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.world") + ": &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "&8\u21E8 &7" + SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.gui.time") + ": &f" + time + "s", "", "&8\u21E8 &c" + SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.gui.tooltip") };

View File

@ -31,10 +31,10 @@ import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.api.network.Network;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -365,7 +365,7 @@ abstract class AbstractItemNetwork extends Network {
ItemMeta im = stack.getItemMeta();
List<String> lore = new ArrayList<>();
lore.add("");
lore.add(ChatColors.color("&7Stored Items: &f" + DoubleHandler.getFancyDouble(item.getInt())));
lore.add(ChatColors.color("&7Stored Items: &f" + NumberUtils.getCompactDouble(item.getInt())));
if (stack.getMaxStackSize() > 1) {
int amount = item.getInt() > stack.getMaxStackSize() ? stack.getMaxStackSize() : item.getInt();

View File

@ -23,10 +23,10 @@ import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.core.services.localization.Language;
import io.github.thebusybiscuit.slimefun4.core.services.localization.SlimefunLocalization;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import me.mrCookieSlime.Slimefun.api.Slimefun;
/**
@ -245,13 +245,15 @@ public class LocalizationService extends SlimefunLocalization {
}
}
return Math.min(DoubleHandler.fixDouble(100.0 * (matches / (double) defaultKeys.size())), 100.0);
return Math.min(NumberUtils.reparseDouble(100.0 * (matches / (double) defaultKeys.size())), 100.0);
}
@Nonnull
private Set<String> getTotalKeys(@Nonnull Language lang) {
return getKeys(lang.getFiles());
}
@Nonnull
private Set<String> getKeys(FileConfiguration... files) {
Set<String> keys = new HashSet<>();

View File

@ -152,7 +152,7 @@ class PerformanceSummary {
builder.append(ChatColor.YELLOW);
for (Map.Entry<String, Long> entry : results) {
if (!inspector.isVerbose() || (shownEntries < MAX_ITEMS && (shownEntries < MIN_ITEMS || entry.getValue() > VISIBILITY_THRESHOLD))) {
if (inspector.isVerbose() || (shownEntries < MAX_ITEMS && (shownEntries < MIN_ITEMS || entry.getValue() > VISIBILITY_THRESHOLD))) {
builder.append("\n ");
builder.append(ChatColor.stripColor(formatter.apply(entry)));
shownEntries++;

View File

@ -333,8 +333,12 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
}), 0);
// Setting up the command /sf and all subcommands
command.register();
// Setting up our commands
try {
command.register();
} catch (Exception | LinkageError x) {
getLogger().log(Level.SEVERE, "An Exception occurred while registering the /slimefun command", x);
}
// Armor Update Task
if (config.getBoolean("options.enable-armor-effects")) {
@ -353,6 +357,16 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
getLogger().log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp));
}
@Override
public JavaPlugin getJavaPlugin() {
return this;
}
@Override
public String getBugTrackerURL() {
return "https://github.com/Slimefun/Slimefun4/issues";
}
/**
* This method gets called when the {@link Plugin} gets disabled.
* Most often it is called when the {@link Server} is shutting down or reloading.
@ -656,6 +670,19 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
}
}
/**
* This private static method allows us to throw a proper {@link Exception}
* whenever someone tries to access a static method while the instance is null.
* This happens when the method is invoked before {@link #onEnable()} or after {@link #onDisable()}.
* <p>
* Use it whenever a null check is needed to avoid a non-descriptive {@link NullPointerException}.
*/
private static void validateInstance() {
if (instance == null) {
throw new IllegalStateException("Cannot invoke static method, Slimefun instance is null.");
}
}
/**
* This returns the global instance of {@link SlimefunPlugin}.
* This may return null if the {@link Plugin} was disabled.
@ -667,69 +694,97 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return instance;
}
public static Config getCfg() {
return instance.config;
}
public static Config getResearchCfg() {
return instance.researches;
}
public static Config getItemCfg() {
return instance.items;
}
public static GPSNetwork getGPSNetwork() {
return instance.gpsNetwork;
}
public static TickerTask getTickerTask() {
return instance.ticker;
}
/**
* This returns the version of Slimefun that is currently installed.
*
* @return The currently installed version of Slimefun
*/
@Nonnull
public static String getVersion() {
validateInstance();
return instance.getDescription().getVersion();
}
@Nonnull
public static Config getCfg() {
validateInstance();
return instance.config;
}
@Nonnull
public static Config getResearchCfg() {
validateInstance();
return instance.researches;
}
@Nonnull
public static Config getItemCfg() {
validateInstance();
return instance.items;
}
@Nonnull
public static GPSNetwork getGPSNetwork() {
validateInstance();
return instance.gpsNetwork;
}
@Nonnull
public static TickerTask getTickerTask() {
validateInstance();
return instance.ticker;
}
/**
* This returns the {@link LocalizationService} of Slimefun.
*
* @return The {@link LocalizationService} of Slimefun
*/
@Nonnull
public static LocalizationService getLocalization() {
validateInstance();
return instance.local;
}
@Nonnull
public static ProtectionManager getProtectionManager() {
validateInstance();
return instance.protections;
}
@Nonnull
public static MinecraftRecipeService getMinecraftRecipeService() {
validateInstance();
return instance.recipeService;
}
@Nonnull
public static CustomItemDataService getItemDataService() {
validateInstance();
return instance.itemDataService;
}
@Nonnull
public static CustomTextureService getItemTextureService() {
validateInstance();
return instance.textureService;
}
@Nonnull
public static PermissionsService getPermissionsService() {
validateInstance();
return instance.permissionsService;
}
@Nonnull
public static BlockDataService getBlockDataService() {
validateInstance();
return instance.blockDataService;
}
@Nonnull
public static PerWorldSettingsService getWorldSettingsService() {
validateInstance();
return instance.worldSettingsService;
}
@ -753,6 +808,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*/
@Nonnull
public static IntegrationsManager getIntegrations() {
validateInstance();
return instance.integrations;
}
@ -762,7 +818,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*
* @return The {@link UpdaterService} for Slimefun
*/
@Nonnull
public static UpdaterService getUpdater() {
validateInstance();
return instance.updaterService;
}
@ -772,7 +830,9 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*
* @return The {@link MetricsService} for Slimefun
*/
@Nonnull
public static MetricsService getMetricsService() {
validateInstance();
return instance.metricsService;
}
@ -782,30 +842,99 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*
* @return The {@link GitHubService} for Slimefun
*/
@Nonnull
public static GitHubService getGitHubService() {
validateInstance();
return instance.gitHubService;
}
@Nonnull
public static SlimefunRegistry getRegistry() {
validateInstance();
return instance.registry;
}
@Nonnull
public static NetworkManager getNetworkManager() {
validateInstance();
return instance.networkManager;
}
@Nonnull
public static GrapplingHookListener getGrapplingHookListener() {
validateInstance();
return instance.grapplingHookListener;
}
@Nonnull
public static BackpackListener getBackpackListener() {
validateInstance();
return instance.backpackListener;
}
@Nonnull
public static SlimefunBowListener getBowListener() {
validateInstance();
return instance.bowListener;
}
/**
* The {@link Command} that was added by Slimefun.
*
* @return Slimefun's command
*/
@Nonnull
public static SlimefunCommand getCommand() {
validateInstance();
return instance.command;
}
/**
* This returns our instance of the {@link SlimefunProfiler}, a tool that is used
* to analyse performance and lag.
*
* @return The {@link SlimefunProfiler}
*/
@Nonnull
public static SlimefunProfiler getProfiler() {
validateInstance();
return instance.profiler;
}
/**
* This returns the currently installed version of Minecraft.
*
* @return The current version of Minecraft
*/
@Nonnull
public static MinecraftVersion getMinecraftVersion() {
validateInstance();
return instance.minecraftVersion;
}
/**
* This method returns whether this version of Slimefun was newly installed.
* It will return true if this {@link Server} uses Slimefun for the very first time.
*
* @return Whether this is a new installation of Slimefun
*/
public static boolean isNewlyInstalled() {
validateInstance();
return instance.isNewlyInstalled;
}
@Nonnull
public static String getCSCoreLibVersion() {
validateInstance();
Plugin cscorelib = instance.getServer().getPluginManager().getPlugin("CS-CoreLib");
if (cscorelib == null) {
throw new IllegalStateException("CS-CoreLib is not installed.");
} else {
return cscorelib.getDescription().getVersion();
}
}
/**
* This method returns a {@link Set} of every {@link Plugin} that lists Slimefun
* as a required or optional dependency.
@ -816,6 +945,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*/
@Nonnull
public static Set<Plugin> getInstalledAddons() {
validateInstance();
String pluginName = instance.getName();
// @formatter:off
@ -827,65 +958,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
// @formatter:on
}
/**
* The {@link Command} that was added by Slimefun.
*
* @return Slimefun's command
*/
public static SlimefunCommand getCommand() {
return instance.command;
}
/**
* This returns our instance of the {@link SlimefunProfiler}, a tool that is used
* to analyse performance and lag.
*
* @return The {@link SlimefunProfiler}
*/
public static SlimefunProfiler getProfiler() {
return instance.profiler;
}
/**
* This returns the currently installed version of Minecraft.
*
* @return The current version of Minecraft
*/
public static MinecraftVersion getMinecraftVersion() {
return instance.minecraftVersion;
}
/**
* This method returns whether this version of Slimefun was newly installed.
* It will return true if this {@link Server} uses Slimefun for the very first time.
*
* @return Whether this is a new installation of Slimefun
*/
public static boolean isNewlyInstalled() {
return instance.isNewlyInstalled;
}
@Nonnull
public static String getCSCoreLibVersion() {
Plugin cscorelib = instance.getServer().getPluginManager().getPlugin("CS-CoreLib");
if (cscorelib == null) {
throw new IllegalStateException("CS-CoreLib is not installed.");
} else {
return cscorelib.getDescription().getVersion();
}
}
@Override
public JavaPlugin getJavaPlugin() {
return this;
}
@Override
public String getBugTrackerURL() {
return "https://github.com/Slimefun/Slimefun4/issues";
}
/**
* This method schedules a delayed synchronous task for Slimefun.
* <strong>For Slimefun only, not for addons.</strong>
@ -945,4 +1017,4 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return instance.getServer().getScheduler().runTask(instance, runnable);
}
}
}

View File

@ -228,6 +228,10 @@ public final class NumberUtils {
return DECIMAL_FORMAT.format(number);
}
public static double reparseDouble(double number) {
return Double.valueOf(roundDecimalNumber(number));
}
public static long getLong(@Nullable Long value, long defaultValue) {
return value == null ? defaultValue : value;
}

View File

@ -32,8 +32,8 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -168,7 +168,7 @@ public class BlockStorage {
Slimefun.getLogger().log(Level.INFO, "Loaded a total of {0} Blocks for World \"{1}\"", new Object[] { totalBlocks, world.getName() });
if (totalBlocks > 0) {
Slimefun.getLogger().log(Level.INFO, "Avg: {0}ms/Block", DoubleHandler.fixDouble((double) time / (double) totalBlocks, 3));
Slimefun.getLogger().log(Level.INFO, "Avg: {0}ms/Block", NumberUtils.roundDecimalNumber((double) time / (double) totalBlocks));
}
}
}