#custom api questions

1 messages Ā· Page 1 of 1 (latest)

shut dome
#

okay so

#

about question 1:

#

do you want to access another plugin's API, or do you want your own plugin to provide an API?

dawn moth
shut dome
#

okay, so:

#

to use the Heads plugin API, you first of all have to add that plugin as dependency

#

are you using maven?

dawn moth
#

idk if im using maven and also it's a webpage, not a plugin (i think?)

#

how do i check if im using gradle or maven

shut dome
#

do you have a pom.xml file in your project?

dawn moth
#

is it supposed to be here or like in a package or directory

shut dome
#

ok alrighty

#

sooo

#

first of all, I'd suggest you to switch to maven

dawn moth
#

how do i do that

shut dome
#

you do not HAVE to but it'll help you in the long term

dawn moth
#

also what's maven

shut dome
#

I wrote a blog post about it

dawn moth
#

where

dawn moth
#

oh sorry i thought you might have meant like a spigot forum post, i do not click links that i do not know or trust

shut dome
#

you'll be annoyed by maven in the first place, but once you understand what it does, you'll love maven

#

like, you probably added spigot.jar to your plugin manually

#

you do not need to do stuff like that anymore with maven

dawn moth
#

i think i used the buildtools thing for that

shut dome
#

yeah to build it, but you had to choose the file in IntelliJ

dawn moth
#

huh

shut dome
#

pls read it first, and once you did everything mentioned in the link, ping me again and I'll explain you how to use HeadDB in your plugin šŸ™‚

dawn moth
#

i'm sorry but i won't

shut dome
#

if I don't reply feel free to DM me

#

well

#

if you don't want to use maven, I won't help, sorry

dawn moth
#

i don't trust random links and no offense but people aswell

shut dome
#

no problem

#

but I won't help you then

dawn moth
#

i do want to use maven, i just don't want to use your link

shut dome
#

no problem but then you'll have to ask other people for help

dawn moth
#

ok

shut dome
#

maven is the number one build tool / dependency manager for java

#

EVERYONE either uses maven or gradle

#

if you don't use neither, you'll have a bad time in the future šŸ˜›

dawn moth
#

i don't like you very much

#

i'mma be honest with you

shut dome
#

erm lol

#

okay

dawn moth
#

ok bai i'll ask other people now

shut dome
#

I don't need you to like me but I don't think that I was unfriendly to you or sth

#

I actually just wanted to help you

#

but okay

shut dome
#

it's just an advice

#

like

#

imagine you're working in a team

limpid elbow
#

Here we go again

shut dome
#

and you add C:\Users\iDerpy\Spigot\spigot.jar to your project

#

now IntelliJ will only work when everyone has the same windows username

#

maven gets rid of this thing

dawn moth
#

i wasn't talking about maven, i was talking about how you worded that

shut dome
#

but it's okay if you don't understand it yet, I just think that it's quite rude to just say that you don't like me while I'm just trying to explain to you why maven/gradle is a good thing

dawn moth
#

here it is again

shut dome
wind plover
#

damn you dont seem very greatful for help

dawn moth
#

"but it's ok if you don't understand it yet"

shut dome
#

bro

dawn moth
shut dome
#

you are asking for help

#

of course we know more than you

#

otherwise you wouldn't ask us for help

dawn moth
limpid elbow
shut dome
#

and that's totally normal bro

wind plover
#

maven is a good tool, i started java with it and i find it quite cool especially as i dont have to worry about injecting other jars in magical ways

dawn moth
shut dome
#

do you expect us to tell you that you already know everything?

#

if so why are you asking?

dawn moth
#

you seem to really like twisting my words here

#

i never said that i wanted you to say that i know everything

wind plover
#

youve uh said "and again" like 40 times

shut dome
#

I'm sorry if I offended you, I'm sure other people will help you instead since you don't wanna take my advice, no problem

#

have a nice day

dawn moth
#

i just said that how you're wording theses sentences is very annoying and disrespectful

wind plover
#

"again"

#

what is occurring "again"?

dawn moth
#

him disrespecting me, making him look like the victim, etc etc

shut dome
#

I really do not think that I was disrespectful in any way, but okay

dawn moth
#

and the ", but ok" does not add a lot, it's just annoying

shut dome
#

alright

wind plover
#

they literally said "sorry if i offended, others can help as you dont want to listen to me"

shut dome
#

I'm out, have a nice day

dawn moth
#

i literally said that i want to use maven...

wind plover
#

then google it or smth

shut dome
#

you said that you do NOT want to use maven

wind plover
#

oh wait you dont trust like any link

dawn moth
#

no, i said that i do not trust your random link

