Vminecraft.java renamed to vminecraftPlugin.java, settings tweaked.

Compatible with 116

Signed-off-by: nossr50 <nossr50@gmail.com>
This commit is contained in:
nossr50 2010-10-12 15:49:56 -07:00
parent 153e677faf
commit 1b9b57889c
6 changed files with 243 additions and 315 deletions

1
README
View File

@ -1 +0,0 @@
.

132
other.java Normal file
View File

@ -0,0 +1,132 @@
//Contains all the java methods for vminecraft
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;
}
public static boolean lengthCheck(String str)
{
int length = 0;
for(int x = 0; x<str.length(); x++)
{
if("i;,.:|!".indexOf(str.charAt(x)) != -1)
{
length+=2;
}
else if("l'".indexOf(str.charAt(x)) != -1)
{
length+=3;
}
else if("tI[]".indexOf(str.charAt(x)) != -1)
{
length+=4;
}
else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
{
length+=5;
}
else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
{
length+=6;
}
else if("@~".indexOf(str.charAt(x)) != -1)
{
length+=7;
}
else if(str.charAt(x)==' ')
{
length+=4;
}
}
if(length<=316)
{
return true;
} else { return false; }
}
public static String colorChange(char colour)
{
String color = "";
switch(colour)
{
case '0':
color = Colors.Black;
break;
case '1':
color = Colors.Navy;
break;
case '2':
color = Colors.Green;
break;
case '3':
color = Colors.Blue;
break;
case '4':
color = Colors.Red;
break;
case '5':
color = Colors.Purple;
break;
case '6':
color = Colors.Gold;
break;
case '7':
color = Colors.LightGray;
break;
case '8':
color = Colors.Gray;
break;
case '9':
color = Colors.DarkPurple;
break;
case 'a':
color = Colors.LightGreen;
break;
case 'b':
color = Colors.LightBlue;
break;
case 'c':
color = Colors.Rose;
break;
case 'd':
color = Colors.LightPurple;
break;
case 'e':
color = Colors.Yellow;
break;
case 'f':
color = Colors.White;
break;
case 'A':
color = Colors.LightGreen;
break;
case 'B':
color = Colors.LightBlue;
break;
case 'C':
color = Colors.Rose;
break;
case 'D':
color = Colors.LightPurple;
break;
case 'E':
color = Colors.Yellow;
break;
case 'F':
color = Colors.White;
break;
default:
color = Colors.White;
break;
}
return color;
}
}

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"};
}

View File

@ -1,8 +1,7 @@
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.MinecraftServer;
import java.io.File;
import java.io.FileWriter;
public class settings {
private final static Object syncLock = new Object();
@ -26,143 +25,39 @@ public class settings {
String file = "vminecraft.properties";
public String rules[] = null;
public void rules() {
try{
rules = properties.getString("rules", "Rules@#1: No griefing").split("@");
}
catch (Exception e) {
log.log(Level.SEVERE, "Vminecraft: "+ e.getMessage() );
rules = new String[]{"Rules@#1: No griefing"};
}
}
public void loadSettings()
//Will create a file if it doesn't exist
{
if (properties == null) {
properties = new PropertiesFile("vminecraft.properties");
} else {
properties.load();
}
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("cmdTp"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdTp = true;
}
else cmdTp = false;
}
if(split[0].equalsIgnoreCase("cmdTphere"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdTphere = true;
}
else cmdTphere = false;
}
if(split[0].equalsIgnoreCase("globalmessages"))
{
if(split[1].equalsIgnoreCase("true"))
{
globalmessages = true;
}
else globalmessages = false;
}
if(split[0].equalsIgnoreCase("cmdSay"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdSay = true;
}
else cmdSay = false;
}
if(split[0].equalsIgnoreCase("cmdRules"))
{
if(split[1].equalsIgnoreCase("true"))
{
cmdRules = true;
}
else cmdRules = 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, "Vminecraft: "+ e.getMessage() );
}
public void loadSettings()
{
if(properties == null)
{
properties = new PropertiesFile("vminecraft.properties");
} else {
properties.load();
}
try {
adminChat = properties.getBoolean("adminchat",true);
greentext = properties.getBoolean("greentext",true);
FFF = properties.getBoolean("FFF",true);
quakeColors = properties.getBoolean("quakeColors",true);
cmdFabulous = properties.getBoolean("cmdFabulous",true);
cmdPromote = properties.getBoolean("cmdPromote",true);
cmdDemote = properties.getBoolean("cmdDemote",true);
cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
cmdRules = properties.getBoolean("cmdRules",true);
cmdTp = properties.getBoolean("cmdTp",true);
cmdTphere = properties.getBoolean("cmdTphere",true);
globalmessages = properties.getBoolean("globalmessages",true);
cmdSay = properties.getBoolean("cmdSay",true);
rules = properties.getString("rules", "").split("@");
id.a.log(Level.INFO, "vminecraft plugin successfully loaded");
}
catch (Exception e)
{
log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
}
}
public boolean adminchat() {return adminChat;}

View File

@ -1,29 +1,18 @@
//This is where the bulk of the plugin is
import java.util.Locale;
import java.util.logging.Logger;
import java.util.logging.Level;
public class vminecraft extends Plugin {
@Override
public void disable() {
//I have to include this to compile, not sure why.
//Vminecraft plugin by nossr50 & TrapAlice
import java.util.logging.Level; //Need this to use LEVEL.INFO etc
public class vminecraftListener extends PluginListener {
public void disable() {
id.a.log(Level.INFO, "vminecraft disabled");
}
@Override
public void enable() {
//I have to include this to compile, not sure why.
settings.getInstance().loadSettings(); //Load the settings files
id.a.log(Level.INFO, "vminecraft enabled");
}
static final Logger log = Logger.getLogger("Minecraft");
@Override
public void onLogin(Player player)
{
settings.getInstance().rules();
settings.getInstance().loadSettings();
}
private String rules[];
public boolean onChat(Player player, String message){
settings.getInstance().rules();
settings.getInstance().loadSettings(); //So you can disable/enable things in the txt files without having to reload the server
String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Copies the formatting of id.java
String adminchat = Colors.DarkPurple + "{" + player.getColor() + player.getName() + Colors.DarkPurple +"}" + Colors.White + " "; //Special formatting for adminchat
String message2 = ""; //Used for greentext and FFF
@ -42,17 +31,18 @@ public class vminecraft extends Plugin {
}
}
}
}
}
}
log.log(Level.INFO, "@"+temp2+message); //So you can read adminchat from the server console
id.a.log(Level.INFO, "@"+temp2+message); //So you can read adminchat from the server console
return true;
}
//Greentext
if (settings.getInstance().greentext()&&message.startsWith(">")) {
id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
message = Colors.LightGreen + message;
message2 = temp2 + message;
other.gmsg(message2);
other.gmsg(message2);
return true;
}
//FFF
@ -60,35 +50,36 @@ public class vminecraft extends Plugin {
id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
message = Colors.Red + message;
message2 = temp2 + message;
other.gmsg(message2);
other.gmsg(message2);
return true;
}
//QuakeColors
if(settings.getInstance().quakeColors()&&message.length()>2 && lengthCheck(check)) {
if(settings.getInstance().quakeColors()&&message.length()>2 && other.lengthCheck(check)) {
String temp = "";
for(int x = 0; x< message.length(); x++)
{
if(message.charAt(x)=='^'&&x!=message.length()-1)
{
temp+=colorChange(message.charAt(x+1));
temp+=other.colorChange(message.charAt(x+1));
x+=1;
}
else{
temp+=message.charAt(x);
}
}
log.log(Level.INFO, "<"+player.getName()+"> "+message);
id.a.log(Level.INFO, "<"+player.getName()+"> "+message);
message = temp2 + temp + " ";
for (Player p : etc.getServer().getPlayerList()) {
if (p != null) {
other.gmsg(message);
other.gmsg(message);
return true;
}
}
}
}
return false;
}
public boolean onCommand(Player player, String[] split) {
public boolean onCommand(Player player, String[] split) {
if(!player.canUseCommand(split[0])) {
return false;
}
@ -113,7 +104,7 @@ public class vminecraft extends Plugin {
}
if (playerTarget != null) {
log.log(Level.INFO, player.getName() + " teleported to " + playerTarget.getName());
id.a.log(Level.INFO, player.getName() + " teleported to " + playerTarget.getName());
player.teleportTo(playerTarget);
return true;
} else {
@ -128,9 +119,9 @@ public class vminecraft extends Plugin {
player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]");
return true;
}
Player playerTarget = etc.getServer().matchPlayer(split[1]);
if (!player.hasControlOver(playerTarget)) {
player.sendMessage(Colors.Red + "That player has higher permissions than you.");
return true;
@ -141,7 +132,7 @@ public class vminecraft extends Plugin {
}
if (playerTarget != null) {
log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self.");
id.a.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self.");
playerTarget.teleportTo(player);
} else {
player.sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
@ -172,6 +163,11 @@ public class vminecraft extends Plugin {
return false;
}
}
//Should only reload vminecraft settings if the player is able to use /reload
if(split[0].equalsIgnoreCase("/reload") && player.canUseCommand("/reload")) {
settings.getInstance().loadSettings();
return false;
}
//Rules
if(settings.getInstance().cmdRules() && split[0].equalsIgnoreCase("/rules")) {
etc.getInstance().addCommand("/rules", "Displays the rules");
@ -190,9 +186,9 @@ public class vminecraft extends Plugin {
String temp2 = "<" + player.getName() + "> "+str;
String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple};
int counter=0;
if(lengthCheck(temp2))
if(other.lengthCheck(temp2))
{
id.a.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
id.a.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
for(int x=0; x<str.length(); x++)
{
temp+=rainbow[counter]+str.charAt(x);
@ -203,8 +199,9 @@ public class vminecraft extends Plugin {
}
str = temp+" ";
String message = "<" + player.getColor() + player.getName() + Colors.White + "> " + str;
other.gmsg(message);
return true;
} else {
player.sendMessage(Colors.Rose + "Message is too long");
}
@ -215,10 +212,11 @@ public class vminecraft extends Plugin {
if(split.length != 2)
{
player.sendMessage(Colors.Rose + "Usage is /promote [Player]");
}
Player playerTarget = null;
if(split.length==2){
for( Player p : etc.getServer().getPlayerList())
{
if (p.getName().equalsIgnoreCase(split[1]))
@ -229,25 +227,31 @@ public class vminecraft extends Plugin {
if( playerTarget!=null)
{
if(playerTarget.isInGroup("admins"))
String playerTargetGroup[] = playerTarget.getGroups();
String playerGroup[] = player.getGroups();
player.sendMessage("Debug data:");
player.sendMessage("PlayerTarget: "+playerTargetGroup[0]);
player.sendMessage("Player: "+playerGroup[0]);
if(playerTargetGroup[0].equals("admins"))
{
player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher.");
}
if(playerTarget.isInGroup("mods") && (player.isInGroup("superadmins")))
if(playerTargetGroup[0].equals("mods") && (playerGroup[0].equals("owner")))
{
playerTarget.setGroups(ranks.Admins);
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
other.gmsg(message);
}
else if (playerTarget.isInGroup("trusted") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
else if (playerTargetGroup[0].equals("trusted") && (playerGroup[0].equals("admins") || playerGroup[0].equals("owner")))
{
playerTarget.setGroups(ranks.Mods);
playerTargetGroup[0]="Mods";
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod";
other.gmsg(message);
}
else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
else if (playerTargetGroup[0].equals("default") && (playerGroup[0].equals("mods") || playerGroup[0].equals("admins") || player.isInGroup("owner")))
{
playerTarget.setGroups(ranks.Trusted);
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
@ -259,8 +263,9 @@ public class vminecraft extends Plugin {
else{
player.sendMessage(Colors.Rose + "Player not found");
}
log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
id.a.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
}
}
//Demote
if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
{
@ -310,7 +315,7 @@ public class vminecraft extends Plugin {
else{
player.sendMessage(Colors.Rose + "Player not found");
}
log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
id.a.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
return true;
}
//Whois will display info about a player
@ -331,7 +336,7 @@ public class vminecraft extends Plugin {
}
}
if (playerTarget != null){
IP = playerTarget.getIP();
if (playerTarget.canIgnoreRestrictions()) {
ignore = "True";
@ -377,124 +382,8 @@ public class vminecraft extends Plugin {
//Needs to be included
return true;
}
//Calculates how long the specified String is to prevent linebreaks when using scripts that insert color codes, designed to be used with playername included
private boolean lengthCheck(String str)
{
int length = 0;
for(int x = 0; x<str.length(); x++)
{
if("i;,.:|!".indexOf(str.charAt(x)) != -1)
{
length+=2;
}
else if("l'".indexOf(str.charAt(x)) != -1)
{
length+=3;
}
else if("tI[]".indexOf(str.charAt(x)) != -1)
{
length+=4;
}
else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
{
length+=5;
}
else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
{
length+=6;
}
else if("@~".indexOf(str.charAt(x)) != -1)
{
length+=7;
}
else if(str.charAt(x)==' ')
{
length+=4;
}
}
if(length<=316)
{
return true;
} else { return false; }
}
//QuakeColors Part 2
private String colorChange(char colour)
{
String color = "";
switch(colour)
{
case '0':
color = Colors.Black;
break;
case '1':
color = Colors.Navy;
break;
case '2':
color = Colors.Green;
break;
case '3':
color = Colors.Blue;
break;
case '4':
color = Colors.Red;
break;
case '5':
color = Colors.Purple;
break;
case '6':
color = Colors.Gold;
break;
case '7':
color = Colors.LightGray;
break;
case '8':
color = Colors.Gray;
break;
case '9':
color = Colors.DarkPurple;
break;
case 'a':
color = Colors.LightGreen;
break;
case 'b':
color = Colors.LightBlue;
break;
case 'c':
color = Colors.Rose;
break;
case 'd':
color = Colors.LightPurple;
break;
case 'e':
color = Colors.Yellow;
break;
case 'f':
color = Colors.White;
break;
case 'A':
color = Colors.LightGreen;
break;
case 'B':
color = Colors.LightBlue;
break;
case 'C':
color = Colors.Rose;
break;
case 'D':
color = Colors.LightPurple;
break;
case 'E':
color = Colors.Yellow;
break;
case 'F':
color = Colors.White;
break;
default:
color = Colors.White;
break;
}
return color;
}
}
//Temporary until I can figure out how to make my plugin load on startup
public void onLogin(Player player) {
settings.getInstance().loadSettings();
}
}

22
vminecraftPlugin.java Normal file
View File

@ -0,0 +1,22 @@
/**
* vminecraft Plugin
* @author Robert, TrapAlice
*/
//This is how we setup the listener
public class vminecraftPlugin extends Plugin {
static final vminecraftListener listener = new vminecraftListener();
public void enable() {
//If we had commands we would add them here.
}
public void disable() {
//And remove the commands here.
}
public void initialize() {
//Here we add the hook we're going to use. In this case it's the arm swing event.
etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH);
}
}