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/
|
/target/
|
||||||
/craftbukkit-1.13.2.jar
|
/craftbukkit-1.13.2.jar
|
||||||
|
/upload_jar.sh
|
||||||
|
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.hyperling.minecraft</groupId>
|
<groupId>com.hyperling.minecraft</groupId>
|
||||||
<artifactId>CoderDojoEVV</artifactId>
|
<artifactId>CoderDojoEVV</artifactId>
|
||||||
<version>0.1.8-SNAPSHOT</version>
|
<version>0.2.0-SNAPSHOT</version>
|
||||||
<name>Coder Dojo Test</name>
|
<name>Coder Dojo Test</name>
|
||||||
<description>Test project written to learn how to do Minecraft plug-in for Coder Dojo.</description>
|
<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);
|
DiamondItems di = new DiamondItems(this);
|
||||||
getServer().getPluginManager().registerEvents(di, this);
|
getServer().getPluginManager().registerEvents(di, this);
|
||||||
|
|
||||||
|
Invincible i = new Invincible(this);
|
||||||
|
getServer().getPluginManager().registerEvents(i, this);
|
||||||
|
|
||||||
|
super.onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().info("onDisable has been accessed.");
|
getLogger().info("onDisable has been accessed.");
|
||||||
|
super.onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
getLogger().info(player.getName() + " issued command with label " + label + ".");
|
getLogger().info(player.getName() + " issued command with label " + label + ".");
|
||||||
|
|
||||||
switch (label) {
|
switch (label.toLowerCase()) {
|
||||||
case "heal":
|
case "heal":
|
||||||
new Heal(this, player);
|
new Heal(this, player);
|
||||||
break;
|
break;
|
||||||
case "excavate":
|
case "excavate":
|
||||||
int size;
|
new Excavate(this, player, args);
|
||||||
try {
|
break;
|
||||||
size = Integer.parseInt(args[0]);
|
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().");
|
getLogger().info("Finished onCommand().");
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class DiamondItems implements Listener{
|
public class DiamondItems implements Listener {
|
||||||
final JavaPlugin plugin;
|
final JavaPlugin plugin;
|
||||||
|
|
||||||
public DiamondItems (JavaPlugin plugin) {
|
public DiamondItems (JavaPlugin plugin) {
|
||||||
@ -26,7 +26,7 @@ public class DiamondItems implements Listener{
|
|||||||
|
|
||||||
if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
|
if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
|
||||||
giveDiamondItems(inv);
|
giveDiamondItems(inv);
|
||||||
plugin.getServer().broadcastMessage(player.getDisplayName() + " was given back items.");
|
player.sendMessage("Diamond items have been returned.");
|
||||||
}
|
}
|
||||||
plugin.getLogger().info("Finished onRespawn().");
|
plugin.getLogger().info("Finished onRespawn().");
|
||||||
}
|
}
|
||||||
@ -36,14 +36,14 @@ public class DiamondItems implements Listener{
|
|||||||
plugin.getLogger().info("Running onJoin.");
|
plugin.getLogger().info("Running onJoin.");
|
||||||
Player player = event.getPlayer();
|
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();
|
final PlayerInventory inv = player.getInventory();
|
||||||
|
|
||||||
// Give diamond tools and food if not in creative
|
// Give diamond tools and food if not in creative
|
||||||
if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
|
if (plugin.getServer().getDefaultGameMode() != GameMode.CREATIVE) {
|
||||||
giveDiamondItems(inv);
|
giveDiamondItems(inv);
|
||||||
plugin.getServer().broadcastMessage("Enjoy your items!");
|
player.sendMessage("Enjoy your items!");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
inv.clear();
|
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;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
// Remove all blocks around the player by the size they pass through
|
// 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 class Excavate {
|
||||||
public Excavate(JavaPlugin plugin, Player player, int numBlocks) {
|
final int maxBlocks = 128;
|
||||||
plugin.getLogger().info("Gathering all blocks with radius of " + numBlocks + " from " + player.getName() + ".");
|
|
||||||
|
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();
|
Location l = player.getLocation();
|
||||||
int x = l.getBlockX();
|
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();
|
int z = l.getBlockZ();
|
||||||
|
|
||||||
|
plugin.getLogger().info("Player is at ("+x+","+y+","+z+").");
|
||||||
|
|
||||||
World w = l.getWorld();
|
World w = l.getWorld();
|
||||||
|
|
||||||
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
// Loop through all the blocks in the specified area around the user
|
// Loop through all the blocks in the specified area around the user
|
||||||
for (int deltaX = x - numBlocks; deltaX < x + numBlocks; deltaX++) {
|
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++) {
|
for (int deltaZ = z - numBlocks; deltaZ < z + numBlocks; deltaZ++) {
|
||||||
Block b = w.getBlockAt(deltaX, deltaY, 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 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 air: "+!b.getType().name().equals(Material.AIR.name()));
|
||||||
|
|
||||||
// Ignore bedrock and air
|
// Ignore bedrock and air
|
||||||
if (!b.getType().name().equals(Material.BEDROCK.name())
|
if (!b.getType().name().equals(Material.BEDROCK.name())
|
||||||
&& !b.getType().name().equals(Material.AIR.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
|
// 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) {
|
for (ItemStack item : items) {
|
||||||
if (item.getType().name().equals(i.getType().name())) {
|
//plugin.getLogger().info("Stack name is "+item.getType().name()+", block name is "+i.getType().name()+".");
|
||||||
i.setAmount(item.getAmount() + 1);
|
if (item.getType().name().equals(newStack.getType().name())) {
|
||||||
|
oldStack = item;
|
||||||
|
newStack.setAmount(item.getAmount() + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items.add(i);
|
items.remove(oldStack);
|
||||||
plugin.getLogger().info("Added a "+b.getType().name()+", quantity is "+i.getAmount()+".");
|
items.add(newStack);
|
||||||
|
//plugin.getLogger().info("Added a "+b.getType().name()+", quantity is "+i.getAmount()+".");
|
||||||
|
|
||||||
// Remove the block
|
// Remove the block
|
||||||
b.setType(Material.AIR);
|
b.setType(Material.AIR);
|
||||||
@ -64,6 +116,9 @@ public class Excavate {
|
|||||||
plugin.getLogger().info("Adding "+item.getAmount()+" "+item.getType().name()+" to "+player.getName()+".");
|
plugin.getLogger().info("Adding "+item.getAmount()+" "+item.getType().name()+" to "+player.getName()+".");
|
||||||
pi.addItem(item);
|
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
|
name: CoderDojoEVV
|
||||||
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
||||||
version: 0.1.8
|
version: 0.2.0
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
heal:
|
heal:
|
||||||
description: Heal hearts, food, and ends fire.
|
description: Heal hearts, food, and ends fire.
|
||||||
excavate:
|
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
|
name: CoderDojoEVV
|
||||||
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
main: com.hyperling.minecraft.coderdojoevv.CoderDojoEVV
|
||||||
version: 0.1.8
|
version: 0.2.0
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
heal:
|
heal:
|
||||||
description: Heal hearts, food, and ends fire.
|
description: Heal hearts, food, and ends fire.
|
||||||
excavate:
|
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
|
#Generated by Maven
|
||||||
#Fri Dec 28 12:13:17 CST 2018
|
#Sun Dec 30 10:33:53 CST 2018
|
||||||
version=0.1.7-SNAPSHOT
|
version=0.2.0-SNAPSHOT
|
||||||
groupId=com.hyperling.minecraft
|
groupId=com.hyperling.minecraft
|
||||||
artifactId=CoderDojoEVV
|
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/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/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/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/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/Heal.java
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/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 /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