forked from PseudoKnight/Stargate-Bukkit
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splits GateFormat into GateFormat and GateFormatHandler #120
- Loading branch information
1 parent
6481ed5
commit 98ebf73
Showing
9 changed files
with
95 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/net/TheDgtl/Stargate/gate/GateFormatHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package net.TheDgtl.Stargate.gate; | ||
|
||
import org.bukkit.Material; | ||
|
||
import java.util.ArrayList; | ||
import java.util.EnumMap; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* A handler that keeps track of all known gate formats | ||
*/ | ||
public class GateFormatHandler { | ||
|
||
private static Map<Material, List<GateFormat>> controlMaterialToGateFormatsMap; | ||
private static Map<String, GateFormat> knownGateFormats; | ||
|
||
/** | ||
* Gets the gate format corresponding to the given gate design name | ||
* | ||
* @param gateDesignName <p>The gate design name to get the format of</p> | ||
* @return <p>The gate format, or null if no such gate format</p> | ||
*/ | ||
public static GateFormat getFormat(String gateDesignName) { | ||
return knownGateFormats.get(gateDesignName); | ||
} | ||
|
||
/** | ||
* Sets the gate formats known by the gate format handler | ||
* | ||
* @param gateFormats <p>The new list of known gate formats</p> | ||
*/ | ||
public static void setFormats(List<GateFormat> gateFormats) { | ||
controlMaterialToGateFormatsMap = new EnumMap<>(Material.class); | ||
knownGateFormats = new HashMap<>(); | ||
for (GateFormat format : gateFormats) { | ||
addGateFormat(controlMaterialToGateFormatsMap, format, format.getControlMaterials()); | ||
knownGateFormats.put(format.getFileName(), format); | ||
} | ||
} | ||
|
||
/** | ||
* Gets all gate format using the given control block material | ||
* | ||
* @param signParentBlockMaterial <p>The material of a placed sign's parent block</p> | ||
* @return <p>All gate formats using the given control block</p> | ||
*/ | ||
public static List<GateFormat> getPossibleGateFormatsFromControlBlockMaterial(Material signParentBlockMaterial) { | ||
List<GateFormat> possibleGates = controlMaterialToGateFormatsMap.get(signParentBlockMaterial); | ||
if (possibleGates == null) { | ||
return new ArrayList<>(); | ||
} | ||
return possibleGates; | ||
|
||
} | ||
|
||
/** | ||
* Adds a new gate format | ||
* | ||
* @param controlToGateMap <p>The map of registered control block material to gate format mapping</p> | ||
* @param format <p>The gate format to register</p> | ||
* @param controlMaterials <p>The allowed control block materials for the new gate format</p> | ||
*/ | ||
private static void addGateFormat(Map<Material, List<GateFormat>> controlToGateMap, GateFormat format, | ||
Set<Material> controlMaterials) { | ||
for (Material controlMaterial : controlMaterials) { | ||
//Add an empty list if the material has no entry | ||
if (!(controlToGateMap.containsKey(controlMaterial))) { | ||
List<GateFormat> gateFormatList = new ArrayList<>(); | ||
controlToGateMap.put(controlMaterial, gateFormatList); | ||
} | ||
controlToGateMap.get(controlMaterial).add(format); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters