Vice City: Multiplayer

Server Development => Community Plugins => Topic started by: maxorator on Apr 02, 2016, 10:11 PM

Title: New scripting language support: Java
Post by: maxorator on Apr 02, 2016, 10:11 PM
This is a sneak peek into a plugin that implements the bindings between Java and the server. Even though it is ready for use, I am posting it here for now to get some initial feedback and iron out some issues based on that. Also, I am not currently writing up a beginner tutorial for setting this up. Once this goes official, I will try to use any feedback and questions here to provide a proper tutorial (for setting up a project and development environment, not for the language, there are plenty of those) and an FAQ.

A very short intro:

This initial release is aimed at people who are familiar with Java and its build tools (or know how to google). Beginner tutorials will come later.
Title: Re: New scripting language support: Java
Post by: MatheuS on Apr 03, 2016, 02:13 AM
Liked it ;D

Why not create a plugin to support pawn? <3
Title: Re: New scripting language support: Java
Post by: ysc3839 on Apr 03, 2016, 03:32 AM
Quote from: MatheuS on Apr 03, 2016, 02:13 AMLiked it ;D

Why not create a plugin to support pawn? <3
Because Pawn is not suitable for server scripting. @Stormeus has said about it.
Title: Re: New scripting language support: Java
Post by: Stormeus on Apr 03, 2016, 04:05 AM
No one on the dev team is going to support Pawn ever again. Stop asking.
Title: Re: New scripting language support: Java
Post by: KAKAN on Apr 03, 2016, 05:17 AM
Wow! That's awesome, now my bro would easily make a server xd
:edit:
Quote from: maxorator on Apr 02, 2016, 10:11 PM....Once this goes official....
What do you mean? Do you mean that you're going to remove the squirrel plugin?
Title: Re: New scripting language support: Java
Post by: DizzasTeR on Apr 03, 2016, 05:50 AM
No @KAKAN, He means that this is an initial release of the plugin which is in beta sort of. So people with java skills (like your brother as you said) will probably use it to script a server and give feedback to maxorator. Once satisfied this will be included in the plugins list just like the other official plugins.
Title: Re: New scripting language support: Java
Post by: Thijn on Apr 03, 2016, 08:51 AM
Quote from: vito on Apr 03, 2016, 08:38 AMIs it the squirrel will be keeping support? (updates)
Of course it will.
Title: Re: New scripting language support: Java
Post by: maxorator on Apr 03, 2016, 09:43 AM
Quote from: Doom_Kill3R on Apr 03, 2016, 05:50 AMNo @KAKAN, He means that this is an initial release of the plugin which is in beta sort of. So people with java skills (like your brother as you said) will probably use it to script a server and give feedback to maxorator. Once satisfied this will be included in the plugins list just like the other official plugins.
This is correct. This plugin doesn't affect the squirrel plugin in any way.

Answering a question from IRC:
Quote    public boolean onPlayerCommand(Player player, String message) {
        return commandRegistry.processCommand(player, message);
    }
Can you explain to me what is the work of this statement?
I have included a class called CommandRegistry, which will automatically call the command methods defined with the @Command annotation in classes that have been added to the CommandRegistry. In the examples I have this in the event handler constructor:
commandRegistry = new CommandRegistry(server);This in the onServerLoadScripts:
commandRegistry.addController(new OtherCommands(server));And now when the player types in /breakcar <vehicleid>, then this method in OtherCommands gets called when you call commandRegistry.processCommand:
    @Command
    public void breakCar(Player player, Vehicle vehicle) {
        VehicleDamage damage = vehicle.getDamage();
        damage.setDoorStatus(VehicleDamage.Door.Bonnet, VehicleDamage.DoorStatus.Flapping);
        damage.setTyreStatus(VehicleDamage.Tyre.LeftRear, VehicleDamage.TyreStatus.Flat);
        damage.setPanelStatus(VehicleDamage.Panel.Windscreen, VehicleDamage.PanelStatus.Damaged);
        vehicle.setDamage(damage);

        server.sendClientMessage(player, COLOUR_YELLOWISH, "Broke that car.");
    }

The DelegatingEventHandler used in the demo gamemode already has the command handling built into it, so you don't have to call commandRegistry.processCommand manually. Calling delegatingEventHandler.add will make both command and callback methods from the specified class to be called.

I have updated the command examples to also use DelegatingEventHandler, since it's easier to use that instead of passing around events and calling timer/command processing manually.
Title: Re: New scripting language support: Java
Post by: Sebastian on Apr 04, 2016, 03:24 PM
I have no idea about how java works, so that's the reason of the next question:
Is java scripting more efficient than squirrel scripting ?
I didn't hear of any other mp mod to use JAVA, which is just a great idea !
Some scripters may be more familiar with it; and while working on a project they are actually boosting their skills, which again, is just great. JAVA is pretty used, so there are many scripters.
Good job !
Title: Re: New scripting language support: Java
Post by: ysc3839 on Apr 04, 2016, 03:27 PM
Quote from: sseebbyy on Apr 04, 2016, 03:24 PMI have no idea about how java works, so that's the reason of the next question:
Is java scripting more efficient than squirrel scripting ?
I didn't hear of any other mp mod to use JAVA, which is just a great idea ! Some scripters may be more familiar with it. :)
Good job !
I think node.js(JavaScript) would be better.
Title: Re: New scripting language support: Java
Post by: Xmair on Apr 04, 2016, 03:33 PM
Minecraft uses java.
Title: Re: New scripting language support: Java
Post by: KAKAN on Apr 04, 2016, 03:43 PM
Quote from: Xmair on Apr 04, 2016, 03:33 PMMinecraft uses java.
Yeah. Java was mainly made for cross-compatibility. You don't have to compile everytime you need to run it in another OS.
Quote from: ysc3839 on Apr 04, 2016, 03:27 PM
Quote from: sseebbyy on Apr 04, 2016, 03:24 PMI have no idea about how java works, so that's the reason of the next question:
Is java scripting more efficient than squirrel scripting ?
I didn't hear of any other mp mod to use JAVA, which is just a great idea ! Some scripters may be more familiar with it. :)
Good job !
I think node.js(JavaScript) would be better.
That's easy, not better. I think :P
Title: Re: New scripting language support: Java
Post by: . on Apr 04, 2016, 03:50 PM
Quote from: ysc3839 on Apr 04, 2016, 03:27 PMI think node.js(JavaScript) would be better.

Node.js thrives on asynchronous I/O and that's something where VCMP doesn't really perform well. Besides, Node.js is not really what you intended to say there (I think). I believe you mean the V8 JavaScript engine on which Node.js was build. But let me stop you there for a second and tell you that compiling and distributing almost any decent JavaScript engine that features JIT (link (https://en.wikipedia.org/wiki/List_of_ECMAScript_engines)) is not an easy task. Because those were probably created to be embedded into specific web-browsers and not into any kind application. At least not without great effort.



Quote from: sseebbyy on Apr 04, 2016, 03:24 PMIs java scripting more efficient than squirrel scripting ?

Much more efficient. Because Java is very similar to C++, meaning that you have statically typed language with a strong emphasis on OOP. Let me ask you another thing. How many times have you misspelled a variable name and then your Squirrel script compiled just fine, only to screw you later when that code was actually executed. How much code do you actually write to test if a variable is what you're expecting it to be? Well, those are the horrors that come with a dynamically typed language such as Squirrel (also known as weakly typed). While they look good on paper and help with quick prototyping. When it comes to the actual development, they're a pain in the a$$.

But that's not what makes Java more efficient in therms of performance (if that's what you mean). What makes Java more efficient is the JIT (just in time) compiler that comes with the JVM (java virtual machine). Basically, when you execute a piece of Java code, that code is transformed into machine code so you get the best performance possible. Which means you get the benefits of C++ that means you get fast native machine instructions but also the benefits of a scripting language that means you don't have to compile your code before you run it. Well, technically, you still compile it but it's a different story than with C++.

But probably the biggest benefit of all is the plethora of libraries out there. You don't have to worry about asking someone to make a plugin for MySQL/SQLite/PostgreSQL etc. or any kind of utility out there. You have a vast library of things to pick and use in your project. Not to mention the amount of utilities, IDEs and debugging software that you have at your disposal.

The only downside of Java is that you need to have a decent amount of programming and software development experience to use it. It's no longer just a few clicks to get you started. You need to know sh!t before you get started with something like Java.
Title: Re: New scripting language support: Java
Post by: DizzasTeR on Apr 04, 2016, 05:49 PM
I want Lua
Title: Re: New scripting language support: Java
Post by: maxorator on Apr 04, 2016, 08:08 PM
As has been said before, Java has some major advantages:

It's fast
To have a language that runs fast, it must either be efficiently compiled to machine code directly (C, C++, Rust), or run on a virtual machine with a good JIT. Currently there aren't that many good JIT-s. Java and .NET have really good ones, Javascript (V8), Lua also have decent ones.

It's statically typed
What this means is that you can't compile code that has syntax errors or tries to use variables or functions that you haven't defined, or have any of other hundreds of errors that only reveal themselves during runtime in dynamic languages. In fact, if you use a proper IDE, it will already show you errors as you type the code and tell you what's wrong there.

It's well structured
This is a bit related to the previous point. It makes it simple to properly divide your application into logical parts. It forces you to use classes. It has well established naming conventions. Also, it doesn't overload you with too many language features - it has those which are necessary to have at least one good way to do everything. It is a lot easier to start writing good code in Java than in many other languages.

It has good tools
Being statically typed and having very strict structure makes it easy for IDEs to do a lot for you. While Java might look very verbose (uses a lot of keywords, longer code than many dynamically typed languages), most Java developers actually don't type more than people who use dynamic languages. That's because IDEs are very good at autocompletion, code generation and refactoring. Also, it has good debugging and build tools.

It has many libraries
Whatever feature you can think of, most likely there's a library out there that does it for you. Adding them is as simple as adding a line to your build script.

It has a large community
Java is actually one of the most used programming languages. According to some sources (http://www.tiobe.com/tiobe_index), it is currently the most used language. You can find active support forums and chatrooms for it. If you have a problem, there are most likely many examples, tutorials or forum topics already about it somewhere.

It's in high demand
Continuing from the previous point, the market for Java is huge. Every big company is very likely to have an internal system that's running Java, either ordered the project from another company and just have a small team to maintain it, or they have their own in-house development team. There is no need to worry about your knowledge about Java being useless in the long run. It has been used for a long time and will be used for a long time.

It's actually quite simple
Feature-wise Java is a pretty minimalistic language. Instead of throwing in feature after feature, they have concentrated on carefully selecting the features that are the most optimal without littering the language with dozens of different ways to do the same thing. I would actually say that it is way simpler than Javascript. Sure you can throw together a few simple lines of Javascript without much knowledge about it, but the moment you try to do something more complex, you will face issues that are orders of magnitude more difficult to understand than what a beginner Java developer has to deal with.

There is currently only one other (set of) managed languages that shares most of the same benefits, and that is C#. However, it isn't yet as well supported on other platforms than Windows, and personally there are things that I think are done better in Java than C#, although I'm biased since I have worked with Java for several years now.

Java doesn't focus on trying to give you a quick start without any tools and proper structure. You are not going to have a good time when you try to start writing it in Notepad, that's not how it's meant to be done. You will have to choose the right tools and set up the structure of your project properly. And from that point on (assuming you got the right tools for the job), things will be very simple.

For anyone who is starting to look into Java, I have two suggestions:
These are the current industry standards. They are designed to make your life easy.
Title: Re: New scripting language support: Java
Post by: . on Apr 04, 2016, 08:25 PM
Quote from: maxorator on Apr 04, 2016, 08:08 PM... Sure you can throw together a few simple lines of Javascript without much knowledge about it, but the moment you try to do something more complex, you will face issues that are orders of magnitude more difficult to understand than what a beginner Java developer has to deal with. ...

That's what I've been telling to every god damn hippie that comes to my face once in a while and starts bragging about certain scripting languages where it's so damn easy to write "hello world" applications in them. But as soon as you bring some complexity you start hitting walls like you're in the middle of a maze.

Yeah, I like dynamically typed languages for playing around and doing simple tasks quick and dirty. But anything beyond that and I start loosing my mind.
Title: Re: New scripting language support: Java
Post by: NewK on Apr 04, 2016, 10:33 PM
This is great and will bring a whole new world of possibilities previously not possible in Squirrel.


I've tried the demo you provided and it was really helpful, it's pretty much all that one needs to understand how to make a script using the plugin. For me, everything's worked so far with no issues, except for that bug with the reload script method which you've already fixed in version 67 of the plugin. The debbuger support is also working great aswell. :))


I'm not sure if you got my last IRC question last night so I'm just going repeat it here. I asked if you had given any tought yet about how/if you're going to implement Squirrel's compilestring() function. From my understanding this is a native Squirrel function so it's not really so much of a feature from the Squirrel vcmp plugin but more of a language feature itself (proficient squirrel scripters do correct me, if I'm wrong about this assumption). Since Java's a statically typed language and all, it doesn't have such a feature which is normal and completely expected. However if you're willing to implement this I'd suggest using BeanShell which is a java interpreter. I don't know if you've used it before or not, so you may already know what I'm talking about, but I'm currently using it at work for a workflow/bpm application and it's been working great so far. And it's really easy to use aswell, I've been doing some testing using it on this java plugin inside the onPlayerCommand() event and I got it working from ingame very easily with just a few lines. I just passed the main class instance that extends the RootEventHandler (   in your demo that was : ModeEventHandler.java ) to the beanshell interpreter and I was able to call it successfully from ingame while maintaining the context of the class and with the ability to call any methods or global variables inside it. The only reason I ask for this, is because this compilestring() function on squirrel has become such a popular and useful command in alot of servers. Going inside the server and calling /exec <code> to fix a bug rather than restarting the whole server or even running the command from IRC instead, it's really useful, server scripters can access any of the script's global variables from inside the game and manipulate them how they wish,  aswell as any other functions they want to access, it's like a live command line directly into their server/script. It would be great to have this with this plugin aswell, and with BeanShell it's definitely a possibility. If you believe that it should not belong inside the java plugin itself I guess that's fine too since it can be implemented directly on the server script instead like I did. My idea for having it exist as a feature on the plugin instead was just to make it easier for whoever decides to make the  transition from the squirrel plugin to this one.

