Urgent help

Discussion in 'Plugin Development' started by mojangincworker, Apr 26, 2015.

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

    mojangincworker

    I am making a plugin that mutes players when they swear, the problem is, when I try to activate the muting plugin to mute that player in that syntax (/mute (playername) (length) (Reason), the getPlayer goes red and comes up with this error "The method getPlayer() is undefined for the type NoSwear (<-- Plugin name)"
    Please help

    My code is below. The error getPlayer is underlined.





    @EventHandler

    public void onPlayerChat(AsyncPlayerChatEvent e) {
    for (String word : e.getMessage().split(" ")) {
    if (getConfig().getStringList("badwords").contains(word)) {
    e.setCancelled(true);
    e.getPlayer().sendMessage(ChatColor.RED + "Don't curse!");
    getServer().dispatchCommand(getServer().getConsoleSender(), "mute" + getPlayer() + "5m Swearing" );
     
  2. Offline

    mine-care

    Ehm mabe because this method does not exists in the class, i assume you ment e.getPlayer(). Also This will print a random-looking string like CraftPlayer{... you need to get the name or uuid depending on what the command asks for.
    Also why is there a gap between EventHandler and the method?
     
  3. Moved to Plugin Development.
     
  4. Offline

    Tecno_Wizard

    @mojangincworker, recompile your jar. If this continues to happen, then decompile it and see if the file is actually there. I switched from eclipse to intelliJ because I was having severe compiler issues with Eclipse.

    It could also be that your Bukkit jar is corrupt, and getting a new one nowadays isn't a walk in the park.
     
  5. Offline

    mojangincworker

    The guy above was right, It was e.getPlayer() but when I do
    getServer().dispatchCommand(getServer().getConsoleSender(), "mute" + e.getPlayer() );

    It says in the console when a person swears "command not found" , when I tried it with just mute itself but not the e.getPlayer() the command works (/mute (player) (length) (reason))
     
  6. Offline

    timtower Administrator Administrator Moderator

    @mojangincworker Try e.getPlayer().getName() instead.
    Now you are probably running /mute {craftplayer="playername"}
    Or at least something in that direction
     
  7. Offline

    mojangincworker

    @EventHandler

    public void onPlayerChat(AsyncPlayerChatEvent e) {
    for (String word : e.getMessage().split(" ")) {
    if (getConfig().getStringList("badwords").contains(word)) {
    e.setCancelled(true);
    e.getPlayer().sendMessage(ChatColor.RED + "Don't curse!");
    getServer().dispatchCommand(getServer().getConsoleSender(), "mute" + e.getPlayer().getName() + "5m Profanity" );


    Here is the code, I did what you said, still "Command not found"
     
  8. Offline

    timtower Administrator Administrator Moderator

    @mojangincworker Tried to log that command to see what it actually runs? Because you are missing a couple spaces.
    You are running "mute<playername>5m Profanity"
    Only 1 space in there
     
  9. @mojangincworker There are no spaces in the command your running.

    EDIT: Tim you ninja!
     
    timtower likes this.
  10. Offline

    mojangincworker

    I am new to java, please tell me how I can log my command for future reference.
     
  11. Offline

    timtower Administrator Administrator Moderator

  12. Offline

    mojangincworker

    Ok thanks, but if you look at my code, you can list the bad words you can get muted for, but how do I make the mute time (2m) configurable in the config as well?
     
  13. Offline

    Zombie_Striker

    • getConfig().set(Path,Integer.parseint(the string that controlls time));
    • now make a runnable that takes that path in the config and subtract one (making a counter)
    • once the path == 0, remove it and allow the player to speak.
     
  14. Offline

    mojangincworker

    Where would It go in my code for example?
     
  15. Offline

    Zombie_Striker

    The runnable would go in the onEnable, while the getconfig().set would go to the method that adds them to the Config.
     
  16. Offline

    mojangincworker

    Can you help me a bit more, I'm a java noob.
     
  17. Offline

    Zombie_Striker

  18. Offline

    mojangincworker

    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
    for (String word : e.getMessage().split(" ")) {
    if (getConfig().getStringList("badwords").contains(word)) {
    e.setCancelled(true);
    getServer().dispatchCommand(getServer().getConsoleSender(), "mute " + e.getPlayer().getName() + getConfig().getStringList("MuteTime"));
    Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "Player " + e.getPlayer().getName() + " has been muted for using profanity!");



    This is what I did, a simpler way, I added mutetime in the config, but when I swear, the console prints "Player "SteveThePlayer[] has been muted" with those brackets, where are they coming from?


    Also, with essentials, /mute and /mute will mute and unmute, when a player swears again he will no longer be muted, how do I stop this?
     
    Last edited: Apr 26, 2015
  19. Offline

    caderape

    @mojangincworker Put at the begining of your method, if (e. iscancelled() { return; }
    if taht doesnt work, put the event priority to lowest. And if essentials event is still called after yours, you will have to check in the config file of essentials for see if the player is muted or no.

    the reason of your brackets is this.
    "e.getPlayer().getName() + getConfig().getStringList("MuteTime"));"
    the string list must be empty si it's writted in the config file like this : MuteTime: []
     
  20. Offline

    Zombie_Striker

    Turn the string list into a string by using a string builder.
     
  21. Offline

    mojangincworker

    I still don't know whats causing the brackets, here is my config, please explain in more depth so it's easier for me.
    badwords:
    - hello
    - pickle

    (Syntax for BanTime: #s,m,h,d,y)
    MuteTime: 5m
     
  22. Offline

    caderape

    @mojangincworker
    getStringList("MuteTime"));
    You're tring to get a stringlist from a string, so the stringlist return empty. do getString("MuteTime");

    Don't forget a space after the playerName. actually your command is '/mute <player>5m'
     
  23. Offline

    Zombie_Striker

    @mojangincworker YOU CANT JUST CAST AN ARRAY OF A STRING (String[]) TO A STRING!

    Loop through the list and build the string or you will always have this problem.
     
  24. Offline

    mojangincworker

    ok, no errors come up, but the command doesn't work, just cancels the message.
     
  25. Offline

    caderape

  26. Offline

    mojangincworker

    Never mind I got it working, thanks!

    timtower, I've got it all set up, now when a player swears they get muted, but they can just keep swearing and spamming the chat with swears and it will keep remuting them and spam broadcast messages, how do I stop this?


    {{Posts merged by Myrathi}}
     
    Last edited by a moderator: Apr 28, 2015
Thread Status:
Not open for further replies.

Share This Page