From 4235f9d5b31db44d6dc9e3f7dd93229b8dfa2d72 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 20 May 2020 17:05:20 +0200 Subject: [PATCH] Added /new command + possibility to to open a book + ability to admin to reload config file + --- .gitignore | 1 + config.yml | 14 +++++ plugin.yml | 9 ++++ src/fr/topeka/HelpRulesBook/Main.java | 18 ++++++- .../HelpRulesBook/commands/CommandNew.java | 52 +++++++++++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 config.yml create mode 100644 plugin.yml create mode 100644 src/fr/topeka/HelpRulesBook/commands/CommandNew.java diff --git a/.gitignore b/.gitignore index 32868bd..36693c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .classpath .project +/bin/ diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..4a05356 --- /dev/null +++ b/config.yml @@ -0,0 +1,14 @@ +book: + title: "Un magnifique titre" + author: "Auteur du livre" + pages: + - | + Premier page + C'est beau tu trouve pas ? + - | + ça c'est Seconde page. + Magnifique non ? + - | + Et cette troisème alors ? + la meilleure de toutes ! + Tu trouves pas ? \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..7629ba7 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,9 @@ +name: Help-Rules-Book +version: 1.0 +author: Topeka_, Adien1106 +main: fr.topeka.HelpRulesBook.Main +api-version: 1.14 +commands: + new: + description: Open a book (GUI) + permission: HelpRulesBook.use \ No newline at end of file diff --git a/src/fr/topeka/HelpRulesBook/Main.java b/src/fr/topeka/HelpRulesBook/Main.java index 7ed3a89..688ea02 100644 --- a/src/fr/topeka/HelpRulesBook/Main.java +++ b/src/fr/topeka/HelpRulesBook/Main.java @@ -1,12 +1,21 @@ package fr.topeka.HelpRulesBook; +import java.util.List; + import org.bukkit.plugin.java.JavaPlugin; +import fr.topeka.HelpRulesBook.commands.CommandNew; + public class Main extends JavaPlugin{ + public String _title, _author; + public List _pages; + @Override public void onEnable() { - + saveDefaultConfig(); + loadConfig(); + getCommand("new").setExecutor(new CommandNew(this)); } @Override @@ -14,4 +23,11 @@ public class Main extends JavaPlugin{ } + + public void loadConfig() { + this._title = getConfig().getString("book.title"); + this._author = getConfig().getString("book.author"); + this._pages = getConfig().getStringList("book.pages"); + } + } diff --git a/src/fr/topeka/HelpRulesBook/commands/CommandNew.java b/src/fr/topeka/HelpRulesBook/commands/CommandNew.java new file mode 100644 index 0000000..fa7c8cf --- /dev/null +++ b/src/fr/topeka/HelpRulesBook/commands/CommandNew.java @@ -0,0 +1,52 @@ +package fr.topeka.HelpRulesBook.commands; + +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; + +import fr.topeka.HelpRulesBook.Main; + + +public class CommandNew implements CommandExecutor { + + private Main main; + + public CommandNew(Main main) { + this.main = main; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args) { + if(args.length == 1 && args[0].toUpperCase().equals("RELOAD") && sender.hasPermission("HelpRulesBook.admin")) { + main.reloadConfig(); + main.loadConfig(); + sender.sendMessage("§0[§aHelp-Rules-Book§0]§f Plugin reloaded"); + return true; + }else { + if(sender instanceof Player) { + Player player = (Player) sender; + ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1); + BookMeta meta = (BookMeta) book.getItemMeta(); + meta.setTitle(main._title); + meta.setAuthor(main._author); + for(int i=0;i