Skip to content

Commit

Permalink
Added support to be in multiple channels.
Browse files Browse the repository at this point in the history
This commit breaks compatibility with upstream, my changes was to
intrusive so I took the decision to breake compatibility.

This codebase allows the player to be in multiple channels and move
between them without parting from a channel.

I have removed the -o and -a from chanlist, they are integrated into
the normal listings. -p is replaced with the more verbose "hasplayer".
  • Loading branch information
nsg committed Jan 1, 2014
1 parent 093a948 commit e4317d6
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 263 deletions.
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
This is based on SimpleChatChannels from https://github.com/OdiumxXx/SimpleChatChannels

Contributions Welcome. :)
I have re-written/changed the channel management so you can join multiple channels at once.
I have removed/broken some code and changed the syntax to some extent, this version is not compatible with the original.
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# PublicJoinPartMessaes - Broadcast join / part messages to whole server
# ChatPrefix - Define the chat prefix for users in a channel
#
SilenceGeneralChat: true
SilenceGeneralChat: false
PublicJoinPartMessages: true
ChatPrefix:
Prefix: '`2[`g`channel`2/`c`player`2]`w'
Prefix: '`2[`g`channel`2/`c`player`2]`w'
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SimpleChatChannels
main: me.odium.simplechatchannels.Loader
version: 0.7.5
version: 0.7.5-nsg1
description: Simple Chat Channels
commands:
scc:
Expand Down Expand Up @@ -57,4 +57,4 @@ commands:
spychan:
description: Spy on specific/all channel conversation
permission: scc.spychan
usage: /spychan [channelname]
usage: /spychan [channelname]
133 changes: 64 additions & 69 deletions src/me/odium/simplechatchannels/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public void onEnable() {
this.getCommand("scc").setExecutor(new scc(this));
this.getCommand("topic").setExecutor(new topic(this));
this.getCommand("spychan").setExecutor(new spychan(this));

plugin = this;

log.info("[" + getDescription().getName() + "] " + getDescription().getVersion() + " enabled.");
}

Expand Down Expand Up @@ -173,81 +176,73 @@ public String replaceColorMacros(String str) {
return str;
}

public void setChannel(Player player, String channel){
InChannel.put(player, true);
ChannelMap.put(player, channel);
player.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + player.getDisplayName() + ChatColor.DARK_GREEN + " " +channel + " is active");
}

public void toggleChannel(Player player, String channel){
if (InChannel.containsKey(player)) { // IF PLAYER IS IN A CHANNEL
String playerName = player.getName().toLowerCase(); // get the player name
String playerDisplayName = player.getDisplayName();
Player[] players = Bukkit.getOnlinePlayers(); // get all online players

InChannel.remove(player);
ChannelMap.remove(player);

List<String> ChList = getStorageConfig().getStringList(channel+".list"); // get the player list
ChList.remove(playerName); // remove the player from the list
getStorageConfig().set(channel+".list", ChList); // se
saveStorageConfig();

// NOTIFY USERS IN CHANNEL OF A PART
player.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" left "+ channel);
List<String> ChanList = getStorageConfig().getStringList(channel+".list");
for(Player play : players){
if(ChanList.contains(play.getName())) {
play.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" left "+ channel);
}
}
public void joinChannel(Player player, String channel){

// NOTIFY SERVER OF A CHAT PART
if (getConfig().getBoolean("PublicJoinPartMessages") == true) {
for (Player user : players) { // for all players
if (!InChannel.containsKey(user)) { // if player is not in a channel
user.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" has joined general chat");
}
}
}
log.info(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" has joined general chat");

String playerName = player.getName().toLowerCase(); // get the player name
Player[] players = Bukkit.getOnlinePlayers(); // get all online players
String playerDisplayName = player.getDisplayName();

} else { // if player is not in a channel
String playerName = player.getName().toLowerCase(); // get the player name
Player[] players = Bukkit.getOnlinePlayers(); // get all online players
String playerDisplayName = player.getDisplayName();

InChannel.put(player, true);
ChannelMap.put(player, channel);

List<String> ChList = getStorageConfig().getStringList(channel+".list"); // get the player list
ChList.add(playerName); // add the player to the list
getStorageConfig().set(channel+".list", ChList); // set the new list
saveStorageConfig();

// NOTIFY SERVER OF A CHAT JOIN
if (getConfig().getBoolean("PublicJoinPartMessages") == true) {
for (Player user : players) { // for all players
if (!InChannel.containsKey(user)) { // if player is not in a channel
user.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" has left general chat");
}
}
log.info(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" has left general chat");
}


