mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 14:38:55 +00:00
feat: default crafting recipes
This commit is contained in:
1 parent
b5ffc96598
commit
43a8548d44
7 files changed
+148
-1
No files matched your search
@@ -9,6 +9,7 @@ import java.util.UUID;
|
||||
|
||||
import com.github.alathra.siegeengines.command.CommandHandler;
|
||||
import com.github.alathra.siegeengines.config.Config;
|
||||
import com.github.alathra.siegeengines.crafting.CraftingRecipes;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -19,6 +20,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.metadata.MetadataValueAdapter;
|
||||
|
||||
import com.github.alathra.siegeengines.listeners.ClickHandler;
|
||||
import com.github.alathra.siegeengines.listeners.CraftingHandler;
|
||||
import com.github.alathra.siegeengines.listeners.RotationHandler;
|
||||
import com.github.alathra.siegeengines.listeners.PlayerHandler;
|
||||
|
||||
@@ -58,6 +60,7 @@ public class SiegeEngines extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new CraftingHandler(), this);
|
||||
addDefaults();
|
||||
for (SiegeEngine i : definedSiegeEngines.values()) {
|
||||
System.out.println("§eEnabled Weapon : " + i.name);
|
||||
@@ -67,6 +70,9 @@ public class SiegeEngines extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
commandHandler.onEnable();
|
||||
if (Config.craftingRecipes) {
|
||||
CraftingRecipes.loadCraftingRecipes();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
||||
@@ -14,6 +14,7 @@ public class SiegeEnginesAPI {
|
||||
meta.setCustomModelData(122);
|
||||
meta.setDisplayName(Config.trebuchetItemName);
|
||||
meta.setLore(Config.ballistaItemLore);
|
||||
trebuchetItem.setItemMeta(meta);
|
||||
return trebuchetItem;
|
||||
}
|
||||
|
||||
@@ -23,6 +24,7 @@ public class SiegeEnginesAPI {
|
||||
meta.setCustomModelData(145);
|
||||
meta.setDisplayName(Config.ballistaItemName);
|
||||
meta.setLore(Config.ballistaItemLore);
|
||||
ballistaItem.setItemMeta(meta);
|
||||
return ballistaItem;
|
||||
}
|
||||
|
||||
@@ -32,6 +34,7 @@ public class SiegeEnginesAPI {
|
||||
meta.setCustomModelData(141);
|
||||
meta.setDisplayName(Config.swivelCannonItemName);
|
||||
meta.setLore(Config.swivelCannonItemLore);
|
||||
swivelCannonItem.setItemMeta(meta);
|
||||
return swivelCannonItem;
|
||||
}
|
||||
|
||||
@@ -41,6 +44,7 @@ public class SiegeEnginesAPI {
|
||||
meta.setCustomModelData(142);
|
||||
meta.setDisplayName(Config.breachCannonItemName);
|
||||
meta.setLore(Config.breachCannonItemLore);
|
||||
breachCannonItem.setItemMeta(meta);
|
||||
return breachCannonItem;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public class Config {
|
||||
public static int rotateDistance = 32;
|
||||
public static int maxSiegeEnginesControlled = 5;
|
||||
public static boolean autoReload = false;
|
||||
public static boolean craftingRecipes = true;
|
||||
|
||||
|
||||
public static HashSet<World> disabledWorlds = new HashSet<>();
|
||||
@@ -98,6 +99,7 @@ public class Config {
|
||||
rotateDistance = config.getInt("RotateDistance");
|
||||
maxSiegeEnginesControlled = config.getInt("MaxSiegeEnginesControlled");
|
||||
autoReload = config.getBoolean("AutoReload");
|
||||
craftingRecipes = config.getBoolean("CraftingRecipes");
|
||||
|
||||
loadProjectilesConfig();
|
||||
loadSiegeEngineConfig();
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.github.alathra.siegeengines.crafting;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
|
||||
import com.github.alathra.siegeengines.SiegeEngines;
|
||||
import com.github.alathra.siegeengines.api.SiegeEnginesAPI;
|
||||
|
||||
|
||||
public class CraftingRecipes {
|
||||
|
||||
public static Recipe trebuchetRecipe() {
|
||||
ItemStack trebuchet = SiegeEnginesAPI.getTrebuchetItem();
|
||||
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(),
|
||||
SiegeEngines.getInstance().getName() + "trebuchetRecipe");
|
||||
ShapedRecipe trebuchetRecipe = new ShapedRecipe(key, trebuchet);
|
||||
trebuchetRecipe.shape("$@$", "%#$", "@^@");
|
||||
trebuchetRecipe.setIngredient('@', Material.OAK_FENCE);
|
||||
trebuchetRecipe.setIngredient('%', Material.OAK_LOG);
|
||||
trebuchetRecipe.setIngredient('#', Material.OAK_TRAPDOOR);
|
||||
trebuchetRecipe.setIngredient('$', Material.STRING);
|
||||
trebuchetRecipe.setIngredient('^', Material.BOWL);
|
||||
SiegeEngines.getInstance().getServer().addRecipe(trebuchetRecipe);
|
||||
return trebuchetRecipe;
|
||||
}
|
||||
|
||||
public static Recipe ballistaRecipe() {
|
||||
ItemStack ballista = SiegeEnginesAPI.getBallistaItem();
|
||||
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(),
|
||||
SiegeEngines.getInstance().getName() + "ballistaRecipe");
|
||||
ShapedRecipe ballistaRecipe = new ShapedRecipe(key, ballista);
|
||||
ballistaRecipe.shape("@%%", "%# ", "% $");
|
||||
ballistaRecipe.setIngredient('@', Material.CROSSBOW);
|
||||
ballistaRecipe.setIngredient('%', Material.STICK);
|
||||
ballistaRecipe.setIngredient('#', Material.OAK_PLANKS);
|
||||
ballistaRecipe.setIngredient('$', Material.OAK_LOG);
|
||||
SiegeEngines.getInstance().getServer().addRecipe(ballistaRecipe);
|
||||
return ballistaRecipe;
|
||||
}
|
||||
|
||||
public static Recipe swivelCannonRecipe() {
|
||||
ItemStack swivelCannon = SiegeEnginesAPI.getSwivelCannonItem();
|
||||
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(),
|
||||
SiegeEngines.getInstance().getName() + "swivelCannonRecipe");
|
||||
ShapedRecipe swivelCannonRecipe = new ShapedRecipe(key, swivelCannon);
|
||||
swivelCannonRecipe.shape("@@@", "%%#", " $");
|
||||
swivelCannonRecipe.setIngredient('@', Material.IRON_INGOT);
|
||||
swivelCannonRecipe.setIngredient('%', Material.IRON_BLOCK);
|
||||
swivelCannonRecipe.setIngredient('#', Material.CAULDRON);
|
||||
swivelCannonRecipe.setIngredient('$', Material.ANVIL);
|
||||
SiegeEngines.getInstance().getServer().addRecipe(swivelCannonRecipe);
|
||||
return swivelCannonRecipe;
|
||||
}
|
||||
|
||||
public static Recipe breachCannonRecipe() {
|
||||
ItemStack breachCannon = SiegeEnginesAPI.getBreachCannonItem();
|
||||
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(),
|
||||
SiegeEngines.getInstance().getName() + "breachCannonRecipe");
|
||||
ShapedRecipe breachCannonRecipe = new ShapedRecipe(key, breachCannon);
|
||||
breachCannonRecipe.shape(" @#", "@%@", "$@ ");
|
||||
breachCannonRecipe.setIngredient('@', Material.IRON_INGOT);
|
||||
breachCannonRecipe.setIngredient('%', SiegeEnginesAPI.getSwivelCannonItem());
|
||||
breachCannonRecipe.setIngredient('#', Material.CAULDRON);
|
||||
breachCannonRecipe.setIngredient('$', Material.ANVIL);
|
||||
SiegeEngines.getInstance().getServer().addRecipe(breachCannonRecipe);
|
||||
return breachCannonRecipe;
|
||||
}
|
||||
|
||||
public static void loadCraftingRecipes() {
|
||||
trebuchetRecipe();
|
||||
ballistaRecipe();
|
||||
swivelCannonRecipe();
|
||||
breachCannonRecipe();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.github.alathra.siegeengines.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import com.github.alathra.siegeengines.config.Config;
|
||||
import com.github.alathra.siegeengines.crafting.CraftingRecipes;
|
||||
|
||||
public class CraftingHandler implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onCraft(CraftItemEvent event) {
|
||||
if (!Config.craftingRecipes) {
|
||||
return;
|
||||
}
|
||||
Recipe recipe = event.getRecipe();
|
||||
if (!(event.getView().getPlayer() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getView().getPlayer();
|
||||
if (recipe.equals(CraftingRecipes.trebuchetRecipe())) {
|
||||
if (!player.hasPermission("SiegeEngines.craft.trebuchet")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (recipe.equals(CraftingRecipes.ballistaRecipe())) {
|
||||
if (!player.hasPermission("SiegeEngines.craft.ballista")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (recipe.equals(CraftingRecipes.swivelCannonRecipe())) {
|
||||
if (!player.hasPermission("SiegeEngines.craft.swivel_cannon")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (recipe.equals(CraftingRecipes.breachCannonRecipe())) {
|
||||
if (!player.hasPermission("SiegeEngines.craft.breach_cannon")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user