From 46dff16a977eb9244d8893dbf58a066d2e600c87 Mon Sep 17 00:00:00 2001 From: wizjany Date: Mon, 22 May 2017 16:00:50 -0400 Subject: [PATCH] Use our own firstNonNull to maintain back-compat. Fixes WORLDEDIT-3567. --- build.gradle | 2 +- worldedit-core/build.gradle | 2 +- .../command/argument/ReplaceParser.java | 3 +- .../worldedit/function/factory/Apply.java | 2 +- .../worldedit/function/factory/Deform.java | 4 +-- .../worldedit/function/factory/Paint.java | 2 +- .../com/sk89q/worldedit/util/GuavaUtil.java | 33 +++++++++++++++++++ 7 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/GuavaUtil.java diff --git a/build.gradle b/build.gradle index a97b88a56..1f7dd1540 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { configurations.all { resolutionStrategy { - force 'com.google.guava:guava:17.0' + force 'com.google.guava:guava:21.0' } } diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index 079e3c124..ac79454fd 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -5,7 +5,7 @@ dependencies { compile 'de.schlichtherle:truezip:6.8.3' compile 'rhino:js:1.7R2' compile 'org.yaml:snakeyaml:1.9' - compile 'com.google.guava:guava:17.0' + compile 'com.google.guava:guava:21.0' compile 'com.sk89q:jchronic:0.2.4a' compile 'com.google.code.findbugs:jsr305:1.3.9' compile 'com.thoughtworks.paranamer:paranamer:2.6' diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java index 6db624149..eed6e383c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java @@ -30,7 +30,8 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.util.command.composition.SimpleCommand; -import static com.google.common.base.Objects.firstNonNull; +import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; + public class ReplaceParser extends SimpleCommand> { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Apply.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Apply.java index b7695b795..7ff183a37 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Apply.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Apply.java @@ -27,8 +27,8 @@ import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; -import static com.google.common.base.Objects.firstNonNull; import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; public class Apply implements Contextual { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index 1c206843c..f255050b7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.function.factory; -import com.google.common.base.Objects; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; @@ -36,6 +35,7 @@ import com.sk89q.worldedit.regions.Region; import java.util.List; import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; public class Deform implements Contextual { @@ -123,7 +123,7 @@ public class Deform implements Contextual { final Vector zero; Vector unit; - Region region = Objects.firstNonNull(context.getRegion(), this.region); + Region region = firstNonNull(context.getRegion(), this.region); switch (mode) { case UNIT_CUBE: diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Paint.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Paint.java index fe9c80a83..b88c09bbf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Paint.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Paint.java @@ -33,9 +33,9 @@ import com.sk89q.worldedit.math.noise.RandomNoise; import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; -import static com.google.common.base.Objects.firstNonNull; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.regions.Regions.*; +import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; public class Paint implements Contextual { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/GuavaUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/GuavaUtil.java new file mode 100644 index 000000000..1e6fddbfa --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/GuavaUtil.java @@ -0,0 +1,33 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util; + +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkNotNull; + +public final class GuavaUtil { + + private GuavaUtil() {} + + public static T firstNonNull(@Nullable T first, @Nullable T second) { + return first != null ? first : checkNotNull(second); + } +}