Adds a wool gate amongst other things
Adds the wool gate type from legacy Adds some missing material tag-related code Updates the URL for update checking
This commit is contained in:
		@@ -365,7 +365,7 @@ public class Stargate extends JavaPlugin {
 | 
			
		||||
        this.registerCommands();
 | 
			
		||||
 | 
			
		||||
        //Check for any available updates
 | 
			
		||||
        UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=97784",
 | 
			
		||||
        UpdateChecker.checkForUpdate(this, "https://api.spigotmc.org/legacy/update.php?resource=87978",
 | 
			
		||||
                Stargate::getPluginVersion, Stargate::setUpdateAvailable);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -301,7 +301,7 @@ public class Gate {
 | 
			
		||||
            saveEconomyValues(bufferedWriter);
 | 
			
		||||
 | 
			
		||||
            //Store material types to use for frame blocks
 | 
			
		||||
            saveFrameBlockTypes(bufferedWriter);
 | 
			
		||||
            saveFrameBlockType(bufferedWriter);
 | 
			
		||||
 | 
			
		||||
            bufferedWriter.newLine();
 | 
			
		||||
 | 
			
		||||
@@ -342,25 +342,39 @@ public class Gate {
 | 
			
		||||
     * @param bufferedWriter <p>The buffered writer to write to</p>
 | 
			
		||||
     * @throws IOException <p>If unable to write to the buffered writer</p>
 | 
			
		||||
     */
 | 
			
		||||
    private void saveFrameBlockTypes(BufferedWriter bufferedWriter) throws IOException {
 | 
			
		||||
        for (Map.Entry<Character, Material> entry : characterMaterialMap.entrySet()) {
 | 
			
		||||
            Character type = entry.getKey();
 | 
			
		||||
            Material value = entry.getValue();
 | 
			
		||||
    private void saveFrameBlockType(BufferedWriter bufferedWriter) throws IOException {
 | 
			
		||||
        for (Map.Entry<Character, Material> entry : this.characterMaterialMap.entrySet()) {
 | 
			
		||||
            Character key = entry.getKey();
 | 
			
		||||
            //Skip characters not part of the frame
 | 
			
		||||
            if (type.equals(GateHandler.getAnythingCharacter()) ||
 | 
			
		||||
                    type.equals(GateHandler.getEntranceCharacter()) ||
 | 
			
		||||
                    type.equals(GateHandler.getExitCharacter())) {
 | 
			
		||||
            if (key.equals(GateHandler.getAnythingCharacter()) ||
 | 
			
		||||
                    key.equals(GateHandler.getEntranceCharacter()) ||
 | 
			
		||||
                    key.equals(GateHandler.getExitCharacter())) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            saveFrameBlockType(key, entry.getValue().toString(), bufferedWriter);
 | 
			
		||||
        }
 | 
			
		||||
        for (Map.Entry<Character, Tag<Material>> entry : this.characterTagMap.entrySet()) {
 | 
			
		||||
            saveFrameBlockType(entry.getKey(), "#" + entry.getValue().getKey().toString().replaceFirst(
 | 
			
		||||
                    "minecraft:", ""), bufferedWriter);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
            bufferedWriter.append(type);
 | 
			
		||||
    /**
 | 
			
		||||
     * Saves a type of block used for the gate frame/border using a buffered writer
 | 
			
		||||
     *
 | 
			
		||||
     * @param key            <p>The character key to store</p>
 | 
			
		||||
     * @param value          <p>The string value to store</p>
 | 
			
		||||
     * @param bufferedWriter <p>The buffered writer to write to</p>
 | 
			
		||||
     * @throws IOException <p>If unable to write to the buffered writer</p>
 | 
			
		||||
     */
 | 
			
		||||
    private void saveFrameBlockType(Character key, String value, BufferedWriter bufferedWriter) throws IOException {
 | 
			
		||||
        bufferedWriter.append(key.toString());
 | 
			
		||||
        bufferedWriter.append('=');
 | 
			
		||||
        if (value != null) {
 | 
			
		||||
                bufferedWriter.append(value.toString());
 | 
			
		||||
            bufferedWriter.append(value);
 | 
			
		||||
        }
 | 
			
		||||
        bufferedWriter.newLine();
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Writes a formatted string to a buffered writer
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,9 @@ package net.knarcraft.stargate.portal.property.gate;
 | 
			
		||||
import net.knarcraft.stargate.Stargate;
 | 
			
		||||
import net.knarcraft.stargate.utility.GateReader;
 | 
			
		||||
import net.knarcraft.stargate.utility.MaterialHelper;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.NamespacedKey;
 | 
			
		||||
import org.bukkit.Tag;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
 | 
			
		||||
@@ -90,18 +92,16 @@ public class GateHandler {
 | 
			
		||||
        if (blockId != null) {
 | 
			
		||||
            if (!controlBlocks.containsKey(blockId)) {
 | 
			
		||||
                controlBlocks.put(blockId, new ArrayList<>());
 | 
			
		||||
            } else {
 | 
			
		||||
                controlBlocks.get(blockId).add(gate);
 | 
			
		||||
            }
 | 
			
		||||
            controlBlocks.get(blockId).add(gate);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Tag<Material> materialTag = gate.getControlBlockTag();
 | 
			
		||||
        if (!controlBlockTags.containsKey(materialTag.getKey().toString())) {
 | 
			
		||||
            controlBlockTags.put(materialTag.getKey().toString(), new ArrayList<>());
 | 
			
		||||
        } else {
 | 
			
		||||
            controlBlockTags.get(materialTag.getKey().toString()).add(gate);
 | 
			
		||||
        }
 | 
			
		||||
        controlBlockTags.get(materialTag.getKey().toString()).add(gate);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -274,6 +274,7 @@ public class GateHandler {
 | 
			
		||||
        loadGateFromJar("watergate.gate", gateFolder);
 | 
			
		||||
        loadGateFromJar("endgate.gate", gateFolder);
 | 
			
		||||
        loadGateFromJar("squarenetherglowstonegate.gate", gateFolder);
 | 
			
		||||
        loadGateFromJar("wool.gate", gateFolder);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -318,14 +319,25 @@ public class GateHandler {
 | 
			
		||||
     * @return <p>A list of gates using the given material for control block</p>
 | 
			
		||||
     */
 | 
			
		||||
    public static Gate[] getGatesByControlBlock(Material type) {
 | 
			
		||||
        Gate[] result = new Gate[0];
 | 
			
		||||
        List<Gate> lookup = controlBlocks.get(type);
 | 
			
		||||
 | 
			
		||||
        if (lookup != null) {
 | 
			
		||||
            result = lookup.toArray(result);
 | 
			
		||||
        List<Gate> result = new ArrayList<>();
 | 
			
		||||
        List<Gate> fromId = controlBlocks.get(type);
 | 
			
		||||
        List<Gate> fromTag = null;
 | 
			
		||||
        for (String tagString : controlBlockTags.keySet()) {
 | 
			
		||||
            Tag<Material> tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft(tagString.replaceFirst(
 | 
			
		||||
                    "minecraft:", "")), Material.class);
 | 
			
		||||
            if (tag != null && tag.isTagged(type)) {
 | 
			
		||||
                fromTag = controlBlockTags.get(tag.getKey().toString());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return result;
 | 
			
		||||
        if (fromId != null) {
 | 
			
		||||
            result.addAll(fromId);
 | 
			
		||||
        }
 | 
			
		||||
        if (fromTag != null) {
 | 
			
		||||
            result.addAll(fromTag);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return result.toArray(new Gate[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -353,6 +365,7 @@ public class GateHandler {
 | 
			
		||||
    public static void clearGates() {
 | 
			
		||||
        gates.clear();
 | 
			
		||||
        controlBlocks.clear();
 | 
			
		||||
        controlBlockTags.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								src/main/resources/gates/wool.gate
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/main/resources/gates/wool.gate
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
portal-open=WATER
 | 
			
		||||
portal-closed=AIR
 | 
			
		||||
button=STONE_BUTTON
 | 
			
		||||
toowner=false
 | 
			
		||||
X=#WOOL
 | 
			
		||||
-=#WOOL
 | 
			
		||||
 | 
			
		||||
XXXXX
 | 
			
		||||
X...X
 | 
			
		||||
-...-
 | 
			
		||||
X.*.X
 | 
			
		||||
XXXXX
 | 
			
		||||
		Reference in New Issue
	
	Block a user