Fixes compatibility for pre-1.20 spigot
This commit is contained in:
		@@ -1,10 +1,10 @@
 | 
				
			|||||||
package net.knarcraft.stargate.container;
 | 
					package net.knarcraft.stargate.container;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.knarcraft.knarlib.util.ColorHelper;
 | 
					import net.knarcraft.knarlib.util.ColorHelper;
 | 
				
			||||||
 | 
					import net.knarcraft.stargate.utility.SignHelper;
 | 
				
			||||||
import net.md_5.bungee.api.ChatColor;
 | 
					import net.md_5.bungee.api.ChatColor;
 | 
				
			||||||
import org.bukkit.DyeColor;
 | 
					import org.bukkit.DyeColor;
 | 
				
			||||||
import org.bukkit.block.Sign;
 | 
					import org.bukkit.block.Sign;
 | 
				
			||||||
import org.bukkit.block.sign.Side;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * A class that keeps track of the sign colors for a given sign
 | 
					 * A class that keeps track of the sign colors for a given sign
 | 
				
			||||||
@@ -27,7 +27,7 @@ public class SignData {
 | 
				
			|||||||
        this.sign = sign;
 | 
					        this.sign = sign;
 | 
				
			||||||
        this.mainSignColor = mainSignColor;
 | 
					        this.mainSignColor = mainSignColor;
 | 
				
			||||||
        this.highlightSignColor = highlightSignColor;
 | 
					        this.highlightSignColor = highlightSignColor;
 | 
				
			||||||
        this.dyedColor = sign.getSide(Side.FRONT).getColor();
 | 
					        this.dyedColor = SignHelper.getDye(sign);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,12 +6,12 @@ import net.knarcraft.stargate.Stargate;
 | 
				
			|||||||
import net.knarcraft.stargate.container.SignData;
 | 
					import net.knarcraft.stargate.container.SignData;
 | 
				
			||||||
import net.knarcraft.stargate.portal.property.PortalLocation;
 | 
					import net.knarcraft.stargate.portal.property.PortalLocation;
 | 
				
			||||||
import net.knarcraft.stargate.utility.PermissionHelper;
 | 
					import net.knarcraft.stargate.utility.PermissionHelper;
 | 
				
			||||||
 | 
					import net.knarcraft.stargate.utility.SignHelper;
 | 
				
			||||||
import net.md_5.bungee.api.ChatColor;
 | 
					import net.md_5.bungee.api.ChatColor;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.block.Block;
 | 
					import org.bukkit.block.Block;
 | 
				
			||||||
import org.bukkit.block.BlockState;
 | 
					import org.bukkit.block.BlockState;
 | 
				
			||||||
import org.bukkit.block.Sign;
 | 
					import org.bukkit.block.Sign;
 | 
				
			||||||
import org.bukkit.block.sign.Side;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -176,7 +176,7 @@ public class PortalSignDrawer {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    private void clearSign(Sign sign) {
 | 
					    private void clearSign(Sign sign) {
 | 
				
			||||||
        for (int index = 0; index <= 3; index++) {
 | 
					        for (int index = 0; index <= 3; index++) {
 | 
				
			||||||
            sign.getSide(Side.FRONT).setLine(index, "");
 | 
					            SignHelper.setSignLine(sign, index, "");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -189,7 +189,7 @@ public class PortalSignDrawer {
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        clearSign(sign);
 | 
					        clearSign(sign);
 | 
				
			||||||
        sign.getSide(Side.FRONT).setLine(0, translateAllColorCodes(portal.getName()));
 | 
					        SignHelper.setSignLine(sign, 0, translateAllColorCodes(portal.getName()));
 | 
				
			||||||
        sign.update();
 | 
					        sign.update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -257,7 +257,7 @@ public class PortalSignDrawer {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public void setLine(SignData signData, int index, String text) {
 | 
					    public void setLine(SignData signData, int index, String text) {
 | 
				
			||||||
        ChatColor mainColor = signData.getMainSignColor();
 | 
					        ChatColor mainColor = signData.getMainSignColor();
 | 
				
			||||||
        signData.getSign().getSide(Side.FRONT).setLine(index, mainColor + text);
 | 
					        SignHelper.setSignLine(signData.getSign(), index, mainColor + text);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -358,7 +358,7 @@ public class PortalSignDrawer {
 | 
				
			|||||||
        if (!(blockState instanceof Sign sign)) {
 | 
					        if (!(blockState instanceof Sign sign)) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        sign.getSide(Side.FRONT).setLine(3, errorColor + Stargate.getString("signInvalidGate"));
 | 
					        SignHelper.setSignLine(sign, 3, errorColor + Stargate.getString("signInvalidGate"));
 | 
				
			||||||
        sign.update();
 | 
					        sign.update();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Stargate.logInfo(String.format("Gate layout on line %d does not exist [%s]", lineIndex, gateName));
 | 
					        Stargate.logInfo(String.format("Gate layout on line %d does not exist [%s]", lineIndex, gateName));
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										67
									
								
								src/main/java/net/knarcraft/stargate/utility/SignHelper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/main/java/net/knarcraft/stargate/utility/SignHelper.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,67 @@
 | 
				
			|||||||
 | 
					package net.knarcraft.stargate.utility;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.DyeColor;
 | 
				
			||||||
 | 
					import org.bukkit.block.Sign;
 | 
				
			||||||
 | 
					import org.bukkit.block.sign.Side;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A helper class for dealing with signs
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public final class SignHelper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final boolean HAS_SIGN_SIDES = hasSignSides();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private SignHelper() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the dye color of the given sign
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param sign <p>The sign to check</p>
 | 
				
			||||||
 | 
					     * @return <p>The dye currently applied to the sign</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static DyeColor getDye(Sign sign) {
 | 
				
			||||||
 | 
					        if (HAS_SIGN_SIDES) {
 | 
				
			||||||
 | 
					            return sign.getSide(Side.FRONT).getColor();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            // Note: This is depreciated, but is currently necessary for pre-1.19.4 support
 | 
				
			||||||
 | 
					            //noinspection deprecation
 | 
				
			||||||
 | 
					            return sign.getColor();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Sets the text of a line on a sign
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param sign <p>The sign to set text for</p>
 | 
				
			||||||
 | 
					     * @param line <p>The line to set</p>
 | 
				
			||||||
 | 
					     * @param text <p>The text to set</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static void setSignLine(Sign sign, int line, String text) {
 | 
				
			||||||
 | 
					        if (HAS_SIGN_SIDES) {
 | 
				
			||||||
 | 
					            sign.getSide(Side.FRONT).setLine(line, text);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            // Note: This is depreciated, but is currently necessary for pre-1.19.4 support
 | 
				
			||||||
 | 
					            //noinspection deprecation
 | 
				
			||||||
 | 
					            sign.setLine(line, text);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Checks whether the running version differentiates between the front or back of a sign
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return <p>True if the server supports sign side differentiation</p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private static boolean hasSignSides() {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            Class.forName("Side");
 | 
				
			||||||
 | 
					            Class<?> aClass = Class.forName("org.bukkit.block.Sign");
 | 
				
			||||||
 | 
					            aClass.getMethod("getSide", Side.class);
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        } catch (ClassNotFoundException | NoSuchMethodException ignored) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user