Spigot/Bukkit Coding Episode 5 ~ Using Multiple Classes and Packages

Spigot/Bukkit Coding Episode 5 ~ Using Multiple Classes and Packages

Hey guys, I hope you enjoyed the new coding video! If you like it please leave a like and a comment. Also don’t forget to tell me what you want to see next episode.

In this episode, we are going to learn how to use multiple classes and packages. This keeps our code organized and makes it look more professional! We also learn how to register commands and events with different classes, and accessing the main class on different classes.

hey guys it's monkey here and honestly I am a little bit mad I'm not a little bit mad I'm really really really mad really pissed off right now reason being I recorded a in episode a 21 minute long episode yes 21 minutes for this entire episode it was a very important episode to so you know pretty pissed off basically what we did was we created API and we learned how to use multiple classes however the problem was that I had to change a few settings with OBS because I was streaming and such and you know I couldn't even stream so a lot that really sucks but I know it's not that good it's not good enough to stream but you know I didn't mess with some OVS shading OBS settings that you know I really didn't know what I was doing so I messed a few things up and I'm pretty pissed about that and you know I didn't really feel like it was going to be necessary to completely redo the entire episode again so I'm just gonna give a rundown trying to I'll try to be try to give as many details as I can but really I am I'm just really feeling yeah so let's go ahead and and start with the API class also I'm gonna go ahead and explain all this so ignore all these packages for right now these three just concentrate on our tutorial we had our main tutorial class I got rid of all our events from last episodes and put them into different packages in different classes normally I could create a new package like this dot new pack nope new package new package however yours would look differently would say like for me if I didn't have a specific exciting changed with which I will show you guys in a second it would say or it's monkeyduck tutorial dot new package and that looks really really really bad so what you got to do go on top here you see this low error arrow View menu click that then you're going to package presentation normally would be flat and change it to this high Oracle I don't know how to pronounce it guys sorry I had another interruption I like every single video pretty much but let's continue you just go in here pantry incision higher article whatever the heck that's pronounced but and it'll show up like this so I'm just gonna get rid of that package and then so I created three more packages an API an API package commands pet could you know listeners package having multiple packages really helps your code stay clean and you know organized and in the API package it's not really necessary today like creating a package called the API but you know I just did that so if we go into our API class we can see a lot of stuff here first of all we got an instance of the main class the way we actually get an instance of the me like when I say an instance of the main class I mean being able to access the main classes methods I also spoke about like static and how you're really not supposed to use static and I'm just gonna explain that again really quick because it's something very very important so I'm gonna go ahead and get the here you can see we got some underlines some red underlines let's just remove plug-in really quick and by the way plugin was what I want I called my variable to get the main class so if I just do get configured you know it doesn't recognize that method get configured get configures from Java plugin is from the Java playing I don't know how to call it the its inherited from Java playing but we're gonna have to access the main class and to do that you just do tutorial plugin do that we can do AP you can do API and then control space and then it's gonna say constructor here got that constructor they do too for real instance and we can do this thought plugin equals instance and then we just get we already have our handy dandy little main class methods and also so that's pretty much well not let me explain at points so basically we are every time a player gives another player you're giving them points here's it giving them a certain amount of points we go through here the EPI good evening caddy you guys know this from you know the other tutorial like you know just giving them points and you know it's just like a custom currency but with points and then here do you pull or to remove points by RP anti-public ends get points player P load void sub points therapy our move points all we do is remove this integer I because we have our two parameters parameter player parameter integer or on RI and in here we just do plug you can figure out set and our path which is players than the players ID tennis points and then we do points minus I so it's points minus whatever we say and the way I use this let's say remove three move points let's say that whatever player dies I would remove three points from him so just we get you know my current points and then just make them it remove three because in here I specified that was three however I specified it in our listeners class and deploy your death class and then get points just returns the how many points you know the player has in the set points just sets the points to whatever you're you know whatever I want basically we can get out of that player death event this is pretty this is literally copy pasted from last episode and I'm not tired yeah we did use the color clot the color plastic holder method and to access our color method we use plug-in dot color because su as I told you to access methods from the main class that's how you do it there were some people like to do public static string color I'll just say that's static for now she wants a player dust ICU we had some you know weird underlines let's go ahead and remove plug-in from here and then instead of having a plugin you do tutorial dot just ignore this one for now let's concentrate this one so you made her plugin by the way whenever you know when you're working with multiple classes and you want to like see where this certain method is you do control then you click on the method name and it will take you to whatever class the method is in so let's continue on talking about static static isn't really something that you'll be using for now so really not important and it's definitely not needed either we are not gonna be using static pretty much for anything during these tutorials and static this is lazy lazy programming it defeats the entire purpose of plugin has a plugin object-oriented programming and people who are real it just like really lazy use static and then as you can see here it's not the same as how we got our main class but it's different we have the API class right now we just have like an API class we're just declaring it we don't have anything assigned to it however when we do this we actually assigned the class the API class to – I'm sorry guys they just came back from school you know I'm just not really that concentrated I was asleep at the car so you could probably I just woke up just like every other visit think I always just wake up after making an episode what do we were thing anyways we have our handy-dandy API method and that's how we get API to add points we give five points to the killer player who killed the other player now we remove points from the player that died we could also do something like API dot sub points and then from the player who died to zero we don't care how many points he has we're just gonna completely set them to serial because because he died but we don't want to do that we just want to remove the points that already have and we want to remove three then we of course safety comfy and then we sent them handy dandy message in our API class a lot of people whenever they create these kind of custom classes they do public static avoid add points you know then you got to make this static and no no bad by bed and then you know when people watch you go into you know other classes all they do is API dots at points and you know that's really not good not good do not use that it goes you don't need it get rid of API and then we can go into a player join class it's pretty much the same thing we just added the points variable or not variable to points path here why did that – you know the players information want to call like that and yeah that's me nothing change just plug in don't get config and then you know our little constructor here to get the main classes config mm-hmm and then it's gone to commands we have our little stuffs command in here of course we got a constructor and then pretty sure that nothing changed just here like whenever you do stats in a player name it's gonna show you know how many points someone has – it used to be just kills and deaths and I added points in a red color of course to make it stand out and also something that I do not do the other episode was what if someone just does slash stats and they don't declare a player to do if re spawn blanks or equal to zero just go ahead and copy and paste all this Joseph stuff oh yeah actually you know what I just did was ctrl shift F that sometimes helps sometimes it's just a pain in the butt and you know right now I would be sacrificing more than what I can fix and just with a little tab I fixed that so it was really no need for me to do controller stuff however ctrl shift F does help me a lot sometimes to format my code anyways let's go ahead and continue on string D period unity we can do a PS and message P target name and then if we don't Chuck I mean we check if the plug-in was the same as this one same as last episode same everything substance have same same now that's the very important part oh I forgot to say something up here public class stats implements command executor you need to implement command executor in order to run you know commands in different classes so whatever you want to run a new command in a different class command executor right there and for listeners it's the same as the main class implements listener also for the main class you do not need to implement command executors it's not needed but you can know you can do class for you know where there's an event implements listener and let's say I have a command and a event in the same class we could just do comma command executors and then just gonna go right here and then we can just do an ADD unimplemented methods and here is our command or a new command that we use but you're not using a new command so we can just get rid of that get rid of these two and you know get out of this class now here we have plug manager good luck it'll get flowing much Oh Jackie you know same stuff from last episode and in order to watch three events from a new class I'm gonna go ahead and get rid of both of those I'm gonna do one side all right yeah I'm taught register right what are you register events then we discussed takes a listener class and a plugin which is basically the main class so we can just do new layer' death then since we passed an instance of remain class into the player death class you have to put this in there and then for a second argument you can put this if you've seen the last episode so so I'm just gonna conjure shift down I mean ctrl alt down and then pull your join and we also need to need a this in here because we did pass an instance of our main class and in the players on class but if you remember we could register events just by gender this and this if we had an event in this class but we don't and we don't really need to have lament listener either I'm gonna remove it in a second but just listen here though the reason you know I already explained it but the reason you don't need like this inside of everything is because you just we did pass notice of a main class in both of these classes like both I'm sorry guys I'm getting completely mumbling too much night you've really hated it I'm getting really mad at that so we could register at the client we could register this event just like this that's how you would normally register it however since we do have the constructor we gotta put this if we were not using any of the methods from the main class and if we did not have a constructor then you would knock it and you would not get an error here and it would all be good but since we are using the main class I just put this and it's now to register a command over to do is good command command name stats top set executor and new stats and this I'm not gonna explain again I just did be passing source of them any class since you about other class that's how I'm going to say that's why we need it we need it and yeah so just not the longest tutorial but it counts I'm a little bit mad you know a fad a lot of problems lately with recording all kind of stuff I just started school I start school on Monday hit his Thursday today I know I know the reason I was uploading every single day on Easter break was because I just really really wanted to get as many episodes out as I could because I knew that I was not going to have that much time I'm sorry I know it was not gonna have that much time to record however I'm gonna change that the reason I have not recorded too much and I knew I was not going for the record was because oh by the way the video is pretty much done here I'm just explaining a few things from the past so if you just want to leave so good I'm not gonna get mad just make sure to leave a like and you know comment down below what you want to learn but anyways continuing on with my reasons to not uploading which I do hate giving reasons for not uploading but let's continue I and it's Easter break I was going to sleep at like 6 a.m. I'm not even kidding 6 a.m. oh what a bad boy I know we got a badass over here but I I II knew that my sleep schedule was really messed up and I was gonna have a lot of problems like in the week days when I went back to school and I I had to pull an all-nighter two days ago because to you know get my sleep schedule fixed and thank God it's fixed now yesterday I wanted to sleep her a good time and so and the day before I did as well so sleep schedule officially fixed it now I'm really happy about that but I this means also those gonna there's gonna be a bit more uploads you know I do have a lot of other stuff to do school wise you know and other extracurricular activities and of course hanging out with friends I know I'm the coolest kid ever I hang out with friends but something important that you up do you know interact with other people well I'm starting to ramble I don't want to ramble anymore so now that stinks a lot for watching as already said leaf a life tell me what you want to learn in the comments I will see you all later thanks a lot for watching

3 thoughts on “Spigot/Bukkit Coding Episode 5 ~ Using Multiple Classes and Packages

  1. Hello ItsMonkey,
    Your Tutorials are the best to learn Java, after getting recommended to watch them I have been recommending them to others.

Leave a Reply