Replace vanishedPlayers list with set (#1796)

* Replace vanishedPlayers list with set

Not sure if there is any particular reason to keep it ordered, but for now I've used a LinkedHashSet.

* Change return of new method from Set to Collection

Also makes return of old method an unmodifiable list, but this is just as breaking as just changing the method return type as far as I can see
This commit is contained in:
md678685 2018-03-25 22:12:36 +01:00 committed by GitHub
parent 9f6d0fa2d6
commit 61c1485083
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 7 deletions

View file

@ -66,13 +66,11 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -101,7 +99,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
private transient I18n i18n;
private transient Metrics metrics;
private transient EssentialsTimer timer;
private final transient List<String> vanishedPlayers = new ArrayList<>();
private final transient Set<String> vanishedPlayers = new LinkedHashSet<>();
private transient Method oldGetOnlinePlayers;
private transient SpawnerProvider spawnerProvider;
private transient SpawnEggProvider spawnEggProvider;
@ -820,6 +818,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
@Override
public List<String> getVanishedPlayers() {
return Collections.unmodifiableList(new ArrayList<>(vanishedPlayers));
}
@Override
public Collection<String> getVanishedPlayersNew() {
return vanishedPlayers;
}

View file

@ -233,11 +233,14 @@ public class EssentialsPlayerListener implements Listener {
user.setDisplayNick();
updateCompass(user);
if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (String p : ess.getVanishedPlayers()) {
if (!ess.getVanishedPlayersNew().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (String p : ess.getVanishedPlayersNew()) {
Player toVanish = ess.getServer().getPlayerExact(p);
if (toVanish != null && toVanish.isOnline()) {
user.getBase().hidePlayer(toVanish);
if (ess.getSettings().isDebug()) {
ess.getLogger().info("Hiding vanished player: " + p);
}
}
}
}

View file

@ -95,6 +95,7 @@ public interface IEssentials extends Plugin {
EssentialsTimer getTimer();
@Deprecated
List<String> getVanishedPlayers();
Collection<Player> getOnlinePlayers();

View file

@ -715,7 +715,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
}
}
setHidden(true);
ess.getVanishedPlayers().add(getName());
ess.getVanishedPlayersNew().add(getName());
if (isAuthorized("essentials.vanish.effect")) {
this.getBase().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
}
@ -724,7 +724,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
p.showPlayer(getBase());
}
setHidden(false);
ess.getVanishedPlayers().remove(getName());
ess.getVanishedPlayersNew().remove(getName());
if (isAuthorized("essentials.vanish.effect")) {
this.getBase().removePotionEffect(PotionEffectType.INVISIBILITY);
}

View file

@ -3,8 +3,12 @@ package net.ess3.api;
import net.ess3.nms.PotionMetaProvider;
import net.ess3.nms.SpawnEggProvider;
import java.util.Collection;
public interface IEssentials extends com.earth2me.essentials.IEssentials {
Collection<String> getVanishedPlayersNew();
SpawnEggProvider getSpawnEggProvider();
PotionMetaProvider getPotionMetaProvider();