#help-development

1 messages · Page 1409 of 1

quaint mantle
#

no

#

I must become a dev

glossy scroll
#

Capitalize soldier.java

#

Maybe that will fix your issue

wraith rapids
#

inb4 SOLDIER.JAVA

glossy scroll
#

LMFAO

hybrid spoke
#

its unnecressary anyways

quaint mantle
#

@glossy scroll

novel hornet
#

when i run a command on my server nothing happends what could cause this to happen

glossy scroll
wraith rapids
#

what plugin provides this command

glossy scroll
unkempt ore
quaint mantle
glossy scroll
#

Idk

hybrid spoke
#

oh i understood wrong

wraith rapids
#

now we sit down

hybrid spoke
#

i am reading the javadocs in the classes directly

wraith rapids
#

and start to contemplate the futility of human existence

rigid hazel
#

I'm using java player.openBook(book); and for a second or something the book is popping up with the text and closes. Why this intervall so short?

wraith rapids
#

something could be calling player.closeInventory or something

hybrid spoke
quaint mantle
#

@hybrid spoke

glossy scroll
wispy monolith
#

Should I use bukkit ChatColor or bungee ChatcColor?

quaint mantle
#

@glossy scroll how do I use maven?

wraith rapids
#

depends

#

bungee supports rgb

glossy scroll
#

@wraith rapids he wants to use maven

#

Wheres the guide

rigid hazel
#

Can this produce the error?

wraith rapids
#

i don't have the eclipse maven tutorial at hand

#

uh

glossy scroll
#

google

unkempt ore
#

Quick question, I’m making a custom item, just an item with some special meta, and I want to check if another ItemStack matches it. What is the most reliable way to? Testing the metas’ .equals() doesn’t sound right because, say, a player could change the item’s display name in an anvil and it wouldn’t match. Not sure what to do. I wish I could do something like give it a custom Material type

hybrid spoke
#

by 1 tick or smth

wispy monolith
rigid hazel
unkempt ore
#

Alright, I’ll look into that

hybrid spoke
wraith rapids
#

that one guy linked it recently but I don't have it in my browser history for some reason

novel hornet
quaint mantle
#

@wraith rapids what should I do?

wraith rapids
#

@unkempt ore use persistent data container

#

equals is the same as issimilar, it just ignores stack size

glossy scroll
wispy monolith
#

Right, Where I put plugin.yml?

wraith rapids
#

write a tag in the PDC in the item's meta and use that for comparison

#

in the resources directory

glossy scroll
#

Use persistent data container like NNYajcjsojfkeke said

wraith rapids
#

with your config.yml

wispy monolith
wraith rapids
wraith rapids
#

i can't find any properly navigable trie impls either

#

i guess my level of expectations for "navigable" is just too high

wispy monolith
#

thx

#

everything work now

wraith rapids
#

and this is why you should always use a dependency manager

#

your dependency might depend on other dependencies which might depend on yet other dependencies

#

a dependency manager will just grab and import them all

unkempt ore
#

Yeah, sounds perfect

limpid veldt
#

in the plugin.yml is there a way to put variables such as this in other areas such as permissions or smtn?

eternal oxide
#

yes

wraith rapids
#

anything that you have declared as a filtered resource can use them

eternal oxide
#
            <resource>
                <directory>resources</directory>
                <filtering>true</filtering>```
#

or wherever yoru resources are

wraith rapids
#

speaking of

#

how do you people infer the main package of the plugin to use in these vars

limpid veldt
#

like if I want a variable for the permissions, id just stick that in the pom or something along those lines right?

wraith rapids
#

i just have a project property for it but it feels kind of crummy

eternal oxide
#

This is my generic plugin.yml ```yaml
name: ${project.artifactId}
main: ${project.groupId}.${project.artifactId}
version: ${project.version}
api-version: ${project.bukkitAPIVersion}

author: ElgarL
website: ${project.url}```

limpid veldt
#

thats actually pretty smart

#

ultimate boilerplate

quaint mantle
eternal oxide
#

You can;t do that

quaint mantle
sudden raft
#

mmm

quaint mantle
#

Yushu ❤️

eternal oxide
#

It measn replace with your Artifact name

sudden raft
#

You must replace it by your group id and your artifact name

quaint mantle
#

Like this?

eternal oxide
#

no

#

your outer class should extend JavaPlugin

quaint mantle
#

oof I'm stupid

#

I don't know what to do

eternal oxide
#

keep trying. You know the saying about moneys and a typewriter.

wraith rapids
#

doesn't that involve using a different group id for each plugin, though

novel hornet
#

when i run a command on my server nothing happens what could cause this to happen should i provide latest.log

wraith rapids
#

main: includes the class name

eternal oxide
#

yep

#

${project.groupId}.${project.artifactId}

wraith rapids
#

the last element of your main is the artifact id

#

which would make your artifact id the class name

eternal oxide
#

yes

wraith rapids
#

but what about your main package?

#

that should differ between plugins

eternal oxide
#

class = project name

wraith rapids
#

which it can't unless you specify a different group id for each plugin

eternal oxide
#

artifactId would be GroupManager

#

groupId would be the package

wraith rapids
#

give an example for groupId

eternal oxide
#
    <groupId>com.palmergames.spigot.homestead</groupId>
    <artifactId>Homestead</artifactId>```
wraith rapids
#

so you do change the group id for each plugin

eternal oxide
#

I don;t have to

wraith rapids
#

well I don't "have" to have a plugin package either

#

i can just have my classes directly under main

#

but I should have an unique package for each plugin

#

which means that you should change your group id for each plugin

eternal oxide
#

I guess I could include the lower case ArtifactId on the GroupId which would make it fully dynamic

wraith rapids
#

lowercase artifactId is what I do

#

or, would do, if I knew how to make things lowercase

eternal oxide
#

🙂

wraith rapids
#

do you know how to make things lowercase?

quaint mantle
#

What should I do?

chrome beacon
#

You should look in to basic Java before making your first plugin

eternal oxide
wraith rapids
#

remarkable

quaint mantle
#

Is my code not alright?

wraith rapids
#

well i mean

#

you have an empty class

#

but it's no longer on fire and all red and exploding

#

so that's progress

eternal oxide
#

seems not

wraith rapids
#

there's like a maven plugin that can do it I think

#

but I've never bothered to set it up

quaint mantle
#

Can someone tell my, why this doesn't work?

        if(e.getView().getTitle().equalsIgnoreCase(WINDOW.MAIN_NAME)) {
            if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§c✘")) {
                e.setCancelled(true);
            }
        }
#

it doesn't cancel

chrome beacon
#

Looks fine

glossy scroll
#

Oof thats not a good way to test items

chrome beacon
#

^^

quaint mantle
glossy scroll
#