wind plover
#

links directly dont give viruses you know

#

its when you download, input data etc

dawn moth
#

they can install stuff or see your information

shut dome
#

bro it's just a normal wordpress website

wind plover
#

under your permission

shut dome
wind plover
#

you have to accept those

dawn moth
#

i do not know it and therefore i do not trust it

shut dome
#

the link won't kill you

dawn moth
wind plover
#

links directly dont do anything

dawn moth
#

making fun of me

wind plover
#

its you accepting stuff

#

they arent making fun of you.

dawn moth
shut dome
#

noone is making fun of you....

wind plover
shut dome
#

yeah anyway, as said, I'm out, I don't have time for this childish discussions^^

dawn moth
#

mfnalex this is the second time you've said that

shut dome
#

I just wanted to help

dawn moth
shut dome
#

oh sorry I misread it

dawn moth
#

these emoji reactions aren't doing anything except annoy me

dawn moth
#

i did say that i want to not use this link, right

#

or did i just dream it

shut dome
#

you can now be sure that it doesn't give you any viruses etv

wind plover
#

its a wordpress site

dawn moth
#

i do not know what a wordpress is

wind plover
#

used mostly for blogs, website builder

shut dome
#

by now I'm pretty sure you're just trolling

dawn moth
#

i am not, but ok

#

:p

shut dome
#

did you ever visit any porn website?

dawn moth
#

no wtf

shut dome
#

did you ever visit ANY website?

dawn moth
#

yeah...

#

what's your point here

wind plover
#

websites arent harmful themselves if you do nothing

shut dome
#

my point is: visiting a website won't immediately get you a virus^^

wind plover
#

dont accept them trying to download, quite simple

dawn moth
#

i don't know if that's true or not so i'mma put it to a maybe

shut dome
#

yeah, just don't download stuff. visiting normal websites is no problem

wind plover
#

if it auto dowloads, your browser will most likely either block it or you can simply delete it as files dont run themselves

shut dome
#

but I see you're being too paranoid for us to help you at all

dawn moth
#

you haven't even tried to help me in like 20 mins

wind plover
#

no thats not them making fun

#

theyve tried to help

dawn moth
#

we were just arguing about websites and what you're doing

wind plover
#

they

#

tried to help

#

you refused a simple blog website

shut dome
#

I sent you a tutorial that explains on what maven is and how it benefits you and you can use it

dawn moth
#

from my eyes, it's a website that i do not know of and therefore should not click on it

wind plover
#

oh my

shut dome
#

okay then simply google it yourself

dawn moth
#

i'd rather just ask other people for help

shut dome
#

okay

wind plover
#

clicking links does not blow everything up but if you google it youll still find unknown ✨ scary sites ✨

dawn moth
#

i googled it and i have no clue what's going on here

#

i need someone to actually explain it to me

wind plover
#

their tutorial does this

shut dome
#

I'll copy paste the text from the website then...

dawn moth
#

why

shut dome
#

How to create your first Minecraft plugin using the Spigot API and Maven
Posted on August 8, 2021 by mfnalex
Hi! Chances are high that, when you are reading this, you never created a plugin for the Bukkit/Spigot-API yet, or that you did so without having used Maven. So, let’s go right ahead

What is the Spigot-API?
The Spigot API is the interface between your plugin and the Minecraft server. It provides many useful features for you to interact with the game.

What is Maven?
Maven is the most widely used build and dependency management tool for Java. We will use it to include the required dependencies (Spigot-API) and handle building your .jar file.

Requirements
You will need the following things to be able to create your first plugin:

At least basic knowledge in Java
Having Java and Minecraft installed
A decent IDE that can interact with Maven. I highly recommend IntelliJ IDEA Community Edition.
I will be using IntelliJ IDEA as IDE in this tutorial, because it’s free, easier to use than for example Eclipse, and it offers the best Maven support. I highly suggest that you do the same!

Let’s get started!

Creating your first project
First of all, we create a new empty Maven project. When you opened IntelliJ for the first time now, you can click on New Project in the Welcome Screen. Otherwise click on File -> New -> Project …

Now select Maven and click Next. Give your plugin a descriptive name, such as HelloWorldPlugin. If you use another name, please also replace HelloWorldPlugin with the name you chose in all further steps.

IntelliJ will now automatically open your pom.xml file. It is used to tell Maven what dependencies your plugin needs and how it should be compiled. Just copy/paste this example pom.xml:

#

because that way you do not have to click my "suspicous" link

