Added userlist

Build # tracking
Exploding arrows
This commit is contained in:
Steven Lawson 2012-03-09 14:01:04 -05:00
parent 376f5a4edd
commit ccd13369e5
17 changed files with 1445 additions and 1131 deletions

View File

@ -71,4 +71,13 @@
nbproject/build-impl.xml file.
-->
<target name="-pre-jar">
<buildnumber file="buildnumber.properties" />
<propertyfile file="appinfo.properties">
<entry key="program.VERSION" default="2.5" />
<entry key="program.BUILDNUM" value="${build.number}" />
<entry key="program.BUILDDATE" type="date" value="now" pattern="MM/dd/yyyy hh:mm aa" />
</propertyfile>
<copy file="appinfo.properties" todir="${build.classes.dir}" />
</target>
</project>

View File

@ -1,3 +0,0 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
build.xml.data.CRC32=7bf70ec5
build.xml.script.CRC32=b1031e10
build.xml.stylesheet.CRC32=28e38971@1.44.1.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=7bf70ec5
nbproject/build-impl.xml.script.CRC32=c53303a0
nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45
build.xml.data.CRC32=7bf70ec5
build.xml.script.CRC32=b1031e10
build.xml.stylesheet.CRC32=28e38971@1.44.1.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=7bf70ec5
nbproject/build-impl.xml.script.CRC32=ea1ae258
nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46

View File

@ -51,7 +51,7 @@ public class Command_gadmin extends TFM_Command
}
else if (mode.equals("ipban"))
{
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
String user_ip = p.getAddress().getAddress().getHostAddress();
String[] ip_parts = user_ip.split("\\.");
if (ip_parts.length == 4)
{
@ -63,7 +63,7 @@ public class Command_gadmin extends TFM_Command
}
else if (mode.equals("ban"))
{
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
String user_ip = p.getAddress().getAddress().getHostAddress();
String[] ip_parts = user_ip.split("\\.");
if (ip_parts.length == 4)
{

View File

@ -0,0 +1,89 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
import me.StevenLawson.TotalFreedomMod.TFM_UserList.TFM_UserListEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Command_glist extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 2)
{
return false;
}
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
String username;
List<String> ip_addresses = new ArrayList<String>();
try
{
Player p = getPlayer(args[1]);
username = p.getName();
ip_addresses.add(p.getAddress().getAddress().getHostName());
}
catch (CantFindPlayerException ex)
{
TFM_UserListEntry entry = TFM_UserList.getInstance(plugin).getEntry(args[1]);
if (entry == null)
{
sender.sendMessage("Can't find that user. If target is not logged in, make sure that you spelled the name exactly.");
return true;
}
username = entry.getUsername();
ip_addresses = entry.getIpAddresses();
}
String mode = args[0].toLowerCase();
if (mode.equals("ban"))
{
Player p = server.getPlayerExact(username);
if (p != null)
{
p.setBanned(true);
p.kickPlayer("IP and username banned by Administrator.");
}
else
{
server.getOfflinePlayer(username).setBanned(true);
}
for (String ip_address : ip_addresses)
{
server.banIP(ip_address);
String[] ip_address_parts = ip_address.split("\\.");
server.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
}
}
else if (mode.equals("unban"))
{
server.getOfflinePlayer(username).setBanned(false);
for (String ip_address : ip_addresses)
{
server.unbanIP(ip_address);
String[] ip_address_parts = ip_address.split("\\.");
server.unbanIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*");
}
}
}
else
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
}
return true;
}
}

View File

@ -64,7 +64,7 @@ public class Command_gtfo extends TFM_Command
}
//Ban IP Address:
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
String user_ip = p.getAddress().getAddress().getHostAddress();
String[] ip_parts = user_ip.split("\\.");
if (ip_parts.length == 4)
{

View File

@ -53,7 +53,7 @@ public class Command_saconfig extends TFM_Command
}
String user_name = p.getName().toLowerCase().trim();
String new_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
String new_ip = p.getAddress().getAddress().getHostAddress();
boolean something_changed = false;

View File

@ -17,10 +17,28 @@ public class Command_say extends TFM_Command
{
return false;
}
String message = TFM_Util.implodeStringList(" ", Arrays.asList(args));
if (senderIsConsole && sender.getName().equals("Rcon"))
{
if (message.equals("WARNING: Server is restarting, you will be kicked"))
{
TFM_Util.bcastMsg("Server is going offline.", ChatColor.GRAY);
for (Player p : server.getOnlinePlayers())
{
p.kickPlayer("Server is going offline, come back in a few minutes.");
}
server.shutdown();
return true;
}
}
if (senderIsConsole || sender.isOp())
{
String message = TFM_Util.implodeStringList(" ", Arrays.asList(args));
TFM_Util.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE);
}
else

View File

