[Plugin] Shoebill 1.1 - SA-MP Java Development Kit

Oh, I see, it's ok then.
And I have two questions?
It's secure to do the follwing?
Код:
public void onPlayerSpawn(Player player){
Timer.create(2500, 1, (inverval) ->{
                player.setLocation(289.511F, -1873.112F, 6.402F);
                if(player.isOnline()){
                    player.setCameraBehind();
                    player.spawn();
                    if(player.getLocation().getZ() >= 5.0F){
                        Maps.removerObjects(player);
                    }
                }
            }).start();
}
I mean, what happens if the player disconnects before the interval?
Do I need the .isOnline condition?
And the last question, how do I get all the commands from a specific class? I have tried do the following but I think it is not the correct way
Код:
commandM.getCommandEntries("SpecialCommands")
Reply

Most Shoebill functions check if the player is online internally so most likely your code will do nothing if he is offline.
Reply

@Su37Erich: You should check if the player is online, but as dusk already said, most of the functions already do a check. Your timer needs a reference, by the way, because it will be destroyed if you don't assign it to a variable.

I added a .getOrigin() method for the CommandEntry class which allows you to check for the origin of a CommandEntry (http://ci.gtaun.net/job/shoebill-common/156/). Here is an example (keep in mind that you need to do this for all CommandGroups if you want to get all commands from a specific class):

PHP код:
commandManager.getCommandEntries().forEach(commandEntry -> {
            if(
commandEntry.getOrigin() == PlayerCommands.class) {
                
System.out.println("Command " commandEntry.getCommand() + " is of origin PlayerCommands.");
            }
        }); 
Reply

Thanks for the support!
I will be testing
EDIT: I updated to 1.3 and I get an error here:
Код:
specialCommands.setUsageMessageSupplier((player, command, prefix, params, help) -> {
            String message = prefix + command;
            for (String param : params) {//foreach not applicable to type 'lambda parameter'
                message += " <" + param + ">";
            }
            return "» Use: "+message;
        });
Reply

@Su37Erich: The UsageMessageSupplier changed in 1.3, it now looks like this:
PHP код:
    @FunctionalInterface
    
public interface UsageMessageSupplier {
        
String get(Player playerString prefixCommandEntry command);
    } 
and the default one looks like this:
PHP код:
public static final UsageMessageSupplier DEFAULT_USAGE_MESSAGE_SUPPLIER = (playerprefixcommand) ->
    {
        
StringBuilder stringBuilder = new StringBuilder("Usage: " prefix command.getCommand());
        if(
command.getParameters().length 0) {
            for(
int i 0command.getParameters().lengthi++) {
                
stringBuilder.append(" [").append(command.getParameters()[i].name()).append("]");
            }
        }
        if(
command.getHelpMessage() != null)
            
stringBuilder.append(" - ").append(command.getHelpMessage());
        return 
stringBuilder.toString();
    }; 
Reply

Thanks!
By the way, something was changed in the PlayerKeyStateChangeEvent? Yesterday it was detecting the keys fine but today it isn't working:
Код:
event.registerHandler(PlayerKeyStateChangeEvent.class, (e) ->{
            Player player= e.getPlayer();
            if(isSpec(player)){
                System.out.println("Work");
                if(player.getKeyState().isKeyPressed(PlayerKey.JUMP)){
                //do something
                }else{
                    System.out.println("Didn't work");
                }
And it prints:
Work
Didn't work
When I press the SPRINT key (I have tested it with other players)
Also it prints something like this
net.gtaun.shoebill.object.impl.PlayerKeyStateImpl@ 17b0699[keys=0,upDown=0,leftRight=0,action=0,crouch=0,fire =0,sprint=0,secondAttack=0,jump=0,lookRight=0,hand break=0,lookLeft=0,subMission=0,lookBehind=0,walk= 0,analogUp=0,analogDown=0,analogLeft=0,analogRight =0]
Reply

@Su37Erich: I tested it right now and it was working fine. Are you sure that you didn't mix up the Key definitions? In you code you use PlayerKey.JUMP but in your error description you say "When I press SPRINT". JUMP and SPRINT are two different keys (Shift / Spacebar).
Reply

Oh sorry, I posted it wrong. I did the test using the SPRINT key (and pressing the space bar).
But as I said before, it was working yesterday.
I haven't made any changes on it
Maybe it's because I am using the event manager in another class?
Reply

@Su37Erich: I will take a look at it tomorrow, but it shouldn't be caused by the EventManager I think.

//Edit:

This code is working perfectly fine with the newest plugin, api and runtime:
PHP код:
getEventManager().registerHandler(PlayerKeyStateChangeEvent.class, -> {
            
Player player e.getPlayer();
            if(
player.getKeyState().isKeyPressed(PlayerKey.SPRINT)) {
                
player.sendMessage(Color.GREEN"* You pressed SPRINT!");
            } else {
                
player.sendMessage(Color.RED"* You didn't press SPRINT!");
            }
        }); 
You can try to create a new EventManagerNode, but I don't think this is related to this issue.
Reply

I just created an Project Generator to create full Shoebill maven projects. The tool is easy-to-use and really quick.
After your project has been generated, you can use your IDE to import the project.

Here you can get a little taste:




Download:
Reply

beeest <3 nice job bro !!! i really like this !
Reply

@kumasro: Thank you, I'm glad you like it
Reply

Thanks for your answer, I'll be trying to find out what's happening.
Furthermore, I have tried to change the default message but I can't figure how, here is what I tried:
Код:
public final PlayerCommandManager.UsageMessageSupplier CMESSAGE = (player, prefix, command) ->
    {
        StringBuilder stringBuilder = new StringBuilder("» Correct usage: " + prefix + command.getCommand());
        if(command.getParameters().length > 0) {
            for(int i = 0; i < command.getParameters().length; i++) {
                stringBuilder.append(" <").append(command.getParameters()[i].name()).append(">");
            }
        }
        if(command.getHelpMessage() != null)
            stringBuilder.append(" - ").append(command.getHelpMessage());
        return stringBuilder.toString();
    };
Код:
commandManager.setUsageMessageSupplier(CMESSAGE);
Another try:
Код:
commandManager.setUsageMessageSupplier((player, prefix, command) ->
        {
            StringBuilder stringBuilder = new StringBuilder("» Correct usage: " + prefix + command.getCommand());
            if(command.getParameters().length > 0) {
                for(int i = 0; i < command.getParameters().length; i++) {
                    stringBuilder.append(" <").append(command.getParameters()[i].name()).append(">");
                }
            }
            if(command.getHelpMessage() != null)
                stringBuilder.append(" - ").append(command.getHelpMessage());
            return stringBuilder.toString();
        });
But I always get something like this:
java.lang.AbstractMethodError: dev.acesamp.EventManager$$Lambda$1548/21424390.get(Lnet/gtaun/shoebill/object/Player;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/StringLjava/lang/String;
Reply

@Su37Erich: Please keep in mind that UsageMessageSuppliers are now assigned to CommandGroups and not to the PlayerCommandManager. You can set a different MessageSupplier for each CommandGroup. If you don't change it when you create a CommandGroup, the default one will be used.

Please make sure that you got the newest API and Common version (look at your pom.xml and your resources.yml and make sure that resources.yml uses shoebill-common version 1.3 too).
Reply

I'm really sorry if I am doing this by the wrong way, but it continues showing the default message (I have already updated everything):
Код:
CommandGroup group= new CommandGroup();
        group.registerCommands(new BasicCmds(event, commandManager));
        group.registerCommands(new ModCmds());
        group.registerCommands(new AdminCmds(controladorVehiculos));
        group.registerCommands(new DevCmds(vehicleController, event));
        group.registerCommands(new LogCmds());
        group.registerCommands(new EventCmds());
        group.setUsageMessageSupplier((player, prefix, command) ->
        {
            StringBuilder stringBuilder = new StringBuilder("» Type: " + prefix + command.getCommand());
            if(command.getParameters().length > 0) {
                for(int i = 0; i < command.getParameters().length; i++) {
                    stringBuilder.append(" <").append(command.getParameters()[i].name()).append(">");
                }
            }
            if(command.getHelpMessage() != null)
                stringBuilder.append(" - ").append(command.getHelpMessage());
            return stringBuilder.toString();
        });
        commandManager.registerGroup(group);
        commandManager.installCommandHandler(HandlerPriority.NORMAL);
And the next code is being called twice, it shows me both messages when I press SPRINT key. What are the reason for this behavior so I could fix it?
Код:
event.registerHandler(PlayerKeyStateChangeEvent.class, e -> {
            Player player = e.getPlayer();
            if(player.getKeyState().isKeyPressed(PlayerKey.SPRINT)) {
                player.sendMessage(Color.GREEN, "* You pressed SPRINT!");
            } else {
                player.sendMessage(Color.RED, "* You didn't press SPRINT!");
            }
        });
"Main" class:
Код:
new PlayerController(getEventManager(), vehicleController);
        new SpecManager(getEventManager());
Reply

@Su37Erich: I am investigating the UsageMessageSupplier problem right now.

About your PlayerKeyStateChangeEvent:
It will be called twice. The first call is called when you press the key, and the second one is called when you release it. If you want to avoid it, you should check if the key has been pressed in the old state too.

//Edit:

Fixed with this commit: http://ci.gtaun.net/job/shoebill-common/157/
Reply

Hey again, this is more of a maven question than Shoebill.... Can two plugins depend on each other? Although it sounds reasonable, I'm not quite sure on how to achieve it. I need one to build the other...

The only solution I came up with is creating an another dependency purely of interfaces(like shoebill-api) so it would compile. Do you have any other suggestions?
Reply

@dusk: Yes, of course, this is possible. You add your dependency to your target projects as usual, and then you need to add a little bit of code. Of course, only one plugin will be loaded at a time, and that means that one of your two plugins will load after your first one, which means that one will lack the required dependency at the onEnable() method. To fix this, you can use the ResourceLoadedEvent. I made a little example for you:

PHP код:
    @Override
    
protected void onEnable() throws Throwable {
        
eventManager getEventManager();
        
//Replace Plugin.class with your target plugin
        
Plugin plugin ResourceManager.get().getPlugin(Plugin.class); //Try to get the instance of the target plugin.
        
if(plugin != nullmyPluginLoaded(plugin); //If the plugin was found, trigger a custom event (not necessarily needed)
        
else { //If the plugin was not found, because this plugin is loaded before, then:
            
EventManagerNode resourceLoadNode eventManager.createChildNode(); //Make a temporary EventManager
            
resourceLoadNode.registerHandler(ResourceLoadEvent.class, -> { //Register the ResourceLoadEvent
                
if(e.getResource().getClass() == Plugin.class) { //If the loaded resource is of type Plugin (<-- change)
                    
myPluginLoaded((Plugine.getResource()); //Trigger callback method (this is not necessarily needed)
                    
resourceLoadNode.destroy(); //Destroy the temporary EventManager because it will not be neaded
                
}
            });
        }
    }
    private 
void myPluginLoaded(Plugin plugin) {
        
//Interact with the loaded event, maybe assign it to a variable.
    

You will need to add this code to both of your plugins (I didn't test this, but it SHOULD work ).
Reply

Thanks it'll help in the future, but it's not quite what I was asking. Say I have two modules: player and job. I need job to compile player module, but I also need player module to compile job module... So I'm not quite sure what to do.
Reply

@dusk: I am not sure if I understand your problem correctly, but you could create two empty maven project and compile them. After you compiled them once, you can add them to the pom.xml files. You should be able to compile them without getting errors.
Reply


Forum Jump:


Users browsing this thread: 17 Guest(s)