mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Added prelog
Fixed annoying commands More config junk
This commit is contained in:
parent
bb2e32519b
commit
3ba39d40c2
@ -1,6 +1,7 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -23,16 +24,18 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
{
|
{
|
||||||
private final TotalFreedomModEntityListener entityListener = new TotalFreedomModEntityListener(this);
|
private final TotalFreedomModEntityListener entityListener = new TotalFreedomModEntityListener(this);
|
||||||
private final TotalFreedomModBlockListener blockListener = new TotalFreedomModBlockListener(this);
|
private final TotalFreedomModBlockListener blockListener = new TotalFreedomModBlockListener(this);
|
||||||
//private final TotalFreedomModPlayerListener playerListener = new TotalFreedomModPlayerListener(this);
|
private final TotalFreedomModPlayerListener playerListener = new TotalFreedomModPlayerListener(this);
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger("Minecraft");
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
protected static Configuration CONFIG;
|
protected static Configuration CONFIG;
|
||||||
private List<String> superadmins = new ArrayList<String>();
|
private List<String> superadmins = new ArrayList<String>();
|
||||||
|
private List<String> superadmin_ips = new ArrayList<String>();
|
||||||
public Boolean allowExplosions = false;
|
public Boolean allowExplosions = false;
|
||||||
public Boolean allowLavaDamage = false;
|
public Boolean allowLavaDamage = false;
|
||||||
public Boolean allowFire = false;
|
public Boolean allowFire = false;
|
||||||
public double explosiveRadius = 4.0;
|
public double explosiveRadius = 4.0;
|
||||||
|
public Boolean preprocessLogEnabled = false;
|
||||||
|
|
||||||
public final static String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command.";
|
public final static String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command.";
|
||||||
public final static String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
|
public final static String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
|
||||||
@ -49,18 +52,25 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
{
|
{
|
||||||
"Madgeek1450", "markbyron"
|
"Madgeek1450", "markbyron"
|
||||||
});
|
});
|
||||||
|
CONFIG.setProperty("superadmin_ips", new String[]
|
||||||
|
{
|
||||||
|
"0.0.0.0"
|
||||||
|
});
|
||||||
CONFIG.setProperty("allow_explosions", false);
|
CONFIG.setProperty("allow_explosions", false);
|
||||||
CONFIG.setProperty("allow_lava_damage", false);
|
CONFIG.setProperty("allow_lava_damage", false);
|
||||||
CONFIG.setProperty("allow_fire", false);
|
CONFIG.setProperty("allow_fire", false);
|
||||||
CONFIG.setProperty("explosiveRadius", 4.0);
|
CONFIG.setProperty("explosiveRadius", 4.0);
|
||||||
|
CONFIG.setProperty("preprocess_log", false);
|
||||||
CONFIG.save();
|
CONFIG.save();
|
||||||
}
|
}
|
||||||
CONFIG.load();
|
CONFIG.load();
|
||||||
superadmins = CONFIG.getStringList("superadmins", null);
|
superadmins = CONFIG.getStringList("superadmins", null);
|
||||||
|
superadmin_ips = CONFIG.getStringList("superadmin_ips", null);
|
||||||
allowExplosions = CONFIG.getBoolean("allow_explosions", false);
|
allowExplosions = CONFIG.getBoolean("allow_explosions", false);
|
||||||
allowLavaDamage = CONFIG.getBoolean("allow_lava_damage", false);
|
allowLavaDamage = CONFIG.getBoolean("allow_lava_damage", false);
|
||||||
allowFire = CONFIG.getBoolean("allow_fire", false);
|
allowFire = CONFIG.getBoolean("allow_fire", false);
|
||||||
explosiveRadius = CONFIG.getDouble("explosiveRadius", 4.0);
|
explosiveRadius = CONFIG.getDouble("explosiveRadius", 4.0);
|
||||||
|
preprocessLogEnabled = CONFIG.getBoolean("preprocess_log", false);
|
||||||
|
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Event.Priority.High, this);
|
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Event.Priority.High, this);
|
||||||
@ -70,6 +80,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
pm.registerEvent(Event.Type.BLOCK_IGNITE, blockListener, 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);
|
pm.registerEvent(Event.Type.BLOCK_BURN, blockListener, Event.Priority.High, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.High, this);
|
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.High, this);
|
||||||
|
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.High, this);
|
||||||
|
|
||||||
log.log(Level.INFO, "[Total Freedom Mod] - Enabled! - Version: " + this.getDescription().getVersion() + " by Madgeek1450");
|
log.log(Level.INFO, "[Total Freedom Mod] - Enabled! - Version: " + this.getDescription().getVersion() + " by Madgeek1450");
|
||||||
log.log(Level.INFO, "[Total Freedom Mod] - Loaded superadmins: " + implodeStringList(", ", superadmins));
|
log.log(Level.INFO, "[Total Freedom Mod] - Loaded superadmins: " + implodeStringList(", ", superadmins));
|
||||||
@ -81,12 +92,14 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Player player = null;
|
Player player = null;
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
{
|
{
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
log.log(Level.INFO, String.format("[PLAYER_COMMAND] %s(%s): /%s %s", player.getName(), player.getDisplayName().replaceAll("\\xA7.", ""), commandLabel, implodeStringList(" ", Arrays.asList(args))));
|
log.log(Level.INFO, String.format("[PLAYER_COMMAND] %s(%s): /%s %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), commandLabel, implodeStringList(" ", Arrays.asList(args))));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -101,7 +114,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (isUserSuperadmin(sender.getName()))
|
if (isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
tfBroadcastMessage(String.format("(%s: Opping %s)", sender.getName(), sender.getName()), ChatColor.GRAY);
|
tfBroadcastMessage(String.format("(%s: Opping %s)", sender.getName(), sender.getName()), ChatColor.GRAY);
|
||||||
sender.setOp(true);
|
sender.setOp(true);
|
||||||
@ -193,13 +206,13 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else if (cmd.getName().equalsIgnoreCase("deopall"))
|
else if (cmd.getName().equalsIgnoreCase("deopall"))
|
||||||
{
|
{
|
||||||
if (isUserSuperadmin(sender.getName()) || player == null)
|
if (isUserSuperadmin(sender) || player == null)
|
||||||
{
|
{
|
||||||
tfBroadcastMessage(String.format("(%s: De-opping everyone)", sender.getName()), ChatColor.GRAY);
|
tfBroadcastMessage(String.format("(%s: De-opping everyone)", sender.getName()), ChatColor.GRAY);
|
||||||
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!isUserSuperadmin(p.getName()) && !p.getName().equals(sender.getName()))
|
if (!isUserSuperadmin(p) && !p.getName().equals(sender.getName()))
|
||||||
{
|
{
|
||||||
p.setOp(false);
|
p.setOp(false);
|
||||||
p.sendMessage(YOU_ARE_NOT_OP);
|
p.sendMessage(YOU_ARE_NOT_OP);
|
||||||
@ -215,7 +228,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else if (cmd.getName().equalsIgnoreCase("opall"))
|
else if (cmd.getName().equalsIgnoreCase("opall"))
|
||||||
{
|
{
|
||||||
if (isUserSuperadmin(sender.getName()) || player == null)
|
if (isUserSuperadmin(sender) || player == null)
|
||||||
{
|
{
|
||||||
tfBroadcastMessage(String.format("(%s: Opping everyone)", sender.getName()), ChatColor.GRAY);
|
tfBroadcastMessage(String.format("(%s: Opping everyone)", sender.getName()), ChatColor.GRAY);
|
||||||
|
|
||||||
@ -260,7 +273,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.isOp() || player == null || isUserSuperadmin(sender.getName()))
|
if (sender.isOp() || player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
boolean matched_player = false;
|
boolean matched_player = false;
|
||||||
for (Player p : Bukkit.matchPlayer(args[0]))
|
for (Player p : Bukkit.matchPlayer(args[0]))
|
||||||
@ -290,7 +303,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.isOp() || player == null || isUserSuperadmin(sender.getName()))
|
if (sender.isOp() || player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
boolean matched_player = false;
|
boolean matched_player = false;
|
||||||
for (Player p : Bukkit.matchPlayer(args[0]))
|
for (Player p : Bukkit.matchPlayer(args[0]))
|
||||||
@ -403,7 +416,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else if (cmd.getName().equalsIgnoreCase("wildcard"))
|
else if (cmd.getName().equalsIgnoreCase("wildcard"))
|
||||||
{
|
{
|
||||||
if (player == null || isUserSuperadmin(sender.getName()))
|
if (player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
if (args[0].equals("wildcard"))
|
if (args[0].equals("wildcard"))
|
||||||
{
|
{
|
||||||
@ -453,7 +466,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player == null || isUserSuperadmin(sender.getName()))
|
if (player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
Player p;
|
Player p;
|
||||||
List<Player> matches = Bukkit.matchPlayer(args[0]);
|
List<Player> matches = Bukkit.matchPlayer(args[0]);
|
||||||
@ -488,7 +501,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else if (cmd.getName().equalsIgnoreCase("stop"))
|
else if (cmd.getName().equalsIgnoreCase("stop"))
|
||||||
{
|
{
|
||||||
if (player == null || isUserSuperadmin(sender.getName()))
|
if (player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
tfBroadcastMessage("Server is going offline.", ChatColor.GRAY);
|
tfBroadcastMessage("Server is going offline.", ChatColor.GRAY);
|
||||||
|
|
||||||
@ -508,7 +521,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else if (cmd.getName().equalsIgnoreCase("explosives"))
|
else if (cmd.getName().equalsIgnoreCase("explosives"))
|
||||||
{
|
{
|
||||||
if (player == null || isUserSuperadmin(sender.getName()))
|
if (player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
@ -540,7 +553,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else if (cmd.getName().equalsIgnoreCase("fire"))
|
else if (cmd.getName().equalsIgnoreCase("fire"))
|
||||||
{
|
{
|
||||||
if (player == null || isUserSuperadmin(sender.getName()))
|
if (player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
@ -567,7 +580,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
}
|
}
|
||||||
else if (cmd.getName().equalsIgnoreCase("lavadmg"))
|
else if (cmd.getName().equalsIgnoreCase("lavadmg"))
|
||||||
{
|
{
|
||||||
if (player == null || isUserSuperadmin(sender.getName()))
|
if (player == null || isUserSuperadmin(sender))
|
||||||
{
|
{
|
||||||
if (args.length != 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
@ -681,6 +694,42 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (cmd.getName().equalsIgnoreCase("prelog"))
|
||||||
|
{
|
||||||
|
if (player == null || isUserSuperadmin(sender))
|
||||||
|
{
|
||||||
|
if (args.length != 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("on"))
|
||||||
|
{
|
||||||
|
this.preprocessLogEnabled = true;
|
||||||
|
sender.sendMessage("Command preprocess logging is now enabled. This will be spammy in the log.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.preprocessLogEnabled = false;
|
||||||
|
sender.sendMessage("Command preprocess logging is now disabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG.load();
|
||||||
|
CONFIG.setProperty("preprocess_log", this.preprocessLogEnabled);
|
||||||
|
CONFIG.save();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendMessage(MSG_NO_PERMS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
log.severe("Exception in TotalFreedomMod.onCommand: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -718,8 +767,45 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
Math.round(in_loc.getZ()));
|
Math.round(in_loc.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUserSuperadmin(String userName)
|
public boolean isUserSuperadmin(CommandSender user)
|
||||||
{
|
{
|
||||||
return superadmins.contains(userName);
|
try
|
||||||
|
{
|
||||||
|
if (!(user instanceof Player))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Bukkit.getOnlineMode())
|
||||||
|
{
|
||||||
|
if (superadmins.contains(user.getName()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Player p = (Player) user;
|
||||||
|
if (p != null)
|
||||||
|
{
|
||||||
|
InetSocketAddress ip_address_obj = p.getAddress();
|
||||||
|
if (ip_address_obj != null)
|
||||||
|
{
|
||||||
|
String user_ip = ip_address_obj.getAddress().toString().replaceAll("/", "").trim();
|
||||||
|
if (user_ip != null && !user_ip.isEmpty())
|
||||||
|
{
|
||||||
|
if (superadmin_ips.contains(user_ip))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
log.severe("Exception in TotalFreedomMod.isUserSuperadmin: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,41 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod;
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
|
|
||||||
class TotalFreedomModPlayerListener extends PlayerListener
|
class TotalFreedomModPlayerListener extends PlayerListener
|
||||||
{
|
{
|
||||||
public static TotalFreedomMod plugin;
|
public static TotalFreedomMod plugin;
|
||||||
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
TotalFreedomModPlayerListener(TotalFreedomMod instance)
|
TotalFreedomModPlayerListener(TotalFreedomMod instance)
|
||||||
{
|
{
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||||
|
{
|
||||||
|
String command = event.getMessage();
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (plugin.preprocessLogEnabled)
|
||||||
|
{
|
||||||
|
log.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.startsWith("/stop") && !command.equals("/stop"))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(ChatColor.RED + "Piss off.");
|
||||||
|
}
|
||||||
|
else if (command.startsWith("/zeus") || command.startsWith("/vulcan"))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(ChatColor.RED + "Piss off.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: TotalFreedomMod
|
name: TotalFreedomMod
|
||||||
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
|
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
|
||||||
version: 1.3
|
version: 1.4
|
||||||
description: Plugin for the Total Freedom server
|
description: Plugin for the Total Freedom server
|
||||||
author: StevenLawson / Madgeek1450
|
author: StevenLawson / Madgeek1450
|
||||||
commands:
|
commands:
|
||||||
@ -37,6 +37,9 @@ commands:
|
|||||||
opme:
|
opme:
|
||||||
description: Superadmin command - Automatically ops user.
|
description: Superadmin command - Automatically ops user.
|
||||||
usage: /<command>
|
usage: /<command>
|
||||||
|
prelog:
|
||||||
|
description: Superadmin command - Enable/disable the command prelogger. When this is on, logs will be filled with many duplicate messages.
|
||||||
|
usage: /<command> <on|off>
|
||||||
qdeop:
|
qdeop:
|
||||||
description: Quick De-Op - deop someone based on a partial name.
|
description: Quick De-Op - deop someone based on a partial name.
|
||||||
usage: /<command> <partialname>
|
usage: /<command> <partialname>
|
||||||
|
Loading…
Reference in New Issue
Block a user