forked from Aurorion/BlockRegen
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Wertik/3.11.0
3.11.0
- Loading branch information
Showing
28 changed files
with
604 additions
and
170 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ public class PresetEvent { | |
|
||
@Getter | ||
@Setter | ||
@Nullable | ||
private ItemDrop item; | ||
|
||
@Getter | ||
|
68 changes: 68 additions & 0 deletions
68
blockregen-plugin/src/main/java/nl/aurorion/blockregen/system/material/MaterialManager.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,68 @@ | ||
package nl.aurorion.blockregen.system.material; | ||
|
||
import lombok.extern.java.Log; | ||
import nl.aurorion.blockregen.BlockRegen; | ||
import nl.aurorion.blockregen.system.material.parser.MaterialParser; | ||
import nl.aurorion.blockregen.system.preset.struct.material.TargetMaterial; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Log | ||
public class MaterialManager { | ||
|
||
private final BlockRegen plugin; | ||
|
||
private final Map<String, MaterialParser> registeredParsers = new HashMap<>(); | ||
|
||
public MaterialManager(BlockRegen plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
/** | ||
* Register a material parser under a prefix. | ||
* If there is a parser already registered, overwrite (aka Map#put). | ||
* <p> | ||
* A null prefix parser is used for inputs with no prefix. | ||
* <p> | ||
* A prefix cannot match a material name, otherwise the parsing screws up. | ||
* We could use a different separator, but screw it, a colon looks cool. | ||
*/ | ||
public void registerParser(@Nullable String prefix, @NotNull MaterialParser parser) { | ||
registeredParsers.put((prefix == null ? null : prefix.toLowerCase()), parser); | ||
log.fine(String.format("Registered material parser with prefix %s", prefix)); | ||
} | ||
|
||
public MaterialParser getParser(@Nullable String prefix) { | ||
return this.registeredParsers.get((prefix == null ? null : prefix.toLowerCase())); | ||
} | ||
|
||
// Parse a material from a String input (<prefix:?><material input>) | ||
// Ignores chance in dynamic materials | ||
// All prefixes are case-insensitive | ||
public @Nullable TargetMaterial parseMaterial(@NotNull String input) throws IllegalArgumentException { | ||
// Separate parts | ||
String[] parts = input.split(":"); | ||
|
||
// First either prefix or material | ||
|
||
MaterialParser parser = getParser(parts[0].toLowerCase()); | ||
|
||
if (parser == null) { | ||
parser = getParser(null); | ||
|
||
if (parser == null) { | ||
log.fine(String.format("No valid parser found for material input %s", input)); | ||
return null; | ||
} | ||
} else { | ||
// remove parts[0] aka the parser prefix | ||
parts = Arrays.copyOfRange(parts, 1, parts.length); | ||
} | ||
|
||
return parser.parseMaterial(parts[0]); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...n/src/main/java/nl/aurorion/blockregen/system/material/parser/MMOItemsMaterialParser.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,26 @@ | ||
package nl.aurorion.blockregen.system.material.parser; | ||
|
||
import nl.aurorion.blockregen.BlockRegen; | ||
import nl.aurorion.blockregen.system.preset.struct.material.MMOIItemsMaterial; | ||
import nl.aurorion.blockregen.system.preset.struct.material.TargetMaterial; | ||
|
||
public class MMOItemsMaterialParser implements MaterialParser{ | ||
|
||
private final BlockRegen plugin; | ||
|
||
public MMOItemsMaterialParser(BlockRegen plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public TargetMaterial parseMaterial(String input) throws IllegalArgumentException { | ||
int id; | ||
try { | ||
id = Integer.parseInt(input); | ||
} catch (NumberFormatException e) { | ||
throw new IllegalArgumentException("Invalid MMOItem block id: " + input); | ||
} | ||
|
||
return new MMOIItemsMaterial(plugin, id); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...en-plugin/src/main/java/nl/aurorion/blockregen/system/material/parser/MaterialParser.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,16 @@ | ||
package nl.aurorion.blockregen.system.material.parser; | ||
|
||
import nl.aurorion.blockregen.system.preset.struct.material.TargetMaterial; | ||
|
||
public interface MaterialParser { | ||
|
||
/** | ||
* Parse a TargetMaterial from an input string. | ||
* | ||
* @param input String to parse from with the material prefix already removed. (ex.: 'oraxen:caveblock', input = 'caveblock'). | ||
* @return Parsed TargetMaterial | ||
* | ||
* @throws IllegalArgumentException if the provided {@code input} is not a valid oraxen block id | ||
*/ | ||
TargetMaterial parseMaterial(String input) throws IllegalArgumentException; | ||
} |
27 changes: 27 additions & 0 deletions
27
.../src/main/java/nl/aurorion/blockregen/system/material/parser/MinecraftMaterialParser.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,27 @@ | ||
package nl.aurorion.blockregen.system.material.parser; | ||
|
||
import com.cryptomorin.xseries.XMaterial; | ||
import nl.aurorion.blockregen.BlockRegen; | ||
import nl.aurorion.blockregen.system.preset.struct.material.MinecraftMaterial; | ||
import nl.aurorion.blockregen.system.preset.struct.material.TargetMaterial; | ||
import nl.aurorion.blockregen.util.ParseUtil; | ||
|
||
public class MinecraftMaterialParser implements MaterialParser { | ||
|
||
private final BlockRegen plugin; | ||
|
||
public MinecraftMaterialParser(BlockRegen plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public TargetMaterial parseMaterial(String input) throws IllegalArgumentException { | ||
XMaterial xMaterial = ParseUtil.parseMaterial(input, true); | ||
|
||
if (xMaterial == null) { | ||
throw new IllegalArgumentException("Could not parse minecraft material: " + input); | ||
} | ||
|
||
return new MinecraftMaterial(plugin, xMaterial); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...gin/src/main/java/nl/aurorion/blockregen/system/material/parser/OraxenMaterialParser.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,24 @@ | ||
package nl.aurorion.blockregen.system.material.parser; | ||
|
||
import io.th0rgal.oraxen.api.OraxenBlocks; | ||
import nl.aurorion.blockregen.BlockRegen; | ||
import nl.aurorion.blockregen.system.preset.struct.material.OraxenMaterial; | ||
import nl.aurorion.blockregen.system.preset.struct.material.TargetMaterial; | ||
|
||
public class OraxenMaterialParser implements MaterialParser { | ||
|
||
private final BlockRegen plugin; | ||
|
||
public OraxenMaterialParser(BlockRegen plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public TargetMaterial parseMaterial(String input) throws IllegalArgumentException { | ||
if (!OraxenBlocks.isOraxenBlock(input)) { | ||
throw new IllegalArgumentException(input + " is not an Oraxen block"); | ||
} | ||
|
||
return new OraxenMaterial(this.plugin, input); | ||
} | ||
} |
Oops, something went wrong.