Welcome back to plugin Mastery today we will be going through how to use listeners so to create your first listener you go left side you right click new package and you do you type listener and then on the listener package you right click then Java class And here you do your class names for me it’s going to be join message okay and here you have to do implement list listener you remember to do or do bucket. event you got to use the bucket version you click on that you double click on that and here you do Private then you do your plug-in name for me it’s going to be plug-in Mastery then plugin okay simple enough here you do public and then the me um the name of your class you can get it from up here so for me it’s going to be join Message and here you’re going to do plugin Mastery for me be plugin Master for you it’s going to be the name of your plugin you do plugin okay here you do this. plugin equals plugin okay and then you do this. plugin. server get plugin manager register Event and here you type this and then plugin okay this is make sure that the listener actually gets called and works so when you actually run it it will work here we’re going to change the join message so we do at event handler and then we do new public Void on this doesn’t really matter but it’s just going to be unjoined for me and then do player join Event Event okay this is when I player joins this is the event when I player joins first off how do we get the player so we can do player Player we going to import this class equals event. get player okay so this is the player now let the message we can do event let join message actually we can do player. get name to get the name of the player join the tutorial this is going to set the join Message to player’s name the name of the player that joined join the tutorial okay so then to actually make this work and run when we join the game you got to go to your main class it’s right here and un Ena you do new join message or The name of your class and then do this oh type this okay this just make sure that it actually runs let’s try try to build it okay so build success sounds good okay so now we got to put it this on our server and then we got to restart the Server to actually make the plugin run so if we join the server now you should see your name and then join the tutorial so let’s see if that worked okay amazing it worked man join the tutorial let’s add some color to them so how do we do this you might ask You can do shed color and then it’s going to be the bucket version again that let’s just do or let’s just do something else let’s do green okay so sh color do green and then Plus send a message so let’s see if this works success sounds good okay let’s add this to our Server there you go now it’s a green message so let’s say if someone dies you want to send them maybe a title or maybe a message and maybe even a sound so how do we do this so we create a new listener called ler no message you just call it like that and Here you got a type the same thing as before okay so if you don’t want to type this all again you can just copy it from the last one okay so here we’re going to do an event handler public V void on respawn we usually like to do things When they they respawn so they are not on the death screen you know we can do player respawn Event Event okay so first stuff get the player player player equals EV player same thing as before you get the player oh here going player do send Title okay R color like the one we used before from bucket not red okay what do we want to send them maybe like you died here you got to put sub titles you can do just player. get name I think this would look good so let’s add some sounds To this message p on sounds you do player. play sound then you do player. get location and then sound Ender Dragon FL 1.0f 1.0f okay so now we will first off send a title and then play a sound for the player so let’s see if this works build success You might have realized that we forgot something and what is that we forgot to add it to the main class like we did here so we got to do new player fill message and this you can run it again now it has build success and we can add it to the Server okay so you can see the join message right there but let’s do SLK kill zombie man you died and then your name G okay and then you can hear that the Ender Dragon flap sound is playing in the background when you die okay so let’s say you want to make a new Listener that blocks people from being rude okay so you can create a new listener like before and do message listener and here you do the exact same thing that we have done the last two times oh event handler like before public void on message async Layer here shat Event Event okay we get the player we got to import a class for player and then equals and then get player okay so let’s just do a simple list a list of strings and if you remember from last part we talked about strings and variables you know a string Is a text so we do rude words this is what this list is called then it’s new array list okay so let’s add some rude or toxic words to this then you do rude words. add and then let’s add maybe imagine dying a bit toxic or rude words take That L oops take that L okay so now we can get the message to do that we can do string mage message equals event bucket message okay and here we can use a if statement like this if rude rude words. contains message you can do event. can set Canell to true because we don’t want it to send it of course and then we send them a little message like send message red don’t be toxic to others okay so now we got add it to the main class new message listener this okay let’s run this build success Okay let’s add this to our server now okay so let’s test this so let’s say imagine imagine dying and you can see don’t be toxic to others and then if we spam it doesn’t work now we can do uh eight that L and also doesn’t work Video Information
This video, titled ‘Minecraft Java Programming: Introduction to Players and Listeners – Part 3’, was uploaded by PluginMastery on 2023-11-03 08:03:32. It has garnered 53 views and 7 likes. The duration of the video is 00:10:10 or 610 seconds.
Today we will be going through how to use Listeners and Players, this will help you understand the Paper API more! So you can create your own listeners in the future.
Here on PluginMastery you will learn the basics of Minecraft plugin development, in later episodes you will be able to write a fully functional Minecraft plugin all by yourself! So what do you say? Do you want to join me and explore the Minecraft world using the power of plugins?
If you like the content please like and subscribe, it would mean everything!
Shoutout to apenguin8582 for making all the artwork.
Subscribe https://www.youtube.com/@PluginMastery
👉 Check out my other socials here: https://www.tiktok.com/@PluginMastery https://twitter.com/PluginMastery
🙋♂️ Need help? Ask in our Discord community: https://discord.gg/UsUBzpN2Bs
💡 Have an idea for a video? Request it here: https://discord.gg/UsUBzpN2Bs
——————————
🕒 Timestamps: 00:00 – Introduction 00:06 – Create your first Listener 00:26 – Creating a join message 04:22 – Creating a death title/message 06:52 – Creating a anti rude system 09:53 – Ending
——————————
Would you like to support the channel?
Computer: MacBook Pro https://amzn.to/40aXvi4 Mouse: Racer Viper Ultimate https://amzn.to/45O9LGi Mouse Pad: Japanese Sea Wave Large Mouse Pad https://amzn.to/45PDyhQ Keyboard: Razer Huntsman V2 https://amzn.to/47nk1XB Mic: Logitech for Creators Blue Yeticaster Pro Broadcast https://amzn.to/476ow8w
USB C Adapter: USB C Adapter https://amzn.to/45ReKWO
Disclaimer: These links are affiliate links, which means that if you make a purchase through them, I’ll earn a small commission. The best part? It won’t cost you anything extra! In fact, it’s a great way to support the channel and ensure I can keep creating awesome, free YouTube content for all of you to enjoy. Thank you for your support!
——————————
#minecraft #pluginmastery #java #code #programming #papermc #paperapi #minecraftplugins #learnjava #javaprogramming #minecraftplugins #minecraftjavaedition #codingforminecraft #javadevelopment #minecraftdevelopment #minecraftplugintutorial #minecraftcoding #javatutorial #minecraftcodingtutorial #bukkitapi #minecraftspigot #minecraftmodding #minecraftserverplugins #codingforbeginners #javaforgamedevelopment #minecraftprogramming #plugindevelopment #codingtutorials