I've been testing more stuff on a blank script and I haven't found any more bugs yet but I'll let you know if I do. I was never really an avid vcmp scripter, mostly due to just lack of interest. I've played with some scripts from time to time and I can understand it just fine, but I'm not really a fan of dynamically typed languages so Squirrel was just never that appealing to me (not enough for me to get interested in "vcmp scripting" anyway) , despite being a pretty good and easy language to work with. Having that said, this java plugin interests me alot, and enough to actually get involved with "vcmp scripting". I've been working with java for quite sometime now, I use it at my job and for personal projects aswell, so this is alot more appealing to me.  I'm familiar with  the tools/frameworks you mentioned so I guess what I'm really trying to say here is that my feedback will come more from the point of view of a regular java developer rather than a  vcmp scripter, so forgive me if I anything  miss any obvious stuff :P



now for the "Java" discussion

Java is a very underrated language, it gets alof of flak for being verbose but this is not 2006 anymore, Java's no longer as verbose as it once was, heck, local-variable type Inference might actually come to happen in JDK9! (http://openjdk.java.net/jeps/286)  It has evolved alot and still managed keep portability without breaking stuff. However, no mattter how much the language seems to evolve, some people still hold a false, past notion of what Java is today. Modern Java is great, it's portable, it's fast and focuses alot on code readability which is why it's accused of being verbose in the first place, but code readability matters alot, I'd rather have some long ass method name which purpose I can understand by simply reading its name, rather than having a cryptic 4 letter method name to which I have no idea what it does. My first server-side language was PHP and I later moved on to Java and got the amazing opportunity of working for/to some very very big multinational companies (some of them, Industry leaders on their areas) and this allowed me to have some perspective into how and where Java is being used and how it relates to the concepts from the new trendy languages like node.js for instance. I still use PHP once in a while (if I really really have to) and node.js too, they're languages I've used for small and simple projects before, but I'd never dream of doing the work I do daily with some of these big corporate webapps with those languages. And the fact that we can now use a language such as Java for scripting VCMP servers is amazing, the ammount of doors this opens up for server owners is something to look up to. The Java community is huge, there's  excelent tooling, extensive documentation about pretty much everything, and a whole world of libraries out there to pick from. And the best of it all and most satisfying for me is that is scales beautifully. A properly organized Java project from the start is very easy to maintain while keeping your sanity intact.
Title: Re: New scripting language support: Java
Post by: DizzasTeR on Apr 05, 2016, 03:59 AM
I'm very much convinced for Java now, I'll see how it goes, thanks for the suggestions @maxorator.
Title: Re: New scripting language support: Java
Post by: ysc3839 on Apr 06, 2016, 03:29 PM
Quote from: S.L.C on Apr 04, 2016, 03:50 PM
Quote from: ysc3839 on Apr 04, 2016, 03:27 PMI think node.js(JavaScript) would be better.

