use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class DifficultyCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
if (args.length != 1) {
sendUsageMessage(sender, messages);
return false;
}
GlowWorld world = CommandUtils.getWorld(sender);
String difficultyId = args[0];
Difficulty difficulty = DIFFICULTIES.nameToValue(messages.getLocale(), difficultyId);
if (difficulty == null) {
new LocalizedStringImpl("difficulty.unknown", messages.getResourceBundle()).sendInColor(ChatColor.RED, sender, difficultyId);
return false;
}
world.setDifficulty(difficulty);
new LocalizedStringImpl("difficulty.done", messages.getResourceBundle()).send(sender, world, DIFFICULTIES.valueToName(messages.getLocale(), difficulty));
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class GameModeCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
if (args.length == 0 || args.length == 1 && !(sender instanceof Player)) {
sendUsageMessage(sender, messages);
return false;
}
final ResourceBundle bundle = messages.getResourceBundle();
String gm = args[0];
GameMode gamemode = GameModeUtils.build(gm, messages.getLocale());
if (gamemode == null) {
new LocalizedStringImpl("gamemode.unknown", bundle).sendInColor(ChatColor.RED, sender, gm);
return false;
}
if (args.length == 1) {
// self
Player player = (Player) sender;
updateGameMode(sender, player, gamemode, bundle);
return true;
}
String name = args[1];
if (name.startsWith("@") && name.length() >= 2 && CommandUtils.isPhysical(sender)) {
Location location = CommandUtils.getLocation(sender);
CommandTarget target = new CommandTarget(sender, name);
Entity[] matched = target.getMatched(location);
for (Entity entity : matched) {
if (entity instanceof Player) {
Player player = (Player) entity;
updateGameMode(sender, player, gamemode, bundle);
}
}
} else {
Player player = Bukkit.getPlayerExact(name);
if (player == null) {
messages.getGeneric(GenericMessage.OFFLINE).sendInColor(ChatColor.RED, sender, name);
} else {
updateGameMode(sender, player, gamemode, bundle);
}
}
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class GameModeCommand method updateGameMode.
private void updateGameMode(CommandSender sender, Player who, GameMode gameMode, ResourceBundle bundle) {
String gameModeName = GameModeUtils.prettyPrint(gameMode, bundle.getLocale());
who.setGameMode(gameMode);
if (!sender.equals(who)) {
new LocalizedStringImpl("gamemode.done", bundle).send(sender, who.getDisplayName(), gameModeName);
// switch to target's locale for gamemode.done.to-you
bundle = getBundle(who);
}
new LocalizedStringImpl("gamemode.done.to-you", bundle).send(who, gameModeName);
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class GiveCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length < 2) {
sendUsageMessage(sender, commandMessages);
return false;
}
String itemName = CommandUtils.toNamespaced(args[1]);
Material type = ItemIds.getItem(itemName);
if (type == null) {
new LocalizedStringImpl("give.unknown", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, itemName);
return false;
}
ItemStack stack = new ItemStack(type);
if (args.length >= 3) {
String amountString = args[2];
try {
int amount = Integer.valueOf(amountString);
if (amount > 64) {
new LocalizedStringImpl("give.too-many", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, amount);
return false;
} else if (amount < 1) {
new LocalizedStringImpl("give.too-few", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, amount);
return false;
}
stack.setAmount(amount);
} catch (NumberFormatException ex) {
commandMessages.getGeneric(GenericMessage.NAN).sendInColor(ChatColor.RED, sender, amountString);
return false;
}
}
String name = args[0];
if (name.startsWith("@") && name.length() >= 2 && CommandUtils.isPhysical(sender)) {
Location location = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation();
CommandTarget target = new CommandTarget(sender, name);
Entity[] matched = target.getMatched(location);
for (Entity entity : matched) {
if (entity instanceof Player) {
Player player = (Player) entity;
giveItem(sender, player, stack, commandMessages.getResourceBundle());
}
}
} else {
Player player = Bukkit.getPlayerExact(name);
if (player == null) {
commandMessages.getGeneric(GenericMessage.OFFLINE).sendInColor(ChatColor.RED, sender, name);
return false;
} else {
giveItem(sender, player, stack, commandMessages.getResourceBundle());
}
}
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class GiveCommand method giveItem.
private void giveItem(CommandSender sender, Player player, ItemStack stack, ResourceBundle resourceBundle) {
player.getInventory().addItem(stack);
new LocalizedStringImpl("give.done", resourceBundle).send(sender, ItemIds.getName(stack.getType()), stack.getAmount(), player.getName());
}
Aggregations