From e29be0888fdd1edaaa5074008bda599390d33121 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 11 May 2015 22:34:11 +0200 Subject: [PATCH] Fix and improve tab completion of Sender stuff. --- .../massivecore/cmd/arg/ARPlayer.java | 23 +++++++++++-------- .../massivecore/cmd/arg/ARSender.java | 21 +---------------- .../massivecore/cmd/arg/ARSenderEntity.java | 19 --------------- .../massivecore/cmd/arg/ARSenderId.java | 22 ------------------ .../cmd/arg/ARSenderIdAbstract.java | 20 ++++++++++++++++ 5 files changed, 34 insertions(+), 71 deletions(-) diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARPlayer.java b/src/com/massivecraft/massivecore/cmd/arg/ARPlayer.java index 1bfefe87..98750da9 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARPlayer.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARPlayer.java @@ -1,13 +1,10 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.Collection; -import java.util.Set; -import java.util.TreeSet; - +import java.util.Iterator; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.store.SenderIdSourceMixinAllSenderIds; import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.MUtil; @@ -32,22 +29,28 @@ public class ARPlayer extends ARSenderIdAbstract @Override public Player getResultForSenderId(String senderId) { - // Null check is done in IdUtil :) + // Null check is done in IdUtil return IdUtil.getPlayer(senderId); } @Override public Collection getTabList(CommandSender sender, String arg) { - Set ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); + // Super Ret + Collection ret = super.getTabList(sender, arg); - for (String name : IdUtil.getOnlineNames()) + // Filter Ret + Iterator iter = ret.iterator(); + while (iter.hasNext()) { - if ( ! MUtil.isValidPlayerName(name)) continue; - if ( ! Mixin.canSee(sender, name)) continue; - ret.add(name); + String name = iter.next(); + if ( ! MUtil.isValidPlayerName(name)) + { + iter.remove(); + } } + // Return Ret return ret; } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSender.java b/src/com/massivecraft/massivecore/cmd/arg/ARSender.java index 12645de2..8cd2f83b 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSender.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSender.java @@ -1,12 +1,7 @@ package com.massivecraft.massivecore.cmd.arg; -import java.util.Collection; -import java.util.Set; -import java.util.TreeSet; - import org.bukkit.command.CommandSender; -import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.store.SenderIdSourceMixinAllSenderIds; import com.massivecraft.massivecore.util.IdUtil; @@ -30,22 +25,8 @@ public class ARSender extends ARSenderIdAbstract @Override public CommandSender getResultForSenderId(String senderId) { - //Null check is done in IdUtil + // Null check is done in IdUtil return IdUtil.getSender(senderId); } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - Set ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); - - for (String name : IdUtil.getOnlineNames()) - { - if ( ! Mixin.canSee(sender, name)) continue; - ret.add(name); - } - - return ret; - } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java b/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java index 0e99388a..746754fd 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java @@ -1,15 +1,10 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.Collection; -import java.util.Set; -import java.util.TreeSet; - import org.bukkit.command.CommandSender; -import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.store.SenderColl; import com.massivecraft.massivecore.store.SenderEntity; -import com.massivecraft.massivecore.util.IdUtil; public class ARSenderEntity> extends ARSenderIdAbstract implements ARAllAble { @@ -53,20 +48,6 @@ public class ARSenderEntity> extends ARSenderIdAbstrac return this.coll.get(senderId); } - @Override - public Collection getTabList(CommandSender sender, String arg) - { - Set ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); - - for (String name : IdUtil.getOnlineNames()) - { - if ( ! Mixin.canSee(sender, name)) continue; - ret.add(name); - } - - return ret; - } - @Override public Collection getAll(CommandSender sender) { diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSenderId.java b/src/com/massivecraft/massivecore/cmd/arg/ARSenderId.java index d3c59a6e..87e49b27 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSenderId.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSenderId.java @@ -1,15 +1,7 @@ package com.massivecraft.massivecore.cmd.arg; -import java.util.Collection; -import java.util.Set; -import java.util.TreeSet; - -import org.bukkit.command.CommandSender; - -import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.store.SenderIdSource; import com.massivecraft.massivecore.store.SenderIdSourceMixinAllSenderIds; -import com.massivecraft.massivecore.util.IdUtil; public class ARSenderId extends ARSenderIdAbstract { @@ -51,18 +43,4 @@ public class ARSenderId extends ARSenderIdAbstract return senderId; } - @Override - public Collection getTabList(CommandSender sender, String arg) - { - Set ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); - - for (String id : IdUtil.getOnlineIds()) - { - if ( ! Mixin.canSee(sender, id)) continue; - ret.add(id); - } - - return ret; - } - } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java b/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java index 93b8b0e5..5984d5a9 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java @@ -1,6 +1,8 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.Collection; +import java.util.Set; +import java.util.TreeSet; import org.bukkit.command.CommandSender; @@ -89,6 +91,24 @@ public abstract class ARSenderIdAbstract extends ARAbstract return false; } + @Override + public Collection getTabList(CommandSender sender, String arg) + { + // Create Ret + Set ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); + + // Fill Ret + Set names = (online ? IdUtil.getOnlineNames() : IdUtil.getAllNames()); + for (String name : names) + { + if ( ! Mixin.canSee(sender, name)) continue; + ret.add(name); + } + + // Return Ret + return ret; + } + // -------------------------------------------- // // UTIL // -------------------------------------------- //