Node.js thrives on asynchronous I/O and that's something where VCMP doesn't really perform well. Besides, Node.js is not really what you intended to say there (I think). I believe you mean the V8 JavaScript engine on which Node.js was build. But let me stop you there for a second and tell you that compiling and distributing almost any decent JavaScript engine that features JIT (link (https://en.wikipedia.org/wiki/List_of_ECMAScript_engines)) is not an easy task. Because those were probably created to be embedded into specific web-browsers and not into any kind application. At least not without great effort.



Quote from: sseebbyy on Apr 04, 2016, 03:24 PMIs java scripting more efficient than squirrel scripting ?

Much more efficient. Because Java is very similar to C++, meaning that you have statically typed language with a strong emphasis on OOP. Let me ask you another thing. How many times have you misspelled a variable name and then your Squirrel script compiled just fine, only to screw you later when that code was actually executed. How much code do you actually write to test if a variable is what you're expecting it to be? Well, those are the horrors that come with a dynamically typed language such as Squirrel (also known as weakly typed). While they look good on paper and help with quick prototyping. When it comes to the actual development, they're a pain in the a$$.

But that's not what makes Java more efficient in therms of performance (if that's what you mean). What makes Java more efficient is the JIT (just in time) compiler that comes with the JVM (java virtual machine). Basically, when you execute a piece of Java code, that code is transformed into machine code so you get the best performance possible. Which means you get the benefits of C++ that means you get fast native machine instructions but also the benefits of a scripting language that means you don't have to compile your code before you run it. Well, technically, you still compile it but it's a different story than with C++.

But probably the biggest benefit of all is the plethora of libraries out there. You don't have to worry about asking someone to make a plugin for MySQL/SQLite/PostgreSQL etc. or any kind of utility out there. You have a vast library of things to pick and use in your project. Not to mention the amount of utilities, IDEs and debugging software that you have at your disposal.

The only downside of Java is that you need to have a decent amount of programming and software development experience to use it. It's no longer just a few clicks to get you started. You need to know sh!t before you get started with something like Java.
I remembered there's some program communicate with node.exe directly. Maybe in this way we don't need to build it, just use it.
Title: Re: New scripting language support: Java
Post by: . on Apr 06, 2016, 04:08 PM
Quote from: ysc3839 on Apr 06, 2016, 03:29 PMI remembered there's some program communicate with node.exe directly. Maybe in this way we don't need to build it, just use it.

Yeah, but that will introduce latency. If you don't care about too much latency then you could implement something like inter process communication or some kind of shared memory. But either way, that's going to bring some nasty latency. Imagine you call 20 VC:MP function calls and each function call has a latency of 1ms (AT BEST!). You just added 20ms of extra time to every event. Imagine a loop that calls FindPlayer(...) which is quite common. Where does that get you?

This brings us back to the era of IRC scripting. Or so I've been told. I wasn't around when that was "popular".
Title: Re: New scripting language support: Java
Post by: NewK on Apr 06, 2016, 04:52 PM
Quote from: ysc3839 on Apr 06, 2016, 03:29 PMI remembered there's some program communicate with node.exe directly. Maybe in this way we don't need to build it, just use it.
The JVM has had a fully embedded Javascript engine in it since 2006 (Java 6) , it's capable of running javascript code and it has the capability  to make interactions between both languages (javascript->java and java->javascript), like passing Java variables to the Javascript engine and viceversa. With the release of jdk7, "Rhino" was released which is another javascript engine similar to the one in jdk6 but with a few more optimizations. And with jdk8 there's another one called "Nashorn" with more optimizations and it's capable of running full featured node.js apps with the use of an aditional Java library which I now don't remember the name of, but if you google it, there's tons of tutorials about using node.js inside the JVM. Although I don't understand why would one even want to do this in the first place.... also this "Nashorn" engine is obviously not as fast as V8, I remember reading somewhere on a benchmark that it was about 2 times slower than Google's V8, which is normal since the JVM was never meant to execute Javascript code in the first place.

Title: Re: New scripting language support: Java
Post by: BABA1 on Apr 06, 2016, 06:42 PM
Does that mean we can compile the scripts using JIT Compiler and then hand it over to someone with JVM installed, so that he/she wouldn't get the source code but will be able to host the server?
@maxorator, don't you think Eclipse else BlueJ would be a good IDE to start with, why shall we use IntelliJ?
Title: Re: New scripting language support: Java
Post by: maxorator on Apr 06, 2016, 07:11 PM
Quote from: BABA1 on Apr 06, 2016, 06:42 PMDoes that mean we can compile the scripts using JIT Compiler and then hand it over to someone with JVM installed, so that he/she wouldn't get the source code but will be able to host the server?
No. You will compile to class files (which are easily decompilable) with the usual compiler. JIT compiler is a different thing, its name comes from Just In Time, which means it compiles during runtime. You cannot compile to machine code in advance.

Quote from: BABA1 on Apr 06, 2016, 06:42 PM@maxorator, don't you think Eclipse else BlueJ would be a good IDE to start with, why shall we use IntelliJ?
Because it's better. Seriously. Google switched their Android Studio from Eclipse to IntelliJ a few years ago. At a Java conference last year, we were asked what IDE we used at a talk, pretty much everyone used IntelliJ and there were just a few Eclipse and Netbeans users. I also like it the best, and I used Eclipse before I tried IntelliJ. About BlueJ, I haven't tried it, but it seems quite primitive.
Title: Re: New scripting language support: Java
Post by: Gudio on Apr 06, 2016, 07:58 PM
Finally my favourite language is supported here. :)
Title: Re: New scripting language support: Java
Post by: KAKAN on Apr 07, 2016, 11:05 AM
Well, I'm pretty new to Java and just use eclipse to make some basic applications. I want to ask how would you import some .jar files to your project?
Can you give us a .jar file that would contain the basic commands you made. I want to see the structure of the .jar files. I would really appreciate your help :)
Title: Re: New scripting language support: Java
Post by: BABA1 on Apr 07, 2016, 03:51 PM
I want to know all the functions like sendClientMessage and etc. Where can I find those functions? I'm not quite acquainted with the plugin. I want a list of functions and something about their formal parameters type in the method signature. I would really appreciate some help! 
Title: Re: New scripting language support: Java
Post by: maxorator on Apr 07, 2016, 04:08 PM
Quote from: KAKAN on Apr 07, 2016, 11:05 AMWell, I'm pretty new to Java and just use eclipse to make some basic applications. I want to ask how would you import some .jar files to your project?
Via gradle dependencies. Look at this for example: https://bitbucket.org/maxorator/vcmp-java-plugin-demo . There, if you want to add some new library to your project, then go to http://search.maven.org/ and find whatever you're looking for. For example if you want MySQL, then you search there for "mysql", then click on the version number on the line with groupId 'mysql' and artifactId 'mysql-connector-java'. On that page, on the left, there is a list of build tools (maven, gradle), pick "Gradle/Grails" from there and copy the line compile 'mysql:mysql-connector-java:5.1.38' near the other lines like that in the build.gradle file of the project.

Not sure if you've managed to load this project into IntelliJ yet, but to do that, you have to open it by selecting "File->New->Project from existing sources", select the project directory, then select "Gradle" from the list, then don't touch any settings and just click "Finish" and wait a bit. After it shows the project, it will still take a bit of time to download the dependencies and the code will look all red until it has finished.

If this is your first time touching IntelliJ, you should get familiar with its shortcuts. You can see a more complete list here: https://resources.jetbrains.com/assets/products/intellij-idea/IntelliJIDEA_ReferenceCard.pdf , but I find that the most important ones are:

