Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coloured Tab menu #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 16 additions & 15 deletions src/uk/co/oliwali/WhoAreYou/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@
import java.util.HashMap;

import org.bukkit.World;
import org.bukkit.util.config.Configuration;
import org.bukkit.configuration.file.FileConfiguration;


public class Config {

private HashMap<String, String> aliases = new HashMap<String, String>();
public WhoAreYou plugin;
private Configuration config;
private FileConfiguration config;
public boolean onlineMsg;
public boolean tablist;

public Config (WhoAreYou instance) {

this.plugin = instance;
this.config = plugin.getConfiguration();
config.load();
this.config = plugin.getConfig();
plugin.reloadConfig();

//If there are no aliases yet
if (config.getKeys("aliases") == null) {
World[] worlds = (World[]) plugin.getServer().getWorlds().toArray(new World[0]);
for (World world : worlds)
config.setProperty("aliases." + world.getName(), world.getName());
for(World world : plugin.getServer().getWorlds()){
config.addDefault("aliases."+ world.getName(), world.getName());
}

//Message players on join
if (config.getProperty("msg-online-on-join") == null)
config.setProperty("msg-online-on-join", true);
config.addDefault("msg-online-on-join", true);

config.options().copyDefaults(true);

//Load aliasess into hashmap
String[] worlds = (String[]) config.getKeys("aliases").toArray(new String[0]);
for (String world : worlds)
aliases.put(world, config.getString("aliases." + world));
for(World world : plugin.getServer().getWorlds()){
aliases.put(world.getName(), config.getString("aliases."+world.getName()));
}

onlineMsg = config.getBoolean("msg-online-on-join", true);
tablist = config.getBoolean("colour-tab-menu", true);

//Attempt save
if (!config.save())
Util.severe("Error while writing to config.yml");
plugin.saveConfig();

}

Expand Down
93 changes: 0 additions & 93 deletions src/uk/co/oliwali/WhoAreYou/Permission.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/uk/co/oliwali/WhoAreYou/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private enum CustomColor {
GREEN("a", 0xA),
DARK_GREEN("2", 0x2),
AQUA("b", 0xB),
DARK_AQUA("8", 0x8),
DARK_GREY("8", 0x8),
BLUE("9", 0x9),
DARK_BLUE("1", 0x1),
LIGHT_PURPLE("d", 0xD),
Expand All @@ -98,6 +98,7 @@ private enum CustomColor {
GRAY("7", 0x7),
WHITE("f", 0xf),
DARK_AQUA("3", 0x3);


private String custom;
private int code;
Expand Down
52 changes: 52 additions & 0 deletions src/uk/co/oliwali/WhoAreYou/WAUPermission.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package uk.co.oliwali.WhoAreYou;

import org.bukkit.entity.Player;


public class WAUPermission {

private WhoAreYou plugin;


public WAUPermission(WhoAreYou instance) {
plugin = instance;
}

private boolean hasPermission(Player player, String node) {
return player.hasPermission(node);
}

public boolean list(Player player) {
return hasPermission(player, "whoareyou.list");
}
public boolean player(Player player) {
return hasPermission(player, "whoareyou.player");
}
public boolean world(Player player) {
return hasPermission(player, "whoareyou.world");
}

public String getPrefix(Player player) {
String prefix = "&f";
prefix = plugin.chat.getGroupPrefix(player.getWorld(),getGroup(player));

if (prefix.length() == 0)
return "&f";
return prefix;
}

public String getSuffix(Player player) {
String prefix = "";
prefix = plugin.chat.getGroupSuffix(player.getWorld(), getGroup(player));
return prefix;
}

public String getGroup(Player playerInfo) {
return plugin.permission.getPrimaryGroup(playerInfo);
}





}
19 changes: 16 additions & 3 deletions src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package uk.co.oliwali.WhoAreYou;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;

public class WAYPlayerListener extends PlayerListener {

public class WAYPlayerListener implements Listener {

public WhoAreYou plugin;

public WAYPlayerListener(WhoAreYou instance) {
plugin = instance;
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
if (plugin.config.onlineMsg)
plugin.who(event.getPlayer());
if (plugin.config.tablist) {
Player player = event.getPlayer();
String prefix = plugin.permissions.getPrefix(player);
int lastcolor = prefix.lastIndexOf("&");

String coloredname = "&" + prefix.charAt(lastcolor + 1) + player.getName();
player.setPlayerListName(coloredname.replaceAll("(&([a-f0-9]))", "\u00A7$2"));
}
}


}
36 changes: 31 additions & 5 deletions src/uk/co/oliwali/WhoAreYou/WhoAreYou.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
import java.util.ArrayList;
import java.util.List;

import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Type;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public class WhoAreYou extends JavaPlugin {

public static String name;
public static String version;
private Permission permissions;
public WAUPermission permissions;
public Config config;
private WAYPlayerListener playerListener = new WAYPlayerListener(this);
public Chat chat;
public Permission permission;

private Boolean setupPermissions()
{
RegisteredServiceProvider<net.milkbowl.vault.permission.Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}

public void onDisable() {
Util.info("Version " + version + " disabled!");
Expand All @@ -29,15 +42,28 @@ public void onEnable() {
name = this.getDescription().getName();
version = this.getDescription().getVersion();
config = new Config(this);
permissions = new Permission(this);
permissions = new WAUPermission(this);

// Register events
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this);
pm.registerEvents(playerListener, this);

setupChat();
setupPermissions();

Util.info("Version " + version + " enabled!");
}

private Boolean setupChat()
{
RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
if (chatProvider != null) {
chat = chatProvider.getProvider();
}

return (chat != null);
}

private void sendPlayerList(CommandSender sender, String message, List<Player> players) {
for (Player player : players.toArray(new Player[0]))
message = message + " " + permissions.getPrefix(player) + player.getName() + permissions.getSuffix(player);
Expand Down