// NOTIFY USERS IN CHANNEL OF A JOIN
List<String> ChanList = getStorageConfig().getStringList(channel+".list");
for(Player op: players){
if(ChanList.contains(op.getName().toLowerCase())) {
op.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" joined "+ channel);
}
setChannel(player, channel);

List<String> ChList = getStorageConfig().getStringList(channel+".list"); // get the player list
ChList.add(playerName); // add the player to the list
getStorageConfig().set(channel+".list", ChList); // set the new list
saveStorageConfig();

// NOTIFY USERS IN CHANNEL OF A JOIN
List<String> ChanList = getStorageConfig().getStringList(channel+".list");
for(Player op: players){
if(ChanList.contains(op.getName().toLowerCase())) {
op.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" joined "+ channel);
}
// SHOW TOPIC
if (getStorageConfig().getString(channel+".topic") != null) {
String topic = getStorageConfig().getString(channel+".topic");
player.sendMessage(DARK_GREEN+"[SCC] Topic for " + channel + ": "+ChatColor.WHITE+ topic);
}
// SHOW TOPIC
if (getStorageConfig().getString(channel+".topic") != null) {
String topic = getStorageConfig().getString(channel+".topic");
player.sendMessage(DARK_GREEN+"[SCC] Topic for " + channel + ": "+ChatColor.WHITE+ topic);
}

}

public void partChannel(Player player, String channel){

String playerName = player.getName().toLowerCase(); // get the player name
String playerDisplayName = player.getDisplayName();
Player[] players = Bukkit.getOnlinePlayers(); // get all online players

InChannel.remove(player);
ChannelMap.remove(player);

List<String> ChList = getStorageConfig().getStringList(channel+".list"); // get the player list
ChList.remove(playerName); // remove the player from the list
getStorageConfig().set(channel+".list", ChList); // set the new list
saveStorageConfig();

// NOTIFY USERS IN CHANNEL OF A PART
player.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" left "+ channel);
List<String> ChanList = getStorageConfig().getStringList(channel+".list");
for(Player play : players){
if(ChanList.contains(play.getName())) {
play.sendMessage(DARK_GREEN+"[SCC] "+ ChatColor.GOLD + playerDisplayName + ChatColor.DARK_GREEN+" left "+ channel);
}
}

}

public void toggleChannel(Player player, String channel){
if (InChannel.containsKey(player)) { // IF PLAYER IS IN A CHANNEL
partChannel(player, channel);
} else { // if player is not in a channel
joinChannel(player, channel);
}
}

public boolean NotExist(CommandSender sender, String ChanName) {
sender.sendMessage(DARK_RED+"[SCC] Channel "+ChatColor.GOLD+ChanName+ChatColor.DARK_RED+" does not exist!");
return true;
Expand All @@ -260,7 +255,7 @@ public boolean AlreadyInChannel(CommandSender sender) {
sender.sendMessage(DARK_RED+"[SCC] "+ChatColor.DARK_RED+"You are already in a channel");
return true;
}



}
131 changes: 43 additions & 88 deletions src/me/odium/simplechatchannels/commands/addchan.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import me.odium.simplechatchannels.Loader;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -25,104 +23,61 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
player = (Player) sender;
}

Player[] players = Bukkit.getOnlinePlayers();
if (player == null) {
sender.sendMessage("This command can only be run by a player");
return true;
}

