[TuT] Chatclear

Discussion in 'WIP and Development Status' started by FisheyLP, Feb 28, 2014.

Thread Status:
Not open for further replies.
  1. This is a fine working chatclear plugin, ill explain you later how it works:
    2. package your.package.name;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    10. public class YourClass extends JavaPlugin{
    11. @Override
    12. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    13. If(sender instanceof Player){
    14. Player player = (Player) sender;
    15. if(commandLabel.equalsIgnoreCase("Chatclear"){
    16. if(p.hasPermission("Permission.of.your.choice")){
    17. for(int i = 0; i<=250; i++){
    18. Bukkit.broadcastMessage(" ");
    19. }
    20. Bukkit.broadcastMessage("The Chat got cleared by "+p.getName());
    21. return true;
    22. }
    23. }
    24. }else{
    25. for(int i = 0; i<=250; i++){
    26. Bukkit.broadcastMessage(" ");
    27. }
    28. Bukkit.broadcastMessage("The Chat got cleared by the Console");
    29. return true
    30. }
    31. return false;
    32. }
    33. }

    first of all, we test if the commandsender is a player (sender instanceof Player) and wrote the command /Chatclear, if he, then it tests, if the player have the permission to use that command, if yes, then its going to a small for-loop, i explain it: int is a number. we make a new number called i. and i should be the number 0. Like this int i = 0; if the int i is lower or equal to 250, it adds 1 to i, because in java i++ is for adding 1 to a number(you can use too i--, if you want to minus 1). the end result should look like this: for(int i = 0; i<=250; i++){ and all the code, which is inside the for loop(in my case the broadcast) gets 250 times repepated! thats just enough to clear the whole chat. After the for loop we broadcast, who cleared the chat. And on the last else statmentnit just does the same with the console. I hope that i helped you :D
  2. Offline


    Just to point it out, your class doesn't extend JavaPlugin or implement CommandExecutor, so you can't override onCommand.
  3. Offline


    you should make sure the sender is a player before casting, otherwise the console will throw exceptions when called
  4. Offline


    Not a tutorial. Post as Resource instead. Include plugin.yml registration.
  5. Offline


    I think minecraft only accepts like 20 messages per tick? I might be wrong though.
  6. Offline


  7. It's not important how many messages minecraft per ticks accepts, the chat get cleared! :p
  8. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Moved to WIP
  9. 1. why that?
    2. What is WIP
    and 3. where is WIP? ^^
  10. Offline


    WIP and Development Status Section - Work in progress
  11. Offline


    Well when I made a chatclear command it didn't matter if I sent an empty message 50 times or 20 times, you could still scroll up to see the chat! So i was thinking that you could send 20 additional messages one tick later.
Thread Status:
Not open for further replies.

Share This Page