added build automization
This commit is contained in:
52
src/main/java/de/steev/bm/events/BedEvent.java
Normal file
52
src/main/java/de/steev/bm/events/BedEvent.java
Normal file
@ -0,0 +1,52 @@
|
||||
package de.steev.bm.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
||||
|
||||
import de.steev.bm.main;
|
||||
|
||||
public class BedEvent implements Listener {
|
||||
|
||||
private main plugin;
|
||||
|
||||
public BedEvent(main plugin) {
|
||||
plugin.getLogger().info("Bed events Registered");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler // Adding to the Player Variable
|
||||
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||
final World world = event.getPlayer().getWorld();
|
||||
if(world.getTime() >= 13000 || world.getThunderDuration() > 0) {
|
||||
plugin.playerInBed++;
|
||||
// Checks if enough Players (currentSleeping >= OnlinePlayerAmount/2) are Sleeping
|
||||
if(plugin.playerInBed >= (int)plugin.getServer().getOnlinePlayers().size()/2) {
|
||||
// Delayed Task for detecting useless entries
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(plugin.playerInBed >= (int)plugin.getServer().getOnlinePlayers().size()/2) {
|
||||
world.setTime(0);
|
||||
world.setWeatherDuration(7 * 24000);
|
||||
}
|
||||
}
|
||||
}, 20L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler // Subtracting to the Player Variable
|
||||
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
|
||||
// Subtraction from the PlayerInBed variable
|
||||
if(plugin.playerInBed > 0) {
|
||||
plugin.playerInBed--;
|
||||
// Failsafe to prevent integer underflow
|
||||
}else if(plugin.playerInBed > 0) {
|
||||
plugin.playerInBed = 0;
|
||||
}
|
||||
}
|
||||
}
|
57
src/main/java/de/steev/bm/events/InteractEvent.java
Normal file
57
src/main/java/de/steev/bm/events/InteractEvent.java
Normal file
@ -0,0 +1,57 @@
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
@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);
|
||||
Material[] drops;
|
||||
int[] amounts;
|
||||
// Detects which type to replant
|
||||
switch(target.getType().toString()){
|
||||
case "CARROTS":
|
||||
/** Droping items */
|
||||
drops = new Material[] { Material.CARROT };
|
||||
amounts = new int[] {3};
|
||||
replanting.planting(drops, amounts, target);
|
||||
break;
|
||||
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 "BEETROOTS":
|
||||
drops = new Material[] { Material.BEETROOT, Material.BEETROOT_SEEDS };
|
||||
amounts = new int[] {1,2};
|
||||
replanting.planting(drops, amounts, target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
47
src/main/java/de/steev/bm/events/KillEvent.java
Normal file
47
src/main/java/de/steev/bm/events/KillEvent.java
Normal file
@ -0,0 +1,47 @@
|
||||
package de.steev.bm.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
import de.steev.bm.main;
|
||||
import de.steev.bm.changes.interaction.Death;
|
||||
|
||||
public class KillEvent implements Listener{
|
||||
private main plugin;
|
||||
|
||||
public KillEvent(main plugin) {
|
||||
plugin.getLogger().info("Mob Death events Registered");
|
||||
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) {
|
||||
int[] amounts;
|
||||
Material[] drops;
|
||||
|
||||
if(event.getEntity() instanceof Player){
|
||||
Location death = ((Player) event.getEntity()).getPlayer().getLocation();
|
||||
UUID uuid = ((Player) event.getEntity()).getPlayer().getUniqueId();
|
||||
plugin.playerDataConfig.set("" + uuid + ".death", death);
|
||||
} else if(event.getEntity() instanceof Animals) {
|
||||
|
||||
|
||||
if(event.getEntity().toString() == "CraftPig"){
|
||||
amounts = new int[]{ 2,2 };
|
||||
drops = new Material[]{Material.LEATHER, Material.PORKCHOP};
|
||||
Death.onAnimalDeath(amounts, drops, plugin, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user