#help-development
1 messages ยท Page 1411 of 1
#Player.getInventory().getItem(int slot);
loop throu the inventory, check for the item, get it's slot
that's not what he wants i think
ok thx
or is it? lol
i mean...
thats what i needed
then you spelled it wrong lol
you want to get the item of a slot, not the slot of an item then
slot != itemstack
how to get the slot of an item
that pretty much looks like he wanted to get for example, at which slot is cobblestone
I compiled into a jar file and then checked the jar file and i didn't find anything except the plugin.yml
How to fix?
intellij or eclipse?
idk to be honest
intellij
then?
yeah, but that doesn't really works when you have 2 stacks of smt, or similar
it gets confused then pretty much
neither does iterating the inventory, though
well, idk
i think you mean this one right here?
and click ok
it's there
and recompile artifact
this is how it should look like at the end tho
you should throw your java files if you are using maven inside the java folder and resources inside resources folder
idk if that's the same with intellij build system
also if you somehow fucked up these folders
you need to remark them
in order for IDE to detect properly
oh my god
guys
public static void addPermission(UUID uuid, List<String> permission) {
File file = new File(plugin.getDataFolder(), "permissions.yml");
if (!file.exists()) {
try {
file.createNewFile();
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
config.set(uuid.toString(), permission);
config.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
i sit here for like 1 hour, wondering why this isn't saving anything.
now i know why.
so please tell me why i'm dumb lol
that looks horrible
lol
you know it
yeah, was pretty much just shaking my head agains whatever
if (!file.exists()) {
AHHHH
reading and saving an entire file to add a permission
im pretty sure file.createNewFile() return boolean
which you can check if file is created
make sure to modify player permissions in the player move event
tf
i dont think i'll ever do that
do you read the file every time from disk when checking the permission too
yeah, but when using that in commands it's not that performance-demanding
i'm not trying to link movement with an permission dud
is that a rhetoric question or
reading an entire file every time you want to check a permission is omega pepega
^
does everyone know if the player.getOpenInventory().getCursor() is thread safe?
i dont think i need to do smt different, when using this on my 4 players server
which question
yeaaa..
i found an answer
which didn't made sense
since cursor would still be updated from the non volatile field
or wait
maybe it does
packet windowclick
pickup type
clicked item is cursor
let me guess... you still didn't got pm'd from bot bc of spamming?
bot just hates me
tells me i'm spamming
for 3 messages
suffer
So I should not use package?
I have the code inside java folder but inside package
So why it's not appering in jar file?
maven
i am in the god damn matrix
this trie implementation is becoming more and more convoluted
No
?paste
and I want players to be able to search these offers by the item name
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>MutualDamage1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
idk
What should I put?
my package?
Do I need to click this
isn't this going to delete my code?
racist???
ig this is racist
+
u also said it wrong
arab is Plural
u must say I'm not an arabian
@wraith rapids gimme ur thoughts about arab
Wanna like move your brains thoughts that are not focused on coding out of this channel xD
๐
good luck
Yo, anybody knows how can i make every enchantment special? Like i need to detect them that they are special and not multiplied before. I have a plugin what multiplies enchantments.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
im currently stuck here
before
i added my enchantments to a list
and then checked if it doesnt contain
but that fked up since enchantments share all different names
like it multiplied 1 swords sharpness
but not other swords sharpenss
since the list arleady contained
sharpness
Well I cant understand that smar tpeople language yet
i thought i can but i cant
how can i get
enchantments arbitrary data
Is it too much to fucking ask for the development channel to stay a fucking development channel?
Jesus Christ, I don't want to have to baby you
?kick @wraith rapids
๐ข Kicked NNYaKNpGms0eUVpiSdHx#5618
?kick @mortal hare
๐ข Kicked Dovias#0629
maybe go check some of their deleted messages
there is some rather racist stuff up above
snitch
i didnt do any racist comments
but still disrespectful
yeah, mostly the NNY guy
Yea nice i was just starting to understand what he said
and he doesnt accept my friend request
do you need like a role or something to access the dev channel
some of my alts cant talk in here
NNYa
pretty sure there are a bunch of pdc tutorials out there
@mortal hare still doesn't compile the classes
im using pdc
But on my item meta
oh hi its me
nnya
i mean, item meta is the part where you use pdc on o.O
that's you? i have a few bits of criticism for your resource
I could not care less about your input NNY xD
i don't exactly remember what they are
but looking at the guide makes me feel awkward
that is okay, you can also just read the javadocs for it
I am sure you'll get it!
the community here can also help you โค๏ธ
just missed your opinion so much for the short time you were gone xD
oh i wasn't gone
thats for itemmeta, i cant rly figure out how should i use it with enchantments
I arleady have pdc in my code with itemmeta
what
Is there a tutorial for integrating H2 DB into Spigot plugins?
your issue is that you need to keep track of which enchantments you have multiplied already, yes?
or is this not the case?
store the list of multiplied enchantments in the pdc
Okay heres the first thing
if i add the multiplied enchantment in the list
Okay i rly dont know how to explain it very well tb
h
Is it sage
safe to store just enchantment names in the list?
Ahh you problaly didnt understand my plugin. If i enchant an itemstack, it multiplies its itemstacks
ideally you would store the keys
Enchantment implements Keyed
that way it'll (probably) be compatible with custom enchant plugins
And all the enchantments have different keys?
yes, that is the point of a key
aight
every enchantment type in the game has a different key
don't even need to fetch them, can just check if the key of a specific enchantment is present in the set
true that
Okay whatever
ill try
what ill come up with
and see wassup
main.multipliedEnchants.add(ench.getByKey(multipliedKeys));
i came up with this
Like its wrong ik
but i dont then understand the logic behind it
Other things like itemstacks etc ive used have getPersistentDataContainer, but enchants.. How can i get it by key if i havent even set the key. Or do i even have to? That enchantment bs doesnt make any sense to me
get the persistent data container of the itemstack
write the list of enchantments you have multiplied for that itemstack in there
enchantments do not have a persistent data container
you do not get the enchant's persistent data container
you get the item's persistent data container
and put the enchantment's name in it
can i do it with the itemmeta?
yes, you get the persistent data container from the item's item meta
Set<NamespacedKey> enchantsThatHaveBeenMultiplied = item.getItemMeta().getPersistentDataContainer().get(yourKeyForStoringTheSet, yourPersistentDataType);
if (enchantsThatHaveBeenMultiplied.contains(enchantToMultiply.getKey())) {
//do not multiply
} else {
//do multiply
enchantsThatHaveBeenMultiplied.add(enchantToMultiply.getKey())
}
and then write the Set back into the persistent data container
hmm how can I take a specific amount of health from player without using player.damage();
yeah
that seems like a possible choice
What does that do?
Hey ๐
I have just "discovered" the special behaviour of ComplexRecipes, where getResult()... just doesn't work.
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ComplexRecipe.html
Is there a correct way to always get the result of the recipe? Or do I really have to wait one tick to obtain the actual ItemStack in the workbench?
the whole jist of the ComplexRecipe is that the result is too complicated to really define in the contract
like, iirc removing dye from a leather armor piece is a ComplexRecipe
ok I'll try
cant use string as my persistentdatatype
it wont let me use sets then
But sets are rly necessesary here
Pretty sure NNY wants you to implement your own type
yes, you should create a PersistentDataType<String, NamespacedKey>
What should I type in the if statement to avoid doing a task if damage was caused of player.damage()?
uh
check the damage cause and see if it's like UNDEFINED or something
or however that works, i'm not really sure
What should I put here "something for player damage"
Unfortunately this also happens for more normal stuff like crafting tipped arrows. I don't really get how any result can be too complex, isn't it always just an ItemStack?
And What is it? CUSTOM?
well, yes, it's always an ItemStack
but see, the result may depend on the exact ingredients used
for example, the result of the tipped arrow recipe requires the potion item stack's data to tell what effects there'll be on the arrow
the recipe object doesn't have access to what's actually in the grid
it just tells what can be in the grid for it to be that recipe
What is the cause of damage of player.damage();? this is why I asked bcz I tried doing it before But i didn't know the cause
try it and see
not a thing
it should be GENERIC
not a thing also
Let me try
.getDamager isn't a thing
So it's custom
peak bukkit moment
yeah
there is some paper PR open to allow the plugin to define the DamageCause on invokation
but eh
not applicable here xD
i remember seeing talk about it a good while ago
i'm assuming they've done it by now
I got warned bcz I deleted the message to resend it but reply to him this time
cool innit?
the bot is trash yeah
might be confusing it with the custom spawn cause for world::spawnEntity
oh, nah #5191 is still not pulled into paper master ๐ญ
agreed. sadness
oh well, reflection solves all problems
I'm using this
EntityDamageEvent with ```java
if(event.getEntity() instanceof Player)
I use intellij so yeah
if (!event.getCause().equals(EntityDamageEvent.DamageCause.CUSTOM))
use == when comparing enum constants
I'm going to try
What if I used .equals?
it would be the same
So?
you're supposed to use ==
saves you a method invocation, actually probably not true xD
I used .equals just to be sure that it's going to work
Thank you for the explanation ๐
player.remove();
seriously?
thx
But I can't save the players invs in a list or something so alot of glitches happens
@sage swift
huh
well you cant switch them at the same time
you gotta store one while you switch one way
yeah
then put the temp one into the other one's inventory
But this will dupe inv
how do i prevent an entity from slowing down after i set its velocity
for example i have this (its in kotlin but that doesnt matter)
val fb = sender.world.spawnFallingBlock(sender.location.add(0.0, 2.0, 0.0), Bukkit.createBlockData(Material.SAND))
fb.velocity = Vector(1.0, 1.0, 1.0)
fb.setGravity(false)
and initially it goes on for a while but after a bit it starts slowing down and eventually stops
The things that happens bcz of not able to store invs are dupe, clear, items get moved and others don't
and alot other problems
what
How can I store the invs contents?
getContents
I tried lists but it saves the command not the contents
ItemStack[] tempInv = player1.getInventory().getContents()
how to check if a player has permissions in luckperms?
again, luckperms has their own discord
this is my code
TimerTask task = new TimerTask() {
@Override
public void run() {
List<Player> Players = new ArrayList(Bukkit.getServer().getOnlinePlayers());
List<ItemStack[]> invs = new ArrayList();
for (int i = 0; i < Players.size(); i++) {
invs.add(Players.get(i).getInventory().getContents());
}
for (int u = 0; u < invs.size(); u++) {
if (u == Players.size() - 1) {
Players.get(0).getInventory().clear();
Players.get(0).getInventory().setContents(invs.get(u));
Bukkit.broadcastMessage("Invs Swaped");
} else {
Players.get(u + 1).getInventory().clear();
Players.get(u + 1).getInventory().setContents(invs.get(u));
Bukkit.broadcastMessage("Invs Swaped");
}
}
}
};
timer.schedule(task, 10000, 10000);
why do you need that
I'm trying to swap players invs
wtf
ItemStack[] temp = player1.getInventory().getContents();
player1.getInventory().setContents(player2.getInventory().getContents())
player2.getInventory().setContents(temp)```
it's a miss ik
don't overcomplicate stuff
But what if I have alot of players?
perform the algo alot of times
if you find yourself repeating yourself repeating yourself
you're probably going something wrong
you know what i mean
the pp thing
also im very happy and excited that your player set variable is capitalized
sorry, player list
its exciting
isnt it
how do you disable tnt explosion damage to players
ive tried making an unharmed fake explosion and tried setting getDamage to 0
doesnt work
Yeah best bet is probably to listen to ExplosionPrimeEvent, check if it is tnt, cancel the event and create the explosion yourself
power has to be 0 I guess
You do realize there's more than just a handful of topics to learn in order to code, right?
I'd guess the first one teaches more introductory concepts and the second one teaches more intermediate ones
How could I change a passengers y to be higher?
half of the stuff needed in just general coding isn't even found in courses
Hey, whats the best way to get all chunks inside a Worldborder?
int instanceof Integer = new String("4");
no please no lmao
player.getItemInHand().getItemMeta().getDisplayName().equals(CC.GREEN + "Toggle players " + CC.GRAY + "(Right Click)" Most likely .equals is null.
anyone here ever used jackson api
I tried using brackets instead of returning and it still didnt work
I'm trying to read this documentation https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerChatEvent.html#getMessage() and I'm trying to get the method getMessage(); Is there I need to add, or Is there a object i need to create?
What are you trying to do? and also use AsyncPlayerChatEvent.
Can someone explain to me, what the fuck is this? Just happened so randomly, on my localhost.
ItemMeta might be null.
was trying to debug it but my mc isn't starting lmfao
Alright yes I will use Async But, I'm trying to make a filter that removes bad words and replaces them with something funny
Use the #setMessage method, it will modify the message.
Alright thankyou!
So umm... I've imported the modules but 1. It sais that it was never used also, Either way am I supposed to write my methods like this public void <Name>() {}; or <Name>(); I'm sorry i'm new tho java
}```
Anyone got a util for configs for bungee?
hey im having a bit of trouble understanding perlin noise
im not exactly sure what the distribution is of the bukkit perlin noise impl
If I use spigot 1.12 will it work in 1.8?
Depends, in 1.8 there is no off hand.
If you don't do anything with Off Hand on your code then it's fine.
okay
and also other couple things
Gson (:
is there an event that runs every tick
How do i get a sign to edit the lines. I tried
Bukkit.getWorld("world).getBlockAt(x, y, z)
and
Bukkit.getWorld("world).getBlockAt(x, y, z).getState();
getBlockData() and cast to Sign
Sure. Create an ObjectMapper and throw things at it.
In my opinion the custom serialization interfaces of Gson are way easier to implement.
Which one to download?
AdoptOpenJDK
How can I set frosted ice age?
For example change blocks type to frosted ice with age of 2
Thanks
Do I need this to start coding?
develop for Spigot 1.16 and use AdoptOpenJDK 11 or 15
What?
Everyone is moving away from Oracle as much as possible due to their behavior
What behaviour
oar uh cull
Trying to copyright APIs
Who is Jenkins?
You don't need to know Jenkins for a LONG time
okay, mr. British man
how to send messages with clickable text in bungeecord?
How do I download Java?
ok so how would I go about generating pvp arena's on the fly without making the server kill itself
SlimeWorldManager is great for that stuff
or check out this:
What is the best method to make a config file?
spigot has a default method for it
saveDefaultConfig() will save a config.yml from your root to the plugin folder
how can i change the skin from a player in tablist
an existing player?
profile.getProperties().put("textures", new Property("textures", signature, textureBase64)));
just a matter of getting the signature and b64 of the skin
like this? @drowsy helm
How to send a colored message to a CommandSender?
can use the method in ChatColor
to translate alternate whatever
lemme find what it is holup
commandSender.sendMessage("ยงaLime Colored Message");
declaration: package: org.bukkit, enum: ChatColor
ChatColor.translateAlternateColorCodes('&', msg)
super verbose
ยง can be iffy
and requires UTF-8
so annoying
buoobuoo now i have the signature but whats the value?
So you can easily use:
sender.sendMessage("ยงcYou have to be a player to use this command");
ik lol
._.
org.bukkit.plugin.InvalidPluginException: Cannot find main class 'me.tvhee.main.Main'
Btw plugin to test my API
BukkitPlugin does extend JavaPlugin, and directly extending JavaPlugin also doesn't fix the error
please dont name your package main lol
Yes I know, it is only a plugin for myself to test my API
Ok I will try
me.tvhee.testplugin.TestPlugin
No it's not the fix
I also didn't misspell something
hmm im not entirely sure tbh
Ok
If I use the direct arctifact from Intellij it works
API
@Override
public final void onEnable()
{
instance = this;
TvheeAPI.setInstance(new API(this));
config = getAPI().createConfigFile("config.yml");
System.out.println("onEnable bukkit plugin");
onPluginStart();
}```
TestPlugin:
```java
@Override
public void onPluginStart()
{
registerCommand(new TestCommand());
saveDefaultConfig();
getConfiguration().set("testboolean", true);
saveConfig();
getLogger().info("Plugin started");
}```
Why doesn't it get called? TestPlugin is overriding the onPluginStart() method
Oh nvm, used a too old version of my API
@wraith rapids sorry for the ping, but I need a person who knows how to use commodore. Do you mind?
Commodore just allows you to use Brigadier
How to see what the Artifact ID is in Eclipse?
the 4th line doesn't work
it doesn't do anything. Am i using it wrong?
How are you registering the command
imagine if there was a C# plugin compatibility layer for spigot plugins
Olivo are you able to help me?
How can I delete a yml
I'm not using brigadier directly. I just put the PluginCommand obj inside the commandMap
There are transpilers available
for specifically spigot?
48% of transpilers commit suicide
That's not going to work. Register your command properly
๐ฆ
No but for C# to Java
@wraith rapids How to see what the Artifact ID is in Eclipse?
I forgot what I defined it as
Stop pinging random people
if java supported COM calls you'd be able to use C# lol
Is this bad?
use your brain
why would it be
So should I rename it?
why would you rename it
You can call C# from Java
idk
How can I delete a file like... idk config.yml
I am stupid
on enable
I don't know how this stuff works
huh??
you're not stupid
Do I keep it that way?
I've not ever registered the command properly. I always done it through spigot... Do you know how to use brigadier bc I saw on github but they don't specify what should I use as CommandSource
which is worse than stupid
Where do I read up on it?
on the internet
oof
how would you even do that?
try googling "how maven works" or something
Is using IntelliJ easier?
Mhm
it can be
I don't know what my groupID is
ahahhahahaha
I meant GroupName
How can I delete a file on load? I tried file.delete() but it gave this error https://paste.md-5.net/ziduhadova.bash
there is no such thing as group name
No one?
Bro read the commodore example
that's just the guide being dumb
What do I do now?
what is your artifact id
I was not talking about commodore
tfw jetbrains rider committed die on me
Since you are using Brigadier you need to use Commodore
my.soldier.here
I'm not using brigadier.
now, what you are trying to do right now is figure out your 'plugin package'
this is the package where your plugin's code is
I'm using spigot to register the commands
it should be unique to your plugin
the convention is to make it 'groupId'.'artifactIdInLowerCase'
do you still remember your group id
my.soldier.here
good, now, write it down
then, add a . at the end
do you still remember your artifact id?
But you asked how to do it with commodore ;/. Oh well then just add your command to your plugin.yml and then you getCommand and set the executor on enable
I wanted to use commodore on spigot
Soldier
src/main/java
soldier
Soldier.java
I'm looking
this should match the text you write on the first line of a class
which it does not
now, if you were using intellij, I could tell you how to move your package so it matches
Should I download it?
No, IntelliJ
Please look at a basic Java tutorial
I can install IntelliJ if you want me to
you can try it i suppose
Okay, I'll download it
I can send you some tutorials if you want
yes
i've already linked you the intellij maven tutorial several times
anyway olivo. I am able to use commodore. It doesn't give any errors. It even does the auto-completation. The problem is that I don't know how to use commodore
this time, you're going to have to find it yourself
ight imma send u in dms
I don't have to. I have it saved in Google Keep (Google Notes)
I have sent him all he needs
I don't know how should I format the .commodore file
you can't send him effort and the conviction to pull through
which is what he needs
Your file looks fine
either multi-module project layout or reflective fucknuggetry
either way it's 10x the effort
^^
and not worth the time
._.
this line is name brigadier:string single_word;
i should write myself a brigadier library at some point
i doubt i'd have the effort to make it public
do you know what this line does?
i find just tab completitions to be enough most of the time
I'm using commodore over spigot (idk how to use brigadier) just for tab-completations
it works
How can I achieve this?
Basically I have 2 H2 databases (that contains some duplicated data) that I need to merge to 1, it's for a LiteBans database.
remove the duplicate data
project structure/libraries/+/java/yourlib.jar
but yeah, if you use maven, use the pom.xml-way instead. i suggest the intellij-plugin Minecraft-Development, that does all of that automatically
why i getting a diferent location ?
you are either serializing or deserializing it wrong
yes
your code is unintelligible
what code ?
that "should" work
?
print out some debug or stick it into a debugger and see what is going wrong
you are getting the block location yes, not the full precision location
you are also not serializing the direction of the location, but idk if that's intentional or not
i need too xd
unless you want your data to be human readable, you probably also want to serialize the world to its UUID rather than its name
that way, if someone renames a world or something, your database doesn't explode
...
yes, the full location is not an Integer
it is a floating point number
don't call Integer.parseInt() on values that aren't integers
nice
i'm making the code, in addition to adding new things, fixing new things and adding new errors, you know
but if the world not exist xd
I would probably add an error in the gui
player.teleport(location)
I'd try player.teleport
yes but how can i define the location variable
Location location =
new...
then construct a new Location that represents the coordinates you want
and after the =?
there you construct your Location
but where can i give the coordiantes?
in the constructor parameters
?jd
package index
look up Location
new Location(world, x, y, z yaw, pitch));
hate me guys
i'll shove a spoon up your ass
tf
i love hate, hell yeah
it's the same result as letting him look at the doc tho. just saves him time
an we haven't much time :/
it does save him time
but it also saves him the experience of understanding what the fuck he is doing
he'll be back here asking how to construct a player next
I got my mummy player and my daddy player...
Not really
papi basically means daddy lol
how to configure the tab complete to a bungeecord command?
I'm trying to register a custom event (in Kotlin). This is the code for the event itself, and in the class it is in I have another event (not custom). When I register the event, I get an exception (org.bukkit.plugin.IllegalPluginAccessException: java.lang.NullPointerException). If I remove the code from the custom event, this does not happen. Could anybody help me with this?
full error if needed
The class from the event itself
EventManager.kt:77
Report this to the maintainers of com.dualipa.song:Levitating-Base-English:jar:1.0-20210430.184020-2
It's not an issue of yours; they are likely using the system scope somewhere
Yeah I got that, but that just leads to the following line: Bukkit.getPluginManager().registerEvents(RegionEvents(), BandiCore.instance!!)
isn;t guava shaded in Spigot?
What even is that
how can i check if player has a diamond pickaxe named "something" in their hand?
im trying to make a pickaxe that makes everything drop twice
if the name is right
yeah i know
im new and i dont know how
look up a guide
"how to use persistent data container spigot" + google
then skip the youtube videos
those are trash
thanks
Could anybody help me with this?
My plugin doesn't work
package someboodi2.soldier;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.plugin.java.JavaPlugin;
public final class Soldier extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getLogger().info("onEnable is called!");
}
@Override
public void onDisable() {
getLogger().info("onDisable is called!");
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onLeaveBed(PlayerBedLeaveEvent event) {
Player player = event.getPlayer();
player.sendMessage("You left a bed");
}
}
we have been through this before
"doesn't work" does not tell us anything
also
take a good look at what you are doing
use your eyeballs and then your brain
onEnable is called when the server starts, the plugin loads
onDisable is called when the server stops, the plugin unloads
can you see the issue?
oofy
someone can helpme?
other than that, yes, very good progress
you've been able to do something on your own for once, I think
No one here really uses Kotlin
kotlin is gay
i need to verify an data archive with my plugin on a command, but does work :c
debug your issue. The npe is thrown in that register line. So either the class is null or the instance is null
Why do I get this error? https://paste.md-5.net/xogicorofi.cs, java.lang.IllegalStateException: ServerPingEvent may only be triggered synchronously.
you are triggering server ping event asynchronously
And how to trigger sync?
do it on the main thread
if closed false, turn "closed" to true, if true return the "already closed message"
Bukkit.getServer().getScheduler().runTask() ? But I am already doing that
something somewhere is making it happen off the main thread
i can't see shit in your class
it's all unintelligible
print out the current thread you're on and see where your stuff is running
if it's something you can block, you can sync to main thread and fire the event there, and then block until that is done
and then return your serializer or whatever you're doing
How do you guys word wrap on IntelliJ?
actually, show me your stack trace
you're supposed to word wrap manually
by pressing enter before the vertical line on the right
why manually?
I can help you but since Iโm on phone pls use
?paste
that's just how it is
Ok I will show the stacktrace
line breaks are part of your code and shouldn't be diddled with by some line break automation
yeah this happens off the main thread
your code is invoked whenever a packet is received
Ok, but how?
it is invoked by what I assume to be protocollib
or you might just be hooking directly into netty
regardless, it's not the main thread, it's some networking thread somewhere
The problem is that the bukkit method is a void method, and I can't return the serializer. It worked before, but I since I call it inside it doesn't work
what is PingModifier.java:109
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Iterable
Bukkit.getServer().getPluginManager().callEvent(event);
you just need to create an object to hold onto what you want to return
that line is being called async
since it needs to be final
Ok I want to return JsonSerializer<?>, and set it into the Gson
f.e
Serializer[] returnMySerializer = new Serializer[1];
Bukkit.getScheduler().runTask(() -> {
//compute the thing here, write it to the array
});
//block execution until runTask completes
and then return returnMySerializer[0]
Ok thanks
remember to block the execution
And how to block?
use futures or object monitors
why
f.e
CompletableFuture<Serializer> returnMySerializer = new CompletableFuture<>();
Bukkit.getScheduler().runTask(() -> {
//compute the thing here, write it to the array
returnMySerializer.complete(//your result);
});
return returnMySerializer.get();
.get blocks until the future is completed by the code on the main thread
and then returns the value it was completed with
Ok, and I can set the .get into the Gson?
I will first try, then I will speak any further
you can do whatever with it
Ok thanks
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Iterable
this is the error i get
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.plugin.java.JavaPlugin;
public final class Soldier extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getLogger().info("onEnable is called!");
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public void onDisable() {
getLogger().info("onDisable is called!");
}
@EventHandler
public void onLeaveBed(PlayerBedLeaveEvent event) {
Player player = event.getPlayer();
player.sendMessage("You left a bed");
}
}```
send the stack trace
[14:55:42 WARN]: [TestPlugin] Task #523 for TestPlugin v1.0.0 generated an exception
java.lang.IllegalArgumentException: null
at com.google.gson.internal.$Gson$Preconditions.checkArgument($Gson$Preconditions.java:46) ~[patched_1.16.5.jar:git-Paper-597]
at com.google.gson.GsonBuilder.registerTypeAdapter(GsonBuilder.java:472) ~[patched_1.16.5.jar:git-Paper-597]
at me.tvhee.api.PingModifier.lambda$onServerListPing$0(PingModifier.java:61) ~[?:?]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftTask.run(CraftTask.java:100) ~[patched_1.16.5.jar:git-Paper-597]
at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:468) ~[patched_1.16.5.jar:git-Paper-597]
at net.minecraft.server.v1_16_R3.MinecraftServer.b(MinecraftServer.java:1423) ~[patched_1.16.5.jar:git-Paper-597]
at net.minecraft.server.v1_16_R3.DedicatedServer.b(DedicatedServer.java:418) ~[patched_1.16.5.jar:git-Paper-597]
at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1338) ~[patched_1.16.5.jar:git-Paper-597]
at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1126) ~[patched_1.16.5.jar:git-Paper-597]
at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:289) ~[patched_1.16.5.jar:git-Paper-597]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_281]
At this line: .registerTypeAdapter(serverPingClass, getSerializer())
Class: https://paste.md-5.net/ebiliyovax.java
Both are not null
I will try CompletableFuture#thenAccept
you are literally returning null
Yes if there is an error
Wat
also that still runs off the main thread
how to get offline players in bungeecord
youa re just creating the serializer on the main thread
java.lang.IllegalStateException: ServerPingEvent may only be triggered synchronously.
the serialization itself is still done off the main thread
which means your event is also fired off the main thread
What to do then?
ProxiedPlayer would be the representation iirc
run the event on the main thread
wrap it in bukkit.runtask
you have wrapped the creation of your serializer in bukkit.runtask
Ah
you have not wrapped the contents of your serializer in bukkit.runtask
does anyone know a collection class that allows me to write from a thread and concurrently read from another?
Ok
CopyOnWriteArrayList
Collections.synchronizedList synchronizedSet
ConcurrentHashMap.newKeySet()
@Mr.EmPee#8047
Thanks
Ok so I return the event?
Or just synchronize a non thread safe collection externally
Yeah that was the second option
you return whatever information you need
if you need the event, you return the event through the future
Depending on situation, synchronized keyword or Lock interface might be better
really?
If youโre making it thread safe externally yeah
Assume you only have 2 threads both reading and writing to the collection for instance a single thread executor and the server thread. Then use synchronized itโs faster when the amount of threads are lower. But letโs say you use a thread pool like a fork join pool in that case Lock interface may perform better (more amount of threads)
No
If you can, use a thread safe collection
It will abstract away the need of implementing synchronization in a multithreaded environment. Needless to say java does a decent job optimizing those ones.
meanwhile i'm still writing my trie
callServerPingEvent(serverPing).thenAccept(event ->
But how am I going to return the JsonObject then?
normally
No that is not possible
What are you doing precisely? TL;DR
he's trying to run an event on the main thread
and then use the result of that event for a task that's running on a netty thread or something
Oh it is actually working, returning the thing
baby's first concurrency steps
Lol
what is the impl of callServerPingEvent
private CompletableFuture<ServerPingEvent> callServerPingEvent(ServerPing serverPing)
{
CompletableFuture<ServerPingEvent> futureEvent = new CompletableFuture<>();
ServerPingEvent event = new ServerPingEvent(serverPing);
Bukkit.getServer().getPluginManager().callEvent(event);
futureEvent.complete(event);
return futureEvent;
}```
Is there a method to loop though a player inside a location range or do I need to built it myself?
@wraith rapids whay
nothing
location.distance
there was a guy needing help with kotlin earlier
k
figured your princess gloves could be put to use
thanks
wrap the callEvent in bukkit.runtask
and complete the future with the event in the lambda
I done that
you haven't
I will do the bukkitruntask now
private CompletableFuture<ServerPingEvent> callServerPingEvent(ServerPing serverPing)
{
CompletableFuture<ServerPingEvent> futureEvent = new CompletableFuture<>();
final ServerPingEvent event = new ServerPingEvent(serverPing);
bukkit.runtask(() -> {
Bukkit.getServer().getPluginManager().callEvent(event);
futureEvent.complete(event);
});
return futureEvent;
}```
Ok
some one can help me?
the event has already run
you can use it as if it was any other object
you don't need thenX blocks or anything
?ask dont ask to ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply.
i need to verify the ticket ID are closed,
the constructor is:
'ticketID(int)':
closed: 'false'
on the archive, i want to make the command change "closed" to "true" on /helper close "ticketID(int)"
but, when i execute the command
don't change in the tickets.data
stay "closed" "false"
Remote "true", and use true without "
I think he want to set a boolean in the config like true of false
Then don't use ", otherwise it will become a string
the constructor os those classes are string
i cant
sure you can
no, i cant
you can
I am testing now
i use mysql too
that doesn't mean that everything needs to be strings
Boolean.valueOf()
String.valueOf()
you can convert types from one another
Learn Java
always use the correct data type in your code
if you need it as a string later, convert it to string
i can't cast string to boolean when i using other api methods, i have erros when i do this
yes.
public class FlashPet extends Pet {
@Override
public String getName() {
return "Flash";
}
@Override
public String headValue() {
return "id";
}
@Override
public PetAbility getAbility() {
return new SpeedAbility();
}
@Override
public int getValue() {
return 15;
}
}
How would I make the SpeedAbility a instance for every player instead of creating a new instance always
casting is not converting
casting does not convert anything
you need to convert your boolean to a string, or vice versa
Boolean.valueOf(string)
String.valueOf(boolean)
learn java
you clearly don't
understand
i do
i understand that you have no idea what you're doing
and are trying to cast Strings into booleans
kek
its my code
or
your code?
You can cast Entity to LivingEntity because one extends/implements the other. You can NOT cast String to Boolean because they are in no way connected.
bad code is bad code
yeah, bad support its a bad support
sure
you refuse to do it
In earlier times I also didn't agree, but learn Java, then you will understand
If I break carrots or potatoes, the code doesn't go through. I have a debug message but the debug isn't being sended. https://paste.md-5.net/nofoyetuki.java
public class FlashPet extends Pet {
@Override
public String getName() {
return "Flash";
}
@Override
public String headValue() {
return "id";
}
@Override
public PetAbility getAbility() {
return new SpeedAbility();
}
@Override
public int getValue() {
return 15;
}
}
How would I make the SpeedAbility a instance for every player instead of creating a new instance always
declare a field for it somewhere, instantiate and assign it
then retrieve it instead of constructing a new one
Well, I want it different from players
Create something like SpeedAbilityManager class maybe.
create a playerdata class and assign it there
then maintain a single instance of playerdata for each player
Well as Every Ability inherits from PetAbility which just looks like this
public abstract class PetAbility {
public abstract String getName();
public abstract String getDescription(int value);
public abstract void onEquipped(Player plr, Pet pet, int value);
public abstract void onDequipped(Player plr, Pet pet, int value);
}
not relevant to how you maintain the instances of them
I do not need to keep the same instance on restart meaning I do not need to make a data class of it
I just want different instances for the petability for each player
that is not what a data class does
Oh nvm
if you need to hold a specific instance of this class for each player, then you need some sort of a holder for each player
I know what you mean
therefore, create a playerdata class which will hold the instances, and instantiate one for each player
Okay