Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffa50 committed Jan 5, 2020
1 parent ef3cad7 commit 4420154
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.idea
/target
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>aldrigos.mc</groupId>
<artifactId>CraftPlus</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
2 changes: 2 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

38 changes: 38 additions & 0 deletions src/main/java/aldrigos/mc/craftplus/CraftPlusPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package aldrigos.mc.craftplus;

import aldrigos.mc.craftplus.listeners.ShovelListener;
import org.bukkit.inventory.Recipe;
import org.bukkit.plugin.java.JavaPlugin;

public class CraftPlusPlugin extends JavaPlugin {
private void addRecipes(Recipe... recipes){
for(var r: recipes)
getServer().addRecipe(r);

getServer().getLogger().info("[Craft+]Added "+recipes.length+" recipes");
}

@Override
public void onEnable(){
var recipes = new Recipes(this);
addRecipes(
recipes.getTrident(),
recipes.getSaddle(),
recipes.getElytra(),
recipes.getBell(),
recipes.getNameTag(),
recipes.getIronHorseArmor(),
recipes.getGoldHorseArmor(),
recipes.getDiamondHorseArmor(),
recipes.getQuartz(),
recipes.getTotem()
);

getServer().getPluginManager().registerEvents(new ShovelListener(), this);
}

@Override
public void onDisable(){
getServer().getLogger().info("[Craft+]Disabled");
}
}
169 changes: 169 additions & 0 deletions src/main/java/aldrigos/mc/craftplus/Recipes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package aldrigos.mc.craftplus;

import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Item;
import org.bukkit.inventory.*;
import org.bukkit.plugin.Plugin;

public class Recipes {
private final Plugin p;

public Recipes(Plugin plugin){
p = plugin;
}

public Recipe getSaddle(){
var r = new ShapedRecipe(
new NamespacedKey(p, "saddle"),
new ItemStack(Material.SADDLE)
);

r.shape("lll",
"tst");
r.setIngredient('l', Material.LEATHER);
r.setIngredient('s', Material.LEAD);
r.setIngredient('t', Material.TRIPWIRE_HOOK);

return r;
}

public Recipe getBell(){
var r = new ShapedRecipe(
new NamespacedKey(p, "bell"),
new ItemStack(Material.BELL)
);

r.shape("www",
"lgl",
"l l");
r.setIngredient('w', Material.STICK);
r.setIngredient('l', Material.COBBLESTONE_WALL);
r.setIngredient('g', Material.GOLD_BLOCK);

return r;
}

public Recipe getElytra(){
var r = new ShapedRecipe(
new NamespacedKey(p, "eytra"),
new ItemStack(Material.ELYTRA)
);

r.shape("ppp",
"psp",
"p p");

r.setIngredient('p', Material.PHANTOM_MEMBRANE);
r.setIngredient('w', Material.STRING);

return r;
}

public Recipe getTrident(){
var r = new ShapedRecipe(
new NamespacedKey(p, "trident"),
new ItemStack(Material.TRIDENT)
);

r.shape("iii",
" d ",
" d ");
r.setIngredient('i', Material.IRON_INGOT);
r.setIngredient('d', Material.DIAMOND);

return r;
}

public Recipe getNameTag(){
var r = new ShapelessRecipe(
new NamespacedKey(p, "nametag"),
new ItemStack(Material.NAME_TAG)
);

r.addIngredient(Material.PAPER);
r.addIngredient(2, Material.STRING);

return r;
}

public Recipe getIronHorseArmor(){
var r = new ShapedRecipe(
new NamespacedKey(p, "ironhorsearmor"),
new ItemStack(Material.IRON_HORSE_ARMOR)
);

r.shape("i i",
"ili",
"i i");

r.setIngredient('i', Material.IRON_INGOT);
r.setIngredient('l', Material.LEATHER);

return r;
}

public Recipe getGoldHorseArmor(){
var r = new ShapedRecipe(
new NamespacedKey(p, "goldhorsearmor"),
new ItemStack(Material.IRON_HORSE_ARMOR)
);

r.shape("i i",
"ili",
"i i");

r.setIngredient('i', Material.GOLD_INGOT);
r.setIngredient('l', Material.LEATHER);

return r;
}

public Recipe getDiamondHorseArmor(){
var r = new ShapedRecipe(
new NamespacedKey(p, "diamondhorsearmor"),
new ItemStack(Material.IRON_HORSE_ARMOR)
);

r.shape("i i",
"ili",
"i i");

r.setIngredient('i', Material.DIAMOND);
r.setIngredient('l', Material.LEATHER);

return r;
}

public Recipe getQuartz(){
var r = new ShapelessRecipe(
new NamespacedKey(p, "quartz"),
new ItemStack(Material.QUARTZ, 4)
);

r.addIngredient(
new RecipeChoice.MaterialChoice(
Material.QUARTZ_BLOCK,
Material.CHISELED_QUARTZ_BLOCK,
Material.SMOOTH_QUARTZ,
Material.QUARTZ_PILLAR));

return r;
}

public Recipe getTotem(){
var r = new ShapedRecipe(
new NamespacedKey(p, "totem"),
new ItemStack(Material.TOTEM_OF_UNDYING)
);

r.shape(" h ",
"geg",
" g ");
r.setIngredient('h', Material.GOLDEN_HELMET);
r.setIngredient('e', Material.EMERALD);
r.setIngredient('g', Material.GOLD_INGOT);

return r;
}
}
29 changes: 29 additions & 0 deletions src/main/java/aldrigos/mc/craftplus/listeners/ShovelListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package aldrigos.mc.craftplus.listeners;

import org.bukkit.Material;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ShovelListener implements Listener {
private final static List<Material> shovels = new ArrayList<>( Arrays.asList
(Material.STONE_SHOVEL, Material.WOODEN_SHOVEL, Material.IRON_SHOVEL, Material.GOLDEN_SHOVEL, Material.DIAMOND_SHOVEL));

@EventHandler
public void onShovel(PlayerInteractEvent e){
var item = e.getPlayer().getInventory().getItemInMainHand();

switch(e.getAction()){
case RIGHT_CLICK_BLOCK:
if(e.getClickedBlock().getType() != Material.GRASS_BLOCK
|| item == null || !shovels.contains(item.getType()))
return;

e.getClickedBlock().setType(Material.GRASS_PATH);
item.setDurability((short)(item.getDurability() -1));
}
}
}
9 changes: 9 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
main: aldrigos.mc.craftplus.CraftPlusPlugin
name: CraftPlus
version: '0.1.0.0'
description: A test plugin
load: POSTWORLD
author: Aldrigo Raffaele
website: spigotmc.org
prefix: Craft+
api-version: 1.14

0 comments on commit 4420154

Please sign in to comment.