0

Added nametags (tabsorter) module

This commit is contained in:
Pepich 2017-02-06 22:10:51 +01:00
parent 8813d6bf95
commit 1731483792
2 changed files with 143 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import com.redstoner.modules.lagchunks.LagChunks;
import com.redstoner.modules.loginsecurity.LoginSecurity; import com.redstoner.modules.loginsecurity.LoginSecurity;
import com.redstoner.modules.misc.Misc; import com.redstoner.modules.misc.Misc;
import com.redstoner.modules.motd.Motd; import com.redstoner.modules.motd.Motd;
import com.redstoner.modules.nametags.Nametags;
import com.redstoner.modules.pmtoggle.Pmtoggle; import com.redstoner.modules.pmtoggle.Pmtoggle;
import com.redstoner.modules.saylol.Saylol; import com.redstoner.modules.saylol.Saylol;
import com.redstoner.modules.scriptutils.Scriptutils; import com.redstoner.modules.scriptutils.Scriptutils;
@ -61,7 +62,7 @@ public class Main extends JavaPlugin
// TODO: ModuleLoader.addModule(Mentio.class); // TODO: ModuleLoader.addModule(Mentio.class);
ModuleLoader.addModule(Misc.class); ModuleLoader.addModule(Misc.class);
ModuleLoader.addModule(Motd.class); ModuleLoader.addModule(Motd.class);
// TODO: ModuleLoader.addModule(NameTags.class); ModuleLoader.addModule(Nametags.class);
ModuleLoader.addModule(Pmtoggle.class); ModuleLoader.addModule(Pmtoggle.class);
// TODO: ModuleLoader.addModule(Reports.class); // TODO: ModuleLoader.addModule(Reports.class);
ModuleLoader.addModule(Saylol.class); ModuleLoader.addModule(Saylol.class);

View File

@ -0,0 +1,141 @@
package com.redstoner.modules.nametags;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.server.ServerCommandEvent;
import com.nemez.cmdmgr.Command;
import com.redstoner.annotations.AutoRegisterListener;
import com.redstoner.annotations.Version;
import com.redstoner.misc.Utils;
import com.redstoner.modules.Module;
@AutoRegisterListener
@Version(major = 1, minor = 0, revision = 0, compatible = 1)
public class Nametags implements Module, Listener
{
private boolean enabled = false;
@Override
public void onEnable()
{
enabled = true;
}
@Override
public void onDisable()
{
enabled = false;
}
@Override
public boolean enabled()
{
return enabled;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
sortSpecific(event.getPlayer());
}
@EventHandler
public void commandPreprocessEvent(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().contains("promote") || event.getMessage().contains("demote")
|| event.getMessage().matches("pex user .* group (set|add|leave)"))
{
String[] args = event.getMessage().split(" ");
for (String s : args)
{
Player p = Bukkit.getPlayer(s);
if (p != null)
sortSpecific(p);
}
}
}
@EventHandler
public void consoleCommand(ServerCommandEvent event)
{
if (event.getCommand().matches("(pro|de)mote"))
{
String[] args = event.getCommand().split(" ");
for (String s : args)
{
Player p = Bukkit.getPlayer(s);
if (p != null)
sortSpecific(p);
}
}
}
@Command(hook = "sort")
public boolean sortAll(CommandSender sender)
{
for (Player p : Bukkit.getOnlinePlayers())
sortSpecific(p);
Utils.sendMessage(sender, null, "Sorted tab for ya!");
return true;
}
@Command(hook = "sortspecific")
public boolean sortSpecific(CommandSender sender, String player)
{
Player p = Bukkit.getPlayer(player);
if (p == null)
{
Utils.sendErrorMessage(sender, null, "That player couldn't be found!");
return true;
}
else
sortSpecific(p);
Utils.sendMessage(sender, null, "Sorted §e" + player + " §7for ya!");
return true;
}
public void sortSpecific(Player player)
{
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
"scoreboard teams join " + getTeam(player) + " " + player.getName());
}
private String getTeam(Player player)
{
String[] teams = new String[] {"admin", "mod", "trainingmod", "trusted", "builder", "member", "visitor"};
char prefix = 'a';
for (String team : teams)
{
if (player.hasPermission("group." + team))
{
return prefix + "_" + team;
}
prefix++;
}
return "g_visitor";
}
// @noformat
@Override
public String getCommandString()
{
return "command tab {\n" +
" sort {\n" +
" help Resorts the entirety of tab.;\n" +
" run sort;\n" +
" }\n" +
" sort [string:player] {\n" +
" help Resorts one player.;\n" +
" run sortspecific player;\n" +
" }\n" +
" perm utils.tab.admin;\n" +
"}";
}
// @format
}