Mythruna
April 25, 2024, 12:28:17 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: 1 2 [3] 4 5
  Print  
Author Topic: Paul, API: Info/Allow Suggestions?  (Read 49639 times)
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #30 on: August 11, 2013, 08:57:03 PM »

Hmm, I've done some searching within the classes and their methods and it seems that the java version is quite limited to some features compared to the groovy version, as is not so sure about that, did you actually make feature implementations for the game with groovy, because I searched these jar files:
  • meta-jb-cmd-1.0.0
  • meta-jb-core-0.25.1
  • meta-jb-json-1.0.1
  • meta-jb-shell-1.1.1-SNAPSHOT
  • meta-jb-swing-0.25.1-SNAPSHOT
  • meta-jb-util-0.25.1-SNAPSHOT
  • Mythruna-Client
  • Mythruna-Core
..which all contained your package as your website name (I won't say it), and I did not find a method for "addShellCommand" and I am guessing that you actually created the script in groovy, because I found this within the "BaseUiEnvironment.groovy" and "BaseScriptEnvironment.groovy":
Code:
void addShellCommand( Shell shell, String name, String description, String help, Closure exec ) {
   
    String[] helpArray = null;
    if( help != null )
        helpArray = help.split( "\\r?\\n" );

    cmd = new ShellScript( description, helpArray, exec );
    shell.registerCommand( name, cmd );
}
I was able to put it in a plain groovy file to implement, just not in java Undecided
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #31 on: August 11, 2013, 09:11:30 PM »

addShellCommand() is a convenience function for adding a command to the shell.  It takes care of a lot of the boilerplate for you but you can also do it directly from Java... you just have to do it manually.  (Interesting note: in the new version of the API you can add commands directly to the "shell" object without passing it to some other function.)

The "shell" environment variable is really just a variable on the player context... which is the object you get in any player events like playerJoined.

So you can implement and add your own commands that way using the meta-jb command classes.  (meta-jb is one of my open source projects... the oldest one, actually.)

Implementing a command in this way is probably too much for me to go into at the moment.  I think there is some default command you can extend and just override the execute methods or something.  I was going to try to find a good example of writing a player command in Java but I've implemented all of them in groovy because it was so much easier.

Even if you want to write the command logic in Java it's still probably easier to wrap it in groovy boiler plate and then call your custom method to do the work, passing it any of the relevant environment that it needs.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #32 on: August 11, 2013, 09:37:21 PM »

I would like to apologize if this is actually taking up quite a bit of your time, I appreciate the knowledge that you are feeding me so much. This API thing is so stressful, but so fun!

As a side-note, any plans for the new API to come out? Like the next public release or alpha? (I wish I was a donor, I could have the API by now Smiley)
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #33 on: August 11, 2013, 11:30:03 PM »

The API will be different in the next version I release.  Partially because I cleaned up some things and partially because so much of the engine has been rewritten.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #34 on: August 13, 2013, 11:43:18 AM »

I think I will stick to groovy until you release the new version to the public, or not. We'll see how far I get Wink

ehh,.. 6 months away Undecided
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #35 on: August 13, 2013, 11:46:27 AM »

One thing that really ground my gears was that the game always crashed if I did something wrong, so I'm working on a plugin (to be released in a couple weeks with basic fundamentals) and I just put some try..catch statements so I don't get as mad Wink
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #36 on: August 13, 2013, 01:19:28 PM »

One thing that really ground my gears was that the game always crashed if I did something wrong, so I'm working on a plugin (to be released in a couple weeks with basic fundamentals) and I just put some try..catch statements so I don't get as mad Wink

Yes, you need to deal with your errors.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #37 on: August 13, 2013, 01:21:06 PM »

I think I will stick to groovy until you release the new version to the public, or not. We'll see how far I get Wink

ehh,.. 6 months away Undecided

I thought I gave you enough information to have you continue with Java.  I thought the questions were answered.  Using the easier approach, you are even somewhat insulated from engine changes... and would at least know right away when you tried to compile.

That is the hidden advantage to the Java approach is that you will detect those sorts of problems right away when you try to someday compile against the new engine.  Many of the same errors may lay hidden until runtime in Groovy.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #38 on: August 13, 2013, 03:12:38 PM »

I think I will stick to groovy until you release the new version to the public, or not. We'll see how far I get Wink

ehh,.. 6 months away Undecided

I thought I gave you enough information to have you continue with Java.  I thought the questions were answered.  Using the easier approach, you are even somewhat insulated from engine changes... and would at least know right away when you tried to compile.

That is the hidden advantage to the Java approach is that you will detect those sorts of problems right away when you try to someday compile against the new engine.  Many of the same errors may lay hidden until runtime in Groovy.
You gave me quite a great amount of information and you did answer every single question, just the fact that I believe I will do better with more practice in java when I get a better understanding of everything.

The main thing I really like to do is transfer a plugin from groovy into java as good practice, which I plan on doing with the current plugin (write in groovy, transfer to java) or I may intertwine groovy and java.
« Last Edit: August 13, 2013, 03:15:56 PM by Shzylo » Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #39 on: September 14, 2013, 12:47:58 PM »

I am able to retrieve some attributes of the player, but the attributes I get are located in that player's JSON file, which doesn't load their current location. I have this code to actually get their location, that searching doesn't resolve the answer.

Code:
//player = e.getContext();
Vector3f playerX = player.getPlayerData().getLocation(String paramString);

The getting of the location requires a String.. I have seen in your groovy file "player-commands.init.groovy" that you used this to get their location for the escape command:

Code:
on( [playerConnected] ) {
    type, event ->
       
    Object p = conn.getAttribute( "player" );

    println( "Adding player commands to " + p.get("userInfo.userId") );
   
    addShellCommand( shell, "escape", "Teleports you above your current location at 160 meters.", null ) {
        pos = getLocation( connection );
        console.echo( "Warping to:" + pos.x + ", " + pos.y + ", " + 160 );
        warp( connection, (float)(pos.x + 0.5f), (float)(pos.y + 0.5f), 160.0f );                         
    }
}

I have been looking into it, and I know that these are some classes that sort-of work to receive the location, but I cannot construct it correctly:

HostedConnection (jME Class File)
PlayerConnectionContext

Could you fill me in on more information when you have any spare time, or when you feel like being nice? I will continue to try to find the correct way to construct it, lets see who finds out first Wink
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #40 on: September 14, 2013, 01:04:20 PM »

Player location is on the player entity.

In the snippet of admin script you post, getLocation() is part of the API that I've exposed.  Its implementation is different on single player and multiplayer so I abstracted it away.

For the current player getLocation() is supposed to work without any parameters.  I maybe had an issue with that at one time... or maybe it doesn't work from within the shell commands (it relies on script-specific context and shell commands are run outside of that).

If you have access to the player entity, you can also just grab the Position component:
pos = player[Position.class];
...which will have location and facing.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #41 on: September 14, 2013, 01:45:48 PM »

I guess I forgot to state that I am still doing this in java; I tried this code, and it throws an error at Position.this for being No enclosing instance of the type Position is accessible in scope:
Code:
Vector3f playerLoc = Position.this.getLocation();

On a side note,  will try to legitimately get the location like this, no errors, just would like to ask if this would be correct:
Code:
Vector3f playerX = player.getPlayerData().getLocation(Float.toString(playerLoc.x));
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #42 on: September 14, 2013, 02:02:20 PM »

I guess I forgot to state that I am still doing this in java; I tried this code, and it throws an error at Position.this for being No enclosing instance of the type Position is accessible in scope:
Code:
Vector3f playerLoc = Position.this.getLocation();

On a side note,  will try to legitimately get the location like this, no errors, just would like to ask if this would be correct:
Code:
Vector3f playerX = player.getPlayerData().getLocation(Float.toString(playerLoc.x));

This is kind of just random gibberish that looks similar to code.  No offense but it is.  You can't just pass magic things.  The player data is a general bucket for storing persistent player data.  It might store all kinds of locations like "lastLocation" or "myDogsLocation" or whatever.  At any rate, it is totally not what you want to use.

The code on the groovy side for doing this is so much easier that it pains me every time I have to write the 20 lines of Java code to do the same thing. (exaggerating)

Is this from a shell command or something else?  It's important because you will need to access quite a few different things and how you access them is different depending on where you are running.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #43 on: September 14, 2013, 02:40:44 PM »

So, wherever you are running this it seems like you have a player object and that the player object is probably some kind of PlayerContext.

In that case, getting the position in Java should be something like:
Code:
EntityId playerEntity = player.getPlayer();
GameSystems systems = player.getSystems();
EntityData ed = systems.getEntityData();
Position pos = ed.getComponent(playerEntity, Position.class);
Vector3f location = pos.getLocation();
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #44 on: September 14, 2013, 03:28:30 PM »

Paul, you were SO right..
Implementing a command in this way is probably too much for me to go into at the moment.  I think there is some default command you can extend and just override the execute methods or something.  I was going to try to find a good example of writing a player command in Java but I've implemented all of them in groovy because it was so much easier.

Adding a command in groovy:
Code:
addShellCommand(shell, "test", "a test command", null) {
    console.echo(player.name)
}

Adding a command in java (it will even make modifiers final, which I don't like to do when they aren't really "final"):
Code:
ShellCommand cmd = new ShellCommand() {
private static final long serialVersionUID = 1L;

public Result execute(Environment env) { //This method is.. nothing..
return null;
}

public boolean isSimple() { //This method is.. nothing..
return false;
}

public String[] getHelp() {
String[] helpArray = {"Test help information", "More help information"};
return helpArray;
}

public String getDescription() {
return "Just a test command";
}

public int execute(ShellEnvironment shellEnv, String str) {
e.getContext().echo(e.getContext().getPlayerData().get("characterInfo.name"));
return 0;
}
};
shell.registerCommand("test", cmd);
Logged
Pages: 1 2 [3] 4 5
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!