Skip to content

Commit

Permalink
Merge pull request #40 from Wertik/3.11.0
Browse files Browse the repository at this point in the history
3.11.0
  • Loading branch information
Wertik authored Sep 16, 2024
2 parents 1d7e04a + 337c7b5 commit 637c9df
Show file tree
Hide file tree
Showing 28 changed files with 604 additions and 170 deletions.
4 changes: 2 additions & 2 deletions blockregen-ancient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.10.8</version>
<version>3.11.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-version</artifactId>
<version>3.10.8</version>
<version>3.11.0</version>
<scope>compile</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion blockregen-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.10.8</version>
<version>3.11.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions blockregen-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.10.8</version>
<version>3.11.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -14,7 +14,7 @@
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-version</artifactId>
<version>3.10.8</version>
<version>3.11.0</version>
<scope>compile</scope>
</dependency>

Expand Down
18 changes: 9 additions & 9 deletions blockregen-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BlockRegen</artifactId>
<groupId>nl.aurorion.blockregen</groupId>
<version>3.10.8</version>
<version>3.11.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -30,16 +30,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>8</source>
<target>8</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<version>3.6.0</version>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
Expand Down Expand Up @@ -116,25 +116,25 @@
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-common</artifactId>
<version>3.10.8</version>
<version>3.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-version</artifactId>
<version>3.10.8</version>
<version>3.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-legacy</artifactId>
<version>3.10.8</version>
<version>3.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.aurorion.blockregen</groupId>
<artifactId>blockregen-ancient</artifactId>
<version>3.10.8</version>
<version>3.11.0</version>
<scope>compile</scope>
</dependency>
<!-- Spigot API -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import nl.aurorion.blockregen.providers.JobsProvider;
import nl.aurorion.blockregen.system.GsonHelper;
import nl.aurorion.blockregen.system.event.EventManager;
import nl.aurorion.blockregen.system.material.MaterialManager;
import nl.aurorion.blockregen.system.material.parser.MMOItemsMaterialParser;
import nl.aurorion.blockregen.system.material.parser.MinecraftMaterialParser;
import nl.aurorion.blockregen.system.material.parser.OraxenMaterialParser;
import nl.aurorion.blockregen.system.preset.PresetManager;
import nl.aurorion.blockregen.system.regeneration.RegenerationManager;
import nl.aurorion.blockregen.system.region.RegionManager;
Expand Down Expand Up @@ -88,6 +92,9 @@ public static BlockRegen getInstance() {
@Getter
private EventManager eventManager;

@Getter
private MaterialManager materialManager;

@Getter
private GsonHelper gsonHelper;

Expand Down Expand Up @@ -170,9 +177,11 @@ public void onEnable() {
regenerationManager = new RegenerationManager(this);
regionManager = new RegionManager(this);
eventManager = new EventManager(this);
materialManager = new MaterialManager(this);

Message.load();

materialManager.registerParser(null, new MinecraftMaterialParser(this));
checkDependencies(false);

presetManager.loadAll();
Expand Down Expand Up @@ -208,8 +217,9 @@ public void onEnable() {
Bukkit.getScheduler().runTaskLater(this, () -> {
checkDependencies(true);

if (getConfig().getBoolean("Auto-Save.Enabled", false))
if (getConfig().getBoolean("Auto-Save.Enabled", false)) {
regenerationManager.startAutoSave();
}

regenerationManager.reattemptLoad();
regionManager.reattemptLoad();
Expand Down Expand Up @@ -274,6 +284,22 @@ public void checkDependencies(boolean reloadPresets) {
setupResidence();
setupGriefPrevention();
setupPlaceholderAPI();
setupMaterialParsers(reloadPresets);
}

private void setupMaterialParsers(boolean reloadPresets) {
if (getServer().getPluginManager().isPluginEnabled("Oraxen")) {
materialManager.registerParser("oraxen", new OraxenMaterialParser(this));
}

if (getServer().getPluginManager().isPluginEnabled("MMOItems")) {
materialManager.registerParser("mmoitems", new MMOItemsMaterialParser(this));
}

if (reloadPresets) {
log.info("Reloading presets to add material parsers requirements...");
this.presetManager.loadAll();
}
}

private void setupEconomy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package nl.aurorion.blockregen.api;

import com.cryptomorin.xseries.XMaterial;
import lombok.Getter;
import lombok.Setter;
import nl.aurorion.blockregen.system.preset.struct.material.TargetMaterial;
import nl.aurorion.blockregen.system.regeneration.struct.RegenerationProcess;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
Expand Down Expand Up @@ -46,11 +46,11 @@ public static HandlerList getHandlerList() {
* Shortcuts.
* */

public XMaterial getRegenerateInto() {
public TargetMaterial getRegenerateInto() {
return regenerationProcess.getRegenerateInto();
}

public void setRegenerateInto(XMaterial material) {
public void setRegenerateInto(TargetMaterial material) {
regenerationProcess.setRegenerateInto(material);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,8 @@ private void process(RegenerationProcess process, BlockPreset preset, BlockBreak
if (presetEvent.getItem() != null) {
ItemDrop eventDrop = presetEvent.getItem();

if (eventDrop != null) {
ItemStack eventStack = eventDrop.toItemStack(player);
giveItem(eventStack, player, block, eventDrop.isDropNaturally());
}
ItemStack eventStack = eventDrop.toItemStack(player);
giveItem(eventStack, player, block, eventDrop.isDropNaturally());
}

// Add items from presetEvent
Expand Down Expand Up @@ -363,7 +361,6 @@ private void process(RegenerationProcess process, BlockPreset preset, BlockBreak

// Particles
// -------------------------------------------------------------------------------------------
// TODO: Make particles work on 1.8 with it's effect API.
if (preset.getParticle() != null && plugin.getVersionManager().isCurrentAbove("1.8", false))
Bukkit.getScheduler().runTask(plugin,
() -> plugin.getParticleManager().displayParticle(preset.getParticle(), block));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PresetEvent {

@Getter
@Setter
@Nullable
private ItemDrop item;

@Getter
Expand Down
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]);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Loading

0 comments on commit 637c9df

Please sign in to comment.