From 8fff4fb7dd408a936e422c1105e977cbaaa658b8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 22 Mar 2022 17:16:11 +0100 Subject: [PATCH 1/3] Add BookReplaceCommand --- src/de/steamwar/tutorial/TutorialSystem.java | 2 + .../tutorial/commands/BookReplaceCommand.java | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/de/steamwar/tutorial/commands/BookReplaceCommand.java diff --git a/src/de/steamwar/tutorial/TutorialSystem.java b/src/de/steamwar/tutorial/TutorialSystem.java index bfb64b0..a348818 100644 --- a/src/de/steamwar/tutorial/TutorialSystem.java +++ b/src/de/steamwar/tutorial/TutorialSystem.java @@ -19,6 +19,7 @@ package de.steamwar.tutorial; +import de.steamwar.tutorial.commands.BookReplaceCommand; import de.steamwar.tutorial.commands.TutorialCommand; import de.steamwar.tutorial.listener.Joining; import de.steamwar.tutorial.listener.RateSign; @@ -38,6 +39,7 @@ public class TutorialSystem extends JavaPlugin { new RateSign(); new Joining(); + new BookReplaceCommand(); new TutorialCommand(); } diff --git a/src/de/steamwar/tutorial/commands/BookReplaceCommand.java b/src/de/steamwar/tutorial/commands/BookReplaceCommand.java new file mode 100644 index 0000000..43b052f --- /dev/null +++ b/src/de/steamwar/tutorial/commands/BookReplaceCommand.java @@ -0,0 +1,48 @@ +package de.steamwar.tutorial.commands; + +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.List; + +public class BookReplaceCommand extends SWCommand { + + public BookReplaceCommand() { + super("bookreplace"); + } + + @Register("color") + public void color(Player player) { + ItemStack itemStack = player.getInventory().getItemInMainHand(); + ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta instanceof BookMeta) { + BookMeta bookMeta = (BookMeta) itemMeta; + replace(bookMeta, '&', '§'); + itemStack.setItemMeta(bookMeta); + player.getInventory().setItemInMainHand(itemStack); + } + } + + @Register("uncolor") + public void uncolor(Player player) { + ItemStack itemStack = player.getInventory().getItemInMainHand(); + ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta instanceof BookMeta) { + BookMeta bookMeta = (BookMeta) itemMeta; + replace(bookMeta, '§', '&'); + itemStack.setItemMeta(bookMeta); + player.getInventory().setItemInMainHand(itemStack); + } + } + + private void replace(BookMeta bookMeta, char oldChar, char newChar) { + List stringList = bookMeta.getPages(); + for (int i = 0; i < stringList.size(); i++) { + String string = stringList.get(i); + stringList.set(i, string.replace(oldChar, newChar)); + } + } +} -- 2.39.5 From 9cd5671629687dfa12ad994e8da5739635cff58e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 22 Mar 2022 17:26:51 +0100 Subject: [PATCH 2/3] Add UnsignCommand --- src/de/steamwar/tutorial/TutorialSystem.java | 2 ++ .../tutorial/commands/UnsignCommand.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/de/steamwar/tutorial/commands/UnsignCommand.java diff --git a/src/de/steamwar/tutorial/TutorialSystem.java b/src/de/steamwar/tutorial/TutorialSystem.java index a348818..a261375 100644 --- a/src/de/steamwar/tutorial/TutorialSystem.java +++ b/src/de/steamwar/tutorial/TutorialSystem.java @@ -21,6 +21,7 @@ package de.steamwar.tutorial; import de.steamwar.tutorial.commands.BookReplaceCommand; import de.steamwar.tutorial.commands.TutorialCommand; +import de.steamwar.tutorial.commands.UnsignCommand; import de.steamwar.tutorial.listener.Joining; import de.steamwar.tutorial.listener.RateSign; import org.bukkit.plugin.java.JavaPlugin; @@ -41,6 +42,7 @@ public class TutorialSystem extends JavaPlugin { new BookReplaceCommand(); new TutorialCommand(); + new UnsignCommand(); } public static TutorialSystem getPlugin() { diff --git a/src/de/steamwar/tutorial/commands/UnsignCommand.java b/src/de/steamwar/tutorial/commands/UnsignCommand.java new file mode 100644 index 0000000..799cdd9 --- /dev/null +++ b/src/de/steamwar/tutorial/commands/UnsignCommand.java @@ -0,0 +1,21 @@ +package de.steamwar.tutorial.commands; + +import de.steamwar.command.SWCommand; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class UnsignCommand extends SWCommand { + + public UnsignCommand() { + super("unsign"); + } + + @Register(description = "UNSIGN_HELP") + public void unsignCommand(Player p) { + ItemStack itemStack = p.getInventory().getItemInMainHand(); + if (itemStack.getType() != Material.WRITTEN_BOOK) return; + itemStack.setType(Material.WRITABLE_BOOK); + p.getInventory().setItemInMainHand(itemStack); + } +} -- 2.39.5 From 191e96a924dce963115c3e8cab6e69d5caaa50b5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 22 Mar 2022 17:27:40 +0100 Subject: [PATCH 3/3] Add UnsignCommand --- src/de/steamwar/tutorial/commands/UnsignCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/tutorial/commands/UnsignCommand.java b/src/de/steamwar/tutorial/commands/UnsignCommand.java index 799cdd9..847db16 100644 --- a/src/de/steamwar/tutorial/commands/UnsignCommand.java +++ b/src/de/steamwar/tutorial/commands/UnsignCommand.java @@ -11,7 +11,7 @@ public class UnsignCommand extends SWCommand { super("unsign"); } - @Register(description = "UNSIGN_HELP") + @Register public void unsignCommand(Player p) { ItemStack itemStack = p.getInventory().getItemInMainHand(); if (itemStack.getType() != Material.WRITTEN_BOOK) return; -- 2.39.5