Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
Fixed translation argument translation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxammann committed Nov 14, 2014
1 parent 64f66f2 commit 36ab5d8
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 44 deletions.
40 changes: 40 additions & 0 deletions src/main/java/net/catharos/societies/StringDictionary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.catharos.societies;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import net.catharos.lib.core.i18n.DefaultDictionary;
import net.catharos.societies.bridge.ChatColor;

import java.util.Locale;

/**
* Represents a StringDictionary
*/
public class StringDictionary extends DefaultDictionary<String> {

@Inject
public StringDictionary(@Named("default-locale") Locale defaultLocale) {
super(defaultLocale);
}

@Override
public String getTranslation(String key, String locale, Object... args) {
translateArguments(args);
ChatColor.argumentColorReset(args);
return super.getTranslation(key, locale, args);
}

private void translateArguments(Object... args) {
for (int i = 0, length = args.length; i < length; i++) {
Object arg = args[i];

if (arg instanceof String) {
if (((String) arg).startsWith(":")) {
args[i] = getTranslation(((String) arg).substring(1));
}

args[i] = args[i] + ChatColor.RESET.toString();
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/catharos/societies/bridge/ChatColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void argumentColorReset(Object[] args) {
Object arg = args[i];

if (arg instanceof String) {
args[i] = arg + org.bukkit.ChatColor.RESET.toString();
args[i] = arg + RESET.toString();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.jetbrains.annotations.Nullable;

import javax.inject.Provider;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.UUID;

Expand Down Expand Up @@ -118,9 +117,7 @@ public void send(String message, Object... args) {
return;
}

ChatColor.argumentColorReset(args);

player.sendMessage(MessageFormat.format(directory.getTranslation(message), args));
player.sendMessage(directory.getTranslation(message, args));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void execute(CommandContext<S> ctx, S sender) {
sender.send(help);
}

public void execute(GroupCommand<S> command, S sender, LinkedList<Command> pre, Table table) {
public void execute(GroupCommand<S> command, S sender, LinkedList<Command> stack, Table table) {

if (!command.getSenderClass().isInstance(sender)) {
return;
Expand All @@ -57,19 +57,19 @@ public void execute(GroupCommand<S> command, S sender, LinkedList<Command> pre,
if (cmd instanceof ExecutableCommand) {
ExecutableCommand executableCommand = (ExecutableCommand) cmd;

append(builder, executableCommand, pre);
append(builder, executableCommand, stack);
appendDesc(builder, cmd);

table.addRow(builder);
} else {
append(builder, cmd, pre);
append(builder, cmd, stack);
appendDesc(builder, cmd);

table.addRow(builder);

pre.push(cmd);
execute(((GroupCommand<S>) cmd), sender, pre, table);
pre.pop();
stack.push(cmd);
execute(((GroupCommand<S>) cmd), sender, stack, table);
stack.pop();
}
}
}
Expand All @@ -96,11 +96,11 @@ private StringBuilder append(StringBuilder builder, ExecutableCommand<?> command
List<Argument> arguments = command.getArguments();

for (Argument argument : arguments) {
builder.append(' ').append(argument.getName());
builder.append(" [").append(argument.getName()).append(']');
}

for (Argument option : command.getOptions().values()) {
builder.append(" [--").append(option.getName()).append("]");
builder.append(" [--").append(option.getName()).append(']');
}

return builder;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/catharos/societies/commands/RuleStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public void execute(CommandContext<Sender> ctx, Sender sender) throws ExecuteExc
return;
}

if (!member.hasGroup()) {
sender.send("society.not-found");
ctx.cancel();
return;
}

if (!member.hasRule("*") && !member.hasRule(rule)) {
sender.send("no-rule");
ctx.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class RuleCommand {
@Sender(Member.class)
public static class ListCommand implements Executor<Member> {

@Argument(name = "argument.rank.name", description = "The name of the new rank")
@Argument(name = "argument.rank", description = "The name of the new rank")
String name;

@Override
Expand Down Expand Up @@ -79,7 +79,7 @@ public void execute(CommandContext<Member> ctx, Member sender) throws ExecuteExc
@Sender(Member.class)
public static class AssignCommand implements Executor<Member> {

@Argument(name = "argument.rank.name", description = "The name of the new rank")
@Argument(name = "argument.rank", description = "The name of the new rank")
String name;


Expand Down Expand Up @@ -129,7 +129,7 @@ public void execute(CommandContext<Member> ctx, Member sender) {
@Sender(Member.class)
public static class RemoveCommand implements Executor<Member> {

@Argument(name = "argument.rank.name", description = "The name of the new rank")
@Argument(name = "argument.rank", description = "The name of the new rank")
String name;

@Argument(name = "argument.rank.rule")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.google.inject.TypeLiteral;
import net.catharos.lib.core.i18n.Dictionary;
import net.catharos.lib.core.i18n.MutableDictionary;
import net.catharos.lib.core.i18n.StringDictionary;
import net.catharos.societies.StringDictionary;
import net.catharos.lib.shank.service.AbstractServiceModule;

import java.io.File;
Expand Down
16 changes: 10 additions & 6 deletions src/main/resources/languages/default/general.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ command.vote.deny=deny
command.reload=reload
command.backup=backup

command.promote=promote
command.demote=demote

argument.target.file=file
argument.society.name-new=newName
argument.society.tag-new=newTag
argument.target.society=target
argument.target.member=target
argument.target.society=society
argument.target.member=member
argument.society.name=name
argument.society.tag=tag
argument.location=location
argument.rank.name=value
argument.rank=rank
argument.rank.name=name
argument.rank.rule=rule
argument.rank.priority=priority
argument.page=page
Expand Down Expand Up @@ -232,10 +236,10 @@ profile.active=Active

lookup.name=Name: {0}
lookup.society=Society: {0}
lookup.society-tag=Society tag: {0}
lookup.society-tag=Tag: {0}
lookup.rank=Rank: {0}
lookup.uuid=Name: {0}
lookup.join-date=Universal Unique Identifier: {0}
lookup.uuid=Universal Unique Identifier: {0}
lookup.join-date=Join date: {0}
lookup.last-seen=Last seen: {0}
lookup.inactive=Inactive: {0}
lookup.ranks=Ranks:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ authors:
- p000ison
commands:
society:
aliases: [ societies, s ]
description: Society main command
usage: None
34 changes: 13 additions & 21 deletions src/main/resources/todo
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
+(- ff.auto ff.deny profile.active lookup.online)

- /rank create problem ??
(- ff.auto ff.deny profile.active lookup.online)

- extended chat integration

- events (mbassador)

- add descriptions
- list only accessible commands in help
- split in modules
- wars/claiming
- BulletinBoard
- command options
* list only verified
* coords sort
- Performance: Lazy loading of settings/ranks
- cache levels (quick-living cache)
- over-think publishers, collect publishers
- log support
- future api (FutureSupplier with predefined exception handlers)
- Command library: extract information from context and inject them to fields

Bukkit dependencies:
* Player.getLocation()
* Player.sendMessage(...); +
* Server.getWorld(...);
* Server.getScheduler();
* Server.getConsoleCommandSender();
* ChatColor
* JavaPlugin
- future api (FutureSupplier with predefined exception handlers) jdeferred
- Command library: aliases, extract information from context and inject them to fields

Config:
Settings:
Expand All @@ -34,12 +24,14 @@ Config:
kill-weights.civilian

Text renderer:
* Tree like structure
* Tree like structure

Caching
* Pre-rendered listing output


Optimization:
- fast access player metadata -> player, getMember(Player player)
- cache relation targets
- fast access player metadata -> player, getMember(Player player)
- cache relation targets
- cache levels (quick-living cache)
- Lazy loading of settings/ranks
- Caching
* Pre-rendered listing output

0 comments on commit 36ab5d8

Please sign in to comment.