structure has been added.AlexBranch
parent
f36de77761
commit
c4b2441889
@ -0,0 +1,183 @@ |
||||
package org.sig.jobs.Commands; |
||||
|
||||
import java.text.NumberFormat; |
||||
import java.util.UUID; |
||||
|
||||
import org.sig.jobs.PlayerData; |
||||
import org.sig.jobs.main; |
||||
import org.sig.jobs.Players.Buff; |
||||
|
||||
import net.minecraft.command.CommandBase; |
||||
import net.minecraft.command.ICommandSender; |
||||
import net.minecraft.entity.player.EntityPlayer; |
||||
import net.minecraft.server.MinecraftServer; |
||||
import net.minecraft.util.ChatComponentText; |
||||
import net.minecraft.util.EnumChatFormatting; |
||||
|
||||
public class AdminCommandHandler extends CommandBase { |
||||
|
||||
@Override |
||||
public String getCommandName() { |
||||
// TODO Auto-generated method stub
|
||||
return "admin"; |
||||
} |
||||
|
||||
@Override |
||||
public String getCommandUsage(ICommandSender p) { |
||||
// TODO Auto-generated method stub
|
||||
return "/admin - Admin commands."; |
||||
} |
||||
|
||||
boolean hasPermission(ICommandSender p) { |
||||
boolean approved=false; |
||||
if (p instanceof EntityPlayer) { |
||||
if (main.AdminList.contains(((EntityPlayer) p).getDisplayName())) { |
||||
approved=true; |
||||
} |
||||
} else { |
||||
//Has to come from console.
|
||||
approved=true; |
||||
} |
||||
return approved; |
||||
} |
||||
|
||||
public static void sendMessage(ICommandSender p, String message) { |
||||
if (p instanceof EntityPlayer) { |
||||
EntityPlayer pl = (EntityPlayer)p; |
||||
pl.addChatComponentMessage(new ChatComponentText(message)); |
||||
} else { |
||||
System.out.println(message); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void processCommand(ICommandSender p, String[] msg) { |
||||
// TODO Auto-generated method stub
|
||||
if (hasPermission(p)) { |
||||
switch(msg.length) { |
||||
case 1:{ |
||||
switch (msg[0]) { |
||||
case "addAdmin":{ |
||||
sendMessage(p,"addAdmin <name>"); |
||||
}break; |
||||
case "removeAdmin":{ |
||||
sendMessage(p,"removeAdmin <name>"); |
||||
}break; |
||||
case "addBuff":{ |
||||
sendMessage(p,"addBuff <id> <lv> <duration>"); |
||||
}break; |
||||
case "removeBuff":{ |
||||
sendMessage(p,"removeBuff <id>"); |
||||
}break; |
||||
case "displayBuffs":{ |
||||
if (p instanceof EntityPlayer) { |
||||
EntityPlayer pl = (EntityPlayer) p; |
||||
PlayerData pd = main.getPlayerData(pl.getDisplayName()); |
||||
int i=0; |
||||
for (Buff buff : pd.getBuffs()) { |
||||
sendMessage(p,"Buff "+i+": ID:"+buff.getID()+",Level:"+buff.getLevel()+",Duration:"+buff.getDuration()); |
||||
i++; |
||||
} |
||||
} |
||||
}break; |
||||
default:{ |
||||
sendMessage(p,"Unknown Command."); |
||||
} |
||||
} |
||||
}break; |
||||
case 2:{ |
||||
switch (msg[0]) { |
||||
case "addAdmin":{ |
||||
boolean found=false; |
||||
boolean found2=false; |
||||
for (String s2 : main.AdminList) { |
||||
if (msg[1].equalsIgnoreCase(s2)) { |
||||
//main.AdminList.remove(s2);
|
||||
//sendMessage(p,"Removed player "+msg[1]+" from list of Admins.");
|
||||
found2=true; |
||||
break; |
||||
} |
||||
} |
||||
if (!found2) { |
||||
EntityPlayer pl = PlayerData.getPlayer(msg[1]); |
||||
if (pl!=null && pl.getDisplayName().equalsIgnoreCase(msg[1])) { |
||||
//sendMessage(p,"Comparing "+msg[1]+" to "+s);
|
||||
main.AdminList.add(PlayerData.getPlayer(msg[1]).getDisplayName()); |
||||
sendMessage(p,"Added player "+msg[1]+" to list of Admins."); |
||||
found=true; |
||||
break; |
||||
} |
||||
} else { |
||||
sendMessage(p,"Player "+msg[1]+" already added to admin list."); |
||||
} |
||||
if (!found && !found2) {sendMessage(p,"Could not find player "+msg[1]+".");} |
||||
}break; |
||||
case "removeAdmin":{ |
||||
boolean found=false; |
||||
for (String s : main.AdminList) { |
||||
if (msg[1].equalsIgnoreCase(s)) { |
||||
main.AdminList.remove(s); |
||||
sendMessage(p,"Removed player "+msg[1]+" from list of Admins."); |
||||
found=true; |
||||
break; |
||||
} |
||||
} |
||||
if (!found) {sendMessage(p,"Could not find player "+msg[1]+".");} |
||||
}break; |
||||
case "removeBuff":{ |
||||
if (p instanceof EntityPlayer) { |
||||
sendMessage(p,"removeBuff "+msg[1]); |
||||
EntityPlayer pl = (EntityPlayer)p; |
||||
PlayerData pd = main.getPlayerData(pl.getDisplayName()); |
||||
if (pd!=null) { |
||||
pd.removeBuff(Integer.valueOf(msg[1])); |
||||
} else { |
||||
sendMessage(p,"Could not remove buff from Player "+pl.getDisplayName()); |
||||
} |
||||
} |
||||
}break; |
||||
default:{ |
||||
sendMessage(p,"Unknown Command."); |
||||
} |
||||
} |
||||
}break; |
||||
case 4:{ |
||||
switch (msg[0]) { |
||||
case "addBuff":{ |
||||
if (p instanceof EntityPlayer) { |
||||
sendMessage(p,"addBuff "+msg[1]+" "+msg[2]+" "+msg[3]); |
||||
EntityPlayer pl = (EntityPlayer)p; |
||||
PlayerData pd = main.getPlayerData(pl.getDisplayName()); |
||||
if (pd!=null) { |
||||
pd.applyBuff(Integer.valueOf(msg[1]), Integer.valueOf(msg[2]), Integer.valueOf(msg[3])); |
||||
} else { |
||||
sendMessage(p,"Could not add buff to Player "+pl.getDisplayName()); |
||||
} |
||||
} else { |
||||
sendMessage(p,"Can only be done to a player."); |
||||
} |
||||
}break; |
||||
default:{ |
||||
sendMessage(p,"Unknown Command."); |
||||
} |
||||
} |
||||
}break; |
||||
default:{ |
||||
sendMessage(p,"Unknown Command."); |
||||
} |
||||
} |
||||
} else { |
||||
sendMessage(p,EnumChatFormatting.RED+"You do not have permissions to do this."); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCommandSenderUseCommand(ICommandSender p) { |
||||
if (hasPermission(p)) { |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,37 @@ |
||||
package org.sig.jobs.Commands; |
||||
|
||||
import java.text.NumberFormat; |
||||
|
||||
import net.minecraft.command.CommandBase; |
||||
import net.minecraft.command.ICommandSender; |
||||
import net.minecraft.entity.player.EntityPlayer; |
||||
import net.minecraft.server.MinecraftServer; |
||||
import net.minecraft.util.ChatComponentText; |
||||
import net.minecraft.util.EnumChatFormatting; |
||||
|
||||
public class TimeCommandHandler extends CommandBase { |
||||
|
||||
@Override |
||||
public String getCommandName() { |
||||
// TODO Auto-generated method stub
|
||||
return "servertime"; |
||||
} |
||||
|
||||
@Override |
||||
public String getCommandUsage(ICommandSender p) { |
||||
// TODO Auto-generated method stub
|
||||
return "/servertime - Returns the current server time."; |
||||
} |
||||
|
||||
@Override |
||||
public void processCommand(ICommandSender p, String[] msg) { |
||||
// TODO Auto-generated method stub
|
||||
AdminCommandHandler.sendMessage(p, "Current Server Time: "+EnumChatFormatting.GRAY+MinecraftServer.getServer().getTickCounter()); |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCommandSenderUseCommand(ICommandSender p) { |
||||
return true; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,203 @@ |
||||
package org.sig.jobs; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.UUID; |
||||
|
||||
import org.sig.jobs.Players.Buff; |
||||
|
||||
import net.minecraft.entity.player.EntityPlayer; |
||||
import net.minecraft.server.MinecraftServer; |
||||
|
||||
/** |
||||
* A structure that defines data for each entering player. |
||||
* @author sigonasr2 |
||||
* |
||||
*/ |
||||
public class PlayerData { |
||||
UUID id; //Stores the ID this PlayerData refers to.
|
||||
String name; //The player's name.
|
||||
List<Buff> buffs; //A list of buffs this PlayerData contains.
|
||||
|
||||
|
||||
/** |
||||
* Returns the player instance tied to this PlayerData. |
||||
* @return Will return null if it cannot find the player! |
||||
*/ |
||||
EntityPlayer getPlayer() { |
||||
//return MinecraftServer.getServer().getEntityWorld().getPlayerEntityByName(name);
|
||||
return getPlayer(id); |
||||
} |
||||
|
||||
//@Deprecated
|
||||
/** |
||||
* Returns a player instance given a UUID. |
||||
* @param id The UUID. |
||||
* @return Will return null if it cannot find the player! |
||||
*/ |
||||
public static EntityPlayer getPlayer(UUID id) { |
||||
MinecraftServer serv = MinecraftServer.getServer(); |
||||
List<EntityPlayer> playerEntities = serv.getEntityWorld().playerEntities; |
||||
for (EntityPlayer p : playerEntities) { |
||||
//System.out.println("Comparing "+p.getUniqueID()+" to "+id+".");
|
||||
if (p.getUniqueID().equals(id)) { |
||||
return p; |
||||
} |
||||
} |
||||
/* |
||||
for (int i=0;i<playerEntities.size();i++) { |
||||
if (playerEntities.get(i) instanceof EntityPlayer) { |
||||
EntityPlayer p = (EntityPlayer)playerEntities.get(i); |
||||
if (p.getUniqueID().equals(id)) { |
||||
return p; |
||||
} |
||||
} |
||||
}*/ |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* Returns a player instance given a name. |
||||
* @param name The name of the player. |
||||
* @return |
||||
*/ |
||||
public static EntityPlayer getPlayer(String name) { |
||||
|
||||
MinecraftServer serv = MinecraftServer.getServer(); |
||||
List<EntityPlayer> playerEntities = serv.getEntityWorld().playerEntities; |
||||
for (EntityPlayer p : playerEntities) { |
||||
//System.out.println("Comparing "+p.getUniqueID()+" to "+id+".");
|
||||
if (p.getDisplayName().equalsIgnoreCase(name)) { |
||||
return p; |
||||
} |
||||
} |
||||
/* |
||||
for (int i=0;i<playerEntities.size();i++) { |
||||
if (playerEntities.get(i) instanceof EntityPlayer) { |
||||
EntityPlayer p = (EntityPlayer)playerEntities.get(i); |
||||
if (p.getUniqueID().equals(id)) { |
||||
return p; |
||||
} |
||||
} |
||||
}*/ |
||||
return null; |
||||
//return MinecraftServer.getServer().getEntityWorld().getPlayerEntityByName(name);
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param name |
||||
*/ |
||||
public PlayerData(UUID id) { |
||||
this.id=id; |
||||
//Get the player's name.
|
||||
//this.name = getPlayer(id).getDisplayName();
|
||||
buffs = new ArrayList<Buff>(); |
||||
} |
||||
|
||||
@Deprecated |
||||
public PlayerData(String name) { |
||||
this.id=MinecraftServer.getServer().getEntityWorld().getPlayerEntityByName(name).getUniqueID(); |
||||
//Get the player's name.
|
||||
//this.name = MinecraftServer.getServer().getEntityWorld().getPlayerEntityByName(name).getDisplayName();
|
||||
buffs = new ArrayList<Buff>(); |
||||
} |
||||
|
||||
/** |
||||
* Returns the UUID of the player tied to this PlayerData. |
||||
* @return |
||||
*/ |
||||
public UUID getID() { |
||||
return id; |
||||
} |
||||
|
||||
/** |
||||
* Returns the buff array of this player. |
||||
* @return |
||||
*/ |
||||
public List<Buff> getBuffs() { |
||||
return buffs; |
||||
} |
||||
|
||||
/** |
||||
* Returns true if this player has a certain buff. False otherwise. |
||||
* @param id The ID of the buff we are searching for. See main.BUFF_* |
||||
* @return |
||||
*/ |
||||
public boolean hasBuff(int id) { |
||||
for (int i=0;i<buffs.size();i++) { |
||||
if (buffs.get(i).getID()==id) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Returns the Buff object for a particular buff on the player. |
||||
* @param id The ID of the buff we are searching for. See main.BUFF_* |
||||
* @return Returns null if it cannot find it. |
||||
*/ |
||||
public Buff getBuff(int id) { |
||||
for (int i=0;i<buffs.size();i++) { |
||||
if (buffs.get(i).getID()==id) { |
||||
return buffs.get(i); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* Applies a buff to this PlayerData object. If the buff already exists, it will |
||||
* attempt to override it if the lv of this buff is >= the current buff. You can |
||||
* forceOverride this by setting the appropriate argument to true. Returns whether it worked or not. |
||||
* @param id The ID of the buff. See main.BUFF_* |
||||
* @param lv The Level/Power of the buff. |
||||
* @param duration The duration (in ticks) of this buff. |
||||
*/ |
||||
public boolean applyBuff(int id, int lv, int duration) { |
||||
return applyBuff(id,lv,duration,false); |
||||
} |
||||
|
||||
/** |
||||
* Applies a buff to this PlayerData object. If the buff already exists, it will |
||||
* attempt to override it if the lv of this buff is >= the current buff. You can |
||||
* forceOverride this by setting the appropriate argument to true. Returns whether it worked or not. |
||||
* @param id The ID of the buff. See main.BUFF_* |
||||
* @param lv The Level/Power of the buff. |
||||
* @param duration The duration (in ticks) of this buff. |
||||
* @param forceOverride Whether or not to forcefully apply the buff, regardless of current buff level. |
||||
*/ |
||||
public boolean applyBuff(int id, int lv, int duration, boolean forceOverride) { |
||||
if (hasBuff(id)) { |
||||
System.out.println("Found this buff."); |
||||
Buff buff = getBuff(id); |
||||
if (buff!=null && (forceOverride || buff.getLevel()<=lv)) { |
||||
//We're allowed to override it.
|
||||
buffs.remove(buff); |
||||
buffs.add(new Buff(id,lv,duration)); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} else { |
||||
buffs.add(new Buff(id,lv,duration)); |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Attempts to remove a buff on this PlayerData object. Returns whether it worked or not. |
||||
* @param id The ID of the buff. See main.BUFF_* |
||||
* @return |
||||
*/ |
||||
public boolean removeBuff(int id) { |
||||
if (hasBuff(id)) { |
||||
Buff buff = getBuff(id); |
||||
buffs.remove(buff); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
package org.sig.jobs.Players; |
||||
|
||||
import net.minecraft.server.MinecraftServer; |
||||
|
||||
|
||||
/** |
||||
* A buff structure contains a duration, and a buff ID, which determines what type of buff it is. |
||||
* @author sigonasr2 |
||||
* |
||||
*/ |
||||
public class Buff { |
||||
int id; |
||||
int lv; //Level/Potency of the buff.
|
||||
int timeoff; //The server tick time when the buff wears out.
|
||||
int duration; //Saves the duration of this buff.
|
||||
|
||||
public Buff(int id, int level,int duration) { |
||||
this.id=id; |
||||
this.lv=level; |
||||
this.timeoff=MinecraftServer.getServer().getTickCounter()+duration; |
||||
this.duration=duration; |
||||
} |
||||
|
||||
/** |
||||
* Returns the ID of this buff. |
||||
*/ |
||||
public int getID() { |
||||
return id; |
||||
} |
||||
|
||||
/** |
||||
* Returns the level of this buff. |
||||
*/ |
||||
public int getLevel() { |
||||
return lv; |
||||
} |
||||
|
||||
/** |
||||
* Returns the total duration of this buff. |
||||
* @return |
||||
*/ |
||||
public int getDuration() { |
||||
return duration; |
||||
} |
||||
|
||||
/** |
||||
* Returns the time this buff has left (in ticks). |
||||
*/ |
||||
public int getTimeRemaining() { |
||||
return timeoff-MinecraftServer.getServer().getTickCounter(); |
||||
} |
||||
|
||||
/** |
||||
* Returns the server time when this buff wears off. |
||||
*/ |
||||
public int getTimeOff() { |
||||
return timeoff; |
||||
} |
||||
} |
Loading…
Reference in new issue