Created
September 26, 2018 04:29
-
-
Save andrewkm/51a8de041c2d13c6da46c97c8038de5a to your computer and use it in GitHub Desktop.
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
package com.ecocitycraft.lsvanilla.commands; | |
import com.ecocitycraft.liquidcore.commands.LiquidCommand; | |
import com.ecocitycraft.liquidcore.commands.LiquidCommandException; | |
import com.ecocitycraft.lsvanilla.LiquidSafeVanilla; | |
import com.ecocitycraft.lsvanilla.runnables.BookletDBWrite; | |
import com.ecocitycraft.lsvanilla.util.Booklet; | |
import com.ecocitycraft.lsvanilla.util.BookletGUI; | |
import org.bukkit.Material; | |
import org.bukkit.Server; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
public class Commandbooklet extends LiquidCommand | |
{ | |
public Commandbooklet() | |
{ | |
super(); | |
} | |
@Override | |
public void run(Server server, CommandSender sender, Command cmd, String commandLabel, String[] args) throws LiquidCommandException | |
{ | |
switch (args.length) | |
{ | |
case 0: | |
if(!(sender instanceof Player)) | |
throw new LiquidCommandException("Must be a player"); | |
Player player = (Player) sender; | |
BookletGUI gui = new BookletGUI(player); | |
gui.open(); | |
break; | |
case 1: | |
switch (args[0]) | |
{ | |
case "flush": | |
if(sender instanceof Player) | |
throw new LiquidCommandException("No permissions"); | |
plugin.getServer().getScheduler().runTask(plugin, new BookletDBWrite((LiquidSafeVanilla)plugin, false)); | |
break; | |
case "status": | |
player = (Player) sender; | |
Booklet pBooklet = LiquidSafeVanilla.getBooklets().getOrDefault(player.getUniqueId(), null); | |
if(pBooklet == null) | |
throw new LiquidCommandException("Can't find booklet for your UUID"); | |
String id = pBooklet.sendStatus(player); | |
plugin.getLogger().info("Booklet Status Requested: ID: " + id | |
+ " Username: " + player.getName() | |
+ " UUID: " + player.getUniqueId() | |
+ " Complete: " + pBooklet.getAmountSeen() + "/" + pBooklet.getTotalItems()); | |
break; | |
default: | |
player = (Player) sender; | |
Material input; | |
try | |
{ | |
input = Material.valueOf(args[0].toUpperCase()); | |
final boolean[] found = {false}; | |
Booklet booklet = LiquidSafeVanilla.getBooklets().getOrDefault(player.getUniqueId(), null); | |
if (booklet == null) | |
throw new LiquidCommandException("Your booklet does not exist yet."); | |
booklet.getBookletEntries().forEach(e -> | |
{ | |
if (e.getType().toString().equalsIgnoreCase(input.toString())) | |
{ | |
e.sendChatInfo(player); | |
found[0] = true; | |
} | |
}); | |
if (!found[0]) | |
throw new LiquidCommandException("Could not find the specified item in your booklet."); | |
} | |
catch (IllegalArgumentException e) | |
{ | |
throw new LiquidCommandException("That item does not exist, please use the proper name."); | |
} | |
break; | |
} | |
break; | |
default: | |
throw new LiquidCommandException("Syntax: /booklet <item>"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment