Added a simple death detection and global message when a player dies.

Signed-off-by: nossr50 <nossr50@gmail.com>
This commit is contained in:
nossr50 2010-11-27 04:35:23 -08:00
parent e9d3da07f0
commit 3c316c1cca
3 changed files with 71 additions and 18 deletions

View File

@ -21,11 +21,12 @@ public class settings {
private boolean cmdTphere = false; private boolean cmdTphere = false;
private boolean globalmessages = false; private boolean globalmessages = false;
private boolean cmdSay = false; private boolean cmdSay = false;
private boolean cmdEzModo = false;
private PropertiesFile properties; private PropertiesFile properties;
String file = "vminecraft.properties"; String file = "vminecraft.properties";
public String rules[] = null; public String rules[] = null;
public void loadSettings() public void loadSettings() throws IOException
{ {
File theDir = new File("vminecraft.properties"); File theDir = new File("vminecraft.properties");
if(!theDir.exists()) if(!theDir.exists())
@ -52,6 +53,7 @@ public class settings {
writer.write("globalmessages=true\r\n"); writer.write("globalmessages=true\r\n");
writer.write("FFF=true\r\n"); writer.write("FFF=true\r\n");
writer.write("adminchat=true\r\n"); writer.write("adminchat=true\r\n");
writer.write("cmdEzModo=true\r\n");
writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, "Exception while creating " + location, e); log.log(Level.SEVERE, "Exception while creating " + location, e);
@ -86,6 +88,7 @@ public class settings {
cmdTphere = properties.getBoolean("cmdTphere",true); cmdTphere = properties.getBoolean("cmdTphere",true);
globalmessages = properties.getBoolean("globalmessages",true); globalmessages = properties.getBoolean("globalmessages",true);
cmdSay = properties.getBoolean("cmdSay",true); cmdSay = properties.getBoolean("cmdSay",true);
cmdEzModo = properties.getBoolean("cmdEzModo",true);
rules = properties.getString("rules", "").split("@"); rules = properties.getString("rules", "").split("@");
log.log(Level.INFO, "vminecraft plugin successfully loaded"); log.log(Level.INFO, "vminecraft plugin successfully loaded");
@ -110,6 +113,7 @@ public class settings {
public boolean cmdRules() {return cmdRules;} public boolean cmdRules() {return cmdRules;}
public boolean globalmessages() {return globalmessages;} public boolean globalmessages() {return globalmessages;}
public boolean cmdMasstp() {return cmdMasstp;} public boolean cmdMasstp() {return cmdMasstp;}
public boolean cmdEzModo() {return cmdEzModo;}
public static settings getInstance() { public static settings getInstance() {
if (instance == null) { if (instance == null) {

View File

@ -1,25 +1,36 @@
//Vminecraft plugin by nossr50 & TrapAlice //Vminecraft plugin by nossr50 & TrapAlice
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class vminecraftListener extends PluginListener { public class vminecraftListener extends PluginListener {
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
public void disable() {
log.log(Level.INFO, "vminecraft disabled");
}
private ArrayList<String> ezmodo = new ArrayList<String>(); //An array of players currently in ezmodo private ArrayList<String> ezmodo = new ArrayList<String>(); //An array of players currently in ezmodo
public void enable() { public void enable() throws IOException {
settings.getInstance().loadSettings(); //Load the settings files settings.getInstance().loadSettings(); //Load the settings files
if (etc.getInstance().isHealthEnabled()){
etc.getInstance().addCommand("/ezmodo", "Toggle invulnerability");
}
log.log(Level.INFO, "vminecraft enabled"); log.log(Level.INFO, "vminecraft enabled");
} }
public void onPlayerMove () { public void disable() {
if (ezmodo.contains(player.getName())){ log.log(Level.INFO, "vminecraft disabled");
if (player.getHealth() < 30) if (etc.getInstance().isHealthEnabled()) {
{ etc.getInstance().removeCommand("/ezmodo");
player.setHealth(30); }
} }
}
public boolean onHealthChange(Player player,int oldValue,int newValue){
if (player.getHealth() != 30 && ezmodo.contains(player.getName())) {
player.setHealth(30);
}
else if (settings.getInstance().globalmessages() && player.getHealth() < 1) {
other.gmsg(Colors.Gray + player.getName() + " is no more");
}
return false;
} }
public boolean onChat(Player player, String message){ public boolean onChat(Player player, String message){
String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Copies the formatting of id.java String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Copies the formatting of id.java
@ -101,11 +112,34 @@ import java.util.logging.Logger;
} }
player.sendMessage(Colors.Blue+"Summoning successful."); player.sendMessage(Colors.Blue+"Summoning successful.");
} }
//ezmodo //Disable using /modify to add commands (need to make a boolean settings for this)
if (split[0].equals("/ezmodo")) { if(split[0].equals("/modify") && split[2].equals("commands")) {
return true;
}
//ezlist
if(settings.getInstance().cmdEzModo() && split[0].equals("/ezlist")) {
player.sendMessage("Ezmodo: " + ezmodo);
return true;
}
//slay
if(settings.getInstance().cmdEzModo() && split[0].equals("/slay")) {
Player playerTarget = etc.getServer().matchPlayer(split[1]);
if (!ezmodo.contains(playerTarget.getName())) {
playerTarget.setHealth(0);
other.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName());
return true;
}
else {
player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha");
return true;
}
}
//ezmodo
if (settings.getInstance().cmdEzModo() && split[0].equals("/ezmodo")) {
if (ezmodo.contains(player.getName())) { if (ezmodo.contains(player.getName())) {
player.sendMessage(Colors.Red + "ezmodo = off"); player.sendMessage(Colors.Red + "ezmodo = off");
ezmodo.remove(ezmodo.indexOf(player.getName())); ezmodo.remove(ezmodo.indexOf(player.getName()));
return true;
} else { } else {
player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?"); player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?");
player.sendMessage(Colors.Rose + "kimo-i"); player.sendMessage(Colors.Rose + "kimo-i");
@ -113,8 +147,8 @@ import java.util.logging.Logger;
player.sendMessage(Colors.Red + "**Laughter**"); player.sendMessage(Colors.Red + "**Laughter**");
ezmodo.add(player.getName()); ezmodo.add(player.getName());
player.setHealth(30); player.setHealth(30);
return true;
} }
return true;
} }
//Replacement for /tp //Replacement for /tp
if(settings.getInstance().cmdTp() && split[0].equalsIgnoreCase("/tp")) { if(settings.getInstance().cmdTp() && split[0].equalsIgnoreCase("/tp")) {
@ -198,7 +232,11 @@ import java.util.logging.Logger;
} }
//Should only reload vminecraft settings if the player is able to use /reload //Should only reload vminecraft settings if the player is able to use /reload
if(split[0].equalsIgnoreCase("/reload") && player.canUseCommand("/reload")) { if(split[0].equalsIgnoreCase("/reload") && player.canUseCommand("/reload")) {
settings.getInstance().loadSettings(); try {
settings.getInstance().loadSettings();
} catch (IOException ex) {
Logger.getLogger(vminecraftListener.class.getName()).log(Level.SEVERE, null, ex);
}
return false; return false;
} }
//Rules //Rules

View File

@ -1,3 +1,8 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* vminecraft Plugin * vminecraft Plugin
* @author Robert, TrapAlice * @author Robert, TrapAlice
@ -5,14 +10,17 @@
//This is how we setup the listener //This is how we setup the listener
public class vminecraftPlugin extends Plugin { public class vminecraftPlugin extends Plugin {
static final vminecraftListener listener = new vminecraftListener(); static final vminecraftListener listener = new vminecraftListener();
public void enable() { public void enable() {
//If we had commands we would add them here. //If we had commands we would add them here.
etc.getInstance().addCommand("/masstp", "Teleports those with lower permissions to you"); etc.getInstance().addCommand("/masstp", "Teleports those with lower permissions to you");
etc.getInstance().addCommand("/rules", "Displays the rules"); etc.getInstance().addCommand("/rules", "Displays the rules");
etc.getInstance().addCommand("/fabulous", "makes text SUUUPER"); etc.getInstance().addCommand("/fabulous", "makes text SUUUPER");
etc.getInstance().addCommand("/whois", "/whois [user]"); etc.getInstance().addCommand("/whois", "/whois [user]");
settings.getInstance().loadSettings(); //Hopefully this will make the plugin load right away try {
settings.getInstance().loadSettings(); //Hopefully this will make the plugin load right away
} catch (IOException ex) {
Logger.getLogger(vminecraftPlugin.class.getName()).log(Level.SEVERE, null, ex);
}
} }
public void disable() { public void disable() {
@ -23,5 +31,8 @@ public class vminecraftPlugin extends Plugin {
//Here we add the hook we're going to use. In this case it's the arm swing event. //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.CHAT, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH);
if(etc.getInstance().isHealthEnabled()){
etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM);
}
} }
} }