mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
[CI skip] Merge pull request #1593 from WalshyDev/fix/performance-improvements
General performance improvements
This commit is contained in:
commit
106487b2e9
@ -4,6 +4,7 @@ import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -84,7 +85,7 @@ public class StatusEffect implements Keyed {
|
||||
Optional<String> optional = PersistentDataAPI.getOptionalString(p, getKey());
|
||||
|
||||
if (optional.isPresent()) {
|
||||
String[] data = optional.get().split(";");
|
||||
String[] data = PatternUtils.SEMICOLON.split(optional.get());
|
||||
long timestamp = Long.parseLong(data[1]);
|
||||
|
||||
if (timestamp == 0 || timestamp >= System.currentTimeMillis()) {
|
||||
@ -109,7 +110,7 @@ public class StatusEffect implements Keyed {
|
||||
Optional<String> optional = PersistentDataAPI.getOptionalString(p, getKey());
|
||||
|
||||
if (optional.isPresent()) {
|
||||
String[] data = optional.get().split(";");
|
||||
String[] data = PatternUtils.SEMICOLON.split(optional.get());
|
||||
return OptionalInt.of(Integer.parseInt(data[0]));
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -379,18 +380,18 @@ public final class SlimefunGuideSettings {
|
||||
String info = entry.getKey();
|
||||
|
||||
if (!info.startsWith("&")) {
|
||||
String[] segments = info.split(",");
|
||||
String[] segments = PatternUtils.COMMA.split(info);
|
||||
info = SlimefunPlugin.getLocal().getMessage(p, "guide.credits.roles." + segments[0]);
|
||||
|
||||
if (segments.length == 2) {
|
||||
info += " &7(" + SlimefunPlugin.getLocal().getMessage(p, "languages." + segments[1]) + ")";
|
||||
info += " &7(" + SlimefunPlugin.getLocal().getMessage(p, "languages." + segments[1]) + ')';
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.getValue() > 0) {
|
||||
String commits = SlimefunPlugin.getLocal().getMessage(p, "guide.credits." + (entry.getValue() > 1 ? "commits": "commit"));
|
||||
|
||||
info += " &7(" + entry.getValue() + " " + commits + ")";
|
||||
info += " &7(" + entry.getValue() + ' ' + commits + ')';
|
||||
}
|
||||
|
||||
lore.add(ChatColors.color(info));
|
||||
|
@ -230,7 +230,7 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation {
|
||||
|
||||
if (item.getItem().hasItemMeta() && item.getItem().getItemMeta().hasLore()) {
|
||||
for (String line : item.getItem().getItemMeta().getLore()) {
|
||||
tooltip.append("\n" + line);
|
||||
tooltip.append('\n').append(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -97,7 +98,7 @@ abstract class Android extends SlimefunItem {
|
||||
|
||||
public void openScript(Player p, Block b, String script) {
|
||||
ChestMenu menu = new ChestMenu(ChatColor.DARK_AQUA + SlimefunPlugin.getLocal().getMessage(p, "android.scripts.editor"));
|
||||
String[] commands = script.split("-");
|
||||
String[] commands = PatternUtils.DASH.split(script);
|
||||
|
||||
menu.addItem(0, new CustomItem(ScriptPart.START.getItem(), SlimefunPlugin.getLocal().getMessage(p, "android.scripts.instructions.START"), "", "&7\u21E8 &eLeft Click &7to return to the Android's interface"));
|
||||
menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
|
||||
@ -138,10 +139,10 @@ abstract class Android extends SlimefunItem {
|
||||
for (String command : commands) {
|
||||
if (j > 0) {
|
||||
if (j == index) {
|
||||
builder.append(commands[j] + "-");
|
||||
builder.append(commands[j] + "-");
|
||||
builder.append(commands[j]).append('-')
|
||||
.append(commands[j]).append('-');
|
||||
}
|
||||
else if (j < commands.length - 1) builder.append(command + "-");
|
||||
else if (j < commands.length - 1) builder.append(command).append('-');
|
||||
}
|
||||
j++;
|
||||
}
|
||||
@ -155,7 +156,7 @@ abstract class Android extends SlimefunItem {
|
||||
StringBuilder builder = new StringBuilder(ScriptPart.START + "-");
|
||||
|
||||
for (String command : commands) {
|
||||
if (j != index && j > 0 && j < commands.length - 1) builder.append(command + "-");
|
||||
if (j != index && j > 0 && j < commands.length - 1) builder.append(command).append('-');
|
||||
j++;
|
||||
}
|
||||
|
||||
@ -417,7 +418,7 @@ abstract class Android extends SlimefunItem {
|
||||
|
||||
protected void openScriptComponentEditor(Player p, Block b, String script, int index) {
|
||||
ChestMenu menu = new ChestMenu(ChatColor.DARK_AQUA + SlimefunPlugin.getLocal().getMessage(p, "android.scripts.editor"));
|
||||
String[] commands = script.split("-");
|
||||
String[] commands = PatternUtils.DASH.split(script);
|
||||
|
||||
ChestMenuUtils.drawBackground(menu, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
@ -426,7 +427,7 @@ abstract class Android extends SlimefunItem {
|
||||
StringBuilder builder = new StringBuilder("START-");
|
||||
|
||||
for (String command : commands) {
|
||||
if (i != index && i > 0 && i < commands.length - 1) builder.append(command + "-");
|
||||
if (i != index && i > 0 && i < commands.length - 1) builder.append(command).append('-');
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -445,8 +446,8 @@ abstract class Android extends SlimefunItem {
|
||||
|
||||
for (String command : commands) {
|
||||
if (j > 0) {
|
||||
if (j == index) builder.append(part.toString() + "-");
|
||||
else if (j < commands.length - 1) builder.append(command + "-");
|
||||
if (j == index) builder.append(part).append('-');
|
||||
else if (j < commands.length - 1) builder.append(command).append('-');
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
@ -252,7 +253,7 @@ public abstract class ProgrammableAndroid extends Android implements InventoryBl
|
||||
}
|
||||
}
|
||||
else {
|
||||
String[] script = BlockStorage.getLocationInfo(b.getLocation(), "script").split("-");
|
||||
String[] script = PatternUtils.DASH.split(BlockStorage.getLocationInfo(b.getLocation(), "script"));
|
||||
|
||||
int index = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "index")) + 1;
|
||||
if (index >= script.length) index = 0;
|
||||
|
@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -85,7 +86,8 @@ public class EnhancedCraftingTable extends MultiBlockMachine {
|
||||
for (String line : backpack.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7ID: ")) && line.contains("#")) {
|
||||
id = line.replace(ChatColor.translateAlternateColorCodes('&', "&7ID: "), "");
|
||||
PlayerProfile.fromUUID(UUID.fromString(id.split("#")[0])).getBackpack(Integer.parseInt(id.split("#")[1])).setSize(size);
|
||||
String[] idSplit = PatternUtils.HASH.split(id);
|
||||
PlayerProfile.fromUUID(UUID.fromString(idSplit[0])).getBackpack(Integer.parseInt(idSplit[1])).setSize(size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
@ -88,7 +89,8 @@ public class MagicWorkbench extends MultiBlockMachine {
|
||||
for (String line : backpack.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7ID: ")) && line.contains("#")) {
|
||||
id = line.replace(ChatColor.translateAlternateColorCodes('&', "&7ID: "), "");
|
||||
PlayerProfile.fromUUID(UUID.fromString(id.split("#")[0])).getBackpack(Integer.parseInt(id.split("#")[1])).setSize(size);
|
||||
String[] idSplit = PatternUtils.HASH.split(id);
|
||||
PlayerProfile.fromUUID(UUID.fromString(idSplit[0])).getBackpack(Integer.parseInt(idSplit[1])).setSize(size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetBootsTask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.JetpackTask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.MagnetTask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.ParachuteTask;
|
||||
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -21,48 +23,47 @@ import io.github.thebusybiscuit.slimefun4.implementation.tasks.ParachuteTask;
|
||||
|
||||
public class GearListener implements Listener {
|
||||
|
||||
public GearListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
public GearListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onToggleSneak(PlayerToggleSneakEvent e) {
|
||||
if (e.isSneaking()) {
|
||||
Player p = e.getPlayer();
|
||||
SlimefunItem chestplate = SlimefunItem.getByItem(p.getInventory().getChestplate());
|
||||
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
|
||||
|
||||
if (chestplate != null) {
|
||||
if (chestplate instanceof Jetpack) {
|
||||
if (Slimefun.hasUnlocked(p, chestplate, true)) {
|
||||
double thrust = ((Jetpack) chestplate).getThrust();
|
||||
@EventHandler
|
||||
public void onToggleSneak(PlayerToggleSneakEvent e) {
|
||||
if (!e.isSneaking()) return;
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (thrust > 0.2) {
|
||||
JetpackTask task = new JetpackTask(p, thrust);
|
||||
task.setID(Bukkit.getScheduler().scheduleSyncRepeatingTask(SlimefunPlugin.instance, task, 0L, 3L));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (chestplate.getID().equals("PARACHUTE") && Slimefun.hasUnlocked(p, chestplate, true)) {
|
||||
ParachuteTask task = new ParachuteTask(p);
|
||||
task.setID(Bukkit.getScheduler().scheduleSyncRepeatingTask(SlimefunPlugin.instance, task, 0L, 3L));
|
||||
}
|
||||
}
|
||||
|
||||
if (boots instanceof JetBoots && Slimefun.hasUnlocked(p, boots, true)) {
|
||||
double speed = ((JetBoots) boots).getSpeed();
|
||||
|
||||
if (speed > 0.2) {
|
||||
JetBootsTask task = new JetBootsTask(p, speed);
|
||||
task.setID(Bukkit.getScheduler().scheduleSyncRepeatingTask(SlimefunPlugin.instance, task, 0L, 2L));
|
||||
}
|
||||
}
|
||||
|
||||
if (SlimefunManager.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true)) {
|
||||
MagnetTask task = new MagnetTask(p);
|
||||
task.setID(Bukkit.getScheduler().scheduleSyncRepeatingTask(SlimefunPlugin.instance, task, 0L, 8L));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.getInventory().getChestplate() != null) {
|
||||
SlimefunItem chestplate = SlimefunItem.getByItem(p.getInventory().getChestplate());
|
||||
handleChestplate(p, chestplate);
|
||||
}
|
||||
|
||||
if (p.getInventory().getBoots() != null) {
|
||||
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
|
||||
handleBoots(p, boots);
|
||||
}
|
||||
|
||||
if (SlimefunManager.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true))
|
||||
new MagnetTask(p).scheduleRepeating(0, 8);
|
||||
}
|
||||
|
||||
private void handleChestplate(Player p, SlimefunItem chestplate) {
|
||||
if (chestplate == null || !Slimefun.hasUnlocked(p, chestplate, true)) return;
|
||||
|
||||
if (chestplate instanceof Jetpack) {
|
||||
double thrust = ((Jetpack) chestplate).getThrust();
|
||||
|
||||
if (thrust > 0.2)
|
||||
new JetpackTask(p, thrust).scheduleRepeating(0, 3);
|
||||
} else if (chestplate.getID().equals("PARACHUTE"))
|
||||
new ParachuteTask(p).scheduleRepeating(0, 3);
|
||||
}
|
||||
|
||||
private void handleBoots(Player p, SlimefunItem boots) {
|
||||
if (boots instanceof JetBoots && Slimefun.hasUnlocked(p, boots, true)) {
|
||||
double speed = ((JetBoots) boots).getSpeed();
|
||||
|
||||
if (speed > 0.2)
|
||||
new JetBootsTask(p, speed).scheduleRepeating(0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -138,7 +139,8 @@ public class TalismanListener implements Listener {
|
||||
}
|
||||
|
||||
String enchant = enchantments.get(random.nextInt(enchantments.size()));
|
||||
e.getEnchantsToAdd().put(Enchantment.getByKey(NamespacedKey.minecraft(enchant.split("-")[0])), Integer.parseInt(enchant.split("-")[1]));
|
||||
String[] enchantSplit = PatternUtils.DASH.split(enchant);
|
||||
e.getEnchantsToAdd().put(Enchantment.getByKey(NamespacedKey.minecraft(enchantSplit[0])), Integer.parseInt(enchantSplit[1]));
|
||||
}
|
||||
|
||||
if (!e.getEnchantsToAdd().containsKey(Enchantment.SILK_TOUCH) && Enchantment.LOOT_BONUS_BLOCKS.canEnchantItem(e.getItem()) && Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_WIZARD)) {
|
||||
|
@ -23,8 +23,8 @@ public class MagnetTask extends SlimefunTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isInvalid() {
|
||||
return super.isInvalid() || p.getGameMode() == GameMode.SPECTATOR;
|
||||
protected boolean isValid() {
|
||||
return super.isValid() && p.getGameMode() != GameMode.SPECTATOR;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.tasks;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -16,22 +17,29 @@ public abstract class SlimefunTask implements Runnable {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void schedule(long delay) {
|
||||
setID(Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, this, delay));
|
||||
}
|
||||
|
||||
public void scheduleRepeating(long delay, long interval) {
|
||||
setID(Bukkit.getScheduler().scheduleSyncRepeatingTask(SlimefunPlugin.instance, this, delay, interval));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isInvalid()) executeTask();
|
||||
if (isValid()) executeTask();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return True if task was cancelled.
|
||||
*/
|
||||
protected boolean isInvalid() {
|
||||
protected boolean isValid() {
|
||||
if (!p.isOnline() || !p.isValid() || p.isDead() || !p.isSneaking()) {
|
||||
Bukkit.getScheduler().cancelTask(id);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract void executeTask();
|
||||
|
@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
@ -276,7 +277,7 @@ public class TickerTask implements Runnable {
|
||||
.append(chunkItemCount.getOrDefault(entry.getKey(), 0))
|
||||
.append("x &7(")
|
||||
.append(toMillis(entry.getValue()))
|
||||
.append(")");
|
||||
.append(')');
|
||||
}
|
||||
else hidden++;
|
||||
}
|
||||
@ -303,8 +304,8 @@ public class TickerTask implements Runnable {
|
||||
}
|
||||
|
||||
private String formatChunk(String chunk) {
|
||||
String[] components = chunk.split(";");
|
||||
return components[0] + " [" + components[2] + "," + components[3] + "]";
|
||||
String[] components = PatternUtils.SEMICOLON.split(chunk);
|
||||
return components[0] + " [" + components[2] + ',' + components[3] + ']';
|
||||
}
|
||||
|
||||
public long getTimings(Block b) {
|
||||
|
@ -43,14 +43,14 @@ public final class ChatUtils {
|
||||
|
||||
String[] segments = string.toLowerCase().split("_");
|
||||
|
||||
builder.append(Character.toUpperCase(segments[0].charAt(0)));
|
||||
builder.append(segments[0].substring(1));
|
||||
builder.append(Character.toUpperCase(segments[0].charAt(0)))
|
||||
.append(segments[0].substring(1));
|
||||
|
||||
for (int i = 1; i < segments.length; i++) {
|
||||
String segment = segments[i];
|
||||
builder.append(" ");
|
||||
builder.append(Character.toUpperCase(segment.charAt(0)));
|
||||
builder.append(segment.substring(1));
|
||||
builder.append(' ')
|
||||
.append(Character.toUpperCase(segment.charAt(0)))
|
||||
.append(segment.substring(1));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
|
@ -35,11 +35,11 @@ public final class ChestMenuUtils {
|
||||
|
||||
private static final MenuClickHandler CLICK_HANDLER = (p, s, i, a) -> false;
|
||||
|
||||
public static final ItemStack getBackground() {
|
||||
public static ItemStack getBackground() {
|
||||
return UI_BACKGROUND;
|
||||
}
|
||||
|
||||
public static final MenuClickHandler getEmptyClickHandler() {
|
||||
public static MenuClickHandler getEmptyClickHandler() {
|
||||
return CLICK_HANDLER;
|
||||
}
|
||||
|
||||
@ -99,17 +99,17 @@ public final class ChestMenuUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateProgressbar(ChestMenu menu, int slot, int timeleft, int time, ItemStack indicator) {
|
||||
public static void updateProgressbar(ChestMenu menu, int slot, int timeLeft, int time, ItemStack indicator) {
|
||||
ItemStack item = indicator.clone();
|
||||
ItemMeta im = item.getItemMeta();
|
||||
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
|
||||
if (im instanceof Damageable) {
|
||||
((Damageable) im).setDamage(getDurability(item, timeleft, time));
|
||||
((Damageable) im).setDamage(getDurability(item, timeLeft, time));
|
||||
}
|
||||
|
||||
im.setDisplayName(" ");
|
||||
im.setLore(Arrays.asList(getProgressBar(timeleft, time), "", ChatColor.GRAY + NumberUtils.getTimeLeft(timeleft / 2) + " left"));
|
||||
im.setLore(Arrays.asList(getProgressBar(timeLeft, time), "", ChatColor.GRAY + NumberUtils.getTimeLeft(timeLeft / 2) + " left"));
|
||||
item.setItemMeta(im);
|
||||
|
||||
menu.replaceExistingItem(slot, item);
|
||||
@ -118,32 +118,32 @@ public final class ChestMenuUtils {
|
||||
public static String getProgressBar(int time, int total) {
|
||||
StringBuilder progress = new StringBuilder();
|
||||
float percentage = Math.round(((((total - time) * 100.0F) / total) * 100.0F) / 100.0F);
|
||||
|
||||
|
||||
if (percentage < 16.0F) progress.append("&4");
|
||||
else if (percentage < 32.0F) progress.append("&c");
|
||||
else if (percentage < 48.0F) progress.append("&6");
|
||||
else if (percentage < 64.0F) progress.append("&e");
|
||||
else if (percentage < 80.0F) progress.append("&2");
|
||||
else progress = progress.append("&a");
|
||||
|
||||
else progress.append("&a");
|
||||
|
||||
int rest = 20;
|
||||
for (int i = (int) percentage; i >= 5; i = i - 5) {
|
||||
progress.append(":");
|
||||
progress.append(':');
|
||||
rest--;
|
||||
}
|
||||
|
||||
progress.append("&7");
|
||||
|
||||
for (int i = 0; i < rest; i++) {
|
||||
progress.append(":");
|
||||
progress.append(':');
|
||||
}
|
||||
|
||||
progress.append(" - " + percentage + "%");
|
||||
progress.append(" - ").append(percentage).append('%');
|
||||
return ChatColors.color(progress.toString());
|
||||
}
|
||||
|
||||
private static short getDurability(ItemStack item, int timeleft, int max) {
|
||||
return (short) ((item.getType().getMaxDurability() / max) * timeleft);
|
||||
private static short getDurability(ItemStack item, int timeLeft, int max) {
|
||||
return (short) ((item.getType().getMaxDurability() / max) * timeLeft);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package io.github.thebusybiscuit.slimefun4.utils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* This class is created for common-use patterns used in things such as {@link String#split(String)}. <br />
|
||||
* Every time something like {@link String#split(String)} is called it will compile a {@link Pattern}, for code that is called
|
||||
* often this can be a massive performance loss. This class solves that, one compile but many uses!
|
||||
*/
|
||||
public final class PatternUtils {
|
||||
|
||||
private PatternUtils() {}
|
||||
|
||||
public static final Pattern SEMICOLON = Pattern.compile(";");
|
||||
public static final Pattern HASH = Pattern.compile("#");
|
||||
public static final Pattern COMMA = Pattern.compile(",");
|
||||
public static final Pattern SLASH_SEPARATOR = Pattern.compile(" / ");
|
||||
public static final Pattern DASH = Pattern.compile("-");
|
||||
}
|
@ -45,8 +45,7 @@ public class Research implements Keyed {
|
||||
/**
|
||||
* The constructor for a Research.
|
||||
*
|
||||
* Create a new research by calling {@link #Research(int, String, int)}, then
|
||||
* bind this research to the Slimefun items you want by calling
|
||||
* Create a new research, then bind this research to the Slimefun items you want by calling
|
||||
* {@link #addItems(SlimefunItem...)}. Once you're finished, call {@link #register()}
|
||||
* to register it.
|
||||
*
|
||||
@ -56,7 +55,7 @@ public class Research implements Keyed {
|
||||
* @param key A unique identifier for this research
|
||||
* @param id old way of identifying researches
|
||||
* @param name Display name of the research
|
||||
* @param cost Cost in XP levels to unlock the research
|
||||
* @param defaultCost Cost in XP levels to unlock the research
|
||||
*
|
||||
*/
|
||||
public Research(NamespacedKey key, int id, String name, int defaultCost) {
|
||||
@ -211,7 +210,7 @@ public class Research implements Keyed {
|
||||
public void register() {
|
||||
SlimefunPlugin.getResearchCfg().setDefaultValue("enable-researching", true);
|
||||
|
||||
String path = key.getNamespace() + "." + key.getKey();
|
||||
String path = key.getNamespace() + '.' + key.getKey();
|
||||
migrate(id, path);
|
||||
|
||||
if (SlimefunPlugin.getResearchCfg().contains(path + ".enabled") && !SlimefunPlugin.getResearchCfg().getBoolean(path + ".enabled")) {
|
||||
|
@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@ -69,12 +70,12 @@ public class BlockStorage {
|
||||
}
|
||||
|
||||
private static String serializeChunk(World world, int x, int z) {
|
||||
return world.getName() + ";Chunk;" + x + ";" + z;
|
||||
return world.getName() + ";Chunk;" + x + ';' + z;
|
||||
}
|
||||
|
||||
private static Location deserializeLocation(String l) {
|
||||
try {
|
||||
String[] components = l.split(";");
|
||||
String[] components = PatternUtils.SEMICOLON.split(l);
|
||||
if (components.length != 4) return null;
|
||||
|
||||
World w = Bukkit.getWorld(components[0]);
|
||||
@ -170,7 +171,7 @@ public class BlockStorage {
|
||||
|
||||
for (String key : cfg.getKeys(false)) {
|
||||
try {
|
||||
if (world.getName().equals(key.split(";")[0])) {
|
||||
if (world.getName().equals(PatternUtils.SEMICOLON.split(key)[0])) {
|
||||
SlimefunPlugin.getRegistry().getChunks().put(key, new BlockInfoConfig(parseJSON(cfg.getString(key))));
|
||||
}
|
||||
} catch (Exception x) {
|
||||
|
@ -13,6 +13,7 @@ import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -320,10 +321,11 @@ public final class PlayerProfile {
|
||||
String uuid = "";
|
||||
|
||||
for (String line : item.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7ID: ")) && line.contains("#")) {
|
||||
if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7ID: ")) && line.indexOf('#') != -1) {
|
||||
try {
|
||||
id = Optional.of(Integer.parseInt(line.split("#")[1]));
|
||||
uuid = line.split("#")[0].replace(ChatColor.translateAlternateColorCodes('&', "&7ID: "), "");
|
||||
String[] splitLine = PatternUtils.HASH.split(line);
|
||||
id = Optional.of(Integer.parseInt(splitLine[1]));
|
||||
uuid = splitLine[0].replace(ChatColor.translateAlternateColorCodes('&', "&7ID: "), "");
|
||||
} catch(NumberFormatException x) {
|
||||
return null;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package me.mrCookieSlime.Slimefun.api.energy;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -22,7 +23,7 @@ public final class ItemEnergy {
|
||||
|
||||
for (String line : item.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) {
|
||||
return Float.valueOf(line.split(" / ")[0].replace(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7"), ""));
|
||||
return Float.parseFloat(PatternUtils.SLASH_SEPARATOR.split(line)[0].replace(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7"), ""));
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +36,7 @@ public final class ItemEnergy {
|
||||
|
||||
for (String line : item.getItemMeta().getLore()) {
|
||||
if (line.startsWith(ChatColors.color("&c&o&8\u21E8 &e\u26A1 &7")) && line.contains(" / ") && line.endsWith(" J")) {
|
||||
return Float.valueOf(line.split(" / ")[1].replace(" J", ""));
|
||||
return Float.parseFloat(PatternUtils.SLASH_SEPARATOR.split(line)[1].replace(" J", ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user