If you have an instance of that itemstack anywhere, use that and call itemStack#isSimilar

quaint mantle
#

ok

#
        ItemStack GLASS = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
        ItemMeta GLASS_META = GLASS.getItemMeta();
        GLASS_META.setDisplayName("§c✘");
        GLASS.setItemMeta(GLASS_META);
        
        if(e.getView().getTitle().equalsIgnoreCase(WINDOW.MAIN_NAME)) {
            if(e.getCurrentItem().isSimilar(GLASS)) {
                e.setCancelled(true);
            }
        }

still not working

sour rampart
#

Is it possible to access the config in a static? Here's my code: https://paste.md-5.net/iyofuligob.cpp
Error: Cannot make a static reference to the non-static method getConfig() from the type JavaPlugin

glossy scroll
#

Use that item

quaint mantle
#

that's the same item

#

but just in another class

obtuse basin
#

Sooo, Following Situation: I want to add an Membersystem for my worldmanagement plugin (each player it's own world), but have no Idea how to save and remove the members of the world, I already tried with a config in the world but it not really helped, any ideas? the code I tried to use for that: ```
fun addmember(world: String, uuid: String): Void? {
val ccfg: File = File("world//" + world + "//world.yml")
val cfg: YamlConfiguration = YamlConfiguration.loadConfiguration(ccfg)
cfg.set("- ", uuid)
try {
cfg.save(ccfg)
} catch (e: IOException) {
e.printStackTrace()
}
return null
}

fun delmember(world: String): Void? {
    val ccfg: File = File("world//" + world + "//world.yml")
    val cfg: YamlConfiguration = YamlConfiguration.loadConfiguration(ccfg)
    cfg.set("- ", null)
    try {
        cfg.save(ccfg)
    } catch (e: IOException) {
        e.printStackTrace()
    }
    return null
}```
glossy scroll
#

Ok well then thats fine

#

Your next problem is coaring inventory names

quaint mantle
#

so it doesn't cancel

glossy scroll
#

I would probably call IntventoryView#getTopInventory

#

Im not sure what InventoryView.getTitle does

quaint mantle
#

it get's the name

glossy scroll
#

I dont think it does apparently

quaint mantle
#

that's the only thing I found for 1.16.5

glossy scroll
#

ugh i just wouldnt realy do it this way so im not sure whats wrong

quaint mantle
#

but I have to do it in 1.16.5

glossy scroll
#

@quaint mantle id just recommend debugging

quaint mantle
#
        ItemStack GLASS = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
        ItemMeta GLASS_META = GLASS.getItemMeta();
        GLASS_META.setDisplayName("§c✘");
        GLASS.setItemMeta(GLASS_META);
        
        if(e.getCurrentItem().isSimilar(GLASS)) {
            e.setCancelled(true);
        }
#

this doesn't work either

#

and it doesn't spit any errors

glossy scroll
#

Make sure you have eventhandler

#

And once again try debugging

quaint mantle
#

omfg

#

I'm sooooooo dumb

ivory sleet
#

Same frankly

glossy scroll
quaint mantle
#

yes

#

xd

bleak sapphire
#

Hi everyone, I've been trying to code a plugin that allows an entity to follow me for a long time. With all the research I've done I still can't do it. Could someone help me?

obtuse basin
glossy scroll
#

LOL i used to make that mistake all the time

glossy scroll
ivory sleet
#

Also uh I mean the type is inferred for val so Idk why write it out but that’s a preference Ig.

#

Also btw iirc kotlin has string interpolation

wispy monolith
#

How to replace player inv?

obtuse basin
ivory sleet
#

List != Map

wraith rapids
#

define "for a long time"

wispy monolith
#

is this going to work?

Inventory player2inv = player2.getInventory();
player1.getInventory().clear();
player1.getInventory().addItem((ItemStack) player2inv);
wraith rapids
#

from across the entire world?

#

for x hours?

quaint mantle
#

you're casting an inventory to an item

wispy monolith
#

So how to do it?

glossy scroll
#

learn java idk

quaint mantle
glossy scroll
#

learn to read jd too

#

player2Inv*

novel hornet
#

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Commandss implements CommandExecutor {
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        
        Player player = (Player) sender;
        player.getInventory().addItem(me.mrpiedot.PantsThatPoopTnt.items.items.TntPants);
        
        return true;
    }
} ```
quaint mantle
#

no

novel hornet
#

i have a error in line 14

wraith rapids
#

check instanceof before cast

obtuse basin
crude charm
#

why did my plugin compile as a bunch of files not classes

#

it should look like this

ivory sleet
#

Reload maven project

crude charm
#

aight

novel hornet
#

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Commandss implements CommandExecutor {
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        
        Player player = (Player) sender;
        player.getInventory().addItem(me.mrpiedot.PantsThatPoopTnt.items.items.TntPants);
        
        return true;
    }
} ``` I'm getting a error in line 14 whats causing this problem
crude charm
ivory sleet
#

Uh weird, restart and invalidate caches

crude charm
#

I did

#

idk how to invalidate caches tho

ivory sleet
#

File -> Invalidate Caches -> Restart and invalidate caches

#

iirc

crude charm
#

ah ok

#

doing that rn

wraith rapids
#
              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.12</version>
                <executions>
                    <execution>
                        <id>compute-plugin-package</id>
                        <goals>
                            <goal>regex-property</goal>
                        </goals>
                        <configuration>
                            <name>plugin.package</name>
                            <regex>.*</regex>
                            <value>${project.artifactId}</value>
                            <replacement>$0</replacement>
                            <failIfNoMatch>false</failIfNoMatch>
                            <toLowerCase>true</toLowerCase>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

ended up with doing this

#

it seems to work

crude charm
wraith rapids
#

but is a bit excessive for just lowercasing a single fucking value

ivory sleet
#

Ah nice zoi

crude charm
#

didnt work

#

but im trying smth else rn

#

which will

#

and

#

it worked

#

🙂

#

the thing I needed to do was add it as a maven project

ivory sleet
#

Pog

ocean warren
crude charm
#

grandle is so shit

#

and ugly

#

idk how people use it

#

I tried it today

#

and rubish

#

hot 💩

ocean warren
#

Pea brain yessir

unkempt ore
#

Would it be a good idea to store an ItemMeta for when I want to create an item stack and just assign the meta right there with the stored data? I assume I should clone it, right?

wraith rapids
#

if I were using gradle I could've done what I did there in like 1 line

#

gradle is definitely better in some ways

#

maven is pretty inflexible and archaic

#

all item metas are clones

ivory sleet
#

True

crude charm
#

mvn package 😋

wraith rapids
#

every time you call getItemMeta, you clone the item's meta

crude charm
#

mvn clean install

compact haven
#

i literally hat eintellij rn

unkempt ore
crude charm
#

mvn package -s

#

mvn package -e

wraith rapids
#

i'm not sure about set

#

but get does clone

crude charm
wraith rapids
#

let me check I suppose

unkempt ore
#

Thanks

crude charm
#

-e shows more info on an error

ivory sleet
#

Yeah, man IntelliJ has been screwing me recently like sheesh

unkempt ore
#

Having more than one item refer to the same meta sounds like it could be catastrophic, so I'm expecting it does defensive copy

crude charm
#

I had an issue with one of my plugins where it wouldn't want to compile my plugin.yml so I had to add it manually each time

wraith rapids
#

it depends

crude charm
#

works with every other plugin

crude charm
#

git clone

wraith rapids
#

bukkit handles items in a pretty convoluted fashion

crude charm
#

mvn clean install

ivory sleet
#

Yeah, it couldn’t find the dependencies onetime so I had to yeet .m2 and reinstall BuildTools for different versions which was a painful process

crude charm
#

boom

unkempt ore
#

Hmmmmm

wraith rapids
#

if you're setting the itemmeta of a craft item stack, it always clones

#

because craftstacks hold nms meta, not bukkit meta

#

all bukkit stacks are also converted to craft stacks and then nms stacks when you insert them in an inventory

#

which clones the meta into nms meta

#

so unless you are holding them as raw itemstacks in an array or something, it won't be an issue

unkempt ore
#

Nice

wraith rapids
#

itemstacks are fucking cancer because you can literally not do anything without tripping a million clones

#

a simple isSimilar clones the item meta of the associated items 2-4 times

#

and considering the meta size of shit like books and shulker boxes, that is a fucking shit fest

ivory sleet
#

didnt know it cloned it so often

wraith rapids
#

some plugins like slimefun that do a lot of issimilar comparisons and set items in inventories will literally make your server shit bricks

#

it doesn't help that they are using a fucking retarded "optimization" which actually just increases the number of meta clones per comparison by a factor of 4

crude charm
#

?paste

queen dragonBOT
wraith rapids
#

i rewrote myself an itemstack impl that is more sane with the way it handles itemmeta and cloning and comparisons

#

i've been working on a live-view itemmeta on and off for a while

ivory sleet
#

hmm so by convenience writing our own itemstack comparison methods might be a good optimization

wraith rapids
#

yeah, but you will of course need nms for that

#

or reflection, i guess

crude charm
#

slime fun has changed SO much

wraith rapids
#

it hasn't

#

it was shit

#

it's still shit

crude charm
#

oh

wraith rapids
#

the author was a tard

#

the author is still a tard

ivory sleet
#

uh that sucks

crude charm
#

im just looking at screenshots

wraith rapids
#

there are just more items now

crude charm
#

not code

wraith rapids
#

that's the only difference

crude charm
#

screenshots

#

not code

#

never seen the code

wraith rapids
#

you don't want to, either

#

i'm currently in the slow process of rewriting slimefun from scratch

crude charm
#

but whatever these pipy things are look cool

wraith rapids
#

i have even decided on a name

crude charm
#

idk what they doi

wraith rapids
#

i shall call it shrekfun

crude charm
#

or what the plugin is about

wraith rapids
#

so I can keep the /sf shorthand

#

it will be ogre and onion themed

crude charm
#

call it

#

slimefunissoshitsoimadethisinstead

wraith rapids
#

i feel strangely accomplished now that i've managed to automagically lowercase my artifactId

#

how magical

ivory sleet
#

lmao

vast quest
#

can someone help me with making custom config files

crude charm
#

its easy

vast quest
#

I cant understand from the tutorial

crude charm
#

its easy tho

wraith rapids
#

new YamlConfiguration

vast quest
#

I cant understand tho

wraith rapids
#

config.save(file)

crude charm
#

then understand

wraith rapids
#

config.load(file)

vast quest
#

do I put those on load?

crude charm
#

yes

wraith rapids
#

you put them where you need them

#

load the config when you need to load it

#

save it when you need to save it

vast quest
#

how to reload it

crude charm
#

delete it when you need to delete it

#

#reload

vast quest
#

can I have multiple?

wraith rapids
#

reload is just re-loading it; calling load again

crude charm
#

yes

wraith rapids
#

keep in mind that .save nukes all comments

#

because nobody has bothered to update bukkit to use the new snakeyaml versions that don't explode with comments

minor garnet
#
    public static List<Loot> loadAll(){
        List<Loot> loots = new ArrayList<Loot>();
        try {
            String query = "SELECT * FROM loot";
            ResultSet rs = stmt.executeQuery(query);
            while(rs.next()) {
                Loot loot = new Loot(rs.getString(1), Utils.itemStackFromBase64(rs.getString(2)),
                                        rs.getInt(3), Utils.deserializeLocation(rs.getString(4)));
                loots.add(loot);
            }
        } catch(SQLException e) {
            
        }
        return loots;
    }```
