#help-development
1 messages · Page 2010 of 1
i've been trying to solve this problem for a long time and now i'm starting to think it may have something to do with spigot..
I'm making a resource pack for my plugin, here's my models/item/potions.json
{
"parent": "item/generated",
"textures": {
"layer0": "item/potion_overlay",
"layer1": "item/potion"
},
"overrides": [
{
"predicate": {
"custom_model_data": 1
},
"model": "item/beer"
}
]
}
however the custom texture is being applied to every potion that has a custom model data on it:
i wouldnt check for the name "world_nether" but for Bukkit.getWorlds().get(1).getName()
assuming there is a nether world, idk if thats possible to play without
each one of the 3 potions on the bottom has 3 different custom model datas
what else would you expect to happen?
I expect the texture to be only applied to items that have a custom model data of 1
i think the issue is tostring
but its being applied to literally any item that has any number for custom model data
if you specify custom data for int 1, it also applies to 2, 3, 4, ....... if those aren't defined explicitly
i don't think it returns the world name
oh really?
also it has nothing to do with spigot, the vanilla client handles that stuff
yes
there is
ah ye that too
nope if you say
1 = texture a
2 = texture b
3 = texture c
and that's it, texture c applies to everything above 2
is there a way to make it not do that
How can i make a loop for loop all online players.
well thanks, i know this isnt entirely spigot related but i've been asking on like 5 other servers and no one had an answer
Bukkit.getOnlinePlayers() returns a Collection<Player>
now just do a regular for-each
thanks
Alex do you make money from plugin development
how can i generate a void world? afaik you need to override generatechunkdata from chunkgenerator but it's deprecated
reposts message after like 10 minutes, pain
i've bumped once and i preferred reasking than rebumping
if(e.getPlayer().getLocation().getWorld().toString().equals("world_nether")) {
is this rigth?
huh
hey
why is my plugin not working
name: Fortune 1000 # the plugins name as it should appear in the plugin list /pl
version: 1.0 # the plugin's version
author: Orla
main: me.orla.Main
api-version: 1.18.1
commands:
fortune:
description: Give a fortune 1000 pickaxe
usage: /fortune
no
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
dont use getWorld().toString()
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
no
aight lemme check rq
@tender shard
java.lang.NullPointerException: Cannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "me.orla.main.getCommand(String)" is null
use getWorld().getName()
register your commands in plugin.yml
i did
yea i have changed the msg
here
show the full stacktrace @raw ibex
i meant to say dont
do u have a typo where u register the command
stacktrace?

oh
[17:36:39 ERROR]: Error occurred while enabling MaxFortune v1.0 (Is it up to date?)
java.lang.NullPointerException: Cannot invoke "org.bukkit.command.PluginCommand.setExecutor(org.bukkit.command.CommandExecutor)" because the return value of "me.orla.main.getCommand(String)" is null
at me.orla.main.onEnable(main.java:9) ~[maxFortune-1.0.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugin(CraftServer.java:564) ~[paper-1.18.1.jar:git-Paper-177]
at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugins(CraftServer.java:478) ~[paper-1.18.1.jar:git-Paper-177]
at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:727) ~[paper-1.18.1.jar:git-Paper-177]
at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:503) ~[paper-1.18.1.jar:git-Paper-177]
at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:313) ~[paper-1.18.1.jar:git-Paper-177]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1202) ~[paper-1.18.1.jar:git-Paper-177]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.1.jar:git-Paper-177]```
what's main line 9?
this.getCommand("fortune").setExecutor(new GivePickaxe());
what can work Then?
can't help but notice that the main class is 1.) named main, and 2.) its lowercase. more pain
Don't name your main class "main" bruh
open your .jar file with WinRar and check if your plugin.yml is actually the same as in your IntelliJ / IDE
oh i typoed
check the world's name
i know why
not the world's toString()
ok
I recommend you naming the file using UpperCamelCase and not naming it main but after your plugin
?main
wait, your whole plugin can't work
for (Player s: Bukkit.getOnlinePlayers()) {
if(s.hasPermission("Doktor")) {
if(p.isDead()) {
Location p_locationx = p.getLocation();
double x = p_locationx.getX();
double y = p_locationx.getY();
double z = p_locationx.getZ();
s.sendMessage("X:" + p_locationx + " Y:" + p_locationx.getY() + " Z:" + p_locationx.getZ());
}
}
}
}```
what people do with java sometimes
it is
first you have a space in your plugin.yml "name", second your main class is not called the same as in your plugin.yml
Somehow its not working
well then compile a .jar that contains the correct plugin.yml lol
oki
it is not. World#toString returns CraftWorld{@172651} or sth like that
and not the world's name
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
The message not sending the player who has doctor perm. No error on console.
Location p_locationx naming convention police 
the world folder name is world_nether
and World#toString() is NOT "world_nether", as I already said
is the permission "Doktor" or "doktor"?
let me take a lok
also a player is not dead yet in PlayerDeathEvent IIRC
why do you even loop over all players in the death event?
what are you actually trying to achieve?
cntrolling all players if they have doktor perm
Hello everyone!
can anyone help me how to check is a bungee server online or not?
huh?
does the event actually fire tho or is it just getting caught on the p.isDead()
I think players are dead in the death event but I'm not certain
its Doktor
Is it not the same as the other damage events? The player is actually dead when the event exits?
idk
I don't think they are because IIRC I always had to wait a tick to call Player.spigot().respawn()
but I am not sure either
I'd make a quick test to check but it'd take me forever to open minecraft & intellij
add debug statements. e.g. add an "else" clause to your permission check and also to your isDead check, then print out what players are actually dead or not and whether they have the permission or not
yeah fuck it. I'll check it lol
I always have my Test project open
pluginname.permission.subpermission
Memory leak issue problem
yep same
both does not responding
a player IS dead in PlayerDeathEvent
problem can be event
They are not
they are
^
[18:53:25 INFO]: mfnalex issued server command: /kill mfnalex
[18:53:25 INFO]: true
@EventHandler
public void onDeath(PlayerDeathEvent e) {
System.out.println(e.getEntity().isDead());
}
That’s freaky because they shouldn’t be dead lol
I’ve looked at the code, the player state doesn’t get modified until after the event finishes
cuz its cancellable
PlayerDeathEvent is not cancellable
oh yeah thats weird
if an event is cancellable it fires before the event happens.l
No it isn’t, but you can set the health and un-kill them
if you want to check, just heal them in the death event
it is nto cancellable
thats programmed weirdly
It’s strange
it would follow the damageEvent behavior though
@tender shard my guess is that isDead only returns based on health so their health is 0 but none of the actual death stuff has happened yet
then they are already dead
I already have to do the PlayerEquipArmorEvent so it's someone elses turn
If you heal them on death none of the death stuff happens iirc
So isDead must be just returning true because their health is 0
Can you try healing them before the print since you already have the test code up @tender shard
They will also not exist in getOnlinePlayers() in the PlayerDeathEvent.
Yes they will?
no
They don’t get disconnected when they die
check it and see
help my intellij is now light mode and idk what i did
durring or after the event exits?
how do i fix it lol
ok
during, and after, until they respawn
They aren’t removed from the world when they die
All the respawn does is teleport them and heal them
Old bukkit voodoo moments with #help-development
thanks
@EventHandler
public void onDeath(PlayerDeathEvent e) {
e.getEntity().setHealth(10);
System.out.println(e.getEntity().isDead());
}
[18:58:11 INFO]: mfnalex issued server command: /kill mfnalex
[18:58:11 INFO]: false
But the player dies anyway
Does it drop their stuff?
let me check
Or what do you mean they die anyway
check if they exist in the getOnlinePlayers() while you are at it
no, and when clicking on Respawn, they also respawn at the same location
seems like they don't actually die, the client just gets confused
I'll do a videoi
The respawn screen isn’t going away?
It’s supposed to
Ahhh
That makes sense
this could be likely, especially if the dead are pushed async
what is a good theme that has easy readable colors?
for intellij
?
That makes sense
the included default themes
yeah that's how I remembered it too
I always use runTask to respawn them a tick later
but I also never set their health to > 0 in the death event lol
I’d have to check to verify that’s how we make sure the respawn screen is never displayed but I buy it
I also don't see any reason why someone would do that
if someone wants to prevent people from dying, they should NOT wait until the death event but instead cancel the damage event
To respawn them without showing a respawn screen
i just use Darcula
most material themes are god ascend
I switch between dark and light theme depending on the weather outside
if the sun is shining = light mode
if not = darcula lol
mac does it automatically :3
windows doesn't 😦
I’m checking our code
you have to have it enabled in windows if you want that - I rather cortana and edge not be that integrated to get weather variance
is this something my plugin did or just some random 1/1000 error?
I’m just looking for where we hide the respawn screen
never seen this before and also i don't see any reference to your plugin
Ill try to do that again
are you trying to place an AIR block?
a tick task was run but its also looking at Async?
I’m doing it on mobile so it’s a pain to find it
But we’ve definitely hidden it from the player
And we aren’t cancelling damage before they die, we use the PlayerDeathEvent
no, i made an item which launches you forward. the error occurs every time I make the item break
show your code pls
hold on, trying to reproduce the error
they do get a respawn screen but only for 1/20th second
The error occurs when I am in creative mode, not in survival
?paste
private void updateEmptyCacheFlag() {
if (this.emptyCacheFlag && this == EMPTY) {
throw new AssertionError("TRAP");
} else {
this.emptyCacheFlag = false;
this.emptyCacheFlag = this.isEmpty();
}
}
this is the nms method throwing the ex
not really sure what is this meant to do but
I assume the error occurs in line 31 in that paste
full code pls
like
what event is that even
oh so basically this is something about trying to modify something about an air itemstack
Just found it, that’s what we do
yeah I suspected it sth to do with an AIR itemstack
Looks like you have a respawn screen still popping up
https://paste.md-5.net/enamoxaviv.cs that is the entire class
yes, the method is called in setCount
so trying to change an itemstack that has a null itemlike value will throw an exception
it's probably because you are changing the item within the event, you're probably not allowed to do that
EMPTY here is public static final ItemStack EMPTY = new ItemStack((ItemLike)null);
It’s because the event finishes firing and then they die
break the item a tick later
it only happens when I am in creative and the item breaks
aka when it reaches 0 durability
You’re respawning them in the event before they’ve finished dying, which is what I said when I looked at the code the other day. Glad we’re in agreement
the method that could throw an assertionerror is only called in the setcount method and in ItemStack constructors
so i am not sure how are you getting that exception if an item breaks while you are in creative
maybe minecraft tries to replace your hand slot with EMPTY (the constant) and set its count to 0?
im confused
I make my plugin break the item by playing a sound and removing the item when it reaches 0 durability. The plugin reduces the durability itself
could it be a fix to replace the Material.AIR with null?
you could try that
this is the main thing I believe
also how is the durability reducing if you are in creative
@tender shard checked but its not entering this condition if(p.isDead())
so you are changing it
yes
try to not change it if it's gonna get to 0
gotcha
but just remove the item before making the durability 0
will do, thanks
dont ask to ask
np lemme know if that fixes it
will do, mind if I ping you at that point?
did you seriously
scroll up to yesterday
to tell me this
props to you thats dedication
i don't
I was mentioned, and i searched mentions user:
i got a question about code design, I'm coding a skyblock island manager class that will hold all the island objects
would it be fine if I made a private static class in the manager that holds the methods to generate an island?
nope, just make this class handle all the island generation
and not copy paste code from anywhere
I would create a island generator class
since i don't need it elsewhere but i don't fancy slapping those methods in the manager class
Well theres no reason to be making it onily saccessable from your manager right?
i thought of that too but i'd need a single instance of it
yeah else than the fact that it is unnecessary
actually instanciating it could be useful instead of putting only static methods
yea i think i'll make a separate class
Well, you should make a generator class weith static methods no?
nvm
also, i coded a spiral-like generation thing but i am not sure how efficient it is
would you mind looking at it rq
public void execute(Player player, String[] args) {
iteration = 0;
int arg1 = Integer.parseInt(args[0]);
Location loc = player.getLocation().getBlock().getLocation();
Bukkit.broadcastMessage(String.valueOf(System.currentTimeMillis()));
for(iteration = 0; iteration < arg1; iteration++){
//loc.getBlock().setType(Material.GOLD_BLOCK);
changeLocation(loc);
}
Bukkit.broadcastMessage(String.valueOf(System.currentTimeMillis()));
}
private void changeLocation(Location location){
switch (getDirection()) {
case 0 -> location.add(distance, 0, 0);
case 1 -> location.add(0, 0, distance);
case 2 -> location.add(-distance, 0, 0);
case 3 -> location.add(0, 0, -distance);
}
}
private int getDirection(){
int direction = 0;
int iteration = this.iteration;
for(int j = 1; true; j++) {
for(int k = 0; k < 2; k++) {
iteration -= j;
if (iteration < 0) return direction;
direction = (direction + 1) % 4;
}
}
}
execute is a method my command api calls
also there is an iteration global field
getDirection returns an int based on the direction the next island should go towards
changeLocation adds to the center location based on getDirection
yea that should be fine
Are you creating the islands by hand/by code?
Why not use a schematic
And either do code yoursel;f or use worldedit as a dependency
i think i'll either use fawe or structureblocks
he never said he was going to?
this code was just a test
that was the idea but i couldn't really come up with a better name
Yea thats good
any suggestions?
Kinda a weird question: Was Lua made using Java?
I see massive similarties between the 2, just the way its coded is different
y?
nothing really appeared lol
so i was asking here
Lua has been used to extend programs written not only in C and C++, but also in Java, C#, Smalltalk, Fortran, Ada, Erlang
nvm found my awnser
its a port of a crapload of languages, made to be easier for others basically
:P
so lua just "ez code"
so what should i call it? it is a class with a map that contains island objects and methods to create/remove them
doesnt that just mean "Manager classes are generally considered bad"
Anti-pattern is just a fancy way of saying not good am i wrong?
@misty current I fixed it by not replacing the item in the hand with air or null, but by setting the amount of the item to 0.
This is the new code, thanks for the help 😄
no problem
But WHY
I guesse
When your managing islands
Its not that vague
could you elaborate, i wanna learn things
Idk what either of those are
so a registry should also be a singleton
You should look into the jackson json serializer if you are saving it to a file.
gross
I tried using it a long time ago and i couldnt figure it out 😅
Their pretty much the same no?
i'll actually hook it up with mongo
mongo uses bson iirc so i don't think i got many options here
that works
Michael Gson
I went to the lido the day he died
what a weird word
lido
"open air bath"
i have this class:
public class Alcohol {
...
private ItemStack itemStack;
...
public void setPersistentDataValue(NamespacedKey key, int value) {
ItemMeta meta = itemStack.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(key, PersistentDataType.INTEGER, value);
itemStack.setItemMeta(meta);
}
no matter what I do, setPersistentDataValue doesn't seem to save the value I give it..
here's the whole class:
i want to consume a sip and check that if it's empty, remove the item from the player's inventory
@EventHandler
public void onPlayerConsume(final PlayerItemConsumeEvent event) {
if (Alcohol.isAlcohol(event.getItem())) {
event.setCancelled(true);
Alcohol alcohol;
Player player = event.getPlayer();
try {
alcohol = new Alcohol(event.getItem());
alcohol.consumeSip();
if (alcohol.isEmpty()) {
Inventory inventory = player.getInventory();
inventory.remove(event.getItem());
}
} catch (AlcoholMissingPersistentData e) {
e.printStackTrace();
return;
}
}
}
in my testing, sipsLeft is always the initial value i set in the constructor, even if i try to decrement it
this feels weird
does itemstack have a value?
yes
alcohol = new Alcohol(event.getItem());
obviously, otherwise it'd throw an error
its perfect
;
the important thing if this code is working
var initialLocation = loc.clone();
initialLocation.add(0, 100, 0);
System.out.println(initialLocation);
var armorStand = (ArmorStand) e.getEntity().getWorld().spawnEntity(initialLocation, EntityType.ARMOR_STAND);
initialLocation.add(0, -100, 0);
System.out.println(initialLocation);
armorStand.setVisible(false);
armorStand.setGravity(false);
armorStand.setCustomNameVisible(true);
armorStand.setInvulnerable(true);
armorStand.setMarker(true);
armorStand.teleport(initialLocation);```
the teleport doesnt work
the location goes back to normal
but it does not teleprot back
am i somehow updating the ItemMeta wrong?
@ornate patio item stacks may or may not be snapshots
wdym snapshots
in the case of this event it is
e.g. you get an instance you can modify
but it won't reflect in game
erm what do you expect to happen
you add 100 to the location, then remove 100 again
so you teleport it to the original location
@eternal nighthello friendo
yes so
when i create the armor stand
so @ornate patio https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerItemConsumeEvent.html#setItem(org.bukkit.inventory.ItemStack)
declaration: package: org.bukkit.event.player, class: PlayerItemConsumeEvent
you will need to feed the mutated item stack back to the event/server
ohhhh
thanks
i call PlayerItemConsumeEvent#setItem(alcohol.getItemstack())?
and teleport it back to its start location
Yea 👍
@eternal night umm still still not working somehow
Static abuse to me
same issue
@EventHandler
public void onPlayerConsume(final PlayerItemConsumeEvent event) {
if (Alcohol.isAlcohol(event.getItem())) {
event.setCancelled(true);
Alcohol alcohol;
Player player = event.getPlayer();
try {
alcohol = new Alcohol(event.getItem());
alcohol.consumeSip();
event.setItem(alcohol.getItemStack());
if (alcohol.isEmpty()) {
Inventory inventory = player.getInventory();
inventory.remove(alcohol.getItemStack());
}
} catch (AlcoholMissingPersistentData e) {
e.printStackTrace();
return;
}
}
}
yeah but it does not teleport it to te original location
is anyone here familiar with the ACF command framework ?
what exactly?
yes
Am I using rand.nextInt(); wrong?
int counter = 0;
Random rand = new Random();
String rewardData = "Crates.crateRewardData.";
FileConfiguration conf = EmeraldsPlugin.jp.getConfig();
ItemStack item = null;
for (int i = 0; i < conf.getInt("Crates."+crateType+".Amount"); i++) {
String s = conf.getString("Crates."+crateType+".Items."+i);
counter += conf.getInt(rewardData+s+".Weight");
}
double Chosen = rand.nextInt();
for (int i = 0; i < conf.getInt("Crates."+crateType+".Amount"); i++) {
String s = conf.getString("Crates."+crateType+".Items."+i);
counter -= conf.getInt(rewardData+s+".Weight");
if (counter > Chosen) {
item = new ItemStack(Material.getMaterial(conf.getString(rewardData+s+".Material")), conf.getInt(rewardData+s+".Amount"));
}
}
It doesnt work as expected
can I dm you?
ask here pls
I don't understand why he's using static methods in his case...
To me, it shouldn't be static
any errrors?
Nope, but it only shows the first item half the time
Which is a diamond
because no instance is needed for those methods
and the second item?
(haven't looked at the whole class though)
EVERYTHING that does NOT need any instance SHOULD be static
alright so I'm using ACF and I'm getting this error (https://prnt.sc/sPZ1PcykllfH) I looked at it and it's something regarding unsafe API's, even though in my build.gradle im using spigot, lombok, lucko's helper & acf
oh you cancel the event @ornate patio that might bite you 😅 not too sure, but I'd expect the replacement to not happen then
hmm
at which point, this is pretty ugly
what if i cancel after
Okay th
oh weird, never seen that before, sorry no idea
alright thanks
your entire method finishes before it checks for cancelled state
what version of acf are you using?
I always use acf-paper 0.5.0-SNAPSHOT
so.. what would be the correct way of doing this
worked fine since forever
(acf-paper is the recommended one, even when supporting spigot)
Alright ill try use 0.5.0
?
yeah use acf-paper 0.5.0-SNAPSHOT and use PaperCommandManager (works also on bukkit / spigot)
I really don't know 😅 nothing not ugly for sure
so like rng#nextInt(2)
yea but its based on weight
can i just not cancel the event, and instead immediately replace the empty glass bottle with the item after its consumed
I mean yea, or just replace the item manually during the event and cancel it
how so
bruhh
actually
im lost
I was about to suggest you just grab the current active item of the player
after you cancel the event
Nvm, I got it to work!
but oh well, that is a paper only method 😅
Horray!
so what should i even do then
How would I make a chest have text above it, if right clicked w/ an item?
*I just want to know how to do the text above it part btw
"If the ItemStack is modified the server will use the effects of the new item and not remove the original one from the player's inventory.
If the event is cancelled the effect will not be applied and the item will not be removed from the player's inventory."
either create an armorstand or area effect cloud using spigot API, or using packets (NMS)
i dont even know what that means
then make the entity invisible and give it a custom name
when you consume something, normally an effect happens
if a player eats a pumpkin pie
but i set the item to a golden apple
the pumpkin pie won't get consumed
and they get golden apple effects?
yes
i tried setting the item to beetroot instead
@EventHandler
public void onPlayerConsume(final PlayerItemConsumeEvent event) {
if (Alcohol.isAlcohol(event.getItem())) {
Alcohol alcohol;
Player player = event.getPlayer();
try {
alcohol = new Alcohol(event.getItem());
alcohol.consumeSip();
event.setItem(new ItemStack(Material.BEETROOT));
System.out.println(alcohol.getSipsLeft());
if (alcohol.isEmpty()) {
Inventory inventory = player.getInventory();
inventory.remove(alcohol.getItemStack());
}
} catch (AlcoholMissingPersistentData e) {
e.printStackTrace();
return;
}
}
}
it consumed the potion..
you didnt really modify the itemstack
I mean, you can't even do that with spigot
how would i make it so a custom death message would appear upon a custom death?
the item you get is a copy not a mirror
i made it so when you enter water in a cold biome you freeze
setItem only works if not cancelled but then is also consumed
paper has some nice API to fix this 😄 ¯_(ツ)_/¯
well i kind of have to use spigot
is there some sort of event listener for after an event was fired?
no
lemme see
then you'd just have to remove the glass bottle
if needed
tho that would have to be done a tick after
The closest you can get is
not at all close tho
still closer then LOWEST priority lol
wow xD
How would I do p.getInventory().removeItem()
ah yes, I have 2 cents instead of 1
closer to a car than before
You'd basically see what's going to happen but you'd still be pre execution
(removeItem for some reason removes an entire stack of items)
(how do I make it only remove one)
ughh
wouldnt there be an inventory event right after?
loop through inventory, get the first matching stack, remove its amount by 1
ok i've got some code that will just consume the potion
maybe i can set a 1 tick timeout to replace the bottle with the potion?
@quaint mantle https://github.com/JEFF-Media-GbR/JeffLib/blob/f667ad2408f03c786cf839712eaa5c6e61118426/core/src/main/java/de/jeff_media/jefflib/InventoryUtils.java#L120 just copy this from my lib
the int parameter should be 1 in your case
IIRC they tried that and it removes the whole stack
It will try to remove 'as much as possible' from the types and amounts you give as arguments.
they only want to remove one item / reduce one stack by 1
Yeah
and also removeItem seems to behave different between different forks
It is known that in some implementations this method will also set the inputted argument amount to the number of that item not removed from slots.
So pass an itemstack with a size of one
but what does the last sentence mean?
I don't really understand that one, that's why I made my own method IIRC lol
It means it may mutate the input item
that's so weird
if the javadocs are so weird I tend to just use my own methods instead
So don’t try and reuse it after, as the amount may change
removeItem works perfectly
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. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
i did
where?
ill reask it it got covered by other messages
how do i make a custom death message for a custom death event?
I made it so you freeze when entering water in a snow biome
but it still says "(PLAYER) withered away"
declaration: package: org.bukkit.event.entity, class: PlayerDeathEvent
thanks
You’ll need to track if it’s your wither effect killing them
IIRC you can use "%s" in that to get the player's name but not 100% sure
maybe you have to manually insert the player name
but i want the witherd away death message to still be there for wither skele
mmm removeItem says it removes item stacks, not items
Exactly
?
hm? what do you mean? players cannot have items in their inventory. items are entities
ohhhh "your" wither effect
inventories can only contain itemstacks
removeItem
@NotNull HashMap<Integer,ItemStack> removeItem(@NotNull ItemStack... items) throws IllegalArgumentException
Removes the given ItemStacks from the inventory.
Yes
yes, that's what was asked for
What about it
right, but it doesnt say it works for anything less than a stack
It does
If you pass a stack with an amount of 7
It will remove up to 7 of that item
clone the itemstack, set it's amount to 1, then pass that to the removeItem method
A stack of items. The size of the stack can vary, from 1 to any number.
or use the method I've sent
solved my problem, I just used a Runnable:
@EventHandler
public void onPlayerConsume(final PlayerItemConsumeEvent event) {
if (Alcohol.isAlcohol(event.getItem())) {
Alcohol alcohol;
Player player = event.getPlayer();
try {
alcohol = new Alcohol(event.getItem());
alcohol.consumeSip();
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(main, new Runnable() {
public void run() {
try {
if (alcohol.isEmpty()) {
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));;
}
else {
player.getInventory().setItemInMainHand(alcohol.getItemStack());
}
} catch (AlcoholMissingPersistentData e) {
e.printStackTrace();
}
}
}, 1L);
} catch (AlcoholMissingPersistentData e) {
e.printStackTrace();
return;
}
}
}
I suggested that to you an hour ago lol
Arrow code
I am thinking this is where the Try part comes in
Weird that you have a custom exception there
I said to do it one tick later 😄
why
You should probably avoid that
Because exceptions are slow, and are meant for unexpected issues
Use a simple null check
it's there because Alcohol is gonna be available for other plugins to use
Or an optional
trying to make it user friendly
exceptions don't make code more user friendly
anyways if you really wanted to use an exception you should choose a better name
a simple illegalStateException should be good since the persistent data missing would be an illegalstate
or a wrapper of it
you shouldn't use exceptions to control the code flow. instead of throwing and catching your own exceptions, you should only use exceptions for "unexpected" situations. you should instead just check if your PersistentData is present or not, and if not, don't run your code in the first place
it's not a big deal imho though
but yeah if you CAN easily avoid try/catch, you should probably avoid it
you know it's like having a safety net under a bridge
it'll prevent you from dying when jumping off the bridge
but it's better to just not jump off any bridges in the first place
you know? 😄 I think that's a good comparison
exactly, it's useful for accidently falling down but that doesn't mean you should force having to use the safety net
Why does this not save the now modified config to disk?
Great, now I have to write a new post again...
what is "data"?
a FileConfiguration
but sometimes you might want to when you are bungee jumping 🙂
hm yes else no fun
it should save it. any errors?
no nothing
just FYI you should NEVER hardcode "/" as directory separator
i don't think a developer would agree that a code throwing exceptions would be fun
yea
you sure you are saving to the right folder?
yes, the file appears correctly
damnit there's another problem with this
good to know, just went wondering why it works as I am on windows
it's possible to quickly switch items just as you consume the drink
you're meant to use the constant in the File class aren't you
sometimes, java will add it to the filename though
this could be dangerous because if you drink the potion and immediately switch to a valueable item in your hotbar
it'll be replaced
But that still doesn't solve the issue that the config file does not save any changes
are you certain that the file config instance is the same one you think it is?
yes
when i make a custom death message, the player's name is red despite me doing "ChatColor.WHITE"
depends on the filesystem, used JRE, etc etc
I would never trust it
Hence why I said modern
it should be removed lol
even if it will work in 99% of cases, there is no reason to try your luck
a better line of code to get your file, instead of the way you have it
is this
File(plugin.getDataFolder(), "data.yml");
notice I used a comma
Files should always be used either using
new File(pathFile, "child.yml");
or
new File("path" + File.separator() + "child.yml");
this will automatically add a path separator for the file
Well I can correctly read stuff from that file. It is simply not displaying it correctly
Not entirely sure if that is your problem or not, however as I stated sometimes java will in fact put / as the filename the way you are doing it
Probably should input customConfigFile for Save()'s parameter.
Or include the data folder path with "data.yml"
"It is simply not displaying it correctly" ??
oh you need to reload your config instance
so when you call save, call load
it should refresh the instance
It's trying to save to wrong location
thats not it, it isnt saving properly, the file itself if viewed exterrnally isnt
well the only thing I can think of is the way are specifying the file
So I save it like this now the first time?
if does not exist?
I guess you can go with that, but you could just use a comma after getDataFolder()
yes
File(plugin.getDataFolder(), "data.yml").exists;
you should also change it for your save method and load methods
player name on death messages is always red, despite me prefixing it with "ChatColor.WHITE". Any suggestions?
Are you using getDisplayName
yessir
use getName for a raw name
oh ok
Or strip colors if you want to use display names
the way you are saving is fine, just use similar file params we showed you for the save method
?
ChatColor.stripColor
this way / doesn't get added to the actual filename
ok
no one? :(
No
How would I get a ui then without people just renaming a chest to smth
also - wtf
Cause I wanna add protection
why does it do that
When you openInventory it returns an inventory view
Use that to identify your custom inv
you need to call toString() to save UUID's as strings
UUID.toString()
ty
the way I coded that makes it hard to do that lol
Normally you just add the view to a set
And then check contains() on that set in inventory events
and then when you go to load a UUID, you can use UUID.fromString(string_here)
and that should get you back a proper UUID object from the uuid string 😛
can someone help me how to get the server to safe entities which are inheriting a super entity like the Skeleton upon shutdown?
so its loaded correctly
because like custom AI behavior where pathfinding goals are overriden obv dont make it past restart
since its in RAM only
How do I get the name of an itemstack?
the displayname*
.getItemMeta().getDisplayName()?
ok good im not going crazy
that wont matter for my context but ty
how can a item name be null
oh ye
Hi! I now make a BungeeCord plugin, but when I try to load the config, I got this error. Can anyone help me?
i cant even read it
so any help for me with custom entities?
wait a minute
what you need?
@ivory sleet are you familiar with google guice?
- I want to create custom entities
- I inherit a superclass like the Zombie as base
- I want to override pathfinding goals with custom written ones(can do dont need help)
- I need help with making the server save those to the harddrive in the world files on shutdown and be restored as it is, because by default it looses its inheriting class and is being saved as vanilla entity rather than the custom one
why code block
because i used line breaks alot and discord tends to send the msg too early
if u press enter
basically anything you inherit returns to its vanilla counterpart as soon as u shutdown the server
declare it global and define it onEnable first thing
so u can wrap the try catch clause around it
the super constructor expects the instance to handle exceptions
which u cant do in global scopes
alternatively put the whole thing in
static
{
//...
}
doesnt really change anything functionally since plugins are merely callbacks anyway
So what exactly are you having issues with
Just extend the Zombie class and start adding Pathfinders
Then save the custom type in PDC or something
And when the entity is loaded, if the custom type is in their PDC, respawn them with the new custom type
?pdc if you dont know
A bit janky but yeah that works
thy
In the past I think you could make their custom type save if you loaded your plugin and startup and a bunch of stuff
Don’t think it ever worked for me
Maybe we’ll get data driven entities next :p
hmm
That'd be great
u mean destroy the existing vanilla instance and re-instantiate it as its custom variant?
Pretty much yep
Hmmm
Although I would definitely try to do whatever Coll is talking about first.
That seems like a much better approach if you can figure out how it's done.
I don’t think entities that already exist fire any event when they are loaded
Could be wrong
elaborate? 😛
sorry, i dont remember
Player p = event.getPlayer()
p is object? if no, what is object
Make your plugin load: STARTUP and register your entities in onLoad
Might work, no idea haven’t done it in a while
p is referring to a player object
well im mostly busy writing auxillary functions rn(putting everything into a master plugin and accessing it via reflection) XD which is what i get alot of hate for from the java community
so yes
Yes p is an object
Of type player
You don't have to register entities at all
how can i load custom entities then
You don’t have to inject them into stuff anymore? That’s nice
tried that before the problem is that every entity gets stored in a binary file and custom classes are ignored. if i have a class BossZombie extends EntityZombie, it gets stored as EntityZombie not as BossZombie
I mean normal entities that are used by nms works fine without being registered
At least for me ^^
Ah, yeah then it probably isn’t going to work
and i mean
i inherit existing entities and override the pathfinder goals with my own ones
true, that's why i delete all of them on disable
to create a boss AI for the giant
PDC it is then 
well not much to override since its empty but still xD
Lol maybe we need 2Hex to extend his EntitySerializer to support Custom entities
doesnt work because my provider has a custom API which actually manages it on reload, they make a backup on shutdown and it has priority
so my destroy on shutdown gets ignored
basically
I wrote a blog post about why you shouldn't use exceptions in this case: https://blog.jeff-media.com/dont-jump-off-bridges-or-why-you-shouldnt-use-exceptions-to-control-code-flow/
by the backup method
hmm
it's pretty non-technical but I guess it explains what exceptions are actually meant for
^^
I'd elect PDC if I could
That’ll probably be useful
PDC would do a great prime minister / president / whatever is electable in any country
thx
It's definitely got my vote
I don't know what about the three first things, but you can use the saver / loader in a file using this https://github.com/ThisKarolGajda/OpPets/blob/oppets/OpPetsPlugin/src/main/java/me/opkarol/oppets/files/FileManager.java
I wonder if that's called when /reload is ran 
That'd be great if it was lol
Doubt it
Why would you even run /reload
what if i use custom nms tags and on entity load i check for it having custom nms tags and then serialize, destroy existing entity and create new instance of custom entity inheriting the serialized object
Like what the hell bru
Reload doesn’t reload chunks
That’s what we said
well
Pdc is just NBT without the NMS
isnt that resource heavy?
No?
weeeeeell kinda
okay so the entitiesload event is an alternative to letting the server handle it with vanilla methods
btw because someone mentioned it before, id also need custom textures without overriding the vanilla entities texture if possible
and if possible without armor stands
Well you can make them invisible and place an item on their head
Said item having a 3D model
That only works for mobs that display helmets though
No-
I think there’s a program for that
Why am I lagging
AnimatedJava or something
so basically custom skin easy
with item thats undroppable and head worn
animation not
Pretty much
and the item has a custom model data is suppose
Yes
i can tell u it is 100% not because entities survive /reload (the custom entity thing)
and if the entity was reloaded on /reload it would turn vanilla
public class InvClickEvent implements Listener {
@EventHandler
public void clickEvent(InventoryClickEvent event){
Inventory inv = event.getClickedInventory();
if(inv != null){
Player p = (Player) event.getWhoClicked();
String title = p.getOpenInventory().getTitle();
if(title.equals(ChatColor.DARK_RED + "Challenges")) {
Material itemType = event.getCurrentItem().getType();
This seems a bit risky.
Any way I can make this not risky?
cause if somebody renames to a chest then
.e
whats risky about that
Didn’t I say to use inventoryView and a set
I cant here
Like at all
I tried that lol
Then you have design issues
Rename a chest to the title and they can interact w/ it like its the correct gui
well.. I get my ui by doing this:
Challenges.getUi(p);
for example
so idk
that
put custom nms tags on it
i did that with obsidian tools
where ive created new items server side only
How do I make that?
uff
NMS tags
What kind of tag should I use for an array of compound tags?
means u have to update ur plugin with every version chance
wait
?
Well thats not all that helpful lol
?pdc
I'm just messing around with NMS without APIs atm
something like that
Arent PDC's unable to be used on UI?
inventory guis
ItemStack itemNMS = CraftItemStack.asNMSCopy(inv.getItem(i));
NBTTagCompound itemCompound = (itemNMS.hasTag()) ? itemNMS.getTag() : new NBTTagCompound();
itemCompound.setInt("custom.Durability", (250 - itemNMS.getDamage()) * 6);
itemNMS.setTag(itemCompound);
inv.setItem(i, CraftItemStack.asBukkitCopy(itemNMS));
its just a snipped from a super old project which ill rewrite soon
well
save your created inventories in a list, hashmap etc
then compare them using ==
instead of comparing the title
@tender shard are you familiar with google guice?
the real uglyness comes from this
import net.minecraft.server.v1_16_R3.ItemStack;
import net.minecraft.server.v1_16_R3.NBTTagCompound;
ugh why do you need NBT in 1.16?
means u MUST always update ur plugin every server version
PDC exists since 1.14.1
?pdc
and i didnt know about pdc
That one isn’t
I have this
public CustomPotion(String name, int color, int effectId, int effectDuration, int effectAmplifier) {
item = Items.POTION.getDefaultInstance();
CompoundTag effectsTag = new CompoundTag();
CompoundTag effectTag = new CompoundTag();
effectTag.put("id", IntTag.valueOf(effectId));
effectTag.put("amplifier", IntTag.valueOf(effectAmplifier));
effectTag.put("duration", IntTag.valueOf(effectDuration));
effectsTag.put("", effectTag);
CompoundTag displayTag = new CompoundTag();
displayTag.put("name", StringTag.valueOf("Potion of " + name));
CompoundTag nbtData = new CompoundTag();
nbtData.put(PotionUtils.TAG_CUSTOM_POTION_COLOR, IntTag.valueOf(color));
nbtData.put(PotionUtils.TAG_CUSTOM_POTION_EFFECTS, effectsTag);
nbtData.put("display", displayTag);
item.setTag(nbtData);
}
But the NBT it creates looks like this
{id: "minecraft:potion", tag: {display: {name: "Potion of Haste"}, CustomPotionColor: 15724066, CustomPotionEffects: {"": {id: 3, duration: 3600, amplifier: 1}}}, Count: 1b}
When it should look like this
{id: "minecraft:potion", tag: {CustomPotionColor: 16777215, CustomPotionEffects: [{ShowParticles: 1b, Id: 9b, Duration: 100, ShowIcon: 1b, Amplifier: 0b, Ambient: 0b}], Potion: "minecraft:water"}, Count: 1b} (Notice the array inside CustomPotionEffects)
I'm just not sure what the type would be for an array of CompoundTags
btw would you say its like acceptable to outsource methods used by many of my plugins into a master plugin and access them via reflection rather than implementing it in every individual plugin?
makes updating indiviual methods easier
Oh I'm stupid I think ListTag would be applicable lmfao
Land Plot Math
Is there anyway to check if the player is in water specificaly? I know there's such thing as .isLiquid(), but that means lava to.
oh ok
is there a map that has 2 values for the same key? i'd need it to store islands, as i want to be able to get an island from the owner and from the location
That sounds more like 2 keys with the same value
maybe a hashmap with the value being a set or a list or something?
yea basically
where key is player and values are the islands
it would make the queries even harder to make
why not just store the island's location with the island?
Because then you can’t get the island from location
Well you can with ugly loops, but that’s not efficient
#getValues()
then find the island with the location
Armor stand
how about making a class with attributes for both values you want to store and then store those objects in a map?
wdym armor stand
I'd rather find an island's location in O(n) async than use double the memory while a server's up personally
It’s not double the memory
Well I guess it is, but it’s double a tiny amount of memory
i thought of making a map implementation or similar myself
the O(n) is temporary, the space complexity is forever
A reference is 4 bytes
on god
it's not that big since the object stored as a value is the same
help
since both map values will point to the same thing
Exactly
also i can't really query stuff async since i'll need to check if a player breaks stuff in an island they are not a member of
and canceling events async is kind of a nono
/kill @e[type=armor_stand,distance=..10]
Hmm so you don’t want a single location
ty, also when spawning on a chest, why does it spawn in the corner?
You want the entire island
do i have to place it 1 block above or
Add 0.5 to xyz
well you could also say that earlier
In that cast store a bounding box in the island instance
i have a class called islandLocation that you can get from a location
the islandLocation basically is a 2d location that stores a y int and a z int
So you can get that from a location
then there's a static nullable method that returns an IslandLocation from a Bukkit Location
Yeah just map that to an island then
since i know the size of the island and the distance between them its easy to math
It’s what, 16 bytes
with a very small complexity too
i have 2 ints inside so 8 unless the object takes a bit more
How did i do this exactly?
oh and i have some static constants but they are very negligible
Why ints
did u register ur command in plugin.yml
yes it works
only some people get that
and i have no clue how lmao
its like if some people have a working plugin, and others don't
@young knoll last question: how do I add multiple lines to the armor stands na,e?
More armor stands
it could even be a smaller datatype since islands are gonna be far apart but we live in 2022 so i cba