예제 #1
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		ISettings settings = ess.getSettings();
		switch (args.length)
		{
		case 0:
			throw new NotEnoughArgumentsException();

		case 1:
			final IUser player = ess.getUserMap().matchUserExcludingHidden(args[0], user.getPlayer());
			if (!player.getData().isTeleportEnabled())
			{
				throw new Exception(_("{0} has teleportation disabled.", player.getPlayer().getDisplayName()));
			}
			if (settings.getData().getGeneral().isPerGroupTeleport() && !Permissions.PERGROUPTELEPORT.isAuthorized(
					user, ess.getRanks().getMainGroup(player)))
			{
				throw new Exception(_("You do not have the {0} permission.", "essentials.teleport.groups." + ess.getRanks().getMainGroup(player)));
			}
			if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() && !Permissions.WORLD.isAuthorized(
					user, player.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("You do not have the {0} permission.", "essentials.world." + player.getPlayer().getWorld().getName()));
			}
			user.sendMessage(_("Teleporting..."));
			final Trade charge = new Trade(commandName, ess);
			charge.isAffordableFor(user);
			user.getTeleport().teleport(player.getPlayer(), charge, TeleportCause.COMMAND);
			throw new NoChargeException();

		default:
			if (!Permissions.TPOHERE.isAuthorized(user))
			{
				throw new Exception(_("needTpohere"));
			}
			user.sendMessage(_("Teleporting..."));

			final IUser target = ess.getUserMap().matchUserExcludingHidden(args[0], user.getPlayer());

			final IUser toPlayer = ess.getUserMap().matchUserExcludingHidden(args[1], user.getPlayer());

			if (!target.getData().isTeleportEnabled())
			{
				throw new Exception(_("{0} has teleportation disabled.", target.getPlayer().getDisplayName()));
			}
			if (!toPlayer.getData().isTeleportEnabled())
			{
				throw new Exception(_("{0} has teleportation disabled.", toPlayer.getPlayer().getDisplayName()));
			}
			if (target.getPlayer().getWorld() != toPlayer.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() && !Permissions.WORLD.isAuthorized(
					user, toPlayer.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("You do not have the {0} permission.", "essentials.world." + toPlayer.getPlayer().getWorld().getName()));
			}
			target.getTeleport().now(toPlayer.getPlayer(), false, TeleportCause.COMMAND);
			target.sendMessage(_("{0} teleported you to {1}.", user.getPlayer().getDisplayName(), toPlayer.getPlayer().getDisplayName()));
			break;
		}
	}
예제 #2
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 3)
		{
			throw new NotEnoughArgumentsException();
		}

		final int x = Integer.parseInt(args[0]);
		final int y = Integer.parseInt(args[1]);
		final int z = Integer.parseInt(args[2]);
		final Location location = new Location(user.getPlayer().getWorld(), x, y, z);
		if (args.length > 3)
		{
			location.setYaw((Float.parseFloat(args[3]) + 180 + 360) % 360);
		}
		if (args.length > 4)
		{
			location.setPitch(Float.parseFloat(args[4]));
		}
		final Trade charge = new Trade(commandName, ess);
		charge.isAffordableFor(user);
		user.sendMessage(_("teleporting"));
		user.getTeleport().teleport(location, charge, TeleportCause.COMMAND);
		throw new NoChargeException();
	}
예제 #3
0
	@Override
	protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
	{
		if ((sign.getLine(3).length() > 3 && sign.getLine(3).substring(2).equalsIgnoreCase(username))
			|| SignsPermissions.TRADE_OVERRIDE.isAuthorized(player))
		{
			try
			{
				final Trade stored1 = getTrade(sign, 1, true, false, ess);
				final Trade stored2 = getTrade(sign, 2, true, false, ess);
				stored1.pay(player);
				stored2.pay(player);
				Trade.log("Sign", "Trade", "Break", username, stored2, username, stored1, sign.getBlock().getLocation(), ess);
			}
			catch (SignException e)
			{
				if (SignsPermissions.TRADE_OVERRIDE.isAuthorized(player))
				{
					return true;
				}
				throw e;
			}
			return true;
		}
		else
		{
			return false;
		}
	}