if (args.length == 0) {
sender.sendMessage("/addchan <channelname> - Create a channel");
sender.sendMessage("/addchan -l <channelname> - Create a locked channel");
return true;
} else if (args.length == 1) {
String ChanName = args[0].toLowerCase();
String PlayerName = player.getName().toLowerCase();
// CHECK IF PLAYER IS IN A CHANNEL
if (plugin.ChannelMap.containsKey(player)) {
String channel = plugin.ChannelMap.get(player);
sender.sendMessage(plugin.DARK_RED+"[SCC] Cannot create a channel while in "+plugin.GOLD+channel);
return true;
}
// CHECK IF CHANNEL EXISTS
if (plugin.getStorageConfig().contains(ChanName)) {
sender.sendMessage(plugin.DARK_RED+"[SCC] "+plugin.GOLD + ChanName + plugin.DARK_RED+ " already exists");
return true;
}
plugin.getStorageConfig().createSection(ChanName); // create the 'channel'
List<String> ChList = plugin.getStorageConfig().getStringList(ChanName+".list"); // create/get the player list
List<String> OwList = plugin.getStorageConfig().getStringList(ChanName+".owner"); // create/get the owner list
List<String> AccList = plugin.getStorageConfig().getStringList(ChanName+".AccList"); // create/get the owner list
List<String> ChannelsList = plugin.getStorageConfig().getStringList("Channels"); // create/get the owner list
ChList.add(PlayerName); // add the player to the list
OwList.add(PlayerName); // add the player to the owner list
AccList.add(PlayerName); // add the player to the access list
ChannelsList.add(ChanName);
plugin.getStorageConfig().set(ChanName+".list", ChList); // set the new list
plugin.getStorageConfig().set(ChanName+".owner", OwList); // set the new list
plugin.getStorageConfig().set(ChanName+".AccList", AccList); // set the new list
plugin.getStorageConfig().set(ChanName+".Locked", false); // set the new list
plugin.getStorageConfig().set("Channels", ChannelsList); // set the new list
plugin.saveStorageConfig();
sender.sendMessage(plugin.DARK_GREEN+"[SCC] "+ plugin.GOLD + ChanName + plugin.DARK_GREEN + " Created");
plugin.ChannelMap.put(player, ChanName);
plugin.InChannel.put(player, true);
List<String> ChanList = plugin.getStorageConfig().getStringList(ChanName+".list");
}

for(Player op: players){
if(ChanList.contains(op.getName())) {
op.sendMessage(plugin.DARK_GREEN+"[SCC] "+ ChatColor.GOLD + PlayerName + ChatColor.DARK_GREEN+" joined "+ ChanName);
}
}
return true;
String ChanName;
String PlayerName;
Boolean lockedChannel = false;
if (args.length == 1) {
ChanName = args[0].toLowerCase();
PlayerName = player.getName().toLowerCase();
} else if (args.length == 2 && args[0].equalsIgnoreCase("-l")) {
String ChanName = args[1].toLowerCase();
String PlayerName = player.getName().toLowerCase();
Boolean bool = true;
// CHECK IF PLAYER IS IN A CHANNEL
if (plugin.ChannelMap.containsKey(player)) {
String channel = plugin.ChannelMap.get(player);
sender.sendMessage(plugin.DARK_RED+"[SCC] Cannot create a channel while in "+plugin.GOLD+channel);
return true;
}
// CHECK IF CHANNEL EXISTS
if (plugin.getStorageConfig().contains(ChanName)) {
sender.sendMessage(plugin.DARK_RED+"[SCC] "+plugin.GOLD + ChanName + plugin.DARK_RED+ " already exists");
return true;
}
plugin.getStorageConfig().createSection(ChanName); // create the 'channel'
List<String> ChList = plugin.getStorageConfig().getStringList(ChanName+".list"); // create/get the player list
List<String> OwList = plugin.getStorageConfig().getStringList(ChanName+".owner"); // create/get the owner list
List<String> AccList = plugin.getStorageConfig().getStringList(ChanName+".AccList"); // create/get the owner list
List<String> ChannelsList = plugin.getStorageConfig().getStringList("Channels"); // create/get the owner list
ChList.add(PlayerName); // add the player to the list
OwList.add(PlayerName); // add the player to the owner list
AccList.add(PlayerName); // add the player to the access list
ChannelsList.add(ChanName);
plugin.getStorageConfig().set(ChanName+".list", ChList); // set the new list
plugin.getStorageConfig().set(ChanName+".owner", OwList); // set the new list
plugin.getStorageConfig().set(ChanName+".AccList", AccList); // set the new list
plugin.getStorageConfig().set(ChanName+".locked", bool); // set the new list
plugin.getStorageConfig().set("Channels", ChannelsList); // set the new list
plugin.saveStorageConfig();
sender.sendMessage(plugin.DARK_GREEN+"[SCC] "+"Locked Channel " + plugin.GOLD + ChanName + plugin.DARK_GREEN + " Created");
plugin.ChannelMap.put(player, ChanName);
plugin.InChannel.put(player, true);
List<String> ChanList = plugin.getStorageConfig().getStringList(ChanName+".list");
// NOTIFY SERVER OF A CHAT JOIN
for (Player user: players) { // for all players
if (!plugin.InChannel.containsKey(user)) { // if player is not in a channel
user.sendMessage(plugin.DARK_GREEN+"[SCC] "+ ChatColor.GOLD + PlayerName + ChatColor.DARK_GREEN+" has left general chat");
plugin.log.info(plugin.DARK_GREEN+"[SCC] "+ ChatColor.GOLD + PlayerName + ChatColor.DARK_GREEN+" has left general chat");
}
}
for(Player op: players){
if(ChanList.contains(op.getName())) {
op.sendMessage(plugin.DARK_GREEN+"[SCC] "+ ChatColor.GOLD + PlayerName + ChatColor.DARK_GREEN+" joined "+ ChanName);
}
}
ChanName = args[1].toLowerCase();
PlayerName = player.getName().toLowerCase();
lockedChannel = true;
} else {
return false;
}