#
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <!-- The GroupID is something like your personal "identifier" for maven. If you own a domain, you can just -->
  <!-- use it in the backwards way, e.g. if you own "example.com", use "com.example". -->
  <!-- You can also just use "me.yourusername" (obviously you have to replace "yourusername" with your username) -->
  <groupId>me.yourusername</groupId>
  <!-- The name of your plugin. Should only contain normal letters, numbers, and hyphens (-). -->
  <artifactId>HelloWorldPlugin</artifactId>
  <!-- The version. You should change this on every new release. -->
  <version>1.0-SNAPSHOT</version>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- The Java version used to compile the plugin. I suggest to use 1.8 because many servers are still using Java 8. -->
    < java.version > 1.8 </ java.version >
  </properties>
  <!-- In the following section you can define dependencies for your plugin. -->
  <!-- Right now, we only need the Spigot API -->
  <dependencies>
    <dependency>
      <groupId>org.spigotmc</groupId>
      <artifactId>spigot-api</artifactId>
      <version>1.17.1-R0.1-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <!-- Here we tell maven where it should look for the defined dependencies. -->
  <!-- Right now, we only need the Spigot repository because we don't have other dependencies -->
  <repositories>
    <repository>
      <id>spigot-snapshots</id>
      <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
  </repositories>
  <build>
    <resources>
      <!-- This tells Maven that it should "filter" all files in the resource directory. More on that later. -->
      < resource >
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </ resource >
    </resources>
  </build>
</project>
#

Please replace the <groupId> part in the highlighted line. I added some comments so you know what you can use as Group ID. For example, if you own the domain example.com, you can use com.example for your Group ID. If you do not own any domain, just use me.<yourusername>. Please note that the GroupID may not contain any special symbols, so if your username consists of Chinese symbols or something, just invent a new username for this purpose šŸ˜€

After you have copy/pasted the pom.xml, you will need to tell IntelliJ to read this file again, so that it downloads and detects the Spigot-API. Just click on Maven in the top right corner, and then hit the Reload All Maven Projects button. If this is your first time, it will take some time because it has to download the Spigot-API first. You can see the progress in the status bar at the bottom.

dawn moth
#

i don't know if it's suspicous, i just don't want to click on it because i do not know it

shut dome
#

Creating your plugin.yml file
Now we’re going to add our plugin.yml file. This file is needed by Bukkit/Spigot to actually load your plugin when the server starts.

Create a new file inside your src/main/resources directory, called plugin.yml. It should look like this:

#

Again, just copy/paste the following code into your plugin.yml file:

wind plover
#

links dont give you viruses.

#

downloading stuff does

shut dome
#
name: HelloWorldPlugin # The name of your plugin
author: "mfnalex" # Your username.
main: me.mfnalex.helloworldplugin.HelloWorldPlugin # Replace "me.mfnalex" with the Group ID you chose, and adjust "helloworldplugin.HelloWorldPlugin" if you chose another plugin name.
version: ${project.version} # Maven will automatically replace this with the version number defined in your pom.xml
api-version: "1.13" # Optional, but you should add this when your plugin should run on ANY versions above 1.13
wind plover
#

thats the end of it like thats how it works

shut dome
#

The most important part in your plugin.yml is the main part. It tells Spigot where the Main class of your plugin is located. The most commonly used convention for choosing the name of your Main class is this:

<yourGroupId>.<yourPluginNameInLowerCase>.<YourPluginName>

For example, I was using me.mfnalex as as Group ID and HelloWorldPlugin as plugin name, so my Main class will be called me.mfnalex.helloworldplugin.HelloWorldPlugin.

Creating your plugin’s Main class
The Main class is the entry point to your plugin. Spigot will use it to create the instance of your plugin so that it can interact with the game.

Important: You MUST use exactly the same name for this class as you used in your plugin.yml’s main section!

On the left side of IntelliJ, right-click the /src/main/java folder and click on New -> Java class:

#

A menu opens. Give your main class the same name as you defined in your plugin.yml’s main section – in my case, it’s me.mfnalex.helloworldplugin.HelloWorldPlugin:

#

The actual name of your class is HelloWorldPlugin, but it’s located in the me.mfnalex.helloworldplugin package. If you didn’t do something wrong, it should look like this:

#

From now on, I’m going to assume that you have at least basic Java knowledge.

As you know, every class in Java extends the basic Object class. Bukkit/Spigot however requires your plugin to extend the JavaPlugin class, so we will add extends JavaPlugin behind your class name in it’s definition:

#

As you see, JavaPlugin is highlighted in red, because IntelliJ doesn’t know what JavaPlugin is. So, we have to import the class. Just hover with your mouse over the JavaPlugin part until the following menu appears:

#

Click on Import class. IntelliJ automatically added import org.bukkit.plugin.java.JavaPlugin; to your class file.