wraith rapids
#

because it is a law of nature that literally everything in bukkit must stagnate and be at least 5 years out of date

#

because otherwise, what would happen to those poor, poor plugins written for 1.8 that nobody fucking uses anymore

minor garnet
#

why i getting null by array list ?

wraith rapids
#

what is line 48

minor garnet
#

well its other method because spaces,

wraith rapids
#

???

minor garnet
#

but i think is this List<Loot> loots = new ArrayList<Loot>();

wraith rapids
#

that can not throw a npe

#

GroundLoot class, line 48

minor garnet
#

sorry i mistake

#

is thios

wraith rapids
#

something is null

crude charm
#

WTF is that red terminal

minor garnet
#

red terminal ?

crude charm
#

that is so ugly how do you see

unkempt ore
#

It hurts

wraith rapids
#

let me show you some red

crude charm
#

oops

#

ignore that

minor garnet
#

?

crude charm
minor garnet
#

yes ?

crude charm
#

its ugly

#

I cant read it

minor garnet
#

because of it

#

i send a text message

vast quest
#

what does this mean saveResource("name of file in jar here", replaceIfAlreadyExists). and where am I suppose to put it

crude charm
#

this is alot easier to read

crude charm
#

LMFAO

#

VIRTUAL BOY

#

HAHAHAHA

minor garnet
#

ok so ?

crude charm
minor garnet
#

whats is suposse to be null i think a loot class maybe ?

#

i already tried debug it

wraith rapids
#

a class cannot be null

crude charm
#

so its throwing an error

#

yeah

#

use

#

ready for it

#

dependency injection

#

WOW

wraith rapids
#

@vast quest you put it in the resources directory

#

maven will then package it into your jar

#

and that method will pull it out of the jar

vast quest
#

ok then

wraith rapids
#

maven or whatever dependency manager you're using

vast quest
#

how can I use it?

wraith rapids
#

what do you mean use