// CHECK IF CHANNEL EXISTS
if (plugin.getStorageConfig().contains(ChanName)) {
sender.sendMessage(plugin.DARK_RED+"[SCC] "+plugin.GOLD + ChanName + plugin.DARK_RED+ " already exists");
return true;
}

return true;
plugin.getStorageConfig().createSection(ChanName); // create the 'channel'
List<String> ChList = plugin.getStorageConfig().getStringList(ChanName+".list"); // create/get the player list
List<String> OwList = plugin.getStorageConfig().getStringList(ChanName+".owner"); // create/get the owner list
List<String> AccList = plugin.getStorageConfig().getStringList(ChanName+".AccList"); // create/get the owner list
List<String> ChannelsList = plugin.getStorageConfig().getStringList("Channels"); // create/get the owner list
ChList.add(PlayerName); // add the player to the list
OwList.add(PlayerName); // add the player to the owner list
AccList.add(PlayerName); // add the player to the access list
ChannelsList.add(ChanName);
plugin.getStorageConfig().set(ChanName+".list", ChList); // set the new list
plugin.getStorageConfig().set(ChanName+".owner", OwList); // set the new list
plugin.getStorageConfig().set(ChanName+".AccList", AccList); // set the new list
plugin.getStorageConfig().set(ChanName+".Locked", lockedChannel); // set the new list
plugin.getStorageConfig().set("Channels", ChannelsList); // set the new list
plugin.saveStorageConfig();

if (lockedChannel) {
sender.sendMessage(plugin.DARK_GREEN+"[SCC] "+"Locked Channel " + plugin.GOLD + ChanName + plugin.DARK_GREEN + " Created");
} else {
sender.sendMessage(plugin.DARK_GREEN+"[SCC] "+ plugin.GOLD + ChanName + plugin.DARK_GREEN + " Created");
}

plugin.setChannel(player, ChanName);

return true;
}
}
2 changes: 1 addition & 1 deletion src/me/odium/simplechatchannels/commands/adduser.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
List<String> ChanList = plugin.getStorageConfig().getStringList(ChanName+".list");
for(Player op: players){
if(ChanList.contains(op.getName())) {
op.sendMessage(plugin.DARK_GREEN+"[SCC] "+plugin.GOLD +AddPlayName + plugin.DARK_GREEN + " has been added to" + plugin.GOLD + ChanName + "'s " + plugin.DARK_GREEN + "Access List by " + PlayerName);
op.sendMessage(plugin.DARK_GREEN+"[SCC] "+plugin.GOLD +AddPlayName + plugin.DARK_GREEN + " has been added to " + plugin.GOLD + ChanName + "'s " + plugin.DARK_GREEN + "Access List by " + PlayerName);
}
}

Expand Down
Loading

0 comments on commit e4317d6

Please sign in to comment.