From 7e773c88e43d8651694ce5f40c580bcc249e5ac9 Mon Sep 17 00:00:00 2001 From: Edith Boles Date: Fri, 1 Oct 2021 20:03:37 -0700 Subject: [PATCH] Ritual listing --- .../java/top/penowl/quidproquo/Commands.java | 21 +++++++++++++++++++ .../top/penowl/quidproquo/QuidProQuo.java | 6 +++--- .../penowl/quidproquo/rituals/HitRitual.java | 9 -------- src/main/resources/plugin.yml | 11 +++++++++- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/top/penowl/quidproquo/Commands.java b/src/main/java/top/penowl/quidproquo/Commands.java index 15f12d5..7d3b3c1 100644 --- a/src/main/java/top/penowl/quidproquo/Commands.java +++ b/src/main/java/top/penowl/quidproquo/Commands.java @@ -1,8 +1,11 @@ package top.penowl.quidproquo; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Set; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -21,6 +24,24 @@ public class Commands implements CommandExecutor { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length < 1) { // display help + return false; + } else if (args[0].toLowerCase().equals("list")) { + List ritualNames = new ArrayList(recipes.keySet()); + int max = ritualNames.size() - 1; + int maxPages = max / 10; + int page = 0; + try { + 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); + for (int i = page * 10; i < Math.min(page * 10 + 10, max + 1); i++) { + builder.append(ritualNames.get(i)); + builder.append("\n" + ChatColor.GREEN); + } + sender.sendMessage(builder.toString()); return true; } else if (recipes.containsKey(args[0].toUpperCase())) { // display recipe info diff --git a/src/main/java/top/penowl/quidproquo/QuidProQuo.java b/src/main/java/top/penowl/quidproquo/QuidProQuo.java index 778a2e0..cbd4d8a 100644 --- a/src/main/java/top/penowl/quidproquo/QuidProQuo.java +++ b/src/main/java/top/penowl/quidproquo/QuidProQuo.java @@ -30,9 +30,6 @@ public class QuidProQuo extends JavaPlugin { getLogger().info("Loading rituals..."); getServer().getPluginManager().registerEvents(new Events(), this); - // register command handler - getCommand("ritual").setExecutor(new Commands(rituals)); - // register all rituals rituals.add(new HealRitual()); rituals.add(new WoolingRitual()); @@ -53,6 +50,9 @@ public class QuidProQuo extends JavaPlugin { getLogger().info("Loaded a " + ritual.name + " ritual."); } + // register command handler + getCommand("ritual").setExecutor(new Commands(rituals)); + } @Override public void onDisable() { diff --git a/src/main/java/top/penowl/quidproquo/rituals/HitRitual.java b/src/main/java/top/penowl/quidproquo/rituals/HitRitual.java index 2d7200b..00b7407 100644 --- a/src/main/java/top/penowl/quidproquo/rituals/HitRitual.java +++ b/src/main/java/top/penowl/quidproquo/rituals/HitRitual.java @@ -11,10 +11,7 @@ public class HitRitual extends Ritual { @Override public void setup() { addIngredient(Material.IRON_SWORD, 1); -<<<<<<< HEAD addIngredient(Material.IRON_INGOT, 1); -======= ->>>>>>> 7f77c0dac5cb9bbd0ceaf70f710f7fdecac3e9ad addIngredient(Material.WHEAT, 9); name = "shadow hit"; health = 1; @@ -22,14 +19,8 @@ public class HitRitual extends Ritual { @Override public void execute(Player caster, Player target, Location location) { -<<<<<<< HEAD target.playSound(target.getLocation(), Sound.HURT_FLESH, 1, 1); //target.damage(1.0); -======= - for(int i = 0; i < 3; i ++) { - target.playSound(target.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1); - } ->>>>>>> 7f77c0dac5cb9bbd0ceaf70f710f7fdecac3e9ad } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8affbef..af8ea84 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,3 +1,12 @@ main: top.penowl.quidproquo.QuidProQuo name: QuidProQuo -version: 0.1 \ No newline at end of file +version: 0.1 +commands: + ritual: + description: Check ritual information. + aliases: [quidproquo, rt] + permission: quidproquo.command + permission-message: You do not have /<permission> + usage: | + §3/ritual list - List all available rituals. + §3/ritual - See the information on a ritual \ No newline at end of file