mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-24 03:25:24 +01:00
Change some collections and cache player names.
This commit is contained in:
parent
c43a24d78f
commit
3a2b453e3f
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user