Created
March 3, 2012 11:47
-
-
Save NeatMonster/1965704 to your computer and use it in GitHub Desktop.
XPStore
This file contains hidden or 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 me.messageofdeath.xpstore; | |
import org.bukkit.ChatColor; | |
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.plugin.java.JavaPlugin; | |
public class XPStore extends JavaPlugin { | |
class XPSCommandExecutor implements CommandExecutor { | |
private final int MAXIMUM_LEVEL = 100; | |
@Override | |
public boolean onCommand(final CommandSender sender, final Command command, final String label, | |
final String[] args) { | |
if (!(sender instanceof Player)) | |
sender.sendMessage("This command is only for InGame players!"); | |
else { | |
final Player player = (Player) sender; | |
if (args.length != 1) | |
player.sendMessage(ChatColor.GREEN + "[" + ChatColor.BLUE + "XPStore" + ChatColor.GREEN + "]" | |
+ ChatColor.RED + " Please use /xps <1-" + MAXIMUM_LEVEL + ">"); | |
else if (args[0].equalsIgnoreCase("help")) { | |
player.sendMessage(ChatColor.GOLD + " _________"); | |
player.sendMessage(ChatColor.GOLD + "_______________-[XPStore]-_______________"); | |
player.sendMessage(ChatColor.GOLD + " ---------"); | |
player.sendMessage(ChatColor.GREEN + "/xps <1-" + MAXIMUM_LEVEL + ">"); | |
player.sendMessage(ChatColor.GREEN + "Iron Ingots will be 1-" + MAXIMUM_LEVEL + ""); | |
} else | |
try { | |
final int level = Integer.parseInt(args[0]); | |
if (level > MAXIMUM_LEVEL) | |
player.sendMessage(ChatColor.GREEN + "[" + ChatColor.BLUE + "XPStore" + ChatColor.GREEN | |
+ "]" + ChatColor.RED + "The level you've requested is too hight!"); | |
else if (player.hasPermission("xps.buy")) | |
if (player.getInventory().contains(Material.IRON_INGOT, level)) { | |
if (player.getLevel() < level) { | |
player.getInventory().removeItem(new ItemStack(Material.IRON_INGOT, level)); | |
player.setLevel(level); | |
} else if (player.getLevel() == level) | |
player.sendMessage(ChatColor.GREEN + "[" + ChatColor.BLUE + "XPStore" | |
+ ChatColor.GREEN + "]" + ChatColor.RED + " You are already level " + level | |
+ "!"); | |
else if (player.getLevel() > level) | |
player.sendMessage(ChatColor.GREEN + "[" + ChatColor.BLUE + "XPStore" | |
+ ChatColor.GREEN + "]" + ChatColor.RED | |
+ " Why do you want to lower your level?!"); | |
} else | |
player.sendMessage(ChatColor.GREEN + "[" + ChatColor.BLUE + "XPStore" + ChatColor.GREEN | |
+ "]" + ChatColor.RED + " You need " + level + " Iron Ingot(s)!"); | |
else | |
player.sendMessage(ChatColor.GREEN + "[" + ChatColor.BLUE + "XPStore" + ChatColor.GREEN | |
+ "]" + ChatColor.RED + " You do not have permission to buy from the store!"); | |
} catch (final NumberFormatException e) { | |
player.sendMessage(ChatColor.GREEN + "[" + ChatColor.BLUE + "XPStore" + ChatColor.GREEN + "]" | |
+ ChatColor.RED + " Please use /xps <1-" + MAXIMUM_LEVEL + ">"); | |
} | |
} | |
return true; | |
} | |
} | |
private final XPSCommandExecutor commandExecutor = new XPSCommandExecutor(); | |
@Override | |
public void onEnable() { | |
super.onEnable(); | |
getCommand("xps").setExecutor(commandExecutor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment