Added adminmode.

Made the /flatlands command check to see if flatlands is enabled.
Made qop actually op :D
Fixed bug in message truncation
This commit is contained in:
Steven Lawson 2012-09-15 17:00:44 -04:00
parent e2ec640f29
commit 0f1fa3612a
7 changed files with 88 additions and 6 deletions

View File

@ -50,3 +50,6 @@ mob_limiter_disable_giant: true
generate_flatlands: true generate_flatlands: true
# Flatlands generation parameters, uses CleanroomGenerator syntax - http://dev.bukkit.org/server-mods/cleanroomgenerator/ # Flatlands generation parameters, uses CleanroomGenerator syntax - http://dev.bukkit.org/server-mods/cleanroomgenerator/
flatlands_generation_params: 16,stone,32,dirt,1,grass flatlands_generation_params: 16,stone,32,dirt,1,grass
# Admin-Only Mode
admin_only_mode: false

View File

@ -0,0 +1,43 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Command_adminmode extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!senderIsConsole || sender.getName().equalsIgnoreCase("remotebukkit"))
{
sender.sendMessage(ChatColor.GRAY + "This command may only be used from the Telnet or BukkitHttpd console.");
return true;
}
if (args[0].equalsIgnoreCase("off"))
{
TotalFreedomMod.adminOnlyMode = false;
TFM_Util.bcastMsg("Server is now open to all players.", ChatColor.RED);
return true;
}
else if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.adminOnlyMode = true;
TFM_Util.bcastMsg("Server is now closed to non-superadmins.", ChatColor.RED);
for (Player p : server.getOnlinePlayers())
{
if (TFM_Util.isUserSuperadmin(p))
{
p.kickPlayer("Server is now closed to non-superadmins.");
}
}
return true;
}
return false;
}
}

View File

@ -1,6 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -10,7 +12,14 @@ public class Command_flatlands extends TFM_Command
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
TFM_Util.gotoWorld(sender, "flatlands"); if (TotalFreedomMod.generateFlatlands)
{
TFM_Util.gotoWorld(sender, "flatlands");
}
else
{
sender.sendMessage(ChatColor.GRAY + "Flatlands is currently disabled.");
}
return true; return true;
} }
} }

View File

@ -24,7 +24,7 @@ public class Command_qop extends TFM_Command
matched_player = true; matched_player = true;
TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false); TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false);
p.setOp(false); p.setOp(true);
p.sendMessage(TotalFreedomMod.YOU_ARE_OP); p.sendMessage(TotalFreedomMod.YOU_ARE_OP);
} }
if (!matched_player) if (!matched_player)
@ -34,7 +34,7 @@ public class Command_qop extends TFM_Command
if (args[0].toLowerCase().startsWith(p.getDisplayName().toLowerCase())) if (args[0].toLowerCase().startsWith(p.getDisplayName().toLowerCase()))
{ {
TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false); TFM_Util.adminAction(sender.getName(), "Opping " + p.getName(), false);
p.setOp(false); p.setOp(true);
p.sendMessage(TotalFreedomMod.YOU_ARE_OP); p.sendMessage(TotalFreedomMod.YOU_ARE_OP);
return true; return true;

View File

@ -329,7 +329,7 @@ public class TFM_PlayerListener implements Listener
{ {
if (!TFM_Util.isUserSuperadmin(p)) if (!TFM_Util.isUserSuperadmin(p))
{ {
p.sendMessage(ChatColor.RED + "You're muted, STFU!"); p.sendMessage(ChatColor.RED + "You are currently muted.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -341,7 +341,11 @@ public class TFM_PlayerListener implements Listener
} }
// Truncate messages that are too long. // Truncate messages that are too long.
event.setMessage(event.getMessage().substring(0, 85)); String message = event.getMessage();
if (message.length() > 85)
{
event.setMessage(message.substring(0, 85));
}
event.setMessage(ChatColor.stripColor(event.getMessage())); event.setMessage(ChatColor.stripColor(event.getMessage()));
} }
@ -488,7 +492,7 @@ public class TFM_PlayerListener implements Listener
{ {
try try
{ {
Player p = event.getPlayer(); final Player p = event.getPlayer();
TFM_UserList.getInstance(plugin).addUser(p); TFM_UserList.getInstance(plugin).addUser(p);
@ -509,6 +513,18 @@ public class TFM_PlayerListener implements Listener
p.setOp(true); p.setOp(true);
} }
} }
if (TotalFreedomMod.adminOnlyMode)
{
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable()
{
@Override
public void run()
{
p.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
}
}, 60L);
}
} }
catch (Throwable ex) catch (Throwable ex)
{ {
@ -652,6 +668,12 @@ public class TFM_PlayerListener implements Listener
return; return;
} }
if (TotalFreedomMod.adminOnlyMode)
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is currently closed to non-superadmins.");
return;
}
for (Player test_player : server.getOnlinePlayers()) for (Player test_player : server.getOnlinePlayers())
{ {
if (test_player.getName().equalsIgnoreCase(player_name)) if (test_player.getName().equalsIgnoreCase(player_name))

View File

@ -167,6 +167,7 @@ public class TotalFreedomMod extends JavaPlugin
public static boolean generateFlatlands = true; public static boolean generateFlatlands = true;
public static String flatlandsGenerationParams = "16,stone,32,dirt,1,grass"; public static String flatlandsGenerationParams = "16,stone,32,dirt,1,grass";
public static boolean allowFliudSpread = false; public static boolean allowFliudSpread = false;
public static boolean adminOnlyMode = false;
public void loadMainConfig() public void loadMainConfig()
{ {
@ -201,6 +202,7 @@ public class TotalFreedomMod extends JavaPlugin
generateFlatlands = config.getBoolean("generate_flatlands", generateFlatlands); generateFlatlands = config.getBoolean("generate_flatlands", generateFlatlands);
flatlandsGenerationParams = config.getString("flatlands_generation_params", flatlandsGenerationParams); flatlandsGenerationParams = config.getString("flatlands_generation_params", flatlandsGenerationParams);
allowFliudSpread = config.getBoolean("allow_fluid_spread", allowFliudSpread); allowFliudSpread = config.getBoolean("allow_fluid_spread", allowFliudSpread);
adminOnlyMode = config.getBoolean("admin_only_mode", adminOnlyMode);
} }
public static List<String> superadmins = new ArrayList<String>(); public static List<String> superadmins = new ArrayList<String>();

View File

@ -4,6 +4,9 @@ version: 2.7
description: Plugin for the Total Freedom server. description: Plugin for the Total Freedom server.
authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon] authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon]
commands: commands:
adminmode:
description: Console-only command - Close server to non-superadmins.
usage: /<command> [on | off]
cage: cage:
description: Superadmin command - Place a cage around someone. description: Superadmin command - Place a cage around someone.
usage: /<command> <partialname> [off | outermaterial] [water | lava] usage: /<command> <partialname> [off | outermaterial] [water | lava]