Important: If for some reason the ā€œImport classā€ button did not appear, you probably didn’t have IntelliJ reload your pom.xml after copy/pasting it. If you are sure that you properly did so, and it still doesn’t work, click on File -> Invalidate Caches…, tick the first and second checkbox, and then click on Invalidate and Restart.

#

Adding functionality
Congratulations, you just created your first working Bukkit/Spigot plugin! There’s one downside though: it doesn’t do anything yet. Let’s just add a nice message to our plugin that get’s printed when the plugin gets enabled.

As said, our plugin’s Main class extends JavaPlugin. The JavaPlugin class already provides a method called onEnable(). We can simply override this method by adding the following stuff inside our class:

#
    @Override
    public void onEnable() {
        getLogger().info("Yo bro, my awesome plugin is indeed working!");
    }
#

Important: The @Override part is optional. It tells your IDE that you are overriding the onEnable() function that’s already present in JavaPlugin, but it’s not needed for your plugin to actually work. If you decide to add it, you have to import the java.lang.Override annotation just like you did with the JavaPlugin part earlier.

It should look something like this:

#

Compiling and testing your plugin
Let’s try to see if our awesome plugin works. As we’re using Maven to handle the building process, please DO NOT use IntelliJ’s build feature. Instead, we click on Maven at the top right corner, and then choose Lifecycle -> package. (You have to double-click on package)

ā€œPackageā€ means that Maven will compile our plugin’s class files, and store them inside a .jar file, while also adding the plugin.yml.

#

After you did that, your .jar file will be located in your project’s directory inside the target/ folder, so for example C:\Users\mfnalex\IdeaProjects\HelloWorldPlugin\target. You can simply copy it into your server’s plugins/ folder, restart it and you will see our awesome message in the console once the plugin loads.

Adding actual useful functionality
Adding actual features will be covered in my next post, which will be linked here when I’m done writing it. Thanks for reading šŸ™‚

#

take it or leave it

#

TL;DR: Maven allows you to get rid of "hardcoded" dependencies and lets you easily use APIs of other plugins

#

it also helps you in building your .jar file

wind plover
#

mvn clean install is all i do to remake and build the jar

shut dome
#

in case that you trust wikipedia: https://en.wikipedia.org/wiki/Apache_Maven

Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project.
Maven addresses two aspects of building software: how software is...

wild ice
#

@dawn moth there are no network scripts on that website

#

you can enter it safely

dawn moth
#

what's a network script

wild ice
#

scripts that use your network

dawn moth
#

huh

wild ice
#

Dude

dawn moth
#

i am website nub

wild ice
#

there is no virus

#

it will not take your info

dawn moth
#

i don't know it, i don't trust it

wild ice
#

you dont know half the websites you visit

shut dome
#

I know that I'm biased because it's my website, but... dude, how are you using the internet if you do not click on any links?

wild ice
#

^

dawn moth
#

how many websites do you think i visit

wild ice
#

are you trolling?

dawn moth
#

no

#

i just don't trust random links and websites

#

anyways i put the thingie in the pom.xml thing

#

it has like 5 errors

shut dome
#

please show us the error messages

#

obviously you have to adjust the file at some lines

dawn moth
shut dome
#

what's line 15?

dawn moth
#

< java.version > 1.8 </ java.version >

#

38 is < resource >

shut dome
#

why do you have spaces between "<" and "java"?

dawn moth
#

i just copied it from your message

shut dome
#

hm maybe discord messed up the formatting

#

you should really just click on the link

#

but I accept you're afraid, seems like you don't really know how a webbrowser works

dawn moth
#

k i fixed it

shut dome
#

kk

dawn moth
#

are u sure this is updated?

shut dome
#

yes I am

dawn moth
#

it says that most servers use java 8

#

isn't there like java 16 now

shut dome
#

yes, java 16 exists

#

but many people are still on java 8

dawn moth
#

and if they're not?

shut dome
#

java is backwards compatible

#

if something works on java 8,it'll also work on java 16

dawn moth
#

so i should just leave it as 1.8?

#

i don't really understand

shut dome
#

it depends

#

do you want your plugin to work for all people, or just for you?

dawn moth
#

just for me, but i use a server hosting service

shut dome
#

okay, then use java 16

dawn moth
#

i'm not planning on sharing these plugins

shut dome
#

if you're on java 16, then you can change "1.8" to "16"

#

it will then allow you to use java 16 features

#

I only use java 1.8 because many people are still using it and my plugins are available to the public

dawn moth
#

wouldn't java 16 have more features tho?

shut dome
#

of course

dawn moth
#

