commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package io.github.itzispyder.ogredupealias.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
|
||||||
|
public record CmdExHandler(Exception ex, Command cmd) {
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
String help = "§cError: §7";
|
||||||
|
if (ex instanceof IndexOutOfBoundsException) help += "Unknown or incomplete command.";
|
||||||
|
else if (ex instanceof NullPointerException) help += "Command contains a null value.";
|
||||||
|
else help += ex.getMessage();
|
||||||
|
return help + "\n§cCaused by: §7" + ex.getClass().getSimpleName() + "\n" + "§cUsage: §7" + cmd.getUsage();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package io.github.itzispyder.ogredupealias.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class TabComplBuilder {
|
||||||
|
|
||||||
|
private Map<Integer,List<String>> entries = new HashMap<>();
|
||||||
|
private final CommandSender sender;
|
||||||
|
private final Command command;
|
||||||
|
private final String alias;
|
||||||
|
private final String[] args;
|
||||||
|
|
||||||
|
public TabComplBuilder(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.command = command;
|
||||||
|
this.alias = alias;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds to the tab completion
|
||||||
|
* @param atIndex should be a number above or equal to 1
|
||||||
|
* @param entry string array
|
||||||
|
* @param condition condition
|
||||||
|
*/
|
||||||
|
public TabComplBuilder add(int atIndex, String[] entry, boolean condition) {
|
||||||
|
if (condition) add(atIndex,entry);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds to the tab completion
|
||||||
|
* @param atIndex should be a number above or equal to 1
|
||||||
|
* @param entry string array
|
||||||
|
*/
|
||||||
|
public TabComplBuilder add(int atIndex, String[] entry) {
|
||||||
|
atIndex = Math.max(1,atIndex);
|
||||||
|
entries.put(atIndex,Arrays.stream(entry).toList());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TabComplBuilder add(int atIndex, List<String> entry, boolean condition) {
|
||||||
|
if (condition) add(atIndex,entry);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TabComplBuilder add(int atIndex, List<String> entry) {
|
||||||
|
entries.put(atIndex,entry);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> build() {
|
||||||
|
List<String> list = new ArrayList<>(entries.get(args.length) != null ? entries.get(args.length) : new ArrayList<>());
|
||||||
|
list.removeIf(s -> !s.toLowerCase().contains(args[args.length - 1].toLowerCase()));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package io.github.itzispyder.ogredupealias.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.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ItemBuilder {
|
||||||
|
|
||||||
|
private final ItemStack stack;
|
||||||
|
private final 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 ItemStack build() {
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.github.itzispyder.ogredupealias.utils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public abstract 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package io.github.itzispyder.ogredupealias.utils;
|
||||||
|
|
||||||
|
import static io.github.itzispyder.enderpv.EnderPV.prefix;
|
||||||
|
|
||||||
|
public class Text {
|
||||||
|
|
||||||
|
public static String of(String s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces all & with § to color the text
|
||||||
|
* @param s string
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
public static String color(String s) {
|
||||||
|
return s.replaceAll("&","§");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String asPath(String s) {
|
||||||
|
return s.toLowerCase()
|
||||||
|
.replaceAll(" ","_")
|
||||||
|
.replaceAll("[^.a-b0-9_-]","")
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String asDirectory(String s) {
|
||||||
|
return s.toLowerCase()
|
||||||
|
.replaceAll(" ","_")
|
||||||
|
.replaceAll("[^./a-b0-9_-]","")
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String prefixed(String s) {
|
||||||
|
return prefix + s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TextBuilder builder(String s) {
|
||||||
|
return new TextBuilder(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TextBuilder builder() {
|
||||||
|
return builder("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TextBuilder {
|
||||||
|
|
||||||
|
private String s;
|
||||||
|
|
||||||
|
public TextBuilder(String s) {
|
||||||
|
this.s = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBuilder message(String s) {
|
||||||
|
this.s = s;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBuilder color() {
|
||||||
|
s = Text.color(s);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBuilder prefix() {
|
||||||
|
s = Text.prefixed(s);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBuilder asPath() {
|
||||||
|
s = Text.asPath(s);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBuilder asDirectory() {
|
||||||
|
s = Text.asDirectory(s);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String build() {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user