@ -1,6 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -10,7 +12,15 @@ public class Command_status extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
sender.sendMessage(ChatColor.GRAY + "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.");
sender.sendMessage(ChatColor.GOLD + "Madgeek1450's Total Freedom Mod v" + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + ", built " + TotalFreedomMod.buildDate);
sender.sendMessage(ChatColor.YELLOW + "Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.");
sender.sendMessage(ChatColor.GOLD + "Loaded worlds:");
int i = 0;
for (World world : server.getWorlds())
{
sender.sendMessage(ChatColor.GOLD + "World " + Integer.toString(i++) + ": " + world.getName() + " - " + Integer.toString(world.getPlayers().size()) + " players.");
}
return true;
}

View File

@ -28,7 +28,7 @@ public class TFM_EntityListener implements Listener
return;
}
event.setYield(0.0f);
event.setYield(0.0F);
}
@EventHandler(priority = EventPriority.HIGH)
@ -138,4 +138,17 @@ public class TFM_EntityListener implements Listener
event.setDroppedExp(0);
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHit(ProjectileHitEvent event)
{
if (TotalFreedomMod.allowExplosions)
{
Projectile entity = event.getEntity();
if (event.getEntityType() == EntityType.ARROW && entity.getShooter() instanceof Player)
{
entity.getWorld().createExplosion(entity.getLocation(), 2F);
}
}
}
}

View File

