Merge branch 'master' of git@github.com:nossr50/vminecraft-plugin.git

Conflicts:
	README
	vminecraft.java
This commit is contained in:
nossr50 2010-10-06 11:27:32 -07:00
commit fd3df0696e
6 changed files with 243 additions and 132 deletions

1
README Normal file
View File

@ -0,0 +1 @@
.

7
TODO Normal file
View File

@ -0,0 +1,7 @@
TODO:
Improve logging
Fix existing bugs in /promote and /demote
Add toggles to all features
Add more info if I can think of anything useful to /whois and format it more nicely with linebreaks and stuff
Maybe include a "last online" feature for /whois
Look into block protection

View File

@ -1,11 +0,0 @@
public class other {
public static other gmsg;
public static other gmsg(String msg){
for (Player p : etc.getServer().getPlayerList()) {
if (p != null) {
p.sendMessage(msg);
}
}
return gmsg;
}
}

View File

@ -1,9 +0,0 @@
/* Class of all ranks so I don't need to type them in */
public class ranks {
public static final String[] Def = {"default"};
public static final String[] Trusted = {"trusted"};
public static final String[] Mods = {"mods"};
public static final String[] Admins = {"admins"};
public static final String[] SuperAdmins = {"superadmins"};
}

127
settings.java Normal file
View File

@ -0,0 +1,127 @@
//This doesn't do anything yet, eventually you will be able to toggle features by writing true or false in vminecraft-config.txt
//This is high up on my priority list
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.MinecraftServer;
public class settings {
private final static Object syncLock = new Object();
protected static final Logger log = Logger.getLogger("Minecraft");
private static volatile settings instance;
static boolean toggle = true;
private boolean adminChat = false;
private boolean greentext = false;
private boolean FFF = false;
private boolean quakeColors = false;
private boolean cmdFabulous = false;
private boolean cmdPromote = false;
private boolean cmdDemote = false;
private boolean cmdWhoIs = false;
private PropertiesFile properties;
String file = "vminecraft.properties";
//Unfinished was interrupted in the middle of making this shit, where we can triggle toggles in a text file for commands
//example return true for greentext=true in vminecraft.properties file would disable that code
public void loadSettings()
{
try{
Scanner scanner = new Scanner(new File(file));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if( line.startsWith("#") || line.equals(""))
{
continue;
}
String[] split = line.split("=");
if(split[0].equalsIgnoreCase("adminchat"))
{
if(split[1].equalsIgnoreCase("true"))
{
adminChat = true;
}
else adminChat = false;
}
if(split[0].equalsIgnoreCase("Greentext"))
{
if(split[1].equalsIgnoreCase("true"))
{
greentext = true;
}
else greentext = false;
}
if(split[0].equalsIgnoreCase("FFF"))
{
if(split[1].equalsIgnoreCase("true"))
{
FFF = true;
}
else FFF = false;
}
if(split[0].equalsIgnoreCase("QuakeColors"))
{
if(split[1].equalsIgnoreCase("true"))
{
quakeColors = true;
}
else quakeColors = false;
}
if(split[0].equalsIgnoreCase("cmdFabulous"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdFabulous = true;
}
else cmdFabulous = false;
}
if(split[0].equalsIgnoreCase("cmdPromote"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdPromote = true;
}
else cmdPromote = false;
}
if(split[0].equalsIgnoreCase("cmdDemote"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdDemote = true;
}
else cmdDemote = false;
}
if(split[0].equalsIgnoreCase("cmdWhoIs"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdWhoIs = true;
}
else cmdWhoIs = false;
}
}
scanner.close();
}
catch (Exception e) {log.log(Level.SEVERE, "Oh shi-: "+ e.getMessage() );}
}
public boolean adminchat() {return adminChat;}
public boolean greentext() {return greentext;}
public boolean FFF() {return FFF;}
public boolean quakeColors() {return quakeColors;}
public boolean cmdFabulous() {return cmdFabulous;}
public boolean cmdPromote() {return cmdPromote;}
public boolean cmdDemote() {return cmdDemote;}
public boolean cmdWhoIs() {return cmdWhoIs;}
public static settings getInstance() {
if (instance == null) {
instance = new settings();
}
return instance;
}
}

