2011-09-20 02:52:08 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod;
|
|
|
|
|
2011-09-21 03:31:59 +00:00
|
|
|
import java.util.ArrayList;
|
2011-09-22 22:56:17 +00:00
|
|
|
import java.util.Arrays;
|
2011-09-25 06:17:32 +00:00
|
|
|
import java.util.Collections;
|
2011-09-21 03:31:59 +00:00
|
|
|
import java.util.List;
|
2011-09-20 02:52:08 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
2011-09-22 22:56:17 +00:00
|
|
|
import org.bukkit.GameMode;
|
2011-09-25 06:17:32 +00:00
|
|
|
import org.bukkit.Location;
|
2011-09-20 02:52:08 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-09-23 03:22:10 +00:00
|
|
|
import org.bukkit.event.Event;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
2011-09-20 02:52:08 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2011-09-21 03:31:59 +00:00
|
|
|
import org.bukkit.util.config.Configuration;
|
2011-09-20 02:52:08 +00:00
|
|
|
|
|
|
|
public class TotalFreedomMod extends JavaPlugin
|
|
|
|
{
|
2011-09-23 15:45:34 +00:00
|
|
|
private final TotalFreedomModEntityListener entityListener = new TotalFreedomModEntityListener(this);
|
|
|
|
private final TotalFreedomModBlockListener blockListener = new TotalFreedomModBlockListener(this);
|
|
|
|
//private final TotalFreedomModPlayerListener playerListener = new TotalFreedomModPlayerListener(this);
|
2011-09-21 03:31:59 +00:00
|
|
|
private static final Logger log = Logger.getLogger("Minecraft");
|
|
|
|
protected static Configuration CONFIG;
|
|
|
|
private List<String> superadmins = new ArrayList<String>();
|
2011-09-23 03:22:10 +00:00
|
|
|
public Boolean allowExplosions = false;
|
2011-09-23 15:45:34 +00:00
|
|
|
public Boolean allowLavaDamage = false;
|
2011-09-23 19:44:42 +00:00
|
|
|
public Boolean allowFire = false;
|
2011-09-24 04:24:02 +00:00
|
|
|
public final static String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command.";
|
2011-09-25 04:32:00 +00:00
|
|
|
public final static String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
|
|
|
|
public final static String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
|
2011-09-20 02:52:08 +00:00
|
|
|
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2011-09-21 03:31:59 +00:00
|
|
|
CONFIG = getConfiguration();
|
|
|
|
CONFIG.load();
|
2011-09-23 15:45:34 +00:00
|
|
|
if (CONFIG.getString("superadmins", null) == null) //Generate config file:
|
2011-09-21 03:31:59 +00:00
|
|
|
{
|
|
|
|
log.log(Level.INFO, "[Total Freedom Mod] - Generating default config file (plugins/TotalFreedomMod/config.yml)...");
|
2011-09-25 04:32:00 +00:00
|
|
|
CONFIG.setProperty("superadmins", new String[]
|
|
|
|
{
|
|
|
|
"Madgeek1450", "markbyron"
|
|
|
|
});
|
2011-09-23 03:22:10 +00:00
|
|
|
CONFIG.setProperty("allow_explosions", false);
|
2011-09-23 15:45:34 +00:00
|
|
|
CONFIG.setProperty("allow_lava_damage", false);
|
|
|
|
CONFIG.setProperty("allow_fire", false);
|
2011-09-21 03:31:59 +00:00
|
|
|
CONFIG.save();
|
|
|
|
CONFIG.load();
|
|
|
|
}
|
|
|
|
superadmins = CONFIG.getStringList("superadmins", null);
|
2011-09-23 03:22:10 +00:00
|
|
|
allowExplosions = CONFIG.getBoolean("allow_explosions", false);
|
2011-09-23 15:45:34 +00:00
|
|
|
allowLavaDamage = CONFIG.getBoolean("allow_lava_damage", false);
|
2011-09-23 19:44:42 +00:00
|
|
|
allowFire = CONFIG.getBoolean("allow_fire", false);
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 03:22:10 +00:00
|
|
|
PluginManager pm = this.getServer().getPluginManager();
|
|
|
|
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Event.Priority.High, this);
|
2011-09-23 15:45:34 +00:00
|
|
|
pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_IGNITE, blockListener, Event.Priority.High, this);
|
|
|
|
pm.registerEvent(Event.Type.BLOCK_BURN, blockListener, Event.Priority.High, this);
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 16:14:09 +00:00
|
|
|
log.log(Level.INFO, "[Total Freedom Mod] - Enabled! - Version: " + this.getDescription().getVersion() + " by Madgeek1450");
|
2011-09-22 22:56:17 +00:00
|
|
|
log.log(Level.INFO, "[Total Freedom Mod] - Loaded superadmins: " + implodeStringList(", ", superadmins));
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2011-09-20 16:14:09 +00:00
|
|
|
log.log(Level.INFO, "[Total Freedom Mod] - Disabled.");
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 02:52:08 +00:00
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
|
|
|
{
|
2011-09-20 14:03:03 +00:00
|
|
|
Player player = null;
|
|
|
|
if (sender instanceof Player)
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
player = (Player) sender;
|
2011-09-23 03:22:10 +00:00
|
|
|
log.log(Level.INFO, String.format("[PLAYER_COMMAND] %s(%s): /%s %s", player.getName(), player.getDisplayName().replaceAll("\\xA7.", ""), commandLabel, implodeStringList(" ", Arrays.asList(args))));
|
2011-09-22 22:56:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log.log(Level.INFO, String.format("[CONSOLE_COMMAND] %s: /%s %s", sender.getName(), commandLabel, implodeStringList(" ", Arrays.asList(args))));
|
2011-09-20 14:03:03 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
|
|
|
if (cmd.getName().equalsIgnoreCase("opme"))
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage("This command only works in-game.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-20 14:03:03 +00:00
|
|
|
if (isUserSuperadmin(sender.getName()))
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
tfBroadcastMessage(String.format("(%s: Opping %s)", sender.getName(), sender.getName()), ChatColor.GRAY);
|
2011-09-20 02:52:08 +00:00
|
|
|
sender.setOp(true);
|
2011-09-25 04:32:00 +00:00
|
|
|
sender.sendMessage(YOU_ARE_OP);
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 02:52:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("listreal") || cmd.getName().equalsIgnoreCase("list"))
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-23 16:46:31 +00:00
|
|
|
StringBuilder onlineStats = new StringBuilder();
|
2011-09-20 02:52:08 +00:00
|
|
|
StringBuilder onlineUsers = new StringBuilder();
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 16:46:31 +00:00
|
|
|
if (player == null)
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-23 16:46:31 +00:00
|
|
|
onlineStats.append(String.format("There are %d out of a maximum %d players online.", Bukkit.getOnlinePlayers().length, Bukkit.getMaxPlayers()));
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 16:46:31 +00:00
|
|
|
onlineUsers.append("Connected players: ");
|
|
|
|
boolean first = true;
|
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onlineUsers.append(", ");
|
|
|
|
}
|
|
|
|
|
2011-09-23 19:44:42 +00:00
|
|
|
if (sender.getName().equalsIgnoreCase("remotebukkit"))
|
|
|
|
{
|
|
|
|
onlineUsers.append(p.getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
if (p.isOp())
|
|
|
|
{
|
|
|
|
onlineUsers.append("[OP]").append(p.getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onlineUsers.append(p.getName());
|
|
|
|
}
|
2011-09-23 19:44:42 +00:00
|
|
|
}
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
2011-09-23 16:46:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(Bukkit.getOnlinePlayers().length);
|
|
|
|
onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(Bukkit.getMaxPlayers());
|
|
|
|
onlineStats.append(ChatColor.BLUE).append(" players online.");
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 16:46:31 +00:00
|
|
|
onlineUsers.append("Connected players: ");
|
|
|
|
boolean first = true;
|
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onlineUsers.append(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p.isOp())
|
|
|
|
{
|
|
|
|
onlineUsers.append(ChatColor.RED).append(p.getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onlineUsers.append(p.getName());
|
|
|
|
}
|
|
|
|
|
2011-09-23 16:46:31 +00:00
|
|
|
onlineUsers.append(ChatColor.WHITE);
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 16:46:31 +00:00
|
|
|
sender.sendMessage(onlineStats.toString());
|
2011-09-20 02:52:08 +00:00
|
|
|
sender.sendMessage(onlineUsers.toString());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("deopall"))
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-20 14:03:03 +00:00
|
|
|
if (isUserSuperadmin(sender.getName()) || player == null)
|
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
tfBroadcastMessage(String.format("(%s: De-opping everyone)", sender.getName()), ChatColor.GRAY);
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-20 14:03:03 +00:00
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
if (!isUserSuperadmin(p.getName()) && !p.getName().equals(sender.getName()))
|
|
|
|
{
|
|
|
|
p.setOp(false);
|
2011-09-25 04:32:00 +00:00
|
|
|
p.sendMessage(YOU_ARE_NOT_OP);
|
2011-09-20 14:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-20 14:03:03 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 02:52:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("opall"))
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-20 14:03:03 +00:00
|
|
|
if (isUserSuperadmin(sender.getName()) || player == null)
|
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
tfBroadcastMessage(String.format("(%s: Opping everyone)", sender.getName()), ChatColor.GRAY);
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
boolean doSetGamemode = false;
|
|
|
|
GameMode targetGamemode = GameMode.CREATIVE;
|
|
|
|
if (args.length != 0)
|
|
|
|
{
|
|
|
|
if (args[0].equals("-c"))
|
|
|
|
{
|
|
|
|
doSetGamemode = true;
|
|
|
|
targetGamemode = GameMode.CREATIVE;
|
|
|
|
}
|
|
|
|
else if (args[0].equals("-s"))
|
|
|
|
{
|
|
|
|
doSetGamemode = true;
|
|
|
|
targetGamemode = GameMode.SURVIVAL;
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 14:03:03 +00:00
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
p.setOp(true);
|
2011-09-25 04:32:00 +00:00
|
|
|
p.sendMessage(YOU_ARE_OP);
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-25 04:32:00 +00:00
|
|
|
if (doSetGamemode)
|
|
|
|
{
|
|
|
|
p.setGameMode(targetGamemode);
|
|
|
|
}
|
2011-09-20 14:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-20 14:03:03 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 02:52:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("qop")) //Quick OP
|
2011-09-20 16:14:09 +00:00
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 16:14:09 +00:00
|
|
|
if (sender.isOp() || player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
2011-09-20 21:10:13 +00:00
|
|
|
boolean matched_player = false;
|
2011-09-20 16:14:09 +00:00
|
|
|
for (Player p : Bukkit.matchPlayer(args[0]))
|
|
|
|
{
|
2011-09-20 21:10:13 +00:00
|
|
|
matched_player = true;
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-25 04:32:00 +00:00
|
|
|
tfBroadcastMessage(String.format("(%s: Opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
|
2011-09-20 16:14:09 +00:00
|
|
|
p.setOp(true);
|
2011-09-25 04:32:00 +00:00
|
|
|
p.sendMessage(YOU_ARE_OP);
|
2011-09-20 16:14:09 +00:00
|
|
|
}
|
2011-09-20 21:10:13 +00:00
|
|
|
if (!matched_player)
|
|
|
|
{
|
|
|
|
sender.sendMessage("No targets matched.");
|
|
|
|
}
|
2011-09-20 16:14:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-20 16:14:09 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 16:14:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("qdeop")) //Quick De-op
|
2011-09-20 16:14:09 +00:00
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 16:14:09 +00:00
|
|
|
if (sender.isOp() || player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
2011-09-20 21:10:13 +00:00
|
|
|
boolean matched_player = false;
|
2011-09-20 16:14:09 +00:00
|
|
|
for (Player p : Bukkit.matchPlayer(args[0]))
|
|
|
|
{
|
2011-09-20 21:10:13 +00:00
|
|
|
matched_player = true;
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-25 04:32:00 +00:00
|
|
|
tfBroadcastMessage(String.format("(%s: De-opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
|
2011-09-20 16:14:09 +00:00
|
|
|
p.setOp(false);
|
2011-09-25 04:32:00 +00:00
|
|
|
p.sendMessage(YOU_ARE_NOT_OP);
|
2011-09-20 16:14:09 +00:00
|
|
|
}
|
2011-09-20 21:10:13 +00:00
|
|
|
if (!matched_player)
|
|
|
|
{
|
|
|
|
sender.sendMessage("No targets matched.");
|
|
|
|
}
|
2011-09-20 16:14:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-20 16:14:09 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 16:14:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("survival"))
|
2011-09-22 22:56:17 +00:00
|
|
|
{
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
sender.sendMessage("When used from the console, you must define a target user to change gamemode on.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!sender.isOp())
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
Player p;
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
p = Bukkit.getPlayerExact(sender.getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
List<Player> matches = Bukkit.matchPlayer(args[0]);
|
|
|
|
if (matches.isEmpty())
|
|
|
|
{
|
|
|
|
sender.sendMessage("Can't find user " + args[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = matches.get(0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
sender.sendMessage("Setting " + p.getName() + " to game mode 'Survival'.");
|
|
|
|
p.sendMessage(sender.getName() + " set your game mode to 'Survival'.");
|
|
|
|
p.setGameMode(GameMode.SURVIVAL);
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("creative"))
|
2011-09-22 22:56:17 +00:00
|
|
|
{
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
sender.sendMessage("When used from the console, you must define a target user to change gamemode on.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!sender.isOp())
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
Player p;
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
p = Bukkit.getPlayerExact(sender.getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
List<Player> matches = Bukkit.matchPlayer(args[0]);
|
|
|
|
if (matches.isEmpty())
|
|
|
|
{
|
|
|
|
sender.sendMessage("Can't find user " + args[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = matches.get(0);
|
|
|
|
}
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
sender.sendMessage("Setting " + p.getName() + " to game mode 'Creative'.");
|
|
|
|
p.sendMessage(sender.getName() + " set your game mode to 'Creative'.");
|
|
|
|
p.setGameMode(GameMode.CREATIVE);
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("wildcard"))
|
2011-09-22 22:56:17 +00:00
|
|
|
{
|
|
|
|
if (player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
|
|
|
if (args[0].equals("wildcard"))
|
|
|
|
{
|
|
|
|
sender.sendMessage("What the hell are you trying to do, you stupid idiot...");
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
String base_command = implodeStringList(" ", Arrays.asList(args));
|
|
|
|
|
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
String out_command = base_command.replaceAll("\\x3f", p.getName());
|
|
|
|
sender.sendMessage("Running Command: " + out_command);
|
|
|
|
Bukkit.getServer().dispatchCommand(sender, out_command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-22 22:56:17 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("say"))
|
2011-09-22 22:56:17 +00:00
|
|
|
{
|
2011-09-23 19:44:42 +00:00
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
if (player == null || sender.isOp())
|
|
|
|
{
|
|
|
|
String message = implodeStringList(" ", Arrays.asList(args));
|
2011-09-25 04:32:00 +00:00
|
|
|
tfBroadcastMessage(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE);
|
2011-09-22 22:56:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-22 22:56:17 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("gtfo"))
|
2011-09-22 22:56:17 +00:00
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
if (player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
|
|
|
Player p;
|
|
|
|
List<Player> matches = Bukkit.matchPlayer(args[0]);
|
|
|
|
if (matches.isEmpty())
|
|
|
|
{
|
|
|
|
sender.sendMessage("Can't find user " + args[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = matches.get(0);
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
Bukkit.getServer().dispatchCommand(sender, "smite " + p.getName());
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
p.setOp(false);
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
|
2011-09-25 04:32:00 +00:00
|
|
|
|
|
|
|
tfBroadcastMessage(String.format("Banning: %s, IP: %s.", p.getName(), user_ip), ChatColor.RED);
|
2011-09-22 22:56:17 +00:00
|
|
|
Bukkit.banIP(user_ip);
|
|
|
|
Bukkit.getOfflinePlayer(p.getName()).setBanned(true);
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
p.kickPlayer("GTFO");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-22 22:56:17 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("stop"))
|
2011-09-22 22:56:17 +00:00
|
|
|
{
|
|
|
|
if (player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
tfBroadcastMessage("Server is going offline.", ChatColor.GRAY);
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
p.kickPlayer("Server is going offline, come back in a few minutes.");
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
Bukkit.shutdown();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-22 22:56:17 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("explosives"))
|
2011-09-23 03:22:10 +00:00
|
|
|
{
|
|
|
|
if (player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 03:22:10 +00:00
|
|
|
if (args[0].equalsIgnoreCase("on"))
|
|
|
|
{
|
|
|
|
this.allowExplosions = true;
|
2011-09-25 04:32:00 +00:00
|
|
|
sender.sendMessage("Explosives are now enabled.");
|
2011-09-23 03:22:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.allowExplosions = false;
|
2011-09-25 04:32:00 +00:00
|
|
|
sender.sendMessage("Explosives are now disabled.");
|
2011-09-23 03:22:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-23 03:22:10 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 03:22:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("fire"))
|
2011-09-23 19:44:42 +00:00
|
|
|
{
|
|
|
|
if (player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 19:44:42 +00:00
|
|
|
if (args[0].equalsIgnoreCase("on"))
|
|
|
|
{
|
|
|
|
this.allowFire = true;
|
|
|
|
sender.sendMessage("Fire is now enabled.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.allowFire = false;
|
|
|
|
sender.sendMessage("Fire is now disabled.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-23 19:44:42 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 19:44:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("lavadmg"))
|
2011-09-23 19:44:42 +00:00
|
|
|
{
|
|
|
|
if (player == null || isUserSuperadmin(sender.getName()))
|
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 19:44:42 +00:00
|
|
|
if (args[0].equalsIgnoreCase("on"))
|
|
|
|
{
|
|
|
|
this.allowLavaDamage = true;
|
|
|
|
sender.sendMessage("Lava damage is now enabled.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.allowLavaDamage = false;
|
|
|
|
sender.sendMessage("Lava damage is now disabled.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-24 04:24:02 +00:00
|
|
|
sender.sendMessage(MSG_NO_PERMS);
|
2011-09-23 19:44:42 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-23 19:44:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 06:17:32 +00:00
|
|
|
else if (cmd.getName().equalsIgnoreCase("radar"))
|
|
|
|
{
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
sender.sendMessage("This command can only be used in-game.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player sender_player = Bukkit.getPlayerExact(sender.getName());
|
|
|
|
Location sender_pos = sender_player.getLocation();
|
|
|
|
String sender_world = sender_player.getWorld().getName();
|
|
|
|
|
|
|
|
List<RadarData> radar_data = new ArrayList<RadarData>();
|
|
|
|
|
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
if (sender_world.equals(p.getWorld().getName()))
|
|
|
|
{
|
|
|
|
radar_data.add(new RadarData(p, sender_pos.distance(p.getLocation())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(radar_data, new RadarData());
|
|
|
|
|
|
|
|
sender.sendMessage(ChatColor.YELLOW + "People nearby in " + sender_world + ":");
|
|
|
|
|
|
|
|
int countmax = 5;
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
countmax = Integer.parseInt(args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
for (RadarData i : radar_data)
|
|
|
|
{
|
|
|
|
if (count++ > countmax)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(ChatColor.YELLOW + String.format("%s - %d", i.player.getName(), Math.round(i.distance)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
|
|
|
return false;
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
|
|
|
public static void tfBroadcastMessage(String message, ChatColor color)
|
2011-09-23 19:44:42 +00:00
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
log.info(message);
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-23 19:44:42 +00:00
|
|
|
for (Player p : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
2011-09-25 04:32:00 +00:00
|
|
|
p.sendMessage(color + message);
|
2011-09-23 19:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-25 06:17:32 +00:00
|
|
|
|
2011-09-22 22:56:17 +00:00
|
|
|
private static String implodeStringList(String glue, List<String> pieces)
|
|
|
|
{
|
|
|
|
StringBuilder output = new StringBuilder();
|
|
|
|
for (int i = 0; i < pieces.size(); i++)
|
|
|
|
{
|
|
|
|
if (i != 0)
|
|
|
|
{
|
|
|
|
output.append(glue);
|
|
|
|
}
|
|
|
|
output.append(pieces.get(i));
|
|
|
|
}
|
|
|
|
return output.toString();
|
|
|
|
}
|
2011-09-25 04:32:00 +00:00
|
|
|
|
2011-09-20 14:03:03 +00:00
|
|
|
private boolean isUserSuperadmin(String userName)
|
2011-09-20 02:52:08 +00:00
|
|
|
{
|
2011-09-21 03:31:59 +00:00
|
|
|
return superadmins.contains(userName);
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|
|
|
|
}
|