vast quest
#

like get smth from it

wraith rapids
#

you call the method

#

it shits out a file into the plugin directory

#

then you access that file

#

as you would any other file

vast quest
#

it wants me to make public FileConfiguration getCustomConfig() {
return this.customConfig;
} static

minor garnet
#

d e a d.. code ???

unkempt ore
#

Means it can't be reached

vast quest
#

im reading from this but it doesnt say it needs to be

wraith rapids
#

you don't need to put the config in the jar, no

#

but then you need to write it with code

#

config.set("key", value)
config.save

minor garnet
#

so i dont know

unkempt ore
#

Your flow of control won't let that code be reached, that's what it means

#

That implies loot can't be null

vast quest
wraith rapids
#

why

#

i mean what

vast quest
#

Oh wait

#

nvm

hidden torrent
vast quest
#

I forgot to get instance

unkempt ore
#

if (loot == null) (dead code)

#

I don't know what else that could mean to you

wraith rapids
#

usually that would highligh the if clause itself though

unkempt ore
#

Why?

hidden torrent
#

dang, yea I didn't see immediately that it is pointing towards that if-code

wraith rapids
#

because it is either always true or always false

#

thus making it redundant

unkempt ore
#

You're right actually

#

It would say "This would always be true"

wraith rapids
#

well, whatever

#

redundant is redundant

#

just delete it

unkempt ore
#

But I mean, dead execution means the same thing, true

quaint mantle
#

oops wrong discord

wraith rapids
#

my client keeps all deleted images

#

i will now dox you using this image you accidentally sent

quaint mantle
#

mine does too

#

I just didn't want it to be there for people that didn't see it

wraith rapids
#

looks fancy though

obtuse basin
wraith rapids
#

config.set("key", map)

#

all of the elements in the map should be ConfigurationSerializable

#

iirc

eternal oxide
#

reload after saving to have the Map convert into a MemorySection

wraith rapids
#

and the keys should be strings

#

i think there might also be an util method somewhere to create a memorysection or a configsection out of a map, but I'm not sure

unkempt ore
#

Are NamespacedKeys reusable?

wraith rapids
#

they are immutable

#

so yes

unkempt ore
#

Good

wraith rapids
#

and you should always at least try to reuse them

#

constructing them on the spot is relatively cheap but is a bit of a code smell unless doing that is actually necessary

vast quest
#

do I have to create the file in the jar

#

for it to generatwe

wraith rapids
#

yes

#

that's what saveResource does

#

it takes the file out of the jar

#

if there's nothing to take, it can't take it out

#

put it in your resources directory in your ide and it should be automatically packaged into your plugin

#

like config.yml

#

and plugin.yml

vast quest
#

Ok

#

btw wdym by commenting breaks?

#

can I not put comments in the yml

wraith rapids
#

config.save deletes comments

vast quest
#

oh

wraith rapids
#

only way to have comments is to write them in the yml file in your ide

#

and then save it with saveResource

#

that keeps comments

vast quest
#

ok

minor garnet
#

okay ```vb
List<Loot> list = ConnectionSQL.loadAll();
if (list != null) sendMessage("is not null");
}

#

public static List<Loot> loot; i need add it to

wraith rapids
#

split every deference onto a new line

vast quest
#

welp imma recode my entire plugin cuz im changing from normal config to custom config

wraith rapids
#

and try again

vast quest
#

for events adn stuff

wraith rapids
#

use a configuration library or framework

#

bukkit's is mediocre at best

vast quest
#

uh

#

whats that

wraith rapids
#

a thing that does configurations

vast quest
#

Uhm

wraith rapids
#

i guess bukkit's config api is beginner friendly

vast quest
#

it doesnt generate the config

#

:/

wraith rapids
#

open up the jar

#

is the file there

vast quest
#

the jar

#

or the editor

wraith rapids
#

the jar

vast quest
#

ok I made it zip

#

yes its there

wraith rapids
#

what is its name

vast quest
#

events.yml

wraith rapids
#

what is the line of code you're extracting it with

sharp bough
#

how many ticks does this delay the action?

#

Bukkit.getScheduler().runTask(Main.get(), () -> player.teleport(loc));

wraith rapids
#

0 to 1

#

it runs at the start of the next tick

vast quest
#
    private void createEventFile() {
        Events = new File(getDataFolder(), "events.yml");
        if (!Events.exists()) {
            Events.getParentFile().mkdirs();
            saveResource("events.yml", false);
        }

        customConfig = new YamlConfiguration();
        try {
            customConfig.load(Events);
        } catch (IOException | InvalidConfigurationException e) {
            e.printStackTrace();
        }
    }
#

this is what I have

compact haven
#

thats

#

not how u java

#

at all

#

well actually its pretty similar

#

minus the incorrect naming

vast quest
#

o

#

ok

wraith rapids
#

how does that even compile

compact haven
#

and Events needs to be init

#

before u call that

wraith rapids
#

i guess "Events" is a field you've declared earlier with a type of File

#

stick to the conventions please

#

variables and fields should be lowercase

#

trying to read code that throws the conventions out of the window is cancer

#

that said

#

events.yml will never exist

#

although you are extracting it if it doesn't exist

#

dunno

minor garnet
#

public static List<Loot> loot;

        List<Loot> list = ConnectionSQL.loadAll();
        sendMessage(list.get(1).getName());```

is working but tho define all i need cast it ?
wraith rapids
#

that looks haram

minor garnet
#

haram ?

#

when i execute that line e get null exception message

vast quest
#

NNY imma be honest

#

I just copied from the thing

wraith rapids
#

i hate the antichrist

vast quest
#

??

quaint mantle
vast quest
#

can someone tell me what im missing/

sour rampart
sour sand
#

how to do you set the amount in an itemstack

wraith rapids
#

itemstack.setAmount

sour sand
#

ok thanks

wraith rapids
#

it's fucking rocket science, I know

sharp bough
#

is there a way to cancel the next event happening by a player or update a gui without closing and reopening the inv?

#

i have a gui with a listener that sends you to a location if you exit the gui, but i want to be able to delete the beds without sending you to the default location , when you click an item it sends you to that location

wraith rapids
#

mark the player in a set or something when you close their inventory

#

in your listener, check if the player is marked, and if they are, ignore the event

#

then unmark them

sharp bough
#

hm

#

thats a good ideaa

#

and then reopen the gui with the new items

wraith rapids
#

super hyper technically you don't even need a set or anything, just a single boolean

sharp bough
#

wdym

wraith rapids
#

but a set would probably be a less fragile solution

vast quest
#

so how can I make a custom config generate?

sharp bough
#

i could save them in the yaml file with false, and then if getIsUpdating cancel the event

#

or something like that

#

right?

wraith rapids
#

strip out all of the ifs and shit and see if the saveResource call works

