Hello everyone, Im recently working on a class for my project. This class is called Thor and when wielding a WOOD_AXE and right clicking with it it will set lightning there. I need it to be delayed. I took a look into the Scheduler_Programming Docs and could not understand it. Here is my code: Code:Java @EventHandler public void onPlayerInteractBlock(PlayerInteractEvent evt){ if(evt.getPlayer().getItemInHand().getTypeId() == Material.WOOD_AXE.getId() && (evt.getAction() == Action.RIGHT_CLICK_BLOCK )){ //maximal distance between player and thunder is 200 blocks evt.getPlayer().getWorld().strikeLightning(evt.getPlayer().getTargetBlock(null, 200).getLocation()); } Also how would i make the block there looking at turn on fire? Thank you to anyone who can help me.
Something like: Code: @EventHandler public void onPlayerInteractBlock(final PlayerInteractEvent evt) { if (evt.getPlayer().getItemInHand().getTypeId() == Material.WOOD_AXE .getId() && (evt.getAction() == Action.RIGHT_CLICK_BLOCK)) { // maximal distance between player and thunder is 200 blocks int seconds = 3; Bukkit.getScheduler().scheduleSyncDelayedTask(null, new Runnable() { @Override public void run() { evt.getPlayer() .getWorld() .strikeLightning( evt.getPlayer().getTargetBlock(null, 200) .getLocation()); } }, seconds * 20); } } Ofcourse replace the null with your reference to the main class.
Ops didn't catch that bit my bad.. ive made a refrence but it says Code: public Kitpvp plugin; public MyDeathlistener (Kitpvp instance){ plugin = instance; } Bukkit.getScheduler().scheduleAsyncDelayedTask(Kitpvp, new Runnable() { Anyone help me please? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Is the statement: Bukkit.getScheduler().scheduleAsyncDelayedTask(Kitpvp, new Runnable() {... inside of a method? Otherwise you will have problems.
Yes,but i don't know how to refrence my Main class into the Listener class. I put this code into my class: Code: public class MyDeathlistener implements Listener{ public Kitpvp plugin; public MyDeathlistener (Kitpvp instance){ plugin = instance; } but it still doesn't Recognize Kitpvp. Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Java is CaSe-SeNsItIve, so check to make sure it was Kitpvp. Other then that, I don't see any other problem. Are you instancing it properly via new MyDeathlistener(Some Kitpvp class)?
Cirno What do you mean? "instancing it properly via new MyDeathlistener(Some Kitpvp class)" Please anyone help im trying to get this out there due date was Friday, but i wasn't expecting Update. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
two things dont confuse the type of a variable for the name of the variable. never use a async task for bukkit api methods (minor exceptions apply but if you don't know an exception just don't do it).
Are you doing: MyDeathlistener.somefunction(); or are you doing: MyDeathlistener listener; public void onEnable(){ listener = new Mydeathlistener(this); /register listener here and rest of stuff }
Cirno Im Registering the event, i don't have any of those lines above. Do they go in the main class or my listener?
Add this to your main class Outside the onEnable() function: Code:JAVA MyDeathlistener listener; Inside the onEnable() function: Code:JAVA listener = new MyDeathlistener(this);
Cirno Added them, Still the Kitpvp in: Code: Bukkit.getScheduler().scheduleAsyncDelayedTask(Kitpvp, new Runnable() { is not recognized error:
Is it CaSeD Kitpvp or is it KitPVP or kitPVP etc etc.? EDIT: it would help if you posted your entire source code.
Its just Kitpvp Main Class here: Code:Java package com.dyrocraft.kitpvp; import java.util.ArrayList;import java.util.HashMap;import java.util.logging.Logger;import com.dyrocraft.kitpvp.Soilderjump;import com.dyrocraft.kitpvp.Explosion;import com.dyrocraft.kitpvp.MyDeathlistener;import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Material;import org.bukkit.block.Block;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.enchantments.Enchantment;import org.bukkit.entity.Player;import org.bukkit.event.Listener;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.PlayerInventory;import org.bukkit.plugin.PluginManager;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.potion.PotionEffect;import org.bukkit.potion.PotionEffectType;import com.dyrocraft.kitpvp.Kitpvp; public class Kitpvp extends JavaPlugin implements Listener{final private static Enchantment power = Enchantment.ARROW_DAMAGE;final private static Enchantment firebow = Enchantment.ARROW_FIRE;final private static Enchantment knockbow = Enchantment.ARROW_KNOCKBACK;final private static Enchantment sharpness = Enchantment.DAMAGE_ALL;final private static Enchantment knockback = Enchantment.KNOCKBACK;final private static Enchantment fire = Enchantment.FIRE_ASPECT;public final Logger logger = Logger.getLogger("Minecraft");public static Kitpvp plugin;public final Explosion ex = new Explosion(null);public final MyDeathlistener dl = new MyDeathlistener(null);public final Soilderjump sj = new Soilderjump();public final HashMap<Player, ArrayList<Block>> hashmap = new HashMap<Player, ArrayList<Block>>();MyDeathlistener listener;@Overridepublic void onDisable() {this.logger.info("Disabled Kitpvp"); } @Overridepublic void onEnable() {this.logger.info("Enabled Kitpvp!");PluginManager pm = Bukkit.getPluginManager();listener = new MyDeathlistener(this);pm.registerEvents(ex,this);pm.registerEvents(dl,this);pm.registerEvents(sj,this); }public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){Player player = (Player) sender; Here is my Listener: Code:Java package com.dyrocraft.kitpvp; import org.bukkit.Bukkit;import org.bukkit.Material;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.entity.PlayerDeathEvent;import org.bukkit.event.player.PlayerInteractEvent;import com.dyrocraft.kitpvp.Kitpvp; public class MyDeathlistener implements Listener{public Kitpvp plugin;public MyDeathlistener (Kitpvp instance){plugin = instance;}public MyDeathlistener listener;@EventHandlerpublic void onPlayerDeathEvent(PlayerDeathEvent event) {event.getDrops().clear();} @EventHandlerpublic void onPlayerInteractBlock(final PlayerInteractEvent evt) {if (evt.getPlayer().getItemInHand().getTypeId() == Material.WOOD_AXE.getId() && (evt.getAction() == Action.RIGHT_CLICK_BLOCK)) {// maximal distance between player and thunder is 200 blocksint seconds = 3;Bukkit.getScheduler().scheduleAsyncDelayedTask(Kitpvp, new Runnable() {@Overridepublic void run() {evt.getPlayer().getWorld().strikeLightning(evt.getPlayer().getTargetBlock(null, 200).getLocation());}}, seconds * 20); }}}