#help-development
1 messages · Page 2101 of 1
wtf did i do to my computer im on windows 10 XD
oh 99% of my cpu is being used... that explain it
oof
lmfao i just closed half my tabs and it dropped to 29%
x)
kinda impressive tho bc besides for that there was nothing else that made it seems like i was using that much cpu
maybe windows update have forces you updated it
doubt it i just updated a few days ago
🙄
couldn't imagine they'd already be forcing me to update
Any idea as to why am I getting index out of bounds here?
Location[] locs = new Location[3];
Chest[] chests = new Chest[3];
for(int i=0;i<9;i+=3) {
locs[i/3] = new Location(w, Integer.parseInt(split[i]), Integer.parseInt(split[i + 1]), Integer.parseInt(split[i + 2]));
chests[i/3] = (Chest) w.getBlockAt(locs[i]).getState();
}
ugh its a bit intricate to see as you're doing quite many array accesses in one line
but one of them would be w.getBlockAt(locs[i])
Oh I didn't notice the locs[i]😅
Whats IOOB?
IndexOutOfBounds
Oh, no these should be fine if im correct
aight
hey guys im back
wb bro
and ready to give you all the most scuffed code solutions youve ever seen
lmao
do you think you'd be able to help with what i dm'd?
choose or die is such a scary movie on netflix
holy shit im watching it and I already got jump scared twice and almost broke my monitor
lmfaoi
package de.leleedits.ffahardcore.listener;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
public class PlayerDamageListener implements Listener {
@EventHandler
public void onPlayerDamage(EntityDamageEvent e) {
Player p = (Player) e.getEntity();
Location coord1 = new Location(p.getWorld(), -13, 190, -13);
Location coord2 = new Location(p.getWorld(), 13, 150, 13);
if ((p.getLocation().getBlockX() > coord1.getBlockX()) && (p.getLocation().getBlockX() < coord2.getBlockX())) {
if ((p.getLocation().getBlockY() > coord1.getBlockY()) && (p.getLocation().getBlockY() < coord2.getBlockY())) {
if ((p.getLocation().getBlockZ() > coord1.getBlockZ()) && (p.getLocation().getBlockZ() < coord2.getBlockZ())) {
e.setCancelled(true);
}
}
}
if (e.getCause().equals(EntityDamageEvent.DamageCause.FALL)) {
e.setCancelled(true);
}
}
}
why can I still pvp inside of the area where I cancel the event?
- Please, make some variables and constants
- EntityDamageEvent#getEntity() gets the entity that was damaged, not the one inflicting the damage. You want EntityDamageByEntityEvent and #getDamager()
choco so nice
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent e) {
Player p = (Player) e.getDamager();
Location coord1 = new Location(p.getWorld(), -13, 190, -13);
Location coord2 = new Location(p.getWorld(), 13, 150, 13);
if ((p.getLocation().getBlockX() > coord1.getBlockX()) && (p.getLocation().getBlockX() < coord2.getBlockX())) {
if ((p.getLocation().getBlockY() > coord1.getBlockY()) && (p.getLocation().getBlockY() < coord2.getBlockY())) {
if ((p.getLocation().getBlockZ() > coord1.getBlockZ()) && (p.getLocation().getBlockZ() < coord2.getBlockZ())) {
e.setCancelled(true);
}
}
}
if (e.getCause().equals(EntityDamageEvent.DamageCause.FALL)) {
e.setCancelled(true);
}
}```
Like this? Idk what you mean with variables, I have enough lol
Should work fine but you're going to get exceptions because getDamager() isn't always a Player. It might be a zombie or anything else that can inflict damage
Check first, cast after
if (!(e.getDamager() instanceof Player player)) {
return;
}
// Continue using the player variable```
Or if you're not using J16/17
Entity entity = e.getDamager();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity```
(the fall damage part is going to need to be in EntityDamageEvent though)
Location coord1 = new Location(p.getWorld(), -13, 190, -13);
Location coord2 = new Location(p.getWorld(), 13, 150, 13);
if ((p.getLocation().getBlockX() > coord1.getBlockX()) && (p.getLocation().getBlockX() < coord2.getBlockX())) {
if ((p.getLocation().getBlockY() > coord1.getBlockY()) && (p.getLocation().getBlockY() < coord2.getBlockY())) {
if ((p.getLocation().getBlockZ() > coord1.getBlockZ()) && (p.getLocation().getBlockZ() < coord2.getBlockZ())) {
e.setCancelled(true);
}
}
}```
this part should work? Because like 1 hour ago it didnt worked
its like a spawn protection
Can re use some stuffs in there by storing them in a variable
Other than that, you can clean things up a lot.
private static final int MIN_X = -13, MIN_Y = 150, MIN_Z = -13;
private static final int MAX_X = 13, MAX_Y = 190, MAX_Z = 13;
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player player) {
return;
}
Location location = player.getLocation();
double x = location.getX(), y = location.getY(), z = location.getZ();
if (x < MIN_X || x > MAX_X || y < MIN_Z || y > MAX_Y || z < MIN_Z || z > MAX_Z) {
return;
}
e.setCancelled(true);
}```
See how much easier that is to read? 
Can do one better and create a BoundingBox which has a method to check if a location is within it
yes, thank you
ill test it tomorrow :)
hellooo how can i spawn a random Entity, doenst have to be living or non living, both i guess. thanks
o rhow cna i get a list of all the entities available in the spigot api
anyone?
choco how are you so nice
Canadian
EntityType.values() returns a list of entity types
Can get spawnable ones with EntityType spawnableEntities = Arrays.stream(EntityType.values()).filter(EntityType::isSpawnable).toArray(EntityType[]::new)
ohhh
tysm
how can i do the same but for items :)
in other words, how can i get a random itemstack
thank you
my plugin cannot connect with mariaDB
then you did something wrong
Is there a built in way to check if a player punches a Falling sand block? (Before I have to implement my own) and no entity attack event doesn't work
PlayerSmackSandEvent
Yeah but that's naughty for people with high ping
kick players with 400 ping +
I care too much about my high ping players
Hello, I have a small problem, I need to check if the player is standing in a lily pad. I have tried multiple ways of doing it but nothing works, can someone help me?
And please ping me if you've got an answer
In or on
Check the relative block below
Is it possible to send custom achievements?
yes
Ah, not in 1.8 sorry bro, only 1.12+ with advancements
Hi guys, what's the easiest way for me to implement vanilla selectors into my plugin? Like full minecraft logic including [type= or distance=]?
how do i get the server type and version?
like Spigot 1.18.2-rev69420 or something
or Paper MCVER+VERSION
declaration: package: org.bukkit, class: Bukkit
how to break out of this Bukkit.getScheduler().scheduleSyncRepeatingTask(test.getInstance(), () -> { Bukkit.broadcastMessage("This message is shown immediately and then repeated every second"); }, 10L, 60L);
lets say after 5 times running
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Bukkit.html#getVersion()
You will have to use Regex to find what you need
declaration: package: org.bukkit, class: Bukkit
for what will i have to use regex
?scheduling (Use a bukkit runnable)
That gives you the entire version string. If you only want the mc version for example you will have to find it in the string
Alright then just use the method I sent without using Regex on it
aight thanks
tried already, theres random errors i have no idea what to do with, I need 1 example and the entire net doesnt seem to provide one that works
Add a parameter instead of empty one
All of them on that page work. Send your errors
?paste
task -> {
Condition
task.cancel
}
Bukkit.broadcastMessage("This message is shown immediately and then repeated every second");
task.cancel();
}, 0L, 60L);``` how to make task.cancel work
Use run task timer
task.cancel(); still not working
public void run() {
Bukkit.broadcastMessage("Mooooo!");
task.cancel();
}
}.runTaskTimer(test.getInstance(), 20L * 10L /*<-- the initial delay */, 20L * 5L /*<-- the interval */);```
ok so
public void run() {
Bukkit.broadcastMessage("Mooooo!");
cancel();
}
}.runTaskTimer(test.getInstance(), 20L * 10L);``` this will cancel after 1 time? I'm confused
Yes it will cancel after first time
ok so to break it after x times
i could do something like this right?
new BukkitRunnable() {
public void run() {
Bukkit.broadcastMessage("Mooooo!");
counter = counter + 1;
if (counter == 10) {
cancel();
}
}
}.runTaskTimer(test.getInstance(), 20L * 10L);```
You should put the counter inside the BukkitRunnable
You can also use counter++ and >= instead of ==
new BukkitRunnable(counter = counter + 1) {
public void run() {
Bukkit.broadcastMessage("Mooooo!");
if (counter == 10) {
cancel();
}
}
}.runTaskTimer(test.getInstance(), 20L * 10L);```?
No
The counter variable should be defined inside your BukkitRunnable class but outside the run method
?scheduling 🙂
It has an example that works
If you read it
Anyways I have a feeling you're not very experienced with Java. And I highly recommend to keep practicing it so you know what you can do and what you cannot do
And their inside a anonymous
Much better if u have a seperate class extends BukkitRunnable if its a complex task
Can reuse the object too
true
is there a 1 liner to play a block breaking sound that correlates with the block id
public Mudwalker (String namespace) {
super(new NamespacedKey(MudwingCustomEnchant.getPlugin(), key:"namespace"));
}
``` does anyone know y this doesn't work? it is telling me that "key has privet accesse in org.bukkit.enchantments.Enchant how do i fix that?
declaration: package: org.bukkit, interface: SoundGroup
Please don’t randomly access the enum lol
We lose 1.18
declaration: package: org.bukkit.block.data, interface: BlockData
What do you mean loose 1.8
Do you know of a 1.12 technique
Does that method not exist in 1.12
Right that is pre flattening
Well rip people living in the past
what is the eventhandler i am targeting for when a player walks on a block?
1.12 is the future
thx
every other version requires so much ram to even have the server exist with 0 people on 😦
i am making a enchant that works like soulspeed for a different block and i want to track when they are ontop of it to get them a speed boost
it was over 1gb for no players when I tested
ok
i would need to use @EventHandler public void onPlayerMoveEvent or would it be just PlayerMoveEvent?
ik how some work i am still learning how this works
My servers all work insanely smooth with 1gb 1.12 and under
bro 2b2t test was running 1.18 at 20 tps @ ~120 people online vs like 14 tps on 1.12
I'm not complaining 😦
Some haters would say that a certain forks of spigot also just has a lot of optimisation, even now including Timothy
Tunity LOL
anyone know y this is a problem?
what version of java is that
The "java with named parameter" fork obviously
is there a way to carry data with an event through the handlers?
i want to check if the event was previously handled
by one of my other handlers
if its not possible ill need to make a custom pipeline to broadcast the events and then carry data with them
16?
I rage quit plugin development, I had the solution to my problem like an hour ago but I had block sounds off on my client
lmfao
anyone?
no
the event is a plain java class
dunno how you want to attach data to it directly
you can obviously just throw it at a map
or abuse the fact that event handler logic is guaranteed to be in order, e.g. just have a single field you set/read from
is it possible to set the ai of a snowman to another entity?
yes
How would I fill all slots of a gui with a block ( dark gray stained glass )
for loop
just make a for loop with i=0 and then fill the slot with the index i with the item you want
of course you have to limit the for loop to the amount of slots in the inventory
Oh, sorry for the typo, I meant on top of the block
guys im trying to edit someone's code wtf is this
idk what is EbeanServer and there is no EbeanServer in the code
ctrl shift + f and search for private Database database;
and it doesnt show any errors in the ide?
does the implementing class already have a getDatabase method
the 2 could be conflicting (lombok + implementing class)
Looks like Database is a invalid object too
It's the wrong return type
check the import of Database as well as the returning value
yep figured something along the lines of that was happening
kind of odd that plugin compiled for the OG author
maybe hes built different
yes
My question: How come intellij tells me this value can be null, yet the isString specifically checks for null https://hub.spigotmc.org/javadocs/spigot/org/bukkit/configuration/ConfigurationSection.html#isString(java.lang.String)
cause ij got no brain
and doesn't know what is isString
and is a null check
well I would assume it would check the API of the ConfigurationSection, maybe not
not sure if theres a setting for that either
big brain
made fromString argument nullable
ConfigurationSection is an interface
I believe the common implementation is MemorySection
not sure
So it can't magically guess each implementation
public void registerNextPermutation(
IngredientNodeLike node,
int depth,
List<Ingredient> ingredients,
List<Integer> usedIndexes,
Recipe recipe
) {
if (depth >= ingredients.size() - 1) {
((RecipeMatchTree.Node)node).setRecipe(recipe);
return;
}
int il = ingredients.size();
int ui = 0;
for (int i = 0; i < il; i++) {
if (usedIndexes.get(ui) == i) {
ui++;
continue;
}
Ingredient in = ingredients.get(i);
RecipeMatchTree.Node n = node.getIngredientChild(in);
usedIndexes.add(i);
registerNextPermutation(
n,
depth + 1,
ingredients,
usedIndexes,
recipe
);
usedIndexes.remove(usedIndexes.size() - 1);
}
}
@Override
@SuppressWarnings("unchecked")
public void register(Recipe recipe) {
registerNextPermutation(
tree,
0,
recipe.ingredients(),
new ArrayList<>(),
recipe
);
}
``` bruh
anyone know a better way of doing this lmao
the IDE doesn't know if what you're calling will return whatever you ask for
isString could do some heavy operation
and null values could break it
sure it could be slightly smarter and look at all implementations of it
but then someone could make a new implementation, inject shit via reflections and break everything
Ngl i can see what you mean since it is calling get() which returns and object and instead getString returns a string directly i think
Not that
if you call MemorySection#isString your IDE will recognize it
if you call ConfigurationSection#isString, your IDE won't due to polymorphism
best way to make your IDE stop screaming is annotating isString with @NotNull
but neither of us are spigot maintainers afaik so that's annoying
What if i use MemorySection object directly instead of the ConfigurationSection interface?
Or would it still cause the same thing
also calling get... again could produce a different result
best way is just
Object value = get("path");
if(!(value instanceof String text))
return;
text...
your ide doesn't yell at you unless the config is nuill
and it does the job
not a bad idea, I think in a later version ill implement that
for now i just added @smoky tinsel to my method argument and null check it in there
slightly more messy but I need to refactor this whole project i think anyway
https://github.com/Burchard36/DynamicItems/tree/main/src/main/java/com/burchard36/github
Most of the code around this is rather dogwater
I would really love to use Json and i could shorten this by ten-folds
But then im gonna force people to use json and I feel like it may make my plugin less popular
why do you have both @Getter and public 🤦
also getStringList returns an empty list if the path is invalid so you can avoid some console logs
probably slight miss by me when typing and tab completions like with this
was looking at the wordconfig
you know you can annotate the entire class and all fields will have getters right
Like @Getter at the top of the class file?
@Getter
public class ...
also @AllArgsConstructor makes a constructor with all args
@RequiredArgsConstructor makes a constructor with args that do not have a pre-defined value
@Data is even cooler here no?
@Data sometimes causes issues
I remember having issues for having a data class within another data class
Lombok is the issue xd
Ill have to look into that never used it
Changing it to
@Getter
@Setter
@EqualsAndHashCode
fixed it for me
thing is
would i be able to select only certain variable to be part of the AllArgsConstructor?
no
„AllArgs“
there's also NoArgsConstructor which you can stack with others
I have some things that arent even variables as well, so i dont thing that annotation would work very well for me
you can shorten this to 2 lines
ohh yes i could for that class ty for pointing that out
@Getter
@AllArgsConstructor
private static class LoreValue {
private final List<String> lore;
private final ItemQualityField quality;
}
that's all
if you're storing values on hashsets or as keys of a hashmap
annotate with @EqualsAndHashCode
Nah LoreValue is just a list of Strings for the Lore, and item quality stores +50 in a sense as a Operation + Integer
ew lombok
i prefer it just to keep my code base relatively short and not bloat it with getters and setters
why not
on top of the class
Have you considered reading the rest of the convo
yep Illusion told me that im redoing it rn
where tf did my Statistic refresh button go
How can I make a cooldown item but only decrease the cooldown time If player is holding the item?
Youll need a runnable for that more than likely and check the players main/offhand during the runnable
What to store?
UUID of players that are in that specific "need to hold item" cooldown
Is it okay to store the time in pdc?
Your API you showed me the other day should be able to handle to rest
should be i dont really see and issue with it
Noice 590 to 554 after lombok refactoring
The thing is with using System#currentTimeMillis the time will still keep running even If player isn't holding the item right?
Yep, youll need to store a milli value of how long player was holding the item for
no i mean since when can you use boolean
So, update the millis value whenever player stop holding the item?
nah its for explicitly specifying type arguments
but i used a primitive
in a generic type
tf
while holding the item is the only time you increment that value
if player isnt holding that item simply dont increase the time
btw Kotlin does it better just sayin'
loreConfig.get<String>("shit")
Like it continues to make no sense that explicit type args are before the method name
That's a good question
Consult the JLS to see what it actually means, maybe?
Okay
umm, i still don't get it somehow
What part dont you get my good sir
how am i able to stop counting when player aren't holding the item
how should i make a deserializeString() method that gets a String and turns it into milliseconds? the string should contain like "1m 29s" or "2h 30m"
does anyone know if there is like a premade java or bukkit method for that?
check if held item is null/air
Pretty certain there isn’t an inbuilt method that for that format
Jods time had a period parser
^ i always just did it myself
Java now has iso format Parsing on duration (Java 8)
So you might be able to convert your string to that format
can u turn duration into milliseconds?
Yes
i dont really know how to get the string and turn it to duration
because i tried but didnt actually understand much
Like what should I store when the player used the item's skill.
dang that's exactly what I wanted
thank you so much
You should have a config name of the item, store that and have a long of the cooldown the player has inside of that Data class you showed me the other day
like itemsInCooldown Map
<String, Long>
String = config name of item
unless your item is hard coded in
I want the cooldown to bound on the item not the player
So then store the cooldown inside PDC
and while player is holding an item with that PDC tag do something
yeah i'm trying to figure out that something
if (hasPdc) {
reduceCooldownPdc(item);
}
inside a runnable
then after reducing check if value <=0
if true remove that pdc tag
so to check if player is on cooldown don't use the System#currentTimeMillis?
reduce the time manually
No for that type of system youll have to manually do it
since you only want it while the players holding the item
ahh okay
only thing i dont know
is what 1 tick is to millis
youll have to figure that part out
i think its 50
yeah
i'm gonna use integer i guess
50 * 20 = 1000
You could but
If the player keeps switching items
theyre cooldown may not cooldown properly
so youll have to check very often
like 5-10 ticks in time
yeah since i assume since your using integer it will be in seconds
and doing that can cause issue if player switches item very often?
yeah say theyre constantly switching every second and they held it for most of the second, it could lead to cooldown being longer than expected
i would say do one tick check BUUUUUT performance might hinder
5 ticks is probably the magic spot
after all you are only checking a PDC tag and decrementing a long value
my way right now is start a task as soon as player hold the item
and stop the task if player is no longer hold the item
is that worse than having 1 runnable and loop through all players and check the item that they're currently hold?
https://www.spigotmc.org/threads/how-bad-is-it-to-loop-through-bukkit-getonlineplayers.419206/
Was actually doing that reaserch for you
should be fine
way your doing it rather scuffed
as youd constantly re-initing runnables
okay, i'll do that then
if you are concerned for performance
./timings on and /timings paste
and you can check its performance there
but IMO shouldnt really be an issue
i mean having 1 runnable than a runnable for every player is better i guess
indeed it is
Probably best to have a tick loop if 5 rather than 1 though, im sure 1 would be fine but if this is a public plugin it could cause issues
you could make it a config option too
check-item-cooldown-in-ticks: 5
And larger servers can make the delay higher if they do run into issues with it, but they honestly shouldnt
of course it will change how i decrease the cooldown right?
Yep!
let's say if i want to put the cooldown in seconds
600 seconds
how can i decrease it if the task is running every 5 tick?
best to convert those 600 seconds to millis
millis are btter for cooldowns like that
600 * 1000
I can convert it I guess, but for just readability I'll put the initial values to seconds
yep thats what i normally do with my plugins
config cooldown is in seconds
but ill convert to milli on the actual code
okay, so how much should i decrease every 5 ticks?
Is this as far as you can go for a blank item?
you can hide that attributes
Is that with with ItemFlag
yup
ok cheers
one tick is 50 ms
so 5 * 50
double angle = Math.random() * 360;
double radius = Math.random() * config.getSpawnRadius();
Location location = player.getLocation().add(Math.cos(angle) * radius, 0, Math.sin(angle) * radius);
this should get a random location in a radius around the player right
hey how would i pick a random one from here and use it's chance? i'm spawning 5 mobs in a radius and i want them to be picked with chances
should i not use an enum
EntityEnum.values()[<random number>]
yeah but how would i pick with teh chance too
just use the random function
i guess
chance is the chance it has to spawn after it’s picked?
I'd just create an array of the length of all chances combined and add the values with the amount of their chance
I.e. something like
int len = 0;
final EnityEnum values = EntityEnum.values();
for (EntityEnum val : values) {
len += val.getChance();
}
EntityEnum[] weightedValues = new EntityEnum[len];
int x = 0;
for (int i = 0; i < values.length; i++) {
EntityEnum val = values[i];
for (int j = 0; j < val.getChance(); j++) {weightedValues[x++] = val;} /* or just use arrays#fill */
}
Why not make this a config option
seems weird to hardcode that
this wouldnt make it random though
you need to use Random class or ThreadLocalRandom and generate a random number 0 - 100 for each mob
It would be random
Provided you access a random element of weightedValues my approach is as random as I assume is wanted
will giving potion effect override the current potion?
even when the new effect is worse?
i always just do something like
static final int averageWeight = 35; // or something
static final List<EntityEnum> weighted;
static {
// preallocate a rough estimation of how many values you might need
weighted = new ArrayList<>(averageWeight * EntityEnum.values().length);
// initialize weighted values
for (EntityEnum e : EntityEnum.values())
// if we say x is the chance,
// we will add x elements of the instance to the list
// as that makes it x times more likely to
// occur than a single element
for (int i = 0; i < e.getChance(); i++)
weighted.add(e);
}
public static EntityEnum getRandomEntityType(Random r) {
return weighted.get(r.nextInt(weighted.size()));
}
you could put that in your EntityEnum class
Yeah, basically my approach
no, the chance of it being picked on the whole : e.g.
program chooses a random one in the enum, generates a random number, if that number is in the chance, it will spawn, else it will redo that process
but can i set specific chances for each entity though
yeah
the averageWeight is just to estimate how much memory should be allocated
completely unneccesary optimization
but i like it
oh ok damn
how lol
i dont really understand that weighted bit
so it will add that item to a list, chance times and make the program more likely to choose it?
Yes, which is why it is best to keep the chances rather low
I.e. once you have a combined chance of like 8 000 000, you'll have a really large array that is kinda pointless if all chances are a multiple of let's say 4 000
A) What sort of GUI
B) What the player clicked or which player clicked?
C) Sure that you cannot use a library for that - there is a high risk involved in GUIs
D) There is rarely a univerally best method
I use PDC stuff for that
You could also use indices
(Assuming you want an inventory GUI and the player cannot manipulate the inventory)
Hi! I'm stuck here. I have the game profile with the custom texture from the head value and i want to set it to block data (Skull). I've seen the methods of that class and there aren't any. My guess is that it is a private field like SkullMeta (see second image).
Could anyone help me?
?jd
declaration: package: org.bukkit.inventory.meta, interface: SkullMeta
Oh you are using NMS. Bad boy!
i'm not using SkullMeta
Oh that other thing
yeah
yeah but thats a 1.18 thing
yes
i don't have it
what version are you using
i'm on 1.17
"performance"
Actually thats not my concern
enlighten me
my question was if the field of Skull for the profile is named profile or what?
probably not during runtime
?stash
whats this?
source code management for spigot
e.g. there is your impl for the Skull interface
so yes
Probably been there ever since the DMCA happened
there is something wrong with this sentence, but i cant work it out 
Umm, I'm trying to put a pdc into item but when I check it using PersistentDataContainer#has it says that it doesn't have even tho I already set it.
This is how I check and how I create the item https://paste.md-5.net/oxifocoqir.java
Basically the isShard method is returning false
w class org.bukkit.craftbukkit.v1_17_R1.block.impl.CraftSkullPlayer cannot be cast to class org.bukkit.block.Skull (org.bukkit.craftbukkit.v1_17_R1.block.impl.CraftSkullPlayer and org.bukkit.block.Skull are in unnamed module of loader 'app') uhm
skulls are block state
not block data
or at least the player profile etc is stored in the block state
like this?
Does one NamespacedKey can only store 1 type of data?
you cannot store different data under the same key
in my experience yes
ah im dumb
I mean
you could but like good luck
it is a map in the end
your key has one and only one value
got it, thank you
you could store two values under the same namespace by probably serializing a class that holds that two values (if i'm wrong correct me) to a byte
nothing really changed
If u are using it for a pdc then each key can have different values i think
Each key can only store 1 data type
Is there a way of getting the block location from the InventoryOpenEvent? Needing to find the chest clicked
get the inventory holder
check if the holder is an instance of a Chest
and then there ya go
of same type forgot to mention that above
really?
e.getPlayer().getTargetBlock(
Set.of(Material.AIR)
, 15);
Should work
That worked, was trying to get instanceof Block instead 🤦♂️
Of course i should credit u first since u can't accept mistakes
wdym?

So basically now it kinda works @eternal night . No error is thrown but the skull doesn't change its texture
🤷♂️
okay
anyone has got ideas?
whoever said you cant iterate over something and remove it you are correct
you need to use iterators
: )
Oh my bad, wdym by really though, is it the different values i mentioned? Me being dumbass cuz im sleepy af
remove or add, either way gives a CME
learnt it from personal experiences... i was like destroying the keyboard
or just use removeIf(Predicate)
I need
or an iterator
.
correct me if im wrong but, did you said that you can store multiple values with one namespacedkey but same data type?
hey, so what does the averageweight do?
what does it change in the long run
you can... you can
SkullMeta#setOwner
oh
and it is for blocks
I mean each pdc for each meta can have unique values under same key
@noble lantern this is what I got right now, following your suggestion to update every 5 ticks, but I got this ugly problem when the item is updated, is there any workaround or fix?
Oh yeah, I got what you mean.
wym updated
Yeah sorry about making it unclear
Like setting the item meta of the item stack after I edit the pdc value.
You can see the video I sent above.
it estimates how many elements it will have
for pre allocation
performance
its an unneccessary optimization
no
can you show the code thats using this
your not updating the block states data
there should be a setBlockState or similar
https://paste.md-5.net/ejesoyosih.cpp So right now everytime I decrease the cooldown, I will change the pdc value of the item that means I need to set the item meta and setting the item meta will play that animation.
no there isn't.. there is just this update thing
according to this video though
It looks like its working?
It's working yes, but the animation is very bad, looks very scuffed.
declaration: package: org.bukkit.block, interface: Block
ohh
you not want it to do that dippy thing huh
not do*
yup
cancel interact event
it isn't block data though
this is block state
well
SKull is deprecated
so im not sure why you use that class
You should be using BlockData to manipulate skulls
PlayerInteractEvent is not called at all
it should when your right clicking that shard
either way thought according to spigot javadocs Skull is deprecated
You should be using BlockData/BlockDataMeta
I'm not right clicking the shard tho, the animation happened because I set the item meta
unless your developing on ancient 1.8
are you replacing the item by chance
or only updating the meta
and how do i set the skull using that?
Try using updateInventory after setting the meta, saw some posts and people used that
SkullMeta should be castable to BlockDataMeta
im not sure why Skull isnt showing deprecated to you
oh fuck
mb
duck duckgo is stupid
it showed me old asf javadocs
ignore everything i said, my apologies
Nothing changes
seems like this is some client sided issue when updating item meta's hmm
https://www.spigotmc.org/threads/1-8-8-updating-item-meta-without-updating-the-item-itself.335649/
This thread is older but same thing basically
You might need to use packets @summer scroll and cancel the packet the plays the re-equip packet
Uh oh
theres this thread
according to the last post you might not be able to cancel it :c
If it's not possible to cancel, then I might have to change how to store the item's data then.
I'm thinking about having a uuid each item, and store the data into yaml when server stops and load them on server start.
meh i wouldnt worry about storing cooldowns on server start/stop for items especially if there some type of skill
You might have to just handle this in your UserData class as mentioned earlier
I would try canceling the packet first
thats the only singular i post i saw where someone said you cant cancel it
On the last post it says that the animation is played first before sending the packet.
how do i get HOW an entity was killed?
as in like, shot, fall damage, etc
is it getLastDamageCause()
that returns the EntityDamageEvent, which in turn should get the reason
Alright, I'll try to cancel the animation packet
declaration: package: org.bukkit.event.entity, class: EntityDamageEvent, enum: DamageCause
SHould be a method that returns this enum: getCause()
Why not not use newline?
I dont think you can modify spigots logger
this is why
Your probably can, but I'd advise against it
,
Yes, you can simply get rid of newline and use one log statement for one line
well
i got a idea
i will put this thing in string and i will put before the database login check
And don't use Sysout, you'll get a bug report at some point
Don't use the newline char
yeah it's better than before i think
If you really want do something like for (String ln : line.split("\n")) {getLogger().info(ln);}
why not just send these all as seperate logs instead of appending like above ^
because i want to look like this
And beware that huge banner messages aren't well liked by the admin community
but i can keep data in left side
why? :)
IMO that looks more messy than having the timer before each message
well
Yeah
well
plus its gonna look super funky in server log files
got a idea again
It might even break a few log parsers
brb
Non-monospace fonts
As soon as you use somethign other than monospace your message will look ugly
no need for \n doing that
hey, from an online website, i have this code for a custom world.
Where do i put it when the world is creating (im using worldcreator btw)
forgot to remove those, pretend they dont exists in the image
Is this a java question orrrr
if its a java question
you need to go through that json object
it's json
and go through each field and set it as a settings in WorldCreator class
ie is he trying to use that object in java or not
i hope this wont be a public plugin and your hard coding database info in
it wont be lol
You should use a config for this tbh
If you need a config tool I can give you one
Who knows
well
if it can help, here is my code :
if (command.getName().equalsIgnoreCase("roofed")) {
Player player = (Player) sender;
WorldCreator worldcreator = new WorldCreator("Monde_Jeu");
worldcreator.type(WorldType.NORMAL);
worldcreator.generateStructures(true);
worldcreator.createWorld();
WorldBorder worldBorder = worldcreator.createWorld().getWorldBorder();
Location location = new Location(Bukkit.getWorld("Monde_Jeu"), 0,0,0);
worldBorder.setCenter(location);
worldBorder.setSize(500);
worldbordersize = 250;
for (Player playerr : Bukkit.getOnlinePlayers()){
playerr.teleport(new Location(Bukkit.getWorld("Monde_Jeu"), getRandomNumber(-200,200), 200, getRandomNumber(-200,200)));
}
}
ik that i would need to use the Customized world type i just havnt changed it rn
no mutual servers, friends or dm
Where would it be from lmao
idk lol
read down @steel swan
you need to go through that json object and apply it to WorldCreator class for every field in that json object
and how would i modify it?
ok lemme check
Gson is built into Spigot you can use the fromString method
ok i think it's ok
a lot better
well since its just a plugin for your server i assume dont worry about it
ok
like i dont rly understand where i would use it?
so you meant by server devs, not spigot admins
like u mean in the code of worldcreator?
you would need to loop through that large JSON object you have, and then use WorldCreator methods to set to the values you have in the JSON object
but how would i use worldcreator to put it in the json object ? like wich method
lemme explain, i have those parameters for a world. I create a world with world creator. what i want is to add those parametres to the world. But idk how to do that
Then you need to loop through those parameters you have and apply them to WorldCreator
yeah i know. But How do i apply them to worldcreator
like is there a special method?
yes
for that you need to create a ChunkGenerator (which is rather complicated, your basiccally making your own generator)
Heres this too: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/WorldCreator.html
ok imma read that out
OH
that should help for the block settings
i should of said one thing
i m using 1.8.8 ( i know very bad version but i dont have a choice)
Hmm
might need to use NMS idk if that class exists in 1.8.8
idk if thats an official javadoc though
same method exists in there it seems
https://hugo4715.github.io/SpigotJavadoc/org/bukkit/WorldCreator.html#generatorSettings(java.lang.String)
hmmmm
smth like that for instance?
worldcreator.generatorSettings("usecaves"= true; )
you should be able to shove your whole json object in that argument
okeeey
So, when i create a custom item with an extra NBT tag, but it has the material of a Diamond Block, how can i prevent that custom item being turned into normal diamonds in the crafting table?
theres a few different ways
i know i can override the default recipe with my own, but thats not ideal
- prevent the diamond block with NBT from being put into a crafting GUI's slots
- Cancel result slot click if the ingredient in the table is the item with your NBT tag
does anyone know how to change biomes with a world generated with https://bukkit.fandom.com/wiki/Developing_a_World_Generator_Plugin to only one biome of my choosing? (jungle)
unexpected type
like the entire stack trace
send your code too
?paste
Yea i was afraid of having to use the last option, but it seems to be the best option, and i actually just thought of someting!
I can just check if the resulting item has the nbt Key that all the items have, and if it doesnt AND contains a custom item i can safely set the result to null
just that part where your getting the Json object and inputting it into WOrldCreator
CraftHumanEntity does not work for me how can i fix that?
that argument isnt a string
encapsulate that json object as a string
"thatobject"
i have to put it as a string?
Isnt that a NMS object
yes, read the doc i sent it takes a String as an argument
the error code is Cannot reslove symbol `CraftHumanEntity
and I already found a workaround but i dont now how to implemt this in my code
"org.bukkit.craftbukkit." + Bukkit.getServer().getClass().getPackage().getName().split( "\\." )[3] + ".entity.CraftHumanEntity"
);
Field field = craftHumanEntity.getDeclaredField( "perm" );
field.setAccessible( true );
field.set( player, new CustomPermissibleBase( player ) );
field.setAccessible( false );```
thats whta i found on github
?paste
bump
what version?
version of?
minecraft
1.18.2
if i cast ```java
ItemStack.getItemMeta().toString()
ok so there is a built in way to do it
which is?
:proccessing:
biomeProvider(String biomeProvider)
what's worldgenerator? the chunk in the 2 for loops?
ok so
ooooh
i see
there is a setBiome() thing
try it for the chunk
imma be back
ahem
also there is no .getBiome().set()or whatever
wait i think i got it
there's a biome parameter in the method
https://paste.md-5.net/pegiloraye.coffeescript
im trying to generate a custom wold
world*
the worldcreator.generatorSettings doesnt work
this?
hey, what is the CUSTOM and CONTACT death types?
in the DamageCause enum sorry
not the death type
is contact like entity cramming?
nvm the docs say
sorry
Hey there guys, new to Java dev, I'm trying to extract some data from the console when an event happens from Economshop GUI, I'm looking to tax players when they sell stuff by parsing data logged to console
18:14:31
[EconomyShopGUI]: User sold 1 x Diorite for $0.18 with the sell screen.
is an example of what I will be using to extract into a plugin, does anyone recommend any approach for trying to see what is logged and then using the data here? I want to parse 0.18 from console and apply a tax on the value
that is a bad approach check out its api
well rip me i guess
hey, it is not directly an question to spigot programming itself. But it is the first time that i downloaded source code from github and edit it. it is an spigot plugin that i want to edit for my server. If i build the plugin, will it automatically upload the changes to the github repository? because i dont want that. i dont want to update the github repository of this plugin with my changes.
no
i dont know how this git(hub) stuff works.
Even if it did, git is a Version control system, you’d be able to revert it
Okay thanks for the quick answer. The changes i made would not make sense in the main repository.
It won’t push or commit automatically
Also, if you download from someone else’s repository, you’d have to create a pull request if you wanted your changes to be submitted to the repo.
Okay. then its fine. i only want to build the plugin locally
Okay and how can i build source code in gradle? i only work with maven normally. thats why i dont have experience with gradle
So I have a PlayerInteractEvent which checks to see if a chest is left clicked. I then set the block clicked to Chest by casting Chest. However, when running this code I get an error which says that block.CraftBlock cant be casted to block.Chest. How do I do this?
Why are you setting the block to a chest if the block you’re checking for is already a chest?
I need to get the inventory title of the chest
Anyone knows why would this happen when trying to refresh my project?
Spigot
Are you casting the block to a chest or the blockstate?
Block
I think you need to cast the blockstate to a chest instead.
Why do I get this error?
Code:
public static Boolean isEnoughPlayer()
{
Boolean bool = false;
Integer count = 0;
Integer teams = Main.TEAMS;
for(Player p : Bukkit.getOnlinePlayers()){ //ERROR LINE
if(!Main.PLAYERTEAM.containsKey(p)){
count++;
}
}
while(teams > 0){
if(Main.TEAMLIST.get(teams).size() > 0){
count++;
}
teams--;
}
if(count >= Main.MINPLAYERSTART){
bool = true;
}else{
bool = false;
}
return bool;
}
Error:
Caused by: java.lang.StackOverflowError
at com.google.common.collect.Lists$TransformingRandomAccessList.listIterator(Lists.java:579) ~[SPIGOT_1_8_8.jar:git-Spigot-db6de12-18fbb24]
at java.util.AbstractList.listIterator(AbstractList.java:299) ~[?:1.8.0_312]
at com.google.common.collect.Lists$TransformingRandomAccessList.iterator(Lists.java:576) ~[SPIGOT_1_8_8.jar:git-Spigot-db6de12-18fbb24]
at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1041) ~[?:1.8.0_312]
at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1040) ~[?:1.8.0_312]
at de.vinemc.plugin.mine2death.GameFunctions.isEnoughPlayer(GameFunctions.java:125) ~[?:?]
Which should be available as chest is a block, so you can just use #getBlockState() on it.
ok let me try that quickly
how do minecraft furnaces work?
does it re-evaluate the recipe every tick for every block
or does it store the recipe in the nbt tag or something like that
and rematch that every time the input is modified
that worked. Now to get the custom name. Thanks!
21.04 17:47:14 [Server] INFO Caused by: java.lang.ClassCastException: class java.lang.ClassNotFoundException cannot be cast to class java.util.ArrayList (java.lang.ClassNotFoundException and java.util.ArrayList are in module java.base of loader 'bootstrap')
``` why? ```java
public static void onPlayerJoin(Player p)
{
File invDir = new File(Utils.getOwnDir + "inv");
if (invDir.exists())
{
if (new File(invDir.getPath() + '/' + p.getUniqueId().toString() + ".bin").exists())
{
ArrayList<Item> itemFile = (ArrayList<Item>) Utils.deserializeFromFile(invDir.getPath() + '/' + p.getUniqueId().toString() + ".bin");
//itemFile = (ArrayList<Item>) obj;
if (itemFile instanceof ArrayList)
{
Bukkit.broadcastMessage("IS INSTANCE");
}
else
{
Bukkit.broadcastMessage("IS NOT INSTANCE");
}
//ArrayList<Item> itemFile = (ArrayList<Item>) Utils.deserializeFromFile(invDir.getPath() + '/' + p.getUniqueId().toString() + ".bin");
//ItemStack[] itemList = new ItemStack[41];
//int i = 0;
//for (Item item : itemFile)
//{
//itemList[i] = new ItemStack(item.getType(), item.getAmount());
//i++;
//}
//p.getInventory().setContents(itemList);
}
}
}
it serializes correctly
but it fails to cast into the type
your utils thing is doing something not good
bukkit.getServer.getonlienplayer?
that error message is not very helpful
its not the full thing but it tells everything you need to know
i mean it’s pretty obvious a classnotfoundexception can’t get cast to an arraylist
I'd assume that in case of an exception, the deserialize method returns the exception. Which is a bit strange but eh
yea but either it actually serialized a CNFE or the deserialize method returns a CNFE
public static Object serializeToFile(Object obj, String str)
{
try
{
return (Object)SerializePtr.invoke(UtilsPtr, obj, str);
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
{
e.printStackTrace();
}
return null;
}
public static Object deserializeFromFile(String str)
{
try
{
return (Object)DeserializePtr.invoke(UtilsPtr, str);
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
{
e.printStackTrace();
}
return null;
}
Oh no wtf
public static Object serializeToFile(Object obj, String str)
{
try
{
ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(str));
s.writeObject(obj);
s.flush();
s.close();
return 0;
}
catch (Exception e)
{
return e;
}
}
public static Object deserializeFromFile(String str)
{
try
{
ObjectInputStream s = new ObjectInputStream(new FileInputStream(str));
Object ret = s.readObject();
s.close();
return ret;
}
catch (Exception e)
{
return e;
}
}
Yeah, Propagate the exception
this isn't golang 😅
so thats why i cant i deserialize ahhh
Well it is failing somewhere
it works just fine
using ArrayList<String> as type
oh and btw thats my Item
package admin.commands;
import java.io.Serializable;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class Item implements Serializable
{
private static final long serialVersionUID = -338300065334497259L;
public String type = "";
public String meta = "";
public int amount = 0;
public Item(ItemStack is)
{
super();
this.type = is.getType().toString();
if (is.hasItemMeta()) this.meta = is.getItemMeta().toString();
this.amount = is.getAmount();
}
public void setType(Material type)
{
this.type = type.toString();
}
public Material getType()
{
if (!this.type.equals(""))
{
return Material.valueOf(this.type);
}
return null;
}
public void setMeta(ItemMeta meta)
{
this.meta = meta.toString();
}
public ItemMeta getMeta()
{
if (!this.meta.equals(""))
{
ItemStack dummy = new ItemStack(Material.AIR, 1);
ItemMeta meta = dummy.getItemMeta();
//return this.meta;
return null;
}
return null;
}
public void setAmount(int amount)
{
this.amount = amount;
}
public int getAmount()
{
return this.amount;
}
}
its an error thrown by the bukkit layer
and btw it serializes just fine
¬í sr java.util.ArrayListxÒ™Ça I sizexp )w )sr admin.commands.ItemûNâ
>ð I amountL metat Ljava/lang/String;L typeq ~ xp t IUNSPECIFIC_META:{meta-type=UNSPECIFIC, enchants={DAMAGE_ALL=1}, Damage=1}t NETHERITE_SWORDsq ~ @t t
DIAMOND_BLOCKsq ~ q ~ t WOODEN_SWORDsq ~ q ~ t CHICKENsq ~ q ~ t FEATHERsq ~ t 0UNSPECIFIC_META:{meta-type=UNSPECIFIC, Damage=1}q ~
sq ~ q ~ t
GRASS_BLOCKsq ~ q ~ t AIRsq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ sq ~ q ~ q ~ x
otherwise id throw an error in the file
this represents an arrraylist filled with the player invs content using my wrapper class
the error you sent isn’t helpful since you’re trying to cast the classnotfoundexception to the arraylist which obviously won’t work
send the actual classnotfoundexception
from the server?
yes?
that’s not the exception
then wdym
you are trying to cast
the classnotfoundexception to your arraylist
because it’s getting returned from your util method instead of thrown/printed
wait
sure ive rewritten it
public static Object serializeToFile(Object obj, String str)
{
try
{
ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(str));
s.writeObject(obj);
s.flush();
s.close();
return null;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
public static Object deserializeFromFile(String str)
{
try
{
ObjectInputStream s = new ObjectInputStream(new FileInputStream(str));
Object ret = s.readObject();
s.close();
return ret;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
```+
(but generally, you will need to use BukkitObjectInputStream instead of ObjectInputStream)
but im using my own class
bukkit independent
good to know tho i can try that i guess
hm
so it can’t find your Item class for some reason
just also properly works with bukkit things
which makes no sense because it finds it during serialization
takes me a sec
to adapt
i need to rewrite it because my serializer is accessed using reflection
i suppose using the BukkitObjectOutputStream i can just serialize the entire player inventory?
potentially
which suffices
ye
ive only written the wrapper class because
i wasnt able to store bukkit objs
sure lemme try
problem is i cant reflect bukkit instances from loading a class
so i need a sec to rewrite it
take your time 👍
@eternal night so like this?
public static boolean serializeBukkitObjectToFile(Object obj, String str)
{
try
{
BukkitObjectOutputStream s = new BukkitObjectOutputStream(new FileOutputStream(str));
s.writeObject(obj);
s.flush();
s.close();
return true;
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
public static Object deserializeBukkitObjectFromFile(String str)
{
try
{
BukkitObjectInputStream s = new BukkitObjectInputStream(new FileInputStream(str));
Object ret = s.readObject();
s.close();
return ret;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
That should work ye
