New scripting language support: Java
[C++] Vice Racing »

NewK

  • VC:MP Beta Tester
  • Posts: 176
Re: New scripting language support: Java
« Reply #45, on May 31st, 2017, 01:19 AM »
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:
 
Code: [Select]
   @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

  • Hero Member
  • "We are the champions my fellahs" - Sufyan/VK.SuFy
  • Posts: 1,761

NewK

  • VC:MP Beta Tester
  • Posts: 176
Re: New scripting language support: Java
« Reply #47,  »

@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 
Re: New scripting language support: Java
« Reply #49,  »
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:

Code: [Select]
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
Re: New scripting language support: Java
« Reply #50,  »
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.
Re: New scripting language support: Java
« Reply #51,  »
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.

[C++] Vice Racing »