Quote from: KAKAN on Apr 07, 2016, 11:05 AMCan you give us a .jar file that would contain the basic commands you made. I want to see the structure of the .jar files. I would really appreciate your help :)
Not sure what you mean. If you mean how to create the jar file to use with the plugin (as classPath) in your configuration file, then open the Gradle panel from the menu with View->Tool Windows->Gradle and from there you can see a list of tasks. What you want is the Tasks->shadow->shadowJar task. If you run that task, it will generate the jar file to build/libs/vcmp-java-plugin-demo-0.0.1-all.jar in the project directory.

Actually you don't need an IDE to compile the project, but actually changing something in the code without an IDE would be a pain. Anyway, you can just run the same task from the command line by typing "gradlew shadowJar".
Title: Re: New scripting language support: Java
Post by: maxorator on Apr 07, 2016, 04:30 PM
Quote from: BABA1 on Apr 07, 2016, 03:51 PMI want to know all the functions like sendClientMessage and etc. Where can I find those functions? I'm not quite acquainted with the plugin. I want a list of functions and something about their formal parameters type in the method signature. I would really appreciate some help! 
There is an instance of Server in the initial event handler class. It contains all those functions:
com/maxorator/vcmp/java/plugin/integration/server/Server.java (https://bitbucket.org/maxorator/vcmp-java-plugin-base/src/0f00b80247a3054fb7e362c22ecc372070128784/integration/src/main/com/maxorator/vcmp/java/plugin/integration/server/Server.java?at=default&fileviewer=file-view-default)

Same thing exists for players, vehicles, etc:
com/maxorator/vcmp/java/plugin/integration/player/Player.java (https://bitbucket.org/maxorator/vcmp-java-plugin-base/src/0f00b80247a3054fb7e362c22ecc372070128784/integration/src/main/com/maxorator/vcmp/java/plugin/integration/player/Player.java?at=default&fileviewer=file-view-default)
com/maxorator/vcmp/java/plugin/integration/vehicle/Vehicle.java (https://bitbucket.org/maxorator/vcmp-java-plugin-base/src/0f00b80247a3054fb7e362c22ecc372070128784/integration/src/main/com/maxorator/vcmp/java/plugin/integration/vehicle/Vehicle.java?at=default&fileviewer=file-view-default)

If you create another class for handling events and commands, you need to pass the Server instance to it via the contructor, like here:
com/maxorator/vcmp/mode/jdbctest/RegistrationManager.java (https://bitbucket.org/maxorator/vcmp-java-plugin-demo/src/b7a5f22661021d845a67f5810c7772080240a879/src/main/java/com/maxorator/vcmp/mode/jdbctest/RegistrationManager.java?at=default&fileviewer=file-view-default)

The best option to split events and commands into separate classes is to use the DelegatingEventHandler, so use this project as an example: https://bitbucket.org/maxorator/vcmp-java-plugin-demo .
Title: Re: New scripting language support: Java
Post by: Klaus on Apr 07, 2016, 09:39 PM
As a Java programmer myself, I'm glad to see this.
Title: Re: New scripting language support: Java
Post by: NewK on Apr 08, 2016, 01:24 AM
For anyone that's starting with Java now, I would advise to stay clear of Eclipse. Either use IntelliJ or Netbeans. Eclipse is the work of the devil. (http://www.ihateeclipse.com/) BlueJ I've heard about it before but never really used it either. I know some local schools in my area use it alot to teach beginner "Intro to Java"  classes. I've tried Eclipse, IntelliJ and Netbeans and I opted with Netbeans. It's a pretty good IDE which in my opinion has been forgotten by alot of Java devs which is a shame because it's a  really good IDE and also completely free. I also find it to be alot more intuitive than IntelliJ, the learning curve is not as steep for beginners.  Although I might be biased since it's the IDE I've used the longest. However, I've had to teach a few interns before with zero java experience and they always seemed to catch on quick with Netbeans.
Title: Re: New scripting language support: Java
Post by: EK.IceFlake on Apr 08, 2016, 09:01 AM
pl0x .net?
Title: Re: New scripting language support: Java
Post by: KAKAN on Apr 08, 2016, 09:25 AM
Quote from: NE.CrystalBlue on Apr 08, 2016, 09:01 AMpl0x .net?
No. Windows only plugins are not allowed.
Title: Re: New scripting language support: Java
Post by: Stormeus on Apr 08, 2016, 09:52 AM
Quote from: KAKAN on Apr 08, 2016, 09:25 AM
Quote from: NE.CrystalBlue on Apr 08, 2016, 09:01 AMpl0x .net?
No. Windows only plugins are not allowed.

.NET is cross-platform using Mono (http://www.mono-project.com/).
Title: Re: New scripting language support: Java
Post by: Thijn on Apr 08, 2016, 05:18 PM
Quote from: Stormeus on Apr 08, 2016, 09:52 AM
Quote from: KAKAN on Apr 08, 2016, 09:25 AM
Quote from: NE.CrystalBlue on Apr 08, 2016, 09:01 AMpl0x .net?
No. Windows only plugins are not allowed.

.NET is cross-platform using Mono (http://www.mono-project.com/).
"cross-platform"
Title: Re: New scripting language support: Java
Post by: EK.IceFlake on Apr 09, 2016, 07:16 PM
Quote from: Thijn on Apr 08, 2016, 05:18 PM
Quote from: Stormeus on Apr 08, 2016, 09:52 AM
Quote from: KAKAN on Apr 08, 2016, 09:25 AM
Quote from: NE.CrystalBlue on Apr 08, 2016, 09:01 AMpl0x .net?
No. Windows only plugins are not allowed.

.NET is cross-platform using Mono (http://www.mono-project.com/).
"cross-platform"
I don't find anything special about these words...
Title: Re: New scripting language support: Java
Post by: Thijn on Apr 09, 2016, 07:29 PM
Quote from: NE.CrystalBlue on Apr 09, 2016, 07:16 PM
Quote from: Thijn on Apr 08, 2016, 05:18 PM
Quote from: Stormeus on Apr 08, 2016, 09:52 AM
Quote from: KAKAN on Apr 08, 2016, 09:25 AM
Quote from: NE.CrystalBlue on Apr 08, 2016, 09:01 AMpl0x .net?
No. Windows only plugins are not allowed.

.NET is cross-platform using Mono (http://www.mono-project.com/).
"cross-platform"
I don't find anything special about these words...
Using mono isn't making .NET cross platform. It's hacking something to work on another platform. It's ugly to say the least...
Title: Re: New scripting language support: Java
Post by: 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?
Title: Re: New scripting language support: Java
Post by: maxorator on Apr 11, 2016, 10:07 PM
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?
player.setOption(PlayerOption.Controllable, false);
Title: Re: New scripting language support: Java
Post by: 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
Title: Re: New scripting language support: Java
Post by: NewK on Jul 05, 2016, 02:10 AM
@maxorator , not sure if you're still around at the moment, but I found a few bugs, whether these are in the plugin itself or the server I'll leave that to your judgement :)

First is the createCheckPoint method
//trying to create a sphere for 1 player creates a checkpoint instead
boolean isSphere = true;
CheckPoint cp = server.createCheckPoint(player, 2, isSphere, player.getPosition(), new Colour(0xFFDB5555), 2);

//trying to create a sphere for all players doesn't work and returns null
boolean isSphere = true;
CheckPoint cp = server.createCheckPoint(null, 2, isSphere, player.getPosition(), new Colour(0xFFDB5555), 2);
System.out.println(cp == null); //true

//trying to create a checkpoint for all players doesn't work and returns null
boolean isSphere = false;
CheckPoint cp = server.createCheckPoint(null, 2, isSphere, player.getPosition(), new Colour(0xFFDB5555), 2);
System.out.println(cp == null); //true

Next is the server.getAllPlayers()method:
The method behaves weirdly under the following scenario:
Player1 joins the server - at this point, server.getAllPlayers() returns an array of length 1 with one Player instance inside it
Player2 joins the server - at this point, server.getAllPlayers() returns an array of length 2 with two Player instances inside it
Player1 leaves the server - at this point, server.getAllPlayers() returns an array of length 1 with one Player instance inside it, but it's
null

If I want to fetch Player2's Player instance I can't loop through alll the players in the server using the method to find it since the instance inside the array is null so I won't be able to find it, however, if I know this player's ID I can still fetch it with server.getPlayer(id) and it won't be null then.

Last, is an issue with the radar blips. I've been told this also happens with the squirrel plugin but it's very very rare and very hard to reproduce. Using the Java plugin it always happens and can be reproduced at anytime. The issue is as follows: When I use a custom image to create a radar blip it will be placed with no issues. However, if a player leaves the server and rejoins, he won't be able to see the custom radar blip that I created, instead he will see blip 39, the "W" from radio wave  (http://wiki.vc-mp.org/wiki/File:Icon_RWave.jpg) in its place. For this player my custom blip will show as blip 39, but for all the other players inside the server they will still see the custom blip, that is, until they leave the server and rejoin it. If I try to re-create the custom blips after these players rejoin the server, they will once again be able to see the correct custom blip instead of blip 39. I believe there's something going with the OnPlayerConnect event that's causing this, because I've tried to re-create (delete and then create) these blips inside this event right when the players join the server and what happens is that the delete works, but not the create. I then tested (still inside this event) to add a 200ms timer to run before the create method is called and this seems to work. This issue has also been identified by murdock in his topic:
Quote from: Murdock on Aug 30, 2015, 12:07 AM
  • Sometimes custom mapicons will not appear and the icon of Wave103 (id 39) will show for all icons instead (rarely occurs so hard to reproduce)
So I'm inclined to think this a bug in the server rather than the plugin but I can't really tell for sure.


Hope this helps finish the plugin, other than those problems I'd say the plugin's pretty solid so far.
Title: Re: New scripting language support: Java
Post by: KAKAN on Jul 05, 2016, 01:03 PM
@NewK, that's not the only bugs, there are many a bugs around. Try asking @Murdock if you want a list.
Title: Re: New scripting language support: Java
Post by: NewK on Jul 05, 2016, 01:59 PM
Quote from: KAKAN on Jul 05, 2016, 01:03 PM@NewK, that's not the only bugs, there are many a bugs around. Try asking @Murdock if you want a list.
You clearly did not understand my reply. The bugs I posted above (with the exception of that last one), are bugs in the Java plugin, not the Squirrel plugin. Some of the bugs that murdock identified, are bugs in the Squirrel plugin or the actual server. The ones I posted above are specific to the java plugin only (once again with the exception of that radar blips bug)
Title: Re: New scripting language support: Java
Post by: KAKAN on Jul 05, 2016, 04:22 PM
Quote from: NewK on Jul 05, 2016, 01:59 PM
Quote from: KAKAN on Jul 05, 2016, 01:03 PM@NewK, that's not the only bugs, there are many a bugs around. Try asking @Murdock if you want a list.
You clearly did not understand my reply. The bugs I posted above (with the exception of that last one), are bugs in the Java plugin, not the Squirrel plugin. Some of the bugs that murdock identified, are bugs in the Squirrel plugin or the actual server. The ones I posted above are specific to the java plugin only (once again with the exception of that radar blips bug)
Yes, I'm talking about Java plugin. There are many bugs in that plugin. Murdock was using it, so he knows it well.
Title: Re: New scripting language support: Java
Post by: NewK on Jul 05, 2016, 07:49 PM
Quote from: KAKAN on Jul 05, 2016, 04:22 PM
Quote from: NewK on Jul 05, 2016, 01:59 PM
Quote from: KAKAN on Jul 05, 2016, 01:03 PM@NewK, that's not the only bugs, there are many a bugs around. Try asking @Murdock if you want a list.
You clearly did not understand my reply. The bugs I posted above (with the exception of that last one), are bugs in the Java plugin, not the Squirrel plugin. Some of the bugs that murdock identified, are bugs in the Squirrel plugin or the actual server. The ones I posted above are specific to the java plugin only (once again with the exception of that radar blips bug)
Yes, I'm talking about Java plugin. There are many bugs in that plugin. Murdock was using it, so he knows it well.
No, you don't know what you're talking about, murdock uses the Squirrel plugin.
[20:04] <NewK> hey
[20:20] <Murdock> he
[20:30] <NewK> do you use the java plugin?
[20:44] <Murdock> nop

Can you stop making things up now?
Title: Re: New scripting language support: Java
Post by: maxorator on May 30, 2017, 08:13 PM
Fixed:

Added:
Title: Re: New scripting language support: Java
Post by: NewK on May 31, 2017, 12: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:
    @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
Title: Re: New scripting language support: Java
Post by: EK.IceFlake on Jul 27, 2017, 12:25 PM
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
Title: Re: New scripting language support: Java
Post by: NewK on Jun 02, 2018, 06:49 PM

@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 (http://v04.thijn.ovh/maven/com/maxorator/vcmp/plugin/tools/0.1.2/) 
Title: Re: New scripting language support: Java
Post by: NewK on Jun 24, 2018, 06:46 AM
Updated to support 0.4.5 release:

Plugin : https://github.com/newk5/vcmp-java-plugin/releases/tag/v76
Integration jar : https://github.com/newk5/vcmp-java-plugin-integration/releases/tag/v0.1.4
Title: Re: New scripting language support: Java
Post by: NewK on Aug 11, 2018, 08:14 PM
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:

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
Title: Re: New scripting language support: Java
Post by: NewK on Aug 17, 2018, 08:32 AM
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 (https://github.com/newk5/vcmp-java-plugin/releases/tag/v78)

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.
Title: Re: New scripting language support: Java
Post by: NewK on Aug 16, 2019, 04:14 AM
The plugin is now compatible with Java 9 and above. Just download the integration.jar from HERE (https://github.com/newk5/vcmp-java-plugin-integration/releases/tag/v0.1.6) 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.
Title: Re: New scripting language support: Java
Post by: NewK on Mar 24, 2020, 10:13 PM
Plugin download: here (https://github.com/newk5/vcmp-java-plugin/releases/tag/v79)
Title: Re: New scripting language support: Java
Post by: NewK on Apr 25, 2020, 06:31 AM
Plugin download: here (https://github.com/newk5/vcmp-java-plugin/releases/tag/v80)

Title: Re: New scripting language support: Java
Post by: NewK on May 10, 2020, 09:32 PM
Plugin download: here (https://github.com/newk5/vcmp-java-plugin/releases/tag/v81)
Title: Re: New scripting language support: Java
Post by: NewK on Dec 20, 2021, 12:52 PM
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.

Title: Re: New scripting language support: Java
Post by: rishabs on Jan 13, 2022, 08:50 AM

Great! this is helpful, thanks for sharing.