ChaosBauGUI #183
@ -4,10 +4,7 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
|
||||||
import de.steamwar.bausystem.tracer.show.TraceShowManager;
|
import de.steamwar.bausystem.tracer.show.TraceShowManager;
|
||||||
import de.steamwar.bausystem.world.AutoLoader;
|
import de.steamwar.bausystem.world.*;
|
||||||
import de.steamwar.bausystem.world.Detonator;
|
|
||||||
import de.steamwar.bausystem.world.Region;
|
|
||||||
import de.steamwar.bausystem.world.Welt;
|
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
@ -122,8 +119,9 @@ public class CommandGUI implements CommandExecutor, Listener {
|
|||||||
inv.setItem(4, skull);
|
inv.setItem(4, skull);
|
||||||
}
|
}
|
||||||
|
|
||||||
inv.setItem(6, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + 0 + " §7Bücher"), true, clickType -> {
|
inv.setItem(6, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + ScriptBook.getBookCount() + " §7Bücher"), true, clickType -> {
|
||||||
// TODO: 04.02.2021 Implement Script Book Database
|
player.closeInventory();
|
||||||
|
scriptBooksGUI(player);
|
||||||
});
|
});
|
||||||
|
|
||||||
inv.setItem(21, Material.OBSERVER, "§7Tracer", getNoPermsLore(Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> {
|
inv.setItem(21, Material.OBSERVER, "§7Tracer", getNoPermsLore(Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> {
|
||||||
@ -326,6 +324,17 @@ public class CommandGUI implements CommandExecutor, Listener {
|
|||||||
inv.open();
|
inv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void scriptBooksGUI(Player player) {
|
||||||
|
List<SWListInv.SWListEntry<ScriptBook>> entries = new ArrayList<>();
|
||||||
|
List<ScriptBook> books = ScriptBook.getBooks();
|
||||||
|
books.forEach(scriptBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(scriptBook.getBookMat(), scriptBook.getName()), scriptBook)));
|
||||||
|
SWListInv<ScriptBook> inv = new SWListInv<>(player, "Script Bücher", entries, (clickType, scriptBook) -> {
|
||||||
|
player.closeInventory();
|
||||||
|
player.getInventory().addItem(scriptBook.toItemStack());
|
||||||
|
});
|
||||||
|
inv.open();
|
||||||
|
}
|
||||||
|
|
||||||
private static void autoLoaderGUI(Player player) {
|
private static void autoLoaderGUI(Player player) {
|
||||||
SWInventory inv = new SWInventory(player, 9, "Autoloader");
|
SWInventory inv = new SWInventory(player, 9, "Autoloader");
|
||||||
|
|
||||||
|
114
BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java
Normale Datei
114
BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java
Normale Datei
@ -0,0 +1,114 @@
|
|||||||
|
package de.steamwar.bausystem.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.core.VersionedCallable;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ScriptBook {
|
||||||
|
|||||||
|
|
||||||
|
private static final FileConfiguration configuration;
|
||||||
|
private static List<ScriptBook> bookCache;
|
||||||
|
|
||||||
|
static {
|
||||||
|
configuration = YamlConfiguration.loadConfiguration(new File(BauSystem.getPlugin().getDataFolder(), "books.yml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ScriptBook> getBooks() {
|
||||||
|
if(bookCache != null)
|
||||||
|
return bookCache;
|
||||||
|
List<ScriptBook> books = new ArrayList<>();
|
||||||
|
for (String book:configuration.getKeys(false)) {
|
||||||
|
ConfigurationSection section = Objects.requireNonNull(configuration.getConfigurationSection(book));
|
||||||
|
books.add(new ScriptBook(section));
|
||||||
|
}
|
||||||
|
bookCache = books;
|
||||||
|
return books;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getBookCount() {
|
||||||
|
return configuration.getKeys(false).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> lines;
|
||||||
|
private String author;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
ScriptBook(ConfigurationSection section) {
|
||||||
|
this.lines = section.getStringList("lines");
|
||||||
|
this.author = section.getString("author", "§8Steam§eWar");
|
||||||
|
this.name = section.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack toItemStack() {
|
||||||
|
ItemStack book = new ItemStack(getBookMat());
|
||||||
|
BookMeta meta = (BookMeta) book.getItemMeta();
|
||||||
|
meta.setPages(getPages());
|
||||||
|
meta.setDisplayName(name);
|
||||||
|
meta.setTitle(name);
|
||||||
|
meta.setAuthor(author);
|
||||||
|
meta.setGeneration(BookMeta.Generation.ORIGINAL);
|
||||||
|
book.setItemMeta(meta);
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getBookMat() {
|
||||||
|
return Material.WRITTEN_BOOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getLines() {
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] getPages() {
|
||||||
|
List<StringBuilder> pages = new ArrayList<>();
|
||||||
|
pages.add(0, new StringBuilder());
|
||||||
|
int charsPerLine = 19;
|
||||||
|
int currentLine = 0;
|
||||||
|
int currentpage = 0;
|
||||||
|
boolean first = true;
|
||||||
|
for (String line:lines) {
|
||||||
|
int linesPlus = (int) Math.ceil((double) line.length() / charsPerLine);
|
||||||
|
currentLine += linesPlus;
|
||||||
|
if(currentLine >= 14 || line.equals("!")) {
|
||||||
|
currentLine = linesPlus;
|
||||||
|
currentpage++;
|
||||||
|
if(currentpage > 50)
|
||||||
|
throw new IllegalStateException("Book " + name + " has more pages than 50");
|
||||||
|
pages.add(currentpage, new StringBuilder());
|
||||||
|
first = true;
|
||||||
|
if(line.equals("!"))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!first) {
|
||||||
|
pages.get(currentpage).append("\n");
|
||||||
|
}else {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
pages.get(currentpage).append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] finalPages = new String[pages.size()];
|
||||||
|
for (int i = 0; i < pages.size(); i++) {
|
||||||
|
finalPages[i] = pages.get(i).toString();
|
||||||
|
}
|
||||||
|
return finalPages;
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren
Vllt. Predefined Books statt ScriptBook? So könnte das mit den normalen Skriptbüchern irritieren.