SteamWar/BauSystem2.0
Archiviert
12
0

Add BookReplaceCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-05-30 11:16:32 +02:00
Ursprung d90782c4b3
Commit f2c44c76d7

Datei anzeigen

@ -0,0 +1,51 @@
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
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;
@Linked(LinkageType.COMMAND)
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<String> stringList = bookMeta.getPages();
for (int i = 0; i < stringList.size(); i++) {
String string = stringList.get(i);
bookMeta.setPage(i + 1, string.replace(oldChar, newChar));
}
}
}