Skip to content

Commit

Permalink
- Fix UnsupportedOperationException which was possible when leaving a
Browse files Browse the repository at this point in the history
channel.
  • Loading branch information
LlmDl committed Feb 8, 2021
1 parent f12fda4 commit ceef862
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion resources/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,5 @@ v0.86:
- Fix firing PlayerJoinChatChannelEvent async.
v0.87:
- Fix event firing async.
- Fix ranged global channels' chat being forwarded to dynmap.
- Fix ranged global channels' chat being forwarded to dynmap.
- Fix UnsupportedOperationException which was possible when leaving a channel.
21 changes: 11 additions & 10 deletions src/com/palmergames/bukkit/TownyChat/util/TownyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.palmergames.bukkit.towny.Towny;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -32,24 +33,24 @@ public static boolean removePlayerMode(Towny towny, Player player, String mode,

public static void removeAndSetPlayerMode(Towny towny, Player player, String removeMode, String addMode, boolean notify) {
List<String> modes = towny.getPlayerMode(player);
List<String> newModes = new ArrayList<>();
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;
}
for (String mode : modes) {
if (!mode.equalsIgnoreCase(removeMode))
newModes.add(mode);
}
modesChanged = true;
}
if (addMode != null) {
modes.add(addMode);
newModes.add(addMode);
modesChanged = true;
}
if (modesChanged) {
towny.setPlayerMode(player, modes.toArray(new String[0]), notify);
if (newModes.isEmpty())
towny.removePlayerMode(player);
else
towny.setPlayerMode(player, newModes.toArray(new String[0]), notify);
}
}
}

0 comments on commit ceef862

Please sign in to comment.