diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/api/SnitchListQualifier.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/api/SnitchListQualifier.java index f3aa238..643897e 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/api/SnitchListQualifier.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/api/SnitchListQualifier.java @@ -8,6 +8,8 @@ */ public class SnitchListQualifier { + public static final int MAX_QUALIFIER_TEXT_LENGTH = Integer.MAX_VALUE; + private static final String CULL_TIME_TOKEN = "cull_time"; private static final String WORLD_TOKEN = "world"; private static final String GROUP_TOKEN = "group"; diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditColorGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditColorGui.java index bafacc5..f4d17cd 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditColorGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditColorGui.java @@ -40,6 +40,8 @@ public EditColorGui(GuiScreen cancelToScreen, Color baseColor, String titleText, this.titleWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(titleText); } + private static final int MAX_COLOR_TEXT_LENGTH = 3; + public void initGui() { greenWidth = mc.fontRendererObj.getStringWidth("Green"); @@ -51,24 +53,21 @@ public void initGui() int rgbBoxWidth = (width-GuiConstants.STANDARD_SEPARATION_DISTANCE)/3; int buttonWidth = (width-GuiConstants.STANDARD_SEPARATION_DISTANCE)/3; - this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); + this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH); redBox.setClamp(0,255); - redBox.setMaxStringLength(3); redBox.setText(Integer.toString(baseColor.getRedInt())); redBox.setFocused(true); yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE); - this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); + this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH); greenBox.setClamp(0,255); - greenBox.setMaxStringLength(3); greenBox.setText(Integer.toString(baseColor.getGreenInt())); yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE); - this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); + this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH); blueBox.setClamp(0,255); - blueBox.setMaxStringLength(3); blueBox.setText(Integer.toString(baseColor.getBlueInt())); this.buttonList.clear(); diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditDescriptionGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditDescriptionGui.java new file mode 100644 index 0000000..aa147a0 --- /dev/null +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditDescriptionGui.java @@ -0,0 +1,11 @@ +package com.gmail.nuclearcat1337.snitch_master.gui; + +import net.minecraft.client.gui.GuiScreen; + +/** + * Created by Mr_Little_Kitty on 1/7/2017. + */ +public class EditDescriptionGui extends GuiScreen +{ + +} diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditStringGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditStringGui.java index 771c771..458cdb3 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditStringGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditStringGui.java @@ -40,8 +40,7 @@ public void initGui() int xPos = (this.width/2) - (GuiConstants.LARGE_TEXBOX_LENGTH/2); int yPos = (this.height/2) - (GuiConstants.STANDARD_TEXTBOX_HEIGHT) - (GuiConstants.STANDARD_SEPARATION_DISTANCE/2); - stringBox = new TextBox(editString,fontRendererObj,xPos,yPos,GuiConstants.LARGE_TEXBOX_LENGTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false); - stringBox.setMaxStringLength(maxStringLength); + stringBox = new TextBox(editString,fontRendererObj,xPos,yPos,GuiConstants.LARGE_TEXBOX_LENGTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false,maxStringLength); stringBox.setFocused(true); this.buttonList.clear(); diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java index 7a09c87..b6864a6 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java @@ -44,6 +44,9 @@ public NewSnitchListGui(GuiScreen cancelToScreen, SnitchMaster snitchMaster) this.snitchMaster = snitchMaster; } + private static final int MAX_NAME_TEXT_LENGTH = 20; + private static final int MAX_COLOR_TEXT_LENGTH = 3; + public void initGui() { qualifierBoxWidth = mc.fontRendererObj.getStringWidth(SnitchList.MAX_NAME_CHARACTERS+"WWW"); //TODO---Idk this is kind of just an arbitrary width @@ -56,33 +59,28 @@ public void initGui() int yPos = (this.height / 2) - (GuiConstants.STANDARD_BUTTON_HEIGHT*3) - (GuiConstants.STANDARD_SEPARATION_DISTANCE) ; int xPos = (this.width/2) - (nameBoxWidth/2); - nameBox = new TextBox("",fontRendererObj,xPos,yPos,nameBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false); - nameBox.setMaxStringLength(20); + nameBox = new TextBox("",fontRendererObj,xPos,yPos,nameBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false,MAX_NAME_TEXT_LENGTH); nameBox.setFocused(true); yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE); xPos = nameBox.xPosition; - this.qualifierBox = new TextBox("",fontRendererObj,xPos,yPos,qualifierBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false); - qualifierBox.setMaxStringLength(100); + this.qualifierBox = new TextBox("",fontRendererObj,xPos,yPos,qualifierBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false,SnitchListQualifier.MAX_QUALIFIER_TEXT_LENGTH); yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE); - this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); + this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH); redBox.setClamp(0,255); - redBox.setMaxStringLength(3); yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE); - this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); + this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH); greenBox.setClamp(0,255); - greenBox.setMaxStringLength(3); yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE); - this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); + this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH); blueBox.setClamp(0,255); - blueBox.setMaxStringLength(3); this.buttonList.clear(); diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/TargetedSnitchUpdateGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/TargetedSnitchUpdateGui.java index 236c57b..38e27e7 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/TargetedSnitchUpdateGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/TargetedSnitchUpdateGui.java @@ -44,15 +44,13 @@ public void initGui() int yPos = (this.height / 2) - (GuiConstants.STANDARD_TEXTBOX_HEIGHT/2); int xPos = (this.width/2) - GuiConstants.STANDARD_SEPARATION_DISTANCE/2 - BOX_AND_BUTTON_WIDTH; - startIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); - startIndexBox.setMaxStringLength(3); + startIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,3); startIndexBox.setClamp(0,999); startIndexBox.setFocused(true); xPos += (startIndexBox.width + GuiConstants.STANDARD_SEPARATION_DISTANCE); - stopIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false); - stopIndexBox.setMaxStringLength(3); + stopIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,3); stopIndexBox.setClamp(0,999); yPos += GuiConstants.STANDARD_TEXTBOX_HEIGHT + GuiConstants.STANDARD_SEPARATION_DISTANCE; diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/controls/ControlGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/controls/ControlGui.java new file mode 100644 index 0000000..d056dcc --- /dev/null +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/controls/ControlGui.java @@ -0,0 +1,11 @@ +package com.gmail.nuclearcat1337.snitch_master.gui.controls; + +import net.minecraft.client.gui.GuiControls; +import net.minecraft.client.gui.GuiTextField; + +/** + * Created by Mr_Little_Kitty on 1/7/2017. + */ +public class ControlGui +{ +} diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/controls/TextBox.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/controls/TextBox.java index 3ff666a..c2137c4 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/controls/TextBox.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/controls/TextBox.java @@ -13,9 +13,10 @@ public class TextBox extends GuiTextField private Integer clampedMinimum; private Integer clampedMaximum; - public TextBox(String text, FontRenderer renderer, int x, int y, int width, int height, boolean numeric, boolean allowNegative) + public TextBox(String text, FontRenderer renderer, int x, int y, int width, int height, boolean numeric, boolean allowNegative, int maxStringLength) { super(0,renderer,x,y,width,height); + super.setMaxStringLength(maxStringLength); super.setText(text); this.number = numeric; this.allowNegative = allowNegative; diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/snitchtable/SnitchDescriptionColumn.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/snitchtable/SnitchDescriptionColumn.java new file mode 100644 index 0000000..5b6da5b --- /dev/null +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/snitchtable/SnitchDescriptionColumn.java @@ -0,0 +1,88 @@ +package com.gmail.nuclearcat1337.snitch_master.gui.snitchtable; + +import com.gmail.nuclearcat1337.snitch_master.gui.tables.TableColumn; +import com.gmail.nuclearcat1337.snitch_master.snitches.Snitch; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; + +import java.util.List; + +/** + * Created by Mr_Little_Kitty on 1/7/2017. + */ +public class SnitchDescriptionColumn implements TableColumn +{ + private static Minecraft mc; + + public SnitchDescriptionColumn() + { + mc = Minecraft.getMinecraft(); + } + + @Override + public GuiButton[] prepareEntry(Snitch item) + { + return null; + } + + @Override + public String getColumnName() + { + return "Description"; + } + + @Override + public boolean doBoundsCheck() + { + return true; + } + + @Override + public void clicked(Snitch item, boolean leftClick, int xPos, int yPos, GuiButton[] buttons, GuiScreen parentScreen, int slotIndex) + { + + } + + @Override + public void released(Snitch item, int xPos, int yPos, GuiButton[] buttons, GuiScreen parentScreen,int slotIndex) + { + + } + + @Override + public void draw(Snitch snitch, int xPos, int yPos, int columnWidth, int slotHeight, GuiButton[] buttons,int slotIndex, int mouseX, int mouseY) + { + String text = snitch.getDescription() == null ? "No Description" : "Hover to view"; + int yFinal = yPos + ((slotHeight - mc.fontRendererObj.FONT_HEIGHT) /2); + int nameWidth = mc.fontRendererObj.getStringWidth(text); + int namePos = xPos + (columnWidth /2) - (nameWidth/2); + mc.fontRendererObj.drawString(text, namePos ,yFinal, 16777215); + } + + @Override + public int getDrawWidth(Snitch snitch) + { + String text = snitch.getDescription() == null ? "No Description" : "Hover to view"; + return mc.fontRendererObj.getStringWidth(text); + } + + + @Override + public List hover(Snitch snitch, int xPos, int yPos) + { + return snitch.getDescription(); + } + + @Override + public boolean canSort() + { + return false; + } + + @Override + public int compare(Snitch snitch, Snitch other) + { + return 0; + } +} diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/snitchtable/SnitchesTable.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/snitchtable/SnitchesTable.java index bae79d6..2cf3052 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/snitchtable/SnitchesTable.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/snitchtable/SnitchesTable.java @@ -64,12 +64,13 @@ protected Collection,Boolean>> initializeColumns() columns.add(packageValues(new SnitchNameColumn(), true)); columns.add(packageValues(new SnitchGroupColumn(), true)); + columns.add(packageValues(new SnitchDescriptionColumn(), true)); columns.add(packageValues(new SnitchCullTimeColumn(), false)); - columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.X), true)); - columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Y), true)); - columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Z), true)); - columns.add(packageValues(new SnitchWorldColumn(), true)); + columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.X), false)); + columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Y), false)); + columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Z), false)); + columns.add(packageValues(new SnitchWorldColumn(), false)); columns.add(packageValues(new SnitchDistanceColumn(), true)); columns.add(packageValues(new TableButtonColumn<>("Lists", "View", VIEW_LISTS_BUTTON_WIDTH, viewListsClick), true)); diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/handlers/SnitchRenderer.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/handlers/SnitchRenderer.java index 15c4884..52f781e 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/handlers/SnitchRenderer.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/handlers/SnitchRenderer.java @@ -100,6 +100,12 @@ public void renderSnitches(RenderWorldLastEvent event) } } + private static final float MIN_TEXT_RENDER_SCALE = 0.0075f; + private static final float MAX_TEXT_RENDER_SCALE = 0.04f; + + private static final float SCALE_STEP = (MAX_TEXT_RENDER_SCALE-MIN_TEXT_RENDER_SCALE)/TEXT_RENDER_DISTANCE; + + private static void RenderFloatingText(String[] text, float x, float y, float z, int color, boolean renderBlackBackground, float partialTickTime) { //Thanks to Electric-Expansion mod for the majority of this code @@ -114,8 +120,8 @@ private static void RenderFloatingText(String[] text, float x, float y, float z, float dx = x-playerX; float dy = y-playerY; float dz = z-playerZ; - //float distance = (float) Math.sqrt(dx*dx + dy*dy + dz*dz); - float scale = 0.03f; + float distance = (float) Math.sqrt(dx*dx + dy*dy + dz*dz); + float scale = MIN_TEXT_RENDER_SCALE + (distance*SCALE_STEP);//.01f; //Min font scale for max text render distance GL11.glColor4f(1f, 1f, 1f, 0.5f); GL11.glPushMatrix(); @@ -147,20 +153,8 @@ private static void RenderFloatingText(String[] text, float x, float y, float z, Tessellator tessellator = Tessellator.getInstance(); VertexBuffer worldrenderer = tessellator.getBuffer(); - //GL11.glDisable(GL11.GL_TEXTURE_2D); GlStateManager.disableTexture2D(); - /* OLD 1.8 rendering code - //worldrenderer.startDrawingQuads(); - worldrenderer.func_181668_a(7, DefaultVertexFormats.field_181709_i); //field_181707_g maybe? - - GlStateManager.color(0.0F, 0.0F, 0.0F, 0.5F); - worldrenderer.putPosition(-stringMiddle - 1, -1 + 0, 0.0D); - worldrenderer.putPosition(-stringMiddle - 1, 8 + lineHeight*text.length-lineHeight, 0.0D); - worldrenderer.putPosition(stringMiddle + 1, 8 + lineHeight*text.length-lineHeight, 0.0D); - worldrenderer.putPosition(stringMiddle + 1, -1 + 0, 0.0D); - */ - //This code taken from 1.8.8 net.minecraft.client.renderer.entity.Render.renderLivingLabel() worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); worldrenderer.pos((double) (-stringMiddle - 1), (double) (-1), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); @@ -169,7 +163,7 @@ private static void RenderFloatingText(String[] text, float x, float y, float z, worldrenderer.pos((double) (stringMiddle + 1), (double) (-1), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); tessellator.draw(); - //GL11.glEnable(GL11.GL_TEXTURE_2D); + GlStateManager.enableTexture2D(); } @@ -200,7 +194,6 @@ private void renderBox(int x, int y, int z, int radius, Color color, double alph GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glLineWidth(5.0F); - //GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); @@ -237,7 +230,6 @@ private void renderBox(int x, int y, int z, int radius, Color color, double alph GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL13.GL_MULTISAMPLE); - //GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/snitches/Snitch.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/snitches/Snitch.java index b23bf78..05cd9e1 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/snitches/Snitch.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/snitches/Snitch.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.List; /** * Created by Mr_Little_Kitty on 6/25/2016. @@ -70,6 +71,8 @@ public class Snitch extends LocatableObject */ private ArrayList attachedSnitchLists; + private List description; + /** * Creates a new Snitch and populates "Name" and "Citadel Group Name" with the default name. * @param location The location of this Snitch block. @@ -83,6 +86,7 @@ public Snitch(ILocation location, String origin) this.ctGroup = DEFAULT_NAME; this.name = DEFAULT_NAME; attachedSnitchLists = new ArrayList<>(); + description = null; } /** @@ -112,6 +116,15 @@ public double getCullTime() return cullTime; } + public void setDescription(List description) + { + this.description = description; + } + + public List getDescription() + { + return description; + } /** * Returns true if the given point if within the area covered by this Snitch block. * Returns false otherwise. @@ -280,7 +293,8 @@ public int compare(SnitchList one, SnitchList two) * The number of parameters in a comma separated value string representing a Snitch object */ private static final int NUMBER_OF_CSV_PARAMS = 8; - + private static final String CSV_SEPARATOR = ","; + private static final String DESCRIPTION_SEPARATOR = ";"; /** * Returns a string that represents the given Snitch object. * The returned string is in comma separated value form. @@ -289,14 +303,22 @@ public static String ConvertSnitchToCSV(Snitch snitch) { //x, y, z, world, oring, groupName, snitchName, cullTime StringBuilder builder = new StringBuilder(); - builder.append(snitch.location.getX()).append(','); - builder.append(snitch.location.getY()).append(','); - builder.append(snitch.location.getZ()).append(','); - builder.append(snitch.location.getWorld()).append(','); - builder.append(snitch.getOrigin()).append(','); - builder.append(snitch.getGroupName()).append(','); - builder.append(snitch.getSnitchName()).append(','); - builder.append(snitch.getCullTime()).append(','); + builder.append(snitch.location.getX()).append(CSV_SEPARATOR); + builder.append(snitch.location.getY()).append(CSV_SEPARATOR); + builder.append(snitch.location.getZ()).append(CSV_SEPARATOR); + builder.append(Scrub(snitch.location.getWorld())).append(CSV_SEPARATOR); + builder.append(Scrub(snitch.getOrigin())).append(CSV_SEPARATOR); + builder.append(Scrub(snitch.getGroupName())).append(CSV_SEPARATOR); + builder.append(Scrub(snitch.getSnitchName())).append(CSV_SEPARATOR); + builder.append(snitch.getCullTime()).append(CSV_SEPARATOR); + + List description = snitch.getDescription(); + if(description != null) + { + for(String line : description) + builder.append(Scrub(line)).append(DESCRIPTION_SEPARATOR); + } + builder.append(CSV_SEPARATOR); return builder.toString(); } @@ -309,37 +331,55 @@ public static String ConvertSnitchToCSV(Snitch snitch) public static Snitch GetSnitchFromCSV(String csv) { - String[] args = csv.split(","); - if(args.length != NUMBER_OF_CSV_PARAMS) - { - new NumberFormatException("The CSV string provided does not have the correct number of arguments for a Snitch.").printStackTrace(); - return null; - } + String[] args = csv.split(CSV_SEPARATOR); - try + //We allow one less than the correct for when we didn't have a description + if(args.length == NUMBER_OF_CSV_PARAMS || args.length == NUMBER_OF_CSV_PARAMS-1) { - int index = 0; - - int x = Integer.parseInt(args[index++]); - int y = Integer.parseInt(args[index++]); - int z = Integer.parseInt(args[index++]); - String world = args[index++]; - String origin = args[index++]; - String groupName = args[index++]; - String snitchName = args[index++]; - - if(snitchName.isEmpty()) - snitchName = DEFAULT_NAME; - - double cullTime = Double.parseDouble(args[index++]); - - Snitch snitch = new Snitch(new Location(x, y, z, world), origin, cullTime, groupName, snitchName); - - return snitch; - } - catch(Exception e) - { - return null; + try + { + int index = 0; + + int x = Integer.parseInt(args[index++]); + int y = Integer.parseInt(args[index++]); + int z = Integer.parseInt(args[index++]); + String world = Scrub(args[index++]); + String origin = Scrub(args[index++]); + String groupName = Scrub(args[index++]); + String snitchName = Scrub(args[index++]); + double cullTime = Double.parseDouble(args[index++]); + + if (snitchName.isEmpty()) + snitchName = DEFAULT_NAME; + + Snitch snitch = new Snitch(new Location(x, y, z, world), origin, cullTime, groupName, snitchName); + + //If there is an argument for the description + if(args.length > index) + { + String descriptionCompressed = args[index++]; + if (!descriptionCompressed.isEmpty()) + { + String[] lines = descriptionCompressed.split(DESCRIPTION_SEPARATOR); + ArrayList description = new ArrayList<>(lines.length); + for (int i = 0; i < lines.length; i++) + description.set(i,Scrub(lines[i])); + snitch.setDescription(description); + } + } + + return snitch; + } + catch (Exception e) + { + return null; + } } + return null; + } + + private static String Scrub(String string) + { + return string.replace(CSV_SEPARATOR,"").replace(DESCRIPTION_SEPARATOR,""); } }