Fix undoCommandChanges.

Remove entries after undoing them. change type of change history to
List, remove in reverse order to avoid potential problems with
overriding of multiple changes.
This commit is contained in:
asofold 2012-11-07 08:16:01 +01:00
parent 28afa77c74
commit b64beac0b4
2 changed files with 8 additions and 7 deletions

View File

@ -2,7 +2,6 @@ package fr.neatmonster.nocheatplus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@ -174,7 +173,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI
* Commands that were changed for protecting them against tab complete or
* use.
*/
protected Collection<CommandProtectionEntry> changedCommands = null;
protected List<CommandProtectionEntry> changedCommands = null;
@Override
public void addComponent(final Object obj) {
@ -242,18 +241,20 @@ public class NoCheatPlus extends JavaPlugin implements Listener, NoCheatPlusAPI
}
/**
* Does not undo 100%, but restore old permission, permission-message, label (unliekly to be changed), permission default.
* Does not undo 100%, but restore old permission, permission-message, label (unlikely to be changed), permission default.
*/
public void undoCommandChanges() {
if (changedCommands != null){
for (final CommandProtectionEntry entry : changedCommands){
while (!changedCommands.isEmpty()){
final CommandProtectionEntry entry = changedCommands.remove(changedCommands.size() - 1);
entry.restore();
}
changedCommands = null;
}
}
private void setupCommandProtection() {
final Collection<CommandProtectionEntry> changedCommands = PermissionUtil.protectCommands(
final List<CommandProtectionEntry> changedCommands = PermissionUtil.protectCommands(
Arrays.asList("plugins", "version", "icanhasbukkit"), "nocheatplus.feature.command", false);
if (this.changedCommands == null) this.changedCommands = changedCommands;
else this.changedCommands.addAll(changedCommands);

View File

@ -64,7 +64,7 @@ public class PermissionUtil {
* @param ops
* @return
*/
public static Collection<CommandProtectionEntry> protectCommands(Collection<String> commands, String permissionBase, boolean ops){
public static List<CommandProtectionEntry> protectCommands(Collection<String> commands, String permissionBase, boolean ops){
return protectCommands(permissionBase, commands, true, ops);
}
@ -76,7 +76,7 @@ public class PermissionUtil {
* @param ops
* @return
*/
public static Collection<CommandProtectionEntry> protectCommands(String permissionBase, Collection<String> ignoredCommands, boolean invertIgnored, boolean ops){
public static List<CommandProtectionEntry> protectCommands(String permissionBase, Collection<String> ignoredCommands, boolean invertIgnored, boolean ops){
Set<String> checked = new HashSet<String>();
for (String label : ignoredCommands){
checked.add(CommandUtil.getCommandLabel(label, false));