#help-development
1 messages · Page 1615 of 1
wait no this wont work
no
why not?
you do
PlayerData data = playerMap.get(player.getUniqueId());
oh your talking about what he said
and then you do data.cooldownMap.put("cooldownName", new CooldownData("cooldownName", time))
for which you probably want to create a method on the PlayerData class, something like playerData.addCooldown(name, time)
myes
are there any errors in console on load?
also wouldn't I want to do public Map<String, CooldownData> cooldownMap = new HashMap<>(); instead of public Map<String, Long> cooldownMap = new HashMap<>();
yes
of what? when?
Plugin does not work
I see the load confirmation using the onEnable() method, but the ones using other events don't work
I checked with /pl and the plugin is loaded
package dorokei.pyuagotto.dorokei;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Team;
import java.util.Objects;
public final class Dorokei extends JavaPlugin implements Listener {
@Override
public void onEnable() {
// Plugin startup logic
getLogger().info("てすとぷらぐいん");
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
//JoinEvent
@EventHandler
public void onPlayerJoin(PlayerJoinEvent p) {
//入ってきたプレイヤーを取得
//Player player = p.getPlayer();
//Team nameHide = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard().getTeam("nameHide");
//System.out.println(nameHide);
System.out.println("test");
//assert nameHide != null;
//nameHide.addEntry(player.getName());
}
@EventHandler
public void onDropEvent(PlayerDropItemEvent e) {
e.getPlayer().sendMessage("test");
}
}```
Where should I fix it?
Why am I doing ```java
data.cooldownMap.put(res.getString("Cooldown"), new CooldownData(res.getString("Cooldown"), res.getLong("Time")));
when I can dojava
data.cooldownMap.put(res.getString("Cooldown"), res.getLong("Time"));```
because you for some reason went and made a CooldownData class even though I said it'd be fine to just have a Map<String, Long>
which is fine
but now you need to create a new instance of it, instead of just putting a long in a map
@plain oxide you haven't registered your listener
Bukkit.getPluginManager().registerEvents()
Didn't you say to make a new class?
i said if cooldowns had more data than just a single long, you'd have to make a new class
I forgot it. thanks
are you loading the data yet
yeah
I did that already
I made it so when the player joins their data gets put into the map
then you are done
oh shit it was that simple
the next step would be to do the reverse of what we did now
that is, to read the data from the object oriented model and save it in the db
Yeah that's what I did
so your server doesn't shit bricks when a bunch of players join and you need to run to the db 20 times doing random queries
if you wanted the cooldown time for ender pearls, you'd do data.cooldownMap.get("ender pearls")
if i remove the plugin chunk ticket, the chunk will be unloaded instantly in that same tick?
can anyone give me a eclipse setup?
setup eclipse for what
so would it be what it's named in the db?
I want to start coding spigot plugins
is there a way to run certain code when a message in chat is clicked or at least run multiple commands?
nvm that's a bit annoying but ok
does ProjectileSource#launchProjectile call ProjectileLaunchEvent?
seems like it doesn't, I'll test
how can i do to push player upwards?
Set their Y velocity
hey, i seem to be getting the error [23:04:17] [Server thread/ERROR]: Could not pass event BlockBreakEvent to FallingFalling v1.0.0, and org.bukkit.event.EventException: null are there any common causes for this?
?paste
?
@waxen locust Post your code in it
Can you post the full error?
sure
wait
i think i see it
nvm
just an error in my logic so an Interger object is null and is causing problems
it does
I get this error but it gives me no class written by me, only spigot classes...
I'm modifying someone's command, and only this command does it
no other command does it
Send the full error
it is the full error
There's nothing under the Caused by: java.lang.ArrayIndexOutOfBoundsException?
idk, its really weird
?paste
Send the command code
?stacktraces
https://paste.md-5.net/kefesulige.java line 136 is my command
it would be "/dac stats" the full command
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Check that out
I did... normally it gives me my exact line in my own class where the error was caused
but here its NMS and other stuff
but no class of my plugin
that class is a fucking mess
Bro split your code up
holy hell
not my code
then why are you here
I would but not that much time with college coming soon
Also not much reason making all those vars final
this plugin is just a mess
from what I've learn you should try to put your variables that you won't redifine final, makes it run a tiny bit faster
Yeah that change is gonna be negligible
you get a few ms, not noticeable but yeah
I doubt its that much honestly lol
It's not
maybe a few ns
Final has it's uses but I only tend to use it on stuff other people will interact with
^
Yeah I generally know my own code & what not to change
sorry for interrupting, I thought i had fixed the [23:04:17] [Server thread/ERROR]: Could not pass event BlockBreakEvent to FallingFalling v1.0.0 and org.bukkit.event.EventException: null error but apparently it still doesn't work. basically it runs fine the first time but when trying to update an existing score it breaks.
code: https://paste.md-5.net/akusaraxow.cs
error log: https://paste.md-5.net/fisehigowo.cs
relevant main class stuff: https://paste.md-5.net/tejebihejo.java (error is in the code pastebin so this shouldn't matter)
Can you send us the entire error
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "java.util.HashMap.get(Object)" is null
FallingBlockListener line 26
also please format your code better (your IDE can do it)
it's bad
ik will do soon, just moved a lot of stuff around so it all got messed up
CTRL + ALT + L is the keybind for code format in IntelliJ I think
I presume it's Eclipse
I don't think IntelliJ auto does the author and license things
Oh true
as for line 26 i have an if statement checking if the value is null. it seems to get past that if statement and crash on the next line due to being null
ref.blocksbroken and ref.kills are not the same thing
do me a favor
hey does anyone know of a way to hide an Entity from a specified player?
how to whitelist a people using spigot?
like if i want to whitelist : _Aslt
whitelist a player using commands
you could register a command, that when it gets a username input, it stores that username in the "whitelist.json" file. Then register an event that triggers when a player attempts to connect, that checks if that username is in the "whitelist.json" file, and if not then kick them. found an article that might help with the reading of the json file part : https://attacomsian.com/blog/java-read-write-json-files.
or just... /whitelist add _Aslt?
@light terrace
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
player.setWhitelisted(isWhitelisted);
no, i dont have op
packets
how to send title for a player?
declaration: package: org.bukkit.entity, interface: Player
player.sendTittle()
._.
this method is deprecated
if (!action.getPlayer().getInventory().contains(Material.AIR)){
action.getPlayer().closeInventory();
//action.getPlayer().sendMessage(ChatUtils.color("&f(&c!&f) &cYour inventory is full."));
action.getPlayer().sendTitle(null, ChatUtils.color("&cInventory Full"), 10, 30, 10);
}
why its not working :/
What programm u using
Eclipse, IntelliJ IDEA
IntelliJ IDEA
Do you have any errors in console
no
it closed the inventory but didnt show any title
Set tittle to "", idk it maybe don't work with null, but its strange
Subtitle requires a title iirc
I'm just really sleepy right now
didnt work
if (!action.getPlayer().getInventory().contains(Material.AIR)){
action.getPlayer().closeInventory();
action.getPlayer().sendMessage(ChatUtils.color("&f(&c!&f) &cYour inventory is full."));
action.getPlayer().sendTitle("", ChatUtils.color("&cInventory Full"), 10, 30, 10);
}
its sent the message
but not title
You need to have something in the title
You do
I have used it many times like his and everything worked
if (!action.getPlayer().getInventory().contains(Material.AIR)){
action.getPlayer().closeInventory();
action.getPlayer().sendTitle("title", ChatUtils.color("&cInventory Full"), 10, 30, 10);
action.getPlayer().sendMessage(ChatUtils.color("&f(&c!&f) &cYour inventory is full."));
}
ok now see ^^
umm yes
it worked now
Set in tittle " "
If you don't the tittle
it worked with " "
I remembered that I was getting a string from the configuration from the configuration, so everything worked even if it was empty✌️
I'm just reeally sleepy right now
thanks both of you for helping :>
;)
np
if (!action.getPlayer().getInventory().contains(new ItemStack(Material.AIR)))
this check wont work?
Use first empty instead
declaration: package: org.bukkit.inventory, interface: Inventory
ok
OfflinePlayer playerw = Bukkit.getOfflinePlayer("_Aslt");
playerw.setWhitelisted(isWhitelisted);
This shows an error
can i change the (isWhitelisted) to true?
yeah obv, since isWhitelist is just pseudo
you have to
?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.
how to unban someone (by name) using spigot library ?
@light terrace please look above and learn Java before you try to make a plugin.
Anyone know if theres an api for the spigot resources page (to get a list of plugins)
i learn a bit
Remove them from the ban list
how?
barely nothing obviously
Get the ban list
Remove them
A lot of these questions can be solved by just googling things
he will probably just come back every minute if he doesn’t learn basic Java
damn it the way I'm handling entity queries is stinky and I don't like it
do I really have to rewrite it
i just use java to make plugins
and? You need to know Java to make plugins.
i know
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.
fuck this I'm not going to rewrite it
feels good to see that I tried to spawn an entity 6800 times but it's using so little power to search for valid spawn locations that it's not even showing up in the timings
?paste
I have a question
I have a recursion with objects
as the recursion moves
do the player objects get duplicated?
In the memory
or any other objects for that matter
I mean assuming that's the general idea of what you're doing you're just passing along the same object so there's no duplication
you are not passing the object, you are passing the reference to the object.
Gee I wonder why my bossbars aren't showing up
1 hour later, oh I just happened to forget to assign a player
Is there a Chunk event before ChunkLoad?
Don't think so, what are you trying to do
how to delay a task by a set amount of time
?scheduling
How should I approach this? I'm trying to softdepend on protocollib and only performing the protocollib effects if it exist on the server, but I'm getting a NoClassDefFoundError even if this code is never reached.
https://gyazo.com/114a03792e12d9e149b5e7a9b14826f6
Looks like you're creating the variable outside of that hence the error
Oh, makes sense. Thanks! 😄
Does anyone knows how to set multiple killers
is there a nicer way of writing this statement instead of leaving empty curlies?
while (!queue.isEmpty() && !queue.poll().equals(stopper)) {}
because entityDeathEvent only catches someone who gets last hit
mention me if you know how to do that
guys do you think is it good idea to use Dependency Injection pattern in spigot?
i mean the automatically injection
Ah
It's generally not used in spigot
But stuff like Velocity (proxy) uses it a lot
i dont event know if its possible with java
but i do often use this approach with C#
It is possible with java
But IMO annotation processing is something I don't use much
do you have some paper how it work under the hood?
Because it needs reflections to work
It basically just obtains the constructor and calls it using reflections
Either that or it does some weird hack at compile-time
ye but how does Java knows when Constructor is triggered?
there is some reflection event onObjectCreated or sth?
Here's a framework that uses it
o thanks : )
It does some bytecode stuff to change classes I think
List<SimplePersistentEntity> list = persistentEntities.get(chunkLocation);
if (list == null) return;
list.forEach((simplePersistentEntity -> {
if (simplePersistentEntity.customBossEntity != null)
simplePersistentEntity.customBossEntity.chunkLoad();
else if (simplePersistentEntity.npcEntity != null)
simplePersistentEntity.npcEntity.chunkLoad();
}));
persistentEntities.removeAll(chunkLocation);
chunkLocations.remove(chunkLocation);
I'm sort of confused here, this is giving me a CME on list.forEach((simplePersistentEntity -> { , am I forgetting something here?
You're modifying the list while looping
Also for loops are better than Collection#forEach
#forEach is a modification?
that's the part I don't get
why is it erroring there specifically?
I know this isn't the best setup for the iterator, I was just trying to see exactly where it was messing up
Collection<Object> collection = ...;
for(Object object : collection) {
// Do stuff
collection.add(anotherObject);
}
This will throw a CME
Now
yeah but I am not doing that on that specific line am I
Let's say you're looping
And on another method that happens to be called at the same time
You're adding to the list
You get a CME
One thing you can do is clone the list
Another (which I believe will work but not 100% sure) is using the synchronized keyword
player.getInventory().addItem(new ItemStack(Material.BOW, 1).addUnsafeEnchantment(Enchantment.ARROW_KNOCKBACK, 1000));
sender.sendMessage("You Have Been Given a " + ChatColor.GREEN + "Punch 1000 Bow"));
Hello,
Im trying to add an enchantment for the bow but it gives me this error Cannot resolve method 'addItem(void)'
this is so weird
ItemStack#addUnsafeEnchantment is a void
I understand the underlying issue with a CME but I didn't think it would tell me it errors on the first line of the iterator
ItemStack item = ...;
item.addUnsafeEnchantment(...);
addItem(item);
works
You need to check where you're adding to the list
actually I wonder...
One amazing thing I used to do
Which made the garbage collector work extra hard
Was basically
for(Object obj : new ArrayList<>(list))
Which clones the list and loops through the clone
You won't have any CMEs on that
And you can modify the original list inside
But cloning a list temporarily isn't the best way to avoid CMEs honestly
Thank You
the iterator is the one that checks for modifications
basically, each collection has a modification counter in it
any modifications will bump the number up
the forEach call, and any other iterator like a for loop for that matter, will look at this modification counter at the start of every iteration
if the counter has changed, it throws an exception
this is why the forEach line is throwing the exception, and not the code that is actually causing the modification and the CME
^
why TF does this not work
I couldn't bother explaining
see that makes more sense, also this was never meant to modify the list as it iterated through it and it turns out I found a different bug
it's not there for the purposes of debugging why your collection is being modified, it's there to prevent unwanted behaviour
well... something somewhere that you're calling is modifying it
Do you register the player data?
as for what that is it's not super simple to find out
How do I get rid of this message? https://prnt.sc/1ic7dyb
but it's server.properties
show achevements
I am currently wrapping it up being it looks like the code I'm using to detect whether a chunk is loaded is not working correctly when it's checking for chunks that are mid-load event
thanks
which makes sense
https://prnt.sc/1ic7jhv can anyone help me ?
I guess
the whole "is a chunk loaded" deal has gotten more and more batshit over the years
I am genuinely rewriting everything due to that and entity spawns in loading chunks
it sucks, hard
mojang keeps changing how things work under the hood and bukkit, being the colossal clump of indextrous shit that it is, can't reflect that
as much as I hate it I think I'm going to have to run the code one tick later or smth
I really hate it
https://prnt.sc/1ic7jhv can anyone help me?
man it's either this or feed data to my chunk checker to let it know about chunks that aren't done loading yet
if (Tag.CROPS.isTagged(block.getType())
Code written other than Main.java does not work.
Do I need to draw any special code?
the 1.17 entity loading mechanics change has caused other issues as well
for example, now it's basically impossible to detect when mobs load into the world
as opposed to them being spawned
previously, you'd listen to chunk load event and get the entities in the chunk
but now, the entities aren't loaded in the chunk yet by the time the event fires
yeah this blows chunks
check intellij error description
well, yes, my answer went much later than I wanted, thank you dacha internet😒
if(Tag.CROPS.isTagged(type)) {
Ageable crop = (Ageable) block.getBlockData();
if (crop.getAge() == crop.getMaximumAge()) {
block.breakNaturally(playerTool);
block.setType(type);
crop.setAge(0);
block.setBlockData(crop);
}
}``` This should be correct.
imagine that the code works when you do it right
fml
now I'll get to find out whether entities are loading correctly with chunk loads on 1.17 when you do it manually or not
they should get loaded.
How would I know if a conversation is still active with the conversation api in spiot?
?paste
#getState should it be
stopping energy drinks cold turkey sucks
GetState cannot return null
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/conversations/Conversation.html#getState() -> @NotNull
declaration: package: org.bukkit.conversations, class: Conversation
the conversation api... 
when you need a series of text inputs
"what do you want this to be called" -> they reply
"what about this" -> they reply again
what would be the event of an activating totem of undying?
declaration: package: org.bukkit.event.entity, class: EntityResurrectEvent
if they have no totem = cancelled
thanks
ah
yeah its a pain doe
Hi! I wanted to know what the current version for BlockState#update(false) is. In the bottom of this post https://www.spigotmc.org/threads/blockstate-update-doing-nothing.322795/ BillyGalbreath explained that updating the copy does nothing anymore. How can I make sure a item hasn't changed when I want to apply the blockstate?
How do I make autocomplete?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Thank you
If you mean tab autocompletion then this example should help.
yeah I meant that
that site really needs a redesign lmao
Is there any easy way to get a player who resurrected ender dragon?
If there probably is no API for that I would just check who was the last player to place a ender crystal on a valid bedrock block to respawn the dragon. Then when the DragonBattle starts you simply do #hasBeenPreviouslyKilled() and that should be it.
not sure if there is a player statistic. otherwise save it yourself
Hey who can teach(or help) me to debug? my plugin playerEvent have error
The Plugin code: https://paste.md-5.net/oqumemufor.cs
The PlayerEvent Error: https://paste.md-5.net/igajamejiv.cs
https://prnt.sc/1icwkdc Thanks, should I add import for type?
type is the Material
Caused by: java.lang.IllegalArgumentException: Health must be between 0 and 20.0(25.0)
Already indicates you try to set player health to something over max health
at co2.rto.RTOPlus.Main.onPlayerJoin(Main.java:42) ~[RTOPlus.jar:?]
Shows you the error is in line 42
thanks you, let me try to edit that code
player.setHealth(NowHP + 5);
player.setMaxHealth(DefaultHealth + 5 * NowLevel);
``` edit to
player.setMaxHealth(DefaultHealth + 5 * NowLevel);
player.setHealth(NowHP + 5);
Shows me error
Learn java
One sec, imma read it to get context
yes
you need to make the max health higher before setting the health
Sorry I am a beginner @@
it is fine lol at least you didn't say "where is my error"
thanks you
you're welcome
since you have to probably go over the attribute
can anyone help me please
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply.
emm i have write lccording to player's level to edit player maxhealth
Code: https://paste.md-5.net/zexozoqoho.cs Version: 1.12.2
setMaxHealth is deprecated use attributes
Emm what attributes can set maxhealth?
i just know setMaxHealth @@
That would be the MAX_HEALTH attribute
declaration: package: org.bukkit.attribute, enum: Attribute
my API is 1.12.2 not 1.17
okay, and?
same?
emm how to use xd have example project?
i write final Attribute GENERIC_MAX_HEALTH; in line 35
.-.
declaration: package: org.bukkit.attribute, interface: Attributable
How much experience with Java do you have
emmm 3 month xd
Aight
oh thanks you maxhealth have change 🙂
?paste
?paste
Also you should avoid opening or closing the inventory in the event
Delay that until the next tick
okay
sorry did not know the order
Don't detect inventories by name either
is okey
Is there any way to achieve effect of "fear" (like creeper running away from cat, skeleton running away from dog) on other mobs?
In vault, when is Economy#createPlayerAccount(OfflinePlayer offlinePalyer) called?
It is an AI goal I believe
You need nms
Hello, I am coming to see you because I would like to make a patch for Spigot but I cannot find the sources. Can you clarify this for me? Thanks a lot !
depends on the economy plugin, but im blindly guessing PlayerJoinEvent
that's how you get $200
I’m working on an economy plugin, so I have to call that myself?
Thats bad 😦 Would not want to use NMS
If you're using paper they expose the AI in the API
Otherwise it has to be nms :/ idk why spigot hasn't added AI support yet
Its iirc inconsistent
Would be a whole lot nicer if it was registry based or something
Inconsistent by Mojang?
No but goals change from version to version
paper API could be a solution, thanks
Ah I see
Yeah I believe even paper doesn’t have a too rich api when it comes to the goals altho sufficient enough probably
Nvm it’s kinda good
just a paper hater smh
you cant be a specific hater if you hate everything
a
Does anyone knows how to set multiple killers, because entityDeathEvent only catches someone who gets last hit
big lines can cause some lag in java?
No
You can technically minimize all Java classes to 1 line wouldn’t do much of a difference
How can I remove this message?
Is there any examples of using Paper's AI api?
Is there a way to check if itemIn main hand is a block?
For me it looks like it is only possible if you create your own entity
I cant seem to find a way to obtain the ID,and the isBlock method does not exist anymore
Material might have the isBlock method
Yeah, it does
thx bro
Does #isgliding just check if the player is using an elytra?
yes
awesome ty
how can i do to add the player's inventory to an arraylist?
I already set an arraylist for the inventory type
i was trying this: inv.add(p.getInventory());
PlayerInventory#getContents
#addAll
it returns ItemStack[] but you can convert that to a List<ItemStack>
How can i auto ignite tnt on placement without removing it and making a TNTprimed
TNT#setUnstable?
oh is that what that is?
noun
noun: syntax
1.
the arrangement of words and phrases to create well-formed sentences in a language.
"the syntax of English"
a set of rules for or an analysis of the syntax of a language.
plural noun: syntaxes
"generative syntax"
the branch of linguistics that deals with syntax.
2.
the structure of statements in a computer language.
selfrole Add or remove a selfrole from yourself.
cleanup Base command for deleting messages.
embedset Commands for toggling embeds on or off.
info Shows info about CafeBabe.
licenseinfo Get info about Red's licenses.
mydata Commands which interact with the data CafeBabe has about...
set Commands for changing CafeBabe's settings.
uptime Shows CafeBabe's uptime.
findcog Find which cog a command comes from.
names Show previous names and nicknames of a member.
listcases List cases for the specified member.
reason Specify a reason for a modlog case.
permissions Command permission management tools.
There is no syntax command
i swear there is
Do you mean javadocs?
the bot is 🚮
?jd
How do i stop monsters targetting player?
A smart way could be to make player invisible only serverside
But some mobs (such as guardian) can still see invisible players
There is a target event iirc
Let me check
Yeah use EntityTargetLivingEntityEvent and cancel it
Sometimes it does not work
For example if i spawn creeper
I do not even see the event to be fired
But he still targets me
And even if i cancel this event
At some point it just doesn't get cancelled
is there a fall damage event?
thanks
How can i make EntityItem unpickable? which method (nms)
Why NMS
i would send packets to certain players
If it's packet items you don't need to do anything
are u sure? i can't pick them?
the client will attempt to pick it up but nothing will happen
the packets result would be only clientside. you can't pick something up, what is not there
?paste
use this
k'
how do i check if a player has custom armor equipped?
what version
Hi, who can help me ?
i want to place my players to array, but when i want to use it, i've errors
https://paste.md-5.net/silihunimu.cs
1.17.1
use the PDC
PDC?
persistentdatacontainer
so how would that work?
store a NSK in it and search for it whenever you are equipping armor
or whenever you wanna check if its a custom armor
but there is no equipping armor event
so how do you check that?
There's a lib you can use
trick a bit or make your own by listening for the playerinteract-, inventory Event
iirc there is already one
oh?
ah library
imagine if that event ever got pulled here from downstream
ew, how can i send packets in 1.17 nms? in 1.16.5 nms i use ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); but i cant use it in 1.17 :/
Player connection is b
That's all I remember
Yeah
ugh, what?
Reflection time 👏
it is public class :/ why i have this issue?
Make your life easier and use Protocollib
which could be a tp that have TeleportCause.UNKNOWN type?
If you get glitched through a block slightly when a block break is cancelled that will trigger Unknown iirc
And so do doors when their opening is cancelled
is there any other way out? 😬
only that?
im doing a /back command, should i care about unknown?
That's what I know of
Tbh I’d use NMS over protocollib for some cases
make the teleport cause list configurable and you don't need to care about anything
Because protocolib has some limitations
PacketWrapper makes Protocollib easy
too much work
literally just like 4 method calls
^^
eh, I tried, I had a few bugs, for example spawning a magmacube spawned me a pillager: /
What
its old, but i have this
someone just recommended it to me and I tried, but failed, I tried ordinary nms and so far I stayed
Oh well you might not get support from here
NMS is undocummented and generally unsupported
if i get the player location inside the PlayerTeleportEvent, ill get the old location? or the new one? if i get the new one, how can i get the old location previous to the tp?
That's just packet info not really docummentation of the code
use getFrom and getTo
the behaviour of Player::getLocation is undefined during a move event
thanks
There were some issues regarding how it affects the saturation of the pipeline and adds too much to it
For example heavy processes requiring a ton of packets to be sent to users may suffer if ProtocalLib is used, so some people switched to NMS
To optimize packets
Yeah that's what you do when you know how things work
Not when you need to get spoonfed NMS code
muh pocket performance
There is some option to set default Lore color to White instead of Purple?
Prefixify &f for every line
meh i thought there is some option to avoid loop ;/
That loop isn’t probably going to hurt performance the slightest
If it does you might wanna do the string operations async and then callback bit that has some latency on its own
What
Well ofc every method call is overhead
But point is, if string operations are too heavy then that might slow down server thread thus lag spikes
Arrays.asList returns an inmutable list or a mutable one? what about List.of? which one is mutable?
declaring a callback is negligible and even more negligible than that
It’s a fixed size list
Arrays::asList
List::of is an immutable one
is there any way i can declare a normal list, mutable, dynamic size, etc, but inserting an item automatically?
like Arrays.asList(x) but mutable and dynamic size
Lists.newArrayList(vararg)
new ArrayList(x)
ok thx
can i do that??
Depends what your original data format is
@ivory sleet is there some fancy lamda for this kind of operation?
Probably description.stream().map(s -> ChatColor.WHITE + s).something
Yeah ^
Does InventoryMoveItemEvent not work for players?
But it’s not worth using consider the overhead
right
Maybe if you’re writing an enterprise app ¯_(ツ)_/¯
Agreed. It's syntaxic sugar.
just write an util that does it tbh
Yeah
pretty sure like google's collections libraries have utils that do similar things too so you don't even need to write it
If not then Apache got it
im saving the teleport history of each player using the PlayerTeleportEvent event, but i want to be able to teleport players from this plugin, without modifying that history, how could i know, inside the teleport event, that the tp was made by the plugin itself? is there any way to get the plugin that teleported the player? i can do e.getCause and know that it was a plugin, but not which plugin, or can i?
Can you make a custom cause? Idk if it's supported
That would be the most proper way
Otherwise you'd have to set some flag and do it in a wishy-washy manner
can i specify the cause when doing player.teleport?
Or, if the event fires instantly when you call teleport, pop the latest tp from your stack
in that case, i could set the cause to unknown, bc im only listening to command and plugin causes
So have:
player.teleport()
teleports.pop()
i assume plugin is the default, and i can overwrite it, right?
The params should show you if you can do so
yea i thought about that, but im adding 2 locations sometimes, so, it would be a lot more complicated than that, specifying a teleport cause sounds like the proper way
Yeah thing is idk if you can do custom causes so in the case that you can't you'd have to do the other way
yes you can https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Entity.html#teleport(org.bukkit.entity.Entity)
declaration: package: org.bukkit.entity, interface: Entity
yea, ill do that, thanks
Is it better to shade custom Java annotations (E.G., Jetbrains annotations), or to use Spigot's bundled JavaX annotations?
you generally don't need to shade such annotations
annotations are a little strange in that their classes aren't actually required to be present in the runtime
oh
well whoops
that contradicts something what i learned earlier from here
guess that i will remove them from shading for several pom.xml files
if you're reflectively looking at the annotations at runtime, then you need the classes
but you probably aren't reflectively looking at things like @Nullable or @NotNull and whatever
Yeah usually they aren’t even kept at runtime
as a half-related question, what about adding their javadoc urls to the javadoc plugin's links
does that do anything
do annotations what function similarly to javax just become converted to javax at compilation or something
to make things simpler
man, i need to look up more about annotations
Does this mean that they do not even need to have the compile scope in Maven?
Would some one explain what is https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/enchantments/Enchantment.html#getItemTarget() and how it relates to https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/enchantments/Enchantment.html#canEnchantItem(org.bukkit.inventory.ItemStack)
declaration: package: org.bukkit.enchantments, class: Enchantment
getItemTarget return an a group of items that can be enchanted and canEnchant check a specific items if it meets all requirements to be enchanted
I create scoreboard, but how can i add player on team with command ?
So if in custom enchants which override the canEnchantItem, getItemTarget returns null (Which must not be null) would not cause isuue?
Yeah it would cause issues
I need to get offline players names often, but dosent Bukkit.getOfflinePlayer(UUID) have a limit since its accessing an api?
It literally doesn’t
It might since it can fetch data from Mojang
Yeah well Server#getOfflinePlayer(uuid) will never
Maybe methods on the OfflinePlayer will
Ah only name one does?
Oh ok thanks
Does something like Swing need to be shaded/have the compile scope?
If you are going to use it, yes
so both
It’s default set to compile
should i shade it, though
how i can create a custom config yml?
have you tried googling
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
How can i find player on scoreboard team ?
I started making a plugin that uses bundles, but I noticed I can't craft one. Can I craft it in 1.17?
Wiki says that it is experimental and not enabled by default.
oh, that sucks, but I quess I could add the recipe myself 😅
it says that it can be enabled with a data pack
but it can probably be enabled by a plugin too, somehow
or, at least, simulated
yes, probably will do so
i want to create a custom items system should i use JSON to save the data for each item or something else?
after my inventory is closed, should i somehow dispose of the listener? are there any performance problems?
it's created and shown whenever a player runs a command
You can keep the Listener running. Otherwise you're going to have to unregister and re-register it everytime the command runs, keep track if any inventories are open... etc, it's more of a pain to do & it really shouldn't make a performance difference anyways
Cause the first thing you check I assume is if they clicked within that Inventory I assume? So it's only doing 1 thing
unregistering and registering listeners is significantly more expensive than a simple check against a boolean or a set or whatever in the event handler itself
I think you can use PDC with an Item's Meta, so if you're looking for persistent storage for a "custom item", you should probably use that
every time event handler registrations are changed, the underlying arrays need to be rebaked
PDC?
thank you i will look into it
hi guys, im trying to make a subcommand to handle tabcompletions, how could i do that? i have a tab completion for the main command but i also want it for the "admin" subcommand, how could i achieve this? this is my current class. https://hastebin.com/cotoviligi.java ( Command Manager, also Main command )
I have something horrible I wrote some time ago if you’re interested
Check if args[0] is "admin", then return copyPartialMatches(args[1], <sub commands for admin>, new ArrayList<>())
thank you very much
https://github.com/NeptunMC/Casino I did this where every sub command handles the completion in case you’re interested, check command/nodes/admin/RollNode and ofc the manager classes
Don’t judge the code, was actually in a hurry when writing it lol
What are the hotbar item id's?
Like the slot ids?
yeah
0-8 I think
alright
69 (:
nice
Bundles do be experimental. I just found a glitch that kicks me when using a bundle lol.
hey, how do i change the amount of players online
not to like, fake having players on -- to do the opposite
to make it so that vanished players dont appear
Hello, I'm trying to create a Minecraft plugin but my onPlayerJoin event is not working. Like it's never seen by the server. Does someone know how to fix? I really appreciate
package com.test.pluginname.paladin;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin{
//VARIABLES
Server thisServer = null;
ConsoleCommandSender console = null;
//START AREA
@Override
public void onEnable()
{
thisServer = getServer();
console = thisServer.getConsoleSender();
console.sendMessage(ChatColor.WHITE+ "["+ChatColor.AQUA +"LastWords"+ChatColor.WHITE+"]"+ChatColor.GREEN+" Last Words has been enabled!" );
}
@Override
public void onDisable()
{
console.sendMessage(ChatColor.WHITE+ "["+ChatColor.AQUA +"LastWords"+ChatColor.WHITE+"]"+ChatColor.RED+" Last Words has been disabled!" );
}
//END START AREA+-
//EVENTS
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
console.sendMessage("Test" );
console.sendMessage("tfwefwefe: "+player.getUniqueId() +" test." );
getServer().getConsoleSender().sendRawMessage("raw");
player.sendMessage("TSTTSTST HI");
}
}
register the listener
Hi @valid crag , I tried this:
Bukkit.getPluginManager().registerEvents(this, this);
But it's not working
How can I register it?
it works fine
It says:
The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (Main, Main)
And it's an error
For the hotbar item clicks, PlayerInteractEvent would be the correct event for that correct? I haven't done a hotbar setup in a long time
implement Listener
how can I make an entity affect a player only it's in the FOV of the player? Should I use raytracing?
The UUID is unique only for the name or the minecraft account?
For example, if I change my Minecraft name, will I have the same UUID or another one?
same
the mc account
@formal warren your event handlers must be in a class which implements Listener
well, they don't "have" to, but they are pretty useless otherwise
hey i just made a server and i want to edit a plugin i got
i dont know anything about java
can someone help me
where can i ask for help regarding plugin creation
Do you want to create one or edit one?
edit one
You can ask about creating plugins here (after following the guides) but you probably won't get help with editing a plugin if you have no other experience in programming
You could ask the plugin developer to add the feature you want
to do plugin creation or editing plugins you first need to learn programming
i know basic stuff
which is beyond the scope of this channel
They should have a github page for suggestions and bug reports
but im having trouble sorting the files
Do you have the source code?
yeah
Do you have IntelliJ?
yeah
And you can edit the code in intellij right
this will end in tears
So then to export you just follow the tutorials on the spigot page
alright thanks
How can I get the console logs in real time?
append a log handler
Bukkit.getLogger.addHandler ?
I tried this but I my server crashed maybe I did something wrong.
Hello, is there a way to make an armorstand moving fluidly like a player instead of teleporting it block per block ?
depends on who's looking at it
hey, how do i change the amount of players online
not to like, fake having players on -- to do the opposite
to make it so that vanished players dont appear
hey guys
got a lil issue here
so im making a custom weapon where a trident beingg dropped will strike all nearby enemies
but its striking each enemy two times
show code
yes
?jd
wait no
hm?
if its PlayerInteractEvent then it's because its counting both hands
Java Coding Conventions: https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
my apologies
You didn't know 👀
@crimson scarab oh alsoo
ur code can be abused rly easily
with displaynames
players can change their stuff to anything with that display name and abuse ur plugin
even with the colours?
yeah
they can change colors
what is the alternative
does anybody have an idea on why the variable i is being counted to twice the amount before the scheduler ends
nope
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new zeusSceptre(), this);
getCommand("givecustomsword").setExecutor(new giveWeapon());
}
sorry again for the lack of conventions I was only aware of variables
I can't figure out why it's being called twice, are you sure it did?
sorry for the confusion, its not being called twice however, the bukkit runnable is ending at 2x more iterations than the amount of entites nearb
its running twice because you are counting ALL entities, then only applying damage and counting up for living ones.
so the first run doesn;t find enough
o
so do i need to change my entity list to exclude those i'm not targeting
actually only players, monsters and not dead, yet the count is ALL entities
and create a Collection, so you are not calling it twice
also u could replace the (entity instanceof Monster || entity instanceof Player) with checking if its not an animal
If you use teh Predicate you don;t need any other test
in an event or something?
ye
@EventHandler
public void Spruce(StructureGrowEvent e) {
for (BlockState b : e.getBlocks()) {
if (b.getType() == Material.PODZOL) {
b.setType(Material.AIR);
}
}
}
i thought of that
idk tho i havent tried it
Could just check if e.getSpecies() is a dark oak.
Well check for spruce then xD
declaration: package: org.bukkit, enum: TreeType
I checked that.
there is no TreeType.SPRUCE
it might be REDWOOD, I don't think so tho
REDWOOD or MEGA_REDWOOD
hm
If anything just debug it... plant saplings use bonemeal and check if e.isFromBonemeal()
Off that code above... you are removing the block that is turned to podzol... not stopping it from changing xD
Its not... You are removing a block
e.getBlocks().removeIf(b -> b.getType() == Material.PODZOL)
Adjust the code accordingly.
How do I reduce a player's knockback in 1.8.8?
Silly question maybe, but I've been pulling my hair out for an hour now. I need to get a constructor taking in a Class<?>[] reflectively, the question is how do I stick that Class<?>[] in the constructor. the compiler doesnt like any of:
Object.class.getClass.arrayType()Class<?>[].class(This is allowed forObject[].classthough?)Class.forName("java.lang.Class").arrayType()(On Windows this is fine, On Linux withopenjdk-16-jdk-headlessdoesn't like it)Class.class.arrayType()
Object.class.getConstructor(Class[].class)
quick question how to remove item from list java?
Why didnt I think of this T_T
you can further cast the Class[].class to a (Class<?>[])
im not sure how to use filter for nearbyentites
to get the exact type
class objects don't exist with type parameters because of type erasure
so Class[].class is equivalent to Class<?>[].class
Interestingly, with the type parameter isnt allowed
getNearByEntities(5,5,5).filter(e -> e instanceof Animal).collect(Collectors.toList())
Might need to change some of the code.
the distinction only exists at compile time
Still curious though that some things work on Win but not on linux lol
which is why you can cast a Class[].class to Class<?>[].class, but not create the latter directly
just use the Predicate
Not for me, Response to the message I replied to
on spigot 1.8.8,
how do i make it so that a player cannot attack any entities? is there something like player.setcantattack(true) idk
EntityDamageByEntityEvent and cancel it if its a player
also, does getNearbyEntities get all the entities within an ellipsoid of the player, or within a box of the player?
a sphere
Most likely a box based on this "Returns a list of entities within a bounding box centered around a Location."
Was a guess 🙂
could be wrong ig, none of my logic has ever really hinged on it being either
If you want it to be a circle you could just do it yourself
store them in a file
for after restarts
and when the server starts
restore the mobs
just like how MythicMobs,WildStacker etc plugins do
if it's a bounding box i'll just filter it
idk
look on ws's github
hey does anybody know the MC experience scale
is it like
(xp points / (their level * 2))
for xp adding/removign
so I see that Map#get takes a long meaning I can't use it under a string is there another way around this?
can somebody explain how to filter nearby entites i'm having issues
how do i check if a coordinate, is inside of an entities bounding box?
entity.getBoundingBox().contains(location.toVector())
omg ty
does location.toVector just give (x, y, z) or is it (x, z, y) bcz i know that most things use z as height, instead of y
alr
minecraft is pretty odd about its axes
i don't remember the details but y being used for the vertical axis is nonstandard
only the +-
so hey
ye mc is weird
how do i remove players from the online players counter with the ServerListPingEvent
I've not done any 3d for many years, other than MC so I've likely forgotten
oh yes, normally GL etc is z is into teh screen
I can get my self screwed up sometimes if im working with models and switch to mc and the axis's are diff lol
yeah in rendering and shit z is the depth
in most stuff it is
I totally forgot that
@EventHandler
public void OnDropTrident(PlayerDropItemEvent event) {
final int[] i = {0};
if (event.getItemDrop().getItemStack().getItemMeta().getDisplayName().equals(ChatColor.LIGHT_PURPLE + "Zeus's Sceptre")) {
event.setCancelled(true);
BukkitScheduler scheduler = plugin.getServer().getScheduler();
int size = event.getPlayer().getNearbyEntities(32, 32, 32).size();
List<Entity> entities = (List<Entity>) event.getPlayer().getNearbyEntities(32, 32, 32).stream().filter(Monster.class::isInstance);
for (Entity entity : entities){
BukkitTask task = new BukkitRunnable() {
public void run() {
if (size <= i[0]) {
cancel();
}
if ((entity instanceof Monster || entity instanceof Player) && !entity.isDead()) {
entity.getWorld().strikeLightning(entity.getLocation());
}
i[0]++;
System.out.println(size + " | " + i[0]);
}
}.runTaskTimer(plugin, 20L, 20L);
}
}
}
My error is
java.lang.ClassCastException: class java.util.stream.ReferencePipeline$2 cannot be cast to class java.util.List (java.util.stream.ReferencePipeline$2 and java.util.List are in module java.base of loader 'bootstrap')
I believe it resonates from line 8
That is way more complex than you need
You don;t need a counter
You only need getNearbyEntites with a Predicate to select which types
no filters
no streams
i googled and look through docs for predicate but couldn't understand it
Would you happen to know the JNI equivalent of java.lang.Class[]?
entities = event.getPlayer().getNearByEntities(32, 32, 32, e -> { e instanceof Monster});
and why do i not need a counter?