Add BookReplaceCommand #2
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
package de.steamwar.tutorial;
|
package de.steamwar.tutorial;
|
||||||
|
|
||||||
|
import de.steamwar.tutorial.commands.BookReplaceCommand;
|
||||||
import de.steamwar.tutorial.commands.TutorialCommand;
|
import de.steamwar.tutorial.commands.TutorialCommand;
|
||||||
|
import de.steamwar.tutorial.commands.UnsignCommand;
|
||||||
import de.steamwar.tutorial.listener.Joining;
|
import de.steamwar.tutorial.listener.Joining;
|
||||||
import de.steamwar.tutorial.listener.RateSign;
|
import de.steamwar.tutorial.listener.RateSign;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -38,7 +40,9 @@ public class TutorialSystem extends JavaPlugin {
|
|||||||
new RateSign();
|
new RateSign();
|
||||||
new Joining();
|
new Joining();
|
||||||
|
|
||||||
|
new BookReplaceCommand();
|
||||||
new TutorialCommand();
|
new TutorialCommand();
|
||||||
|
new UnsignCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TutorialSystem getPlugin() {
|
public static TutorialSystem getPlugin() {
|
||||||
|
48
src/de/steamwar/tutorial/commands/BookReplaceCommand.java
Normale Datei
48
src/de/steamwar/tutorial/commands/BookReplaceCommand.java
Normale Datei
@ -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<String> stringList = bookMeta.getPages();
|
||||||
|
for (int i = 0; i < stringList.size(); i++) {
|
||||||
|
String string = stringList.get(i);
|
||||||
|
stringList.set(i, string.replace(oldChar, newChar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
src/de/steamwar/tutorial/commands/UnsignCommand.java
Normale Datei
21
src/de/steamwar/tutorial/commands/UnsignCommand.java
Normale Datei
@ -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
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren