Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace vanishedPlayers list with set #1796

Merged
merged 2 commits into from
Mar 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Essentials/src/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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;
Expand Down Expand Up @@ -820,6 +820,13 @@ public EssentialsTimer getTimer() {

@Override
public List<String> getVanishedPlayers() {
List<String> list = new ArrayList<>();
list.addAll(vanishedPlayers);
Copy link
Contributor

@caojohnny caojohnny Feb 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be replaced by:

return new ArrayList<>(this.vanishedPlayers);

I'd also like to question the validity of returning a modifiable collection. While changes to this collection might not cause changes, returning a modifiable collection in getVanishedPlayersSet() would, which may confuse some people. I recommend perhaps using Collections#unmodifiableXYZ(...) to wrap the result instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this logic. Please do use unmodifiableList().

return list;
}

@Override
public Set<String> getVanishedPlayersSet() {
return vanishedPlayers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public void run() {
user.setDisplayNick();
updateCompass(user);

if (!ess.getVanishedPlayers().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (String p : ess.getVanishedPlayers()) {
if (!ess.getVanishedPlayersSet().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (String p : ess.getVanishedPlayersSet()) {
Player toVanish = ess.getServer().getPlayerExact(p);
if (toVanish != null && toVanish.isOnline()) {
user.getBase().hidePlayer(toVanish);
Expand Down
1 change: 1 addition & 0 deletions Essentials/src/com/earth2me/essentials/IEssentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public interface IEssentials extends Plugin {

EssentialsTimer getTimer();

@Deprecated
List<String> getVanishedPlayers();

Collection<Player> getOnlinePlayers();
Expand Down
4 changes: 2 additions & 2 deletions Essentials/src/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ public void setVanished(final boolean set) {
}
}
setHidden(true);
ess.getVanishedPlayers().add(getName());
ess.getVanishedPlayersSet().add(getName());
if (isAuthorized("essentials.vanish.effect")) {
this.getBase().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
}
Expand All @@ -724,7 +724,7 @@ public void setVanished(final boolean set) {
p.showPlayer(getBase());
}
setHidden(false);
ess.getVanishedPlayers().remove(getName());
ess.getVanishedPlayersSet().remove(getName());
if (isAuthorized("essentials.vanish.effect")) {
this.getBase().removePotionEffect(PotionEffectType.INVISIBILITY);
}
Expand Down
5 changes: 5 additions & 0 deletions Essentials/src/net/ess3/api/IEssentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import net.ess3.nms.PotionMetaProvider;
import net.ess3.nms.SpawnEggProvider;

import java.util.LinkedHashSet;
import java.util.Set;

public interface IEssentials extends com.earth2me.essentials.IEssentials {

SpawnEggProvider getSpawnEggProvider();

PotionMetaProvider getPotionMetaProvider();

Set<String> getVanishedPlayersSet();
}