Hello, I am getting some weird stuff submitted into a database. This is the code (i've removed some of the other stuff) I have imported AdamKi11s Plugin: Code: import couk.Adamki11s.SQL.SyncSQL; Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = null; if (sender instanceof Player) { player = (Player) sender; } if(cmd.getName().equalsIgnoreCase("support")) { if (player == null) { sender.sendMessage("[ICU] This command must be run in game only."); } else { if (args.length < 2) { sender.sendMessage("§7[§5ICU§7] You must enter some more details or else the ticket will be ignored. Then you will be laughed at, ICU doesn't want to see this. ICU Loves you."); } else { final Random generator = new Random(); Object id = null; @SuppressWarnings("null") Date date = new Date((long) id); SyncSQL sql = new SyncSQL("216.244.84.162","myfallen_ticket","xxxxx","xxxx"); sql.initialise(); sql.standardQuery("INSERT INTO `myfallen_ticket`.`tickets` (`id`, `sender`, `body`, `submit_date`, `ticketID`, `currentStatus`, `priority`, `assignedTo`, `title`) VALUES (NULL, '"+ player + "', '" + args + "', '" + date + "', 'MFT-" + generator + "', 'Open', 'Medium', 'Ingame Staff', 'Minecraft Support');"); sender.sendMessage("§7[§5ICU§7] Your ticket has been submitted. Click the following link:"); sender.sendMessage("§7[§5ICU§7] §bhttp://support.myfallen.net/ticket.php?id=MFT-" + generator + ""); } } return true; } return false; } }
With the data i'm getting sent through: CraftPlayer{name=NoMansLand_MFGC} [Ljava.lang.String;@3c7f9d04 java.text.SimpleDateFormat@beefd189 MFT-java.util.Random@5e1d90a3 Is there any way to change this to show the data? Code: Date dNow = new Date(0 ); Format formatter; Date date = new Date(0); formatter = new SimpleDateFormat("dd/MM/yyyy 'at' HH.mm.ss"); Object s = null; s = formatter.format(date); Random randomGenerator = new Random(); int randomInt = randomGenerator.nextInt(999999); SyncSQL sql = new SyncSQL("myfallen.net:3306","myfallen_ticket","xxxxxxxxxxxxxx","xxxxxxxxxxxx"); sql.initialise(); sql.standardQuery("INSERT INTO `myfallen_ticket`.`tickets` (`id`, `sender`, `body`, `submit_date`, `ticketID`, `currentStatus`, `priority`, `assignedTo`, `title`) VALUES (NULL, '"+ sender.getName() + "', '" + args.toString() + "', '" + s + "', 'MFT-" + randomInt + "', 'Open', 'Medium', 'Ingame Staff', 'Minecraft Support');"); sender.sendMessage("§7[§5ICU§7] Your ticket has been submitted. Click the following link:"); sender.sendMessage("§7[§5ICU§7] §bhttp://support.myfallen.net/ticket.php?id=MFT-" + randomInt + ""); } } return true; Fixed the getName()
How can I get all the text from the args[]? with out having to save to the database again & again & again
You mean something like "/msg arg1 And long message that holds more arguments" ? Then you merge them back together... I'm unsure if there's a single method for this but you can do it like this as well: Code: String message = ""; // 1 is the argument to start the message from for(int i = 1; i < args.length; i++) { message = message + " " + args[i]; } // message now holds all arguments since arg 1 (2nd argument)
Oh, actually an improvement to avoid starting space: Code: int startArg = 1; // 2nd arg String message = ""; for(int i = startArg; i < args.length; i++) { message = message + (i == startArg ? "" : " ") + args[i]; } // "message" now holds all arguments since arg defined in startArg
If I could suggest one change: use StringBuilder. Code: final StringBuilder sb = new StringBuilder(); for(int i = startArg; i < args.length; i++) { sb.append(args[i] + " "); } final String message = sb.toString(); Or something like the above.
Hmm, yes, I just googled about those to know the diferences and it seems that re-asigning a string actually creates a new one and it discards the old one for GC, which isn't favorable for memory. It goes down to: From: http://javarevisited.blogspot.ro/2011/07/string-vs-stringbuffer-vs-stringbuilder.html