Add unblocking hack
This commit is contained in:
1 parent
c2073ff43b
commit
decc71effa
4 files changed
+167
No files matched your search
@@ -6,3 +6,4 @@
|
||||
.metadata
|
||||
.idea/
|
||||
*.iml
|
||||
logs
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.programmerdan.minecraft.simpleadminhacks.configs;
|
||||
|
||||
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHackConfig;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import vg.civcraft.mc.civmodcore.inventory.items.ItemUtils;
|
||||
import vg.civcraft.mc.civmodcore.inventory.items.MaterialUtils;
|
||||
|
||||
public class UnblockingHackConfig extends SimpleHackConfig {
|
||||
|
||||
private Map<Material, Material> ninePartsBlocks;
|
||||
private Map<Material, Material> fourPartsBlocks;
|
||||
private Map<Material, Material> nineItemsBlocks;
|
||||
private Map<Material, Material> fourItemsBlocks;
|
||||
|
||||
public UnblockingHackConfig(final SimpleAdminHacks plugin, final ConfigurationSection base) {
|
||||
super(plugin, base);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void wireup(final ConfigurationSection config) {
|
||||
parseUnblockConfigs(this.ninePartsBlocks = new Hashtable<>(), config, "9block");
|
||||
parseUnblockConfigs(this.fourPartsBlocks = new Hashtable<>(), config, "4block");
|
||||
parseUnblockConfigs(this.nineItemsBlocks = new Hashtable<>(), config, "9items");
|
||||
parseUnblockConfigs(this.fourItemsBlocks = new Hashtable<>(), config, "4items");
|
||||
}
|
||||
|
||||
private void parseUnblockConfigs(final Map<Material, Material> destination,
|
||||
final ConfigurationSection origin,
|
||||
final String type) {
|
||||
if (origin == null) {
|
||||
return;
|
||||
}
|
||||
final var config = origin.getConfigurationSection(type);
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
config.getValues(false).forEach((key, value) -> {
|
||||
final var fromMaterial = MaterialUtils.getMaterial(key);
|
||||
if (!ItemUtils.isValidItemMaterial(fromMaterial)) {
|
||||
plugin().warning("[UnblockingHackConfig] Could not find a valid item material from: " + key);
|
||||
return;
|
||||
}
|
||||
final var toMaterial = MaterialUtils.getMaterial("" + value);
|
||||
if (!ItemUtils.isValidItemMaterial(toMaterial)) {
|
||||
plugin().warning("[UnblockingHackConfig] Could not find a valid item material from: " + value);
|
||||
return;
|
||||
}
|
||||
destination.put(fromMaterial, toMaterial);
|
||||
plugin().info("[UnblockingHackConfig] Added " + type + ": "
|
||||
+ fromMaterial.name() + " -> " + toMaterial.name());
|
||||
});
|
||||
}
|
||||
|
||||
public Map<Material, Material> getNinePartsBlocks() {
|
||||
return this.ninePartsBlocks;
|
||||
}
|
||||
|
||||
public Map<Material, Material> getFourPartsBlocks() {
|
||||
return this.fourPartsBlocks;
|
||||
}
|
||||
|
||||
public Map<Material, Material> getNineItemsBlocks() {
|
||||
return this.nineItemsBlocks;
|
||||
}
|
||||
|
||||
public Map<Material, Material> getFourItemsBlocks() {
|
||||
return this.fourItemsBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.programmerdan.minecraft.simpleadminhacks.hacks;
|
||||
|
||||
import com.programmerdan.minecraft.simpleadminhacks.SimpleAdminHacks;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.configs.UnblockingHackConfig;
|
||||
import com.programmerdan.minecraft.simpleadminhacks.framework.SimpleHack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
import vg.civcraft.mc.civmodcore.inventory.RecipeManager;
|
||||
|
||||
public class UnblockingHack extends SimpleHack<UnblockingHackConfig> {
|
||||
|
||||
public UnblockingHack(final SimpleAdminHacks plugin, final UnblockingHackConfig config) {
|
||||
super(plugin, config);
|
||||
}
|
||||
|
||||
public static UnblockingHackConfig generate(final SimpleAdminHacks plugin, final ConfigurationSection config) {
|
||||
return new UnblockingHackConfig(plugin, config);
|
||||
}
|
||||
|
||||
private final List<Recipe> recipes = new ArrayList<>();
|
||||
private int recipeCounter = 0;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
// Blocks that turn into 9 parts
|
||||
config().getNinePartsBlocks().forEach((fromMaterial, toMaterial) -> {
|
||||
final var recipe = new ShapelessRecipe(
|
||||
new NamespacedKey(this.plugin, "unblocking_9part_" + (++this.recipeCounter)),
|
||||
new ItemStack(toMaterial, 9));
|
||||
recipe.addIngredient(fromMaterial);
|
||||
RecipeManager.registerRecipe(recipe);
|
||||
});
|
||||
// Blocks that turn into 4 parts
|
||||
config().getFourPartsBlocks().forEach((fromMaterial, toMaterial) -> {
|
||||
final var recipe = new ShapelessRecipe(
|
||||
new NamespacedKey(this.plugin, "unblocking_4part_" + (++this.recipeCounter)),
|
||||
new ItemStack(toMaterial, 4));
|
||||
recipe.addIngredient(fromMaterial);
|
||||
RecipeManager.registerRecipe(recipe);
|
||||
});
|
||||
// 9 items that turn into blocks
|
||||
config().getNineItemsBlocks().forEach((fromMaterial, toMaterial) -> {
|
||||
final var recipe = new ShapedRecipe(
|
||||
new NamespacedKey(this.plugin, "blocking_9item_" + (++this.recipeCounter)),
|
||||
new ItemStack(toMaterial));
|
||||
recipe.shape("xxx", "xxx", "xxx");
|
||||
recipe.setIngredient('x', fromMaterial);
|
||||
RecipeManager.registerRecipe(recipe);
|
||||
});
|
||||
// 4 items that turn into blocks
|
||||
config().getFourItemsBlocks().forEach((fromMaterial, toMaterial) -> {
|
||||
final var recipe = new ShapedRecipe(
|
||||
new NamespacedKey(this.plugin, "blocking_4item_" + (++this.recipeCounter)),
|
||||
new ItemStack(toMaterial));
|
||||
recipe.shape("xx", "xx");
|
||||
recipe.setIngredient('x', fromMaterial);
|
||||
RecipeManager.registerRecipe(recipe);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
this.recipes.forEach(RecipeManager::removeRecipe);
|
||||
this.recipes.clear();
|
||||
this.recipeCounter = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -403,3 +403,19 @@ hacks:
|
||||
ToggleLamp:
|
||||
enabled: false
|
||||
cooldownTime: 100
|
||||
UnblockingHack:
|
||||
enabled: true
|
||||
# Block materials that turn into 9 item materials
|
||||
# Example => NETHER_WART_BLOCK: NETHER_WART
|
||||
9block:
|
||||
NETHER_WART_BLOCK: NETHER_WART
|
||||
# Block materials that turn into 4 item materials
|
||||
# Example => CLAY: CLAY_BALL
|
||||
4block:
|
||||
CLAY: CLAY_BALL
|
||||
# Item materials, 9 of which combine into a block material
|
||||
# Example => NETHER_WART: NETHER_WART_BLOCK
|
||||
9items:
|
||||
# Item materials, 4 of which combine into a block material
|
||||
# Example => CLAY_BALL: CLAY
|
||||
4items:
|
||||
Reference in new issue
Block a user