Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b535198
Merge pull request #1 from EssentialsX/2.x
Banbeucmas Mar 23, 2018
0dda123
Adding EssentialsWarpEvent for checking if player is wrapping
Banbeucmas Mar 24, 2018
d6af21c
Spacing
Banbeucmas Mar 24, 2018
aadcd82
Adding Trade parameter
Banbeucmas Mar 24, 2018
5176f3c
Refactoring
Banbeucmas Mar 24, 2018
5713538
Adding #setWarp() to the Event
Banbeucmas Mar 24, 2018
0714f53
Spacing
Banbeucmas Mar 26, 2018
e66e636
Documenting the purpose of the Event
Banbeucmas Mar 26, 2018
e203c3f
Adding the option to use PlaceholderAPI chat format internally
Banbeucmas Apr 1, 2018
9935e93
Merge remote-tracking branch 'origin/papi' into papi
Banbeucmas Apr 1, 2018
cf960bf
Pull from upstream
Banbeucmas Apr 1, 2018
470db34
Update pom.xml
Banbeucmas Apr 1, 2018
460facd
Switching method to FormatUtils
Banbeucmas Apr 1, 2018
f0800f6
Only check whether PAPI is enabled first time
mdcfe Apr 3, 2018
4d639c7
Add placeholderAPIFormat overload
mdcfe Apr 3, 2018
02b1425
Add tl overload for PAPI formatting
mdcfe Apr 3, 2018
8d01691
Rename new tl to tlp, deprecate old tl
mdcfe Apr 3, 2018
002470b
Allow passing Player to tlp
mdcfe Apr 3, 2018
f8ae0b7
Replace {} into %%, allow the config can be kept in sync.
Banbeucmas Apr 3, 2018
7a933f4
Allow passing CommandSource to tlp
mdcfe Apr 3, 2018
d07ed26
Merge remote-tracking branch 'origin/papi' into papi
Banbeucmas Apr 3, 2018
a9a6875
Switch tl to tlp, part 1
mdcfe Apr 3, 2018
e2aa8c1
Switch tl to tlp, part 2
mdcfe Apr 3, 2018
917324c
Switch tl to tlp, part 3 - commands
mdcfe Apr 3, 2018
de44b37
Switch tl to tlp, part 4
mdcfe Apr 3, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Essentials/src/com/earth2me/essentials/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlp;


public class Backup implements Runnable {
Expand Down Expand Up @@ -73,7 +73,7 @@ public void run() {
active = false;
return;
}
LOGGER.log(Level.INFO, tl("backupStarted"));
LOGGER.log(Level.INFO, tlp(null, "backupStarted"));
final CommandSender cs = server.getConsoleSender();
server.dispatchCommand(cs, "save-all");
server.dispatchCommand(cs, "save-off");
Expand Down Expand Up @@ -121,7 +121,7 @@ public void run() {
stopTask();
}
active = false;
LOGGER.log(Level.INFO, tl("backupFinished"));
LOGGER.log(Level.INFO, tlp(null, "backupFinished"));
}
}
ess.scheduleSyncDelayedTask(new BackupEnableSaveTask());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlp;


