v 0.1.6
Move code to classes.
This commit is contained in:
parent
b031d20ca7
commit
220df1269b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/target/
|
||||
/craftbukkit-1.13.2.jar
|
||||
|
@ -1,13 +1,15 @@
|
||||
# CoderDojoEVVMinecraftExample
|
||||
Project written to learn and demonstrate how to do Minecraft plugins for Coder Dojo in Evansville, Indiana.
|
||||
|
||||
pom.xml is a configuration file which automaticall downloads the .jar binaries of bukkit and spigot.
|
||||
Notes:
|
||||
pom.xml is a configuration file which automatically downloads the .jar binaries of bukkit and spigot.
|
||||
|
||||
Java code is locared in /src/main/java/com/hyperling/minecraft/coderdojotest/.
|
||||
Java code is located in /src/main/java/com/hyperling/minecraft/coderdojotest/.
|
||||
|
||||
Plugin exports are located in /target/.
|
||||
|
||||
|
||||
Link to setup and development tutorial:
|
||||
Link to development setup and coding tutorial:
|
||||
https://bukkit.gamepedia.com/Plugin_Tutorial
|
||||
|
||||
Guide on running a Minecraft server:
|
||||
|
Binary file not shown.
6
pom.xml
6
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.hyperling.minecraft</groupId>
|
||||
<artifactId>CoderDojoEVV</artifactId>
|
||||
<version>0.1.5-SNAPSHOT</version>
|
||||
<version>0.1.6-SNAPSHOT</version>
|
||||
<name>Coder Dojo Test</name>
|
||||
<description>Test project written to learn how to do Minecraft plug-in for Coder Dojo.</description>
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -1,17 +1,9 @@
|
||||
package com.hyperling.minecraft.coderdojoevv;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attributable;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class CoderDojoEVV extends JavaPlugin implements Listener {
|
||||
@ -19,7 +11,9 @@ public final class CoderDojoEVV extends JavaPlugin implements Listener {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("onEnable has been accessed.");
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
|
||||
DiamondItems di = new DiamondItems(this);
|
||||
getServer().getPluginManager().registerEvents(di, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,63 +21,6 @@ public final class CoderDojoEVV extends JavaPlugin implements Listener {
|
||||
getLogger().info("onDisable has been accessed.");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
getLogger().info("Running onJoin.");
|
||||
Player player = event.getPlayer();
|
||||
|
||||
getServer().broadcastMessage("Welcome to the server, " + player.getDisplayName() + "!");
|
||||
|
||||
final PlayerInventory inv = player.getInventory();
|
||||
|
||||
// Give diamond tools and food if not in creative
|
||||
if (getServer().getDefaultGameMode() != GameMode.CREATIVE) {
|
||||
getServer().broadcastMessage("Enjoy your items!");
|
||||
ItemStack item;
|
||||
item = new ItemStack(Material.DIAMOND_SWORD);
|
||||
inv.remove(Material.DIAMOND_SWORD);
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_AXE);
|
||||
inv.remove(Material.DIAMOND_AXE);
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_PICKAXE);
|
||||
inv.remove(Material.DIAMOND_PICKAXE);
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_SPADE);
|
||||
inv.remove(Material.DIAMOND_SPADE);
|
||||
/* For 1.13 API
|
||||
item = new ItemStack(Material.DIAMOND_SHOVEL);
|
||||
inv.remove(Material.DIAMOND_SHOVEL);
|
||||
*/
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_HOE);
|
||||
inv.remove(Material.DIAMOND_HOE);
|
||||
inv.addItem(item);
|
||||
|
||||
// Give food
|
||||
item = new ItemStack(Material.GOLDEN_APPLE);
|
||||
inv.remove(Material.GOLDEN_APPLE);
|
||||
item.setAmount(64);
|
||||
inv.addItem(item);
|
||||
|
||||
// These work
|
||||
item = new ItemStack(Material.DIAMOND_BOOTS);
|
||||
inv.setBoots(item);
|
||||
item = new ItemStack(Material.DIAMOND_LEGGINGS);
|
||||
inv.setLeggings(item);
|
||||
item = new ItemStack(Material.DIAMOND_CHESTPLATE);
|
||||
inv.setChestplate(item);
|
||||
item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
inv.setHelmet(item);
|
||||
}
|
||||
else {
|
||||
inv.clear();
|
||||
getServer().broadcastMessage("Inventory has been cleared for Creative mode.");
|
||||
}
|
||||
|
||||
getLogger().info("Finished onJoin().");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
@ -91,13 +28,7 @@ public final class CoderDojoEVV extends JavaPlugin implements Listener {
|
||||
getLogger().info(player.getName() + " issued command with label " + label + ".");
|
||||
|
||||
if (label.equals("heal")) {
|
||||
double health = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue();
|
||||
int food = (int) health;
|
||||
|
||||
player.setHealth(health);
|
||||
player.setFireTicks(0);
|
||||
player.setFoodLevel(food);
|
||||
getLogger().info(player.getName() + " has healed successfully.");
|
||||
new Heal(this, player);
|
||||
}
|
||||
|
||||
getLogger().info("Finished onCommand().");
|
||||
|
@ -0,0 +1,78 @@
|
||||
package com.hyperling.minecraft.coderdojoevv;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class DiamondItems implements Listener{
|
||||
final JavaPlugin plugin;
|
||||
|
||||
public DiamondItems (JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
plugin.getLogger().info("Running onJoin.");
|
||||
Player player = event.getPlayer();
|
||||
|
||||
plugin.getServer().broadcastMessage("Welcome to the server, " + player.getDisplayName() + "!");
|
||||
|
||||
final PlayerInventory inv = player.getInventory();
|
||||
|
||||
// Give diamond tools and food if not in creative
|
||||
if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
|
||||
plugin.getServer().broadcastMessage("Enjoy your items!");
|
||||
ItemStack item;
|
||||
item = new ItemStack(Material.DIAMOND_SWORD);
|
||||
inv.remove(Material.DIAMOND_SWORD);
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_AXE);
|
||||
inv.remove(Material.DIAMOND_AXE);
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_PICKAXE);
|
||||
inv.remove(Material.DIAMOND_PICKAXE);
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_SPADE);
|
||||
inv.remove(Material.DIAMOND_SPADE);
|
||||
/* For 1.13 API
|
||||
item = new ItemStack(Material.DIAMOND_SHOVEL);
|
||||
inv.remove(Material.DIAMOND_SHOVEL);
|
||||
*/
|
||||
inv.addItem(item);
|
||||
item = new ItemStack(Material.DIAMOND_HOE);
|
||||
inv.remove(Material.DIAMOND_HOE);
|
||||
inv.addItem(item);
|
||||
|
||||
// Give food
|
||||
item = new ItemStack(Material.GOLDEN_APPLE);
|
||||
inv.remove(Material.GOLDEN_APPLE);
|
||||
item.setAmount(64);
|
||||
inv.addItem(item);
|
||||
|
||||
// These work
|
||||
item = new ItemStack(Material.DIAMOND_BOOTS);
|
||||
inv.setBoots(item);
|
||||
item = new ItemStack(Material.DIAMOND_LEGGINGS);
|
||||
inv.setLeggings(item);
|
||||
item = new ItemStack(Material.DIAMOND_CHESTPLATE);
|
||||
inv.setChestplate(item);
|
||||
item = new ItemStack(Material.DIAMOND_HELMET);
|
||||
inv.setHelmet(item);
|
||||
}
|
||||
else {
|
||||
inv.clear();
|
||||
plugin.getServer().broadcastMessage("Inventory has been cleared for Creative mode.");
|
||||
}
|
||||
|
||||
plugin.getLogger().info("Finished onJoin().");
|
||||
}
|
||||
}
|
17
src/main/java/com/hyperling/minecraft/coderdojoevv/Heal.java
Normal file
17
src/main/java/com/hyperling/minecraft/coderdojoevv/Heal.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.hyperling.minecraft.coderdojoevv;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Heal {
|
||||
public Heal (JavaPlugin plugin, Player player) {
|
||||
double health = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue();
|
||||
int food = (int) health;
|
||||
|
||||
player.setHealth(health);
|
||||
player.setFireTicks(0);
|
||||
player.setFoodLevel(food);
|
||||
plugin.getLogger().info(player.getName() + " has healed successfully.");
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
name: CoderDojoEVV
|
||||
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
||||
version: 0.1.5
|
||||
version: 0.1.6
|
||||
|
||||
commands:
|
||||
heal:
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: CoderDojoEVV
|
||||
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
||||
version: 0.1.5
|
||||
version: 0.1.6
|
||||
|
||||
commands:
|
||||
heal:
|
||||
|
@ -1,5 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Fri Dec 28 11:14:14 CST 2018
|
||||
version=0.1.5-SNAPSHOT
|
||||
#Fri Dec 28 11:40:41 CST 2018
|
||||
version=0.1.6-SNAPSHOT
|
||||
groupId=com.hyperling.minecraft
|
||||
artifactId=CoderDojoEVV
|
||||
|
@ -1 +1,3 @@
|
||||
/home/ling/Programs/eclipse-workspace/CoderDojoEVV/src/main/java/com/hyperling/minecraft/coderdojoevv/DiamondItems.java
|
||||
/home/ling/Programs/eclipse-workspace/CoderDojoEVV/src/main/java/com/hyperling/minecraft/coderdojoevv/Heal.java
|
||||
/home/ling/Programs/eclipse-workspace/CoderDojoEVV/src/main/java/com/hyperling/minecraft/coderdojoevv/CoderDojoEVV.java
|
||||
|
Reference in New Issue
Block a user