Better lists

This commit is contained in:
Edith Boles 2021-10-04 11:42:01 -07:00
parent 40d824c26e
commit 45843478df
4 changed files with 49 additions and 9 deletions

View File

@ -13,6 +13,14 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.dom4j.Text;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
public class Commands implements CommandExecutor {
@ -39,18 +47,40 @@ public class Commands implements CommandExecutor {
page = Math.min(Math.max(Integer.parseInt(args[1]) - 1, 0), maxPages);
} catch(Exception e) {
}
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.DARK_PURPLE + "======== Rituals ======== " + ChatColor.YELLOW + "Page " + String.valueOf(page + 1) + " / " + String.valueOf(maxPages + 1));
builder.append("\n" + ChatColor.GREEN);
ComponentBuilder builder = new ComponentBuilder("");
builder.append(ChatColor.DARK_PURPLE + "======== Rituals ======== ");
if (page != 0) {
builder.append(" < ");
builder.color(net.md_5.bungee.api.ChatColor.YELLOW);
builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/rt list " + String.valueOf(page)));
} else {
builder.append(" < ");
builder.color(net.md_5.bungee.api.ChatColor.GRAY);
}
builder.append("Page " + String.valueOf(page + 1) + " / " + String.valueOf(maxPages + 1) + " ");
builder.color(net.md_5.bungee.api.ChatColor.AQUA);
if (page != maxPages) {
builder.append(" > ");
builder.color(net.md_5.bungee.api.ChatColor.YELLOW);
builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/rt list " + String.valueOf(page + 2)));
} else {
builder.append(" > ");
builder.color(net.md_5.bungee.api.ChatColor.GRAY);
}
for (int i = page * 9; i < page * 9 + 9; i++) {
if (i > max) {
builder.append(" \n");
continue;
}
builder.append(ritualNames.get(i));
builder.append("\n" + ChatColor.GREEN);
builder.append("\n" + ritualNames.get(i));
builder.color(net.md_5.bungee.api.ChatColor.GREEN);
builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ritual " + ritualNames.get(i)));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColor.YELLOW + "Click to see more...").create()));
}
if (sender instanceof Player) {
Player playerSender = (Player) sender;
playerSender.spigot().sendMessage(builder.create());
}
sender.sendMessage(builder.toString());
return true;
} else if (recipes.containsKey(String.join(" ", args).toLowerCase())) {
String key = String.join(" ", args).toLowerCase();

View File

@ -1,10 +1,12 @@
package top.penowl.quidproquo;
import java.lang.reflect.Constructor;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import org.reflections.Reflections;
@ -38,10 +40,13 @@ public class QuidProQuo extends JavaPlugin {
for (Class<? extends Ritual> ritualClass : subClasses) {
Class<?>[] params = {};
try {
if (ritualClass.getField("enabled").getBoolean(null)) {
Constructor<? extends Ritual> constructor = ritualClass.getConstructor(params);
Object[] args = {};
rituals.add(constructor.newInstance(args));
}
} catch (Exception e) {
System.out.println(e.toString());
}
}

View File

@ -11,6 +11,9 @@ import org.bukkit.inventory.ItemStack;
public abstract class Ritual {
// whether the ritual is enabled, shouldn't change during runtime
public static boolean enabled = true;
// ingredients, map of type to count
public HashMap<Material, Integer> ingredients = new HashMap<Material, Integer>();

View File

@ -7,6 +7,8 @@ import top.penowl.quidproquo.Ritual;
public class BlankRitual extends Ritual {
public static boolean enabled = false;
@Override
public void setup() {