#

you don't need to save them in an yaml

#

you only need to mark them for 1 tick

#

yaml and files are used when you need to remember something after the server restarts

sharp bough
#

and how do you mark a player? do i save the uuid?

wraith rapids
#

which you do not need to do

#

Set<Player> or Set<UUID>

#

add and remove

sharp bough
#

oh

#

didnt know what existed

quaint mantle
#
            try {
                if(Economy.hasEnough(p.getDisplayName(), 300)) {
                    try {
                        Economy.subtract(p.getDisplayName(), 300);
                        p.sendMessage(Main.PREFIX + "Du hast erfolgreich §e1 Netherite §7gekauft.");
                        p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 2F, 2F);
                    } catch (NoLoanPermittedException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                } else {
                    p.sendMessage(Main.PREFIX + "Du hast nicht genügend Geld!");
                }
            } catch (UserDoesNotExistException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

it doesn't work

#

how do I broadcast message in server?

wraith rapids
#

why are you using display names

#

you should be using the player name, not the player display name

sharp bough
quaint mantle
wraith rapids
#

player display name can be changed with shit like essentials /nickname

sharp bough
#

lol

wraith rapids
#

you probably don't want that

eternal oxide
#

@wraith rapids I found no way to lowerCase so this is the best I ended up with ```yaml
<groupId>com.palmergames</groupId>
<artifactId>homestead</artifactId>
<name>Homestead</name>
<version>0.0.1-SNAPSHOT</version>
<description>Homestead land claim and protection system.</description>

<!-- Project's website -->
<url>http://palmergames.com</url>

<properties>
    <project.bukkitAPIVersion>1.16</project.bukkitAPIVersion>
    <project.javaVersion>1.8</project.javaVersion>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jar.finalName>${project.name}</jar.finalName>
</properties>

name: ${project.name}
main: ${project.groupId}.${project.artifactId}.${project.name}
version: ${project.version}
api-version: ${project.bukkitAPIVersion}

author: ElgarL
website: ${project.url}

description: >
${project.description}```

quaint mantle
#

with my homies

#

not public

wraith rapids
#

you still don't want to use display name

#

bad code is bad code

quaint mantle
#

ok, UUID then?

wraith rapids
#

homies or not

#

no

#

player name

#

player.getName

quaint mantle
#

Ok

wraith rapids
#
              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.12</version>
                <executions>
                    <execution>
                        <id>compute-plugin-package</id>
                        <goals>
                            <goal>regex-property</goal>
                        </goals>
                        <configuration>
                            <name>plugin.package</name>
                            <regex>.*</regex>
                            <value>${project.artifactId}</value>
                            <replacement>$0</replacement>
                            <failIfNoMatch>false</failIfNoMatch>
                            <toLowerCase>true</toLowerCase>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I also came up with something @eternal oxide

#

this little plugin thingy converts the artifact id to lowercase

quaint mantle
#
wraith rapids
#

but i guess it is pretty excessive just to convert one string to lowercase lmao

#

oh so you gave up on the eclipse tutorial now

#

and now you want to switch to intellij

#

and want a tutorial for it

quaint mantle
#

no but a frand told me to use intellij

eternal oxide
grand coral
#

How to make own BreakBlockEvent?

wraith rapids
#

you know, you're going to run out of things to give up on at this rate

sharp bough
quaint mantle
#
public class Broadcast implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        if (args.length > 0){
            Bukkit.broadcastMessage(String.valueOf(args));
        }
        else {
            player.sendMessage(ChatColor.GRAY.toString() + "Usage:" + ChatColor.AQUA.toString() + " /broadcast <message>");
        }

        return false;
    }
}
#

why its giving error

sharp bough
#

cuz args is not 1 word

#

you have to use for string in args

#

add that to a list replacing _ with " "

#

i think

hexed rover
#

String.join(" ", args)

wraith rapids
#

i mean it takes the artifact id, converts it to lowecase, and writes it as the value of the "plugin.package" property @eternal oxide

#

the actual artifact id remains capitalized

quaint mantle
#
public class Broadcast implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        if (args.length > 0){
            Bukkit.broadcastMessage(String.join("", args));
        }
        else {
            player.sendMessage(ChatColor.GRAY.toString() + "Usage:" + ChatColor.AQUA.toString() + " /broadcast <message>");
        }

        return false;
    }
}
#

like this?

eternal oxide
wraith rapids
#

why? the artifact Id remains capitalized

eternal oxide
#

They started enforcing lower case on Artifacts a while back

wraith rapids
#

what

#

that's gay

eternal oxide
#

very

wraith rapids
#

well fuck github i guess

eternal oxide
#

I had to move GroupManager to groupmanager to be able to install

wraith rapids
#

i thought you meant they enforced not having them as lowercase

eternal oxide
#

it worked for years, but all of a sudden gave a wierd error that tells you nothing

wraith rapids
#

github is going down the shitter

eternal oxide
#

one step forward, two back

young knoll
#

What packet

quaint mantle
# hexed rover String.join(" ", args)
public class Broadcast implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        if (args.length > 0){
            Bukkit.broadcastMessage(String.join("", args));
        }
        else {
            player.sendMessage(ChatColor.GRAY.toString() + "Usage:" + ChatColor.AQUA.toString() + " /broadcast <message>");
        }

        return false;
    }
}
wraith rapids
#

good thing I don't really use github actions or anything

#

or really use github at all

eternal oxide
#

I have my own private git locally hosted, but public goes on GitHub

wraith rapids
#

they don't actually block like your entire repository if they sniff out you have a not-lowercase artifact id in your pom somewhere, do they

#

it's just for like, actions and all of the other build magic and shit

eternal oxide
#

no, only if you use install

#

general hosting works fine

#

everyone is just going to use jitpack if they made things any more difficult.

wraith rapids
#

or just not deploy to github

#

i've found the github packages support work really terribly anyway

#

tried to get it to work for a good few days at one point and everything just kept blowing up one by one

hexed rover
quaint mantle
#

@hexed rover

#
[20:59:09 ERROR]: Error occurred while enabling Demo v0.0.1 (Is it up to date?)
java.lang.NullPointerException
        at me.nix.demo.Demo.onEnable(Demo.java:22) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[patched.jar:git-PaperSpigot-"4c7641d"]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [patched.jar:git-PaperSpigot-"4c7641d"]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:407) [patched.jar:git-PaperSpigot-"4c7641d"]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:359) [patched.jar:git-PaperSpigot-"4c7641d"]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:318) [patched.jar:git-PaperSpigot-"4c7641d"]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:408) [patched.jar:git-PaperSpigot-"4c7641d"]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:372) [patched.jar:git-PaperSpigot-"4c7641d"]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:327) [patched.jar:git-PaperSpigot-"4c7641d"]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:267) [patched.jar:git-PaperSpigot-"4c7641d"]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:563) [patched.jar:git-PaperSpigot-"4c7641d"]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
