Worked a bit on a new terminal system

This is more of me starting back up on global access lists for sentry
guns and chests. The idea right now is to create a system like bukkit
plugin permissions has. In which a player can create a group, assign
command node, and then assign players. As well can assign direct command
nodes to the player user instance. These groups will be managed from a
GUI that can be access anytime. The data will be saved to a NBT file in
the map, and can be access by any object. Objects will not save a copy
of the list but will request it to be loaded.
This commit is contained in:
DarkGuardsman 2013-10-08 06:11:43 -04:00
parent 5c1d3bdb48
commit d620e24ba0
10 changed files with 213 additions and 7 deletions

View file

@ -0,0 +1,59 @@
package com.builtbroken.common;
import java.util.ArrayList;
import java.util.List;
/** Generic class for link objects of the same class type to each other.
*
* @author Robert Seifert */
public class Group<J>
{
private String groupName;
protected List<J> memebers = new ArrayList<J>();
public Group(String name, J... js)
{
this.groupName = name;
if (js != null)
{
for (J obj : js)
{
this.addMemeber(obj);
}
}
}
protected boolean isValid(J obj)
{
return obj != null && memebers.contains(obj);
}
public boolean addMemeber(J obj)
{
if (this.isValid(obj))
{
return memebers.add(obj);
}
return false;
}
public boolean removeMemeber(J obj)
{
return memebers.remove(obj);
}
public boolean isMemeber(J obj)
{
return memebers.contains(obj);
}
public String name()
{
return this.groupName;
}
public void setName(String name)
{
this.groupName = name;
}
}

View file

@ -0,0 +1,19 @@
package com.builtbroken.common;
/** Class to track a user. Mainly used to create groups of users
*
* @author Robert Seifert */
public class User
{
protected String username;
protected User()
{
}
public User(String username)
{
this.username = username;
}
}

View file

@ -44,7 +44,10 @@ public class UnitHelper
{ {
String editedString = input; String editedString = input;
char[] chars = input.toCharArray(); char[] chars = input.toCharArray();
String number = ""; Object unitEnumValue = null;
String numberAsString = "";
float number = 0;
String units = ""; String units = "";
int toPowerOf = 1; int toPowerOf = 1;
int timeTenToPowerOF = 1; int timeTenToPowerOF = 1;
@ -55,12 +58,20 @@ public class UnitHelper
char c = chars[i]; char c = chars[i];
if (numbers.contains(c)) if (numbers.contains(c))
{ {
number += c; numberAsString += c;
} }
else else
{ {
break; break;
} }
}
try
{
number = Float.parseFloat(numberAsString);
}
catch (Exception e)
{
} }
editedString.replaceAll("[0-9]", ""); editedString.replaceAll("[0-9]", "");
chars = editedString.toCharArray(); chars = editedString.toCharArray();
@ -79,6 +90,8 @@ public class UnitHelper
} }
} }
//TODO detect units
return new Pair<Object, Float>(unitEnumValue, number);
} }
return def; return def;

View file

@ -2,7 +2,6 @@ package dark.api;
import java.util.List; import java.util.List;
import dark.core.prefab.access.UserAccess;
/** Used by any object that needs to restrict access to it by a set of usernames /** Used by any object that needs to restrict access to it by a set of usernames
* *

View file

@ -0,0 +1,50 @@
package dark.api;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import com.builtbroken.common.Group;
/** Used by a terminal to track what users are part of each group. As well used to setup access
* points to the terminal.
*
* @author DarkGuardsman */
public class TerminalGroup extends Group<TerminalUser>
{
public TerminalGroup(String name, TerminalUser... js)
{
super(name, js);
}
public NBTTagCompound save(NBTTagCompound nbt)
{
nbt.setString("groupName", this.name());
NBTTagList usersTag = new NBTTagList();
for (TerminalUser user : this.memebers)
{
if (!user.isTempary)
{
NBTTagCompound accessData = new NBTTagCompound();
user.save(accessData);
usersTag.appendTag(accessData);
}
}
nbt.setTag("Users", usersTag);
return nbt;
}
public void load(NBTTagCompound nbt)
{
this.setName(nbt.getString("groupName"));
NBTTagList userList = nbt.getTagList("users");
for (short i = 0; i < userList.tagCount(); ++i)
{
NBTTagCompound var4 = (NBTTagCompound) userList.tagAt(i);
memebers.add(TerminalUser.loadFromNBT(var4));
}
}
}

View file

@ -0,0 +1,66 @@
package dark.api;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import com.builtbroken.common.User;
/** Used to define a users access to a terminal based object.
*
* @author DarkGuardsman */
public class TerminalUser extends User
{
protected boolean isTempary = false;
protected NBTTagCompound extraData;
public TerminalUser(String username)
{
super(username);
}
public TerminalUser(EntityPlayer player)
{
super(player.username);
}
private TerminalUser()
{
}
public NBTTagCompound save(NBTTagCompound nbt)
{
nbt.setString("username", this.username);
nbt.setCompoundTag("extraData", this.userData());
return nbt;
}
public TerminalUser load(NBTTagCompound nbt)
{
this.username = nbt.getString("username");
this.extraData = nbt.getCompoundTag("extraData");
return this;
}
public static TerminalUser loadFromNBT(NBTTagCompound nbt)
{
return new TerminalUser().load(nbt);
}
public TerminalUser setTempary(boolean si)
{
this.isTempary = si;
return this;
}
/** Used to add other data to the user */
public NBTTagCompound userData()
{
if (this.extraData == null)
{
this.extraData = new NBTTagCompound();
}
return this.extraData;
}
}

View file

@ -1,11 +1,10 @@
package dark.core.prefab.access; package dark.api;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import dark.api.AccessLevel;
public class UserAccess public class UserAccess
{ {

View file

@ -9,6 +9,7 @@ import java.util.Map.Entry;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import dark.api.AccessLevel; import dark.api.AccessLevel;
import dark.api.UserAccess;
import dark.core.prefab.helpers.NBTFileLoader; import dark.core.prefab.helpers.NBTFileLoader;
public class GlobalAccessManager public class GlobalAccessManager

View file

@ -19,9 +19,9 @@ import universalelectricity.core.vector.Vector2;
import universalelectricity.prefab.vector.Region2; import universalelectricity.prefab.vector.Region2;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import dark.api.UserAccess;
import dark.core.interfaces.IScroll; import dark.core.interfaces.IScroll;
import dark.core.prefab.ModPrefab; import dark.core.prefab.ModPrefab;
import dark.core.prefab.access.UserAccess;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class GuiGlobalList extends GuiContainer implements IScroll public class GuiGlobalList extends GuiContainer implements IScroll

View file

@ -13,9 +13,9 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.tile.TileEntityAdvanced; import universalelectricity.prefab.tile.TileEntityAdvanced;
import dark.api.AccessLevel; import dark.api.AccessLevel;
import dark.api.ISpecialAccess; import dark.api.ISpecialAccess;
import dark.api.UserAccess;
import dark.core.interfaces.IExternalInv; import dark.core.interfaces.IExternalInv;
import dark.core.interfaces.IInvBox; import dark.core.interfaces.IInvBox;
import dark.core.prefab.access.UserAccess;
import dark.core.prefab.invgui.InvChest; import dark.core.prefab.invgui.InvChest;
/** Prefab for simple object who only need basic inv support and nothing more /** Prefab for simple object who only need basic inv support and nothing more