diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f56d839
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,37 @@
+# mac files
+.DS_Store
+
+# ignore vscode stuff
+.settings
+.settings/
+.project
+.idea/
+
+# ignore other java files
+bin/
+.classpath
+target/
+
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
\ No newline at end of file
diff --git a/BetterMinecraft.iml b/BetterMinecraft.iml
new file mode 100644
index 0000000..26ab7b0
--- /dev/null
+++ b/BetterMinecraft.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..4df35c9
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,89 @@
+
+
+
+ 4.0.0
+
+ de.steev
+ betterminecraft
+ 1.2
+
+ betterminecraft
+
+ http://www.example.com
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ org.spigotmc
+ spigot-api
+ 1.17-R0.1-SNAPSHOT
+ provided
+
+
+
+
+
+
+
+
+ maven-clean-plugin
+ 3.1.0
+
+
+
+ maven-resources-plugin
+ 3.0.2
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+
+ maven-surefire-plugin
+ 2.22.1
+
+
+ maven-jar-plugin
+ 3.0.2
+
+
+ maven-install-plugin
+ 2.5.2
+
+
+ maven-deploy-plugin
+ 2.8.2
+
+
+
+ maven-site-plugin
+ 3.7.1
+
+
+ maven-project-info-reports-plugin
+ 3.0.0
+
+
+
+
+
diff --git a/src/de/steev/bm/changes/interaction/Death.java b/src/de/steev/bm/changes/interaction/Death.java
new file mode 100644
index 0000000..68dd1a0
--- /dev/null
+++ b/src/de/steev/bm/changes/interaction/Death.java
@@ -0,0 +1,30 @@
+package de.steev.bm.changes.interaction;
+
+import de.steev.bm.main;
+import org.bukkit.Material;
+import org.bukkit.event.entity.EntityDeathEvent;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+public class Death {
+ /**
+ * handles animal loot drops only works as array
+ * @param amount the drop amount
+ * @param drops the dropping items
+ * @param plugin plugin reference
+ */
+ public void onAnimalDeath(int[] amount, Material[] drops, main plugin, EntityDeathEvent event){
+
+ // Random Drop amount generation DO NOT TOUCH!!!!
+ int i1_amnt = ThreadLocalRandom.current().nextInt(1, amount[0] + 1);
+ int i2_amnt = ThreadLocalRandom.current().nextInt(1, amount[1] + 1);
+
+ // Clears Vanilla drops
+ event.getDrops().clear();
+
+ // Drops specified amount of the specified items
+ for(int i = 0; i < i1_amnt; i++) { event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), new ItemStack(drops[0])); }
+ for(int i = 0; i < i2_amnt; i++) { event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), new ItemStack(drops[1])); }
+ }
+}
diff --git a/src/de/steev/bm/changes/interaction/Item_Recipy_Override.java b/src/de/steev/bm/changes/interaction/Item_Recipy_Override.java
index 3e3dc06..72cfe46 100644
--- a/src/de/steev/bm/changes/interaction/Item_Recipy_Override.java
+++ b/src/de/steev/bm/changes/interaction/Item_Recipy_Override.java
@@ -13,6 +13,13 @@ public class Item_Recipy_Override {
NamespacedKey item;
static ShapedRecipe rec_item;
+ /**
+ * Overrides vanilla recipes
+ * @param plugin Plugin Reference
+ * @param Item Item name
+ * @param result the dropping item
+ * @param amount the droprate
+ */
public Item_Recipy_Override(main plugin, String Item, Material result, int amount){
this.plugin = plugin;
item = new NamespacedKey(plugin, Item);
@@ -22,6 +29,12 @@ public class Item_Recipy_Override {
rec_item = new ShapedRecipe(item, itemStack);
}
+ /**
+ * registers recipe to bukkit recipe handler
+ * @param ing Ingredience reference
+ * @param mat material ing will reference
+ * @param rec the recipe shape
+ */
public static void register_recipy(char[] ing, Material[] mat, String[] rec){
//Recipe shapes
rec_item.shape(rec[0], rec[1], rec[2]);
diff --git a/src/de/steev/bm/changes/interaction/replanting.java b/src/de/steev/bm/changes/interaction/replanting.java
index dd1e851..5b75a78 100644
--- a/src/de/steev/bm/changes/interaction/replanting.java
+++ b/src/de/steev/bm/changes/interaction/replanting.java
@@ -5,93 +5,43 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
-import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.block.Action;
-import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
-import java.util.concurrent.ThreadLocalRandom;
-
-public class replanting implements Listener {
+public class replanting {
private main plugin;
+ /**
+ * event constructor
+ * @param plugin plugin instance
+ */
public replanting(main plugin) {
plugin.getLogger().info("replanting handler Registered");
this.plugin = plugin;
}
- // TODO: change planting to a single function that gets reused as the job plugin did
+ /**
+ * simplified function for handling replanting works only with arrays
+ * @param item the material of each drop
+ * @param amount the drop amount of each item
+ */
+ public static void planting(Material[] item, int[] amount, Block target){
+ Ageable crop = (Ageable) target.getBlockData();
+ Location loc = target.getLocation().clone().add(0.5, 0.5, 0.5);
- @EventHandler
- public void onPlayerInteract(PlayerInteractEvent event){
- if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
+ // TODO: validate if code may throw errors
- // Get needed values and states
- Block target = event.getClickedBlock();
- Location loc = target.getLocation().clone().add(0.5, 0.5, 0.5);
-
- System.out.println(target.getType());
-
- // Detects the right block and its required action
- if(target.getType() == Material.CARROTS){
- Ageable crop = (Ageable) target.getBlockData();
-
- if(crop.getAge() == crop.getMaximumAge()){
- for(int i = 0; i < 3; i++) {
- target.getLocation().getWorld().dropItem(loc, new ItemStack(Material.CARROT));
- }
- crop.setAge(0);
- target.setBlockData(crop);
- }
- } else if(target.getType() == Material.POTATOES){
- Ageable crop = (Ageable) target.getBlockData();
-
- if(crop.getAge() == crop.getMaximumAge()){
- if(crop.getAge() == crop.getMaximumAge()){
- int i1_amnt = ThreadLocalRandom.current().nextInt(1, 2 + 1);
-
- for(int i = 0; i < i1_amnt; i++) {
- target.getLocation().getWorld().dropItem(loc, new ItemStack(Material.POTATO));
- }
- crop.setAge(0);
- target.setBlockData(crop);
- }
- }
- } else if(target.getType() == Material.WHEAT){
- Ageable crop = (Ageable) target.getBlockData();
-
- if(crop.getAge() == crop.getMaximumAge()){
- if(crop.getAge() == crop.getMaximumAge()){
- int i1_amnt = ThreadLocalRandom.current().nextInt(1, 2 + 1);
-
- target.getLocation().getWorld().dropItem(loc, new ItemStack(Material.WHEAT));
- for(int i = 0; i < i1_amnt; i++) {
- target.getLocation().getWorld().dropItem(loc, new ItemStack(Material.WHEAT_SEEDS));
- }
- crop.setAge(0);
- target.setBlockData(crop);
- }
- }
- } else if(target.getType() == Material.BEETROOTS){
- Ageable crop = (Ageable) target.getBlockData();
-
- if(crop.getAge() == crop.getMaximumAge()){
- if(crop.getAge() == crop.getMaximumAge()){
- int i1_amnt = ThreadLocalRandom.current().nextInt(1, 3 + 1);
-
- target.getLocation().getWorld().dropItem(loc, new ItemStack(Material.BEETROOT));
- for(int i = 0; i < i1_amnt; i++) {
- target.getLocation().getWorld().dropItem(loc, new ItemStack(Material.BEETROOT_SEEDS));
- }
- crop.setAge(0);
- target.setBlockData(crop);
- }
- }
- } else {
- return;
+ if(crop.getAge() == crop.getMaximumAge()){
+ for(int i = 0; i < amount[0]; i++) {
+ target.getLocation().getWorld().dropItem(loc, new ItemStack(item[0]));
}
+
+ for(int i = 0; i < amount[1]; i++) {
+ target.getLocation().getWorld().dropItem(loc, new ItemStack(item[1]));
+ }
+ crop.setAge(0);
+ target.setBlockData(crop);
}
}
}
diff --git a/src/de/steev/bm/events/InteractEvent.java b/src/de/steev/bm/events/InteractEvent.java
index b609396..1bdb000 100644
--- a/src/de/steev/bm/events/InteractEvent.java
+++ b/src/de/steev/bm/events/InteractEvent.java
@@ -1,4 +1,48 @@
package de.steev.bm.events;
-public class InteractEvent {
+import de.steev.bm.main;
+import org.bukkit.Location;
+import org.bukkit.block.Block;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+
+public class InteractEvent implements Listener {
+
+ private main plugin;
+
+ public InteractEvent(main plugin){
+ this.plugin = plugin;
+ }
+
+ /**
+ * Carrot: Carrot 3
+ * Potato: potato 2
+ * Wheat: 2 Wheat, 2 Wheat Seeds
+ * Beetroots: 1 Beetroot, 3 Beetroot seeds
+ */
+ @EventHandler
+ public void onPlayerInteract(PlayerInteractEvent event){
+ if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
+
+ /** the clicked block */
+ Block target = event.getClickedBlock();
+ /** the location of the clicked block */
+ Location loc = target.getLocation().clone().add(0.5, 0.5, 0.5);
+
+ // Detects which type to replant
+ // TODO: do the replant implementation
+ switch(target.getType().toString()){
+ case "CARROT":
+ break;
+ case "POTATO":
+ break;
+ case "WHEAT":
+ break;
+ case "BEETROOT":
+ break;
+ }
+ }
+ }
}
diff --git a/src/de/steev/bm/events/KillEvent.java b/src/de/steev/bm/events/KillEvent.java
index c14f6e1..e759b59 100644
--- a/src/de/steev/bm/events/KillEvent.java
+++ b/src/de/steev/bm/events/KillEvent.java
@@ -22,6 +22,10 @@ public class KillEvent implements Listener{
this.plugin = plugin;
}
+ /**
+ * Implements drops on death and can handle other deaths
+ * @param event the parsed event on any death
+ */
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if(event.getEntity() instanceof Player){
@@ -29,25 +33,11 @@ public class KillEvent implements Listener{
UUID uuid = ((Player) event.getEntity()).getPlayer().getUniqueId();
plugin.playerDataConfig.set("" + uuid + ".death", death);
} else if(event.getEntity() instanceof Animals) {
+
+
if(event.getEntity().toString() == "CraftPig"){
-
- int i1_amnt = ThreadLocalRandom.current().nextInt(1, 2 + 1);
- int i2_amnt = ThreadLocalRandom.current().nextInt(1, 2 + 1);
-
- plugin.getLogger().info("Output amount: " + i1_amnt);
- plugin.getLogger().info("Output amount: " + i2_amnt);
-
- event.getDrops().clear();
-
- for(int i = 0; i < i1_amnt; i++) {
- event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), new ItemStack(Material.LEATHER));
- plugin.getLogger().info("Output Leather");
- }
-
- for(int i = 0; i < i2_amnt; i++) {
- event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), new ItemStack(Material.PORKCHOP));
- plugin.getLogger().info("Output Porkchop");
- }
+ // leather: 2, porkchop: 2
+ // TODO: do the implementation
}
}
}
diff --git a/src/de/steev/bm/main.java b/src/de/steev/bm/main.java
index f4986c5..0187324 100644
--- a/src/de/steev/bm/main.java
+++ b/src/de/steev/bm/main.java
@@ -1,9 +1,10 @@
package de.steev.bm;
import de.steev.bm.changes.interaction.Item_Recipy_Override;
-import de.steev.bm.changes.interaction.replanting;
import de.steev.bm.events.BedEvent;
+import de.steev.bm.events.InteractEvent;
import de.steev.bm.events.KillEvent;
+
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
@@ -40,7 +41,7 @@ public class main extends JavaPlugin implements Listener {
this.getLogger().info(ChatColor.AQUA + "Lade Events");
this.getServer().getPluginManager().registerEvents(new BedEvent(this), this);
this.getServer().getPluginManager().registerEvents(new KillEvent(this), this);
- this.getServer().getPluginManager().registerEvents(new replanting(this), this);
+ this.getServer().getPluginManager().registerEvents(new InteractEvent(this), this);
this.getServer().getPluginManager().registerEvents(this, this);
// PlayerData
diff --git a/workspace.code-workspace b/workspace.code-workspace
new file mode 100644
index 0000000..99aa626
--- /dev/null
+++ b/workspace.code-workspace
@@ -0,0 +1,14 @@
+{
+ "folders": [
+ {
+ "path": "."
+ }
+ ],
+ "settings": {
+ "files.autoGuessEncoding":true,
+ "files.encoding": "utf8",
+ "java.home": "C:\\Program Files\\Java\\jdk-16.0.1",
+ "java.jdt.ls.vmargs": "-Dfile.encoding=UTF-8",
+ "javac-linter.javac": "javac -Dfile.encoding=UTF-8"
+ }
+}
\ No newline at end of file