public class EssentialsEntityListener implements Listener {
Expand Down Expand Up @@ -143,7 +143,7 @@ public void onPlayerDeathEvent(final PlayerDeathEvent event) {
final User user = ess.getUser(event.getEntity());
if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back")) {
user.setLastLocation();
user.sendMessage(tl("backAfterDeath"));
user.sendMessage(tlp(user, "backAfterDeath"));
}
if (!ess.getSettings().areDeathMessagesEnabled()) {
event.setDeathMessage("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlp;


public class EssentialsPlayerListener implements Listener {
Expand Down Expand Up @@ -80,8 +80,8 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
final User user = ess.getUser(event.getPlayer());
if (user.isMuted()) {
event.setCancelled(true);
user.sendMessage(tl("voiceSilenced"));
LOGGER.info(tl("mutedUserSpeaks", user.getName(), event.getMessage()));
user.sendMessage(tlp(user, "voiceSilenced"));
LOGGER.info(tlp(null, "mutedUserSpeaks", user.getName(), event.getMessage()));
}
try {
final Iterator<Player> it = event.getRecipients().iterator();
Expand Down Expand Up @@ -276,7 +276,7 @@ public void run() {
final List<String> mail = user.getMails();
if (mail.isEmpty()) {
if (ess.getSettings().isNotifyNoNewMail()) {
user.sendMessage(tl("noNewMail")); // Only notify if they want us to.
user.sendMessage(tlp(user, "noNewMail")); // Only notify if they want us to.
}
} else {
user.notifyOfMail();
Expand All @@ -289,7 +289,7 @@ public void run() {
user.getBase().setAllowFlight(true);
user.getBase().setFlying(true);
if (ess.getSettings().isSendFlyEnableOnJoin()) {
user.getBase().sendMessage(tl("flyMode", tl("enabled"), user.getDisplayName()));
user.getBase().sendMessage(tlp(user, "flyMode", tlp(user, "enabled"), user.getDisplayName()));
}
}
}
Expand Down Expand Up @@ -369,14 +369,14 @@ public void onPlayerLoginBanned(final PlayerLoginEvent event) {
Date banExpiry = banEntry.getExpiration();
if (banExpiry != null) {
String expiry = DateUtil.formatDateDiff(banExpiry.getTime());
event.setKickMessage(tl("tempbanJoin", expiry, banEntry.getReason()));
event.setKickMessage(tlp(event.getPlayer(), "tempbanJoin", expiry, banEntry.getReason()));
} else {
event.setKickMessage(tl("banJoin", banEntry.getReason()));
event.setKickMessage(tlp(event.getPlayer(), "banJoin", banEntry.getReason()));
}
} else {
banEntry = ess.getServer().getBanList(BanList.Type.IP).getBanEntry(event.getAddress().getHostAddress());
if (banEntry != null) {
event.setKickMessage(tl("banIpJoin", banEntry.getReason()));
event.setKickMessage(tlp(event.getPlayer(), "banIpJoin", banEntry.getReason()));
}
}
break;
Expand All @@ -394,7 +394,7 @@ public void onPlayerLogin(final PlayerLoginEvent event) {
event.allow();
return;
}
event.disallow(Result.KICK_FULL, tl("serverFull"));
event.disallow(Result.KICK_FULL, tlp(kfuser, "serverFull"));
break;
default:
break;
Expand Down Expand Up @@ -456,10 +456,10 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
for (User spyer : ess.getOnlineUsers()) {
if (spyer.isSocialSpyEnabled() && !player.equals(spyer.getBase())) {
if (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers()) {
spyer.sendMessage(tl("socialSpyMutedPrefix") + player.getDisplayName() + ": " + event.getMessage());
spyer.sendMessage(tlp(spyer, "socialSpyMutedPrefix") + player.getDisplayName() + ": " + event.getMessage());
}
else {
spyer.sendMessage(tl("socialSpyPrefix") + player.getDisplayName() + ": " + event.getMessage());
spyer.sendMessage(tlp(spyer, "socialSpyPrefix") + player.getDisplayName() + ": " + event.getMessage());
}
}
}
Expand All @@ -469,8 +469,8 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)

if (ess.getUser(player).isMuted() && (ess.getSettings().getMuteCommands().contains(cmd) || ess.getSettings().getMuteCommands().contains("*"))) {
event.setCancelled(true);
player.sendMessage(tl("voiceSilenced"));
LOGGER.info(tl("mutedUserSpeaks", player.getName(), event.getMessage()));
player.sendMessage(tlp(ess.getUser(player), "voiceSilenced"));
LOGGER.info(tlp(null, "mutedUserSpeaks", player.getName(), event.getMessage()));
return;
}

Expand Down Expand Up @@ -512,7 +512,7 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
// User's current cooldown hasn't expired, inform and terminate cooldown code.
if (entry.getValue() > System.currentTimeMillis()) {
String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue());
user.sendMessage(tl("commandCooldown", commandCooldownTime));
user.sendMessage(tlp(user, "commandCooldown", commandCooldownTime));
cooldownFound = true;
event.setCancelled(true);
break;
Expand Down Expand Up @@ -571,11 +571,11 @@ public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
if (ess.getSettings().getNoGodWorlds().contains(newWorld) && user.isGodModeEnabledRaw()) {
// Player god mode is never disabled in order to retain it when changing worlds once more.
// With that said, players will still take damage as per the result of User#isGodModeEnabled()
user.sendMessage(tl("noGodWorldWarning"));
user.sendMessage(tlp(user, "noGodWorldWarning"));
}

if (!user.getWorld().getName().equals(newWorld)) {
user.sendMessage(tl("currentWorld", newWorld));
user.sendMessage(tlp(user, "currentWorld", newWorld));
}
if (user.isVanished()) {
user.setVanished(user.isAuthorized("essentials.vanish"));
Expand All @@ -590,7 +590,7 @@ public void onPlayerInteract(final PlayerInteractEvent event) {
User player = ess.getUser(event.getPlayer());
if (player.isAuthorized("essentials.sethome.bed")) {
player.getBase().setBedSpawnLocation(event.getClickedBlock().getLocation());
player.sendMessage(tl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
player.sendMessage(tlp(player, "bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
}
}
break;
Expand Down
22 changes: 22 additions & 0 deletions Essentials/src/com/earth2me/essentials/I18n.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.earth2me.essentials;

import net.ess3.api.IEssentials;
import net.ess3.api.IUser;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -14,6 +15,10 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;

import com.earth2me.essentials.utils.FormatUtil;

import org.bukkit.entity.Player;


public class I18n implements net.ess3.api.II18n {
private static I18n instance;
Expand Down Expand Up @@ -69,6 +74,23 @@ private String translate(final String string) {
}
}

@SuppressWarnings("deprecation")
public static String tlp(final Object target, final String string, final Object... objects) {
String formatted = string;
if (target instanceof IUser) {
formatted = FormatUtil.placeholderAPIFormat((IUser) target, string);
} else if (target instanceof Player) {
formatted = FormatUtil.placeholderAPIFormat((Player) target, string);
} else if (target instanceof CommandSource && ((CommandSource) target).getSender() instanceof Player) {
formatted = FormatUtil.placeholderAPIFormat((Player) ((CommandSource) target).getSender(), string);
} else {
formatted = FormatUtil.placeholderAPIFormat((Player) null, string);
}

return tl(formatted, objects);
}

@Deprecated
public static String tl(final String string, final Object... objects) {
if (instance == null) {
return "";
Expand Down
3 changes: 2 additions & 1 deletion Essentials/src/com/earth2me/essentials/ItemDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.regex.Pattern;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlp;


public class ItemDb implements IConf, net.ess3.api.IItemDb {
Expand Down Expand Up @@ -232,7 +233,7 @@ public List<ItemStack> getMatching(User user, String[] args) throws Exception {
}

if (is.isEmpty() || is.get(0).getType() == Material.AIR) {
throw new Exception(tl("itemSellAir"));
throw new Exception(tlp(user, "itemSellAir"));
}

return is;
Expand Down
13 changes: 7 additions & 6 deletions Essentials/src/com/earth2me/essentials/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.logging.Level;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlp;


public class Kit {
Expand All @@ -42,7 +43,7 @@ public String getName() {

public void checkPerms(final User user) throws Exception {
if (!user.isAuthorized("essentials.kits." + kitName)) {
throw new Exception(tl("noKitPermission", "essentials.kits." + kitName));
throw new Exception(tlp(user, "noKitPermission", "essentials.kits." + kitName));
}
}

Expand All @@ -52,10 +53,10 @@ public void checkDelay(final User user) throws Exception {
if (nextUse == 0L) {
return;
} else if (nextUse < 0L) {
user.sendMessage(tl("kitOnce"));
user.sendMessage(tlp(user, "kitOnce"));
throw new NoChargeException();
} else {
user.sendMessage(tl("kitTimed", DateUtil.formatDateDiff(nextUse)));
user.sendMessage(tlp(user, "kitTimed", DateUtil.formatDateDiff(nextUse)));
throw new NoChargeException();
}
}
Expand Down Expand Up @@ -85,7 +86,7 @@ public long getNextUse(final User user) throws Exception {
// Make sure delay is valid
delay = kit.containsKey("delay") ? ((Number) kit.get("delay")).doubleValue() : 0.0d;
} catch (Exception e) {
throw new Exception(tl("kitError2"));
throw new Exception(tlp(user, "kitError2"));
}

// When was the last kit used?
Expand Down Expand Up @@ -203,12 +204,12 @@ public void expandItems(final User user, final List<String> items) throws Except
}
user.getBase().updateInventory();
if (spew) {
user.sendMessage(tl("kitInvFull"));
user.sendMessage(tlp(user, "kitInvFull"));
}
} catch (Exception e) {
user.getBase().updateInventory();
ess.getLogger().log(Level.WARNING, e.getMessage());
throw new Exception(tl("kitError2"), e);
throw new Exception(tlp(user, "kitError2"), e);
}
}
}
5 changes: 3 additions & 2 deletions Essentials/src/com/earth2me/essentials/MetaItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.regex.Pattern;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlp;


public class MetaItemStack {
Expand Down Expand Up @@ -476,7 +477,7 @@ public Enchantment getEnchantment(final User user, final String name) throws Exc
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);

if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false)) {
throw new Exception(tl("enchantmentPerm", enchantmentName));
throw new Exception(tlp(user, "enchantmentPerm", enchantmentName));
}
return enchantment;
}
Expand Down Expand Up @@ -550,7 +551,7 @@ private boolean hasMetaPermission(final User user, final String metaPerm, final
if (graceful) {
return false;
} else {
throw new Exception(tl("noMetaPerm", metaPerm));
throw new Exception(tlp(user, "noMetaPerm", metaPerm));
}
}

Expand Down
24 changes: 12 additions & 12 deletions Essentials/src/com/earth2me/essentials/SpawnMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.util.*;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlp;


public class SpawnMob {
Expand All @@ -28,7 +28,7 @@ public static String mobList(final User user) {
}
}
if (availableList.isEmpty()) {
availableList.add(tl("none"));
availableList.add(tlp(user, "none"));
}
return StringUtil.joinList(availableList);
}
Expand Down Expand Up @@ -70,7 +70,7 @@ public static List<String> mobData(final String mobString) {
public static void spawnmob(final IEssentials ess, final Server server, final User user, final List<String> parts, final List<String> data, int mobCount) throws Exception {
final Block block = LocationUtil.getTarget(user.getBase()).getBlock();
if (block == null) {
throw new Exception(tl("unableToSpawnMob"));
throw new Exception(tlp(user, "unableToSpawnMob"));
}
spawnmob(ess, server, user.getSource(), user, block.getLocation(), parts, data, mobCount);
}
Expand Down Expand Up @@ -101,21 +101,21 @@ public static void spawnmob(final IEssentials ess, final Server server, final Co

if (mobCount > effectiveLimit) {
mobCount = effectiveLimit;
sender.sendMessage(tl("mobSpawnLimit"));
sender.sendMessage(tlp(sender, "mobSpawnLimit"));
}

Mob mob = Mob.fromName(parts.get(0)); // Get the first mob
try {
for (int i = 0; i < mobCount; i++) {
spawnMob(ess, server, sender, target, sloc, parts, data);
}
sender.sendMessage(mobCount * parts.size() + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + tl("spawned"));
sender.sendMessage(mobCount * parts.size() + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + tlp(sender, "spawned"));
} catch (MobException e1) {
throw new Exception(tl("unableToSpawnMob"), e1);
throw new Exception(tlp(sender, "unableToSpawnMob"), e1);
} catch (NumberFormatException e2) {
throw new Exception(tl("numberRequired"), e2);
throw new Exception(tlp(sender, "numberRequired"), e2);
} catch (NullPointerException np) {
throw new Exception(tl("soloMob"), np);
throw new Exception(tlp(sender, "soloMob"), np);
}
}

Expand Down Expand Up @@ -155,23 +155,23 @@ private static void spawnMob(final IEssentials ess, final Server server, final C

private static void checkSpawnable(IEssentials ess, CommandSource sender, Mob mob) throws Exception {
if (mob == null || mob.getType() == null) {
throw new Exception(tl("invalidMob"));
throw new Exception(tlp(sender, "invalidMob"));
}

if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("disabledToSpawnMob"));
throw new Exception(tlp(sender, "disabledToSpawnMob"));
}

if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.spawnmob." + mob.name.toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("noPermToSpawnMob"));
throw new Exception(tlp(sender, "noPermToSpawnMob"));
}
}

private static void changeMobData(final CommandSource sender, final EntityType type, final Entity spawned, final String inputData, final User target) throws Exception {
String data = inputData;

if (data.isEmpty()) {
sender.sendMessage(tl("mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned))));
sender.sendMessage(tlp(sender, "mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned))));
}

if (spawned instanceof Zombie) {
Expand Down
Loading