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

PHP код:
    @Command 
    
public boolean giveveh(Player pString targetint modelint color1int color2)
    {
        if(
p.getVarInt(VAR_ADMIN_LEVEL) < GIVE_VEH_LEVEL)
        {
            
p.sendMessage(new Color(-1), MESSAGE_LOW_LEVEL);
            return 
true;
        }
        
// ...
        
return true;
    }
    @
Command 
    
public boolean giveweap(Player pString targetint weaponint ammo)
    {
        if(
p.getVarInt(VAR_ADMIN_LEVEL) < GIVE_WEAPON_LEVEL)
        {
            
p.sendMessage(new Color(-1), MESSAGE_LOW_LEVEL);
            return 
true;
        }
        
// ...
        
return true;
    } 
How can I automatize check for admin level? I don't understand, how CommandGroup can help me with it.
And also I need to checking target's isOnline in all commands, how can I automatize all of it?
Reply

gtaun.net is http 118
Reply

@steki.: gtaun.net is up again. Sorry for the downtime.

@DrumYum: You can create a BeforeCheck, to check the adminlevel etc. like this:
PHP код:
@BeforeCheck
public boolean checkPremission(Player pString cmdString params)
{
    return 
p.isAdmin();

This will be called before every command, and if it returns false, the command won't be executed.
Reply

123marvin123, yes, I understand it. But I want to unite level and command together, like level is part of command. I wrote this 5 minutes ago (not tested), but I want automatize it more:

PHP код:
    private Object COMMANDS_LEVELS[][] = 
    {
            {
"giveveh"5},
            {
"giveweap"5},
            {
"sethealth"4}
    }; 
    
    @
BeforeCheck
    
public boolean beforeCheck(Player pString cmdString params)
    {
        for(
int i 0COMMANDS_LEVELS.lengthoi++)
        {
            if(!
cmd.equals(COMMANDS_LEVELS[i][0])) continue;
            if((int) 
COMMANDS_LEVELS[i][1] < p.getVarInt(VAR_ADMIN_LEVEL)) continue;
            
            return 
true;
        }
        return 
false;
    } 
Reply

Yes, you can do it like this, but you could make a Map, and then assign all the values to it.
Then you can do like:

PHP код:
if(hashMap.get(cmd) > player.getAdminLevel()) {
    return 
false;
}
return 
true;
//Or just
return player.getAdminLevel() >= hashMap.get(cmd); 
Reply

Thanks again, I'll try it.
Reply

Oh, how I can extend Player class (interface) correctly? I want to add variables like adminLevel from PVars to this class, or not worth it?
Reply

You can't, and this has it's good reasons , but you can use the PlayerLifecycleHolder from shoebill-common.
PHP код:
PlayerLifecycleHolder playerLifecycleHolder = new PlayerLifecycleHolder(getEventManager());
playerLifecycleHolder.registerClass(GamePlayer.class, (eventManagerp) -> new GamePlayer(eventManagerp)); 
then you can create a class called GamePlayer. This class has to extend the PlayerLifecycleObject. For example:
PHP код:
public class GamePlayer extends PlayerLifecycleObject {
    private 
int adminLevel;
 
    public 
GamePlayer(EventManager managerPlayer p) {
        
super(managerp);
    }
     public 
int getAdminLevel() {
         return 
adminLevel;
     }
     public 
void setAdminLevel(int level) {
          
this.adminLevel level;
     }
    @
Override
    
protected void onInit() {
        
//Create objects, 3dtextlabels etc.
    
}
    @
Override
    
protected void onDestroy() {
        
//Destroy objects etc.
    
}

and you can get the class like this:

PHP код:
GamePlayer playerClass playerLifecycleHolder.getObject(event.getPlayer(), GamePlayer.class); 
or, you can get all players like this:
PHP код:
Collection<GamePlayerplayers playerLifecycleHolder.getObjects(GamePlayer.class); 
Reply

What is PlayerLifecycleHolder and PlayerLifecycleObject? And for what I need to .registerClass?
Reply

@DrumYum: The PlayerLifecycleHolder will create and destroy custom player objects when a player connects or disconnect. It was made, because you can't extend the player class. With .getObject you can get a custom object that is assigned to that player. It is like having a Map<Player, GamePlayer> (GamePlayer is a custom class, with adminLevel, isOnline, level, server-side money etc.). You need to call the .registerClass to let the PlayerLifecycleHolder know, that he should create a GamePlayer object for every player that connects (and destroy it when he disconnects).

The GamePlayer class has to extend the PlayerLifecycleObject, because it contains some methods and variables.
You can only register classes, that extend the PlayerLifecycleObject.

Example use:
PHP код:
//OnPlayerConnect
getEventManager().registerHandler(PlayerConnectEvent.class, (event) -> {
    
GamePlayer gamePlayer playerLifecycleHolder.getObject(event.getPlayer(), GamePlayer.class); //Getting the players custom object with all information in it like adminLevel, money etc.
    
if(event.getPlayer().getName().equals("123marvin123")) //Check if player's name equals 123marvin123
        
gamePlayer.setAdminLevel(5); //assign admin level 5 to player
});
//OnPlayerDisconnect
getEventManager().registerHandler(PlayerDisconnectEvent.class, event -> {
    
GamePlayer gamePlayer playerLifecycleHolder.getObject(event.getPlayer(), GamePlayer.class); //Getting the players custom object with all information in it like adminLevel, money etc.
    
event.getPlayer().sendMessage(Color.WHITE"You had adminlevel " gamePlayer.getAdminLevel()); //Send message with his current adminlevel as information
}); 
Reply

How do I get a streamer running without having to make one by myself?
Reply

@steki.: You can't. Right now you have to make your own, or wait for Shoebill 1.1.
Reply

So, I can't cast Player and playerLifecycleObject?
Like this:
PHP код:
Player p = (PlayerplayerLifecycleHolder.getObject(e.getPlayer(), PlayerFW.class); 
I must use .getObject every time when I need to setAdminlevel etc?
Reply

@DrumYum: No, you don't have to cast it. You can call the .getPlayer() function in your custom Player class, which is already inherited from PlayerLifecycleObject. Like this:
PHP код:
PlayerFW playerFw playerLifecycleHolder.getObject(e.getPlayer(), PlayerFW.class);
playerFw.setAdminLevel(6); //For example
Player player playerFw.getPlayer();
//Or just:
Player player playerLifecycleHolder.getObject(e.getPlayer(), PlayerFW.class).getPlayer(); 
And of course, your PlayerFW class need to have the needed methods. Like this:

PHP код:
public class .... {
    private 
int adminLevel;
    public 
void setAdminLevel(int adminLevel) {
        
this.adminLevel adminLevel;
    }
    public 
int getAdminLevel() {
        return 
this.adminLevel;
    }

@EmilLykke: No, it does not contain any kind of viruses. It's opensource and you can build it youself if you don't trust mk124.
Sourcecode can be found @ https://github.com/Shoebill
Reply

Tomorrow we will release a quick fix for 0.3z R2-4.
Reply

Ok, Shoebill for 0.3z R2-4 got released:
http://puu.sh/bGqjO/66ed0bd7bb.zip
Reply

Can I add my own events to this?
Reply

@SetupDLL:

Yes, you can. For example, this is a event to detect when a player changed his armed weapon:

PHP код:
//PlayerEvent contains a Player variable already. You can also create you all own type of event, when you just implement Event. Or if you want t make some Vehicle Event you can use VehicleEvent.
public class PlayerChangedWeapon extends PlayerEvent {
    private 
WeaponModel oldWeapon;
    private 
WeaponModel newWeapon;
    protected 
PlayerChangedWeapon(Player playerWeaponModel oldWeaponWeaponModel newWeapon) {
        
super(player);
        
this.oldWeapon oldWeapon;
        
this.newWeapon newWeapon;
    }
    public 
WeaponModel getNewWeapon() {
        return 
newWeapon;
    }
    public 
WeaponModel getOldWeapon() {
        return 
oldWeapon;
    }

To register it, you can use it like this:
PHP код:
eventManager.registerHandler(PlayerChangedWeapon.class, (e) -> {
    
Player player e.getPlayer();
    
player.sendMessage(Color.RED"* Your old weapon was " e.getOldWeapon().getName() + " and your new one is " e.getNewWeapon().getName());
}); 
But it won't trigger itself, so you need to recognize somehow if the player changed his weapon. In this case,
we can use the PlayerUpdate event and compare his old and current weapon:

PHP код:
//We need to save his old weapon, so create a global hashmap:
private WeakHashMap<PlayerWeaponModeloldWeapons;
//Initzialize it in constructor
oldWeapons = new WeakHashMap<>();
//Register PlayerUpdateEvent
eventManager.registerHandler(PlayerUpdateEvent.class, (e) -> {
    if(
oldWeapons.containsKey(e.getPlayer())) {
        
WeaponModel old oldWeapons.get(e.getPlayer());
        
WeaponModel newModel e.getPlayer().getArmedWeapon();
         if(!
old.equals(newModel)) {
            
oldWeapons.put(e.getPlayer(), newModel);
//Trigger the PlayerChangedWeapon
            
eventManager.dispatchEvent(new PlayerChangedWeapon(e.getPlayer(), oldnewModel),
e.getPlayer());
        }
    } else 
oldWeapons.put(e.getPlayer(), e.getPlayer().getArmedWeapon());
}); 
Reply

Hello I cannot seem to get the server running.

I have java 8 jdk and jre (Both 32 bit) installed and my JAVA_PATH and JRE_PATH variables are pointing at them.
I've downloaded the dev pack from this thread and downloaded the sa-mp server from the sa-mp website. I've merged the folders and changed nothing in them.

everytime i run it i get these errors:

[17:36:11]
[17:36:11] Server Plugins
[17:36:11] --------------
[17:36:11] Loading plugin: Shoebill
[17:36:11] > Shoebill 1.0 NativePlugin for SA-MP 0.3z R2-4 by MK124, JoJLlmAn & 123marvin123
[17:36:11] > Java VM has been created.
[17:36:11] Loaded.
[17:36:11] Loaded 1 plugins.

[17:36:11]
[17:36:11] Filterscripts
[17:36:11] ---------------
[17:36:11] Loaded 0 filterscripts.

[17:36:11] ShoebillPlugin: AMX registered.
[17:36:11] Script[gamemodes/Shoebill.amx]: Run time error 19: "File or function is not found"
[17:36:11] Number of vehicle models: 0

Does anyone have a surgestion as where to look for a solution? Thanks in advance.
Reply

@joh999: Are you sure, that you use Server version 0.3z R2-4?
It can be found here: https://sampforum.blast.hk/showthread.php?tid=531302
Reply


Forum Jump:


Users browsing this thread: 18 Guest(s)