From 1671d4839c27dd89c2855153bcafbdf121f2c446 Mon Sep 17 00:00:00 2001 From: JRoy Date: Sun, 30 Aug 2020 12:06:39 -0400 Subject: [PATCH] Clean up some tab completes that I missed --- .../com/earth2me/essentials/CommandSource.java | 4 ++++ .../earth2me/essentials/commands/Commandafk.java | 11 +---------- .../essentials/commands/Commandbalance.java | 11 +---------- .../earth2me/essentials/commands/Commandban.java | 6 ++---- .../essentials/commands/Commandbroadcast.java | 12 +----------- .../commands/Commandbroadcastworld.java | 15 +-------------- .../essentials/commands/Commanddelhome.java | 7 ++++--- .../earth2me/essentials/commands/Commandfeed.java | 11 +---------- .../essentials/commands/Commandgetpos.java | 11 +---------- .../earth2me/essentials/commands/Commandheal.java | 12 ++---------- .../earth2me/essentials/commands/Commandme.java | 3 ++- .../earth2me/essentials/commands/Commandnick.java | 11 +---------- 12 files changed, 21 insertions(+), 93 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/CommandSource.java b/Essentials/src/com/earth2me/essentials/CommandSource.java index 33e24a017..2340c6ed1 100644 --- a/Essentials/src/com/earth2me/essentials/CommandSource.java +++ b/Essentials/src/com/earth2me/essentials/CommandSource.java @@ -51,4 +51,8 @@ public class CommandSource { public String getSelfSelector() { return sender instanceof Player ? getPlayer().getName() : "*"; } + + public String getDisplayName() { + return sender instanceof Player ? getPlayer().getDisplayName() : getSender().getName(); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index b939618d3..154bb8de0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -90,18 +90,9 @@ public class Commandafk extends EssentialsCommand { user.setDisplayNick(); // Set this again after toggling } - @Override - protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { - if (args.length == 1 && user.isAuthorized("essentials.afk.others")) { - return getPlayers(server, user); - } else { - return Collections.emptyList(); - } - } - @Override protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { - if (args.length == 1) { + if (args.length == 1 && sender.isAuthorized("essentials.afk.others", ess)) { return getPlayers(server, sender); } else { return Collections.emptyList(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index 2eb73bcdf..9323c2a7e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -38,18 +38,9 @@ public class Commandbalance extends EssentialsCommand { } } - @Override - protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { - if (args.length == 1 && user.isAuthorized("essentials.balance.others")) { - return getPlayers(server, user); - } else { - return Collections.emptyList(); - } - } - @Override protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { - if (args.length == 1) { + if (args.length == 1 && sender.isAuthorized("essentials.balance.others", ess)) { return getPlayers(server, sender); } else { return Collections.emptyList(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index e7ff69964..22dd6ff82 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -37,10 +37,8 @@ public class Commandban extends EssentialsCommand { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.ban.offline")) { throw new Exception(tl("banExemptOffline")); } - } else { - if (user.isAuthorized("essentials.ban.exempt") && sender.isPlayer()) { - throw new Exception(tl("banExempt")); - } + } else if (user.isAuthorized("essentials.ban.exempt") && sender.isPlayer()) { + throw new Exception(tl("banExempt")); } final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index dfd165f59..90cb28439 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; @@ -13,21 +12,12 @@ public class Commandbroadcast extends EssentialsCommand { super("broadcast"); } - @Override - public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - sendBroadcast(user.getDisplayName(), args); - } - @Override public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { - sendBroadcast(sender.getSender().getName(), args); - } - - private void sendBroadcast(final String name, final String[] args) throws NotEnoughArgumentsException { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - ess.broadcastMessage(tl("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), name)); + ess.broadcastMessage(tl("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), sender.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java index 7ca9cd87e..3ddbcf189 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java @@ -78,22 +78,9 @@ public class Commandbroadcastworld extends EssentialsCommand { } } - @Override - protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { - if (args.length == 1 && ess.getSettings().isAllowWorldInBroadcastworld()) { - List worlds = Lists.newArrayList(); - for (World world : server.getWorlds()) { - worlds.add(world.getName()); - } - return worlds; - } else { - return Collections.emptyList(); - } - } - @Override protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { - if (args.length == 1) { + if (args.length == 1 && (!sender.isPlayer() || ess.getSettings().isAllowWorldInBroadcastworld())) { List worlds = Lists.newArrayList(); for (World world : server.getWorlds()) { worlds.add(world.getName()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java index 0d2d5adba..1a8e606b1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.IUser; import com.earth2me.essentials.User; import org.bukkit.Server; @@ -54,10 +55,10 @@ public class Commanddelhome extends EssentialsCommand { @Override protected List getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { - User user = ess.getUser(sender.getPlayer()); - boolean canDelOthers = user == null || user.isAuthorized("essentials.delhome.others"); + IUser user = sender.getUser(ess); + boolean canDelOthers = sender.isAuthorized("essentials.delhome.others", ess); if (args.length == 1) { - List homes = user == null ? new ArrayList<>() : user.getHomes(); + List homes = sender.isPlayer() ? new ArrayList<>() : user.getHomes(); if (canDelOthers) { int sepIndex = args[0].indexOf(':'); if (sepIndex < 0) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java index 4e5e69e3d..8f868a19d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java @@ -65,18 +65,9 @@ public class Commandfeed extends EssentialsLoopCommand { player.setExhaustion(0F); } - @Override - protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { - if (args.length == 1 && user.isAuthorized("essentials.feed.others")) { - return getPlayers(server, user); - } else { - return Collections.emptyList(); - } - } - @Override protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { - if (args.length == 1) { + if (args.length == 1 && sender.isAuthorized("essentials.feed.others", ess)) { return getPlayers(server, sender); } else { return Collections.emptyList(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index c6ba0c484..2bb961a40 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -47,18 +47,9 @@ public class Commandgetpos extends EssentialsCommand { } } - @Override - protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { - if (args.length == 1 && user.isAuthorized("essentials.getpos.others")) { - return getPlayers(server, user); - } else { - return Collections.emptyList(); - } - } - @Override protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { - if (args.length == 1) { + if (args.length == 1 && sender.isAuthorized("essentials.getpos.others", ess)) { return getPlayers(server, sender); } else { return Collections.emptyList(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index a47acbd96..47f1f1547 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -78,21 +78,13 @@ public class Commandheal extends EssentialsLoopCommand { } } - @Override - protected List getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) { - if (args.length == 1 && user.isAuthorized("essentials.heal.others")) { - return getPlayers(server, user); - } else { - return Collections.emptyList(); - } - } - @Override protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { - if (args.length == 1) { + if (args.length == 1 && sender.isAuthorized("essentials.heal.others", ess)) { return getPlayers(server, sender); } else { return Collections.emptyList(); + } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 2167d7242..9ce633be4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -10,6 +10,7 @@ import org.bukkit.Server; import org.bukkit.World; import org.bukkit.entity.Player; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -101,6 +102,6 @@ public class Commandme extends EssentialsCommand { @Override protected List getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) { - return null; // It's a chat message, use the default chat handler + return Collections.emptyList(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index cbd0244dd..38a73ada3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -122,18 +122,9 @@ public class Commandnick extends EssentialsLoopCommand { } } - @Override - protected List getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) { - if (args.length == 1 && user.isAuthorized("essentials.nick.others")) { - return getPlayers(server, user); - } else { - return Collections.emptyList(); - } - } - @Override protected List getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { - if (args.length == 1) { + if (args.length == 1 && sender.isAuthorized("essentials.nick.others", ess)) { return getPlayers(server, sender); } else { return Collections.emptyList();