Makes it easier to use any compatible block as a button

This commit is contained in:
2021-02-10 03:29:28 +01:00
parent 7b9f5a6de5
commit 095e59c65e
5 changed files with 25 additions and 7 deletions

View File

@ -1,7 +1,6 @@
package net.knarcraft.stargate;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import java.io.BufferedWriter;
@ -399,7 +398,7 @@ public class Gate {
return null;
}
if (!Tag.BUTTONS.isTagged(gate.button) && !MaterialHelper.isWallCoral(gate.button)) {
if (!MaterialHelper.isButtonCompatible(gate.button)) {
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gate button must be a type of button.");
return null;
}

View File

@ -22,4 +22,14 @@ public class MaterialHelper {
material.equals(Material.DEAD_TUBE_CORAL_WALL_FAN);
}
/**
* Checks whether the given material can be used as a button
* @param material <p>The material to check</p>
* @return <p>True if the material can be used as a button</p>
*/
public static boolean isButtonCompatible(Material material) {
return Tag.BUTTONS.isTagged(material) || isWallCoral(material) || Tag.SHULKER_BOXES.isTagged(material) ||
material == Material.CHEST;
}
}

View File

@ -1,7 +1,6 @@
package net.knarcraft.stargate;
import org.bukkit.GameMode;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.WallSign;
@ -230,7 +229,7 @@ public class PlayerEventsListener implements Listener {
}
// Implement right-click to toggle a stargate, gets around spawn protection problem.
if (Tag.BUTTONS.isTagged(block.getType()) || MaterialHelper.isWallCoral(block.getType())) {
if (MaterialHelper.isButtonCompatible(block.getType())) {
if (MaterialHelper.isWallCoral(block.getType())) {
if (previousEvent != null &&

View File

@ -6,7 +6,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.EndGateway;
@ -846,7 +845,7 @@ public class Stargate extends JavaPlugin {
// Handle keeping portal material and buttons around
if (block.getType() == Material.NETHER_PORTAL) {
portal = Portal.getByEntrance(block);
} else if (Tag.BUTTONS.isTagged(block.getType()) || MaterialHelper.isWallCoral(block.getType())) {
} else if (MaterialHelper.isButtonCompatible(block.getType())) {
portal = Portal.getByControl(block);
}
if (portal != null) event.setCancelled(true);