can i change this later?

shut dome
#

well it depends^^

#

just use java 16, okay?

dawn moth
#

alr

shut dome
#

the plugin is only meant for you, and you are running java 16, so set it to "16"

dawn moth
#

so this, right? <java.version> 16 </java.version>

dawn moth
wind plover
#

i was wondering, you have mentioned you use google, google has sites you do not know

#

websites. do. not. magically. install. viruses. the internet has been developed over many decades to patch security flaws for. this. reason.

#

they cannot install anything without you going out of your way to click open on a file or accept to a permission

shut dome
#

but bstats has .org so it's an organization and so it must be safe šŸ˜›

wind plover
#

but scary link

shut dome
dawn moth
#

i feel like you're still making fun of me

wind plover
#

bc no recognize šŸ˜µā€šŸ’«

#

ok that message was

#

but not those other ones

shut dome
#
  1. You don't click on links
  2. You don't know what java version your hoster is using
    -> You shouldn't try to create MC plugins at this point
dawn moth
wind plover
#

those other ones are to inform you on how links arent some scary stuff

wind plover
#

the internet exists, millions upon millions, probably billions use it just okay

shut dome
#

Being careful on the internet is important but if you don't even want to visit websites, tbh noone can help you here, we're not here to repeat stuff that can be easily found in the internet

wind plover
#

surely you didnt recognise google one day, how did you use that?

shut dome
#

I get paid to code stuff, helping people is my free time and I won't invest it into people who do not even click on links I send that exactly explain what you're looking for

#

I hope you can understand that

dawn moth
#

if you don't want to help, don't. there's no reason to make fun or continue this argument

wind plover
#

oh yeah ill note that every modern browser will notify you of an issue that links have

shut dome
dawn moth
#

i'm currently following your tutorial for maven btw

shut dome
#

okay nice, let me know if you got any questions

#

let me know when you're done and we'll add the head database plugin as dependency

dawn moth
#

you've already said 2 other times that you will leave

shut dome
#

yes, sometimes I get a bit upset when people are annoying me, but I get your point in not clicking links which I can understand a bit

dawn moth
#

ok

dawn moth
#

oh nvm it was in the plugin folder

#

ok i got an error:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project DerpyPlugin: Compilation failure

#

when i double clicked package

shut dome
#

post the full log please

dawn moth
#

that's it

shut dome
#

no, it will give you tons of errors, there must be more information

dawn moth
#

nop

#

that's literally it

shut dome
#

click on the top most part of the "tree" thing on the left side

dawn moth
shut dome
#

then you'll get the full log

#

click on the top most thing on the left side and you'll get the full error

dawn moth
#

it does what you sent, but then moves to this thing

#

what tree thing

shut dome
#

click on the red thing, and then send the whole text from the green area

dawn moth
#

i replaced the computer name with "NAME" btw

shut dome
#

send your pom.xml file pls

dawn moth
shut dome
#

inside your pom.xml, inside <properties>, add this pls:

#
     <maven.compiler.source>1.8</maven.compiler.source>
     <maven.compiler.target>1.8</maven.compiler.target>
#

then double click "clean", and when it's done, double click on "package" again

dawn moth
#

liek dis?

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- The Java version used to compile the plugin. I suggest to use 1.8 because many servers are still using Java 8. -->
        <java.version> 1.8 </java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>```
shut dome
#

yes

dawn moth
#

ok

#

no error, pog

shut dome
#

nice^^

#

normally maven should use the java version you're running it with

#

no idea why it didn't do it now

#

but anyway, you can override it with the options I sent above

#

you're now using java 8

#

but that's no problem unless you specifically need Java 9+ features, which you probably don't

dawn moth
#

so package is the one i need to double click to build?

shut dome
#

yes

#

package = "build .jar file and put all the .yml files into it as well" ^^

dawn moth
#

is there a way i can change where it puts the plugin? so then i can just like put it in the plugins folder instead of moving it from the target to the plugins folder each time

shut dome
#

yeah sure

#

but I don't know it by heart

#
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>2.3.1</version>
      <configuration>
        <outputDirectory>/my/path</outputDirectory>
      </configuration>
    </plugin>
  </plugins>
</build>
#

just check the <configuration> section

#

if you don't have the whole maven-jar-plugin stuff yet: add it. if you already have it, just add the configuration section inside it

#

you could also use the maven-exec plugin to copy the file to a location of your choice afterwards

shut dome
#

I already sent the xml stuff

shut dome
#

anyway I gotta go to sleep now, DM me when I forget to answer here

shut dome
#

did you get it working?

#

@dawn moth

dawn moth
#

i ended up using a tutorial on youtube