How to create custom events?

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

1 Like

If you’re not good at something, you practice. And in this case its called studying.

2 Likes

There isn’t really in depth “instruction” on how to create various aspects of a Sponge plugin. @FerusGrim, the only problem about your code snippet was that on the line
Block block = event.getPlayer().getWorld().getBlock(loc.getX().loc.yetY()-1,loc.getZ());

The class Block does not exsist.

You know, it’s not a good idea to reveal the entire truth sometimes, especially not publicly on the internet… just sayin.

All I can do is agree with that. Just put the time in. It’ll be worth it in the end, believe me :smiley:

EDIT:

Look here:
You’ll get all the info on the library. But you can’t use a library if you don’t know the language.

https://github.com/SpongePowered/SpongeAPI/blob/master/src/main/java/org/spongepowered/api/event/entity/living/player/PlayerMoveEvent.java

2 Likes

Give the JavaDocs a look. :smile:

1 Like

Code snippet: Please rate and help fix issues.

 @Subscribe
    public void onPlayerMove(PlayerMoveEvent event) {
        Location location = event.getPlayer().getLocation();
        BlockState JumpPadTriggerBlock = event.getPlayer().getWorld().getBlock((int)location.getPosition().getX(), (int)location.getPosition().getY(), (int)location.getPosition().getZ());
        BlockState JumpPadBlock = event.getPlayer().getWorld().getBlock((int)location.getPosition().getX(), (int)location.getPosition().getY() -1, (int)location.getPosition().getZ());
        /*
        If the block found was a REDSTONE_BLOCK, activate jumppad.
        */
        if (JumpPadTriggerBlock == BlockTypes.STONE_PRESSURE_PLATE ) {
            if (JumpPadBlock == BlockTypes.REDSTONE_BLOCK) {
                
            }
        }
    }
  • You’re giving variables names starting with a capital letter.
  • Are you sure bumping the player’s XYZ to int is giving you the correct block they’re on?
  • Why not put both checks on the same if() statement?
  • Is a BlockState really the same as a BlockType?

HI @mbaxter, the getBlock() method may only return a int. Therefore Netbeans gave a an warning, forcing me to cast a double value into a int value. When @FerusGrim showed me this code snippet, the Block class did not exist. The most related working class was BlockState> which was most likely incorrect. BlockState and BlockType is most likely unrelated. For the if{} statement, Netbeans states the BlockState cannot be converted to BlockType. I cannot really seem to work everything out, that is why I need help from the SpongePowered community.

Again, that snippet was coded within my browser, using “best-guess” programming. That’s why I called it pseudo-code. Its purpose was to show you the flow, rather than a legitimate, out-of-box working code.

And we totally get that. However, you’ve shown a lack of ability in this field where our best advice to you is to properly learn what it is you’re trying to do.

Beginning programmers should not be working with APIs on this level. Not because it’s impossible to grasp, but because you’ll start to learn a reliance on the API, and then never be able to branch-out, or have your creativity limited to what an API such as Sponge could provide for you.

To be honest, it’s bad enough relying on the JavaAPI as a new programmer, but I’d be a bit of a hypocrite if I shamed you on that regard, too much. :smile:

6 Likes

[quote=“FerusGrim, post:48, topic:6200”]
Beginning programmers should not be working with APIs on this level. Not because it’s impossible to grasp, but because you’ll start to learn a reliance on the API, and then never be able to branch-out, or have your creativity limited to what an API such as Sponge could provide for you.
[/quote] I am learning SpongeApi while learn some commons Java Apis such as the Collection Api. Hopefully after Sponge goes through more growth, there would be much more tutorials. I am coding as hobby, and books cannot get ,me to a advanced level.

But to a high enough level to effectively gather experience.

Well, hopefully the SpongeDocs will update soon…:slight_smile:

1 Like

There are plans to update and restructure SpongeDocs soon (pending approval by others, of course).

I really want to stress that the goal of SpongeDocs, if I recall correctly, is not to be a comprehensive source of information about every aspect of the Sponge API - at least not at this point in time. To be quite honest, that is not a feasible goal, given the vast size of the Sponge API. Rather, the goal of SpongeDocs is to help developers get started with the Sponge API, and to inspire them to create bigger and better plugins based on the information we offer. The Javadocs fill in where SpongeDocs leaves off.

I know you mentioned that the Javadocs are difficult to read, and given that you are still learning Java, that’s fine. Nonetheless, I recommend that you spend a few minutes each day looking through the Sponge Javadocs. They may not make sense at first, but I am sure you will get the hang of it after looking over them for a while. Also, I would like to recommend that you try out a different IDE - perhaps IntelliJ IDEA. I have no clue if Netbeans, which you said you were using, offers suggestions as you type… but I know that IDEA certainly does. Those suggestions can be very useful.

It can be said with relative certainty that SpongeDocs will not have articles on Java basics anytime soon. Having such articles does not fit in with the end goal of SpongeDocs. That being said, I would like to recommend a few (free) resources on Java that you may be interested in:

It is important to master the basics before moving on to an “advanced level” - which is where you said you want to be. Anyways, I wish you luck with your Sponge plugins and endeavors in Java. Try out Sponge’s IRC channels for help as well (if you haven’t already)!

5 Likes

What is the SpongeIRC channel and how do you go on the Sponge IRC channel?

You’ll find out if you use the search function.

1 Like

IRC = Internet relay chat.
Sponge, spongedev and spongedocs are channels where devs and users discuss things.

Webchat.esper.net is the way to go. Then read what its saying (nickserv register something…) and do it. After you’re done do nickserv identify and then /join spongedev.

That’s it (at least the short Version). Now you can chat with us :wink:

1 Like

For the longer version of what @Tzk said, check this out:

Blasphemy! How dare you?!

2 Likes

3 Likes

For IRC newbies its probably the easiest way to go. I wanted to avoid explaining the setup of an IRC client… Im using a bouncer and a proper client myself :wink:

And yes, you are right :stuck_out_tongue: