Added /new command + possibility to to open a book + ability to admin to reload config file +

This commit is contained in:
Quentin Legot 2020-05-20 17:05:20 +02:00
parent ee02bcd0b7
commit 4235f9d5b3
5 changed files with 93 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.classpath .classpath
.project .project
/bin/

14
config.yml Normal file
View File

@ -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 ?

9
plugin.yml Normal file
View File

@ -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

View File

@ -1,12 +1,21 @@
package fr.topeka.HelpRulesBook; package fr.topeka.HelpRulesBook;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import fr.topeka.HelpRulesBook.commands.CommandNew;
public class Main extends JavaPlugin{ public class Main extends JavaPlugin{
public String _title, _author;
public List<String> _pages;
@Override @Override
public void onEnable() { public void onEnable() {
saveDefaultConfig();
loadConfig();
getCommand("new").setExecutor(new CommandNew(this));
} }
@Override @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");
}
} }

View File

@ -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<main._pages.size();i++) {
meta.addPage(main._pages.get(i));
}
if(book.setItemMeta(meta)) {
player.openBook(book);
return true;
}else {
player.sendMessage("§0[§aHelp-Rules-Book§0]§f An error occured");
return false;
}
}
sender.sendMessage("§0[§aHelp-Rules-Book§0]§f You need to be a player to view your tutorial");
return false;
}
}
}