Implemented mechanics

This commit is contained in:
steevLP 2021-08-03 01:26:08 +02:00
parent 5510a73c20
commit 220c7c7ff7
4 changed files with 29 additions and 17 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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
}
}