From b6dac546772e228d39559aeec661112852738634 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Tue, 13 Sep 2016 18:10:01 -0400 Subject: [PATCH] Code cleaning and Gradle Update Updated gradle wrapper to 3.0 Updated Gradle files for Nukkit Added/cleaned minor Nukkit code Removed duplicate TitleManagement code Signed-off-by: MattBDev --- .../bukkit/titles/DefaultTitleManager.java | 19 ++------- .../titles/DefaultTitleManager_183.java | 13 +----- .../bukkit/titles/HackTitleManager.java | 16 +------- .../bukkit/titles/TitleManager.java | 13 ++++++ .../bukkit/util/BukkitChunkManager.java | 40 +++++++++---------- Nukkit/build.gradle | 7 ++-- Nukkit/build/resources/main/plugin.yml | 2 +- .../nukkit/listeners/PlayerEvents.java | 9 ++--- .../nukkit/util/NukkitEventUtil.java | 2 +- .../nukkit/util/NukkitSchematicHandler.java | 2 +- .../nukkit/util/NukkitSetupUtils.java | 4 +- .../nukkit/util/block/NukkitLocalQueue.java | 5 +-- build.gradle | 1 - gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew | 5 +++ 15 files changed, 58 insertions(+), 84 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java index 888700dc4..98ea32db9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java @@ -18,7 +18,7 @@ public class DefaultTitleManager extends TitleManager { * @param stayTime Stay on screen time * @param fadeOutTime Fade out time */ - public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { + DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } @@ -106,9 +106,9 @@ public class DefaultTitleManager extends TitleManager { } } - private Method getMethod(Class clazz, String name, Class... args) { + Method getMethod(Class clazz, String name, Class... args) { for (Method m : clazz.getMethods()) { - if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { + if (m.getName().equals(name) && (args.length == 0 || classListEqual(args, m.getParameterTypes()))) { m.setAccessible(true); return m; } @@ -116,17 +116,4 @@ public class DefaultTitleManager extends TitleManager { return null; } - boolean ClassListEqual(Class[] l1, Class[] l2) { - if (l1.length != l2.length) { - return false; - } - boolean equal = true; - for (int i = 0; i < l1.length; i++) { - if (l1[i] != l2[i]) { - equal = false; - break; - } - } - return equal; - } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java index 20d050f01..559e296fd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java @@ -17,7 +17,7 @@ public class DefaultTitleManager_183 extends DefaultTitleManager { * @param stayTime Stay on screen time * @param fadeOutTime Fade out time */ - public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { + DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } @@ -67,15 +67,4 @@ public class DefaultTitleManager_183 extends DefaultTitleManager { } } } - - private Method getMethod(Class clazz, String name, Class... args) { - for (Method m : clazz.getMethods()) { - if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) { - m.setAccessible(true); - return m; - } - } - return null; - } - } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index feae37dc4..cf8e87b95 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -19,7 +19,7 @@ public class HackTitleManager extends TitleManager { * @param stayTime Stay on screen time * @param fadeOutTime Fade out time */ - public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { + HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) { super(title, subtitle, fadeInTime, stayTime, fadeOutTime); } @@ -162,18 +162,4 @@ public class HackTitleManager extends TitleManager { return null; } - private boolean classListEqual(Class[] l1, Class[] l2) { - if (l1.length != l2.length) { - return false; - } - boolean equal = true; - for (int i = 0; i < l1.length; i++) { - if (l1[i] != l2[i]) { - equal = false; - break; - } - } - return equal; - } - } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java index ba75b71b6..91a5d68a0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java @@ -241,4 +241,17 @@ public abstract class TitleManager { return true; } + boolean classListEqual(Class[] l1, Class[] l2) { + if (l1.length != l2.length) { + return false; + } + boolean equal = true; + for (int i = 0; i < l1.length; i++) { + if (l1[i] != l2[i]) { + equal = false; + break; + } + } + return equal; + } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 8e008c08c..fcd195343 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -610,27 +610,27 @@ public class BukkitChunkManager extends ChunkManager { public static class ContentMap { - public final Map chestContents; - public final Map furnaceContents; - public final Map dispenserContents; - public final Map dropperContents; - public final Map brewingStandContents; - public final Map beaconContents; - public final Map hopperContents; - public final Map furnaceTime; - public final Map skullData; - public final Map jukeboxDisc; - public final Map brewTime; - public final Map spawnerData; - public final Map cmdData; - public final Map signContents; - public final Map noteBlockContents; - public final Map> bannerPatterns; - public final Map bannerBase; - public final Set entities; - public final Map allBlocks; + final Map chestContents; + final Map furnaceContents; + final Map dispenserContents; + final Map dropperContents; + final Map brewingStandContents; + final Map beaconContents; + final Map hopperContents; + final Map furnaceTime; + final Map skullData; + final Map jukeboxDisc; + final Map brewTime; + final Map spawnerData; + final Map cmdData; + final Map signContents; + final Map noteBlockContents; + final Map> bannerPatterns; + final Map bannerBase; + final Set entities; + final Map allBlocks; - public ContentMap() { + ContentMap() { this.chestContents = new HashMap<>(); this.furnaceContents = new HashMap<>(); this.dispenserContents = new HashMap<>(); diff --git a/Nukkit/build.gradle b/Nukkit/build.gradle index 52e56f3e4..ff14a95fb 100644 --- a/Nukkit/build.gradle +++ b/Nukkit/build.gradle @@ -1,5 +1,5 @@ repositories { - maven {url "https://hub.spigotmc.org/nexus/content/groups/public/"} + maven {url "http://ci.regularbox.com/plugin/repository/everything/"} maven { url = "https://oss.sonatype.org/content/repositories/snapshots/"} maven {url "http://nexus.hc.to/content/repositories/pub_releases"} } @@ -16,9 +16,8 @@ configurations.all { } } -sourceCompatibility = 1.7 -targetCompatibility = 1.7 - +sourceCompatibility = 1.8 +targetCompatibility = 1.8 processResources { from('src/main/resources') { include 'plugin.yml' diff --git a/Nukkit/build/resources/main/plugin.yml b/Nukkit/build/resources/main/plugin.yml index 0afd5358d..11087834b 100644 --- a/Nukkit/build/resources/main/plugin.yml +++ b/Nukkit/build/resources/main/plugin.yml @@ -1,5 +1,5 @@ name: "PlotSquared" -version: "3.4.6-SNAPSHOT-0557671" +version: "3.4.6-SNAPSHOT-a95b68b" author: Empire92 api: ["1.0.0"] main: com.plotsquared.nukkit.NukkitMain diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java b/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java index 1736d610a..2acd46080 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java @@ -12,6 +12,7 @@ import cn.nukkit.entity.item.EntityPotion; import cn.nukkit.entity.item.EntityVehicle; import cn.nukkit.entity.mob.EntityMob; import cn.nukkit.entity.passive.EntityAnimal; +import cn.nukkit.entity.passive.EntityTameable; import cn.nukkit.entity.passive.EntityWaterAnimal; import cn.nukkit.entity.projectile.EntityProjectile; import cn.nukkit.event.Cancellable; @@ -552,7 +553,7 @@ public class PlayerEvents extends PlotListener implements Listener { PlotPlayer plotPlayer = NukkitUtil.getPlayer(event.getPlayer()); Location location = plotPlayer.getLocation(); PlotArea area = location.getPlotArea(); - if (area == null || (!area.PLOT_CHAT != plotPlayer.getAttribute("chat"))) { + if (area == null || (area.PLOT_CHAT == plotPlayer.getAttribute("chat"))) { return; } Plot plot = area.getPlot(location); @@ -1052,9 +1053,7 @@ public void blockDestroy(BlockBreakEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onInventoryClose(InventoryCloseEvent event) { - Player closer = event.getPlayer(); - Player player = (Player) closer; - NukkitUtil.getPlayer(player).deleteMeta("inventory"); + NukkitUtil.getPlayer(event.getPlayer()).deleteMeta("inventory"); } @EventHandler(priority = EventPriority.MONITOR) @@ -1224,7 +1223,7 @@ public void blockDestroy(BlockBreakEvent event) { MainUtil.sendMessage(plotPlayer, C.NO_PERMISSION_EVENT, "plots.admin.pve." + stub); return false; } - } else if (false) { // TODO victim is tameable + } else if (victim instanceof EntityTameable) { if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK, false) || plot.getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) { return true; } diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java index 24b1bbd5a..8254af2d1 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java @@ -50,7 +50,7 @@ public class NukkitEventUtil extends EventUtil { public boolean callEvent(Event event) { plugin.getServer().getPluginManager().callEvent(event); - return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled(); + return !(event instanceof Cancellable) || !event.isCancelled(); } @Override diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSchematicHandler.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSchematicHandler.java index f8b2aec6a..dcdee81a6 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSchematicHandler.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSchematicHandler.java @@ -79,7 +79,7 @@ public class NukkitSchematicHandler extends SchematicHandler { public void run() { schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); schematic.put("Data", new ByteArrayTag("Data", blockData)); - schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList())); + schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<>())); schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities)); whenDone.value = new CompoundTag("Schematic", schematic); TaskManager.runTask(whenDone); diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java index 4e8e999be..a259975b1 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java @@ -34,7 +34,7 @@ public class NukkitSetupUtils extends SetupUtils { return; } String testWorld = "CheckingPlotSquaredGenerator"; - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put("world", testWorld); map.put("plot-generator", new HybridGen()); NukkitPlotGenerator gen = new NukkitPlotGenerator(map); @@ -117,7 +117,7 @@ public class NukkitSetupUtils extends SetupUtils { e.printStackTrace(); } if (object.setupGenerator != null) { - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put("world", object.world); map.put("plot-generator", new HybridGen()); plugin.getServer().generateLevel(object.world, object.world.hashCode(), NukkitPlotGenerator.class, map); diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitLocalQueue.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitLocalQueue.java index d19e74db8..d8e3492d5 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitLocalQueue.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/block/NukkitLocalQueue.java @@ -8,7 +8,6 @@ import cn.nukkit.level.generator.biome.Biome; import cn.nukkit.math.Vector3; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue; import com.plotsquared.nukkit.NukkitMain; @@ -112,9 +111,7 @@ public class NukkitLocalQueue extends BasicLocalBlockQueue { for (int y = 0; y < biomes2.length; y++) { String biomeStr = biomes2[y]; if (biomeStr != null) { - if (last == null || !StringMan.isEqual(last, biomeStr)) { - biome = Biome.getBiome(biomeStr.toUpperCase()).getId(); - } + biome = Biome.getBiome(biomeStr.toUpperCase()).getId(); level.setBiomeId(bx + x, bz + y, biome); } } diff --git a/build.gradle b/build.gradle index 0ef30476a..2f02607d9 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,6 @@ subprojects { } repositories { mavenCentral() - maven {url "http://ci.regularbox.com/plugin/repository/everything/"} maven {url "http://empcraft.com/maven2"} maven {url "http://repo.mcstats.org/content/repositories/public"} maven {url "http://maven.sk89q.com/repo/"} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 44a4bea14..0f335290f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jun 28 19:14:40 AEST 2016 +#Sun Sep 11 16:39:31 EDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip diff --git a/gradlew b/gradlew index 27309d923..9aa616c27 100644 --- a/gradlew +++ b/gradlew @@ -161,4 +161,9 @@ function splitJvmOpts() { eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then + cd "$(dirname "$0")" +fi + exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"