added build automization
This commit is contained in:
16
src/main/java/de/steev/bm/Commands/back.java
Normal file
16
src/main/java/de/steev/bm/Commands/back.java
Normal file
@ -0,0 +1,16 @@
|
||||
package de.steev.bm.Commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class back implements CommandExecutor {
|
||||
// TODO save death coordinates in playerdata
|
||||
// TODO grab them
|
||||
// TODO ensure the position is safe
|
||||
// TODO teleport player back
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
return false;
|
||||
}
|
||||
}
|
22
src/main/java/de/steev/bm/changes/env/weather.java
vendored
Normal file
22
src/main/java/de/steev/bm/changes/env/weather.java
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
package de.steev.bm.changes.env;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
public class weather {
|
||||
|
||||
static long lastThunder = 0;
|
||||
long delay = 24000;
|
||||
private static boolean isThunder(World world) {
|
||||
return world.getThunderDuration() > 0;
|
||||
}
|
||||
|
||||
public static void changeWeather(World world) {
|
||||
if(isThunder(world)) {
|
||||
if(lastThunder + 24000 > world.getFullTime()) {
|
||||
world.setClearWeatherDuration(1000);
|
||||
}else {
|
||||
lastThunder = world.getFullTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
src/main/java/de/steev/bm/changes/interaction/Death.java
Normal file
30
src/main/java/de/steev/bm/changes/interaction/Death.java
Normal file
@ -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 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);
|
||||
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])); }
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package de.steev.bm.changes.interaction;
|
||||
|
||||
import de.steev.bm.main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
|
||||
public class Item_Recipy_Override {
|
||||
|
||||
main plugin;
|
||||
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);
|
||||
ItemStack itemStack = new ItemStack(result);
|
||||
itemStack.setAmount(amount);
|
||||
|
||||
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]);
|
||||
|
||||
for(int i = 0; i < ing.length; i++) {
|
||||
// Material Definitions
|
||||
rec_item.setIngredient(ing[i], mat[i]);
|
||||
}
|
||||
|
||||
// Add recipes to Server
|
||||
Bukkit.addRecipe(rec_item);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package de.steev.bm.changes.interaction;
|
||||
|
||||
import de.steev.bm.main;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
// TODO: validate if code may throw errors
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
src/main/java/de/steev/bm/main.java
Normal file
100
src/main/java/de/steev/bm/main.java
Normal file
@ -0,0 +1,100 @@
|
||||
package de.steev.bm;
|
||||
|
||||
import de.steev.bm.changes.interaction.Item_Recipy_Override;
|
||||
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;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class main extends JavaPlugin implements Listener {
|
||||
|
||||
// Global Variables that might come helpfull later
|
||||
public int playerInBed = 0;
|
||||
public World world;
|
||||
String version = "1.2";
|
||||
|
||||
// Custom Playerdata File
|
||||
public File playerdata;
|
||||
public FileConfiguration playerDataConfig;
|
||||
public final String playerdatafilename = "playerdata.yml";
|
||||
|
||||
// Handles initialisation
|
||||
public void onEnable() {
|
||||
// Messaging
|
||||
this.getLogger().info(ChatColor.AQUA + "Plugin Startet");
|
||||
|
||||
// Registers Events
|
||||
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 InteractEvent(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
// PlayerData
|
||||
playerdata = new File(this.getDataFolder(), playerdatafilename);
|
||||
playerDataConfig = YamlConfiguration.loadConfiguration(playerdata);
|
||||
saveplayerdata();
|
||||
|
||||
// More Messaging
|
||||
this.getLogger().info(ChatColor.AQUA + "Erstelle Rezepte");
|
||||
|
||||
Item_Recipy_Override Saddle = new Item_Recipy_Override(this, "Saddle", Material.SADDLE, 1);
|
||||
char[] s_ing = { 'L', 'S', 'I' };
|
||||
String[] s_rec = { "LLL", "LSL", " I " };
|
||||
Material[] s_mat = { Material.LEATHER, Material.STRING, Material.IRON_NUGGET };
|
||||
Saddle.register_recipy(s_ing, s_mat, s_rec);
|
||||
|
||||
Item_Recipy_Override Wool = new Item_Recipy_Override(this, "String", Material.STRING, 8);
|
||||
char[] w_ing = { 'W', 'F', };
|
||||
String[] w_rec = { " W ", "WFW", " W " };
|
||||
Material[] w_mat = { Material.WHITE_WOOL, Material.FLINT };
|
||||
Wool.register_recipy(w_ing, w_mat, w_rec);
|
||||
|
||||
// More Messaging
|
||||
this.getLogger().info(ChatColor.AQUA + "Ich bin Fertig :D");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerJoin(PlayerJoinEvent e) {
|
||||
Player p = (Player) e.getPlayer();
|
||||
UUID uuid = p.getUniqueId();
|
||||
// prevent this allways resetting the job count
|
||||
if (this.playerDataConfig.get(uuid + "." + version + ".read") == null) {
|
||||
p.sendMessage("================= Better Minecraft " + version + " =================");
|
||||
p.sendMessage("Command: /back eingefügt");
|
||||
p.sendMessage("=====================================================");
|
||||
|
||||
this.playerDataConfig.set(uuid + ".name", p.getName());
|
||||
this.playerDataConfig.set(uuid + "." + version + ".read", "true");
|
||||
saveplayerdata();
|
||||
}
|
||||
}
|
||||
|
||||
void saveplayerdata() {
|
||||
try {
|
||||
playerDataConfig.save(playerdata);
|
||||
} catch (IOException e) {
|
||||
this.getLogger().warning("Unable to save " + playerdatafilename); // shouldn't really happen, but save
|
||||
// throws the exception
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
// Even more Messaging
|
||||
this.getLogger().info(ChatColor.AQUA + "Ich geh dann mal :c");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user