Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Java
You last visited: Today at 05:23

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Plugin Eclipse 1.8 chat event

Discussion on Plugin Eclipse 1.8 chat event within the Java forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2013
Posts: 94
Received Thanks: 1
Plugin Eclipse 1.8 chat event

Hallo alle zusammen ich verzweifel an einem event
Code:
 public void onchat(AsyncPlayerChatEvent e) {

          }
Ich versuche schon die ganze zeit raus zu bekommen wie ich abfragen kann
ob ein Spieler eine nachricht versendet hat
Kann mir einer da helfen (wüsste jemand eine Methode das abzufragen)?
Ich hab schon echt viel aus dem internet ausprobiert und auch selbst rumprobiert aber ich komme nicht drauf was mein fehler sein könnte.

LG
ProdielerNR(1)



ProDielerNR(1) is offline  
Old 02/15/2020, 17:03   #2
 
elite*gold: 0
Join Date: Apr 2011
Posts: 313
Received Thanks: 123

First you need to create a class to keep your listener
Code:
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

public class MyCustomEventListener implements Listener {
    @ EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {

        Player player = event.getPlayer();

        if ( event.getMessage().equalsIgnoreCase("hi")) {
            event.setMessage("I replaced your hi message, how do u feel?");
            player.sendMessage("I go before");
        }
    }
}
Then you need to register that listener to work

in your OnEnable method

Code:
   @ Override
    public void onEnable() {
        // Plugin startup logic
        this.getLogger().info("Plugin loaded yay!");
        this.getServer().getPluginManager().registerEvents(new MyCustomEventListener(),this);
    }
But i don't know if that is what you want, if you need chat to execute plugin commands, that is not the way to go...

In order to execute commands in chat you need:
  1. Define your command in resources/plugin.yml file
  2. Create your command listener class, one for each command
  3. Register your command listeners


1 - Defining your commands
Here is an extract code of my yaml file of my plugin

plugin.yml


Creating command listener

Example of my start command

CommandIrcBotStart.java

Registering your command in onEnable

Main.java

If you have any doubts, check the source of my plugin too


Btw: if you need permission for your commands you will need to check them and add them too


elmarcia is offline  
Old 02/15/2020, 21:43   #3
 
elite*gold: 0
Join Date: Jan 2013
Posts: 94
Received Thanks: 1
when i send something written something should happen, in my case a sound should be played by a player.

that should happen automatically, no matter what I write, without a command.

i hope you can this understand (Power by google translate) xD

LG
ProDielerNr(1)

Code:
    @ EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {

        Player player = event.getPlayer();
        String msg = event.getMessage();
        if ( event.getMessage().equalsIgnoreCase(msg)) {
            player.playSound(player.getLocation(),Sound.CHICKEN_EGG_POP,3,2);
        }
    }
}
I got it done after trying a few things!

Closed Quest
ProDielerNR(1) is offline  
Old 02/15/2020, 22:21   #4
 
elite*gold: 0
Join Date: Apr 2011
Posts: 313
Received Thanks: 123
Quote:
Originally Posted by ProDielerNR(1) View Post
when i send something written something should happen, in my case a sound should be played by a player.

that should happen automatically, no matter what I write, without a command.

i hope you can this understand (Power by google translate) xD

LG
ProDielerNr(1)

Code:
    @ EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {

        Player player = event.getPlayer();
        String msg = event.getMessage();
        if ( event.getMessage().equalsIgnoreCase(msg)) {
            player.playSound(player.getLocation(),Sound.CHICKEN_EGG_POP,3,2);
        }
    }
}
I got it done after trying a few things!

Closed Quest
U don't have to compare with anything, the event is fired every time a chat message is sent so no need to use that if, also if you want the sound to be heared by other players you should consider playing the sound in the world and not the player

Code:
    @ EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {

        Player player = event.getPlayer();
        World world = player.getWorld();            
        world.playSound(player.getLocation(),Sound.CHICKEN_EGG_POP,3,2);
        
    }
}
elmarcia is offline  
Reply



« Java Fragen Klassen und objekte | eclipse fehler oder so »

Similar Threads
[Buying] Kaufe Perins auf Eclipse Flyff | Buying Perins on Eclipse Flyff
10/04/2019 - Flyff Trading - 0 Replies
Hallo zusammen, ich würde gerne ein paar Perins auf Eclipse Flyff kaufen. Bezahlung am liebsten über PayPal oder Überweisung. Erreichen könnt ihr mich über PN oder per Skype (b_brandmeier). MfG --------------------------------------- Hello everybody, I want to buy some perins on Eclipse Flyff. Payment through PayPal or Bank Transfer.
WTB Shaiya ES Gold Eclipse server/Compro oro shaiya ES Eclipse servidor
04/16/2015 - Shaiya Trading - 0 Replies
WTB Shaiya ES Gold Eclipse server/Compro oro shaiya ES Eclipse servidor
[Selling] FFA Plugin/Support Plugin/Musik Plugin/Umfrage Plugin
12/09/2014 - Minecraft Trading - 3 Replies
Hey, ich biete euch hier einige Bukkit Plugins an :) Weitere folgen ^^ FFA-Plugin Was wird benötigt? Server + BungeeCord Netzwerk (Plugin ist auf BungeeCord ausgelegt.)
[Plugin suche] Chat-Level Plugin
09/15/2014 - Minecraft - 2 Replies
Hey ich suche ein Plugin, das in dem Chat, ein Level anzeigt. Dieses Level kann man durch Quests erhöhen. Zb. Ich schreibe in den chat: lv0Naschix3: Hallo Und diese Level-Anzeige soll im Chat zu sehen sein. Man kann dieses Level mit selbst erstellen Quests erhöhen wie zb, Sammle 20 Dollar, wenn man das geschafft hat ist man lv 1 und das sieht dann so aus:



All times are GMT +2. The time now is 05:23.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

BTC: 33E6kMtxYa7dApCFzrS3Jb7U3NrVvo8nsK
ETH: 0xc6ec801B7563A4376751F33b0573308aDa611E05

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2020 elitepvpers All Rights Reserved.