From 299fac95fbcd4e15c440db2d6f902415501ca0c5 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Mon, 29 Apr 2019 11:02:47 -0400 Subject: [PATCH] Add a stupidity fail-safe. --- .../plotsquared/bukkit/BukkitMain.java | 3 - .../bukkit/util/BukkitLegacyMappings.java | 61 +++++++++++-------- .../plotsquared/bukkit/util/BukkitUtil.java | 8 ++- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index 8aaea98fe..3411e85ba 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -116,10 +116,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain @Override public void onEnable() { - this.pluginName = getDescription().getName(); - getServer().getName(); - PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer); if (Bukkit.getVersion().contains("git-Spigot")) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitLegacyMappings.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitLegacyMappings.java index 00edbb660..061712d02 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitLegacyMappings.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitLegacyMappings.java @@ -1,36 +1,44 @@ package com.github.intellectualsites.plotsquared.bukkit.util; +import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings; import com.github.intellectualsites.plotsquared.plot.util.StringComparison; -import lombok.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.ToString; import org.bukkit.Bukkit; import org.bukkit.Material; -import java.util.*; -import java.util.stream.Collectors; - /** * Borrowed from https://github.com/Phoenix616/IDConverter/blob/master/mappings/src/main/java/de/themoep/idconverter/IdMappings.java * Original License: *

- * Minecraft ID mappings - * Copyright (C) 2017 Max Lee (https://github.com/Phoenix616) + * Minecraft ID mappings Copyright (C) 2017 Max Lee (https://github.com/Phoenix616) *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 free software: you can redistribute it and/or modify it under the terms of the + * GNU 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 General Public License for more details. + * 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 + * General Public License for more details. *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License along with this program. If + * not, see . */ public final class BukkitLegacyMappings extends LegacyMappings { @@ -702,7 +710,15 @@ public final class BukkitLegacyMappings extends LegacyMappings { try { material = Material.valueOf(legacyBlock.getNewName()); } catch (final Exception e) { - material = Material.getMaterial(legacyBlock.getLegacyName(), true); + try { + material = Material.getMaterial(legacyBlock.getLegacyName(), true); + } catch (NoSuchMethodError error) { + PlotSquared.log( + "You can't use this version of PlotSquared on a server " + + "less than Minecraft 1.13.2"); + Bukkit.shutdown(); + break; + } } legacyBlock.material = material; } @@ -721,13 +737,10 @@ public final class BukkitLegacyMappings extends LegacyMappings { } /** - * Try to find a legacy plot block by any means possible. - * Strategy: - * - Check if the name contains a namespace, if so, strip it - * - Check if there's a (new) material matching the name - * - Check if there's a legacy material matching the name - * - Check if there's a numerical ID matching the name - * - Return null if everything else fails + * Try to find a legacy plot block by any means possible. Strategy: - Check if the name contains + * a namespace, if so, strip it - Check if there's a (new) material matching the name - Check if + * there's a legacy material matching the name - Check if there's a numerical ID matching the + * name - Return null if everything else fails * * @param string String ID * @return LegacyBlock if found, else null diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index 065756932..66b509615 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -340,9 +340,11 @@ import java.util.*; } else if (world.getBlockAt(x, y, z - 1).getType().isSolid()) { facing = BlockFace.SOUTH; } - block.setType(Material.valueOf( - PlotSquared.get().IMP.getServerVersion()[1] == 13 ? "WALL_SIGN" : "OAK_WALL_SIGN"), - false); + if (PlotSquared.get().IMP.getServerVersion()[1] == 13) { + block.setType(Material.valueOf("WALL_SIGN"), false); + } else { + block.setType(Material.valueOf("OAK_WALL_SIGN"), false); + } final Directional sign = (Directional) block.getBlockData(); sign.setFacing(facing); block.setBlockData(sign, false);