[20:59:09 INFO]: [DEMO] Disabling Demo v0.0.1
hexed rover
#

Did u register the command in plugin.yml

quaint mantle
#

oof

wraith rapids
#

lmao paperspigot

vast quest
#
package whyhax.proje;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;

public class Proje extends JavaPlugin {

    private File customConfigFile;
    private FileConfiguration customConfig;

    @Override
    public void onEnable(){
        createCustomConfig();
    }

    public FileConfiguration getCustomConfig() {
        return this.customConfig;
    }

    private void createCustomConfig() {
        customConfigFile = new File(getDataFolder(), "custom.yml");
        if (!customConfigFile.exists()) {
            customConfigFile.getParentFile().mkdirs();
            saveResource("custom.yml", false);
        }

        customConfig= new YamlConfiguration();
        try {
            customConfig.load(customConfigFile);
        } catch (IOException | InvalidConfigurationException e) {
            e.printStackTrace();
        }
    }
}
 ``` I copied from <https://www.spigotmc.org/wiki/config-files/#using-custom-configurations> word by word and it STILL DOESNT GENERATE
hexed rover
#

do you have a custom.yml in your src folder

wraith rapids
#

get rid of all ifs and shit and just test the saveResource call

vast quest
wraith rapids
#

yes

#

just delete literally everything

#

and add only the saveResource call to onenable

hexed rover
#
        if (!file.exists()) {
            if (!file.getParentFile().exists())
                if (!file.getParentFile().mkdirs()) {
                    // error 
                }

            plugin.saveResource(file, false);
        }```
this is usually what i do
vast quest
#
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;

public class Proje extends JavaPlugin {

    private File customConfigFile;
    private FileConfiguration customConfig;

    @Override
    public void onEnable(){
        saveResource("custom.yml", false);
    }

}
 ``` deleted litteraly anything
#

imma tst

hexed rover
#

does it give you any errors if that doesnt work?

vast quest
#

Nope doesnt work

wraith rapids
#

and you have a custom.yml file in the root of your plugin jar

vast quest
wraith rapids
#

next to your config.yml and plugin.yml

vast quest
#

Yes

wraith rapids
#

and you are checking the compiled jar

#

and not your ide or whatever

vast quest
#

no ;-;

wraith rapids
#

i told you to open up the jar

#

what did you think I meant by that

#

open it with like winrar or whatever

vast quest
#

the config.yml is IN the compiled jar

wraith rapids
#

and custom.yml?

vast quest
#

Yes

wraith rapids
#

they're in the root of the jar, both in the same directory

vast quest
#

yes

#

just when I open it

#

[18:37:34 ERROR]: Could not load 'plugins\Proje-1.0.jar' in folder 'plugins'

wraith rapids
#

and what's the exception

vast quest
wraith rapids
#

use some paste site

vast quest
#

ok

wraith rapids
#

Cannot find main class `whyhax.proje.Proje'

vast quest
#

huh

#

