added gui
This commit is contained in:
Binary file not shown.
@@ -5,3 +5,20 @@ api-version: 1.17
|
||||
authors: [ ImproperIssues ]
|
||||
description: Manager server explosions with just a few simple clicks!
|
||||
website: github.com/ItziSpyder
|
||||
permissions:
|
||||
exc.commands.updateworlds:
|
||||
description: Command access
|
||||
default: op
|
||||
exc.commands.configworlds:
|
||||
description: Command access
|
||||
default: op
|
||||
commands:
|
||||
updateworlds:
|
||||
description: Update all world explosion configs
|
||||
usage: /updateworlds
|
||||
permission: exc.commands.updateworlds
|
||||
configworld:
|
||||
description: Config world explosion configs
|
||||
usage: /configworld <world>
|
||||
permission: exc.commands.configworld
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,8 +1,13 @@
|
||||
package io.github.itzispyder.explosionscontrol;
|
||||
|
||||
import io.github.itzispyder.explosionscontrol.commands.BukkitCommand;
|
||||
import io.github.itzispyder.explosionscontrol.commands.commands.ConfigWorldCommand;
|
||||
import io.github.itzispyder.explosionscontrol.commands.commands.UpdateWorldsCommand;
|
||||
import io.github.itzispyder.explosionscontrol.data.ExplosionConfig;
|
||||
import io.github.itzispyder.explosionscontrol.events.InventoryListener;
|
||||
import io.github.itzispyder.explosionscontrol.utils.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
@@ -10,12 +15,14 @@ import java.util.logging.Logger;
|
||||
public final class ExplosionsControl extends JavaPlugin {
|
||||
|
||||
public static final Logger logger = Bukkit.getLogger();
|
||||
public static final String starter = Text.color("&7[&6Ex&eC&7] &r");
|
||||
public static final PluginManager pm = Bukkit.getPluginManager();
|
||||
public static final String starter = Text.color("&7[&6Ex&eC&7]&r ");
|
||||
public static ExplosionsControl instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
this.init();
|
||||
ExplosionConfig.updateAllWorlds();
|
||||
}
|
||||
|
||||
@@ -23,4 +30,18 @@ public final class ExplosionsControl extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
ExplosionConfig.updateAllWorlds();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
// listeners
|
||||
pm.registerEvents(new InventoryListener(), this);
|
||||
|
||||
// commands
|
||||
addCommand(new UpdateWorldsCommand());
|
||||
addCommand(new ConfigWorldCommand());
|
||||
}
|
||||
|
||||
public void addCommand(BukkitCommand command) {
|
||||
getCommand(command.getName()).setExecutor(command);
|
||||
getCommand(command.getName()).setTabCompleter(command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.github.itzispyder.explosionscontrol.commands;
|
||||
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
public interface BukkitCommand extends TabExecutor {
|
||||
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.github.itzispyder.explosionscontrol.commands.commands;
|
||||
|
||||
import io.github.itzispyder.explosionscontrol.commands.BukkitCommand;
|
||||
import io.github.itzispyder.explosionscontrol.commands.CmdExHandler;
|
||||
import io.github.itzispyder.explosionscontrol.commands.TabComplBuilder;
|
||||
import io.github.itzispyder.explosionscontrol.data.ExplosionConfig;
|
||||
import io.github.itzispyder.explosionscontrol.data.ExplosionGui;
|
||||
import io.github.itzispyder.explosionscontrol.utils.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigWorldCommand implements BukkitCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "configworld";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
try {
|
||||
Player player = (Player)sender;
|
||||
World world = Bukkit.getWorld(args[0]);
|
||||
ExplosionConfig config = ExplosionConfig.load(world);
|
||||
ExplosionGui gui = new ExplosionGui(config);
|
||||
|
||||
player.openInventory(gui.loadGui());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
CmdExHandler handler = new CmdExHandler(ex, command);
|
||||
sender.sendMessage(handler.getHelp());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return new TabComplBuilder(sender, command, alias, args)
|
||||
.add(1, ArrayUtils.toNewList(Bukkit.getWorlds(), World::getName))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.github.itzispyder.explosionscontrol.commands.commands;
|
||||
|
||||
import io.github.itzispyder.explosionscontrol.commands.BukkitCommand;
|
||||
import io.github.itzispyder.explosionscontrol.commands.CmdExHandler;
|
||||
import io.github.itzispyder.explosionscontrol.data.ExplosionConfig;
|
||||
import io.github.itzispyder.explosionscontrol.utils.Text;
|
||||
import io.github.itzispyder.explosionscontrol.utils.Timer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UpdateWorldsCommand implements BukkitCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
try {
|
||||
Timer timer = Timer.start();
|
||||
ExplosionConfig.updateAllWorlds();
|
||||
Timer.End end = timer.end();
|
||||
|
||||
sender.sendMessage(Text.ofAll("&eUpdated all world configs, took &7" + end.getStampPrecise()));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
CmdExHandler handler = new CmdExHandler(ex, command);
|
||||
sender.sendMessage(handler.getHelp());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "updateworlds";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package io.github.itzispyder.explosionscontrol.data;
|
||||
|
||||
import io.github.itzispyder.explosionscontrol.utils.ItemPresets;
|
||||
import io.github.itzispyder.explosionscontrol.utils.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static io.github.itzispyder.explosionscontrol.ExplosionsControl.starter;
|
||||
|
||||
public class ExplosionGui {
|
||||
|
||||
public final ExplosionConfig config;
|
||||
|
||||
public ExplosionGui(ExplosionConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public Inventory loadGui() {
|
||||
String title = Text.color(starter + config.getWorld().getName());
|
||||
Inventory inv = Bukkit.createInventory(null, 54, title);
|
||||
ItemStack x = ItemPresets.GUI_BLANK;
|
||||
ItemStack o = ItemPresets.GUI_BORDER;
|
||||
ItemStack f = ItemPresets.GUI_FLOOR;
|
||||
|
||||
ItemStack minecartMode = ItemBuilder.create()
|
||||
.material(Material.TNT_MINECART)
|
||||
.name(config.getMinecartMode().getDisplay())
|
||||
.build();
|
||||
ItemStack tntMode = ItemBuilder.create()
|
||||
.material(Material.TNT)
|
||||
.name(config.getTntMode().getDisplay())
|
||||
.build();
|
||||
ItemStack crystalMode = ItemBuilder.create()
|
||||
.material(Material.END_CRYSTAL)
|
||||
.name(config.getCrystalMode().getDisplay())
|
||||
.build();
|
||||
ItemStack creeperMode = ItemBuilder.create()
|
||||
.material(Material.CREEPER_HEAD)
|
||||
.name(config.getCreeperMode().getDisplay())
|
||||
.build();
|
||||
ItemStack witherMode = ItemBuilder.create()
|
||||
.material(Material.WITHER_SKELETON_SKULL)
|
||||
.name(config.getWitherMode().getDisplay())
|
||||
.build();
|
||||
ItemStack fireballMode = ItemBuilder.create()
|
||||
.material(Material.FIRE_CHARGE)
|
||||
.name(config.getFireballMode().getDisplay())
|
||||
.build();
|
||||
ItemStack blockMode = ItemBuilder.create()
|
||||
.material(Material.RESPAWN_ANCHOR)
|
||||
.name(config.getBlockMode().getDisplay())
|
||||
.build();
|
||||
|
||||
inv.setContents(new ItemStack[]{
|
||||
o,o,o,o,o,o,o,o,o,
|
||||
o,x,x,x,x,x,x,x,o,
|
||||
o,minecartMode,x,tntMode,x,witherMode,x,fireballMode,o,
|
||||
o,x,creeperMode,x,crystalMode,x,blockMode,x,o,
|
||||
o,x,x,x,x,x,x,x,o,
|
||||
f,f,f,f,f,f,f,f,f
|
||||
});
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onInventoryClick(InventoryClickEvent e) {
|
||||
Inventory inv = e.getClickedInventory();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package io.github.itzispyder.explosionscontrol.data;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
private ItemStack stack;
|
||||
private ItemMeta meta;
|
||||
|
||||
public ItemBuilder() {
|
||||
this(new ItemStack(Material.STONE));
|
||||
}
|
||||
|
||||
public ItemBuilder(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
this.meta = this.stack.getItemMeta();
|
||||
}
|
||||
|
||||
public ItemBuilder material(Material m) {
|
||||
stack.setType(m);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder name(String s) {
|
||||
meta.setDisplayName(s);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder lore(String s) {
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
lore.add(s);
|
||||
meta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder lore(Iterable<String> s) {
|
||||
s.forEach(this::lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder count(int c) {
|
||||
stack.setAmount(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder enchant(Enchantment e, int level) {
|
||||
meta.addEnchant(e,level,true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder flag(ItemFlag... f) {
|
||||
meta.addItemFlags(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder attribute(Attribute a, AttributeModifier am) {
|
||||
meta.addAttributeModifier(a,am);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder unbreakable(boolean b) {
|
||||
meta.setUnbreakable(b);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder customModelData(int d) {
|
||||
meta.setCustomModelData(d);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder runTaskItem(Function<ItemStack, ItemStack> task) {
|
||||
this.stack = task.apply(build());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder runTaskMeta(Function<ItemMeta, ItemMeta> task) {
|
||||
this.meta = task.apply(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemBuilder create() {
|
||||
return new ItemBuilder();
|
||||
}
|
||||
|
||||
public static ItemBuilder create(ItemStack item) {
|
||||
return new ItemBuilder(item);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,52 @@
|
||||
package io.github.itzispyder.explosionscontrol.data;
|
||||
|
||||
import io.github.itzispyder.explosionscontrol.utils.StringUtils;
|
||||
import io.github.itzispyder.explosionscontrol.utils.Text;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum Mode {
|
||||
|
||||
ENABLED,
|
||||
DISABLED,
|
||||
NONE,
|
||||
DYNAMIC
|
||||
ENABLED("✔", 0),
|
||||
DISABLED("✘", 1),
|
||||
NONE("◯", 2),
|
||||
DYNAMIC("☀", 3);
|
||||
|
||||
private final String name;
|
||||
private final int id;
|
||||
|
||||
Mode(String name, int id) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Mode next() {
|
||||
int i = id + 1;
|
||||
i = i >= values().length ? 0 : i;
|
||||
return fromId(i);
|
||||
}
|
||||
|
||||
public static Mode fromId(int id) {
|
||||
return Arrays.stream(values()).filter(m -> m.id == id).toList().get(0);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
String pre;
|
||||
switch (this) {
|
||||
case NONE -> pre = "&7";
|
||||
case DYNAMIC -> pre = "&6";
|
||||
case DISABLED -> pre = "&c";
|
||||
case ENABLED -> pre = "&a";
|
||||
default -> pre = "&8";
|
||||
}
|
||||
return Text.color("&f" + StringUtils.capitalize(name()) + " " + pre + name);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package io.github.itzispyder.explosionscontrol.events;
|
||||
|
||||
import io.github.itzispyder.explosionscontrol.data.ExplosionConfig;
|
||||
import io.github.itzispyder.explosionscontrol.data.ExplosionGui;
|
||||
import io.github.itzispyder.explosionscontrol.utils.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static io.github.itzispyder.explosionscontrol.ExplosionsControl.starter;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
private void onInvClick(InventoryClickEvent e) {
|
||||
try {
|
||||
this.handleConfigGui(e);
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleConfigGui(InventoryClickEvent e) {
|
||||
String title = e.getView().getTitle();
|
||||
ItemStack item = e.getCurrentItem();
|
||||
Player p = (Player)e.getWhoClicked();
|
||||
|
||||
if (title.contains(starter) && item != null) {
|
||||
e.setCancelled(true);
|
||||
String name = title.split(" ")[title.split(" ").length - 1];
|
||||
World world = Bukkit.getWorld(name);
|
||||
|
||||
if (world == null) {
|
||||
p.closeInventory();
|
||||
p.sendMessage("matching worlds: " + p.getWorld().getName().equals(name));
|
||||
p.sendMessage(Text.ofAll("&cWorld &7\"" + name + "&7\" &cis not found!"));
|
||||
return;
|
||||
}
|
||||
|
||||
ExplosionConfig config = ExplosionConfig.load(world);
|
||||
ExplosionGui gui = new ExplosionGui(config);
|
||||
|
||||
switch (item.getType()) {
|
||||
case END_CRYSTAL -> {
|
||||
config.setCrystalMode(config.getCrystalMode().next());
|
||||
config.save();
|
||||
p.openInventory(gui.loadGui());
|
||||
}
|
||||
case TNT_MINECART -> {
|
||||
config.setMinecartMode(config.getMinecartMode().next());
|
||||
config.save();
|
||||
p.openInventory(gui.loadGui());
|
||||
}
|
||||
case TNT -> {
|
||||
config.setTntMode(config.getTntMode().next());
|
||||
config.save();
|
||||
p.openInventory(gui.loadGui());
|
||||
}
|
||||
case FIRE_CHARGE -> {
|
||||
config.setFireballMode(config.getFireballMode().next());
|
||||
config.save();
|
||||
p.openInventory(gui.loadGui());
|
||||
}
|
||||
case WITHER_SKELETON_SKULL -> {
|
||||
config.setWitherMode(config.getWitherMode().next());
|
||||
config.save();
|
||||
p.openInventory(gui.loadGui());
|
||||
}
|
||||
case CREEPER_HEAD -> {
|
||||
config.setCreeperMode(config.getCreeperMode().next());
|
||||
config.save();
|
||||
p.openInventory(gui.loadGui());
|
||||
}
|
||||
case RESPAWN_ANCHOR -> {
|
||||
config.setBlockMode(config.getBlockMode().next());
|
||||
config.save();
|
||||
p.openInventory(gui.loadGui());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.github.itzispyder.explosionscontrol.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class ArrayUtils {
|
||||
|
||||
/**
|
||||
* Transforms an array to another one
|
||||
* @param e iterable list
|
||||
* @param a action
|
||||
* @return new transformed list
|
||||
* @param <I> input
|
||||
* @param <O> output
|
||||
*/
|
||||
public static <I,O> List<O> toNewList(Iterable<I> e, Function<I,O> a) {
|
||||
List<O> list = new ArrayList<>();
|
||||
e.forEach(i -> list.add(a.apply(i)));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static <T> String list2string(List<T> list) {
|
||||
return Text.color("&7[&e" + String.join("&7, &e", ArrayUtils.toNewList(list, Object::toString)) + "&7]");
|
||||
}
|
||||
|
||||
public static <T> List<T> bind(Iterable<T> tList, T... ts) {
|
||||
List<T> list = Arrays.asList(ts);
|
||||
tList.forEach(list::add);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class Constants {
|
||||
public static final List<String> MATERIAL_NAMES = toNewList(Arrays.stream(Material.values()).toList(),m -> m.name().toLowerCase());
|
||||
public static final List<String> ENTITY_NAMES = toNewList(Arrays.stream(EntityType.values()).toList(),e -> e.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.github.itzispyder.explosionscontrol.utils;
|
||||
|
||||
import io.github.itzispyder.explosionscontrol.data.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class ItemPresets {
|
||||
|
||||
public static final ItemStack GUI_BLANK = ItemBuilder.create()
|
||||
.material(Material.GRAY_STAINED_GLASS_PANE)
|
||||
.name(" ")
|
||||
.build();
|
||||
|
||||
public static final ItemStack GUI_BORDER = ItemBuilder.create()
|
||||
.material(Material.YELLOW_STAINED_GLASS_PANE)
|
||||
.name(" ")
|
||||
.build();
|
||||
|
||||
public static final ItemStack GUI_FILL = ItemBuilder.create()
|
||||
.material(Material.BLACK_STAINED_GLASS_PANE)
|
||||
.name(" ")
|
||||
.build();
|
||||
|
||||
public static final ItemStack GUI_FLOOR = ItemBuilder.create()
|
||||
.material(Material.ORANGE_STAINED_GLASS_PANE)
|
||||
.name(" ")
|
||||
.build();
|
||||
|
||||
public static final ItemStack GUI_RESET = ItemBuilder.create()
|
||||
.material(Material.COMPASS)
|
||||
.name(Text.color("&bReset"))
|
||||
.lore(Text.color("&7- Click to reset"))
|
||||
.build();
|
||||
|
||||
public static final ItemStack AIR = ItemBuilder.create()
|
||||
.material(Material.AIR)
|
||||
.build();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.github.itzispyder.explosionscontrol.utils;
|
||||
|
||||
public final class StringUtils {
|
||||
|
||||
public static String capitalize(String s) {
|
||||
if (s.length() == 1) return s.toUpperCase();
|
||||
s = s.toLowerCase();
|
||||
return String.valueOf(s.charAt(0)).toUpperCase() + s.substring(1);
|
||||
}
|
||||
|
||||
public static String capitalizeWords(String s) {
|
||||
s = s.replaceAll("[_-]"," ");
|
||||
String[] sArray = s.split(" ");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String str : sArray) sb.append(capitalize(str)).append(" ");
|
||||
return sb.toString().trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package io.github.itzispyder.explosionscontrol.utils;
|
||||
|
||||
public class Timer {
|
||||
|
||||
public static final long MILLIS_IN_SECOND = 1000L;
|
||||
public static final long MILLIS_IN_MINUTE = MILLIS_IN_SECOND * 60L;
|
||||
public static final long MILLIS_IN_HOUR = MILLIS_IN_MINUTE * 60L;
|
||||
public static final long MILLIS_IN_DAY = MILLIS_IN_HOUR * 24L;
|
||||
private long start;
|
||||
|
||||
private Timer() {
|
||||
this.start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static Timer start() {
|
||||
return new Timer();
|
||||
}
|
||||
|
||||
public static End zero() {
|
||||
return new End(0);
|
||||
}
|
||||
|
||||
public End end() {
|
||||
return new End(start);
|
||||
}
|
||||
|
||||
|
||||
public static class End {
|
||||
|
||||
private final long start;
|
||||
private final long end;
|
||||
|
||||
private End(long start) {
|
||||
this.end = System.currentTimeMillis();
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public long timePassed() {
|
||||
return end - start;
|
||||
}
|
||||
|
||||
public String getStamp(boolean day, boolean hr, boolean min, boolean sec, boolean ms) {
|
||||
long time = timePassed();
|
||||
String stamp = "";
|
||||
|
||||
if (day) {
|
||||
long l = (long)Math.floor((double)time / (double)MILLIS_IN_DAY);
|
||||
time -= l * MILLIS_IN_DAY;
|
||||
if (l > 0L) stamp += l + "d";
|
||||
}
|
||||
if (hr) {
|
||||
long l = (long)Math.floor((double)time / (double)MILLIS_IN_HOUR);
|
||||
time -= l * MILLIS_IN_HOUR;
|
||||
if (l > 0L) stamp += " " + l + "hr";
|
||||
}
|
||||
if (min) {
|
||||
long l = (long)Math.floor((double)time / (double)MILLIS_IN_MINUTE);
|
||||
time -= l * MILLIS_IN_MINUTE;
|
||||
if (l > 0L) stamp += " " + l + "min";
|
||||
}
|
||||
if (sec) {
|
||||
long l = (long)Math.floor((double)time / (double)MILLIS_IN_SECOND);
|
||||
time -= l * MILLIS_IN_SECOND;
|
||||
if (l > 0L) stamp += " " + l + "sec";
|
||||
}
|
||||
if (ms) {
|
||||
if (time > 0L) stamp += " " + time + "ms";
|
||||
}
|
||||
|
||||
return stamp.trim();
|
||||
}
|
||||
|
||||
public String getStampStandard() {
|
||||
return getStamp(false, true, true, false, false);
|
||||
}
|
||||
|
||||
public String getStampLogger() {
|
||||
return getStamp(false, true, true, true, false);
|
||||
}
|
||||
|
||||
public String getStampPrecise() {
|
||||
return getStamp(false, false, true, true, true);
|
||||
}
|
||||
|
||||
public String getStampFull() {
|
||||
return getStamp(true, true, true, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,20 @@ api-version: 1.17
|
||||
authors: [ ImproperIssues ]
|
||||
description: Manager server explosions with just a few simple clicks!
|
||||
website: github.com/ItziSpyder
|
||||
permissions:
|
||||
exc.commands.updateworlds:
|
||||
description: Command access
|
||||
default: op
|
||||
exc.commands.configworlds:
|
||||
description: Command access
|
||||
default: op
|
||||
commands:
|
||||
updateworlds:
|
||||
description: Update all world explosion configs
|
||||
usage: /updateworlds
|
||||
permission: exc.commands.updateworlds
|
||||
configworld:
|
||||
description: Config world explosion configs
|
||||
usage: /configworld <world>
|
||||
permission: exc.commands.configworld
|
||||
|
||||
|
||||
Reference in New Issue
Block a user