mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
Added Essentials interface.
Moved nick customization commands from Essentials to TFM.
This commit is contained in:
parent
c5ddc60b97
commit
01807d1f0f
@ -1,5 +1,5 @@
|
||||
#Tue, 24 Sep 2013 07:27:17 -0400
|
||||
#Tue, 24 Sep 2013 10:08:38 -0400
|
||||
|
||||
program.VERSION=3.2
|
||||
program.BUILDNUM=602
|
||||
program.BUILDDATE=09/24/2013 07\:27 AM
|
||||
program.BUILDNUM=604
|
||||
program.BUILDDATE=09/24/2013 10\:08 AM
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Tue Sep 24 07:27:17 EDT 2013
|
||||
build.number=603
|
||||
#Tue Sep 24 10:08:38 EDT 2013
|
||||
build.number=605
|
||||
|
@ -50,7 +50,8 @@ jar.index=${jnlp.enabled}
|
||||
javac.classpath=\
|
||||
${libs.CraftBukkit.classpath}:\
|
||||
${libs.WorldEdit.classpath}:\
|
||||
${libs.DisguiseCraft.classpath}
|
||||
${libs.DisguiseCraft.classpath}:\
|
||||
${libs.Essentials.classpath}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
||||
javac.deprecation=false
|
||||
|
@ -0,0 +1,58 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Essentials Interface Command - Color your current nickname.", usage = "/<command> <color>")
|
||||
public class Command_colorme extends TFM_Command
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("list".equalsIgnoreCase(args[0]))
|
||||
{
|
||||
playerMsg("Colors: " + StringUtils.join(TFM_Util.CHAT_COLOR_NAMES.keySet(), ", "));
|
||||
return true;
|
||||
}
|
||||
|
||||
final String needle = args[0].trim().toLowerCase();
|
||||
ChatColor color = null;
|
||||
final Iterator<Map.Entry<String, ChatColor>> it = TFM_Util.CHAT_COLOR_NAMES.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Map.Entry<String, ChatColor> entry = it.next();
|
||||
if (entry.getKey().contains(needle))
|
||||
{
|
||||
color = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (color == null)
|
||||
{
|
||||
playerMsg("Invalid color: " + needle + " - Use \"/colorme list\" to list colors.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final String newNick = color + ChatColor.stripColor(sender_p.getDisplayName()) + ChatColor.WHITE;
|
||||
|
||||
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick);
|
||||
|
||||
playerMsg("Your nickname is now: " + newNick);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Essentials Interface Command - Remove the nickname of all players on the server.", usage = "/<command>")
|
||||
public class Command_denick extends TFM_Command
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), "Removing all nicknames.", false);
|
||||
|
||||
Player[] onlinePlayers = server.getOnlinePlayers();
|
||||
for (Player player : onlinePlayers)
|
||||
{
|
||||
TFM_EssentialsBridge.getInstance().setNickname(player.getName(), null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_EssentialsBridge;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
|
||||
@CommandParameters(description = "Essentials Interface Command - Nyanify your nickname.", usage = "/<command> <<nick> | off>")
|
||||
public class Command_nicknyan extends TFM_Command
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TFM_Util.isStopCommand(args[0]))
|
||||
{
|
||||
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), null);
|
||||
playerMsg("Nickname cleared.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final String nickPlain = ChatColor.stripColor(TFM_Util.colorize(args[0].trim()));
|
||||
|
||||
if (!nickPlain.matches("^[a-zA-Z_0-9\u00a7]+$"))
|
||||
{
|
||||
playerMsg("That nickname contains invalid characters.");
|
||||
return true;
|
||||
}
|
||||
else if (nickPlain.length() < 4 || nickPlain.length() > 30)
|
||||
{
|
||||
playerMsg("Your nickname must be between 4 and 30 characters long.");
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player[] onlinePlayers = server.getOnlinePlayers();
|
||||
for (final Player player : onlinePlayers)
|
||||
{
|
||||
if (player == sender_p)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).equalsIgnoreCase(nickPlain))
|
||||
{
|
||||
playerMsg("That nickname is already in use.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuilder newNick = new StringBuilder();
|
||||
|
||||
final char[] chars = nickPlain.toCharArray();
|
||||
for (char c : chars)
|
||||
{
|
||||
newNick.append(TFM_Util.randomChatColor()).append(c);
|
||||
}
|
||||
|
||||
newNick.append(ChatColor.WHITE);
|
||||
|
||||
TFM_EssentialsBridge.getInstance().setNickname(sender.getName(), newNick.toString());
|
||||
|
||||
playerMsg("Your nickname is now: " + newNick.toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class TFM_EssentialsBridge
|
||||
{
|
||||
private Essentials essentialsPlugin = null;
|
||||
|
||||
private TFM_EssentialsBridge()
|
||||
{
|
||||
}
|
||||
|
||||
public Essentials getEssentialsPlugin()
|
||||
{
|
||||
if (this.essentialsPlugin == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||
if (essentials != null)
|
||||
{
|
||||
if (essentials instanceof Essentials)
|
||||
{
|
||||
this.essentialsPlugin = (Essentials) essentials;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
return this.essentialsPlugin;
|
||||
}
|
||||
|
||||
public User getEssentialsUser(String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Essentials essentials = getEssentialsPlugin();
|
||||
if (essentials != null)
|
||||
{
|
||||
return essentials.getUserMap().getUser(username);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setNickname(String username, String nickname)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = getEssentialsUser(username);
|
||||
if (user != null)
|
||||
{
|
||||
user.setNickname(nickname);
|
||||
user.setDisplayNick();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static TFM_EssentialsBridge getInstance()
|
||||
{
|
||||
return TFM_EssentialsBridgeHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class TFM_EssentialsBridgeHolder
|
||||
{
|
||||
private static final TFM_EssentialsBridge INSTANCE = new TFM_EssentialsBridge();
|
||||
}
|
||||
}
|
@ -27,7 +27,8 @@ public class TFM_Util
|
||||
public static final List<String> DEVELOPERS = Arrays.asList("Madgeek1450", "DarthSalamon", "AcidicCyanide", "wild1145", "HeXeRei452");
|
||||
private static final Random RANDOM = new Random();
|
||||
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||
public static final List<ChatColor> COLOR_POOL = Arrays.asList(
|
||||
public static final Map<String, ChatColor> CHAT_COLOR_NAMES = new HashMap<String, ChatColor>();
|
||||
public static final List<ChatColor> CHAT_COLOR_POOL = Arrays.asList(
|
||||
ChatColor.DARK_BLUE,
|
||||
ChatColor.DARK_GREEN,
|
||||
ChatColor.DARK_AQUA,
|
||||
@ -59,6 +60,11 @@ public class TFM_Util
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
for (ChatColor chatColor : CHAT_COLOR_POOL)
|
||||
{
|
||||
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
||||
}
|
||||
}
|
||||
|
||||
private TFM_Util()
|
||||
@ -804,7 +810,7 @@ public class TFM_Util
|
||||
|
||||
public static ChatColor randomChatColor()
|
||||
{
|
||||
return COLOR_POOL.get(RANDOM.nextInt(COLOR_POOL.size()));
|
||||
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
||||
}
|
||||
|
||||
public static String colorize(String string)
|
||||
|
Loading…
Reference in New Issue
Block a user