View File

@ -16,7 +16,6 @@ public class vminecraft extends Plugin {
} }
static final Logger log = Logger.getLogger("Minecraft"); static final Logger log = Logger.getLogger("Minecraft");
@Override
public void onLogin(Player player) public void onLogin(Player player)
{ {
settings.getInstance().loadSettings(); settings.getInstance().loadSettings();
@ -26,14 +25,14 @@ public class vminecraft extends Plugin {
//Settings.loadSettings(); //Settings.loadSettings();
settings.getInstance().loadSettings(); settings.getInstance().loadSettings();
String playerb = player.getName(); //Used to get names from players, can't remember why I can't just use 'player' String playerb = player.getName(); //Used to get names from players, can't remember why I can't just use 'player'
String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Inserts a name before the message String temp2 = "<" + etc.getInstance().getUserColor(playerb) + player.getName() + Colors.White +"> "; //Inserts a name before the message
String adminchat = Colors.LightGreen + "{" + player.getColor() + player.getName() + Colors.LightGreen +"}" + Colors.White + " "; //Inserts names admin chat style before the message String adminchat = Colors.LightGreen + "{" + etc.getInstance().getUserColor(playerb) + player.getName() + Colors.LightGreen +"}" + Colors.White + " "; //Inserts names admin chat style before the message
String message2 = ""; //Used for greentext and FFF String message2 = ""; //Used for greentext and FFF
String check = temp2+message; //Calculates how long your message will be including your name in the equation, this prevents minecraft clients from crashing when a color code is inserted after a linebreak String check = temp2+message; //Calculates how long your message will be including your name in the equation, this prevents minecraft clients from crashing when a color code is inserted after a linebreak
if (settings.getInstance().adminchat()&&message.startsWith("@") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins"))) { if (settings.getInstance().adminchat()&&message.startsWith("@") && (etc.getInstance().isUserInGroup(player, "mods") || etc.getInstance().isUserInGroup(player, "admins") || etc.getInstance().isUserInGroup(player, "superadmins"))) {
for (Player p : etc.getServer().getPlayerList()) { for (Player p : etc.getServer().getPlayerList()) {
if (p != null) { if (p != null) {
if (player.isInGroup("mods") || (player.isInGroup("admins")) || (player.isInGroup("superadmins"))) { if (etc.getInstance().isUserInGroup(p, "mods") || (etc.getInstance().isUserInGroup(p, "admins")) || (etc.getInstance().isUserInGroup(p, "superadmins"))) {
String blaa = ""; String blaa = "";
for ( int x = 1; x< message.length(); x++) { for ( int x = 1; x< message.length(); x++) {
blaa+=message.charAt(x); blaa+=message.charAt(x);
@ -90,7 +89,7 @@ public class vminecraft extends Plugin {
return false; return false;
} }
public boolean onCommand(Player player, String[] split) { public boolean onCommand(Player player, String[] split) {
if (player.canUseCommand(split[0])) { if (!etc.getInstance().canUseCommand(player.getName(), split[0])) {
return false; return false;
} }
//Fabulous //Fabulous
@ -100,7 +99,7 @@ public class vminecraft extends Plugin {
String temp = ""; String temp = "";
String str = ""; String str = "";
//str = paramString.substring(paramString.indexOf(" ")).trim(); //str = paramString.substring(paramString.indexOf(" ")).trim();
str = etc.combineSplit(1, split, " "); str = id.combineSplit(1, split, " ");
String temp2 = "<" + player.getName() + "> "+str; String temp2 = "<" + player.getName() + "> "+str;
String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple}; String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple};
int counter=0; int counter=0;
@ -116,7 +115,7 @@ public class vminecraft extends Plugin {
if(counter==7){counter = 0; } if(counter==7){counter = 0; }
} }
str = temp+" "; str = temp+" ";
String message = "<" + player.getColor() + player.getName() + Colors.White + "> " + str; String message = "<" + etc.getInstance().getUserColor(player.getName()) + player.getName() + Colors.White + "> " + str;
other.gmsg(message); other.gmsg(message);
} else { } else {
@ -124,108 +123,105 @@ public class vminecraft extends Plugin {
} }
} }
//Promote //Promote
else if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) else if (settings.getInstance().cmdPromote()&&split[0].equalsIgnoreCase("/promote")) {
{ log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
if(split.length != 2) User user2 = etc.getInstance().getUser(split[1]);
{ if (split.length < 2) {
player.sendMessage(Colors.Rose + "Usage is /promote [Player]"); player.sendMessage(Colors.Rose + "Usage is /promote [player]");
} }
if(user2 == null) { //Currently broken
Player playerTarget = null; player.sendMessage(Colors.Rose + "Player does not exist.");
return false;
for( Player p : etc.getServer().getPlayerList()) }
{ //ea player2 = id.match(split[1]);
if (p.getName().equalsIgnoreCase(split[1])) User user = etc.getInstance().getUser(split[1]);
{ boolean newUser = false;
playerTarget = p; if (user == null) {
} player.sendMessage(Colors.Rose + "Adding new user.");
} newUser = true;
user = new User();
if( playerTarget!=null) user.Name = split[1];
{ user.Administrator = false;
if(playerTarget.isInGroup("admins")) user.CanModifyWorld = true;
{ user.IgnoreRestrictions = false;
player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher."); user.Commands = new String[]{""};
} user.Prefix = "";
if(playerTarget.isInGroup("mods") && (player.isInGroup("superadmins"))) log.log(Level.INFO, player + " added new user ("+user+")"); //Not sure about keeping this
{ return false;
playerTarget.setGroups(ranks.Admins); }
etc.getInstance().getDataSource().modifyPlayer(player); if (etc.getInstance().isUserInGroup(split[1], "admins") && (etc.getInstance().isUserInGroup(player, "admins") || etc.getInstance().isUserInGroup(player, "superadmins"))) {
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin"; player.sendMessage(Colors.Rose + "You cannot promote " + split[1] + " any higher.");
other.gmsg(message); } else if (etc.getInstance().isUserInGroup(split[1], "mods") && etc.getInstance().isUserInGroup(player, "superadmins")) {
} user.Groups = ranks.Admins;
else if (playerTarget.isInGroup("trusted") && (player.isInGroup("admins") || player.isInGroup("superadmins"))) etc.getInstance().getDataSource().modifyUser(user);
{ String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
playerTarget.setGroups(ranks.Mods); other.gmsg(message);
etc.getInstance().getDataSource().modifyPlayer(player); } else if (etc.getInstance().isUserInGroup(split[1], "trusted") && etc.getInstance().isUserInGroup(player, "admins")) {
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod"; user.Groups = ranks.Mods;
other.gmsg(message); etc.getInstance().getDataSource().modifyUser(user);
} String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mods";
else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins"))) other.gmsg(message);
{ } else if (etc.getInstance().isUserInGroup(split[1], "default") && etc.getInstance().isUserInGroup(player, "mods")) {
player.setGroups(ranks.Trusted); user.Groups = ranks.Trusted;
etc.getInstance().getDataSource().modifyPlayer(player); etc.getInstance().getDataSource().modifyUser(user);
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted"; String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted";
other.gmsg(message); other.gmsg(message);
} } else player.sendMessage(Colors.Rose + "That didn't work");
} if (newUser) {
else{ etc.getInstance().getDataSource().addUser(user);
player.sendMessage(Colors.Rose + "Player not found"); } else {
} etc.getInstance().getDataSource().modifyUser(user);
log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" "); }
} }
//Demote //Demote
else if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) else if (settings.getInstance().cmdDemote()&&split[0].equalsIgnoreCase("/demote")) {
{ log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
if(split.length != 2) etc.getInstance().addCommand("/demote", "/demote [user]");
{ if (split.length < 2) {
player.sendMessage(Colors.Rose + "Usage is /demote [Player]"); player.sendMessage(Colors.Rose + "Usage is /demote [player]");
} }
if(player == null) { //Currently broken
Player playerTarget = null; player.sendMessage(Colors.Rose + "Player does not exist.");
return false;
for( Player p : etc.getServer().getPlayerList()) }
{ User user = etc.getInstance().getUser(split[1]);
if (p.getName().equalsIgnoreCase(split[1])) boolean newUser = false;
{ if (user == null) {
playerTarget = p; player.sendMessage(Colors.Rose + "Adding new user.");
} newUser = true;
} user = new User();
user.Name = split[1];
if( playerTarget!=null) user.Administrator = false;
{ user.CanModifyWorld = true;
if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins"))) user.IgnoreRestrictions = false;
{ user.Commands = new String[]{""};
playerTarget.setGroups(ranks.Mods); user.Prefix = "";
}
if (etc.getInstance().isUserInGroup(split[1], "admins")&& etc.getInstance().isUserInGroup(player, "superadmins")) {
user.Groups = ranks.Mods;
etc.getInstance().getDataSource().modifyUser(user);
String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod"; String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod";
other.gmsg(message); other.gmsg(message);
} } else if (etc.getInstance().isUserInGroup(split[1], "mods")&& etc.getInstance().isUserInGroup(player, "admins")) {
if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins"))) user.Groups = ranks.Trusted;
{ etc.getInstance().getDataSource().modifyUser(user);
playerTarget.setGroups(ranks.Trusted); String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted";
etc.getInstance().getDataSource().modifyPlayer(player); other.gmsg(message);
String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted"; } else if (etc.getInstance().isUserInGroup(split[1], "trusted")&& etc.getInstance().isUserInGroup(player, "mods")) {
other.gmsg(message); user.Groups = ranks.Def;
} etc.getInstance().getDataSource().modifyUser(user);
else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins"))) String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default";
{ other.gmsg(message);
playerTarget.setGroups(ranks.Def); } else if (etc.getInstance().isUserInGroup(split[1], "default")) {
etc.getInstance().getDataSource().modifyPlayer(player); player.sendMessage(Colors.Rose + "You cannot demote " + split[1] + " any lower.");
String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default"; } else player.sendMessage(Colors.Rose + "That didn't work");
other.gmsg(message); if (newUser) {
} etc.getInstance().getDataSource().addUser(user);
else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins"))) } else {
{ etc.getInstance().getDataSource().modifyUser(user);
player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower."); }
}
}
else{
player.sendMessage(Colors.Rose + "Player not found");
}
log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
}
//Whois will display info about a player //Whois will display info about a player
else if (settings.getInstance().cmdWhoIs()&&split[0].equalsIgnoreCase("/whois")) { } else if (settings.getInstance().cmdWhoIs()&&split[0].equalsIgnoreCase("/whois")) {
String admin =""; String admin ="";
String group =""; String group ="";
String ignore =""; String ignore ="";
@ -234,23 +230,23 @@ public class vminecraft extends Plugin {
if (split.length < 2) { if (split.length < 2) {
player.sendMessage(Colors.Rose + "Usage is /whois [player]"); player.sendMessage(Colors.Rose + "Usage is /whois [player]");
} }
if (player.canIgnoreRestrictions()) { if (etc.getInstance().canIgnoreRestrictions(split[1])) {
ignore = "True"; ignore = "True";
} else { } else {
ignore ="False"; ignore ="False";
} }
if (player.canIgnoreRestrictions()) { if (etc.getInstance().isAdmin(split[1])) {
admin = "True"; admin = "True";
} else { } else {
admin = "False"; admin = "False";
} }
if (player.isInGroup("superadmins")){ if (etc.getInstance().isUserInGroup(split[1], "superadmins")){
group = "superadmins"; group = "superadmins";
}else if(player.isInGroup("admins")){ }else if(etc.getInstance().isUserInGroup(split[1], "admins")){
group = "admins"; group = "admins";
}else if(player.isInGroup("mods")){ }else if(etc.getInstance().isUserInGroup(split[1], "mods")){
group = "mods"; group = "mods";
}else if(player.isInGroup("trusted")){ }else if(etc.getInstance().isUserInGroup(split[1], "trusted")){
group = "trusted"; group = "trusted";
}else{ }else{
group = "Default"; group = "Default";