#help-development
1 messages Β· Page 1845 of 1
it all depends on the purpose of the class
if the class is more for internal purposes DI isn't necessary, but if its something intended to be accessed outside of the library you should use DI but there are some edge cases where you shouldn't use it but most of the time you don't encounter such things
i talking about Spring like DI where you just makes constructor with some Classes and they are automatically passed in
is there an event for when a new user is whitelisted? or when a user is removed from whitelist
But as you exemplified yourself, spring, which is an enterprise library to build enterprise apps with, chances are youβll end up with 10 args constructors thus assisted injection can be a life savior
you could just listen for a command event that is the whitelist
i do my own DI library for spigot and it saves my time when when i comes to use classes like "Settings", "PlayerRepository" etc
i've needed to make a little bit custom DI for Spigot purpose
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerCommandPreprocessEvent.html
@timid kraken
declaration: package: org.bukkit.event.player, class: PlayerCommandPreprocessEvent
Sounds weird, like guice can bind singletons and already created instances
Itβs very sophisticated
inject everything!

oh
why isn't there an event for this tho? it seems reasonable to have one
because there is 2 events that cover this where you can check if its whitelisting
there is the commandpreprocessevent which is for players
and there is ServerCommandEvent for anything not a player
you can easily check from those events if the command being run is the whitelist one
but both of them work for many other commands aswell right, also what if the whitelist failed
like the username provided was wrong or smtg
declaration: package: org.bukkit, interface: OfflinePlayer
can check with that after letting the command run
so, wait like a tick or something run that method and you will know
or you could cancel the command, and then use the api methods to handle whitelisting
then you can provide customized output
ok that makes sense, but don't you think it'd be better if there was just an built in event for this?
you could pr one if want, but I don't really think it is necessary or needed
given we already have events where you can easily obtain that information
well i could try the pr but im not sure if others will agree on this
it isn't about others agreeing on it, but rather if the spigot team wants to accept it
Aight so I'm kinda a big dummy, I have this build.xml file but have no clue how to build the jar file from it. I am trying to update an old plugin, all it has is build.xml. Any pointers would be appreciated.
yeah ok i see, ill think about this. till then ig ill use the methods you mentioned
how do I catch an error
Location location = p.rayTraceBlocks(100, FluidCollisionMode.NEVER).getHitBlock().getLocation();
if (location==null) return;
w.createExplosion(location, 5, false);```
when i raycast
and it doesnt find a block
it makes an null pointer exception in my console
but the if statement doesnt work
you sneak up on it.
with try{} and catch{}
don't catch the NPE
just check if the getHitBlock is null
you're grabbing its location instead of checking if its null
reverse that null check
and add the next statement inside that if code block
World w = p.getWorld();
Location location = p.rayTraceBlocks(100, FluidCollisionMode.NEVER).getHitBlock().getLocation();
if (location != null) {
w.createExplosion(location, 5, false);
}
that's still gonna throw a NPE
just check if the getHitBlock is null
you're grabbing its location instead of checking if its null
ah, I don't usually work with raytraceblocks stuff
didn't realize that getHitBlock() will npe
yeah thats why i was confused
it didnt matter what nullchecks I would add, it still seemed to throw a NPE
I guess Gizmo is right, I should prob just put it in a try/catch block
no don't do that i was half joking
just check if the getHitBlock is null
you're grabbing its location instead of checking if its null
^
why would
World w = p.getWorld();
Block hitBlock = p.rayTraceBlocks(100, FluidCollisionMode.NEVER).getHitBlock();
if (hitBlock != null) {
w.createExplosion(hitBlock.getLocation(), 5, false);
}
not work?
that should work
yeah it should work
well i've created DI to deeply understand how it works and later came up with idea to create something like this to avoid making Hash<UUID,SomeObject> every time i need to assign some object to player
java.lang.NullPointerException: Cannot invoke "org.bukkit.util.RayTraceResult.getHitPosition()" because the return value of "org.bukkit.entity.Player.rayTraceBlocks(double, org.bukkit.FluidCollisionMode)" is null
still produces an NPE
hmm, RayTraceResult is Nullable in LivingEntity#rayTraceBlocks()
so 1 more if is needed
guess rayTraceBlocks can return null
World w = p.getWorld();
RayTraceResult result = p.rayTraceBlocks(100, FluidCollisionMode.NEVER);
if(result!=null && result.getHitBlock()!=null) {
w.createExplosion(result.getHitBlock().getLocation(), 5, false);
}
clean up as desired
np
but ya i was joking earlier, you asked how to catch the exception, not how to prevent it
lol
it was a good one for those of us that understood π
good to hear, almost didn't say it in fear of sounding like a smartass
In Yarn mappings there is a class called DebugInfoSender
Similarly in MCP mappings there is a class called DebugPacketSender
Does this exist in Spigot and is there an easy way to modify these classes?
Normally I would just use mixins but those don't exist for spigot iirc
idk, but if it makes you curious there is a DEBUG_STICK
I don't think Spigot uses that class
No I'm using this to send data on the debug renderer channels
(minecraft already calls the DebugInfoSender functions whenever necessary and I really don't want to have to replicate that)
https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/
developer notes section talks about mappings.
spigot used to partially deobfuscate "NMS" but they are moving away from that
idk if DebugPacketSender is in the server code, never looked, but i think this is likely a push toward the right direction
people usually use reflection with nms
(when they need to gain access to private stuff, etc.)
well yeah but mixins edit the original code
it's not as powerful as mixins, but if you're clever you can get most things to work
ok I'll try to do what I can lol
are you trying to edit client code via server plugins?
Server code
just double check to make sure you can't do it with spigot's api first though
DebugInfoSender is code that sends debug stuff
you're trying to edit client code via server code?
no
I have a mod on the client that reads the debug channels for info abt debug renderer params
server code with plugins?
yes
you can do things with channels in spigot
Yeah my issue isn't the channels its getting them to execute at the correct time
ah
otherwise lag happens and thats bad
how much debug code are you sending?
*debug data
a bit, for example heres what the code would be on fabric
@Inject(method = "sendPathfindingData", at = @At("HEAD"))
private static void sendPathfindingData(World world, MobEntity mob, Path path, float nodeReachProximity, CallbackInfo ci) {
if (!(world instanceof ServerWorld) || path == null || !RenderersState.INSTANCE.get(RenderersState.RendererType.PATHFINDING)) return;
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(mob.getId()).writeFloat(nodeReachProximity);
PacketUtils.writePathToBuffer(buf, path);
sendToAll((ServerWorld) world, buf, CustomPayloadS2CPacket.DEBUG_PATH);
}
i use channels to send info for my own scoreboard system in an optional client mod and it isn't enough info to cause lag
I have a few other functions that do this
except other debug data
how are you reading it in spigot-side?
I'm not reading it spigot side, this was just to make sure it works
eg. in a single player world
how do you know it causes lag when you use channels in spigot then?
idk but it caused lag on the client
the best way for me to run these functions (i think) is to check in a radius every tick
but then theres Paths which are confusing af
(in spigot cuz obfuscation)
the post by md_5 i linked tries to explain how to use mappings in spigot dev, i haven't done so yet though so im not of much help with that
i've been coping by decompiling spigot and compring fabric's mapping with it to find the gobldeygoo names i need
I have the deobfuscated code I just cant use it in my ide which is annoying but its not as hard as no deobfuscation
yea same lol
but ya, there is a way to do it, i just have yet to try it out
2nd post, under the NMS section of "Developer Notes"
this link
but if i was you i'd try to use spigot's built-in channels stuffs before going the nms route
its just imo the nms route seems easier cuz I don't have to add all the detections n shiz lol
Just checked, it does exist in spigot under the name PacketDebug
and just like for fabric and mcp nothing has code except sendGameTestAddMarker which, if the client has the mods to make it work, spawns a small semi-transparent box with a name
hm maybe I am just really stupid
intereting
It also only takes a blue and a green value because the client nulls out the red value
even though the packet takes r, g, and b ints
Can you explain the loop more, im expecting i use the boxs getMinx for all the respective ones but where do i sub in my variables in the loop
like
for one dimension you would do
for (int x = min; x < max; x++) {
...
}
for two dimensions you just add another for-loop inside
i'd guess mojang might remove the method code before making the builds public or somthing, because i've seen pics of this packet in action from the mojang devs
Yup
I'm just reimplementing it
for (int x = minX; x < maxX; x++) {
for (int y = minY; y < maxY; y++) {
...
}
}
im looking through via my fabric setup now to see how much of a nightmare this would be to do with nms
*already forking purpur to add the methods myself*
ok
I meant like for creeper , powered tag and all
how to give nbt tag to mobs that i summon
how to create sub command like /cord help
it isn't really a subcommand but rather its just a single command that accepts multiple arguments
when someone runs the command you just check which argument they used if any at all
and then decide what to do from there
how to do this do you have an example?
hey how to use appy bone meal and break naturally?
I do
@night patrol
https://github.com/frostalf/ServerTutorial/tree/master/ServerTutorial/src/main/java/pw/hwk/tutorial/commands
How could I make a command spawn an animal
I know how to make commands just not spawn mobs.
World#spawn
mhm
declaration: package: org.bukkit, interface: World
For all those people who find it more convenient to bother you with their question rather than to Google it for themselves.
hey how will i spawn mobs with items in their hand?
like summoning skeleton with sword
I too feel N
what
rude
makes me feel like I should have been
ok so basically there was a deleted message
and it was from that one guy who just joined
and doesn't use ?services
and it was just a bunch of spam but amidst it was the letter N in bold
I was there it turns out
lmao
thought maybe you were referring to something else XD
Some people are very impatient
or just plain rude
I mean, I am impatient too, but I try to control it
I'm rude but everyone loves me so it doesn't matter if I don't control it π /s
the trick is not to be rude here
I don't know you so I have no reason to love you
yet
no one said you can't be rude elsewhere
this is like the only server I'm in tho
you are only allowed to be rude online?
lmao
so I don't have anyone to be rude to except for my lil sister
good enough
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
and now he services
How do I recompile minecraft after I decompile it? (eg. after editing source for a jar mod)
you don't
^ :)
but if you're working with somethin' like MCP there should be a way to recompile
wait so how do other people do that what
well you have to fix up quite a bit of things to get it to compile, sometimes it won't compile due to some info in the file you can't see
since you know it was compiled
so, sometimes you have to remake the file with the same info π
it can be a pain sometimes lol
another trick is to not compile
and just stuff the decompiled classes into a jar
doesn't help with running the jar, but works for API/coding purposes
this is why spigot doesn't decompile all the classes
and only decompiles what it actually uses
or needs
that is also performant ^
takes less time to decompile some of NMS as opposed to all of it
one pet peeve i had with MCP was it never actually knew how to decompile the server
or at least, didnt make it easy
o.O
it was great for decompiling client but server? SoL
well I guess that is true in a way, just mainly deobfuscated stuff
but I mean do you really need to decompile it though?
if u wanted to make Bukkit 2 yes π
you could just shade
but then u couldnt post anywhere bc minecraft
shade and create a sources jar π
that license was more to protect them then it was to stop people
isnt that all licenses, honestly?
yes and no
what I meant is that they had no intention in enforcing that aspect
but what it does do is protect them from certain other entities though
reverse engineering is not illegal and can't be prohibited from doing it for private uses
but you can be for commercial uses like Mojang license does
So, by MCP stating using their software is only for private uses Mojang doesn't really have any grounds to go after MCP
anyways I am not a lawyer so don't take it as gospel, but am telling you its purpose XD
this is country dependent, I should specify in the US it isn't illegal
god am i an idiot or something or does java JDK not set a JAVA_HOME on mac
JDK no longer sets a JAVA_HOME
as it doesn't use it anymore
they set the path to a directory that has a what you call it, its like a shortcut
but not quite a shortcut
symbolic link?
there you go
it has a symbolic link to which ever version you most recently installed
its kinda weird bc i install java 8 and it still said 17 in terminal
and i made sure i logged out of everything and logged back in to refresh path
path doesn't change no more
as I said the path for JDK is set to a directory that has symbolic links
which means new installs don't need to update path
just the links
should have, why it didn't not sure
but the way the install works is it doesn't concern itself with that symbolic link area other then ensuring its there, if it doesn't have perms to modify that it wont fail
idk im gonna try install again and see what happens
why not just update the symbolic link?
bc it doesnt even look like its where it shouldve been
or just update the path
aka java 8 didnt even save itself to my drive
or that could be the answer there
if its not installed then obviously that answers why nothing changed π
supposed to be in /Libary/Java/JavaVirtualMachines/ but all i got is 17
well, I don't mess with apple products so I wouldn't know
I just know that JDK stopped messing with the path or updating it on every new install now
i havent touched this laptop in a few years but im on vacation rn n its all i took in terms of computers
And stopped using JAVA_HOME
which is cool, but doesn't help when other tools still use that though
like Maven for example
Maven still looks for JAVA_HOME
-.-
ah
this is why jenv is a work of art
also
HOW THE FUCK
DOES SOMEONE THINK THAT'S A GOOD IDEA
tools would have to check 2 paths now
just for compat
technically they just need to check a single directory
apparently on mac the java 8 jre installed to Internet Plug-Ins
ok oracle
java homebrew install it is!
you only need the JRE?
well no, but just jdk is fucky wucky for me sometimes
usually with anything using javafx
JDK usually contains the JRE o.O
after java 11, there is no more JRE its just a JDK now
JavaFX was removed from the JDK after 11
or 12
requires a separate install to have JavaFX now
even for end user
removed in 11 looks like
but now you know why you have issues sometimes π
i think i only had adoptopenjdk 8 at the time of that issue tho
so maybe adopt didnt bundle it?
i was very slow and reluctant to move past java 8 lol
lol
I have been waiting for Java 16/17 for years
because it contains Unix Sockets π
natively that is
i think my interest only peaked once 11 came out
bc of the upgraded HTTP api
HttpClient
I plan to make a PR to bungeecord/spigot for unix sockets
it replaced the need for my own http code, apache dep, or okhttp
so that when bungee and spigot are on the same system you can choose that for communication method which is more secure and less overhead
apache HTTP libs are still decent
yea but i do like the inbuilt one more, because its built in lol
well built in doesn't always necessarily mean its native, most of the time it does
don't think anything native is needed for httpclient though I don't think
it probably just wraps around methods weve all written ourselves already but
now we dont have to write it π
probably I mean really you don't need http client per-say
could just do it the old fashion of handling sockets yourself
just makes life easier having one
was wondering if anyone else had issues trying to implement the Vault API into their plugins aswell?
??
you dont have a depend/softdepend on vault
i don't really know what that means very well, i did the maven for it right and everything i thought
oh shoot
When Bukkit loads a plugin, it needs to know some basic information about it. It reads this information from a YAML file, 'plugin.yml'. This file consists of a set of attributes, each defined on a new line and with no indentation.
A command block starts with the command's name, and then has a list of attributes.
A permission block starts wit...
Ugly milk bucket
lol
is there a way to include & load datapack from plugin to server? instead of user have to put them into the server manually
Copy to datapack folder?
uh that's sound a workaround
so spigot dont have api for it right now? datapack support from plugin
you could make a pr for this .... but its a lot easier to just copy/paste ^^
I'm trying to find some projectiles with try() / catch(),
But it seems not working nah
Use instanceof instead of try catch
Also either make a projectile variable or add an () around the cast and event.getDamager()
if(event.getDamager instanceof Projectile)
else if(event.getDamager instanceof LivingEntity)
Thanks bro
I was wondering if anything other than LivingEntity or Projectile could be input in EntityDamageByEntityEvent.getDamager()
in short, Is there any reason to put else()?
not rly since it does the same thing like before
Thanks
so i have a function for checking what recipe is in the crafting grid (custom gui) but for some reason "oak_log" and "oak_log" are not matching (for the ids.get(index).equals(recipe.idsIn[index]) part)
public String isRecipe(ItemStack[] items) {
List<String> ids = new ArrayList<String>();
for (ItemStack item : items) {
if (item != null) {
NamespacedKey key = new NamespacedKey((Plugin)Main.instance, "itemid");
String id = item.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING);
ids.add(id);
System.out.println(id);
}
else {
ids.add(null);
}
}
List<Recipe> recipes = new ArrayList<Recipe>(Main.instance.recipeManager.recipeMap.values());
String outId = null;
boolean recipeFound = false;
int matches = 0;
for (Recipe recipe : recipes) {
if (matches > 8) {
return recipe.idOut;
}
matches = 0;
for (int index = 0; index < 9; index++) {
if (ids.get(index).equals(recipe.idsIn[index])) {
matches++;
System.out.println(recipe.idsIn[index] + " == " + ids.get(index) + ", MATCHES TOTAL: " + matches);
}
else {
System.out.println(recipe.idsIn[index] + " != " + ids.get(index));
}
}
}
return null;
}
```
ive used == and that also doesnt work
== for strings will not work
equals should work if the case is the same ... equalsIgnoreCase could be an idea ^^
its the same case
ids.get(index).equals(recipe.idsIn[index])
maybe print them out with " and check then if it is rly the same and not just a space at the end
Cannot invoke "String.equals(Object)" because the return value of "java.util.List.get(int)" is null
yeah i forgor that air in the crafting is null
i gotta do a null check
ok so i check if they both == null
and if they do then increment matches
otherwise do the .equals() check
another thing: if i use onEnable() called from Main.instance, will that reload the plugin?
no
guys
i have EntityPlayer.getDataWatcher().watch(10, (byte) 127); in 1.8
how to do it in 1.9
where is the problem ?
i want to do this thing in 1.16
there is no watch method in 1.16
but set
but the params
is not int, byte
i dont get it
it is DataWatcherObject and a Value right ?
and a byte
3 values or 2 values ?
2
the DataWatcherObject is defined in the nms.Entity class (there are different types (POSE,SILENT,GRAVITY....)) each extended class could have more defined DataWatcherObject's .... the byte could be the same like in 1.8
btw what does this do ?
i use it to make an npc's second layer visible
the customisations ?
hey guys, quick question about Vault.
I'm trying to add it as a optional dependency for some extra stuff but now my plugin wont load without it.
Pretty sure this is because I try and import net.milkbowl.vault.economy.Economy in my main class.
What's the proper way of going about this? Using a separate class that loads vault and only call that one if the plugin is found?
softdepend and not depend in plugin.yml
Oh, derp. i had softdepends
any errors in log ?
do you check if the plugin is loaded in onEnable ?
I do ecoRef = setupEconomy(); in there
private Economy setupEconomy() {
if( checkDependency("vault")){
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
return economyProvider.getProvider();
}else{
return null;
}
}else{
return null;
}
}```
```java
public boolean checkDependency(String dep){
return Bukkit.getServer().getPluginManager().getPlugin(dep) != null;
}```
and if you have setupEconomy() and it returns null then you dont load some events ?
Uhh, Well in the event i just do if(plugin.ecoRef != null) to not run the part that uses economy
Should i seperate that into a seperate event and just not load that then?
you shouldn't try to register a class/event that has Economy stuff in it ... make a extra class to access economy stuff
Alright, Thanks!
Hey, i have a subclass with some extra fields. How do i calculate a hashCode for it?
public final class ClanImpl extends AbstractClanBase implements Clan {
private final int id;
ClanImpl(int id, String tag,
Component displayName,
UUID owner, Map<UUID, ClanMember> memberMap,
Map<String, ClanHome> homeMap,
Map<StatisticType, Integer> statistics) {
super(tag, displayName, owner, memberMap, homeMap, statistics);
this.id = id;
}
@Override
public int getId() {
return id;
}
@Override
public @NotNull DraftClan toDraft() {
return new DraftClanImpl(getTag(), getDisplayName(), getOwner(), memberMap(), homeMap(), getStatistics());
}
@Override
public boolean equals(Object o) {
return super.equals(o);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = (31 * result) + id;
return result;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("id", id).add("super", super.toString()).toString();
}
}
why do you need the hascode ?
Hello, is it good to keep File instance, or should I create new instance every time I use method to get that file?
File in java is just a wrapped path iirc
depends on how many times do you need it
so yes, it is fine
if its just the file its ok... but configuration could be an issue
well, thats a standart; hashmaps and hashsets relies on hashCode implementation
well... i dont think you will need to modify this.... if the id is uniqiue you can just the id ^^
Ok thanks
no
i need. toString, equals and hashCode should be overriden.]
I believe both eclipse/intelliJ offer a way to automatically generate hashcode/equals if you want to use that.
other than that, it's best to just google the proper way to implement those methods.
Hello Im new to Spigot plugin development and I was trying to create a plugin taht will need to store data of players. I want to make a folder in which there will be a file for every player that has joined the server with there last location before logging off. So can you tell me how I can
read and write yml files in different directories.
it would be better to google first .... there are a lot tutorials
Where I did google it
Can you plese send me a link
"minecraft spigot configuration tutorial"
-> https://www.spigotmc.org/wiki/creating-a-config-file/
Worked like a charm, Thanks
Does anyone have suggestions or references for the best setup for intelij/docker development? Looking to make it as efficient as possible
is this the right way of making a hikari datasource?
i got an error which says it cant find a suitable driver
oh
since most drivers use service location I think?
older versions would require you to load their classes via Class.forName but that's not the case anymore
public HikariDataSource getDatasource(String jdbcUrl, String username, String password) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(jdbcUrl);
config.addDataSourceProperty("user", username);
config.addDataSourceProperty("password", password);
config.addDataSourceProperty("cachePrepStmts", true);
config.addDataSourceProperty("prepStmtCacheSize", 250);
config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
config.addDataSourceProperty("useServerPrepStmts", true);
config.addDataSourceProperty("cacheCallableStmts", true);
config.addDataSourceProperty("alwaysSendSetIsolation", false);
config.addDataSourceProperty("cacheServerConfiguration", true);
config.addDataSourceProperty("elideSetAutoCommits", true);
config.addDataSourceProperty("useLocalSessionState", true);
config.addDataSourceProperty("characterEncoding", "utf8");
config.addDataSourceProperty("useUnicode", "true");
config.addDataSourceProperty("maxLifetime", TimeUnit.MINUTES.toMillis(10));
config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15));
config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10));
return new HikariDataSource(config);
}
this always works
and shading hikari also includes the driver
what version of minecraft you running?
more specifically, some forge spigot hybrids like to goob up the classloaders where it can't find hikari or something weird like that
anyone else really hate stuff like Map<String, Object> for properties?
because Object is basically dynamic typing?
well yeah but also bc the config property names become magic constants
don't you have to set driver class name
oh yeah
idk why people use a HikariConfig for the addDataSourceProperty methods, there is one in HikariDataSource too
not for hikari
hikaricp handles that
oh
idk, just convenience i guess
I also have a question, not concerning dbs tho.
I want to create an instance of a class using the
someClass.getDeclaredConstructor(x.class, y.class, ...).newInstance(a, b);
Thing is though that I have more than one constructor in my class which I'm inistiating, which seems to be causing an issue I guess cause I get the
java.lang.NoSuchMethodException
Any words of advice why it isn't working ?
what's the class?
can you send a screenshot so we can see the constructor definition?
Sure:
i'll try to recreate the error
The bottom one is the specific constructor which I'm using, the one I want to use, but it just doesnt
and by the way, why do you need to access constructor with reflect?
idk, probably make sure you are using the same classes, like also checking your imports to make sure it's the exact same class
but why reflect lol
calling this(...) is also something
instead of doing constructor stuff two times
Is there any plugin/datapack which allows to make haste potion? And any datapack/plugin to create portals or smth, I need it to play survival with friends, I can't find anything for 1.18
just use new lmao
?paste
you don't ever really wanna use reflect anyways for that, because something about the jvm GC or something something
except that it is an abstract class
i'm too tired to remember rn
factory pattern is a way to go
well if it's an abstract class you can't instantiate it then because there are methods that have not been defined
what you could do is make it not an abstract class, and those abstract methods, just make them empty
in what context you are instantinating them
so they can be override by children
wrong key name for a namespaced key?
@zealous osprey
i think you're lacking one of these
package com.manya.test;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class Items {
static abstract class AbstractItem {
private final ItemType type;
public AbstractItem(ItemType type, ItemStack item, UUID uuid) {
this.type = type;
}
// stuff
}
static class Item1 extends AbstractItem {
public Item1(ItemType type, ItemStack item, UUID uuid) {
super(type, item, uuid);
}
}
static class Item2 extends AbstractItem {
public Item2(ItemType type, ItemStack item, UUID uuid) {
super(type, item, uuid);
}
}
@FunctionalInterface
interface ItemFactory<T extends AbstractItem> {
T create(ItemType type, ItemStack item, UUID uuid);
}
enum ItemType {
ITEM1(Item1::new),
ITEM2(Item2::new);
private final ItemFactory<?> factory;
ItemType(ItemFactory<?> factory) {
this.factory = factory;
}
public AbstractItem create(ItemStack item, UUID uuid) {
return factory.create(this, item, uuid);
}
}
}
quick solution i made that works without refleciton
That is very generous, sadly I gtg now, Ill pin it down somewhere and look trough it later, but thx ;P
whats the use of the itemfactory?
yo guys any idea on why is spigot highlighting commandexecutor and changing it to executor? package me.Stephen.FirstPlugin.commands;
import me.Stephen.FirstPlugin.Main;
import org.bukkit.command.CommandExecutor;
public class HelloCommand implements CommandExecutor {
private Main plugin;
public HelloCommand(Main plugin){
this.plugin = plugin;
}
}
Also its highlighting org.bukkit
to create new items..?
oooh i see
so for every type you create a factory that creates new Items
is this bad?
factory patterns are nice just for cleanliness
wha
Anyone?
well i dont think
but it says invalid key "&adiamond helmet"
I mean if you're trying to access minecraft:diamond_helmet, I don't think you should use your plugin as the namespace
in the meta.setDisplayName is ChatColor.GREEN
and then the name
i mean, the guide i'm following used his plugin for that
well this line gets triggered
and as you say the displayname is &adiamond helmet
are you sure you use "diamond_helmet" as a key and not the coloured displayname?
i dont understand why i have three times my jar when running mvn package
i'm shading
how to summon mobs with nbt tags?
and not relocating stuff
Or do you guys need more info here
can you send a screen?
Sure 1 sec
you want to get the recipe for an item ?
to make
is there smth after ShapedRecipe recipe = ... ?
because just define a key and the result will not create the recipe
what is the problem ?
import it
@spiral lightthe problem is this
import commandexecutor?
i have changed many things about colors but don't really now what's happening
hover over the red line ._.
should i send a screen of that as well? it says to change commandexecutor to executor in general
and also to create class org,bukkit
i tried that already and there was just an error
nvm, i solved it
like this
You are importing your own class org.bukkit.command.CommandExecutor. Not the actual Bukkit interface
You created both CommandExecutor as a class and JavaPlugin
wait
You have no Spigot/Bukkit dependency and then followed the IDE suggestion to create the class
ah i understand
Oh that makes sense
Well how can i fix that?
Follow a decent plugin tutorial for Eclipse https://bukkit.fandom.com/wiki/Plugin_Tutorial_(Eclipse)
I mean i installed spigot 1.18.1
go through that tutorial (its not for 1.18)
once you have it working you can then learn the 1.18 specific setup
It says bad title, can you tell me the name of the article?
bad title? the link is fine
The link embed removal is fked for me
Idk it showed me this
Kek
There are several things that your group must not begin with and those are:
[...]
net.bukkit
com.bukkit
[...]
com.mojang
I don't think those three are true anymore... unless I'm mistaken
orgbukkit and nms are true though
I think google hates me xD
Yeah. It's just the two
if (name.startsWith("org.bukkit.") || name.startsWith("net.minecraft.")) {
throw new ClassNotFoundException(name);
}```
Others aren't inforced, just strongly discouraged lol
I mean it starts with org.bukkit
Btw its fine ive got it tysm for help
So i have been having trouble finding this, bur im trying to find a plugin that can connect to my bungeecord server and to a discord bot, but i look everywhere but i canβt find anything
Hi Conclure, first thing first. Happy Christmas. Whenever you have time it would be great
That's how it is I guess
First start is slow due to downloading libraries
Because it has to load the world spawns
Heck, if itβs a first start it has to generate the world spawns
Yeah the world part
I canβt imagine the vanilla server is any better
I had an MC server freeze just after assigning its port due to having a SatNav plugged in, it saw two networks and attempted to acces the net over teh Satnav, before failing and using teh correct network
why do you use powershell XD
Other things are nicer other than startup time honestly xd
You can't use getEntities method with async
I don't know, but I don't think you can use getEntities with async in any versions.
Maybe, I never used that method before.
Well, bukkit methods aren't thread-safe so we can't call it async.
Well, some are
Sure
Yo anyone know a plugin that works for 1.18 that clears items from the ground ?
I think Minecraft in general isnt thread-safe
I've always been fine reading chunk data Async, but recently Entities seem to have been broken out
Well if you develop a normal java applications most likely it's not thread-safe unless you really try to do so
I think 17 got dedicated events for entity loading
What's the point of that plugin?
Just ask
Like support server owner?
Or what
Lul
Windows Microsoft 11
The formatting in the htop section is a bit of a mess
Send the link (:
hello, i need some help
do you know how kill entity ? (Enderdragon)
i absolutely tested everything,
i looped all worlds & entities,
i have EnderDragon instance bc it's custom dragon, i set his life to 0, damaged health*2, it didn't worked,
i emulated /kill @e, it didn't work too, sometimes dragon stays alive
.remove?
this work?
yes
EntityEnderDragon class don't contains .remove method
private EntityEnderDragon dragon;```
is that nms?
(Yes)
You will have to send an entity destroy packet
so it's sended by packet?
with the entity ID
yes, send a destroy packet
yeah
I mean NMS doesnβt always mean packet
i can't, i use attribute modiffiers
hmm
AttributeInstance attributesHeal = dragon.getAttributeInstance(GenericAttributes.maxHealth);
AttributeModifier modifierHeal = new AttributeModifier(maxHealthUID, "health",
config.getDouble("ENDERDRAGON.health") - 1, 1);
attributesHeal.b(modifierHeal);
attributesHeal.a(modifierHeal);
dragon.expToDrop = 0;
w.addEntity(dragon);```
w = world
Why do you need NMS for attributes
World w = ((CraftWorld) location.getWorld()).getHandle();
dragon = new EntityEnderDragon(w);
dragon.getDragonControllerManager().setControllerPhase(DragonControllerPhase.i);
dragon.setLocation(location.getX(), location.getY(), location.getZ(), w.random.nextFloat() * 360.0F,
0.0F);```
Are you on a 6 year old version
no lol, 1.12.2
π₯΄
/kill worked for me,
but sometimes, it didn't
so anyone have an idea ?
dragon.getBukkitEntity().remove();```
how do i check if the inventory of a block (chest, hopper) isn't empty
isEmpty ? x)
oh
does Bukkit::shutdown save the world and everything?
Yes
Yep
π
i have created a .jar file
but i need to edit it now
how will i do it
i accidently removed the .java file
thats why i cant open that
decompile it, edit, and recompile ig?
if (!event.getBlock().isEmpty()) {
doesn't work
it's true even tho the chest is empty
i used intelligi hwo will i decompile there
Well you're not checking if the chest is empty. You're checking for air
You need to get the state of the block
Cast it to a chest and check block inventory
add getBlockInventory before isEmpty
if ((Chest) event.getBlock().getState())).getBlockInventory.isEmpty() {
You missed () on getBlockInventory
getBlockInventory doesn't exist
Add another () around ((Chest) event.getBlock().getState()))
I think?
maybe please use variables too many () make me confused
If it still doesn't exist make sure you cast to the right Chest
declaration: package: org.bukkit.block, interface: Chest
if (((Chest) event.getBlock().getState().getBlockInventory().isEmpty())) {
yeah
getBlockInventory doesn't work
readability 100
It's the () missing around your cast
And how can I check it? It returns the internal crafting in both
if ((((Chest)) event.getBlock().getState().getBlockInventory().isEmpty())) {
Not that part
aaah
((((:
if ((((Chest) event.getBlock().getState()).getBlockInventory().isEmpty())) {
isEmpty is red
So getBlockInventory works?
ye
What version of spigot
1.18.1
maybe try to seperate this ^^
^^
is there some way to schedule a task for which the delay decreases with each execution?
say the first delay would be 5 mins, then 2 mins, 30 seconds, ...
yes but you will need to run the schedule like every 1s and check the time
Block chestblock = ...
Chest chest = ....
Inventory inventory = ....
inventory#isEmpty
readability, debugability
You can create a new runnable inside of the runnable
true that's a good solution
You can create your own BukkitRunnable class containing the time and such and do you calculations on that
unnecessary variables?
for debugging, it's a good thing to do
he will find the bug like this and then he can compress it together again ...
"unnecessary variables" sure maybe but I'd prefer "unnecessary variables" than this
if ((((Chest)) event.getBlock().getState().getBlockInventory().isEmpty())) {
this will take 5min and not like 30min asking in discord
readability > "unnecessary variables"
no
yea true ((((
reminds me of the time someone challenged me to make a really compact method to read a file and print every line in console
because "python does it in less lines so python is better"
I hate those people 
I hate those people :PES_HuhWtf:
package me.adelemphii.randomstuff;
public class FileReader {
public void readFile(String path) {
try (java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.FileReader(path))) {
String line;
while ((line = reader.readLine()) != null) System.out.println(line); // I usually don't format my code like this
} catch (java.io.IOException ex) {
System.out.println(ex.getMessage());
}
}
}
u forgot to put the brackets in the same line
boolean isEmpty = (((Chest) event.getBlock().getState()).getBlockInventory()).isEmpty();
:D
just some ( and ) and you can easy compress those 4 lines into a working 1-liner without errors ^^
oof. it's the in-line imports that bother me
same
same
but they were counting package & imports to the total length of the code :)
^
1 liner minus catch
nio is great
I didn't know about nio at the time
I don't use nio as much as I should
Is there anyway to cancel players from sprinting, tried the PlayerToggleSprintEvent but doesn't work, from what I have seen online you have to use hunger, but they were from like 4 years ago, wondering if anything has changed.
Player#setSprinting maybe?
conclure do you do code reviews
is there a way to hide this in console?
I tried what you said Adele but didn't work (thanks anyway), pretty sure its just handled client side
Yeah hunger is the go to still
Sometimes, tho nothing official or professional but yeah
Just write code to perform code reviews for you
btw ... since the initWorld calls the Event "WorldInitEvent" where you can disable the KeepSpawnInMemory and the Method prepareLevels gets called after that and will result into do nothing if in the Event KeepSpawnInMemory is set to false ^^ now you can do a PR because there can't be smth bad happen
can someone rate an api i did with @quaint mantle
https://github.com/decalium/decalium-clans/tree/rewrite/clans-api
setting log level to OFF for hikari's loggers should hide it
well that manya did. i was just coding sql implementations
A bit hard to just review an api π
Hmm nah, but sure, I have tried cloning it on my laptop with a hdd
Didnβt work out :/
aight
no singletones or circular dependencies at all!!!
Actually tbf partly why the code might be bad is due to Minecraft code itself 
Yeah well singletons can be fine
I actually like how the Minecraft code works and look. Sure performance may not be the best but it's honestly quite easy to understand
is this a joke
No >.<
Yeah, Iβd agree apart from their abstraction of lwjgp or whatever itβs called
Haven't looked at that
Minecraft has some code which is reasonable, other parts which are a bit wtf
The parts I've looked at are fine
Maybe exept the structure spawning
My head hurt after that one
LWJGL
doesn't Minecraft have a method that crashes the game
It does
why though
ah okay
bukkit's still bad
still sounds funny without context tho
wtf
agreed
there was a way to do that loudly?
like what do I just go to general and uhh
that
ah, true
Anyways gepron1x the api looks good, like the only thing I can really criticize apis for is if theyβre improper (might be able to review it a bit more thorough given an implementation)
damn
I know that this might sound stupid but I will ask anyway. What are the pros of having an API?
is it possible to make 2 mobs fight each other?
not forcing people who want to extend your plugin to resort to hacky bullshit to do so
also makes your code cleaner in the end tbh
ohh, i see
Yes. You'd probably have to write your own pathfinding or look in to NMS
craftbukkit of "EnchantmentStorageMeta" ?
i have writen zombie.setTarget(skeleton)
Make sure it doesn't change target
Inventory inv = ((((Chest) event.getBlock().getState()).getBlockInventory()));
if it's a double chest, it only gets that half of the chest
Yeah
dont use getBlockInventory
try getInventory
or check if it's a double chest and use that
you can force the game to crash by holding f3 in the singleplayer screen if its not loading
but yea thats not server side
works
btw does Inventory inv = ((((Chest) event.getBlock().getState()).getInventory())); work on items like hoppers
and furnaces ?
kinda the same
no since you're casting it to a chest
smh
how do i make it so it does
Cast it to something the 3 share
(Hopper) maybe?
Can't be bothered to look it up
i'm trying to get all blocks that have inventories
ah in that way im stupid
dont cast to a chest/hopper.... rather cast to Container or smth like this
getInventory doesn't work on Container
Is it good to keep world instance in inventory holder? Does inventory holder gets "finalized" or something after inventory is closed? Or should I use world's UID?
@upper mica not sure if the garbage collector would remove that
So better uses worlds uid
Oh ok thanks
In command /a b c, the command label will be b, right?
b and c are args
so a is a label, thanks
wait
and again... use Container as block (not chests, hoppers ...)
I read your question wrong lol
This code has become such a mess
Show it?
π
Maybe we can help you clean it up
cleaning code up is fun
unless the code is such a mess that I can't even read it but y'know
it doesn't work
I usually just tell myself "I'll do it later", never do or forget how the code works
then dont use a 1-liner
true π
Rewrote half of my first plugin, haven't touched it in 6 months
it's kotlin, but I have a feeling this could be made even simpler
https://paste.md-5.net/ocovatumul.cpp
i feel that... has 10 assigned issues
?
" Inventory inv = ((((Chest) event.getBlock().getState()).getInventory()));"
ok?
i changed it to Inventory inv = ((Chest) event.getBlock().getState()).getInventory();
still 1-liner
ok??
try smth like
if(block.getState() instanceof Container)
Container con = block.getState()
Inventory inv = con.getInventory()
Cannot resolve method 'getInventory' in 'Container'
wrong container import ?
yes
It is if you update
whe tf is there still no release version of maven shade plugin for java 16?
wdym?
It doesn't exist in 1.8
aren't they on 1.18?
Oh
i updated
ye
whut?
of course you can cast ints to doubles
wait. i dont have really a testing enviorment for this.
but:
this should return half of players (rounded up) right?
double halfPlayers = Math.ceil(Bukkit.getOnlinePlayers().size() /2D);
just test it π
erm just replace Bukkit.getOnlinePlayers().size() with some random numbers π
open more mcs
public static void main(String args[]) {
for(int i = 0; i < 20; i++) {
System.out.println("Half of "+i+" runded up: " + Math.ceil(i /2D));
}
}
Half of 0 runded up: 0.0
Half of 1 runded up: 1.0
Half of 2 runded up: 1.0
Half of 3 runded up: 2.0
Half of 4 runded up: 2.0
Half of 5 runded up: 3.0
Half of 6 runded up: 3.0
Half of 7 runded up: 4.0
Half of 8 runded up: 4.0
Half of 9 runded up: 5.0
Half of 10 runded up: 5.0
Half of 11 runded up: 6.0
Half of 12 runded up: 6.0
Half of 13 runded up: 7.0
Half of 14 runded up: 7.0
Half of 15 runded up: 8.0
Half of 16 runded up: 8.0
Half of 17 runded up: 9.0
Half of 18 runded up: 9.0
Half of 19 runded up: 10.0
ignore the typo
so yes, it works
ok thank you very much!
Can you somehow make fishing in lava possible?
Does Chunk#getTileEntities() return in random order?
You probably have to look in to the implementation or to some testing to awnser that. It's a very specific question. I wouldn't rely on it to be random or sorted for that matter...
n m s
probably depends on the server software
what should i do with the nms?
Make the fish hook not sink
and float like it's on water. Then throw in some water particles and you're done
oh, well ty anyways, I kinda need to reconsider the plugin idea if it would be useful or not lol
does (null instanceof Player) causes an npr o what?
It won't cause a null pointer if that's what you're asking
Like teleport it in a task timer?
I want it that It can actually fishing just like in water
also whats faster for comparing player instances? the player object itself or the uuid?
i have my config.yml saved as config. how would i get a specific option from config
wdym saved as? is it a FileConfiguration object?
if true you can call config.getString("key") or config.getInt("key") etc stuff on it
You can use the NMS behavior
A teleport task timer might also work but it won't be exactly the same as the water behavior
you can get the config.yml file by calling plugin.getConfig()
Hey! Does someone know how to filter command suggestions on BungeeCord? I want to remove /bungee, /glist, ... form the list, but could not find a way. On the spigot servers I did it with PlayerCommandSendEvent
How can I do that?
You'll have to figure it out on your own
I need some references
NMS is your reference
What class should I look?
Already tried, but it gets called for the params of the command, i.e. if you write /server and hit Space, then TabCompleteResponseEvent is called. I am trying to find a way to filter the command that appear after writing just the slash, but I think it may not be possible
permissions
The fishing hook would be a good start
True, but the problem are commands from other plugins. For now I have overwritten those commands from other plugins, reimplement the features and set the correct permissions π€
ah I see
If you can't figure it out. You can always use Protocolize and edit the packet directly
what would be the best way to wait a little before you teleport a player to spawn? i dont want to the player to teleport to a chunk which isnt loaded and makes them "fall in the void"
help
what help?
duplicated tag <dependencies></dependencies>
apparently dependencies is an invalid name
oh
i dont have another dependencies tag tho
I bet you do
ok bruh
bump
try coding java on eclipse instead
async task that waits until chunk is loaded?
do a kotlin coroutine
use PaperLib to teleport
uhm you sure?
anyone know why my pom.xml hasnt updated my plugin structure
is there an update project button on eclipse
yes, why not?
it has ways to teleport players async and load chunks async
and it falls back to sync chunk loading if you're running regular spigot
I use it in all my plugins that need to load chunks or teleport players
hmm i'll take a look at it
anyone
You need to reload maven project presumably
did that, still not working
why nos just implementing this myself?
Because theyβve done it for you?
Depends on what method you use
my pom.xml
Player#teleport
That probably wonβt work, at least not on spigot
Worth a try but yeah
Thread safety and concurrency updates dont come free sadly
meh i was thinking about async thread and call Thread.sleep until chunk is loaded
Yuck
whats the difference between ++a and a++ in a single statement?
++ increments before
