use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class SummonCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (sender instanceof ConsoleCommandSender) {
commandMessages.getGeneric(GenericMessage.NOT_PHYSICAL).send(sender);
return true;
}
Location location = CommandUtils.getLocation(sender);
if (args.length == 0) {
sendUsageMessage(sender, commandMessages);
return false;
}
if (args.length >= 4) {
location = CommandUtils.getLocation(location, args[1], args[2], args[3]);
}
location.setYaw(0.0f);
location.setPitch(0.0f);
CompoundTag tag = null;
if (args.length >= 5) {
String data = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(4, args.length));
try {
tag = Mojangson.parseCompound(data);
} catch (MojangsonParseException e) {
commandMessages.getGeneric(GenericMessage.INVALID_JSON).sendInColor(ChatColor.RED, sender, e.getMessage());
}
}
String entityName = args[0];
if (!checkSummon(sender, entityName, commandMessages)) {
return true;
}
GlowEntity entity;
if (EntityType.fromName(entityName) != null) {
entity = (GlowEntity) location.getWorld().spawnEntity(location, EntityType.fromName(entityName));
} else {
Class<? extends GlowEntity> clazz = EntityRegistry.getCustomEntityDescriptor(entityName).getEntityClass();
entity = ((GlowWorld) location.getWorld()).spawn(location, clazz, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
if (tag != null) {
EntityStorage.load(entity, tag);
}
new LocalizedStringImpl("summon.done", commandMessages.getResourceBundle()).send(sender);
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class TellCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length <= 1) {
sendUsageMessage(sender, commandMessages);
return false;
}
String name = args[0];
Player[] players;
if (name.charAt(0) == '@' && CommandUtils.isPhysical(sender)) {
Location location = CommandUtils.getLocation(sender);
CommandTarget target = new CommandTarget(sender, name);
target.getArguments().put("type", // NON-NLS; only players
new CommandTarget.SelectorValue("player"));
Entity[] matched = target.getMatched(location);
if (matched.length == 0) {
commandMessages.getGeneric(GenericMessage.NO_MATCHES).sendInColor(ChatColor.RED, sender, name);
return false;
}
players = new Player[matched.length];
for (int i = 0; i < matched.length; i++) {
players[i] = (Player) matched[i];
}
} else {
Player player = Bukkit.getPlayer(name);
if (player == null) {
commandMessages.getGeneric(GenericMessage.NO_SUCH_PLAYER).sendInColor(ChatColor.RED, sender, name);
return false;
}
players = new Player[] { player };
}
String senderName = CommandUtils.getName(sender);
String message = StringUtils.join(args, ' ', 1, args.length);
ResourceBundle bundle = commandMessages.getResourceBundle();
LocalizedStringImpl senderMessage = new LocalizedStringImpl("tell.sender", bundle);
for (Player player : players) {
if (sender.equals(player)) {
new LocalizedStringImpl("tell.self", bundle).sendInColor(ChatColor.RED, sender);
continue;
}
new LocalizedStringImpl("tell.recipient", getBundle(player)).send(player, senderName, message);
senderMessage.send(sender, senderName, player.getName(), message);
}
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class TestForBlockCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
if (args.length < 4) {
sendUsageMessage(sender, messages);
return false;
}
String itemName = CommandUtils.toNamespaced(args[3].toLowerCase());
Material type = ItemIds.getBlock(itemName);
ResourceBundle bundle = messages.getResourceBundle();
if (type == null) {
new LocalizedStringImpl("testforblock.invalid-block", bundle).sendInColor(ChatColor.RED, sender, itemName);
}
Location location = CommandUtils.getLocation(CommandUtils.getLocation(sender), args[0], args[1], args[2]);
GlowBlock block = (GlowBlock) location.getBlock();
if (block.getType() != type) {
new LocalizedStringImpl("testforblock.wrong-block", bundle).sendInColor(ChatColor.RED, sender, location.getBlockX(), location.getBlockY(), location.getBlockZ(), ItemIds.getName(block.getType()), ItemIds.getName(type));
return false;
}
if (args.length > 4) {
String state = args[4];
BlockStateData data = CommandUtils.readState(sender, block.getType(), state);
if (data == null) {
return false;
}
if (data.isNumeric() && block.getData() != data.getNumericValue()) {
new LocalizedStringImpl("testforblock.wrong-data", bundle).sendInColor(ChatColor.RED, sender, location.getBlockX(), location.getBlockY(), location.getBlockZ(), block.getData(), data);
return false;
} else if (!data.isNumeric()) {
try {
boolean matches = StateSerialization.matches(block.getType(), block.getState().getData(), data);
if (!matches) {
// TODO: Print the actual state of the block
new LocalizedStringImpl("testforblock.wrong-state", bundle).sendInColor(ChatColor.RED, sender, location.getBlockX(), location.getBlockY(), location.getBlockZ(), state);
return false;
}
} catch (InvalidBlockStateException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
return false;
}
}
}
if (args.length > 5 && block.getBlockEntity() != null) {
String dataTag = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(5, args.length));
try {
CompoundTag tag = Mojangson.parseCompound(dataTag);
CompoundTag blockTag = new CompoundTag();
block.getBlockEntity().saveNbt(blockTag);
if (!tag.matches(blockTag)) {
new LocalizedStringImpl("testforblock.wrong-data", bundle).sendInColor(ChatColor.RED, sender, location.getBlockX(), location.getBlockY(), location.getBlockZ(), blockTag, tag);
return false;
}
} catch (MojangsonParseException e) {
messages.getGeneric(GenericMessage.INVALID_JSON).sendInColor(ChatColor.RED, sender, e.getMessage());
return false;
}
}
// All is well
new LocalizedStringImpl("testforblock.done", bundle).send(sender, location.getBlockX(), location.getBlockY(), location.getBlockZ());
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class TestForBlocksCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length < 9) {
sendUsageMessage(sender, commandMessages);
return false;
}
if (!CommandUtils.isPhysical(sender)) {
commandMessages.getGeneric(GenericMessage.NOT_PHYSICAL).send(sender);
return false;
}
GlowWorld world = CommandUtils.getWorld(sender);
Location parsedFrom1 = CommandUtils.getLocation(sender, args[0], args[1], args[2]);
Location parsedFrom2 = CommandUtils.getLocation(sender, args[3], args[4], args[5]);
Location to = CommandUtils.getLocation(sender, args[6], args[7], args[8]);
MatchMode matchMode = args.length >= 10 ? MatchMode.fromCommandName(args[9]) : MatchMode.ALL;
if (matchMode == null) {
sendUsageMessage(sender, commandMessages);
return false;
}
RectangularRegion fromRegion = new RectangularRegion(parsedFrom1, parsedFrom2);
RectangularRegion toRegion = fromRegion.moveTo(to);
Iterator<Location> fromIterator = fromRegion.blockLocations(FORWARDS, FORWARDS, FORWARDS).iterator();
Iterator<Location> toIterator = toRegion.blockLocations(FORWARDS, FORWARDS, FORWARDS).iterator();
int blocksMatched = 0;
ResourceBundle bundle = commandMessages.getResourceBundle();
while (fromIterator.hasNext() && toIterator.hasNext()) {
Location fromLocation = fromIterator.next();
Location toLocation = toIterator.next();
GlowBlock fromBlock = world.getBlockAt(fromLocation);
GlowBlock toBlock = world.getBlockAt(toLocation);
if (matchMode.matches(fromBlock, toBlock)) {
if (!matchMode.isFiltered(fromBlock)) {
blocksMatched++;
}
} else {
new LocalizedStringImpl("testforblocks.no-match", bundle).sendInColor(ChatColor.RED, sender);
return false;
}
}
new LocalizedStringImpl("testforblocks.done", bundle).send(sender, blocksMatched);
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class ToggleDownfallCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
final World world = CommandUtils.getWorld(sender);
world.setThundering(!world.hasStorm());
world.setStorm(!world.hasStorm());
new LocalizedStringImpl("toggledownfall.done", commandMessages.getResourceBundle()).send(sender);
return true;
}
Aggregations