New scripting language support: Java

Started by maxorator, Apr 02, 2016, 10:11 PM

Previous topic - Next topic

NewK

Thank you!

One small sugestion, which would come in handy is the addition of a new utility method to the generic Entity implementation ( Entity.java and EntityImpl.java ) and that is a getDataOrDefault method. This is usually a common method in API's that deal with Object and the possible presence of null. The syntax would be something like:

getDataOrDefault(String name, Class<T> klass, Object defaultValue)

And the idea here is that if the value/data that it's retrieving is null, it would return the default value instead, the one that's being passed as a parameter.

I took a look at your EntityImpl.java and this is what I had in mind:
    @Override
    public <T> T getDataOrDefault(String name, Class<T> klass, Object defaultValue) {
        synchronized (sync) {
            if (data == null) {
                return null;
            }

            Object value = data.get(name);

            if (klass.isInstance(defaultValue) && value == null) {
                return (T) defaultValue;
            } else if (klass.isInstance(value)) {
                return (T) value;
            }
            return null;
        }
    }
Not something super urgent, but it'll surely help writing cleaner code in the future and avoid all those pesky null checks :-X

EK.IceFlake

Quote from: BABA1 on Apr 12, 2016, 05:06 AM
Quote from: NewK on Apr 11, 2016, 10:01 PM@maxorator I've noticed that Player does not have a IsFrozen property similar to the Squirrel plugin, has this not been implemented yet or is this done differently with this java plugin?

New pro static void functions have been med. :D
This is not a static function.
This isn't a bump btw

NewK


@maxorator  2 things I've noticed:

- the onPlayerCrashReport event seems to be missing. I noticed the function is there on the plugin but it's just not implemented, something you forgot maybe?

- Also noticed a really nasty bug on the data hashmap in EntityImpl.java. It would seem that sometimes the data hashmap is passed with previous data to completely new entities. For instance, if I create a new pickup with "server.createPickup(etc..)", and  attach data to it with .setData("test", "blabla.."). If I delete that pickup and create a completely new one with "server.createPickup(etc..)" sometimes this new pickup will have the data that I attached to the old one I deleted. Like if I do newPickup.getData("test", String.class), I will get "blabla..". Kinda hard to reproduce this bug but I believe it's an easy fix if we clear the data hashmap every time a new entity is created.

Seeing that maxorator is inactive, I've fixed both of these issues and decided to share the fixed versions publicly for anyone else that's thinking about doing java server development. Binaries can be found below:

Plugin (only 64bit builds for now) : https://github.com/newk5/vcmp-java-plugin/releases/tag/v75
Integration jar : https://github.com/newk5/vcmp-java-plugin-integration/releases/tag/v0.1.3

The integration.jar is to be used with tools-0.1.2.jar which you can find on thijn's maven server here 


NewK

New update released

Fixed VehicleImunity and PlayerImunity classes always returning true when using the has() method. And implemented the onServerPerformanceReport event. This is not a new vcmp event, it's been on the server quite some time, its just not implmented for the squirrel plugin. The event has the following signature:

onServerPerformanceReport(int entry, String[] descriptions, long[] times)
This event is automatically called every 30 seconds by the server and can be used as a way to monitor server performance. It will return a number of descriptions for various server "phases" and the amount of time (in microseconds) spent on each of those phases in the last 30 seconds. So you can check what's taking the longest for the server process, vehicles, pickups, players, etc...

The available phases are:
  • Streaming
  • Vehicle proximity checks
  • Processing players
  • Processing vehicles
  • Processing pickups
  • Processing objects
  • Packet processing
  • Plugin frame event

Downloads

- Plugin : https://github.com/newk5/vcmp-java-plugin/releases/tag/v77
- Integration jar: https://github.com/newk5/vcmp-java-plugin-integration/releases/tag/v0.1.5

NewK

A server crashing bug has been fixed on the Pickup#isAutomatic()  method. Make sure to update your server plugin to this latest version. Otherwise your server will crash when using that method.

Plugin download: here

This fix did not require any changes to the integration .jar so you just need to download the plugin .dll/.so and replace it with the one on the plugins folder.

NewK

The plugin is now compatible with Java 9 and above. Just download the integration.jar from HERE and replace it with the old version.

Reminder that even though the plugin is now compatible with newer Java versions, some of the libraries you're using may not be. So if you get any errors when starting the server make sure the libraries you're using are compatible with the Java version you're using.

NewK

  • Fixed player.GetPlayerWeaponAtSlot and player.GetPlayerAmmoAtSlot always returning 0
Plugin download: here

NewK

  • New update adds support for Java agents
Plugin download: here


NewK

  • Fixed server.getCoordBlipInfo() never returning null when looking for non existent blip
Plugin download: here

NewK

#55
The integration .jar and tools.jar are now deprecated.

I created a new project called vcmp-integration.jar. This project includes both tools.jar and integration.jar in one single jar. So from now on you only need to use 1 jar file. The repository is located on gitlab https://gitlab.com/newk5/vcmp-integration

The artifact was also uploaded to gitlab's maven server so you can now use it automatically with maven/gradle without needing to do any installs on your local maven. To use it in maven add the following to your pom.xml file:

Add the gitlab maven repository:

<repositories>
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/projects/32257821/packages/maven</url>
  </repository>
</repositories>


Add the dependency:
<dependency>
  <groupId>com.gitlab.newk5</groupId>
  <artifactId>vcmp-integration</artifactId>
  <version>1.1</version>
</dependency>
That's all.

If you need to access the .jar file directly you can download it from here: https://gitlab.com/newk5/vcmp-integration/-/packages Click on the version you want,  then scroll down and click the .jar file.

This .jar is fully backwards compatible and is just a drop-in replacement for tools.jar and integration.jar, you won't need to change anything in your code.


rishabs


Great! this is helpful, thanks for sharing.