Change some collections and cache player names.

This commit is contained in:
sk89q 2014-08-17 20:04:32 -07:00
parent c43a24d78f
commit 3a2b453e3f
4 changed files with 19 additions and 11 deletions

View File

@ -33,18 +33,21 @@ public class BukkitPlayer extends LocalPlayer {
private final WorldGuardPlugin plugin;
private final Player player;
private final String name;
public BukkitPlayer(WorldGuardPlugin plugin, Player player) {
checkNotNull(plugin);
checkNotNull(player);
this.plugin = plugin;
this.player = player;
// getName() takes longer than before in newer versions of Minecraft
this.name = player.getName();
}
@Override
public String getName() {
return player.getName();
return name;
}
@Override

View File

@ -19,7 +19,6 @@
package com.sk89q.worldguard.protection;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ObjectArrays;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.association.RegionAssociable;
@ -35,6 +34,7 @@
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -346,7 +346,7 @@ public int size() {
* @return a set of regions
*/
public Set<ProtectedRegion> getRegions() {
return ImmutableSet.copyOf(applicable);
return new HashSet<ProtectedRegion>(applicable);
}
@Override

View File

@ -31,6 +31,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -55,6 +56,7 @@ public class FlagValueCalculator {
private final List<ProtectedRegion> regions;
@Nullable
private final ProtectedRegion globalRegion;
private final Iterable<ProtectedRegion> applicable;
/**
* Create a new instance.
@ -67,6 +69,12 @@ public FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedReg
this.regions = regions;
this.globalRegion = globalRegion;
if (globalRegion != null) {
applicable = Iterables.concat(regions, Arrays.asList(globalRegion));
} else {
applicable = regions;
}
}
/**
@ -76,11 +84,7 @@ public FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedReg
* @return an iterable
*/
private Iterable<ProtectedRegion> getApplicable() {
if (globalRegion != null) {
return Iterables.concat(regions, ImmutableList.of(globalRegion));
} else {
return regions;
}
return applicable;
}
/**

View File

@ -19,9 +19,10 @@
package com.sk89q.worldguard.protection.flags;
import com.google.common.collect.ImmutableSet;
import com.sk89q.worldguard.domains.Association;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
@ -41,7 +42,7 @@ public enum RegionGroup {
private final Set<Association> contained;
RegionGroup(Association... association) {
this.contained = ImmutableSet.copyOf(association);
this.contained = association.length > 0 ? EnumSet.copyOf(Arrays.asList(association)) : EnumSet.noneOf(Association.class);
}
/**