Skip to content

Instantly share code, notes, and snippets.

@zack6849
Created August 12, 2012 03:29
Show Gist options
  • Save zack6849/3329441 to your computer and use it in GitHub Desktop.
Save zack6849/3329441 to your computer and use it in GitHub Desktop.
MaintenanceMode main
package com.gmail.zcraig29;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class MaintenanceMode extends JavaPlugin {
Logger log;
public void onEnable() {
this.log = getLogger();
this.log.info("Plugin Sucessfully enabled");
getServer().getPluginManager().registerEvents(new PlayerJoin(this), //this is how you register an listener
this);
final File f = new File(getDataFolder(), "config.yml"); //this is how it makes the config
if (!f.exists()) { // if the file doesnt exist
FileConfiguration config = getConfig(); // get the default config from my jar
saveDefaultConfig(); // and save it
}
}
public void onDisable() {
this.log.info("Plugin Sucessfully disabled"); // message to the server log, saying the plugin was disabled
}
public static boolean kickplayers;
public boolean onCommand(CommandSender sender, Command cmd, //comand sender
String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("mm") && (args.length >= 1)) { //commandlistener
String arg1 = args[0];
if (arg1.equalsIgnoreCase("enable")) { // if the command - mm enable
kickplayers = true; // set the boolean kickplayers to true, kickplayers is checked in the PlayerJoin Listener
Bukkit.broadcastMessage(ChatColor.GOLD //broadcast a server wide message
+ "[MM] Maintenance Mode Enabled by: "
+ sender.getName()); // if i enabled i it would say [MM] Maintenance Mode enabled by zack6849
for (Player p : getServer().getOnlinePlayers()) {
if (!p.hasPermission("mm.bypass")) { // an iterarator, it goes through all the players online, and if they dont have that permission
String kickmessage = getConfig().getString(
"defaults.kick-message"); //creatinng the variable kick message (defined in the config)
p.kickPlayer(kickmessage); //kicking the players with the defined bessage
}
}
return true; // tell the server the command exectuted sucessfully
} else {
if (arg1.equalsIgnoreCase("disable")) { //if the command is "mm disable"
kickplayers = false; //set kickplayers to false
Bukkit.broadcastMessage(ChatColor.GOLD //same message as earlier
+ "[MM] Maintenance Mode Disabled by: "
+ sender.getName());
return true;
}
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment