use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class BanCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
final ResourceBundle resourceBundle = commandMessages.getResourceBundle();
if (args.length > 0) {
String name = args[0];
GlowServer server = (GlowServer) ServerProvider.getServer();
// asynchronously lookup player
server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
if (ex != null) {
new LocalizedStringImpl("ban.exception", resourceBundle).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
return;
}
if (player == null) {
commandMessages.getGeneric(GenericMessage.NO_SUCH_PLAYER).sendInColor(ChatColor.RED, sender, name);
return;
}
if (args.length == 1) {
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), null, null, null);
} else {
StringBuilder reason = new StringBuilder();
for (int i = 1; i < args.length; i++) {
reason.append(args[i]).append(" ");
}
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), reason.toString(), null, null);
}
new LocalizedStringImpl("ban.done", resourceBundle).send(sender, player.getName());
});
// todo: asynchronous command callbacks?
return true;
}
sendUsageMessage(sender, commandMessages);
return false;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class CloneCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
if (args.length < 9) {
sendUsageMessage(sender, messages);
return false;
}
final ResourceBundle bundle = messages.getResourceBundle();
if (!CommandUtils.isPhysical(sender)) {
messages.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]);
MaskMode maskMode = args.length >= 10 ? MaskMode.fromCommandName(args[9]) : MaskMode.REPLACE;
CloneMode cloneMode = args.length >= 11 ? CloneMode.fromCommandName(args[10]) : CloneMode.NORMAL;
// TODO: Investigate what happens when maskMode or cloneMode are invalid (thus, null).
if (maskMode == null || cloneMode == null) {
sendUsageMessage(sender, messages);
return false;
}
BlockFilter blockFilter;
switch(maskMode) {
case REPLACE:
blockFilter = new ReplaceBlockFilter();
break;
case MASKED:
blockFilter = new MaskedBlockFilter();
break;
case FILTERED:
if (args.length >= 12) {
Material blockType = ItemIds.getItem(args[11]);
if (args.length >= 13) {
Byte data;
try {
data = Byte.parseByte(args[12]);
} catch (NumberFormatException ignored) {
data = null;
}
if (data == null || 0 > data || data > 15) {
new LocalizedStringImpl("clone.bad-blockdata", bundle).sendInColor(ChatColor.RED, sender);
return false;
} else {
blockFilter = new FilteredWithDataBlockFilter(blockType, data);
}
} else {
blockFilter = new FilteredBlockFilter(blockType);
}
} else {
new LocalizedStringImpl("clone.usage.filtered", bundle).sendInColor(ChatColor.RED, sender);
return false;
}
break;
default:
sendUsageMessage(sender, messages);
return false;
}
RectangularRegion fromRegion = new RectangularRegion(parsedFrom1, parsedFrom2);
RectangularRegion toRegion = fromRegion.moveTo(to);
Location lowCorner = fromRegion.getLowCorner();
Location highCorner = fromRegion.getHighCorner();
boolean overlaps = between(lowCorner.getBlockX(), highCorner.getBlockX(), to.getBlockX()) || between(lowCorner.getBlockY(), highCorner.getBlockY(), to.getBlockY()) || between(lowCorner.getBlockZ(), highCorner.getBlockZ(), to.getBlockZ());
if (overlaps && !cloneMode.isAllowedToOverlap()) {
sendUsageMessage(sender, messages);
return false;
}
int blocksCloned = 0;
IterationDirection directionX = to.getBlockX() < lowCorner.getBlockX() ? IterationDirection.FORWARDS : IterationDirection.BACKWARDS;
IterationDirection directionY = to.getBlockY() < lowCorner.getBlockY() ? IterationDirection.FORWARDS : IterationDirection.BACKWARDS;
IterationDirection directionZ = to.getBlockZ() < lowCorner.getBlockZ() ? IterationDirection.FORWARDS : IterationDirection.BACKWARDS;
Iterator<Location> fromIterator = fromRegion.blockLocations(directionX, directionY, directionZ).iterator();
Iterator<Location> toIterator = toRegion.blockLocations(directionX, directionY, directionZ).iterator();
while (fromIterator.hasNext() && toIterator.hasNext()) {
Location fromLocation = fromIterator.next();
Location toLocation = toIterator.next();
GlowBlock fromBlock = world.getBlockAt(fromLocation);
if (blockFilter.shouldClone(fromBlock)) {
GlowBlock toBlock = world.getBlockAt(toLocation);
toBlock.setType(fromBlock.getType());
toBlock.setBlockData(fromBlock.getBlockData());
BlockEntity fromEntity = fromBlock.getBlockEntity();
if (fromEntity != null) {
BlockEntity toEntity = toBlock.getChunk().createEntity(toBlock.getX(), toBlock.getY(), toBlock.getZ(), toBlock.getType());
if (toEntity != null) {
CompoundTag entityTag = new CompoundTag();
fromEntity.saveNbt(entityTag);
toEntity.loadNbt(entityTag);
}
}
if (cloneMode == CloneMode.MOVE) {
fromBlock.setType(Material.AIR, false);
}
blocksCloned++;
}
}
switch(blocksCloned) {
case 0:
new LocalizedStringImpl("clone.done.zero", bundle).sendInColor(ChatColor.RED, sender);
break;
case 1:
new LocalizedStringImpl("clone.done.singular", bundle).send(sender);
break;
default:
new LocalizedStringImpl("clone.done", bundle).send(sender, blocksCloned);
}
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class EffectCommand 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 name = args[0];
List<GlowPlayer> players;
if (name.startsWith("@") && name.length() >= 2) {
CommandTarget target = new CommandTarget(sender, name);
players = Arrays.stream(target.getMatched(CommandUtils.getLocation(sender))).filter(GlowPlayer.class::isInstance).map(GlowPlayer.class::cast).collect(Collectors.toList());
} else {
GlowPlayer player = (GlowPlayer) Bukkit.getPlayerExact(args[0]);
if (player == null) {
commandMessages.getGeneric(GenericMessage.NO_SUCH_PLAYER).sendInColor(ChatColor.RED, sender, name);
return false;
} else {
players = Collections.singletonList(player);
}
}
if (args[1].equals("clear")) {
// NON-NLS
for (GlowPlayer player : players) {
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
player.removePotionEffect(potionEffect.getType());
}
new LocalizedStringImpl("effect.cleared", commandMessages.getResourceBundle()).send(sender, player.getName());
}
return true;
} else {
PotionEffectType effectType = GlowPotionEffect.parsePotionEffectId(args[1]);
if (effectType == null) {
new LocalizedStringImpl("effect.unknown", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, args[1]);
return false;
}
int duration = TickUtil.secondsToTicks(30);
if (args.length >= 3 && args[2] != null) {
try {
duration = TickUtil.secondsToTicks(Integer.parseInt(args[2]));
} catch (NumberFormatException exc) {
commandMessages.getGeneric(GenericMessage.NAN).sendInColor(ChatColor.RED, sender, args[2]);
return false;
}
}
int amplifier = 0;
if (args.length >= 4 && args[3] != null) {
try {
amplifier = Integer.parseInt(args[3]);
} catch (NumberFormatException exc) {
commandMessages.getGeneric(GenericMessage.NAN).sendInColor(ChatColor.RED, sender, args[3]);
return false;
}
}
boolean hideParticles = false;
if (args.length >= 5 && args[4] != null) {
hideParticles = Boolean.parseBoolean(args[4]);
}
LocalizedStringImpl doneMessage = new LocalizedStringImpl("effect.done", commandMessages.getResourceBundle());
for (GlowPlayer player : players) {
player.addPotionEffect(new PotionEffect(effectType, duration, amplifier, false, !hideParticles));
doneMessage.send(sender, effectType.getName(), effectType.getId(), amplifier + 1, player.getName(), duration / 20);
}
return true;
}
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class FunctionCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length == 0 || args.length == 2) {
sendUsageMessage(sender, commandMessages);
return false;
}
GlowWorld world = CommandUtils.getWorld(sender);
Location location = CommandUtils.getLocation(sender);
String functionName = args[0];
Map<String, CommandFunction> functions = world.getFunctions();
if (!functions.containsKey(functionName)) {
new LocalizedStringImpl("function.unknown", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, functionName);
return false;
}
CommandFunction function = functions.get(functionName);
if (args.length > 2) {
String condition = args[1].toLowerCase(Locale.ENGLISH);
if (condition.equals("if")) {
// NON-NLS
if (!anyMatch(sender, args[2], location)) {
new LocalizedStringImpl("function.skipped", commandMessages.getResourceBundle()).send(sender, function.getFullName());
return false;
}
} else if (condition.equals("unless")) {
// NON-NLS
if (anyMatch(sender, args[2], location)) {
new LocalizedStringImpl("function.skipped", commandMessages.getResourceBundle()).send(sender, function.getFullName());
return false;
}
} else {
sendUsageMessage(sender, commandMessages);
return false;
}
}
function.execute(sender);
return true;
}
use of net.glowstone.i18n.LocalizedStringImpl in project Glowstone by GlowstoneMC.
the class KillCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length == 0) {
if (sender instanceof Entity) {
Entity entity = (Entity) sender;
if (entity.isDead()) {
new LocalizedStringImpl("kill.self-dead", commandMessages.getResourceBundle()).send(entity);
} else if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity) entity;
living.damage(Double.MAX_VALUE, EntityDamageEvent.DamageCause.SUICIDE);
new LocalizedStringImpl("kill.done", commandMessages.getResourceBundle()).send(sender, CommandUtils.getName(entity));
} else {
entity.remove();
new LocalizedStringImpl("kill.done", commandMessages.getResourceBundle()).send(sender, CommandUtils.getName(entity));
}
return true;
} else {
new LocalizedStringImpl("kill.self-not-entity", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender);
return false;
}
}
if (args.length == 1) {
String name = args[0];
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);
if (matched.length == 0) {
commandMessages.getGeneric(GenericMessage.NO_MATCHES).sendInColor(ChatColor.RED, sender, name);
return false;
}
LocalizedStringImpl killDoneMessage = new LocalizedStringImpl("kill.done", commandMessages.getResourceBundle());
for (Entity entity : matched) {
if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity) entity;
living.damage(Double.MAX_VALUE, EntityDamageEvent.DamageCause.VOID);
} else {
entity.remove();
}
killDoneMessage.send(sender, CommandUtils.getName(entity));
}
return true;
} else {
Player player = Bukkit.getPlayerExact(name);
if (player == null) {
commandMessages.getGeneric(GenericMessage.NO_SUCH_PLAYER).sendInColor(ChatColor.RED, sender, name);
return false;
} else {
player.damage(Double.MAX_VALUE, EntityDamageEvent.DamageCause.VOID);
new LocalizedStringImpl("kill.done", commandMessages.getResourceBundle()).send(sender, player.getName());
return true;
}
}
}
sendUsageMessage(sender, commandMessages);
return false;
}
Aggregations