Hi, i have just started to code and i have just attempted an event. Here is my code so far: Code: package com.arkolly.events; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener { public void onEnable() { System.out.println("Events TEST has been ENABLED!!"); } @EventHandler public void eventsTest(PlayerMoveEvent moveEvent){ Player player = moveEvent.getPlayer(); if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.GRASS)) { ItemStack items = new ItemStack(org.bukkit.Material.IRON_CHESTPLATE); player.getInventory().addItem(items); } } } The listener is in the Main.java and the plugin.yml looks like this: Code: main: com.arkolly.events.Main name: Events version: 1.0 description: > Event Testing It loads up ok, but nothing happends when i move on stone? Thanks!
Phahaha sorry XD Thanks! lemme try and see if it works How do i make it so the user has to stand on the block for 5 seconds? Thanks! EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Thats it? Is this correct? : Code: @EventHandler public void eventsTest(PlayerMoveEvent moveEvent){ Player player = moveEvent.getPlayer(); if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.GRASS)) { Cancel PlayerMoveEvent(5); ItemStack items = new ItemStack(org.bukkit.Material.IRON_CHESTPLATE); player.getInventory().addItem(items); } }
Code:java HashMap<String, Long> move = new HashMap<String, Long>(); @EventHandler public void stop(PlayerMoveEvent e) { if (move.containsKey(e.getPlayer().getName())) { if (move.get(e.getPlayer().getName()) < System.currentTimeMillis() - 5*1000) { move.remove(e.getPlayer().getName()); } else { e.setCancelled(true); } } } if you want to freeze someone do: Code:java move.put(p.getName(), System.currentTimeMillis());
If you're just waiting to see if someone stands still for five seconds... Code:java @EventHandleronPlayerMove(PlayerMoveEvent event) { //Good stuff getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { //Are you still there? } }, 100L);} Wherein 100L is 20 ticks (one second) times 5, in data type long, and this is a JavaPlugin.