예제 #4
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		ISettings settings = ess.getSettings();
		switch (args.length)
		{
		case 0:
			throw new NotEnoughArgumentsException();

		case 1:
			final IUser player = ess.getUserMap().matchUser(args[0], false, false);
			if (!player.getData().isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", player.getPlayer().getDisplayName()));
			}
			if (user.getPlayer().getWorld() != player.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
				&& !Permissions.WORLD.isAuthorized(user, player.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("noPerm", "essentials.world." + player.getPlayer().getWorld().getName()));
			}
			user.sendMessage(_("teleporting"));
			final Trade charge = new Trade(commandName, ess);
			charge.isAffordableFor(user);
			user.getTeleport().teleport(player.getPlayer(), charge, TeleportCause.COMMAND);
			throw new NoChargeException();

		default:
			if (!Permissions.TPOHERE.isAuthorized(user))
			{
				throw new Exception(_("needTpohere"));
			}
			user.sendMessage(_("teleporting"));
			
			final IUser target = ess.getUserMap().matchUser(args[0], false, false);
			
			final IUser toPlayer = ess.getUserMap().matchUser(args[1], false, false);

			if (!target.getData().isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", target.getPlayer().getDisplayName()));
			}
			if (!toPlayer.getData().isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", toPlayer.getPlayer().getDisplayName()));
			}
			if (target.getPlayer().getWorld() != toPlayer.getPlayer().getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions()
				&& !Permissions.WORLD.isAuthorized(user, toPlayer.getPlayer().getWorld().getName()))
			{
				throw new Exception(_("noPerm", "essentials.world." + toPlayer.getPlayer().getWorld().getName()));
			}
			target.getTeleport().now(toPlayer.getPlayer(), false, TeleportCause.COMMAND);
			target.sendMessage(_("teleportAtoB", user.getPlayer().getDisplayName(), toPlayer.getPlayer().getDisplayName()));
			break;
		}
	}
예제 #5
0
	@Override
	protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
	{
		validateTrade(sign, 1, false, ess);
		validateTrade(sign, 2, true, ess);
		final Trade charge = getTrade(sign, 2, true, true, ess);
		charge.isAffordableFor(player);
		sign.setLine(3, "§8" + username);
		charge.charge(player);
		Trade.log("Sign", "Trade", "Create", username, charge, username, null, sign.getBlock().getLocation(), ess);
		return true;
	}
예제 #6
0
	protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex, final IUser player, final IEssentials ess) throws SignException
	{
		if (sign.getLine(itemIndex).equalsIgnoreCase("exp") || sign.getLine(itemIndex).equalsIgnoreCase("xp"))
		{
			int amount = getIntegerPositive(sign.getLine(amountIndex));
			sign.setLine(amountIndex, Integer.toString(amount));
			sign.setLine(itemIndex, "exp");
			return;
		}
		final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess);
		final ItemStack item = trade.getItemStack();
		sign.setLine(amountIndex, Integer.toString(item.getAmount()));
		sign.setLine(itemIndex, sign.getLine(itemIndex).trim());
	}
예제 #7
0
	protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
	{
		final String line = sign.getLine(index).trim();
		if (line.isEmpty())
		{
			return;
		}
		final Trade trade = getTrade(sign, index, 0, ess);
		final Double money = trade.getMoney();
		if (money != null)
		{
			sign.setLine(index, FormatUtil.shortCurrency(money, ess));
		}
	}
예제 #8
0
	protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException
	{
		final Double money = trade.getMoney();
		if (money != null)
		{
			changeAmount(sign, index, money, ess);
		}
		final ItemStack item = trade.getItemStack();
		if (item != null)
		{
			changeAmount(sign, index, item.getAmount(), ess);
		}
		final Integer exp = trade.getExperience();
		if (exp != null)
		{
			changeAmount(sign, index, exp.intValue(), ess);
		}
	}
