summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-09-28 21:48:29 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-09-28 21:48:29 +0100
commit7678dabfb2d3550d51cf1514807885e6e7b37b20 (patch)
treee01f7bb0b12df0e533fcdd859fb702ede5f31297
parentbe838b99c1b108049d0027b7ee79dd06f1a5f05a (diff)
joe tires, sophie mines iron, two commands
-rw-r--r--src/main/java/com/yulqen/test/EventListening.java22
-rw-r--r--src/main/java/com/yulqen/test/GiveMeDiamond.java22
-rw-r--r--src/main/java/com/yulqen/test/KillZombies.java30
-rw-r--r--src/main/java/com/yulqen/test/Test.java7
-rw-r--r--src/main/resources/plugin.yml9
5 files changed, 88 insertions, 2 deletions
diff --git a/src/main/java/com/yulqen/test/EventListening.java b/src/main/java/com/yulqen/test/EventListening.java
index a26a1fc..c8c39e0 100644
--- a/src/main/java/com/yulqen/test/EventListening.java
+++ b/src/main/java/com/yulqen/test/EventListening.java
@@ -8,6 +8,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.PlayerJoinEvent;
@@ -33,6 +34,27 @@ public class EventListening implements Listener {
}
@EventHandler
+ public void sophieMinesIron(BlockBreakEvent e) {
+ Player player = e.getPlayer();
+ if (player.getName().equals("SophieLemLem")) {
+ if (e.getBlock().getType().equals(Material.IRON_ORE)) {
+ player.getInventory().addItem(new ItemStack(Material.IRON_INGOT, 8));
+ player.sendMessage("Sophie mines magic iron!");
+ }
+ }
+ }
+
+ @EventHandler
+ public void joeTiresWithCoalAndIron(BlockBreakEvent e) {
+ Player player = e.getPlayer();
+ if (player.getName().equals("_Joex")) {
+ if (e.getBlock().getType().equals(Material.IRON_ORE) || e.getBlock().getType().equals(Material.COAL_ORE)) {
+ player.setHealth(player.getHealth() / 1.2);
+ }
+ }
+ }
+
+ @EventHandler
public void chickenDefender(EntityDamageByEntityEvent e) {
Entity damager = e.getDamager();
if (damager instanceof Player && e.getEntity().getType().equals(EntityType.CHICKEN)) {
diff --git a/src/main/java/com/yulqen/test/GiveMeDiamond.java b/src/main/java/com/yulqen/test/GiveMeDiamond.java
new file mode 100644
index 0000000..359a531
--- /dev/null
+++ b/src/main/java/com/yulqen/test/GiveMeDiamond.java
@@ -0,0 +1,22 @@
+package com.yulqen.test;
+
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+public class GiveMeDiamond implements CommandExecutor {
+
+ @Override
+ public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
+ if (commandSender instanceof Player) {
+ Player player = (Player) commandSender;
+ ItemStack diamond = new ItemStack(Material.DIAMOND);
+ diamond.setAmount(64);
+ player.getInventory().addItem(diamond);
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/com/yulqen/test/KillZombies.java b/src/main/java/com/yulqen/test/KillZombies.java
new file mode 100644
index 0000000..beea25e
--- /dev/null
+++ b/src/main/java/com/yulqen/test/KillZombies.java
@@ -0,0 +1,30 @@
+package com.yulqen.test;
+
+import com.sun.source.tree.Tree;
+import org.bukkit.World;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Zombie;
+
+import java.util.Collection;
+
+import static org.bukkit.Bukkit.getServer;
+
+public class KillZombies implements CommandExecutor {
+ @Override
+ public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
+
+ World world = getServer().getWorld("mad_march_hare");
+ Collection<Entity> zombies = world.getEntitiesByClasses(Zombie.class);
+ for (Entity z : zombies) {
+ z.remove();
+ }
+ if (zombies.isEmpty()) {
+ return false;
+ }
+ System.out.println("Killed all the zombies...");
+ return true;
+ }
+}
diff --git a/src/main/java/com/yulqen/test/Test.java b/src/main/java/com/yulqen/test/Test.java
index 52fe7e0..ddca478 100644
--- a/src/main/java/com/yulqen/test/Test.java
+++ b/src/main/java/com/yulqen/test/Test.java
@@ -1,10 +1,11 @@
package com.yulqen.test;
-import org.bukkit.Location;
import org.bukkit.World;
-import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
+import java.util.List;
+
public final class Test extends JavaPlugin {
@Override
@@ -17,6 +18,8 @@ public final class Test extends JavaPlugin {
// }
getServer().getWorld("mad_march_hare").setFullTime(1000);
getServer().getPluginManager().registerEvents(new EventListening(), this);
+ this.getCommand("toss").setExecutor(new GiveMeDiamond());
+ this.getCommand("killzombies").setExecutor(new KillZombies());
}
@Override
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index e5ec849..6a97cbf 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,3 +2,12 @@ name: ChickenDefender
version: ${project.version}
main: com.yulqen.test.Test
api-version: 1.16
+commands:
+ toss:
+ description: Give me 64 diamonds
+ useage: /diamonds
+ permission: chickendefender.enablediamonds
+ killzombies:
+ description: Kills all zombies
+ useage: /killzombies
+ permission: chickendefender.killzombies