From 220c7c7ff7df4584a0e724ab48f665c5c0a09835 Mon Sep 17 00:00:00 2001 From: steevLP Date: Tue, 3 Aug 2021 01:26:08 +0200 Subject: [PATCH] Implemented mechanics --- .../steev/bm/changes/interaction/Death.java | 2 +- src/de/steev/bm/events/InteractEvent.java | 31 ++++++++++++------- src/de/steev/bm/events/KillEvent.java | 11 ++++--- src/de/steev/bm/main.java | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/de/steev/bm/changes/interaction/Death.java b/src/de/steev/bm/changes/interaction/Death.java index 68dd1a0..80637c3 100644 --- a/src/de/steev/bm/changes/interaction/Death.java +++ b/src/de/steev/bm/changes/interaction/Death.java @@ -14,7 +14,7 @@ public class Death { * @param drops the dropping items * @param plugin plugin reference */ - public void onAnimalDeath(int[] amount, Material[] drops, main plugin, EntityDeathEvent event){ + public static 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); diff --git a/src/de/steev/bm/events/InteractEvent.java b/src/de/steev/bm/events/InteractEvent.java index 1bdb000..702fa7d 100644 --- a/src/de/steev/bm/events/InteractEvent.java +++ b/src/de/steev/bm/events/InteractEvent.java @@ -1,7 +1,9 @@ package de.steev.bm.events; +import de.steev.bm.changes.interaction.replanting; import de.steev.bm.main; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -16,12 +18,6 @@ public class InteractEvent implements Listener { 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)){ @@ -30,17 +26,30 @@ public class InteractEvent implements Listener { Block target = event.getClickedBlock(); /** the location of the clicked block */ Location loc = target.getLocation().clone().add(0.5, 0.5, 0.5); - + Material[] drops; + int[] amounts; // Detects which type to replant - // TODO: do the replant implementation switch(target.getType().toString()){ - case "CARROT": + case "CARROTS": + /** Droping items */ + drops = new Material[] { Material.CARROT }; + amounts = new int[] {3}; + replanting.planting(drops, amounts, target); break; - case "POTATO": + case "POTATOES": + drops = new Material[] { Material.POTATO }; + amounts = new int[] {2}; + replanting.planting(drops, amounts, target); break; case "WHEAT": + drops = new Material[] { Material.WHEAT, Material.WHEAT_SEEDS }; + amounts = new int[] {1,2}; + replanting.planting(drops, amounts, target); break; - case "BEETROOT": + case "BEETROOTS": + drops = new Material[] { Material.BEETROOT, Material.BEETROOT_SEEDS }; + amounts = new int[] {1,2}; + replanting.planting(drops, amounts, target); break; } } diff --git a/src/de/steev/bm/events/KillEvent.java b/src/de/steev/bm/events/KillEvent.java index e759b59..95c32d1 100644 --- a/src/de/steev/bm/events/KillEvent.java +++ b/src/de/steev/bm/events/KillEvent.java @@ -1,7 +1,6 @@ package de.steev.bm.events; import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Location; import org.bukkit.Material; @@ -10,9 +9,9 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.inventory.ItemStack; import de.steev.bm.main; +import de.steev.bm.changes.interaction.Death; public class KillEvent implements Listener{ private main plugin; @@ -28,6 +27,9 @@ public class KillEvent implements Listener{ */ @EventHandler public void onEntityDeath(EntityDeathEvent event) { + int[] amounts; + Material[] drops; + if(event.getEntity() instanceof Player){ Location death = ((Player) event.getEntity()).getPlayer().getLocation(); UUID uuid = ((Player) event.getEntity()).getPlayer().getUniqueId(); @@ -36,8 +38,9 @@ public class KillEvent implements Listener{ if(event.getEntity().toString() == "CraftPig"){ - // leather: 2, porkchop: 2 - // TODO: do the implementation + amounts = new int[]{ 2,2 }; + drops = new Material[]{Material.LEATHER, Material.PORKCHOP}; + Death.onAnimalDeath(amounts, drops, plugin, event); } } } diff --git a/src/de/steev/bm/main.java b/src/de/steev/bm/main.java index 0187324..d88018d 100644 --- a/src/de/steev/bm/main.java +++ b/src/de/steev/bm/main.java @@ -89,7 +89,7 @@ public class main extends JavaPlugin implements Listener { playerDataConfig.save(playerdata); } catch (IOException e) { this.getLogger().warning("Unable to save " + playerdatafilename); // shouldn't really happen, but save - // throws the exception + // throws the exception } }