예제 #9
0
	private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired)
	{
		for (ItemStack item : items)
		{
			if (item == null)
			{
				continue;
			}
			final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
			final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), "repair-item", ess);
			try
			{
				charge.isAffordableFor(user);
			}
			catch (ChargeException ex)
			{
				user.sendMessage(ex.getMessage());
				continue;
			}
			if (!item.getEnchantments().isEmpty()
				&& !Permissions.REPAIR_ENCHANTED.isAuthorized(user))
			{
				continue;
			}

			try
			{
				repairItem(item);
			}
			catch (Exception e)
			{
				continue;
			}
			try
			{
				charge.charge(user);
			}
			catch (ChargeException ex)
			{
				user.sendMessage(ex.getMessage());
			}
			repaired.add(itemName.replace('_', ' '));
		}
	}
예제 #10
0
	@Override
	protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
	{
		if (sign.getLine(3).substring(2).equalsIgnoreCase(username))
		{
			final Trade store = rechargeSign(sign, ess, player);
			Trade stored = null;
			try
			{
				stored = getTrade(sign, 1, true, true, ess);
				subtractAmount(sign, 1, stored, ess);
				stored.pay(player);
			}
			catch (SignException e)
			{
				if (store == null)
				{
					throw new SignException(_("tradeSignEmptyOwner"), e);
				}
			}
			Trade.log("Sign", "Trade", "OwnerInteract", username, store, username, stored, sign.getBlock().getLocation(), ess);
		}
		else
		{
			final Trade charge = getTrade(sign, 1, false, false, ess);
			final Trade trade = getTrade(sign, 2, false, true, ess);
			charge.isAffordableFor(player);
			addAmount(sign, 1, charge, ess);
			subtractAmount(sign, 2, trade, ess);
			if (!trade.pay(player, false))
			{
				subtractAmount(sign, 1, charge, ess);
				addAmount(sign, 2, trade, ess);
				throw new ChargeException("Full inventory");
			}
			charge.charge(player);
			Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, sign.getBlock().getLocation(), ess);
		}
		sign.updateSign();
		return true;
	}
예제 #11
0
	private Trade rechargeSign(final ISign sign, final IEssentials ess, final IUser player) throws SignException, ChargeException
	{
		final Trade trade = getTrade(sign, 2, false, false, ess);
		ItemStack itemInHand = player.getPlayer().getItemInHand();
		if (trade.getItemStack() != null && itemInHand != null
			&& trade.getItemStack().getTypeId() == itemInHand.getTypeId()
			&& trade.getItemStack().getDurability() == itemInHand.getDurability()
			&& trade.getItemStack().getEnchantments().equals(itemInHand.getEnchantments()))
		{
			int amount = itemInHand.getAmount();
			amount -= amount % trade.getItemStack().getAmount();
			if (amount > 0)
			{
				final ItemStack stack = itemInHand.clone();
				stack.setAmount(amount);
				final Trade store = new Trade(stack, ess);
				addAmount(sign, 2, store, ess);
				store.charge(player);
				return store;
			}
		}
		return null;
	}
예제 #12
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}

		if (args[0].equalsIgnoreCase("hand"))
		{
			final ItemStack item = user.getPlayer().getItemInHand();
			if (item == null)
			{
				throw new Exception(_("repairInvalidType"));
			}

			if (!item.getEnchantments().isEmpty()
				&& !Permissions.REPAIR_ENCHANTED.isAuthorized(user))
			{
				throw new Exception(_("repairEnchanted"));
			}

			final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
			final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);

			charge.isAffordableFor(user);

			repairItem(item);

			charge.charge(user);

			user.sendMessage(_("repair", itemName.replace('_', ' ')));
		}
		else if (args[0].equalsIgnoreCase("all"))
		{
			final Trade charge = new Trade("repair-all", ess);
			charge.isAffordableFor(user);
			final List<String> repaired = new ArrayList<String>();
			repairItems(user.getPlayer().getInventory().getContents(), user, repaired);

			if (Permissions.REPAIR_ARMOR.isAuthorized(user))
			{
				repairItems(user.getPlayer().getInventory().getArmorContents(), user, repaired);
			}

			if (repaired.isEmpty())
			{
				throw new Exception(_("repairNone"));
			}
			else
			{
				user.sendMessage(_("repair", Util.joinList(repaired)));
			}
			charge.charge(user);

		}
		else
		{
			throw new NotEnoughArgumentsException();
		}
	}
