v0.2.0
Added /invincible. Added up and down arguments to /excavate. Fixed inventory and performance issue with /excavate. Don't upload shell file for pushing jar.
This commit is contained in:
parent
298c49602e
commit
9bcfc1e0e6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target/
|
||||
/craftbukkit-1.13.2.jar
|
||||
/upload_jar.sh
|
||||
|
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.hyperling.minecraft</groupId>
|
||||
<artifactId>CoderDojoEVV</artifactId>
|
||||
<version>0.1.8-SNAPSHOT</version>
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
<name>Coder Dojo Test</name>
|
||||
<description>Test project written to learn how to do Minecraft plug-in for Coder Dojo.</description>
|
||||
|
||||
|
@ -14,33 +14,37 @@ public final class CoderDojoEVV extends JavaPlugin implements Listener {
|
||||
|
||||
DiamondItems di = new DiamondItems(this);
|
||||
getServer().getPluginManager().registerEvents(di, this);
|
||||
|
||||
Invincible i = new Invincible(this);
|
||||
getServer().getPluginManager().registerEvents(i, this);
|
||||
|
||||
super.onEnable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("onDisable has been accessed.");
|
||||
super.onDisable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
getLogger().info(player.getName() + " issued command with label " + label + ".");
|
||||
|
||||
switch (label) {
|
||||
switch (label.toLowerCase()) {
|
||||
case "heal":
|
||||
new Heal(this, player);
|
||||
break;
|
||||
case "excavate":
|
||||
int size;
|
||||
try {
|
||||
size = Integer.parseInt(args[0]);
|
||||
new Excavate(this, player, args);
|
||||
break;
|
||||
case "invincible":
|
||||
new Invincible(this, player, args);
|
||||
break;
|
||||
}
|
||||
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().");
|
||||
|
@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class DiamondItems implements Listener{
|
||||
public class DiamondItems implements Listener {
|
||||
final JavaPlugin plugin;
|
||||
|
||||
public DiamondItems (JavaPlugin plugin) {
|
||||
@ -26,7 +26,7 @@ public class DiamondItems implements Listener{
|
||||
|
||||
if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
|
||||
giveDiamondItems(inv);
|
||||
plugin.getServer().broadcastMessage(player.getDisplayName() + " was given back items.");
|
||||
player.sendMessage("Diamond items have been returned.");
|
||||
}
|
||||
plugin.getLogger().info("Finished onRespawn().");
|
||||
}
|
||||
@ -36,14 +36,14 @@ public class DiamondItems implements Listener{
|
||||
plugin.getLogger().info("Running onJoin.");
|
||||
Player player = event.getPlayer();
|
||||
|
||||
plugin.getServer().broadcastMessage("Welcome to the server, " + player.getDisplayName() + "!");
|
||||
player.sendMessage("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) {
|
||||
giveDiamondItems(inv);
|
||||
plugin.getServer().broadcastMessage("Enjoy your items!");
|
||||
player.sendMessage("Enjoy your items!");
|
||||
}
|
||||
else {
|
||||
inv.clear();
|
||||
|
10
src/main/java/com/hyperling/minecraft/coderdojoevv/Drop.java
Normal file
10
src/main/java/com/hyperling/minecraft/coderdojoevv/Drop.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.hyperling.minecraft.coderdojoevv;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Drop {
|
||||
public Drop (JavaPlugin plugin, Player player, String[] args) {
|
||||
|
||||
}
|
||||
}
|
@ -12,44 +12,96 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
// Remove all blocks around the player by the size they pass through
|
||||
// Arguments are a number and/or the values "up" or "down"
|
||||
public class Excavate {
|
||||
public Excavate(JavaPlugin plugin, Player player, int numBlocks) {
|
||||
plugin.getLogger().info("Gathering all blocks with radius of " + numBlocks + " from " + player.getName() + ".");
|
||||
final int maxBlocks = 128;
|
||||
|
||||
public Excavate(JavaPlugin plugin, Player player, String[] args) {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// Get the arguments
|
||||
int numBlocks = 0;
|
||||
int direction = 0;
|
||||
for (String arg : args) {
|
||||
try {
|
||||
numBlocks = Integer.parseInt(arg);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (numBlocks == 0) {
|
||||
plugin.getLogger().info("Failed to convert argument to size, defaulting to 8.");
|
||||
numBlocks = 8;
|
||||
}
|
||||
|
||||
switch (arg.toLowerCase()) {
|
||||
case "up":
|
||||
direction = 1;
|
||||
break;
|
||||
case "down":
|
||||
direction = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the number of blocks being excavated
|
||||
if (numBlocks < 0) {
|
||||
plugin.getLogger().info("Negative number was passed, not excavating.");
|
||||
return;
|
||||
}
|
||||
else if (numBlocks > maxBlocks) {
|
||||
plugin.getLogger().info("Maxumum allowed is currently "+maxBlocks);
|
||||
numBlocks = maxBlocks;
|
||||
}
|
||||
|
||||
plugin.getLogger().info("Gathering all blocks with cube size of " + numBlocks + " for " + player.getName() + ".");
|
||||
player.sendMessage("Excavating "+numBlocks+" by "+numBlocks+" cube...");
|
||||
|
||||
numBlocks /= 2;
|
||||
direction *= numBlocks;
|
||||
|
||||
plugin.getLogger().info("Direction="+direction+", numBlocks="+numBlocks+".");
|
||||
|
||||
Location l = player.getLocation();
|
||||
int x = l.getBlockX();
|
||||
int y = l.getBlockY();
|
||||
int y = l.getBlockY();// + 1; // Ensures player does not fall when using "up" argument.
|
||||
int z = l.getBlockZ();
|
||||
|
||||
plugin.getLogger().info("Player is at ("+x+","+y+","+z+").");
|
||||
|
||||
World w = l.getWorld();
|
||||
|
||||
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
||||
// 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 deltaY = y - numBlocks + direction; deltaY < y + numBlocks + direction; 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("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()));
|
||||
//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.");
|
||||
//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());
|
||||
ItemStack oldStack = new ItemStack(b.getType());
|
||||
ItemStack newStack = new ItemStack(b.getType());
|
||||
for (ItemStack item : items) {
|
||||
if (item.getType().name().equals(i.getType().name())) {
|
||||
i.setAmount(item.getAmount() + 1);
|
||||
//plugin.getLogger().info("Stack name is "+item.getType().name()+", block name is "+i.getType().name()+".");
|
||||
if (item.getType().name().equals(newStack.getType().name())) {
|
||||
oldStack = item;
|
||||
newStack.setAmount(item.getAmount() + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
items.add(i);
|
||||
plugin.getLogger().info("Added a "+b.getType().name()+", quantity is "+i.getAmount()+".");
|
||||
items.remove(oldStack);
|
||||
items.add(newStack);
|
||||
//plugin.getLogger().info("Added a "+b.getType().name()+", quantity is "+i.getAmount()+".");
|
||||
|
||||
// Remove the block
|
||||
b.setType(Material.AIR);
|
||||
@ -64,6 +116,9 @@ public class Excavate {
|
||||
plugin.getLogger().info("Adding "+item.getAmount()+" "+item.getType().name()+" to "+player.getName()+".");
|
||||
pi.addItem(item);
|
||||
}
|
||||
plugin.getLogger().info("Finished excavating.");
|
||||
|
||||
long deltaTime = System.currentTimeMillis() - startTime;
|
||||
plugin.getLogger().info("Finished excavating in "+deltaTime+"ms.");
|
||||
player.sendMessage("Excavation finished. It took "+deltaTime/1000+" seconds.");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
package com.hyperling.minecraft.coderdojoevv;
|
||||
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Invincible implements Listener{
|
||||
final JavaPlugin plugin;
|
||||
final String keyValue = "INVINCIBLE";
|
||||
|
||||
// Used when registering events.
|
||||
public Invincible (JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
// Set player's metadata for invincible trait.
|
||||
// Used in JavaPlugin class's onCommand()
|
||||
public Invincible (JavaPlugin plugin, Player player, String[] args) {
|
||||
this.plugin = plugin;
|
||||
boolean invincible;
|
||||
|
||||
// Get default toggle value
|
||||
try {
|
||||
invincible = !player.hasMetadata(keyValue);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().info("Getting metadata for "+keyValue+" returned "+e.getMessage());
|
||||
plugin.getLogger().info("Defaulting to true.");
|
||||
invincible = true;
|
||||
}
|
||||
|
||||
// Check for arguments
|
||||
for (String arg : args) {
|
||||
switch (arg.toLowerCase()) {
|
||||
case "on":
|
||||
invincible = true;
|
||||
break;
|
||||
case "off":
|
||||
invincible = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the metadata
|
||||
if (invincible) {
|
||||
player.setMetadata(keyValue, new FixedMetadataValue(plugin, invincible));
|
||||
plugin.getLogger().info("Player is now invincible.");
|
||||
player.sendMessage("You are now invincible.");
|
||||
}
|
||||
else {
|
||||
player.removeMetadata(keyValue, plugin);
|
||||
plugin.getLogger().info("Player is no longer invincible.");
|
||||
player.sendMessage("You are no longer invincible.");
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel damage done to invincible players.
|
||||
@EventHandler
|
||||
public void onDamage (EntityDamageEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Player player = (Player) e.getEntity();
|
||||
if (player.hasMetadata(keyValue)) {
|
||||
e.setCancelled(true);
|
||||
player.setFireTicks(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
name: CoderDojoEVV
|
||||
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
||||
version: 0.1.8
|
||||
version: 0.2.0
|
||||
|
||||
commands:
|
||||
heal:
|
||||
description: Heal hearts, food, and ends fire.
|
||||
excavate:
|
||||
description: Gather all items in X blocks and add them to inventory
|
||||
description: Gather all items in X blocks and add them to inventory.
|
||||
invincible:
|
||||
description: Prevents player from taking damage.
|
@ -1,9 +1,11 @@
|
||||
name: CoderDojoEVV
|
||||
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
||||
version: 0.1.8
|
||||
version: 0.2.0
|
||||
|
||||
commands:
|
||||
heal:
|
||||
description: Heal hearts, food, and ends fire.
|
||||
excavate:
|
||||
description: Gather all items in X blocks and add them to inventory
|
||||
description: Gather all items in X blocks and add them to inventory.
|
||||
invincible:
|
||||
description: Prevents player from taking damage.
|
@ -1,5 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Fri Dec 28 12:13:17 CST 2018
|
||||
version=0.1.7-SNAPSHOT
|
||||
#Sun Dec 30 10:33:53 CST 2018
|
||||
version=0.2.0-SNAPSHOT
|
||||
groupId=com.hyperling.minecraft
|
||||
artifactId=CoderDojoEVV
|
||||
|
@ -1,5 +1,7 @@
|
||||
/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/Drop.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/Invincible.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
|
||||
|
@ -1,3 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
ssh mc@192.168.1.65 rm -v Programs/minecraft/craftbukkit/plugins/*.jar
|
||||
|
||||
scp /home/ling/Programs/eclipse-workspace/CoderDojoEVV/target/*.jar mc@192.168.1.65:Programs/minecraft/craftbukkit/plugins
|
||||
scp_status=$?
|
||||
|
||||
if [[ $scp_status == 0 ]]; then
|
||||
rm -v /home/ling/Programs/eclipse-workspace/CoderDojoEVV/target/*.jar
|
||||
fi
|
||||
|
Reference in New Issue
Block a user