Posted December 29, 201410 yr I have a command class : package com.dcnick.servmod; import java.util.ArrayList; import java.util.List; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentText; public class AreaCommand implements ICommand { private List<String> aliases; protected AreaCommand() { aliases = new ArrayList<String>(); aliases.add("area"); aliases.add("ar"); } @Override public int compareTo(Object arg0) { return 0; } @Override public String getCommandName() { return "area"; } @Override public String getCommandUsage(ICommandSender cs) { return "Using: /area [create] [name]"; } @Override public List getCommandAliases() { return aliases; } @Override public void processCommand(ICommandSender cs, String[] arg) { EntityPlayer player; if (arg.length < 1) { cs.addChatMessage(new ChatComponentText("§4Not Enought Arguments§f")); return; } if (cs instanceof EntityPlayer) { player = (EntityPlayer) cs; } else { cs.addChatMessage(new ChatComponentText("§4Player Only Command§f")); return; } if (arg[0] == "create") { if (arg.length < 2) { cs.addChatMessage(new ChatComponentText( "§4Not Enought Arguments§f")); return; } if (player.getEntityData().getBoolean("pos1") && player.getEntityData().getBoolean("pos2")) { double x1 = player.getEntityData().getInteger("pos1X"); double y1 = player.getEntityData().getInteger("pos1Y"); double z1 = player.getEntityData().getInteger("pos1Z"); double x2 = player.getEntityData().getInteger("pos2X"); double y2 = player.getEntityData().getInteger("pos2Y"); double z2 = player.getEntityData().getInteger("pos2Z"); String name = arg[1]; cs.addChatMessage(new ChatComponentText( "§fCreating Region named '§e" + name + "§f' with Point1 at (§e" + x1 + "§f,§e" + y1 + "§f,§e" + z1 + "§f) and Point2 at (§e" + x2 + "§f,§e" + y2 + "§f,§e" + z2 + "§f) ..." + "§f")); } else { cs.addChatMessage(new ChatComponentText( "§4Positions not setted! Use /pos command to do this§f")); return; } } else { cs.addChatMessage(new ChatComponentText( "§4Error at argument 1 it can be: create, remove, info§f")); return; } } @Override public boolean canCommandSenderUseCommand(ICommandSender cs) { return true; } @Override public List addTabCompletionOptions(ICommandSender cs, String[] ar) { return null; } @Override public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) { return false; } } And when I comparing arg[0] with "create" Program Jumps to else instruction, but I enter "create" in minecraft, Help!!! I'm Developing Some mods. It's all.
December 29, 201410 yr That is not how you compare strings. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 29, 201410 yr Author Ok, english is not my language) I use (arg[0] == "create") that returns false, but it must return true, because arg[0] is "create" I'm Developing Some mods. It's all.
December 29, 201410 yr This is pretty basic Java, but to compare arbitrary objects, you have to use the equals method. In Java, every object variable is actually a reference. That means object variables only store the memory location of the objects, not the objects themselves. If you use "A == B" with two objects, it compares the addresses of A and B, not A and B themselves. (They are kind of like pointers in C.) Edit: (I meant equals , not compare .) GitHub|Recipe API Proposal
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.