diff --git a/SigJobs/java/org/sig/jobs/Commands/AdminCommandHandler.java b/SigJobs/java/org/sig/jobs/Commands/AdminCommandHandler.java new file mode 100644 index 0000000..d4cea14 --- /dev/null +++ b/SigJobs/java/org/sig/jobs/Commands/AdminCommandHandler.java @@ -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 "); + }break; + case "removeAdmin":{ + sendMessage(p,"removeAdmin "); + }break; + case "addBuff":{ + sendMessage(p,"addBuff "); + }break; + case "removeBuff":{ + sendMessage(p,"removeBuff "); + }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; + } + } + +} diff --git a/SigJobs/java/org/sig/jobs/Commands/TimeCommandHandler.java b/SigJobs/java/org/sig/jobs/Commands/TimeCommandHandler.java new file mode 100644 index 0000000..df22c03 --- /dev/null +++ b/SigJobs/java/org/sig/jobs/Commands/TimeCommandHandler.java @@ -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; + } + +} diff --git a/SigJobs/java/org/sig/jobs/EntityHandler.java b/SigJobs/java/org/sig/jobs/EntityHandler.java index 16d3eb6..9b44627 100644 --- a/SigJobs/java/org/sig/jobs/EntityHandler.java +++ b/SigJobs/java/org/sig/jobs/EntityHandler.java @@ -2,7 +2,9 @@ package org.sig.jobs; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.entity.living.LivingHurtEvent; public class EntityHandler { @SubscribeEvent @@ -16,12 +18,34 @@ public class EntityHandler { //Initialize jobs. for (int i=0;i 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 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 = 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(); + } + + @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(); + } + + /** + * 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 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= 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; + } + } +} diff --git a/SigJobs/java/org/sig/jobs/Players/Buff.java b/SigJobs/java/org/sig/jobs/Players/Buff.java new file mode 100644 index 0000000..9f76aa2 --- /dev/null +++ b/SigJobs/java/org/sig/jobs/Players/Buff.java @@ -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; + } +} \ No newline at end of file diff --git a/SigJobs/java/org/sig/jobs/main.java b/SigJobs/java/org/sig/jobs/main.java index 052e8e9..d1484c3 100644 --- a/SigJobs/java/org/sig/jobs/main.java +++ b/SigJobs/java/org/sig/jobs/main.java @@ -3,9 +3,12 @@ package org.sig.jobs; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.UUID; +import org.sig.jobs.Commands.AdminCommandHandler; import org.sig.jobs.Commands.JobsCommandHandler; import org.sig.jobs.Commands.MoneyCommandHandler; +import org.sig.jobs.Commands.TimeCommandHandler; import net.minecraft.command.ICommandManager; import net.minecraft.command.ServerCommandManager; @@ -42,11 +45,17 @@ public class main { "GREEN", "Woodcutter" }; + public static final int BUFF_DAMAGEREDUCTION = 0; + public static final int BUFF_DAMAGEINCREASE = 0; + public static double STARTMONEY = 100; public static final String MODID = "SigJobs"; public static final String VERSION = "0.0.1"; + public static List PlayerList; + public static List AdminList; + public static int JOBMAXPLAYERS = 0; //The maximum amount of players that can occupy one job. /*This is a factor of the total number of players that have played on the server.*/ @@ -100,6 +109,45 @@ public class main { public static List JOB_INFO14; public static List JOB_STATINFO14; + /** + * Returns the PlayerData instance of a player. + * @param id The UUID of the player to search for. + * @return Returns null if this fails. + */ + public PlayerData getPlayerData(UUID id) { + for (PlayerData i : PlayerList) { + if (i.getID().equals(id)) { + return i; + } + } + /* + for (int i=0;i(); - JOB_INFO6.add(EnumChatFormatting.YELLOW+"Cook"); + JOB_INFO6.add(EnumChatFormatting.GOLD+"Digger"); JOB_INFO6.add(""); - JOB_INFO6.add("A Cook can create delicacies that have interesting effects beyond just keeping yourself full."); + JOB_INFO6.add("A Digger"); JOB_INFO6.add(""); JOB_INFO6.add("COOK:"); JOB_INFO6.add("There are a large abundance of foods to create. Ones that have more steps and ingredients give much more than simpler recipes."); @@ -338,6 +386,9 @@ public class main { JOB_STATINFO14.add("Lv38: -30% damage reduction"); JOB_STATINFO14.add("Lv40: Trees can be cut down in one click by right-clicking with an axe."); + PlayerList = new ArrayList(); + AdminList = new ArrayList(); + Configuration config = new Configuration(new File("SigJobs.cfg")); config.load(); //Create/load our config. for (int i=0;i