outsourced repeating code to own functions created javadoc
This commit is contained in:
parent
f5851e56e6
commit
57f000f6c5
37
.gitignore
vendored
Normal file
37
.gitignore
vendored
Normal file
@ -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*
|
13
BetterMinecraft.iml
Normal file
13
BetterMinecraft.iml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/bin" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="JavaSE-1.8" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Spigot 1.16.5" level="project" />
|
||||
</component>
|
||||
</module>
|
89
pom.xml
Normal file
89
pom.xml
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.steev</groupId>
|
||||
<artifactId>betterminecraft</artifactId>
|
||||
<version>1.2</version>
|
||||
|
||||
<name>betterminecraft</name>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<!-- This adds the Spigot Maven repository to the build -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
30
src/de/steev/bm/changes/interaction/Death.java
Normal file
30
src/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 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])); }
|
||||
}
|
||||
}
|
@ -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]);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
14
workspace.code-workspace
Normal file
14
workspace.code-workspace
Normal file
@ -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"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user