Add material mapping to support legacy types.

This commit is contained in:
Ben Woo 2021-05-02 19:05:29 +08:00
parent ef34f88c6a
commit 485f43d405
7 changed files with 56 additions and 33 deletions

View File

@ -1,16 +1,16 @@
package com.onarandombox.MultiverseCore.configuration; package com.onarandombox.MultiverseCore.configuration;
import java.util.Map; import com.onarandombox.MultiverseCore.utils.MVMaterials;
import com.onarandombox.MultiverseCore.utils.MaterialConverter; import com.onarandombox.MultiverseCore.utils.MaterialConverter;
import me.main__.util.SerializationConfig.Property; import me.main__.util.SerializationConfig.Property;
import me.main__.util.SerializationConfig.SerializationConfig; import me.main__.util.SerializationConfig.SerializationConfig;
import me.main__.util.SerializationConfig.Serializor; import me.main__.util.SerializationConfig.Serializor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Map;
/** /**
* Entryfee-settings. * Entryfee-settings.
*/ */
@ -22,7 +22,7 @@ public class EntryFee extends SerializationConfig {
@Nullable @Nullable
private Material currency; private Material currency;
private final Material DISABLED_MATERIAL = Material.AIR; private final Material DISABLED_MATERIAL = MVMaterials.AIR;
public EntryFee() { public EntryFee() {
super(); super();

View File

@ -1,9 +1,9 @@
package com.onarandombox.MultiverseCore.listeners; package com.onarandombox.MultiverseCore.listeners;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.utils.MVMaterials;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -28,8 +28,8 @@ public class MVMapListener implements Listener {
@EventHandler @EventHandler
public void mapInitialize(final MapInitializeEvent event) { public void mapInitialize(final MapInitializeEvent event) {
for (final Player player : Bukkit.getOnlinePlayers()) { for (final Player player : Bukkit.getOnlinePlayers()) {
if ((player.getItemInHand().getType() == Material.MAP if ((player.getItemInHand().getType() == MVMaterials.MAP
|| player.getItemInHand().getType() == Material.FILLED_MAP) || player.getItemInHand().getType() == MVMaterials.FILLED_MAP)
&& player.getItemInHand().getDurability() == event.getMap().getId()) { && player.getItemInHand().getDurability() == event.getMap().getId()) {
final Location playerLoc = player.getLocation(); final Location playerLoc = player.getLocation();
final MapView map = event.getMap(); final MapView map = event.getMap();

View File

@ -14,10 +14,10 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.enums.RespawnType; import com.onarandombox.MultiverseCore.enums.RespawnType;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent; import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
import com.onarandombox.MultiverseCore.utils.CompatibilityLayer; import com.onarandombox.MultiverseCore.utils.CompatibilityLayer;
import com.onarandombox.MultiverseCore.utils.MVMaterials;
import com.onarandombox.MultiverseCore.utils.PermissionTools; import com.onarandombox.MultiverseCore.utils.PermissionTools;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -260,7 +260,7 @@ public class MVPlayerListener implements Listener {
// REMEMBER! getTo MAY be NULL HERE!!! // REMEMBER! getTo MAY be NULL HERE!!!
// If the player was actually outside of the portal, adjust the from location // If the player was actually outside of the portal, adjust the from location
if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.NETHER_PORTAL) { if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != MVMaterials.NETHER_PORTAL) {
Location newloc = this.plugin.getSafeTTeleporter().findPortalBlockNextTo(event.getFrom()); Location newloc = this.plugin.getSafeTTeleporter().findPortalBlockNextTo(event.getFrom());
// TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what // TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what
// TODO: we want to do here. // TODO: we want to do here.

View File

@ -10,7 +10,7 @@ package com.onarandombox.MultiverseCore.listeners;
import com.dumptruckman.minecraft.util.Logging; import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import org.bukkit.Material; import com.onarandombox.MultiverseCore.utils.MVMaterials;
import org.bukkit.PortalType; import org.bukkit.PortalType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -19,8 +19,6 @@ import org.bukkit.event.entity.EntityCreatePortalEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.event.world.PortalCreateEvent;
import java.util.logging.Level;
/** /**
* A custom listener for portal related events. * A custom listener for portal related events.
*/ */
@ -72,10 +70,10 @@ public class MVPortalListener implements Listener {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return; return;
} }
if (event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) { if (event.getClickedBlock().getType() != MVMaterials.END_PORTAL_FRAME) {
return; return;
} }
if (event.getItem() == null || event.getItem().getType() != Material.ENDER_EYE) { if (event.getItem() == null || event.getItem().getType() != MVMaterials.ENDER_EYE) {
return; return;
} }
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getPlayer().getWorld()); MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getPlayer().getWorld());

View File

@ -0,0 +1,28 @@
package com.onarandombox.MultiverseCore.utils;
import org.bukkit.Material;
import static com.onarandombox.MultiverseCore.utils.MaterialConverter.convertTypeString;
public class MVMaterials {
public static final Material ENDER_EYE = convertTypeString("ENDER_EYE");
public static final Material END_PORTAL_FRAME = convertTypeString("END_PORTAL_FRAME");
public static final Material NETHER_PORTAL = convertTypeString("NETHER_PORTAL");
public static final Material GRASS = convertTypeString("GRASS");
public static final Material VINE = convertTypeString("VINE");
public static final Material SNOW = convertTypeString("SNOW");
public static final Material AIR = convertTypeString("AIR");
public static final Material WATER = convertTypeString("WATER");
public static final Material LAVA = convertTypeString("LAVA");
public static final Material FIRE = convertTypeString("FIRE");
public static final Material WATER_BUCKET = convertTypeString("WATER_BUCKET");
public static final Material LAVA_BUCKET = convertTypeString("LAVA_BUCKET");
public static final Material FLINT_AND_STEEL = convertTypeString("FLINT_AND_STEEL");
public static final Material WOODEN_AXE = convertTypeString("WOODEN_AXE");
public static final Material POWERED_RAIL = convertTypeString("POWERED_RAIL");
public static final Material DETECTOR_RAIL = convertTypeString("DETECTOR_RAIL");
public static final Material RAIL = convertTypeString("RAIL");
public static final Material ACTIVATOR_RAIL = convertTypeString("ACTIVATOR_RAIL");
public static final Material MAP = convertTypeString("MAP");
public static final Material FILLED_MAP = convertTypeString("FILLED_MAP");
}

View File

@ -52,7 +52,7 @@ public class SimpleBlockSafety implements BlockSafety {
public boolean isBlockAboveAir(Location l) { public boolean isBlockAboveAir(Location l) {
Location downOne = l.clone(); Location downOne = l.clone();
downOne.setY(downOne.getY() - 1); downOne.setY(downOne.getY() - 1);
return (downOne.getBlock().getType() == Material.AIR); return (downOne.getBlock().getType() == MVMaterials.AIR);
} }
/** /**
@ -90,12 +90,12 @@ public class SimpleBlockSafety implements BlockSafety {
return false; return false;
} }
if (downOne.getBlock().getType() == Material.LAVA) { if (downOne.getBlock().getType() == MVMaterials.LAVA) {
Logging.finer("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(), isSolidBlock(downOne.getBlock().getType())); Logging.finer("Error Here (downOne)? (%s)[%s]", downOne.getBlock().getType(), isSolidBlock(downOne.getBlock().getType()));
return false; return false;
} }
if (downOne.getBlock().getType() == Material.FIRE) { if (downOne.getBlock().getType() == MVMaterials.FIRE) {
Logging.finer("There's fire below! (%s)[%s]", actual.getBlock().getType(), isSolidBlock(actual.getBlock().getType())); Logging.finer("There's fire below! (%s)[%s]", actual.getBlock().getType(), isSolidBlock(actual.getBlock().getType()));
return false; return false;
} }
@ -211,10 +211,10 @@ public class SimpleBlockSafety implements BlockSafety {
@Override @Override
public boolean isEntitiyOnTrack(Location l) { public boolean isEntitiyOnTrack(Location l) {
Material currentBlock = l.getBlock().getType(); Material currentBlock = l.getBlock().getType();
return (currentBlock == Material.POWERED_RAIL return (currentBlock == MVMaterials.POWERED_RAIL
|| currentBlock == Material.DETECTOR_RAIL || currentBlock == MVMaterials.DETECTOR_RAIL
|| currentBlock == Material.RAIL || currentBlock == MVMaterials.RAIL
|| currentBlock == Material.ACTIVATOR_RAIL); || currentBlock == MVMaterials.ACTIVATOR_RAIL);
} }
/** /**
@ -229,12 +229,12 @@ public class SimpleBlockSafety implements BlockSafety {
} }
Location oneBelow = l.clone(); Location oneBelow = l.clone();
oneBelow.subtract(0, 1, 0); oneBelow.subtract(0, 1, 0);
if (oneBelow.getBlock().getType() == Material.WATER) { if (oneBelow.getBlock().getType() == MVMaterials.WATER) {
Location twoBelow = oneBelow.clone(); Location twoBelow = oneBelow.clone();
twoBelow.subtract(0, 1, 0); twoBelow.subtract(0, 1, 0);
return (oneBelow.getBlock().getType() == Material.WATER); return (oneBelow.getBlock().getType() == MVMaterials.WATER);
} }
if (oneBelow.getBlock().getType() != Material.AIR) { if (oneBelow.getBlock().getType() != MVMaterials.AIR) {
return false; return false;
} }
return hasTwoBlocksofWaterBelow(oneBelow); return hasTwoBlocksofWaterBelow(oneBelow);

View File

@ -9,11 +9,10 @@ package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging; import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.api.MVDestination; import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.destination.InvalidDestination; import com.onarandombox.MultiverseCore.destination.InvalidDestination;
import com.onarandombox.MultiverseCore.enums.TeleportResult; import com.onarandombox.MultiverseCore.enums.TeleportResult;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -25,8 +24,6 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.logging.Level;
/** /**
* The default-implementation of {@link SafeTTeleporter}. * The default-implementation of {@link SafeTTeleporter}.
*/ */
@ -293,19 +290,19 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
public Location findPortalBlockNextTo(Location l) { public Location findPortalBlockNextTo(Location l) {
Block b = l.getWorld().getBlockAt(l); Block b = l.getWorld().getBlockAt(l);
Location foundLocation = null; Location foundLocation = null;
if (b.getType() == Material.NETHER_PORTAL) { if (b.getType() == MVMaterials.NETHER_PORTAL) {
return l; return l;
} }
if (b.getRelative(BlockFace.NORTH).getType() == Material.NETHER_PORTAL) { if (b.getRelative(BlockFace.NORTH).getType() == MVMaterials.NETHER_PORTAL) {
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.NORTH).getLocation(), foundLocation); foundLocation = getCloserBlock(l, b.getRelative(BlockFace.NORTH).getLocation(), foundLocation);
} }
if (b.getRelative(BlockFace.SOUTH).getType() == Material.NETHER_PORTAL) { if (b.getRelative(BlockFace.SOUTH).getType() == MVMaterials.NETHER_PORTAL) {
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.SOUTH).getLocation(), foundLocation); foundLocation = getCloserBlock(l, b.getRelative(BlockFace.SOUTH).getLocation(), foundLocation);
} }
if (b.getRelative(BlockFace.EAST).getType() == Material.NETHER_PORTAL) { if (b.getRelative(BlockFace.EAST).getType() == MVMaterials.NETHER_PORTAL) {
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.EAST).getLocation(), foundLocation); foundLocation = getCloserBlock(l, b.getRelative(BlockFace.EAST).getLocation(), foundLocation);
} }
if (b.getRelative(BlockFace.WEST).getType() == Material.NETHER_PORTAL) { if (b.getRelative(BlockFace.WEST).getType() == MVMaterials.NETHER_PORTAL) {
foundLocation = getCloserBlock(l, b.getRelative(BlockFace.WEST).getLocation(), foundLocation); foundLocation = getCloserBlock(l, b.getRelative(BlockFace.WEST).getLocation(), foundLocation);
} }
return foundLocation; return foundLocation;