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:
2023-03-25 01:54:43 +01:00
parent 91d855312d
commit c1720e05a0
4 changed files with 65 additions and 26 deletions

View File

@@ -365,7 +365,7 @@ public class Stargate extends JavaPlugin {
this.registerCommands(); this.registerCommands();
//Check for any available updates //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); Stargate::getPluginVersion, Stargate::setUpdateAvailable);
} }

View File

@@ -301,7 +301,7 @@ public class Gate {
saveEconomyValues(bufferedWriter); saveEconomyValues(bufferedWriter);
//Store material types to use for frame blocks //Store material types to use for frame blocks
saveFrameBlockTypes(bufferedWriter); saveFrameBlockType(bufferedWriter);
bufferedWriter.newLine(); bufferedWriter.newLine();
@@ -342,25 +342,39 @@ public class Gate {
* @param bufferedWriter <p>The buffered writer to write to</p> * @param bufferedWriter <p>The buffered writer to write to</p>
* @throws IOException <p>If unable to write to the buffered writer</p> * @throws IOException <p>If unable to write to the buffered writer</p>
*/ */
private void saveFrameBlockTypes(BufferedWriter bufferedWriter) throws IOException { private void saveFrameBlockType(BufferedWriter bufferedWriter) throws IOException {
for (Map.Entry<Character, Material> entry : characterMaterialMap.entrySet()) { for (Map.Entry<Character, Material> entry : this.characterMaterialMap.entrySet()) {
Character type = entry.getKey(); Character key = entry.getKey();
Material value = entry.getValue();
//Skip characters not part of the frame //Skip characters not part of the frame
if (type.equals(GateHandler.getAnythingCharacter()) || if (key.equals(GateHandler.getAnythingCharacter()) ||
type.equals(GateHandler.getEntranceCharacter()) || key.equals(GateHandler.getEntranceCharacter()) ||
type.equals(GateHandler.getExitCharacter())) { key.equals(GateHandler.getExitCharacter())) {
continue; 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('='); bufferedWriter.append('=');
if (value != null) { if (value != null) {
bufferedWriter.append(value.toString()); bufferedWriter.append(value);
} }
bufferedWriter.newLine(); bufferedWriter.newLine();
} }
}
/** /**
* Writes a formatted string to a buffered writer * Writes a formatted string to a buffered writer

View File

@@ -3,7 +3,9 @@ package net.knarcraft.stargate.portal.property.gate;
import net.knarcraft.stargate.Stargate; import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.utility.GateReader; import net.knarcraft.stargate.utility.GateReader;
import net.knarcraft.stargate.utility.MaterialHelper; import net.knarcraft.stargate.utility.MaterialHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@@ -90,18 +92,16 @@ public class GateHandler {
if (blockId != null) { if (blockId != null) {
if (!controlBlocks.containsKey(blockId)) { if (!controlBlocks.containsKey(blockId)) {
controlBlocks.put(blockId, new ArrayList<>()); controlBlocks.put(blockId, new ArrayList<>());
} else {
controlBlocks.get(blockId).add(gate);
} }
controlBlocks.get(blockId).add(gate);
return; return;
} }
Tag<Material> materialTag = gate.getControlBlockTag(); Tag<Material> materialTag = gate.getControlBlockTag();
if (!controlBlockTags.containsKey(materialTag.getKey().toString())) { if (!controlBlockTags.containsKey(materialTag.getKey().toString())) {
controlBlockTags.put(materialTag.getKey().toString(), new ArrayList<>()); 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("watergate.gate", gateFolder);
loadGateFromJar("endgate.gate", gateFolder); loadGateFromJar("endgate.gate", gateFolder);
loadGateFromJar("squarenetherglowstonegate.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> * @return <p>A list of gates using the given material for control block</p>
*/ */
public static Gate[] getGatesByControlBlock(Material type) { public static Gate[] getGatesByControlBlock(Material type) {
Gate[] result = new Gate[0]; List<Gate> result = new ArrayList<>();
List<Gate> lookup = controlBlocks.get(type); List<Gate> fromId = controlBlocks.get(type);
List<Gate> fromTag = null;
if (lookup != null) { for (String tagString : controlBlockTags.keySet()) {
result = lookup.toArray(result); 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() { public static void clearGates() {
gates.clear(); gates.clear();
controlBlocks.clear(); controlBlocks.clear();
controlBlockTags.clear();
} }
} }

View 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