Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 20th, 2012  |  syntax: None  |  size: 2.57 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.gmail.zcraig29;
  2.  
  3. import java.io.File;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.List;
  7. import java.util.logging.Logger;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.configuration.file.FileConfiguration;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class MaintenanceMode extends JavaPlugin {
  18.  
  19.         Logger log;
  20.  
  21.         public void onEnable() {
  22.                 this.log = getLogger();
  23.                 this.log.info("Plugin Sucessfully enabled");
  24.                 getServer().getPluginManager().registerEvents(new PlayerJoin(this), //this is how you register an listener
  25.                                 this);
  26.                 final File f = new File(getDataFolder(), "config.yml"); //this is how it makes the config
  27.                 if (!f.exists()) { // if the file doesnt exist
  28.                         FileConfiguration config = getConfig(); // get the default config from my jar
  29.                         saveDefaultConfig(); // and save it
  30.                 }
  31.         }
  32.  
  33.         public void onDisable() {
  34.                 this.log.info("Plugin Sucessfully disabled"); // message to the server log, saying the plugin was disabled
  35.         }
  36.  
  37.         public static boolean kickplayers;
  38.  
  39.         public boolean onCommand(CommandSender sender, Command cmd, //comand sender
  40.                         String commandLabel, String[] args) {
  41.                 if (cmd.getName().equalsIgnoreCase("mm") && (args.length >= 1)) { //commandlistener
  42.                         String arg1 = args[0];
  43.                         if (arg1.equalsIgnoreCase("enable")) { // if the command - mm enable
  44.                                 kickplayers = true; // set the boolean kickplayers to true, kickplayers is checked in the PlayerJoin Listener
  45.                                 Bukkit.broadcastMessage(ChatColor.GOLD //broadcast a server wide message
  46.                                                 + "[MM] Maintenance Mode Enabled by: "
  47.                                                 + sender.getName()); // if i enabled i it would say [MM] Maintenance Mode enabled by zack6849
  48.                                 for (Player p : getServer().getOnlinePlayers()) {
  49.                                         if (!p.hasPermission("mm.bypass")) { // an iterarator, it goes through all the players online, and if they dont have that permission
  50.                                                 String kickmessage = getConfig().getString(
  51.                                                                 "defaults.kick-message"); //creatinng the variable kick message (defined in the config)
  52.                                                 p.kickPlayer(kickmessage); //kicking the players with the defined bessage
  53.                                         }
  54.                                 }
  55.                                 return true; // tell the server the command exectuted sucessfully
  56.                         } else {
  57.                                 if (arg1.equalsIgnoreCase("disable")) { //if the command is "mm disable"
  58.                                         kickplayers = false; //set kickplayers to false
  59.                                         Bukkit.broadcastMessage(ChatColor.GOLD //same message as earlier
  60.                                                         + "[MM] Maintenance Mode Disabled by: "
  61.                                                         + sender.getName());
  62.                                         return true;
  63.                                 }
  64.                         }
  65.                 }
  66.                 return false;
  67.  
  68.         }
  69.  
  70. }