@ -1,19 +1,12 @@
package me.StevenLawson.TotalFreedomMod.Listener;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.TFM_LandmineData;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import me.StevenLawson.TotalFreedomMod.*;
import org.bukkit.*;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
@ -252,38 +245,44 @@ public class TFM_PlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerChat(PlayerChatEvent event)
{
Player p = event.getPlayer();
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p);
playerdata.incrementMsgCount();
if (playerdata.getMsgCount() > 10)
try
{
TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
TFM_Util.autoEject(p, "Kicked for spamming chat.");
Player p = event.getPlayer();
playerdata.resetMsgCount();
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p);
playerdata.incrementMsgCount();
event.setCancelled(true);
return;
}
if (Pattern.compile("^mad(?:geek)?(?:1450)?[\\?\\.\\!]?$").matcher(event.getMessage().toLowerCase()).find())
{
List<Player> matches = server.matchPlayer("Madgeek1450");
if (!matches.isEmpty())
if (playerdata.getMsgCount() > 10)
{
//TFM_Util.bcastMsg("<" + matches.get(0).getDisplayName() + "> Bitch says Madgeek...");
p.setGameMode(GameMode.SURVIVAL);
p.setFoodLevel(0);
p.setHealth(1);
TNTPrimed tnt1 = p.getWorld().spawn(p.getLocation(), TNTPrimed.class);
tnt1.setFuseTicks(40);
tnt1.setPassenger(p);
tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));
TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
TFM_Util.autoEject(p, "Kicked for spamming chat.");
playerdata.resetMsgCount();
event.setCancelled(true);
return;
}
// if (Pattern.compile("^mad(?:geek)?(?:1450)?[\\?\\.\\!]?$").matcher(event.getMessage().toLowerCase()).find())
// {
// if (server.getPlayerExact("Madgeek1450") != null)
// {
// p.setGameMode(GameMode.SURVIVAL);
// p.setFoodLevel(0);
// p.setHealth(1);
//
// TNTPrimed tnt1 = p.getWorld().spawn(p.getLocation(), TNTPrimed.class);
// tnt1.setFuseTicks(40);
// tnt1.setPassenger(p);
// tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));
// }
// }
event.setMessage(ChatColor.stripColor(event.getMessage()));
}
catch (Exception ex)
{
log.log(Level.SEVERE, null, ex);
}
}
@ -419,12 +418,14 @@ public class TFM_PlayerListener implements Listener
{
try
{
TFM_UserList.getInstance(plugin).addUser(event.getPlayer());
if (!server.getOnlineMode())
{
Player p = event.getPlayer();
if (TotalFreedomMod.superadmins.contains(p.getName().toLowerCase()))
{
String user_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
String user_ip = p.getAddress().getAddress().getHostAddress();
if (user_ip != null && !user_ip.isEmpty())
{
TFM_Util.checkPartialSuperadminIP(user_ip, plugin);

View File

@ -7,7 +7,10 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public class TFM_UserInfo
{

View File

@ -0,0 +1,150 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
public class TFM_UserList
{
private static final String USERLIST_FILENAME = "userlist.yml";
private static final Logger log = Logger.getLogger("Minecraft");
private static TFM_UserList instance = null;
private Map<String, TFM_UserListEntry> _userlist = new HashMap<String, TFM_UserListEntry>();
private final TotalFreedomMod _plugin;
protected TFM_UserList(TotalFreedomMod plugin)
{
_plugin = plugin;
primeList();
}
private void primeList()
{
_userlist.clear();
FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(_plugin.getDataFolder(), USERLIST_FILENAME));
for (String username : saved_userlist.getKeys(false))
{
TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username));
_userlist.put(username, entry);
}
for (Player p : _plugin.getServer().getOnlinePlayers())
{
addUser(p);
}
exportList();
}
private void exportList()
{
FileConfiguration new_userlist = new YamlConfiguration();
for (TFM_UserListEntry entry : _userlist.values())
{
new_userlist.set(entry.getUsername(), entry.getIpAddresses());
}
try
{
new_userlist.save(new File(_plugin.getDataFolder(), USERLIST_FILENAME));
}
catch (IOException ex)
{
log.log(Level.SEVERE, null, ex);
}
}
public static TFM_UserList getInstance(TotalFreedomMod plugin)
{
if (instance == null)
{
instance = new TFM_UserList(plugin);
}
return instance;
}
public void addUser(Player p)
{
addUser(p.getName(), p.getAddress().getAddress().getHostAddress());
}
public void addUser(String username, String ip_address)
{
username = username.toLowerCase();
TFM_UserListEntry entry = _userlist.get(username);
if (entry == null)
{
entry = new TFM_UserListEntry(username);
}
_userlist.put(username, entry);
if (entry.addIpAddress(ip_address))
{
exportList();
}
}
public TFM_UserListEntry getEntry(Player p)
{
return getEntry(p.getName());
}
public TFM_UserListEntry getEntry(String username)
{
return _userlist.get(username.toLowerCase());
}
public class TFM_UserListEntry
{
private String _username;
private List<String> _ip_addresses = new ArrayList<String>();
public TFM_UserListEntry(String username, List<String>ip_addresses)
{
_username = username;
_ip_addresses = ip_addresses;
}
public TFM_UserListEntry(String username)
{
_username = username;
}
public List<String> getIpAddresses()
{
return _ip_addresses;
}
public String getUsername()
{
return _username;
}
public boolean addIpAddress(String ip_address)
{
if (!_ip_addresses.contains(ip_address))
{
_ip_addresses.add(ip_address);
return true;
}
return false;
}
}
}

View File

@ -1,35 +1,16 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
@ -225,7 +206,7 @@ public class TFM_Util
tfm.getDataFolder().mkdirs();
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
int length;
while ((length = input.read(buf)) > 0)
{
output.write(buf, 0, length);
@ -554,7 +535,7 @@ public class TFM_Util
try
{
player_ip = p.getAddress().getAddress().toString().replaceAll("/", "").trim();
player_ip = p.getAddress().getAddress().getHostAddress();
Integer num_kicks = TFM_Util.eject_tracker.get(player_ip);
if (num_kicks == null)

View File

@ -1,15 +1,15 @@
package me.StevenLawson.TotalFreedomMod;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.InputStream;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
import me.StevenLawson.TotalFreedomMod.Listener.*;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
@ -43,14 +43,18 @@ public class TotalFreedomMod extends JavaPlugin
@Override
public void onEnable()
{
setAppProperties();
loadMainConfig();
loadSuperadminConfig();
TFM_UserList.getInstance(this);
registerEventHandlers();
server.getScheduler().scheduleAsyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
log.log(Level.INFO, "[" + getDescription().getName() + "] - Enabled! - Version: " + getDescription().getVersion() + " by Madgeek1450");
log.log(Level.INFO, "[" + getDescription().getName() + "] - Enabled! - Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450");
TFM_Util.deleteFolder(new File("./_deleteme"));
@ -231,4 +235,29 @@ public class TotalFreedomMod extends JavaPlugin
pm.registerEvents(playerListener, this);
pm.registerEvents(weatherListener, this);
}
public static String pluginVersion = "";
public static String buildNumber = "";
public static String buildDate = "";
private void setAppProperties()
{
try
{
InputStream in;
Properties props = new Properties();
in = getClass().getResourceAsStream("/appinfo.properties");
props.load(in);
in.close();
pluginVersion = props.getProperty("program.VERSION");
buildNumber = props.getProperty("program.BUILDNUM");
buildDate = props.getProperty("program.BUILDDATE");
}
catch (Exception ex)
{
log.log(Level.SEVERE, null, ex);
}
}
}

View File

@ -1,6 +1,6 @@
name: TotalFreedomMod
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
version: 2.4
version: 2.5
description: Plugin for the Total Freedom server.
author: StevenLawson / Madgeek1450
commands:
@ -58,6 +58,9 @@ commands:
gcmd:
description: Superadmin command - Send a command as someone else.
usage: /<command> <fromname> <outcommand>
glist:
description: Superadmin command - Ban/Unban any player, even those who are not logged in anymore.
usage: /<command> <ban | unban> <username>
gtfo:
description: Superadmin command - Makes someone GTFO (deop and ip ban by username).
usage: /<command> <partialname>