0

Added group join/leave messages

This commit is contained in:
Pepich 2017-03-02 11:46:13 +01:00
parent 02d582f57e
commit 54cd39f7f3

View File

@ -26,7 +26,7 @@ import com.redstoner.modules.Module;
* *
* @author Pepich */ * @author Pepich */
@AutoRegisterListener @AutoRegisterListener
@Version(major = 1, minor = 2, revision = 4, compatible = 1) @Version(major = 1, minor = 3, revision = 0, compatible = 1)
public class Chatgroups implements Module, Listener public class Chatgroups implements Module, Listener
{ {
private static final char defaultKey = ':'; private static final char defaultKey = ':';
@ -222,7 +222,12 @@ public class Chatgroups implements Module, Listener
@Command(hook = "cgleave") @Command(hook = "cgleave")
public boolean cgLeave(CommandSender sender) public boolean cgLeave(CommandSender sender)
{ {
removeGroup(sender); String name;
if (sender instanceof Player)
name = ((Player) sender).getDisplayName();
else
name = sender.getName();
sendToGroup(removeGroup(sender), "&9" + name + " &7left the group!");
Utils.sendMessage(sender, null, "Successfully removed you from your group!"); Utils.sendMessage(sender, null, "Successfully removed you from your group!");
cgtoggled.remove(((Player) sender).getUniqueId()); cgtoggled.remove(((Player) sender).getUniqueId());
return true; return true;
@ -236,6 +241,12 @@ public class Chatgroups implements Module, Listener
@Command(hook = "cgjoin") @Command(hook = "cgjoin")
public boolean cgJoin(CommandSender sender, String name) public boolean cgJoin(CommandSender sender, String name)
{ {
String pname;
if (sender instanceof Player)
pname = ((Player) sender).getDisplayName();
else
pname = sender.getName();
sendToGroup(name, "&9" + pname + " &7joined the group!");
setGroup(sender, name); setGroup(sender, name);
Utils.sendMessage(sender, null, "Successfully joined group §6" + name); Utils.sendMessage(sender, null, "Successfully joined group §6" + name);
return true; return true;
@ -309,13 +320,15 @@ public class Chatgroups implements Module, Listener
/** Removes a CommandSender from their chatgroup. Will also save the groups after finishing /** Removes a CommandSender from their chatgroup. Will also save the groups after finishing
* *
* @param target the CommandSender to get their group removed. */ * @param target the CommandSender to get their group removed. */
private void removeGroup(CommandSender target) private String removeGroup(CommandSender target)
{ {
String group;
if (target instanceof Player) if (target instanceof Player)
groups.remove(((Player) target).getUniqueId().toString()); group = (String) groups.remove(((Player) target).getUniqueId().toString());
else else
groups.remove("CONSOLE"); group = (String) groups.remove("CONSOLE");
saveGroups(); saveGroups();
return group;
} }
/** This method will find the ChatgGroup key of any player. /** This method will find the ChatgGroup key of any player.
@ -358,6 +371,30 @@ public class Chatgroups implements Module, Listener
} }
} }
/** This method sends a message to a chatgroup.
*
* @param sender the sender of the message. Also defines which group the message will be sent to.
* @param message the message to be sent. */
private void sendToGroup(String group, String message)
{
Utils.broadcast(null, "message", new BroadcastFilter()
{
@Override
public boolean sendTo(CommandSender recipient)
{
String rgroup = getGroup(recipient);
if (rgroup != null)
return rgroup.equals(group);
else
return false;
}
}, '&');
if (getGroup(Bukkit.getConsoleSender()) == null || !getGroup(Bukkit.getConsoleSender()).equals(group))
{
Utils.log("In " + group + ": " + message + " §8(hidden)");
}
}
/** Saves the groups. */ /** Saves the groups. */
private void saveGroups() private void saveGroups()
{ {