diff --git a/pom.xml b/pom.xml index b60bf10..95668a5 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.hyperling.minecraft CoderDojoEVV - 0.1.7-SNAPSHOT + 0.1.8-SNAPSHOT Coder Dojo Test Test project written to learn how to do Minecraft plug-in for Coder Dojo. diff --git a/src/main/java/com/hyperling/minecraft/coderdojoevv/CoderDojoEVV.java b/src/main/java/com/hyperling/minecraft/coderdojoevv/CoderDojoEVV.java index 9aadd84..cd738a4 100644 --- a/src/main/java/com/hyperling/minecraft/coderdojoevv/CoderDojoEVV.java +++ b/src/main/java/com/hyperling/minecraft/coderdojoevv/CoderDojoEVV.java @@ -27,8 +27,20 @@ public final class CoderDojoEVV extends JavaPlugin implements Listener { getLogger().info(player.getName() + " issued command with label " + label + "."); - if (label.equals("heal")) { - new Heal(this, player); + switch (label) { + case "heal": + new Heal(this, player); + break; + case "excavate": + int size; + try { + size = Integer.parseInt(args[0]); + } + catch (Exception e) { + getLogger().info("Failed to convert argument to size, defaulting to 8."); + size = 8; + } + new Excavate(this, player, size); } getLogger().info("Finished onCommand()."); diff --git a/src/main/java/com/hyperling/minecraft/coderdojoevv/Excavate.java b/src/main/java/com/hyperling/minecraft/coderdojoevv/Excavate.java new file mode 100644 index 0000000..533d8ca --- /dev/null +++ b/src/main/java/com/hyperling/minecraft/coderdojoevv/Excavate.java @@ -0,0 +1,69 @@ +package com.hyperling.minecraft.coderdojoevv; + +import java.util.ArrayList; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.java.JavaPlugin; + +// Remove all blocks around the player by the size they pass through +public class Excavate { + public Excavate(JavaPlugin plugin, Player player, int numBlocks) { + plugin.getLogger().info("Gathering all blocks with radius of " + numBlocks + " from " + player.getName() + "."); + + Location l = player.getLocation(); + int x = l.getBlockX(); + int y = l.getBlockY(); + int z = l.getBlockZ(); + + World w = l.getWorld(); + + ArrayList items = new ArrayList(); + + // Loop through all the blocks in the specified area around the user + for (int deltaX = x - numBlocks; deltaX < x + numBlocks; deltaX++) { + for (int deltaY = y - numBlocks; deltaY < y + numBlocks; deltaY++) { + for (int deltaZ = z - numBlocks; deltaZ < z + numBlocks; deltaZ++) { + Block b = w.getBlockAt(deltaX, deltaY, deltaZ); + plugin.getLogger().info("Found "+b.getType().name()+" at ("+deltaX+","+deltaY+","+deltaZ+")."); + + plugin.getLogger().info("Block is not bedrock: "+!b.getType().name().equals(Material.BEDROCK.name())); + plugin.getLogger().info("Block is not air: "+!b.getType().name().equals(Material.AIR.name())); + + // Ignore bedrock and air + if (!b.getType().name().equals(Material.BEDROCK.name()) + && !b.getType().name().equals(Material.AIR.name())) { + plugin.getLogger().info("Adding "+b.getType().name()+" to array."); + + // Add 1 of the block to the array for adding to the user's inventory + ItemStack i = new ItemStack(b.getType()); + for (ItemStack item : items) { + if (item.getType().name().equals(i.getType().name())) { + i.setAmount(item.getAmount() + 1); + break; + } + } + items.add(i); + plugin.getLogger().info("Added a "+b.getType().name()+", quantity is "+i.getAmount()+"."); + + // Remove the block + b.setType(Material.AIR); + } + } + } + } + + // Put the items in the player's inventory + final PlayerInventory pi = player.getInventory(); + for (ItemStack item : items) { + plugin.getLogger().info("Adding "+item.getAmount()+" "+item.getType().name()+" to "+player.getName()+"."); + pi.addItem(item); + } + plugin.getLogger().info("Finished excavating."); + } +} diff --git a/src/main/java/com/hyperling/minecraft/coderdojoevv/Fireball.java b/src/main/java/com/hyperling/minecraft/coderdojoevv/Fireball.java new file mode 100644 index 0000000..ec34412 --- /dev/null +++ b/src/main/java/com/hyperling/minecraft/coderdojoevv/Fireball.java @@ -0,0 +1,6 @@ +package com.hyperling.minecraft.coderdojoevv; + +// Shoot fireball (ghast rocket?) out of redstone torch if used as a weapon +public class Fireball { + +} diff --git a/src/main/java/com/hyperling/minecraft/coderdojoevv/UFO.java b/src/main/java/com/hyperling/minecraft/coderdojoevv/UFO.java new file mode 100644 index 0000000..9eb067b --- /dev/null +++ b/src/main/java/com/hyperling/minecraft/coderdojoevv/UFO.java @@ -0,0 +1,5 @@ +package com.hyperling.minecraft.coderdojoevv; + +public class UFO { + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0d5e01a..c779393 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,9 @@ name: CoderDojoEVV main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV -version: 0.1.7 +version: 0.1.8 commands: heal: - description: Heal hearts, food, and ends fire. \ No newline at end of file + description: Heal hearts, food, and ends fire. + excavate: + description: Gather all items in X blocks and add them to inventory \ No newline at end of file diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index 0d5e01a..c779393 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,7 +1,9 @@ name: CoderDojoEVV main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV -version: 0.1.7 +version: 0.1.8 commands: heal: - description: Heal hearts, food, and ends fire. \ No newline at end of file + description: Heal hearts, food, and ends fire. + excavate: + description: Gather all items in X blocks and add them to inventory \ No newline at end of file diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index e6a88c1..0efd1d7 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,3 +1,6 @@ +/home/ling/Programs/eclipse-workspace/CoderDojoEVV/src/main/java/com/hyperling/minecraft/coderdojoevv/Fireball.java +/home/ling/Programs/eclipse-workspace/CoderDojoEVV/src/main/java/com/hyperling/minecraft/coderdojoevv/UFO.java /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/Excavate.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 diff --git a/upload_jar.sh b/upload_jar.sh new file mode 100755 index 0000000..2f4a8a8 --- /dev/null +++ b/upload_jar.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +scp /home/ling/Programs/eclipse-workspace/CoderDojoEVV/target/*.jar mc@192.168.1.65:Programs/minecraft/craftbukkit/plugins