mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Adding full keyword support for newb join message.
Also adding {ADDRESS} and {USERNAME} as new keywords.
This commit is contained in:
parent
fab9688abb
commit
945ae71480
@ -2,6 +2,7 @@ package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -14,9 +15,7 @@ public interface ISettings extends IConf
|
||||
{
|
||||
boolean areSignsDisabled();
|
||||
|
||||
String format(String format, IUser user);
|
||||
|
||||
String getAnnounceNewPlayerFormat(IUser user);
|
||||
IText getAnnounceNewPlayerFormat();
|
||||
|
||||
boolean getAnnounceNewPlayers();
|
||||
|
||||
@ -35,7 +34,7 @@ public interface ISettings extends IConf
|
||||
String getCurrencySymbol();
|
||||
|
||||
int getOversizedStackSize();
|
||||
|
||||
|
||||
int getDefaultStackSize();
|
||||
|
||||
double getHealCooldown();
|
||||
@ -101,7 +100,7 @@ public interface ISettings extends IConf
|
||||
boolean isTradeInStacks(int id);
|
||||
|
||||
List<Integer> itemSpawnBlacklist();
|
||||
|
||||
|
||||
List<EssentialsSign> enabledSigns();
|
||||
|
||||
boolean permissionBasedItemSpawn();
|
||||
@ -143,18 +142,18 @@ public interface ISettings extends IConf
|
||||
public void setDebug(boolean debug);
|
||||
|
||||
Set<String> getNoGodWorlds();
|
||||
|
||||
|
||||
boolean getUpdateBedAtDaytime();
|
||||
|
||||
|
||||
boolean getRepairEnchanted();
|
||||
|
||||
|
||||
boolean getIsWorldTeleportPermissions();
|
||||
|
||||
|
||||
boolean registerBackInListener();
|
||||
|
||||
boolean getDisableItemPickupWhileAfk();
|
||||
|
||||
EventPriority getRespawnPriority();
|
||||
|
||||
|
||||
long getTpaAcceptCancellation();
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import com.earth2me.essentials.signs.Signs;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.textreader.SimpleTextPager;
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
@ -324,15 +328,9 @@ public class Settings implements ISettings
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnnounceNewPlayerFormat(IUser user)
|
||||
public IText getAnnounceNewPlayerFormat()
|
||||
{
|
||||
return format(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"), user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(String format, IUser user)
|
||||
{
|
||||
return format.replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", user.getGroup()).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString());
|
||||
return new SimpleTextInput(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -362,19 +360,19 @@ public class Settings implements ISettings
|
||||
itemSpawnBl = getItemSpawnBlacklist();
|
||||
chatFormats.clear();
|
||||
}
|
||||
|
||||
private List<Integer> itemSpawnBl = new ArrayList<Integer>();
|
||||
|
||||
|
||||
@Override
|
||||
public List<Integer> itemSpawnBlacklist()
|
||||
{
|
||||
return itemSpawnBl;
|
||||
}
|
||||
|
||||
|
||||
private List<Integer> getItemSpawnBlacklist()
|
||||
{
|
||||
final List<Integer> epItemSpwn = new ArrayList<Integer>();
|
||||
if (ess.getItemDb() == null) {
|
||||
if (ess.getItemDb() == null)
|
||||
{
|
||||
logger.log(Level.FINE, "Aborting ItemSpawnBL read, itemDB not yet loaded.");
|
||||
return epItemSpwn;
|
||||
}
|
||||
@ -384,7 +382,7 @@ public class Settings implements ISettings
|
||||
if (itemName.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
final ItemStack iStack = ess.getItemDb().get(itemName);
|
||||
@ -397,19 +395,18 @@ public class Settings implements ISettings
|
||||
}
|
||||
return epItemSpwn;
|
||||
}
|
||||
|
||||
private List<EssentialsSign> enabledSigns = new ArrayList<EssentialsSign>();
|
||||
|
||||
|
||||
@Override
|
||||
public List<EssentialsSign> enabledSigns()
|
||||
{
|
||||
return enabledSigns;
|
||||
}
|
||||
|
||||
|
||||
private List<EssentialsSign> getEnabledSigns()
|
||||
{
|
||||
List<EssentialsSign> newSigns = new ArrayList<EssentialsSign>();
|
||||
|
||||
|
||||
for (String signName : config.getStringList("enabledSigns", null))
|
||||
{
|
||||
signName = signName.trim().toUpperCase(Locale.ENGLISH);
|
||||
@ -604,7 +601,6 @@ public class Settings implements ISettings
|
||||
{
|
||||
return config.getBoolean("death-messages", true);
|
||||
}
|
||||
|
||||
private Set<String> noGodWorlds = new HashSet<String>();
|
||||
|
||||
@Override
|
||||
|
@ -33,12 +33,14 @@ public class KeywordReplacer implements IText
|
||||
String displayName, ipAddress, balance, mails, world;
|
||||
String worlds, online, unique, playerlist, date, time;
|
||||
String worldTime12, worldTime24, worldDate, plugins;
|
||||
String version;
|
||||
String userName, address, version;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
final User user = ess.getUser(sender);
|
||||
displayName = user.getDisplayName();
|
||||
userName = user.getName();
|
||||
ipAddress = user.getAddress().getAddress().toString();
|
||||
address = user.getAddress().toString();
|
||||
balance = Double.toString(user.getMoney());
|
||||
mails = Integer.toString(user.getMails().size());
|
||||
world = user.getLocation().getWorld().getName();
|
||||
@ -107,8 +109,12 @@ public class KeywordReplacer implements IText
|
||||
for (int i = 0; i < input.getLines().size(); i++)
|
||||
{
|
||||
String line = input.getLines().get(i);
|
||||
|
||||
line = line.replace("{PLAYER}", displayName);
|
||||
line = line.replace("{DISPLAYNAME}", displayName);
|
||||
line = line.replace("{USERNAME}", displayName);
|
||||
line = line.replace("{IP}", ipAddress);
|
||||
line = line.replace("{ADDRESS}", ipAddress);
|
||||
line = line.replace("{BALANCE}", balance);
|
||||
line = line.replace("{MAILS}", mails);
|
||||
line = line.replace("{WORLD}", world);
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.earth2me.essentials.textreader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class SimpleTextInput implements IText
|
||||
{
|
||||
private final transient List<String> lines = new ArrayList<String>();
|
||||
|
||||
public SimpleTextInput (final String input) {
|
||||
lines.add(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLines()
|
||||
{
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChapters()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getBookmarks()
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.earth2me.essentials.textreader;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
|
||||
public class SimpleTextPager
|
||||
{
|
||||
private final transient IText text;
|
||||
|
||||
public SimpleTextPager(final IText text)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void showPage(final CommandSender sender)
|
||||
{
|
||||
for (String line : text.getLines())
|
||||
{
|
||||
sender.sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(int line)
|
||||
{
|
||||
if (text.getLines().size() < line)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return text.getLines().get(line);
|
||||
}
|
||||
}
|
@ -25,7 +25,9 @@ Minecraft colors:
|
||||
|
||||
#Tags
|
||||
PLAYER: {PLAYER}
|
||||
USERNAME: {PLAYER}
|
||||
IP: {IP}
|
||||
ADDRESS: {ADDRESS}
|
||||
BALANCE: {BALANCE}
|
||||
MAILS: {MAILS}
|
||||
WORLD: {WORLD}
|
||||
@ -39,3 +41,4 @@ WORLDTIME12: {WORLDTIME12}
|
||||
WORLDTIME24: {WORLDTIME24}
|
||||
WORLDDATE: {WORLDDATE}
|
||||
PLUGINS: {PLUGINS}
|
||||
VERSION: {VERSION}
|
@ -4,6 +4,9 @@ import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.OfflinePlayer;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextPager;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -73,7 +76,9 @@ public class EssentialsSpawnPlayerListener implements Listener
|
||||
|
||||
if (ess.getSettings().getAnnounceNewPlayers())
|
||||
{
|
||||
ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
|
||||
final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user, ess);
|
||||
final SimpleTextPager pager = new SimpleTextPager(output);
|
||||
ess.broadcastMessage(user, pager.getString(0));
|
||||
}
|
||||
|
||||
LOGGER.log(Level.FINE, "New player join");
|
||||
|
Loading…
Reference in New Issue
Block a user