mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 14:38:58 +00:00
Fix mode setting when switching out of default channel
This commit is contained in:
1 parent
e2efed0b01
commit
0c68f59d1e
3 files changed
+37
-5
No files matched your search
@@ -91,9 +91,7 @@ public class LeaveCommand implements CommandExecutor {
|
|||||||
if (plugin.getTowny().hasPlayerMode(player, chan.getName())) {
|
if (plugin.getTowny().hasPlayerMode(player, chan.getName())) {
|
||||||
if (plugin.getChannelsHandler().getDefaultChannel() != null && plugin.getChannelsHandler().getDefaultChannel().isPresent(player.getName())) {
|
if (plugin.getChannelsHandler().getDefaultChannel() != null && plugin.getChannelsHandler().getDefaultChannel().isPresent(player.getName())) {
|
||||||
nextChannel = plugin.getChannelsHandler().getDefaultChannel();
|
nextChannel = plugin.getChannelsHandler().getDefaultChannel();
|
||||||
if (TownyUtil.removePlayerMode(plugin.getTowny(), player, chan.getName(), false)) {
|
TownyUtil.removeAndSetPlayerMode(plugin.getTowny(), player, chan.getName(), nextChannel.getName(), true);
|
||||||
TownyUtil.addPlayerMode(plugin.getTowny(), player, nextChannel.getName(), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextChannel == null) {
|
if (nextChannel == null) {
|
||||||
|
|||||||
@@ -95,13 +95,21 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
if (message.isEmpty()) {
|
if (message.isEmpty()) {
|
||||||
if (plugin.getTowny().hasPlayerMode(player, channel.getName())) {
|
if (plugin.getTowny().hasPlayerMode(player, channel.getName())) {
|
||||||
plugin.getTowny().removePlayerMode(player);
|
|
||||||
// Find what the next channel is if any
|
// Find what the next channel is if any
|
||||||
Channel nextChannel = null;
|
Channel nextChannel = null;
|
||||||
if (plugin.getChannelsHandler().getDefaultChannel() != null && plugin.getChannelsHandler().getDefaultChannel().isPresent(player.getName())) {
|
if (plugin.getChannelsHandler().getDefaultChannel() != null && plugin.getChannelsHandler().getDefaultChannel().isPresent(player.getName())) {
|
||||||
nextChannel = plugin.getChannelsHandler().getDefaultChannel();
|
nextChannel = plugin.getChannelsHandler().getDefaultChannel();
|
||||||
TownyUtil.addPlayerMode(plugin.getTowny(), player, nextChannel.getName(), true);
|
if (!nextChannel.getName().equalsIgnoreCase(channel.getName())) {
|
||||||
|
TownyUtil.removeAndSetPlayerMode(plugin.getTowny(), player, channel.getName(), nextChannel.getName(), true);
|
||||||
|
} else {
|
||||||
|
// They're talking on default channel and want to leave but can't because they'll be put default again
|
||||||
|
// Their only option out is to leave the channel if they have permission to do so.
|
||||||
|
TownyMessaging.sendErrorMsg(player, "[TownyChat] You are already talking in the default channel. To switch to another channel use that channel's command.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.getTowny().removePlayerMode(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextChannel == null) {
|
if (nextChannel == null) {
|
||||||
nextChannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.GLOBAL);
|
nextChannel = plugin.getChannelsHandler().getActiveChannel(player, channelTypes.GLOBAL);
|
||||||
}
|
}
|
||||||
@@ -164,6 +172,7 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.getLogger().info("onPlayerChat: Processing directed message for " + channel.getName());
|
||||||
channel.chatProcess(event);
|
channel.chatProcess(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,4 +41,29 @@ public class TownyUtil {
|
|||||||
towny.setPlayerMode(player, modes.toArray(new String[modes.size()]), notify);
|
towny.setPlayerMode(player, modes.toArray(new String[modes.size()]), notify);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean removeAndSetPlayerMode(Towny towny, Player player, String removeMode, String addMode, boolean notify) {
|
||||||
|
List<String> modes = towny.getPlayerMode(player);
|
||||||
|
boolean modesChanged = false;
|
||||||
|
if (removeMode != null && towny.hasPlayerMode(player, removeMode)) {
|
||||||
|
Iterator<String> iter = modes.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String s = iter.next();
|
||||||
|
if (s == null) continue;
|
||||||
|
if (s.equalsIgnoreCase(removeMode)) {
|
||||||
|
iter.remove();
|
||||||
|
modesChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (addMode != null) {
|
||||||
|
modes.add(addMode);
|
||||||
|
modesChanged = true;
|
||||||
|
}
|
||||||
|
if (modesChanged) {
|
||||||
|
towny.setPlayerMode(player, modes.toArray(new String[modes.size()]), notify);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user