use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandspawner method run.
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length < 1 || args[0].length() < 2) {
throw new NotEnoughArgumentsException(tl("mobsAvailable", StringUtil.joinList(Mob.getMobList())));
}
final Location target = LocationUtil.getTarget(user.getBase());
if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) {
throw new Exception(tl("mobSpawnTarget"));
}
String name = args[0];
int delay = 0;
Mob mob = null;
mob = Mob.fromName(name);
if (mob == null) {
throw new Exception(tl("invalidMob"));
}
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("disabledToSpawnMob"));
}
if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("noPermToSpawnMob"));
}
if (args.length > 1) {
if (NumberUtil.isInt(args[1])) {
delay = Integer.parseInt(args[1]);
}
}
final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
charge.isAffordableFor(user);
try {
CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
spawner.setSpawnedType(mob.getType());
spawner.setDelay(delay);
spawner.update();
} catch (Throwable ex) {
throw new Exception(tl("mobSpawnError"), ex);
}
charge.charge(user);
user.sendMessage(tl("setSpawner", mob.name));
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandrepair method repairHand.
public void repairHand(User user) throws Exception {
final ItemStack item = user.getBase().getItemInHand();
if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
throw new Exception(tl("repairInvalidType"));
}
if (!item.getEnchantments().isEmpty() && !ess.getSettings().getRepairEnchanted() && !user.isAuthorized("essentials.repair.enchanted")) {
throw new Exception(tl("repairEnchanted"));
}
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
charge.isAffordableFor(user);
repairItem(item);
charge.charge(user);
user.getBase().updateInventory();
user.sendMessage(tl("repair", itemName.replace('_', ' ')));
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandjump method run.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length > 0 && args[0].contains("lock") && user.isAuthorized("essentials.jump.lock")) {
if (user.isFlyClickJump()) {
user.setRightClickJump(false);
user.sendMessage("Flying wizard mode disabled");
} else {
user.setRightClickJump(true);
user.sendMessage("Enabling flying wizard mode");
}
return;
}
Location loc;
final Location cloc = user.getLocation();
try {
loc = LocationUtil.getTarget(user.getBase());
loc.setYaw(cloc.getYaw());
loc.setPitch(cloc.getPitch());
loc.setY(loc.getY() + 1);
} catch (NullPointerException ex) {
throw new Exception(tl("jumpError"), ex);
}
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
throw new NoChargeException();
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class SignInfo method onSignInteract.
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
final Trade charge = getTrade(sign, 3, ess);
charge.isAffordableFor(player);
String chapter = sign.getLine(1);
String page = sign.getLine(2);
final IText input;
try {
player.setDisplayNick();
input = new TextInput(player.getSource(), "info", true, ess);
final IText output = new KeywordReplacer(input, player.getSource(), ess);
final TextPager pager = new TextPager(output);
pager.showPage(chapter, page, null, player.getSource());
} catch (IOException ex) {
throw new SignException(ex.getMessage(), ex);
}
charge.charge(player);
Trade.log("Sign", "Info", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
return true;
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class SignRepair method onSignInteract.
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
final Trade charge = getTrade(sign, 2, ess);
charge.isAffordableFor(player);
Commandrepair command = new Commandrepair();
command.setEssentials(ess);
try {
if (sign.getLine(1).equalsIgnoreCase("hand")) {
command.repairHand(player);
} else if (sign.getLine(1).equalsIgnoreCase("all")) {
command.repairAll(player);
} else {
throw new NotEnoughArgumentsException();
}
} catch (Exception ex) {
throw new SignException(ex.getMessage(), ex);
}
charge.charge(player);
Trade.log("Sign", "Repair", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
return true;
}
Aggregations