예제 #13
0
	@Override
	public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
	{
		final Trade charge = new Trade(commandName, ess);
		charge.isAffordableFor(user);
		IUser player = user;
		String homeName = "";
		String[] nameParts;
		if (args.length > 0)
		{
			nameParts = colon.split(args[0]);
			if (nameParts[0].length() == args[0].length() || !Permissions.HOME_OTHERS.isAuthorized(user))
			{
				homeName = nameParts[0];
			}
			else
			{
				player = ess.getUserMap().matchUser(nameParts[0], true);
				if (nameParts.length > 1)
				{
					homeName = nameParts[1];
				}
			}
		}
		try
		{
			if ("bed".equalsIgnoreCase(homeName))
			{
				final Location bed = player.getBedSpawnLocation();
				if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK)
				{
					user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
					throw new NoChargeException();
				}
			}
			goHome(user, player, homeName.toLowerCase(Locale.ENGLISH), charge);
		}
		catch (NotEnoughArgumentsException e)
		{
			Location bed = player.getBedSpawnLocation();
			if (bed != null && bed.getBlock().getType() != Material.BED_BLOCK)
			{
				bed = null;
			}
			final Set<String> homes = player.getHomes();
			if (homes.isEmpty() && player.equals(user))
			{
				if (bed != null)
				{
					user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
					throw new NoChargeException();
				}
				user.getTeleport().respawn(charge, TeleportCause.COMMAND);

			}
			else if (homes.isEmpty())
			{
				throw new Exception(player == user ? _("noHomeSet") : _("noHomeSetPlayer"));
			}
			else if (homes.size() == 1 && player.equals(user))
			{
				goHome(user, player, homes.iterator().next(), charge);
			}
			else
			{
				if (bed != null)
				{
					homes.add("bed");
				}
				user.sendMessage(_("homes", Util.joinList(homes)));
			}
		}
		throw new NoChargeException();
	}
예제 #14
0
	private void sellItem(IUser user, ItemStack is, String[] args, boolean isBulkSell) throws Exception
	{
		if (is == null || is.getType() == Material.AIR)
		{
			throw new Exception(_("itemSellAir"));
		}
		int id = is.getTypeId();
		int amount = 0;
		if (args.length > 1)
		{
			amount = Integer.parseInt(args[1].replaceAll("[^0-9]", ""));
			if (args[1].startsWith("-"))
			{
				amount = -amount;
			}
		}
		double worth = ess.getWorth().getPrice(is);
		boolean stack = args.length > 1 && args[1].endsWith("s");

		if (Double.isNaN(worth))
		{
			throw new Exception(_("itemCannotBeSold"));
		}


		int max = 0;
		for (ItemStack s : user.getInventory().getContents())
		{
			if (s == null)
			{
				continue;
			}
			if (s.getTypeId() != is.getTypeId())
			{
				continue;
			}
			if (s.getDurability() != is.getDurability())
			{
				continue;
			}
			if (!s.getEnchantments().equals(is.getEnchantments()))
			{
				continue;
			}
			max += s.getAmount();
		}

		if (stack)
		{
			amount *= is.getType().getMaxStackSize();
		}
		if (amount < 1)
		{
			amount += max;
		}

		if (amount > max || amount < 1)
		{
			if (!isBulkSell)
			{
				user.sendMessage(_("itemNotEnough1"));
				user.sendMessage(_("itemNotEnough2"));
				throw new Exception(_("itemNotEnough3"));
			}
			else
			{
				return;
			}
		}

		//TODO: Prices for Enchantments
		final ItemStack ris = is.clone();
		ris.setAmount(amount);
		InventoryWorkaround.removeItem(user.getInventory(), true, true, ris);
		user.updateInventory();
		Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth * amount, ess), user.getLocation(), ess);
		user.giveMoney(worth * amount);
		user.sendMessage(_("itemSold", Util.displayCurrency(worth * amount, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth, ess)));
		logger.log(Level.INFO, _("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth * amount, ess), amount, Util.displayCurrency(worth, ess)));

	}