-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated to 1.1-SNAPSHOT - Lots of things changed. Signed-off-by: Steven Downer <grinch@outlook.com>
- Loading branch information
Showing
10 changed files
with
465 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* This file is part of Lore. | ||
* | ||
* Copyright (c) 2013, AlmuraDev <http://www.almuradev.com/> | ||
* Lore is licensed under the Almura Development License. | ||
* | ||
* Lore is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Lore is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License. If not, | ||
* see <http://www.gnu.org/licenses/> for the GNU General Public License. | ||
*/ | ||
package com.almuradev.lore; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.meta.BookMeta; | ||
|
||
public class LoreCommands implements CommandExecutor { | ||
private final LorePlugin plugin; | ||
|
||
public LoreCommands(LorePlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (command.getName().equalsIgnoreCase("lore")) { | ||
Player player = null; | ||
Boolean isPlayer = false; | ||
|
||
if (sender instanceof Player) { | ||
isPlayer = true; | ||
player = (Player) sender; | ||
} | ||
|
||
if (args.length >= 0) { | ||
|
||
if (args[0].equalsIgnoreCase("give")) { | ||
if (args.length >= 2) { | ||
if ((isPlayer && VaultUtil.hasPermission(player.getName(), player.getWorld().getName(), "lore.command.give")) || !isPlayer) { | ||
Player target = Bukkit.getPlayerExact(args[1]); | ||
if (target != null) { | ||
if (plugin.getConfiguration().verifyBook(args[2])) { | ||
target.getInventory().addItem(plugin.getConfiguration().getBook(args[2])); | ||
} else { | ||
sender.sendMessage("Sorry, " + args[2] + " does not exist within Lore's book library."); | ||
return true; | ||
} | ||
if (target.getName() != sender.getName()) { | ||
sender.sendMessage("You've given " + args[1] + " a copy of " + args[2] + "."); | ||
} else { | ||
sender.sendMessage("You've given yourself a copy of " + args[2] + "."); | ||
} | ||
} else { | ||
sender.sendMessage("Unable to give " + args[1] + " a copy of " + args[2] + ", is that player online?"); | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
if (args[0].equalsIgnoreCase("create")) { | ||
if (args.length >= 2) { | ||
if (isPlayer && VaultUtil.hasPermission(player.getName(), player.getWorld().getName(), "lore.command.create")) { | ||
if (!(player.getItemInHand().getItemMeta() instanceof BookMeta)) { | ||
sender.sendMessage("Held item must be a signed book."); | ||
} else if (plugin.getConfiguration().verifyBook(args[1])) { | ||
sender.sendMessage(args[1] + " already exists in Lore's book library."); | ||
} else { | ||
BookMeta meta = (BookMeta) player.getItemInHand().getItemMeta(); | ||
if (meta.hasTitle() == false) { | ||
sender.sendMessage("You must sign this book first before adding it to Lore's book library."); | ||
return true; | ||
} | ||
plugin.getConfiguration().createBook(args[1], meta); | ||
sender.sendMessage(args[1] + " has been added to Lore's book library."); | ||
} | ||
} else if (!isPlayer) { | ||
sender.sendMessage("You must be logged in to perform that command!"); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
if (args[0].equalsIgnoreCase("remove")) { | ||
if (args.length >= 2) { | ||
if (isPlayer && VaultUtil.hasPermission(player.getName(), player.getWorld().getName(), "lore.command.remove")) { | ||
if (plugin.getConfiguration().verifyBook(args[1])) { | ||
plugin.getConfiguration().removeBook(args[1]); | ||
sender.sendMessage(args[1] + " has been removed from Lore's book library."); | ||
} else { | ||
sender.sendMessage(args[1] + " does not exist in Lore's book library."); | ||
} | ||
} else if (!isPlayer) { | ||
sender.sendMessage("You must be logged in to perform that command!"); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
if (args[0].equalsIgnoreCase("join")) { | ||
if (args.length == 3) { | ||
if (args[1].equalsIgnoreCase("add") && isPlayer && VaultUtil.hasPermission(player.getName(), player.getWorld().getName(), "lore.command.join.add")) { | ||
if (plugin.getConfiguration().addJoinBook(args[2])) { | ||
sender.sendMessage(args[2] + " was added to join list."); | ||
} else { | ||
sender.sendMessage(args[2] + " is already on the join list."); | ||
} | ||
} else if (args[1].equalsIgnoreCase("remove") && isPlayer && VaultUtil.hasPermission(player.getName(), player.getWorld().getName(), "lore.command.join.remove")) { | ||
if (plugin.getConfiguration().removeJoinBook(args[2])) { | ||
sender.sendMessage(args[2] + " was removed from the join list."); | ||
} else { | ||
sender.sendMessage(args[2] + " is not on the join list."); | ||
} | ||
} else if (!isPlayer) { | ||
sender.sendMessage("You must be logged in to perform that command!"); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
if (args[0].equalsIgnoreCase("respawn")) { | ||
if (args.length == 3) { | ||
if (args[1].equalsIgnoreCase("add") && isPlayer && VaultUtil.hasPermission(player.getName(), player.getWorld().getName(), "lore.command.respawn.add")) { | ||
if (plugin.getConfiguration().addRespawnBook(args[2])) { | ||
sender.sendMessage(args[2] + " was added to respawn list."); | ||
} else { | ||
sender.sendMessage(args[2] + " is already on the respawn list."); | ||
} | ||
} else if (args[1].equalsIgnoreCase("remove") && isPlayer && VaultUtil.hasPermission(player.getName(), player.getWorld().getName(), "lore.command.respawn.remove")) { | ||
if (plugin.getConfiguration().removeRespawnBook(args[2])) { | ||
sender.sendMessage(args[2] + " was removed from the respawn list."); | ||
} else { | ||
sender.sendMessage(args[2] + " is not on the respawn list."); | ||
} | ||
} else if (!isPlayer) { | ||
sender.sendMessage("You must be logged in to perform that command!"); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
205 changes: 205 additions & 0 deletions
205
src/main/java/com/almuradev/lore/LoreConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/* | ||
* This file is part of Lore. | ||
* | ||
* Copyright (c) 2013, AlmuraDev <http://www.almuradev.com/> | ||
* Lore is licensed under the Almura Development License. | ||
* | ||
* Lore is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Lore is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License. If not, | ||
* see <http://www.gnu.org/licenses/> for the GNU General Public License. | ||
*/ | ||
package com.almuradev.lore; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.BookMeta; | ||
|
||
public class LoreConfiguration { | ||
private final LorePlugin plugin; | ||
|
||
public LoreConfiguration(LorePlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void init() { | ||
// Verify that our config.yml exists | ||
if (!new File(plugin.getDataFolder(), "config.yml").exists()) { | ||
plugin.saveDefaultConfig(); | ||
} | ||
|
||
if (!new File(plugin.getDataFolder() + "/books/").exists()) { | ||
try { | ||
new File(plugin.getDataFolder() + "/books/").mkdir(); | ||
} catch (Exception e) { | ||
plugin.getLogger().log(Level.SEVERE, "Unable to create 'books' folder in basedir/plugins/Lore"); | ||
if (debugMode()) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
final FileConfiguration config = plugin.getConfig(); | ||
} | ||
|
||
public boolean debugMode() { | ||
if (plugin.getConfig().getBoolean("debug")) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public String getJoinMessage() { | ||
if (!plugin.getConfig().getString("join.message").isEmpty()) { | ||
return plugin.getConfig().getString("join.message"); | ||
} | ||
return ""; | ||
} | ||
|
||
public List<String> getJoinBooks() { | ||
return plugin.getConfig().getStringList("join.books"); | ||
} | ||
|
||
public String getRespawnMessage() { | ||
if (!plugin.getConfig().getString("respawn.message").isEmpty()) { | ||
return plugin.getConfig().getString("respawn.message"); | ||
} | ||
return ""; | ||
} | ||
|
||
public List<String> getRespawnBooks() { | ||
return plugin.getConfig().getStringList("respawn.books"); | ||
} | ||
|
||
public ItemStack getBook(String name) { | ||
YamlConfiguration bookConfig = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + "/books/" + name + ".yml")); | ||
ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1); | ||
BookMeta meta = (BookMeta) book.getItemMeta(); | ||
|
||
if (verifyBook(name)) { | ||
if (bookConfig.getStringList("pages") != null && !bookConfig.getStringList("pages").isEmpty()) { | ||
meta.setAuthor(bookConfig.getString("author")); | ||
meta.setTitle(bookConfig.getString("title")); | ||
meta.setPages(bookConfig.getStringList("pages")); | ||
book.setItemMeta(meta); | ||
} else { | ||
plugin.getLogger().log(Level.SEVERE, "Unable to obtain " + name + "\'s pages."); | ||
} | ||
} | ||
return book; | ||
} | ||
|
||
public void createBook(String name, BookMeta meta) { | ||
// Make sure the book file exists | ||
File bookFile = new File(plugin.getDataFolder() + "/books/" + name + ".yml"); | ||
if (!verifyBook(name)) { | ||
try { | ||
bookFile.createNewFile(); | ||
} catch (IOException e) { | ||
plugin.getLogger().log(Level.SEVERE, "Unable to create " + name + ".yml!"); | ||
if (debugMode()) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
// Get the configuration file for the book and add all the stuff | ||
YamlConfiguration bookConfig = YamlConfiguration.loadConfiguration(bookFile); | ||
bookConfig.set("author", meta.getAuthor()); | ||
bookConfig.set("title", meta.getTitle()); | ||
bookConfig.set("pages", meta.getPages()); | ||
try { | ||
bookConfig.save(bookFile); | ||
} catch (IOException e) { | ||
plugin.getLogger().log(Level.WARNING, "Unable to save file for " + name + "."); | ||
if (debugMode()) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public void removeBook(String name) { | ||
if (verifyBook(name)) { | ||
try { | ||
new File(plugin.getDataFolder() + "/books/" + name + ".yml").delete(); | ||
} catch (Exception e) { | ||
plugin.getLogger().log(Level.SEVERE, "Unable to delete " + name + ".yml!"); | ||
if (debugMode()) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public boolean addJoinBook(String name) { | ||
List<String> joinBookList = plugin.getConfig().getConfigurationSection("join").getStringList("books"); | ||
if (!joinBookList.contains(name)) { | ||
joinBookList.add(name); | ||
plugin.getConfig().set("join.books", joinBookList); | ||
plugin.getLogger().log(Level.INFO, name + " has been added to the list of join books."); | ||
plugin.saveConfig(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean addRespawnBook(String name) { | ||
List<String> respawnBookList = plugin.getConfig().getStringList("respawn.books"); | ||
if (!respawnBookList.contains(name)) { | ||
respawnBookList.add(name); | ||
plugin.getConfig().set("respawn.books", respawnBookList); | ||
plugin.getConfig().getConfigurationSection("respawn").getStringList("books").add(name); | ||
plugin.getLogger().log(Level.INFO, name + " has been added to the list of respawn books."); | ||
plugin.saveConfig(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean removeJoinBook(String name) { | ||
List<String> joinBookList = plugin.getConfig().getStringList("join.books"); | ||
if (joinBookList.contains(name)) { | ||
joinBookList.remove(name); | ||
plugin.getConfig().set("join.books", joinBookList); | ||
plugin.getLogger().log(Level.INFO, name + " has been removed from the list of join books."); | ||
plugin.saveConfig(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean removeRespawnBook(String name) { | ||
List<String> respawnBookList = plugin.getConfig().getStringList("respawn.books"); | ||
if (respawnBookList.contains(name)) { | ||
respawnBookList.remove(name); | ||
plugin.getConfig().set("respawn.books", respawnBookList); | ||
plugin.getLogger().log(Level.INFO, name + " has been removed from the list of respawn books."); | ||
plugin.saveConfig(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean verifyBook(String name) { | ||
if (new File(plugin.getDataFolder() + "/books/" + name + ".yml").exists()) { | ||
plugin.getLogger().log(Level.INFO, plugin.getDataFolder() + "/books/" + name + ".yml"); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.