From f33889b88f6b2c53b7c2956e5487eaafc71c539a Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 7 Jan 2015 18:07:30 -0800 Subject: [PATCH] Support both MC 1.7.10 and 1.8. --- pom.xml | 15 +++++++++++++++ .../com/sk89q/worldguard/blacklist/Blacklist.java | 10 +++++----- .../worldguard/blacklist/BlacklistEntry.java | 12 +++--------- .../blacklist/target/TargetMatcherParser.java | 10 +++++----- .../bukkit/listener/PlayerMoveListener.java | 8 ++++---- .../bukkit/listener/debounce/EventDebounce.java | 8 ++++---- .../debounce/legacy/AbstractEventDebounce.java | 8 ++++---- 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 9804bc80..8015d1a0 100644 --- a/pom.xml +++ b/pom.xml @@ -137,6 +137,16 @@ jar + + + com.sk89q + guavabackport + 1.1 + compile + jar + + com.google.code.findbugs jsr305 @@ -377,9 +387,14 @@ org.khelekore:prtree org.flywaydb:flyway-core com.sk89q:squirrelid + com.sk89q:guavabackport + + com.sk89q.guavabackport + com.sk89q.worldguard.internal.guava + org.flywaydb com.sk89q.worldguard.internal.flywaydb diff --git a/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java b/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java index 5c1138e6..32c467e1 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java @@ -19,9 +19,6 @@ package com.sk89q.worldguard.blacklist; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; import com.sk89q.worldguard.blacklist.action.Action; import com.sk89q.worldguard.blacklist.action.ActionType; import com.sk89q.worldguard.blacklist.event.BlacklistEvent; @@ -29,6 +26,9 @@ import com.sk89q.worldguard.blacklist.target.TargetMatcher; import com.sk89q.worldguard.blacklist.target.TargetMatcherParseException; import com.sk89q.worldguard.blacklist.target.TargetMatcherParser; +import com.sk89q.guavabackport.cache.CacheBuilder; +import com.sk89q.guavabackport.cache.CacheLoader; +import com.sk89q.guavabackport.cache.LoadingCache; import org.bukkit.ChatColor; import java.io.BufferedReader; @@ -49,7 +49,7 @@ public abstract class Blacklist { private final BlacklistLoggerHandler blacklistLogger = new BlacklistLoggerHandler(); private BlacklistEvent lastEvent; private boolean useAsWhitelist; - private Cache repeatingEventCache = CacheBuilder.newBuilder() + private LoadingCache repeatingEventCache = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterAccess(30, TimeUnit.SECONDS) .build(new CacheLoader() { @@ -284,7 +284,7 @@ public void notify(BlacklistEvent event, String comment) { */ public abstract void broadcastNotification(String msg); - public Cache getRepeatingEventCache() { + public LoadingCache getRepeatingEventCache() { return repeatingEventCache; } diff --git a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java b/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java index 9ed29a42..22b5d2a3 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/BlacklistEntry.java @@ -19,20 +19,14 @@ package com.sk89q.worldguard.blacklist; -import com.google.common.cache.Cache; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.blacklist.action.Action; import com.sk89q.worldguard.blacklist.action.ActionResult; import com.sk89q.worldguard.blacklist.event.BlacklistEvent; +import com.sk89q.guavabackport.cache.LoadingCache; import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public class BlacklistEntry { @@ -178,7 +172,7 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force boolean repeating = false; String eventCacheKey = event.getCauseName(); - Cache repeatingEventCache = blacklist.getRepeatingEventCache(); + LoadingCache repeatingEventCache = blacklist.getRepeatingEventCache(); // Check to see whether this event is being repeated TrackedEvent tracked = repeatingEventCache.getUnchecked(eventCacheKey); diff --git a/src/main/java/com/sk89q/worldguard/blacklist/target/TargetMatcherParser.java b/src/main/java/com/sk89q/worldguard/blacklist/target/TargetMatcherParser.java index db6376e8..c698c469 100644 --- a/src/main/java/com/sk89q/worldguard/blacklist/target/TargetMatcherParser.java +++ b/src/main/java/com/sk89q/worldguard/blacklist/target/TargetMatcherParser.java @@ -21,7 +21,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.collect.Ranges; +import com.sk89q.guavabackport.collect.Range; import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldguard.util.Enums; import org.bukkit.Material; @@ -84,22 +84,22 @@ private Predicate parseRange(String input) throws TargetMatcherParseExcep matcher = LESS_THAN_PATTERN.matcher(input); if (matcher.matches()) { - return Ranges.atMost(Short.parseShort(matcher.group(1))); + return Range.atMost(Short.parseShort(matcher.group(1))); } matcher = GREATER_THAN_PATTERN.matcher(input); if (matcher.matches()) { - return Ranges.atLeast(Short.parseShort(matcher.group(1))); + return Range.atLeast(Short.parseShort(matcher.group(1))); } matcher = RANGE_PATTERN.matcher(input); if (matcher.matches()) { - return Ranges.closed(Short.parseShort(matcher.group(1)), Short.parseShort(matcher.group(2))); + return Range.closed(Short.parseShort(matcher.group(1)), Short.parseShort(matcher.group(2))); } try { short s = Short.parseShort(input); - return Ranges.closed(s, s); + return Range.closed(s, s); } catch (NumberFormatException e) { throw new TargetMatcherParseException("Unknown data value range: " + input); } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java index 6a1d6f18..3df6a660 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java @@ -19,9 +19,6 @@ package com.sk89q.worldguard.bukkit.listener; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.bukkit.BukkitUtil; @@ -29,6 +26,9 @@ import com.sk89q.worldguard.bukkit.WorldConfiguration; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.listener.FlagStateManager.PlayerFlagState; +import com.sk89q.guavabackport.cache.CacheBuilder; +import com.sk89q.guavabackport.cache.CacheLoader; +import com.sk89q.guavabackport.cache.LoadingCache; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; @@ -50,7 +50,7 @@ public class PlayerMoveListener implements Listener { private final WorldGuardPlugin plugin; - private Cache bypassCache = CacheBuilder.newBuilder() + private LoadingCache bypassCache = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterAccess(5, TimeUnit.SECONDS) .build(new CacheLoader() { diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/EventDebounce.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/EventDebounce.java index d05de27e..45c3ba4d 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/EventDebounce.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/EventDebounce.java @@ -19,10 +19,10 @@ package com.sk89q.worldguard.bukkit.listener.debounce; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; import com.sk89q.worldguard.bukkit.util.Events; +import com.sk89q.guavabackport.cache.CacheBuilder; +import com.sk89q.guavabackport.cache.CacheLoader; +import com.sk89q.guavabackport.cache.LoadingCache; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -31,7 +31,7 @@ public class EventDebounce { - private final Cache cache; + private final LoadingCache cache; public EventDebounce(int debounceTime) { cache = CacheBuilder.newBuilder() diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/legacy/AbstractEventDebounce.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/legacy/AbstractEventDebounce.java index 92951689..10fa2d42 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/legacy/AbstractEventDebounce.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/legacy/AbstractEventDebounce.java @@ -19,10 +19,10 @@ package com.sk89q.worldguard.bukkit.listener.debounce.legacy; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; import com.sk89q.worldguard.bukkit.util.Events; +import com.sk89q.guavabackport.cache.CacheBuilder; +import com.sk89q.guavabackport.cache.CacheLoader; +import com.sk89q.guavabackport.cache.LoadingCache; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -31,7 +31,7 @@ public class AbstractEventDebounce { - private final Cache cache; + private final LoadingCache cache; AbstractEventDebounce(int debounceTime) { cache = CacheBuilder.newBuilder()