Need Good Help With Plugin

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

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

    mojangincworker

    I have made a plugin called Automute, it mutes players when they swear. I want to make It have a configurable messaege 3 warning system before It mutes the player, how do I accomplish this, I need a detailed answer with steps. not just 2 sentences, thanks!

    Here is my code just if you need it.
    package me.joseph;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class AutoMute extends JavaPlugin implements Listener {

    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
    for (String word : e.getMessage().split(" ")) {
    if (getConfig().getStringList("badwords").contains(word)) {
    if (e. isCancelled()) { return; }
    e.setCancelled(true);
    getServer().dispatchCommand(getServer().getConsoleSender(), "mute " + e.getPlayer().getName() + " " + getConfig().getString("Mutetime"));
    Bukkit.getServer().broadcastMessage(ChatColor.GOLD + "Player " + e.getPlayer().getName() + " " + getConfig().getString("BroadcastReason"));



    }
    }
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @mojangincworker 1. Make sure to register the event.
    2. Store the amount of times that the player is warned.
    3. If amount > something, cancel chat events for him
     
  3. please use : [.code=java] [/code] or [.syntax=java] [/syntax] for post your code
     
  4. Offline

    Zombie_Striker

    • Make a map of UUID,Integers (for the warnings)
    • Make Map that hold UUID,Integrs again (for the mutetime)
    • For every time you catch a swear word, cancel the message and add +1 to the map.
    • if the swearcount is over 3, put the playerUUID into second map, with the selected seconds you want him to be muted
    • if he's in that map, cancel all chat events
    • In the Onenabled() make a runnable for 20L (one second) that removes 1 from every player in the Mutetime map(creating a timer)
    • once the Mutetimer for a player == 0, remove the player from the map.
    BTW, you need an onEnable to register your listener. Without it, it will not work. And please use [code.] [/code.] around your code (makes it look cleaner)
     
  5. Offline

    mojangincworker

    Ok, but how do I reset the warnings to 0 after 3 strikes (after mute), so it will start again? What is the code?
     
  6. Offline

    timtower Administrator Administrator Moderator

    Just set the warning amount to 0 again. Can't give code as I don't know what you are using for it.
     
  7. Offline

    mojangincworker

    Thanks, New question ( I know I'm full of them)

    Here is the code for a new question

    Code:
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
    for (String word : e.getMessage().split(" ")) {
    if (getConfig().getStringList("badwords").contains(word)) {
    if (e. isCancelled()) { return; }
    e.setCancelled(true);
    Object level = this.getConfig().get(e.getPlayer().getName());
    if (level == null) {
    e.getPlayer().sendMessage(ChatColor.GOLD + getConfig().getString("WarningFor1stStrike"));
    this.getConfig().set(e.getPlayer().getName(), 1);
    I've set it up, when they first swear they get a warning "don't swear" and It doesn't repeat which is even better, but how do I repeat this again with a second warning, if I copy and paste it just gives this duplicate message and it just doesn't work, please help?!?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @mojangincworker 1. You can use config.contains(key) instead of checking if something is null.
    2. Try config.getInt(key)
    3. You never check how many warnings somebody has.
     
  9. Offline

    mojangincworker

    At least put it somewhere in my code so I understand better. Please, and by the way, thanks for your persistence in helping me.
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    mojangincworker

    how do you register events and hold the number of times someone has been muted?
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    HungerCraftNL

    You would need to do something like this, I didn't test it. Watch it over
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerChat(AsyncPlayerChatEvent e) {
    4. for (String word : e.getMessage().split(" ")) {
    5. if (getConfig().getStringList("badwords").contains(word)) {
    6. if (e. isCancelled()) { return; }
    7. e.setCancelled(true);
    8. if (!this.getConfig().contains(e.getPlayer().getName())) {
    9. e.getPlayer().sendMessage(ChatColor.GOLD + getConfig().getString("WarningFor1stStrike"));
    10. this.getConfig().set(e.getPlayer().getName(), 1);
    11. } else {
    12. int level = this.getConfig().getInt(e.getPlayer().getName());
    13. this.getConfig().set(e.getPlayer().getName(), (level+1));
    14. }
    15. }
    16. }
    17. }
    18. }
    19.  
     
Thread Status:
Not open for further replies.

Share This Page