public class Proje extends JavaPlugin {

wraith rapids
#

no wonder nothing is happening, your plugin isn't even enabling to begin with

vast quest
#

o

#

how can I fix that

wraith rapids
#

open up the jar and check whether the path bukkit is looking for is exactly the same as the path of your main class

vast quest
#

yep

#

it is

wraith rapids
#

restart your server instead of using reload

quaint mantle
#
wraith rapids
#

whichever

vast quest
#

error has gotten shorter

wraith rapids
#

try the first one

#

when you give up on it

#

you can try the second one

vast quest
wraith rapids
#

it still can't find your main class

vast quest
#

idk

wraith rapids
#

show a screenshot of you looking at your compiled main class in your jar

vast quest
wraith rapids
#

that is not a fucking jar

#

open up your compiled jar

#

navigate to your main class

vast quest
wraith rapids
#

yeah i don't know

#

magic i guess

vast quest
#

should I try to open another project?

wraith rapids
#

i guess

vast quest
#

uh

#

magic is weird

#

huh

vast quest
#

for sum reason

#

ok...

sick ravine
#

I created Custom Enchant from net.minecraft.server.v1_12_R1.Enchantment but in minecraft I don't see EnchantName I
Can you help me?

#

;_;

proven sierra
#

You can't get the client to render it

north osprey
#

@sick ravine I also tested creating custom enchantments recently and had the same problem. Perhaps some custom datapack with translations for your enchantment would do it. At least that was my hypothesis but I haven't tested that.

sick ravine
#

on 1.16.5, client is able to render custom enchants names

wraith rapids
#

how unfortunate that you're using a version that is like 4 years old

north osprey
#

BTW you should not need to access classes from the net.minecraft package.

wraith rapids
#

does bukkit let you register custom enchantments through the api now?

#

last I checked you still needed nms

north osprey
#

I did it by enabling org.bukkit.enchantments.Enchantment.acceptingNew private field through the reflection API.

#

But as I said, the name still did not render...

wraith rapids
#

lol

sour rampart
wraith rapids
#

i guess that works

#

you shouldn't access the config in a static void

sour rampart
#

oh

wraith rapids
#

static is static and shouldn't depend on the data held by your plugin instance

#

such as your config

sour rampart
#

how can I access the config not in the main class then

wraith rapids
#

normally

#

pass your plugin object to the object you want to access it in

#

and then just call methods on it

north osprey
#

If you have a piece of code that depends on the config then just pass the config instance.

sick ravine
#

public class CustomEnchantment extends net.minecraft.server.v1_12_R1.Enchantment {

}

CustomEnchantment customEnchantment = new CustomEnchantment(...

net.minecraft.server.v1_12_R1.Enchantment.enchantments.a(100, new KeyMinecraft("customEnchantment"), customEnchantment);
CraftEnchantment craftEnchantment = new CraftEnchantment(customEnchantment);
org.bukkit.enchantments.Enchantment.registerEnchantment(customEnchantment);

north osprey
#

Passing the plugin instance is also ok but then you'll not be 100% truthful about what your code depends on.

north osprey
#

IMO reflection dependent on the Bukkit API is much better than code dependent on decompiled classes...

#

This will break on different versions.

wraith rapids
#

depends

#

the best way is to have version-specific submodules

#

but that is usually only for large projects that require a lot of diddling with the internals

#

reflection is fine for small things

sick ravine
#

It gets repaired sometime with reflection

north osprey
#

I think that in case of enchantments we already rely on some stability throughout versions. Otherwise we would not have that in the Spigot API.

wraith rapids
#

issue with reflective code that it's not as maintainable as directly programming against existent things

#

of course that's not an issue for something as simple as setting a single field somewhere

north osprey
#

agreed\

#

Reflective code does not typecheck

wraith rapids
#

what I usually do is either have version specific submodules + a reflective fallback impl

#

or for smaller projects, just build against the latest version of nms and have a reflective fallback impl

vast quest
#

Ok NNY

#

I made it work

#

tho how can I reload it

wraith rapids
#

config.load

#

like i said, reloading is re-loading

#

loading again

vast quest
#

.getCustomConfig().load;??

wraith rapids
#

you would want to create a method like reloadCustomConfig

#

which would just do customConfig.load

vast quest
#

and what do I put into that

wraith rapids
#

in the class that manages your custom config

#

and remembers the YamlConfiguration that represents the config

#

and the File that specifies where your config is on the disk

#

so it can call config.load(file)

vast quest
#

I just use the main class for config

wraith rapids
#

then do it there

vast quest
#

so but

#

can you show me what to do

wraith rapids
#

no

vast quest
#

im just so confused

wraith rapids
#

make your main plugin object remember the File

#

make your main plugin object remember the YamlConfiguration

vast quest
#

but like getCustomConfig is ALREADY the file

wraith rapids
#

no

#

it should not return the File

#

it should return the YamlConfiguration

vast quest
#
    public FileConfiguration getCustomConfig() {
        return this.customConfig1;
    }```
wraith rapids
#

yes

#

YamlConfiguration is a kind of FileConfiguration

#

it's not a File

#

it's a Configuration

vast quest
#

ok

#

so

north osprey
#

Out of curiosity @wraith rapids how do you manage state that needs persistence and atomic writes in your plugins?

vast quest
#

getCustomConfig().load("config.yml")

wraith rapids
#

atomic in what context

#

cross-server? threaded?

north osprey
#

That a server crash in the middle of a state modification does not corrupt it.

#

Main thread only.

wraith rapids
#

depends on how robust it needs to be

#

the most robust way is to piggyback off the atomicity of the filesystem

north osprey
#

That's the way I want to go right now.

vast quest
#

uh also

north osprey
#

But have you tried out some local no-sql DBs?

wraith rapids
#

or if you are using a database, your db probably has atomicity guarantees

vast quest
#

how can I delete the old config whenever I update the plugin

wraith rapids
#

depends on the db you're using

#

i don't really use nosql

north osprey
#

then how do you serialize your state?

wraith rapids
#

i serialize it and then send it to whatever persists it

#

it's the job of the thing persisting it to make the underlying write atomic

#

if it's a database, I rely on the writes being atomically implemented there

#

if it's like a raw file or something, I write and replace

north osprey
#

What serialization do you use? I wanted my state to be readable so I serialize it to JSON. Having that Mongo seems like an obvious choice for storing it when it comes to a DB.

wraith rapids
#

with raw files, usually I just hammer everything into raw bytes

#

json is fine for readability I suppose

#

i'm not so sure about nosql but in most sql cases, hammering shit into json and storing in a text column is kind of frowned upon except for specific cases

north osprey
#

I asked because I was wondering whether there is some tried and tested solution to that.

wraith rapids
#

the meta is to have a table with columns for each of the keys your json mapping would have

north osprey
#

Or perhaps that you've managed to do some performance analysis.

wraith rapids
#

and then store a reference to that row in the column you'd store your json in

north osprey
#

Yeah, I know how to use an SQL DB 😄

wraith rapids
#

but, well, my point is that the atomicity should be provided by the database

vast quest
#

can I disable my plugin?

wraith rapids
#

it shouldn't be handled on your end

vast quest
#

like make it red on /pl

wraith rapids
#

Bukkit.getPluginManager().disablePlugin

#

or something

north osprey
#

One more question. Have you compared doing file IO on the main server thread vs offloading it to a different thread and then scheduling a continuation to go back to the main thread?

wraith rapids
#

i generally design everything so that doing io on the main thread is not necessary

vast quest
#

can I get the plugins version

#

and use it in main clas

#

the one in the pom

wraith rapids
#

jumping to an off-thread and having the off-thread do the IO and blocking the main thread until the IO is done will obviously be slower than just the raw IO

#

because you get overheads from hopping your data between threads and all of the scheduling overhead

north osprey
#

@vast quest in SBT there is a plugin for that but I don't know how Maven deals with that. I'd guess there is something similar.

#

Yeah, I don't mean blocking the main thread.

eternal oxide
vast quest
#

o

wraith rapids
#

if you absolutely have to have your main thread operation not resume a tick later or something, you can do your work on the main thread while the off-thread IO happens

vast quest
#

so plugin.getDescription("version")?

wraith rapids
#

and once you're done with your MT work, you start blocking on the completed IO result

eternal oxide
#

look and see

#

because no, thats not right

wraith rapids
#

that can be faster than just doing the IO on the main thread, but not necessarily because of the concurrency overhead

vast quest
eternal oxide
#

I know

wraith rapids
#

it's best to design things so that your MT work can be put on hold and allow the server to resume for a tick before checking whether your off-thread resources are ready, and then resuming if they are

#

of course that's not always possible, with things like events

north osprey
#

What do you mean by "MT"?

wraith rapids
#

main thread

north osprey
#

ok

vast quest
#

what???

wraith rapids
#

replace == with equals()

#

don't compare strings with ==

#

read the description of the warning

#

more actions -> show description

vast quest
#

also should I put objectnonull thing

wraith rapids
#

if the string you are calling .equals on can be null

#

use Objects.equals(a,b)

#

instead of a.equals(b)

#

if a is null and you call .equals on it, it explodes

#

Objects.requireNotNull hides the warning but still explodes

vast quest
north osprey
#

What I considered is something like that:

  modifyMinecraftWorldBefore()
  Bukkit.getScheduler().runTaskAsynchronously(plugin, () => {
    saveStateFile()
    Bukkit.getScheduler().runTask(plugin, () => {
      modifyMinecraftWorldAfter()
    })
  })
wraith rapids
#

yeah, that is a pretty standard way of doing some mt work, then doing off thread work, and then resuming work on the main thread

#

there are some libraries and things that simplify it and reduce the indentation madness, like Aikar's TaskChain

north osprey
#

I'm writing in Scala so I considered using the builting Future class

sharp bough
vast quest
#

NNY is there anyway I can catch a empty null error

wraith rapids
#

futures don't really play well with the main thread

#

there are surprisingly few cases where you can use them

#

basically, your future must be completed on the MT if you want to use any of the thenX methods to do bukkit stuff

#

since the thenX methods are called by the thread completing the future

north osprey
#

I mean scala.concurrent.Future

wraith rapids
#

i haven't worked with those, but I'd assume they run into the same restriction

north osprey
#

you can specify an ExecutionContext with every flatMap

#

so it could be done

wraith rapids
#

jist of the issue is that there isn't really any good way to tell a future to run on the main thread

#

since bukkit doesn't provide any executors or anything that futures could hook into

#

there's just the scheduler

#

Bukkit.getScheduler().runTask()

north osprey
#

but I'm not sure I'll get enough value from that to justify the additional overhead

wraith rapids
#

do whatever is easier to maintain

#

without using libraries or whatnot, the simplest and easiest to read way would probably be to create a class for each of these kind of tasks, and then declare a method for each of the phases

#

and then use the bukkit scheduler to invoke the methods either on an off-thread or the main thread

#

and have each of the methods schedule the next one

#

and then you basically have taskchain

#

but, for simple things, you can just nest scheduler calls and lambdas

vast quest
#

how can I check if protocolib is enabled

#

and on the server

wraith rapids
#

BUkkit.getPlugin("ProtocolLib")

#

check if it's null or if it's not isEnabled

north osprey
#

That's the idea. The rest of the code is supposed to be organised into neat functions already so it should still be readable. If I get into a situation where I need to nest state updates then I'll probably go with the "for-comprehension" notation from Scala and try to implement an ExecutionContext based on the Bukkit Scheduler.

#

Should be easy enough.

vast quest
#

there is no getPlugin

wraith rapids
#

try PluginManager::getPlugin

#

bukkit.getpluginmanager

sharp bough
#

why do i get that i dont get it

vast quest
#

Ok

#

how can I check if its not enabled?

wraith rapids
#

read what I said

north osprey
#

@sharp bough use the streams API.

#

It is much more readable.

wraith rapids
#

real men write for loops

vast quest
#

so

#

this?
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null || Bukkit.getPluginManager().getPlugin("ProtocolLib").isEnabled()) {

north osprey
#

😄

wraith rapids
#

don't call it twice

#

assign it to a variable

quiet ice
#

If anything use List#forEach

wraith rapids
#

and use &&

quiet ice
#

Streams have an overhead of their own, not worth it

wraith rapids
#

you want it to be not null and enabled

sharp bough
vast quest
#

but... but... you said OR

north osprey
#

@quiet ice I think what you're suggesting is premature optimisation.

wraith rapids
#

yeah you wouldn't believe how much extra performance paper has squeezed out of the server by just replacing streams with for loops and shit in mojang code

#

it's absolutely insane

#

like a third of the server's tick time is streams overhead

quiet ice
#

It will use an iterator either way, using the iterator directly is a lot better

wraith rapids
#

I said if it's null or if it's not enabled

vast quest
#

Plugin protocheck = Bukkit.getPluginManager().getPlugin("ProtocolLib");
if (protocheck != null && protocheck.isEnabled()) {

wraith rapids
#

(a == null || !a.isEnabled)
is the same as
!(a != null && a.isEnabled)

#

it is

vast quest
#

so then

north osprey
#

@sharp bough I can try to get you a code snippet. Give me a moment.

vast quest
#

if (protocheck == null && !protocheck.isEnabled()) { this will trigger if its NOT installed

#

right

quiet ice
#

Now it is

wraith rapids
#

yes

vast quest
#

Ok

wraith rapids
#

note that you shouldn't import any protocollib classes in the class you're checking that in

#

interacting with classes that don't exist will cause the entire class to blow up before it even gets to your condition

quiet ice
#

Well, it might work, but sometimes will not work

wraith rapids
#

yeah, imports are kind of a rule of thumb

quiet ice
#

It has always been a gamble for me

vast quest
#

im just making it so the plugin does not work when protocolib is not installed

wraith rapids
#

then add protocollib as a depend in plugin.yml

#

and bukkit will check it for you

vast quest
#

I did

wraith rapids
#

and not enable your plugin at all if it isn't enabled

vast quest
#

oh so I dont even need to do that

#

ok.

wraith rapids
#

instead it will throw some arcane and fucking unintelligible exception

#

which is going to result in 300 1 star reviews on your resource page

north osprey
#

@sharp bough

IntStream.range(0, totalLimits)
  .map(index -> Main.get().getConfig().getInt("bedLimits." + index + ".limit")
wraith rapids
#

"plugin doesn't work"

glossy scroll
#

But its the movement packet

sharp bough
#

that looks even worse than what im using lol

wraith rapids
#

in md5 mapped nms yeah

sharp bough
#

its fine i can figure it out thanks tho

wraith rapids
#

md can't name things

north osprey
#

It doesn't involve mutating a list...

glossy scroll
#

And basically i just always set the onGround boolean to true with jump boost 128

north osprey
#

Every opportunity to avoid mutating state is worth considering...

glossy scroll
wraith rapids
#

paper is going to

#

soon ™

glossy scroll
#

Jealous but im loyal to spigot

wraith rapids
#

why eat next to a clown when you could dine with a king

glossy scroll
#

LOL

quiet ice
#

I'll stay loyal to not using nms

glossy scroll
#

Paper is the clown

wraith rapids
#

you're the clown

north osprey
#

xD

glossy scroll
#

:(

young knoll
#

Interesting

glossy scroll
wraith rapids
#

yeah, the packet name belongs to a long list of examples like

#

VillagePlace

glossy scroll
#

LOL

wraith rapids
#

and entityJoinedWorld

quiet ice
#

I don't care about the impl

glossy scroll
#

and Effect.STEP_SOUND

#

that one is one of the worst

#

Its in bukkit too

wraith rapids
#

we can't even change it

#

because it would break backwards compat with the 1.8 plugins

glossy scroll
#

Yes exactly

#

Maybe deprecate and just add a new one unless that breaks something, not checked l

#

But it’s definitely top 10 worst names

wraith rapids
#

the enchantment and potion effect names are also cancer

glossy scroll
#

lol true

#

They used to be worse

#

Same with material

#

DIODE

wraith rapids
#

iirc they're cancer because those used to be their internal names or something at the time

young knoll
#

The entire material enum

wraith rapids
#

yeah the material enum is a fucking travesty

glossy scroll
#

Yea material still is cancer

young knoll
#

And yes, Mojang had some strange internal names

glossy scroll
#

Accept Choco’s pr when?

wraith rapids
#

we changed the material enum to conform with vanilla item and block names

young knoll
#

Until emerald was added, diamonds were emerald internally

wraith rapids
#

and look at all of the hoops we had to jump through to get there

glossy scroll
#

we need the registry system choco has

#

Desperately

wraith rapids
#

the entire fucking plugin bytecode of a plugin running a legacy api version is rewritten prior to plugin load now

#

just to weed out some legacy material names

#

it's fucking ridiculous

young knoll
#

But backwards compat

glossy scroll
#

1.18 should be the great spigot reqrite

#

Similar to 1.8

wraith rapids
#

it breaks a hundred times more shit than just changing the material names alone would have