#help-development
1 messages · Page 858 of 1
dam
nice
wait but can you see my code for a sec i tried something https://paste.md-5.net/igitotanaf.cs
it doesnt really work as i want
if you find a error please let me know
what's the issue?
does it send the message "You respawned with your items"?
nope
then hasRequiredItems(player) is false
strange it shouldnt do that
i don't really understand what hasRequiredItems is supposed to do - you're checking the player's inventory contents inside that (even though the player will be dead, so the inventory will most likely be empty)
your code looks quite clean though and well commented, that's quite unusual to see here lol
I can't really read messy code and I don't really remember things later when I continue my work on the plugin so I comment it and make it look good. I thought everyone did that. (Also my some other developer friends see my code so I gotta impress them :D)
My code may look clean but it doesn't work half the time ;/
I'd probably do the whole thing like this:
- We need to identify our custom "keep on death" items using a PDC tag:
public final NamespacedKey soulboundKey = new NamespacedKey(this, "soulbound"); // tag to identify keep on deah items
public NamespacedKey getSoulboundKey() {
return this.soulboundKey;
}
// returns true if an item should be kept on death
public boolean isSoulbound(ItemMeta meta) {
return meta.getPersistentDataContainer().has(getSoulboundKey(), PersistentDataType.BYTE);
}
- In the death event, we have to loop over all items and store all those that have our custom tag in a list or map.
If you want to keep the exact slot, you'll have to iterate over the whole inventory and use a map <Integer,ItemStack> to remember the slot.
If you don't care about the slot, we can just iterate over getDrops()
// Save items for later
@EventHandler
public void onDeath(PlayerDeathEvent event) {
List<ItemStack> keptItems = new ArrayList<>();
event.getDrops().removeIf(item -> {
if(isSoulbound(item.getItemMeta()) { // Items with our custom PDC tag will be ...
keptItems.add(item); // ... kept on death ...
return true; // ... and removed from the death drops.
}
return false; // other items will not be removed from the death drops list
}
event.getPlayer().getPersistentDataContainer().set(soulboundKey, DataType.asList(DataType.ITEM_STACK), keptItems);
}
- in the respawn event, do the opposite: check if the player has our custom PDC tag, and if yes, get the list of itemstacks and add them back to their inventory (either by just adding it to the inventory if you used a list before, or by setting each slot manually if you've used a map before)
YOOOO
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
List<ItemStack> keptOnDeath = event.getPlayer().getPersistentDataContainer().getOrDefault(soulboundKey, DataType.asList(DataType.ITEM_STACK), new ArrayList<>();
for(ItemStack item : keptOnDeath) {
event.getPlayer().getInventory().addItem(item);
}
}
or when using a map:`
Map<Integer,ItemStack> keptOnDeath = ...getOrDefault(soulboundKey, DataType.asMap(DataType.INTEGER, DataType.ITEM_STACK), new HashMap<>());
for(Map.Entry<Integer, ItemStack> entry : keptOnDeath.entrySet()) {
Integer slot = entry.getKey();
ItemStack item = entry.getValue();
if(player.getInventory().getItem(slot) == null) // might also be AIR, check for that too {
player.getInventory().setItem(slot, item); // set back to the same slot
} else { // oh no, the original slot is meanwhile full, idk maybe other plugins also kept items on death or sth? who knows
player.getInventory().addItem(item); // so we just add it to any slot
thank you so much homiee
np
Any clue why the server thread dump thing appears occasionally when using setLore()? (assuming it is setLore() because of the dump)
Seems to have something to do with Regex and I assume colors?
Send a screenshot.
Your server is most likely running out of resources.
?paste GUIItem
will ask about the resources but it does quite more complex things without hanging up
like the setLore method?
Send the entire dump.
full class would be easier. or just that method and tell us which line is 42
also try whether it only happens on paper or on spigot too
https://paste.md-5.net/iquyojukak.cpp line 42 is this.lore = lore.toList()
Send both the full stacktrace and the class if possible.
class is not much bigger but has nothing to do with the failure
this.lore is setLore() from itemMeta.apply?
yes
basically it is
ItemMeta meta = itemStack.getItemMeta();
meta.setLore(lore.toList());
itemStack.setItemMeta(meta);
how does RegistryViewer look like?
also try using spigot and see if the same thing happens
https://paste.md-5.net/ezereraton.bash the stacktrace line is the setLore() and this is in a loop of items (no more than 15)
does this happen on spigot?
you are using paper, and having issues with paper, this is spigot discord, not paper
I will try in a sec, but I am unable to reproduce it
then it seems to be an issue with paper
well I am using spigot api and having issues with a spigot plugin on a paper server
wouldn't be the first time that something works on spigot but doesn't work on paper
Eh, in fairness, I have never had a plugin break when going from Spigot to PaperSpigot.
this is not relevant, at this point both paper and spigot are literally not the same
I had it happen about a dozen of times in 6 years
which isn't often, but it still sometimes happens
it certainly does in this case, paper makes me use Components (AdventureAPI) and I am using strings that's why I wanted to ask here
so before we spend hours trying to figure it out, it's better to just spend 10 minutes seeing if it also happens on spigot. because if not -> paper issue
anyways point is, unless you can reproduce the problem with spigot, you should be telling paper about the issue because there is nothing spigot can do when its another fork that is the cause
and also, I wanted to know if that is a known issue and/or if I am setting the lore wrongly in some way. Anyways I will try to reproduce on spigot in a moment, although I couldn't reproduce it in paper either
as far as I know, you are the only one right now having issues with lore in regards to spigot
on first glance, your code looks fine to me, and it's not a known issue
or should say, there hasn't been others reporting issues with spigot
in regards to lore
however, people have issues with paper and generally because they are under the belief that paper and spigot work the same
which they do not
then it might be a server resource issue or paper specific, will try
how can I iterate over all blocks in a world?
?xy
do you know how long this would take?
i need to find every block in a world with a specific material
In a render distance?
you are better off scanning the region files themselves
do you need them all at once or only when the respective chunks get loaded?
all at once
RIP then
Also, loded chunks only? Or should this method load unloaded chunks?
aka, ungenerated chunks
yeah no not those
You can if you generate it.
well can't get blocks from unloaded chunks as well
lol
moment the chunk loads it generates as well if it wasn't generated already
That is why I asked, I do not know how far he wishes to go with this.
i just want to get all the blocks that have a specific material in already generated chunks
I once did this in search of chests in an area of 10000x10000 and it was quite fast tbh. Using a large amount of threads. There might be better ways though
ill just set some corners manually ig
make sure the item has meta before checking
@tender shard
nvm it scrolled down all the way ffs
that'll still take forever
I'd recommend just reading the region files with auh
why are we storing attributemodifiers as both a map and a set? 🤔
thread pool
remap it
this is remapped
unless im looking in the wrong place
sec
i dont think it really matters regardless because looking at the code itself, attributemodifiers are both removed from both collections and added to both collections with their respective calls
so the values in c should match d
but ive been having painful ass bugs coming from here and i think its because somehow the map and set dont match
then it should have proper names though
not b, c, d
i mean i dont know how to see otherwise
this is the remapped jar
decompiled so i could see what goes on
would a premium player and a cracked player of the same name have a different uuid?
If it's an offline server then they shouldn't iirc
yes
on a cracked server?
if we are just purely talking about both joining an offline mode server with nothing modifying anything, then no both would have the same uuid and both wouldn't be able to connect if I recall
Yes
however, we don't support offline mode servers here either just fyi
what about a proxy?
Offline mode is poor people mode ig
no
not sure how a proxy changes anything
the only difference between a proxy and a full mc server is that a proxy handles connections and just supports the protocol and nothing beyond that
can you enchant an item with more than 255 level with addEnchant?
it was mojang limited after like 1.17
declaration: package: org.bukkit.inventory, class: ItemStack
already know this page
so you can't?
yep
if you could, why would we have this other method?
.
there is a reason unsafeEnchant method exists, and its so if you want to go beyond what the vanilla normally allows you can, but you have to use this method to do so
o
also this method doesn't guarantee that nothing bad will happen or that anything different would happen
Yes
A list of anything thats ConfigurationSerializable or primitive
how can i do that
like -name: yes
x: 678
y: 567
etc.
but I dunno how it can be done exactly
it depends which location is being used
blocks use ints, where as entities use floats
Why can't I place a block on x 3.471, y 8.5, z 8.109
lol
Wait, arent object lists supported?
FileConfiguration config = ...;
List<Location> locations = ...;
config.set("locations", locations);
FileConfiguration config = this.getConfig();
List<Location> locations = (List<Location>) config.getList("locations");
skill issue
Sounds like they should be
since yaml is a superset of json, yes but you would need to serialize the object
Which object, and why would i need to serialize it myself?
you don't need to serialize it yourself, pretty sure bukkit has methods to serialize them?

Location is ConfigurationSerializable, which means the Codec of FileConfiguration serializes it automatically.
Or am i missing something here
Well if its automatic, then awesome, either way it has to be serialized is all I am saying lol
lol indeed
what's the event i need to cancel if i don't want the player to open barrels/furnaces/etc...? is it PlayerInventoryOpen?
PlayerInteractEvent with a check if it was a right click and if the BlockState is an instance of BlockInventoryHolder
alright
also keep in mind roman numerals dont go past 10
according to minecraft
i know i use the flag to hide enchant
you can enchant an item past 255 afaik
like there were 32k swords i think they were called
all enchant at level 32k
not in 1.20
i also try
/give @p diamond_sword{Enchantments:[{id:"sharpness",lvl:10000}]} 1
block at level 255
ah shucks
if you want those enchantments you'll have to make them custom as a whole then
wait how to add and remove something from the list?
Load the list, remove an element, write the list back to the config.
But you shouldnt constantly access your configs.
For server scoped data:
- Load when server starts
- Save when server stops
For player scoped data: - Load when player joins
- Save when player quits
And load it into proper classes with meaningful names.
Dont constantly access config files.
what if i have configure command that writes the config file?
That is a different case. Having a command to explicitly edit your configuration is fine.
I personally always load my general config data into classes and only work with the classes on runtime.
Working with FileConfigurations is so error prone.
okay thanks
you want a command to modify the configs?
no, like i did that already
oh, well if you are interested in an alternative method for doing such things I can show you how I did mine 🙂
you can show me
seems I don't have the updated one where it asks about changing configs, but this is essentially the same just different data.
https://github.com/frostalf/ServerTutorial/blob/master/ServerTutorial/src/main/java/pw/hwk/tutorial/conversation/CreateTutorial.java
I make use of the Conversation API 🙂
i also mean stuff like grindstones, etc. some stuff like grindstones, anvils and more still work
thanks
Got that DataLoading.getDataLoading().getData() drip
Then check for a subset that suits you. Try if BlockState instanceof TileState
The project wasn't originally created by me. Since then I am the sole owner of the project though, however I haven't touched this project in a long while lmao
but it has some really good things in there though that makes it handy to reference, but yeah not a very good structure there for that 😛
happens in legacy code :p
eventually I will update this project
@eternal night could you tell me the difference between the 2?
in Anvilinventory, the .getResult() didn't work? or maybe i'm dumb
Anvil inventories are broken
they just didn't finish them
if you just open an invetory gui I'm pretty sure it won't work
On which occasion? Could you show some code? (Also which version)
that's why I switched to packets
hm ?
Velocity ConnectionManager
I'd wanna know what each of these channel initializers is responsible for
Get the result from the event. This event fires before an item is placed in the result slot so that you can change the outcome.
I mean one is the public facing server
the other the one that goes to the minecraft servers
I was guessing as much
i forget the event can get the result lol but thank you it work now 🙂
serverChannelInit is the one clients connect to
backend is the one that connects to the backends (the minecraft servers)
PS: Dont forget to use setResult(ItemStack) on the event instead of the inventory
thanks
Have a good one 👍
👍
Holy shit I just got deja-vu'd
is that how you spell that?
No idea
On e and a iirc
stupid french putting wéird stuff on àll letters
In russian we do that to indicate vowel stress lol
the proper word is GNOSTIC MEMORY ILLUSION
"I just got a déjà vu"
would be the correct form
so pretty much spot-on
sup
hello gnostic
I have a question regarding packets and NMS (surprise surprise). I spawn in fake players using packets, but later I try to change their equipment by directly accessing the NMS entity. However, when I try to set an item in the main hand of the entity, nothing seems to happen. Is this because I spawned in the entity using packets?
Oh and I cán change the equipment when I use the "Set entity equipment" packet
you'll have to use the packet yea
given the entity isn't in the server, the server does not tick it or update its state to other players
Alright, I'm new to the whole packets/NMS thing. Thanks
Sending a packet to update the equipment isn't an issue, but how do I check what equipment the entity holds? I can set the equipment, but not get it
given the entity does not exist beyond the scope of the plugin, only you can set the equipment ?
I was thinking of simply saving it to a variable after the package is sent so I can use it later, but it feels like bad practice
Wel if you do construct a nms instance of the entity, you can store it there ?
Fair enough. I'll do that. Thanks
uhhh?
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
if (plugin.getManager().getGameState() == GameState.WAITINGPLAYERS || plugin.getManager().getGameState() == GameState.WAITINGQUEUE) {
event.getDrops().clear();
event.getPlayer().spigot().respawn();
event.getPlayer().setGameMode(GameMode.SURVIVAL);
Location spectatorSpawn = plugin.getConfig().getLocation("blockwars.game.spectatorSpawn");
if (spectatorSpawn != null) {
event.getPlayer().teleport(spectatorSpawn);
}
} else {
event.getDrops().clear();
event.getPlayer().spigot().respawn();
event.getPlayer().setGameMode(GameMode.SPECTATOR);
Location spectatorSpawn = plugin.getConfig().getLocation("blockwars.game.spectatorSpawn");
if (spectatorSpawn != null) {
event.getPlayer().teleport(spectatorSpawn);
}
GameTeam playerTeam = plugin.getManager().getTeamFromPlayer(event.getPlayer());
if (playerTeam != null) {
if (playerTeam.getTeamBlock() != null) {
if (!playerTeam.getTeamBlock().getIsActive()) {
playerTeam.removeAlivePlayer(event.getPlayer());
} else {
runTimer(event.getPlayer());
}
}
}
i have a weird problem. I chache the loaded pages of the auction house in a hashmap and delete it on inventory close
problem is
every time i change the page
it fires inventory close
how would yall solve this
i8nventory death event can not be canceled
get entitydamageevent
check if damage > players hp
im not cancelling it tho
im just respawning
wdum respawning
if theres a playerdeathevent the player will die
no matter what you do
player.spigot.respawn
i want to make bedwars
thats the propper way
okay
what version
1.19.4
How do people handle npcs, that were spawned in using packets, when reloading the server? I use a wrapper class to add behaviour to my NPCs, but all of this information is lost when restarting
yea ik but the respawn button after clicking turns gray and stays like that for 5 or more minutes
and after i click again to respawn then it does the same again
add a delay
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
event.getEntity().spigot().respawn();
}
}, 1L);
i'll try doing the ondamage thing and i'll try that
I think player death is a better option
why would it be
As I said you have to add a delay between your respawn method call. I decompiled a plugin on spigot and it was doing the same thing
@tribal valve
wait lemme test my damage code first
its not. You literally solve all the problems by just simply not even fireing the deathevent
wait i just realised that cancelling the death of player can break other plugins
but i don't have other plugins so imma just test my code
After thinking about it, isn't all data thrown away after a reload? I'm using a wrapper class to add behaviour to my NPC, but after a reload it is all lost. How would you handle that then?
eh, well depends on what you are doing
given it isn't an actual entity in the world, just client state, you need to do basically all saving yourself
the damage plugin works, so imma just keep it that way but thanks mehran for help
gl
That would mean I have to serialize/deserialize the entire entity, correct?
Yea if you don't spawn it, the server won't take care of it
bro what 💀
is that PlayerDeathHandler line 81 ?
I can't be the first to have been facing this. Are there known best practices for this that you know of? All I can think of is saving the whole wrapper object into GSON, but I'm pretty sure the string would be too long to serialize/deserialize
ok where'd I mess up
actually wait, I can just check if the material name .endsWith DOOR
or just Tag.DOORS.isTagged(Material)
how to detect the lured fish?, is there any event for this?
I know its possible, i saw a couple server did it, also hypixel too
Hypixel has its own server software it can maintain and patch into
How would you know, it’s not like you work there
if (this.nibble > 0) {
--this.nibble;
if (this.nibble <= 0) {
this.timeUntilLured = 0;
this.timeUntilHooked = 0;
this.getEntityData().set(EntityFishingHook.DATA_BITING, false);
// CraftBukkit start
PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getPlayerOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
this.level().getCraftServer().getPluginManager().callEvent(playerFishEvent);
// CraftBukkit end
}
Yeah, doesn't look like we fire a PFE for nibbling
(which I assume is what that is)
Oh, wait, no, that's for successful attempts
declaration: package: org.bukkit.event.player, class: PlayerFishEvent, enum: State
Okay, yeah, timeUntilHooked. No event called there either
We definitely should call something there tbh
those are the available states for the event
I think the issue is just that each state is only ever called once, so to introduce a state that is called every tick would be abnormal
Maybe a separate event is in order to expose additional data like the angle
this event is called like 2-3 times
is there a bool in villagers to make them invournable to player attacks? or i must use entity damage event??
with different states tho
yeah with different states
With different states, yes. This user wants to check when the little dribble of water is approaching the bobber
There is only a setting to make them invulnerable to everything
yea that's what i meant
yea, i just want to show indicator over it
setInvulnerable
well its a particle
Maybe a new state for FISH_APPEARANCE and then a new, separate event for the actual movement
FishySwimEvent
that wouldn't make sense
Why not?
since its not an entity or one spawned in, the bubbles are just a particle
I understand that, but it's moving along a set of coordinates
EtherealFishySwimEvent
This user wants that exposed
FishLureEvent would make better sense
I'll write some shit for it. Seems easy enough
Should probably update the component PR while I'm at it today. I'm actually off lol
and yet still working
in the mean time you could create something that detects the bubble particles near the bobber
and from there make whatever it is you are trying to do
yep doing it now, thank you everyone for the help
Yeah, you'd need an outgoing packet listener for that
regardless it seems the only feasible way for them or reliable way to do whatever it is they are wanting
without an appropriate event to aide
is there an event that detects player rightclicking on an entity?
@young knoll I'm trying to set up the persisten data holder. But I think I'm doing something wrong https://paste.md-5.net/giqinaxumu.cs
Oh you are setting it in the explode event
Hmm, I am guessing the explode event is called after the damage event? not too sure
this would be weird if it does
Well they set in the explode event and check in the damage event
And it seems it is not present in the damage event
Hi, So I have i simple question. What is better between json or MySQL database for minecraft server. what is the difference between both ?
Well json is just a file format
MySQL is a relational database
It depends what you want to store
mysql is probably the better practice long term
Checkout the ExplosionPrimeEvent
json is a good way to store config files or similarly yk, but I wouldnt use it to actually store massive amounts of data
(altho spigot uses yaml :>)
maybe they should be using blockexplodeevent?
Nah, tnt is an entity
the explode events happen after the damage
the explosion logic first damages then break blocks
then which blocks is the blockexplodeevent for then?
Also world#createExplosion
Ok so if that just store Player data like kill,death, kit that they unlocked what better ?
Seems fit for sql
the damage event is for entity, not the blocks
okay ty

just really weird to apply damage to an entity before anything happened XD
I mean, you have the compute the damage to the entities first, before you remove blocks that might reduce the damage of the impact
sure you could compute first, store in some list, remove blocks then apply
but why xD (from a mojang perspective)
well both are executed simultaneously essentially, neither relies on the other
the entity damage does rely on the world state
which would be mutated by removing/breaking blocks
for every time the entity is damaged the event is thrown
indeed
point is, all the damage isn't applied all at once except for the initial explosion of course in however close they were to it
yea ? I am confused xD
The thing is that is not getting the persistent data
Yes, EntityExplodeEvent is called after the damage of the explosion has been applied already
use the ExplosionPrimeEvent
I change to that
👍
BlockExplosionPrimeEvent when
myea but depends on what reachability that temporary data has
i don't want to go to hypixel to test this, does anyone remember if you can open upgrades menu when clicking on the upgrades villager when on other team's island?

What's the word I'm looking for
The opposite of mutually-exclusive
Like intrinsicly tied together
Not correlated. There's another word I'm looking for God damn it 
Maybe is because I'm creating 2 NamespacedKey instances?
interdependent?
complementary or reciprocative?
Nah not quite. Meh. I'll just use "correlated" I guess. There's a math term I'm looking for but I can't put my finger on it
symbiotic 
Like I want to use "interchangeable" but that's not accurate
because they're not interchangeable, they're two different units
One just affects the other
reciprocal ?
That might be it
uncle-nephew-related
coupled?
Coupled is probably fine? I'll just use correlated because it's the closest to what I want I guess
gewoecht
I think the word(s) I'm looking for are actually "directly correlated"
is it possible to make YamlConfiguration to be saved in double quotes
like Banana: "This is Banana"
The analysis of reciprocal relations in categorical variables poses methodological challenges. Effects that go in opposite causal directions must be integrated into the same model, and parameters must be interpretable.

equivalent?
if and only if
Here,
/**
* Set the time (in ticks) until the fish will nibble at the fishing hook. The
* distance from the fishing rod and the time until the fish nibbles are directly
* correlated whereby an increase in the time until hooked will also increase the
* distance of the fish from the fishing hook, and the opposite also being true.
*
* @param ticks the ticks until the fish nibbles
*/
Choco is doing a thing
World#getHighestBlockAt() gets first Air at certain location?
It ignores air
you have to get the DumperOptions (I think you'll need reflection, it's private iirc) and then change the default scalar style
yea fair enough
then it'd be pretty pointless
Is the quote thing not exposed in the api?
last time I checked, no
looks like this
So what does it do then?
I only want values in "
?jd
Gets the highest non-empty (impassable) block at the given coordinates.
The docs say the same as i said 💀
you asked if getHighestBlockAt gives you the highest AIR block. And the answer to that is: no
I've asked if it get's first Air block at ceratin location
Not highest AIR block
what even is the "first" air block supposed to be? there can only be one block at any given location
World#getHighestBlockAt() gets first Air at certain location?
it doesn't get any air blocks, it gets the first non-air block
there is no first block at any given location
any given location has exactly one block
If you're asking if it gets the air block above the highest non-air block, then no
^
If the first solid block is grass, it will return that grass block
That's what i asked for
You can getRelative(BlockFace.UP) to get the air block above it
okay
I told you exactly the same
Gets the highest non-empty (impassable) block at the given coordinates.
tfw you run makePatches but you forgot something so you need to do it again
I do still sort of want to introduce a flag for makePatches to pass in a list of files you want to patch
I just fucking hate bash script
The persistent data is not working 😦
That would be nice
then you're doing sth wrong
yeah but I don't know what
Did you change to the prime event
Yes
?paste code
no no
Set the tag via ExplosionPrimeEvent
Then check it in EntityDamageByEntity / EntityExplodeEvent
okey
Can someone give this a run down to see if it makes any sense logically? https://paste.md-5.net/igivejayeh.java cc @molten kestrel because you had wanted an event like this
Is there no way to make a raw setLocation
Not really because the location is actually just relative to the fishing hook's position based on an angle and the time until the hook
So, yes, I can add a setLocation() but it won't move to that location on the next tick unless I calculate the angle change, which I kinda don't wanna do :)
I also don't know if the angle is calculated in radians or degrees by the way. I can't tell. I'm going to test it and find out lol, then I'll document it
https://paste.md-5.net/xetalokeva.java like this yeah?
What's the best way of getting highestGrassBlock, cause when i use World#getHighestBlockAt() when there's tree it returns me leaves/wood
Seems like a hot event on fishing servers - denied 🙅♂️
And what would be correct way of getting highest Grass Block
#uranerdlgtmly
It do be kinda hot
Time to delete player move event
It's certainly no PlayerMoveEvent though, that's for sure
Get the highest block at, then go down until you hit grass or world min height
Is it efficient?
EntityMoveEvent when!??
Looping through every block?
Every time I need to listen for entities moving I have to make packet listeners :/
reflection
Thats already how they work
yes
sth like this should work I guess
@Nullable
public static Block getHighestBlockAt(World world, int x, int z, Predicate<Block> predicate) {
int y = world.getHighestBlockYAt(x, z) + 1;
while(--y >= world.getMinHeight()) {
Block candidate = world.getBlockAt(x, y, z);
if(predicate.test(candidate)) {
return candidate;
}
}
return null;
}
@Nullable
public static Block getHighestGrassBlockAt(World world, int x, int z) {
return getHighestBlockAt(world, x, z, block -> block.getType() == Material.GRASS_BLOCK);
}
if (event.getRightClicked() instanceof Villager) {
GameTeam villagerTeam = null;
for (GameTeam team : plugin.getManager().getTeams()) {
if ((Villager) event.getRightClicked() == team.getTeamShopVillager() || (Villager) event.getRightClicked() == team.getTeamShopVillager()) {
villagerTeam = team;
break;
}
}
event.setCancelled(true);
if ((Villager) event.getRightClicked() == villagerTeam.getTeamUpgradesVillager()) {
showUpgradesGui(event.getPlayer(), villagerTeam);
} else if ((Villager) event.getRightClicked() == villagerTeam.getTeamShopVillager()) {
showShopGui(event.getPlayer(), villagerTeam);
}
}
``` why won't this cancel (the villager is waving his head) and why won't this show gui
okay thanks
What did you think they used?
magic
(idk mane)
im used to nodejs events where they just made an EventEmitter
i thought something similar would be possible in java
I'm sure it is
If the event system was made now I imagine it would be more lambda based
I have been blocked on spigotmc, idk why
I first time visit the site, and I be in block
Are you using a vpn?
No
What an eager fish
private int iterations = 0;
private final float change = 8F;
private final int maxIterations = NumberConversions.floor(360 / change);
@EventHandler
private void onFishLure(PlayerFishLureEvent event) {
if (event.getTimeUntilHooked() % 20 == 0 && iterations++ < maxIterations) {
float newAngle = (event.getAngleFromHook() + change);
event.setTimeUntilHooked(event.getTimeUntilHooked() + 1);
event.setAngleFromHook(newAngle);
return;
}
this.iterations = 0;
}
(it was in degrees by the way, not radians)
I wonder if there would be any performance impact if the event system was converted to use consumers rather than reflection
Realizing this event is a little bit backwards though. This event is called after the position change because it involves randomness
but there's really not much I can do to remedy that
The benefit would be you could do registerEvent(class, consumer<class>)
yea or artifically construct method handles w lambda meta factory
of the event handlers
Why call it registerEvent, call it on
That was my idea for the backwards compat
convert the java.lang.reflect.method stuff into a consumer via LambdaMetafactory
EventSomething.on(PlayerMoveEvent.class, (event) -> {...});
its possible to do that
with PluginManager#registerEvent alr
tho it takes an EventExecutor
not a Consumer :,)
I will ew you into the shadow realm
Is there a difference between having it as a Consumer vs a MethodHandle?
in terms of speed
mm
for instance unreflecting a java.lang.reflect.Method with methodhandles just wraps it around iirc
but if u construct it w lambda meta factory u basically get invokedynamic
I see
Huh, I thought that unreflecting would also get an invokedynamic
Or at the very least the reflection does not show up in the stacktrace
maybe it does in newer versions
but before they optimized reflection, it would basically have the same overhead as a normal reflective invocation had
I mean unreflecting makes only sense to get private members
What about functional interfaces
yea
Or rather said, consumer is an functional interface
so basically the same
it would be nice
there is a slight issue but I think it can be solved
and that is that it must implement Listener yk
so maybe if we have a custom functional interface
Cold elf, you are 20 mins too late it seems
Why gifs
isn't that what my event lambdas system does
I changed it a lil bit to support unregistering listeners in runtime :)
SubscribedListener listener = eventBus.subscribe(PlayerJoinEvent.class, (event) -> {
});
listener.unsubscribe();
type deal
is there a way to get the ping of a player
On modern versions there is getPing
But it's an average
im on 1.8
How does dispatchCommand work? Will it freeze my thread or whatever until it finishes or does it do things differently?
p much
Can I make my own command sender that will redirect sendMessage to some other place
is it OK if I like
event.setDamage(0) and set hearts manually to make my own damage system
I'm trying to do some nms stuff on every player apart from the one executing it but for some reason this code, ```for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
player.sendMessage(player + "\n" + onlinePlayer);
if (onlinePlayer == player) return;
try {
((CraftPlayer) onlinePlayer).getHandle().connection.send(new ClientboundSetEquipmentPacket(player.getEntityId(), airItem));
} catch (Exception e) {
throw new RuntimeException(e);
}
}``` only gets the player that executed it when there are others when done one account. But when I do it on the other, it does get all of them... WHY??
ohh
yes it work, ty
you mean protocollib?
ah
Maybe he is doing some spoofing
Player#sendEquipmentChange()
what do you mean?
btw, in regards to your dispatch command
I tried it with the spigot-api and it didn't want to work, I asked, and packets were how I was told to make it work
and it did eventually work
you don't need to use dispatch command as most times you can just invoke the command directly especially if its a command from another plugin
as command has an execute method
I'm making a little remote controlled thingy and I want to redirect the command output (sendMessage stuff) to that remote controlled thing
I also do need to dispatch it as I'm getting it as a string
getting it as a string?
declaration: package: org.bukkit.event.server, class: RemoteServerCommandEvent
you can send commands remotely without using dispatch
I don't use rcon
Fr
I have no idea how this event helps me at all
As I'm not even remotely using rcon
because you didn't know it could use it -.-
anyways no matter, many people re-invent the wheel without realizing the server already has something implemented lol
it isn't weird
And it's also lacking some functionality I need I'd guess
I'm not only executing commands
I wanna make it like give server info if you request
Ram usage, etc.
Also the player list
Can it?
yes
Well
I literally told you I will not use RCON
its implemented in the server, can be used for basically anything including commands
I'm making a little ws server (because I've been asked to) and it should be useable in stuff like djs bots and websites
and that means rcon is unusable how ?
while many people never heard of rcon, virtually almost everything supports it XD
lol
Well, besides that RCON also doesn't let me implement my own stuff like a plugin I wrote myself
I'm not almighty to change rcon, but I can always change my own thing
nothing needs changing in rcon
probably already compatible with what you have or 90% anyways
What does that even mean
basically rcon isn't anything complex, just have to send the packets in the appropriate format, which there isn't really much to it, and you send it to a different port
Can rcon send me data in json
if it fits in the payload
Oh and besides that, JUST LET ME MAKE THE FUCKING PLUGIN IF I ENJOY THAT
lol
man bro hates rcon for some reason
There isn't even a reason, I just do
Why should I like rcon
its simple and works and is already implemented in the server with events
the actual question why you shouldn't like it
to come into something with an open mind you need it to give you reasons not to use it, not the other way around
Well, atleast because rn it's preventing me from making a plugin I enjoy making
the only downside of it, is security, however that is fixed with a DB though where you can just pull the credentials that are changed for both ends
that's not a good reason, not being informed shouldn't be a reason for anger
No, why are you trying to prevent me from making a plugin I enjoy making
not sure how rcon prevents that
no one is stopping you simply giving you knowledge of a already existing tool
grow up
idk even know what system you are currently using
If there was no rcon I wouldn't be having this discussion rn
other then its something you created XD
I made a plugin to do something that rcon does? Okay, then why not let me do it. Why do you care?
If u want something fast and simple for sending and/or receiving data use Redis
Useless channel
I ultimately don't but if you like to re-invent the wheel for everything instead of learning that the server already had something then go for it I guess
I enjoy the process of doing that
also, not everything you make is the best either just remember that, not saying that everything in MC is the best either XD
Ehh
when it comes to protocols or rolling your own, real easy to slip in some security vulnerabilities or two
Lol
yes but all us needs experience creating own protocol for learning how to better use the existent ones. Because you know how they are internally
But as i said before if you wanna start with networking i would suggest reading about Redis protocol which is an in memory database
not quite true
first, there is two differing kinds of protocols
second you don't need redis to learn networking nor would I even recommend it for learning networking
anyways, back to the protocol. The first kind of protocol is the hardware protocol, well still technically software but easier to think of it like hardware to help keep it separate from the second kind, which is your software protocol. So the hardware ones being TCP, UDP and few others. You can technically make your own protocol here downside is, its only really useful in a network you fully control all hardware and can install said protocol so all hardware understands it. Then the software ones being something like MC protocol or Http. Both are completely different, but both make use of TCP and nothing says what you learn from http will even apply to some other project because it assumes it uses anything remotely similar
I like doing websockets so I can test my stuff from my browser lol
Websockets are http and http is tcp iirc
I said that
𝔱𝔩;𝔡𝔯
4 sentences is too long?
Yes
Screen dependant
What version are you creating it for?
1.18.2
right let try finding some info i havent done much work on latest versions. But i could help
Oke do you know anything about it?
you don't have to wait for the CLA to fork CB
you need the CLA for PR's though
you cannot access your stash account if you do not have the CLA approved
-> you cannot fork
buildtools gives you CB source
it gives source, yes
its a git repo in of itself
ok but that isn't the definition of forking
Пон н
what?
we dont understand that lang we should talk in english
google translate also doesnt understand it
It's russian. Their bio is that of a scammer
nice
Claiming to sell cheap boosts
Oh yeah
How can i make that public?
Player target = (Player) e.getRightClicked();
what
Can I make a command take more than one tick? Not in time, but in actual ticks, so I can send the command on tick 1 and get the success (the boolean onCommand returns) on tick 3 for example
I somehow can't think of how that could be done
you want to make server lag ?
wdym
i want to use that variable in another class
Can't you pass it through a method or something
that would be the way ^
Is block metadata tied to the block, or location?
BlockStates are tied to a block, BlockData are not
Like, I want something like PDC but block based, is there something like that?
?blockpdc
?blockpdc
lol
Learn about CustomBlockData here:
https://www.spigotmc.org/threads/custom-block-data-persistentdatacontainer-for-blocks.512422/
Learn about CustomBlockData here:
https://www.spigotmc.org/threads/custom-block-data-persistentdatacontainer-for-blocks.512422/
Huh
stoopid bot
More like slow bot
damn promoting your own article
damn that dude has a fancy profile pic. i bet he's so cute in rl
Do you think he has green hair irl
Damn, probably 
no like actually he's really hot
gotta be qter irl
if i do smth like that
return (Player) event.getRightClicked();
}```
i can't use it anymore in another type of EventHandler like InventoryClickEvent how can i do i can use `getRightClickedPlayer` in all the EventHandler?
It doesn't work in other events like InventoryClickEvent because you aren't clicking on any entities in them
You'd have to store it in e.g. a Map if you want to re-use that entity later again
how can i do smth like that?
Here's an explanation https://www.w3schools.com/java/java_hashmap.asp
and how can i check if someone check if he close the gui? like with esc it's possible on InventoryClickEvent?
No, because InventoryClickEvent only gets called when he clicks on an item
InventoryCloseEvent gets called when he closes the inventory
It makes logically no sense to combine them
oh ok yes XD
cheat client users will have fun
Guys my script umm not UTF-8
Idk why, someone know how it fix?
player.sendMessage("here my text");
even this cannot be UTF-8 (my text is different there on other language) and he should save like UTF-8.
Server is okay can see UTF-8 on other plugins (not by me).
IDE: IntelliJ IDEA Java: 18 (64-bit) Build: Gradle, Spigot | Bukkit
@Nullable
public static Block getHighestGrassBlockAt(World world, int x, int z) {
return getHighestBlockAt(world, x, z, block -> block.getRelative(BlockFace.UP).getType() == Material.AIR);
}```
Never used Predicate so i wanted to ask if that's correct
yes
that will get the first block which has the block above as air though
you probably want to check the block type
that would give you the highest block where the above block is air, which will always be Y=256
^
why didnt you just use the code I sent?
^
are you using maven or gradle?
ah gradle, I see. show your build.gradle pls
Cause when I have different ground rather than grass_block, it won't work. So should i create List<> with possible block types?
What if he is getting pushed around, falling or in a minecart
yes, that'd work.
- you'll need to tell gradle to use UTF8 when compiling, for example in build.gradle using kotlin dsl:
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
- you'll also need to set the actual source code file to UTF8, at the bottom of IJ when you got the file open, there should be a setting for the file encoding (see picture)
typically if its a custom inventory you would want this to be closed if they are moving at all
saves you from a lot of trouble down the road in regards to cheating etc
and its just easier
@Nullable
public static Block getHighestGrassBlockAt(World world, int x, int z) {
return getHighestBlockAt(world, x, z, block -> allowedMaterials.contains(block.getType()));
}
static List<Material> allowedMaterials = Arrays.asList(Material.GRASS_BLOCK, Material.DIRT, Material.STONE);``` something like that??
I find that something like that should be handled by the anti cheat itself, and it can cause annoyance when it unexpectedly close
developers shouldn't rely on someone else to handle problems for them
if you purposely ignore security vulnerabilities in the things you create you are also part of the very problem
yep, that looks good
you don't need to implement everything around cheating but you should always be mindful of things that can be exploited and implement in a way that avoids such things being used. Inventories and a player moving is one of those
It's not really a security vulnerability, especially since it's very much possible to move with an inventory open without cheats. A plugin shouldn't do what the user doesn't expect it to do, including acting like a half-baked anti-cheat, especially since it damages the QoL experience
I didn't say players couldn't move unless cheating
Btw, getHighestBlockYAt does include player modifies?
what the PotionEffectType use for "strength" effect
cause when i use World#getHighestBlockAt() it returns me original, not changed
I am saying those who cheat make use of inventories quite often and this is thanks to developers not being versed in some of the problems in regarding to inventories or other things
and thus propagating the problem further
However if you want to be part of those I suppose that is your choice I guess, but it doesn't change the fact that developers should be avoiding spreading problems around
True, but those to blame are either the developers of the anti-cheat or the server owner for not properly protecting their server
They're not ignorant for not including what is neither their task, nor something they should even think about
If that'd be the case then this would be baked into Spigot/Paper
they are, if you like your plugin being the cause a cheat is able to be used then I guess continue to ignore problems like 90% of developers
this is untrue
spigot tries to not change vanilla mechanics
paper I can't say they do whatever and this isn't paper discord
They are not the cause of being able to cheat. It's like blaming a minigames developer for not including a anti-fly cheat. It's not really their business at all
anyways, I have little interest to debate with someone who much rather be part of a problem though
so back to my shows I go
Lol
I have this code: ```@EventHandler
public void onItemSwap(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
if (isActivated.contains(player.getUniqueId())) {
player.sendMessage("activated: " + player);
for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer == player) continue;
onlinePlayer.sendEquipmentChange(player, EquipmentSlot.HAND, new ItemStack(Material.AIR));
}
} else {
player.sendMessage("deactivated");
for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer == player) continue;
onlinePlayer.sendEquipmentChange(player, EquipmentSlot.HAND, new ItemStack(Material.AIR));
}
}
}``` And it's supposed to make the item invisible on item swap if it is activate. But for some reason, it does activate, it does send the "activated", it does get the players, but it doesn't send the equipment change packet... Does anyone know why?
ItemHeldEvent is cancellable, so I guess the slot change happens only after that event. you'll either have to cancel the event, or do your stuff one tick later
maybe both, just gotta try it
btw you should not compare objects if (onlinePlayer == player) continue; just compare UUIDs
maybe specify which hand?
nah it work normally
it's prob what mfnalex said
but doesn't that just do the same thing?
yeah probably, I looked and it seems that is the way to refer to main hand
They won't be same instances in memory
never comapre raw objects
if you really want
ah ok
nah the for loop itself works normally
btw it's the same like first if and second
you sure?
yep
how?
because I have it in another piece of code...?
🤔
In java?
14
or 15? i think it was a preview feature in 14
Data classes are your way to go when you want to store information, but they have been very tedious to create, but you can easily avoid that!
but they are a class?
records are classes with auto-generated methods for getters, toString, hashcode and equals
basically that's it
yep
Mhm
immutable
It's like enums, they are still classes but with some extra functionality
yeah, so I need to make it 2 ticks later, but with that it makes it makes it appear for a split second, so I tried this: ```
@EventHandler
public void onItemSwap(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
if (!isActivated.contains(player.getUniqueId())) return;
event.setCancelled(true);
for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.getUniqueId() == player.getUniqueId()) continue;
onlinePlayer.sendEquipmentChange(player, EquipmentSlot.HAND, event.getPlayer().getInventory().getItemInMainHand());
}
player.getInventory().setHeldItemSlot(event.getNewSlot());
for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.getUniqueId() == player.getUniqueId()) continue;
onlinePlayer.sendEquipmentChange(player, EquipmentSlot.HAND, new ItemStack(Material.AIR))
}
}
you probably can't fully prevent it to look weird for a small time
I mean, there is a way right, but not easily I'm guessing right?
maybe not using this event or smth
as I said, I don't think you can prevent it from flickering because the client normally thinks it can change the held slot anytime, so it won't ask the server "yo can I change the slot". It only tells the server that the player already had changed the slot, and then the server sets it back
yeah, but it flickers when I do it with a BukkitRunnable.runTaskLater.() and I'm looking on an external client
the question is if it is possible without bukkitrunnable
but I'll look
simply cancelling the event should be enough
apparently not
tbh I dont really understand what you're trying to do anyway with that code
player.getInventory().setHeldItemSlot(event.getNewSlot());
^ that's basically the same as not cancelling the event?
event.setCancelled(true);
^ I'm cancelling it beforehand
then changing the slot so that it then is happening after
and that's the explanation of what I'm trying to do
does protocolib have a discord?
Probably
i cant find it anywhere
don't think so actually because if so, they hid it well
Probably not then
yeah but then you still set the slot to the changed slot, so what's the point in cancelling it?
quick question, im making a blockwars plugin, like bedwars but with block (that has hp and everything) and i want to know if i should change the shop gui a little bit because i just copied it entirely from hypixel bedwars, kinda feel like the plugin im making is really just a copy of bedwars
Up to you
bruh
Just make the gui 100% configurable
wdym configurable by the player?
By the admin
oh, im not publishing the plugin anywhere, just for showcase of my java abilities and maybe to play it with some friends
If your plugin is not customizable then I question your plugining abilities
i can make it customizable but i just want to finish it quickly
Hello, could anyone explain to me how does one remove the "take out item animation" when rapidly changing the item's nbt data.
basicaly, im just setting the nbt data of an item through item.setItemMeta(meta) . Is there a better method? Or is there a way to remove the animation.
Please let me know.
Thanks :)
i dont think it's possible. if the client gets an update inventory packet for the held item, it'll show that animation
any way to evade that?
oh wait
depends, what are you changing?
i have not learned packets yet
so nothing the player should see? yes, then you could listen to outgoing packets and cancel sending it to the player
and if i were to change the custommodeldata?
depends on what you use it for. if you use it for custom textures, then ofc you want the client to know about the changed value
uh
hold on
so you just listen for the packets and (spoiler i got it wrong) just cancel them?
Yes
ofc you only want to cancel sending this exact packet, but yeah
ok
basicaly
i dont know what am i doing
im trying to comprehend what this says
https://bukkit.org/threads/info-packets-nms-explained.177955/
but
my small ass brain dont work
Damn you got a cool pfp
thanks made it myself
actually i was thinking of making a new one, cuz it is kinda ass lmao
Doesn't look very pfp-y but it does look very cool
yeah
@tender shard ples help can you like send how that should look like in code? ill try to understand it.
I'd use protocollib to listen to outgoing packets
i hev to go to bed and spend the next 8 hours of my life with closed eyes
is it necessery ?
or however you type that word
omagad
ambatukam
ofc you wanna use onPacketSending or however it's called instead of onPacketReceiving
and you'll need to add protocollib as dependency in your build.gradle or pom.xml
did you add the repository?
yuh
Sometimes, people suggest you to change something in your pom.xml, and then IntelliJ starts to complain: That is totally normal. You simply have to click the “maven reload button” in IntelliJ. Maven will then continue to download the required dependency/plugin, if it’s available. After a few seconds, everything should be fine. You can find the.....
eyyy
thanks
i fix it
im stoopid
anyway
packets
gona learn tomorow
buy
oh
BRUH
IM FCKIN SLEEP DEPRIVED
BRO SAID BUY INSTEAD OF BYE
💀:🗣🗣🗣
Next time you end up with сон deprevation
yes
For reload the config with a command, I have to save the config and then reload it?
You reload it
just use reloadConfig()
okey I have it correct