Need help: event error

Discussion in 'Plugin Development' started by andy9330, Aug 4, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    andy9330

    Eclipse gives me an error in the code saying event "could not be resolved".
    Here is the code:
    codeprob1.png

    EDIT: FIXED! I created a new listener for players and put the getPlayer in there and imported the org.bukkit.entity.player and it worked! all done...now i just need the event for nether portal entry
     
  2. Offline

    nisovin

    This would be because you don't have any variable named "event" here. Have you read the tutorials? Watched the tutorial videos? You're clearly just throwing code around here hoping it will magically work.
     
  3. Offline

    andy9330

    i have read the tuts...i guess i should watch the vids next
    and that is the only error in my code, otherwise i'm set.
    last thing i need is the event for player entering nether portal

    still nothing
    if i capitalize event it fixes that problem but makes getPlayer() red

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  4. Offline

    escape

    That's because you're now calling a non-static method on an abstract class. Other than walking you though it, I would suggest looking at some basic java tutorials first.
     
  5. Offline

    OblivionFan

    From what i get from your code,when your plugin is enabled,it automatically says "Activating skylands world" (in the server log) and tries to get a player (what player?) from an event (what event)...

    What you need here is a listener class,which triggers when someone enters a portal with a feather...i suggest this tutorial:
    http://wiki.bukkit.org/HUGE_Plugin_Tutorial

    LE : Well,first of all,the hole "event" thing is supposed to be in the listener class,lol :D
    That's because you have no event in the main class,that one gets triggered every time you open the server,it's the listener class that only triggers when an event is detected...
     
  6. Offline

    nisovin

    I hope you understand our problem here. It's not that we don't want to help you. It's just that, judging by the code you've written, you obviously have no idea what you're doing. So, that leaves us with two options:
    1. Point you to some tutorials so you can learn
    2. Write the plugin for you
    Obviously the first option is better for everyone. So, I suggest you look at these two tutorials at least.
    http://wiki.bukkit.org/HUGE_Plugin_Tutorial
    http://www.youtube.com/dinnerbone
    Note that adam's tutorial also has some links to some Java tutorials. You'll probably want to look at some of those as well.
     
  7. Offline

    andy9330

  8. Offline

    OblivionFan

    Alright,i'll try to help you:
    First of all,delete the onCommand part,it's useless now...

    Then,you need to modify
    pm.registerEvent(Event.Type.ENTITY_DAMAGE, new Listener(this), Priority.Normal, this);

    You need to change the type from entity_damage to something else,not sure what...i think PLAYER_TELEPORT,but i can't be sure...
    After that,you need to go inside the listener,and modify it to teleport you to the skylands,instead of the nether...and i have absolutely no idea how to do that!
    My suggestion is to check if the player has a feather in his hand...if he has one,cancel the event(the teleportation to the nether),and teleport him to the aether instead!

     
  9. Offline

    andy9330

    thanks for the bit of help
     
  10. Offline

    OblivionFan

    Well,since you thanked me,i'll give you another tip,lol...when you start typing "Type.",if you pause for a second there,it will show you all of the possible events! The event you're looking for is under Player,since players enter portals...now,if you look,you'll see something obvious: PLAYER_PORTAL!
    Just add that...
    Now,for the listener class...
    What i just found out (and what isn't written ANYWHERE i looked,despite being really helpfull,is that after you finish your first class (which is something basic, it can even be empty!),you right click the empty space,select source,and then "Override/Implement Methods"

    This will give you a list,in this list you will need to find the right event,in your case OnPlayerPortal!
    You just double-click that,and voala,you have your overriding method!
    Override means that instead of what happens normally,this pugin will execute! (i think,lol,i'm still a newbie at java)
    So,just add your triggers there (yes,event is included,you don't need to make it again :p),and you're DONE!
    Now,i expect a HUGE thank you!
    Btw,i wrote all that cuz i'm extremely happy for my plugin,which is FINALLY WORKING!
     
  11. @Override is just an Eclipse annotation and can even be left out. It just shows that you override a method of your parent class.
     
  12. Offline

    andy9330

    @OblivionFan
    THANKYOU!!!
    The only thing i need now is to figure out how to implement "getServer().getWorld("world_skylands");" in the PlayerListener class. then it'll be done!!!

    btw, could i have a download link to your plugin? i'd like to check it out!

    HAHA YES!!! The plugin is finally finished!!!
    I will submit it in a bit and post a link here!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  13. Offline

    Tster

    I am happy you have learnt, may the force be with you, :D, but as a future notice if you want to become a big developer, don't re invent the wheel, if you are making it different, I dont mind, but below is a quote saying if its the same just help the original
    Quote (open)



    I dont really care if you've re invented a plugin, you've learnt and thats all that matters(well, mostly all), If it is different, please release it, I havent played skylands yet!

    Now, released yet? :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
    andy9330 likes this.
  14. Offline

    andy9330

    I'll do some tweaking and fixing here and there but it should be ready to release today...(hopefully)

    BACKSTORY TIME!!!1!
    It was a long time ago, in a website far away. I found a single player mod that allowed access to the sky dimension through a nether portal if the user had a feather in hand. I thought it would be cool to have it on my server...thus began work.

    And, if minecraft would load, i would test it and then release it
     
  15. Offline

    Tster

    complete agreement, I like seeing new developers :p
     
  16. Offline

    andy9330

    needs more work...still teleports to nether
     
  17. Offline

    Tster

    Post some source an I'll help :D
     
  18. Offline

    andy9330

    should i put it on github?
     
  19. Offline

    Tster

    Yeh, But i be honest git hub is a bloody thing for beginers
     
  20. Offline

    andy9330

    i have GIT installed and i'm going to finish setting it up...then i'll send you a link

    alright...i can't get files to add to GitHub

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  21. Offline

    Tster

    Just send me the source in a code tag,
     
  22. Offline

    andy9330

    alright:

    SimpleSkylands.java:
    Code:
    package me.desmin88.simpleskylands;
    
    import java.io.File;
    
    import org.bukkit.World;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event;
    import org.bukkit.event.player.PlayerListener;
    public class SimpleSkylands extends JavaPlugin {
    	boolean voidteleport = false;
    	private PlayerListener playerListener = new skylandsPlayerListener();
    
    	@Override
    	public void onDisable() {
    		System.out.println("SimpleSkylands: Disabled");
    	}
    
    	@Override
    
    	public void onEnable() {
    		if(new File(this.getDataFolder(), "config.yml").exists()) {
    			voidteleport = true;
    			PluginManager pm = getServer().getPluginManager();
    			pm.registerEvent(Event.Type.ENTITY_DAMAGE, new Listener(this), Priority.Normal, this);
    		}
    
    		System.out.println("Activating skylands world");
    		getServer().createWorld("world_skylands",World.Environment.SKYLANDS);
    	}
    	}
    
    skylandsPlayerListener.java:
    Code:
    package me.desmin88.simpleskylands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Chunk;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerPortalEvent;
    
    public class skylandsPlayerListener extends PlayerListener {
        public void onPlayerPortal(PlayerPortalEvent event) {
            Player player = event.getPlayer();
    		if(player.getItemInHand().getType() == Material.FEATHER) {
    			World w  = Bukkit.getServer().getWorld("world_skylands");
    			Location sloc = w.getSpawnLocation();
    			Chunk c = w.getChunkAt(sloc);
    			w.loadChunk(c);
    			player.teleport(sloc);
    		}
        }
    }
    
    Listener.java:
    Code:
    package me.desmin88.simpleskylands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityListener;
    
    public class Listener extends EntityListener{
    	public SimpleSkylands plugin;
    	public Listener(SimpleSkylands instance){
    		plugin = instance;
    	}
    	@Override
    	public void onEntityDamage(EntityDamageEvent event) {
    		if(event.getEntity() instanceof Player) {
    			Player p = (Player) event.getEntity();
    			if(p.getWorld().getName().equalsIgnoreCase("world_skylands") && event.getCause() ==  EntityDamageEvent.DamageCause.VOID && plugin.voidteleport) {
    				p.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
    			}
    		}
    	}
    }
    
    All the main code is in the skylandsPlayerListener.java

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  23. Offline

    Tster

    Aha, I see, your trying to do it within a portal try replacing:
    if(player.getItemInHand().getType() == Material.FEATHER) {
    withh
    if(player.getItemInHand().getType() == Material.FEATHER) {
    event.setcancelled(true);

    And give it a go, when a player is teleported, you need to cancel the event, as you are manually teleporting them, also remember you will need something to handle players coming back from the skylands

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  24. Offline

    andy9330

    ok

    oh, i see, since it doesn't cancel thee nether teleportation, it will continue to teleport to the nether

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  25. Offline

    Tster

    If it doesnt work tomorrow i shall do a full coding of this, and release with comments for u
     
  26. Offline

    andy9330

    it didn't work for some reason...

    ok thanks
    And thanks to everyone for the help!

    @Tster could you just do the coding and put it on GitHub? I would like to be the one to release it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  27. Offline

    nisovin

    If you didn't create it, what gives you the right to release it as if you did?
     
  28. Offline

    OblivionFan

    Ah,i didn't tell him to do that? damn...nice catch! :D
     
  29. Offline

    Tster

Thread Status:
Not open for further replies.

Share This Page