#help-development
1 messages · Page 257 of 1
I already made InventoryClickEvent, and cancelled when custominventory is opened
and setcancelled below
it works with mouse click or key from 0-9
but not on F (item swap)
How do I cancel the results of a processed event and run the code and call the event again? the player will not have to do it again
what
You mean running a method it after cancelling the event?
When an event runs, the event will be canceled, then the code will run and then I will call the event, but I don't know how to call it.
it would run in loop lol
in what sense
u want to call it once just make an variable or smh
but I need to reflect the event results to the player
So, is the event data given to the player after processing or is it unprocessed? Do I need to set the variable before or after stopping the event?
if the event is cancelable, it will always fire before the action actually happened
otherwise canceling it wouldnt make sense except on twitter
if (event.getClick().equals(ClickType.SWAP_OFFHAND)) event.setCancelled(true); I'm running of of ideas, how to disable swapping item to offhand 💀
pretty much looks like it
everything else would be inventory stuff
public void onPlayerSwapping(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer();
if (player.getOpenInventory().equals(serverSelector.getInventory(player.getUniqueId()))) event.setCancelled(true);
}```Still nothing
then it's not the same inventory
what even is that
I i cannot move it in previous event, why i can swap it tho
got any idea how I can get the custom item in as an item stack in the spigot?
wdym with custom item
public void onPlayerInteraction(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Inventory inventory = event.getClickedInventory();
if (event.getClick().equals(ClickType.SWAP_OFFHAND)) event.setCancelled(true);
if (serverSelector.getInventory(player.getUniqueId()).equals(inventory)) event.setCancelled(true);
}
@EventHandler
public void onPlayerSwapping(PlayerSwapHandItemsEvent event) {
Player player = event.getPlayer();
if (player.getOpenInventory().equals(serverSelector.getInventory(player.getUniqueId()))) event.setCancelled(true);
}```java
One event works, the other does not
please use java code tags
there is a datapack with some custom items. I am trying to make custom recipe to craft them..
you cannot get custom materials via spigot
at least not right now
what are my options then?
SWAP_OFFHAND is only the clicktype, if the offhand already had an item which is then swapped
using NMS maybe
I will have to rebuild the items with NMS?
i don't think datapacks offer truly custom items
but how will I give them the custom texture?
yah, kind of reskins
that you can do
itemstacks have custommodeldata
what about second event?
the event is only for mainhand -> offhand & vice versa
so like there is no way for me to do it without remaking the items in NMS?
you can use https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Bukkit.html#addRecipe(org.bukkit.inventory.Recipe)
declaration: package: org.bukkit, class: Bukkit
so why does it not cancel?
if its fired
it seems its not firing tho xD i even changed it to only one line of event.setCancelled
debug it and see
idk im pressing F
dont wildguess
I know how to make custom crafting recipes, what I donno is how I can make those recipes incorporate items from the data packs
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ShapedRecipe.html it supports an ItemStack, so it should keep the item data
declaration: package: org.bukkit.inventory, class: ShapedRecipe
believe you cant
you'd have to manually recreate the items using spigot
You can
yea u can
how?
first get the nbt
nbt?
PlayerSwap does not fire when inventory is opened 🧐
Use a recipe exact choice as a ingredient
New discovery for me
yea the custommodeldata, custom item name, etc
ok
the event is only for mainhand -> offhand & vice versa
permissions:
protectionstones.create:
description: Protect a region by placing a ProtectionStones block.
default: op
protectionstones.destroy:
description: Allow players to remove their own protected regions (block break).
default: op
but didnt even knew that you can just offhand swap items out of inventories
how i can give permissions to players?
So how to cancel inventory slot -> offhand
with a permissions plugin?
or do you want to code your own perms plugin?
if so, you need to create a PermissionAttachment
I discovered it today
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/inventory/ShapedRecipe.html#setIngredient(char,org.bukkit.inventory.RecipeChoice)
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/inventory/RecipeChoice.ExactChoice.html
declaration: package: org.bukkit.inventory, interface: RecipeChoice, class: ExactChoice
declaration: package: org.bukkit.inventory, class: ShapedRecipe
k, Imma check the nbt doc
I got a plugin from the internet and all the permissions are for the operators and I want to give the players permissions too
But its weird that it stays in inventory
#help-server then
google luckperms and install that
but should be an ghost item
why i can't change variables inside java lambdas
or groupmanager
or groupmanager
why this language is so retatded
because thats an anonymous class
no, you just haven't understood why it's this way
use Atomics if you need to change stuff in a lambda
e.g. AtomicReference<String>
in cpp we pass pointer of var to lamba and it works fine
i prefer not using lambdas then
this is the plugin https://paste.md-5.net/tavoneqico.http
that's exactly what an AtomicReference does
ok
java is not c++, hence it has a different name
thanks
makes sense
in java you don't have to worry about memory management, pointers, and stuff
so yeah just use Atomics and you'll be fine
pointers are extremely useful and helpful if u understand them
i'll check it out thanks
haven't touched java for over 4 years lol
it was primitive int
then you can use AtomicInteger
Somebody can explain me this? Basiclly my problem is that I try get placed exact block coordinates with onBlockPlace it gets me these coordinates -135 64 -77 but when I teleport to them in coordinates shows that im in -134.500 64 -76.500?
are you using paper?
iirc paper does some weird "fixes" that make you unable to choose the exact target destination
please try whether it still happens on regular spigot
Could you show you teleported the player
Now changed to spigot api and it says that package org.bukkit.persistence does not exist
But what... ;d how if it exist
I'm using 1.13
It doesn't exist in 1.13
persistence
What are you trying to do
I set with them to blocks value
who uses 1.13? o0
I'm using creating plugin and it will be till 1.19
nonone uses 1.13 anymore
hmm
less than 10% use versions older than 1.16
1.5.2-1.19.3
and 6% of those are on 1.8
the only versions actually used are 1.8, 1.12, 1.16, 1.17, 1.18 and 1.19
noone uses 1.13 anymore, people are either stuck on pre 1.13 or are at least close to latest (1.16+)
hey ! i get an error damager cannot be resolved as a variable
@EventHandler
public void onPlayerHurt(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && (event.getDamager() instanceof LivingEntity || event.getDamager() instanceof Projectile)) {
Player playerHurt = (Player) event.getEntity();
if (event.getDamager() instanceof LivingEntity) {
LivingEntity damager = (LivingEntity) event.getDamager();
} else {
if (! (((Projectile) event.getDamager()).getShooter() instanceof LivingEntity)) {
event.setCancelled(true);
return;
}
LivingEntity damager = (LivingEntity) ((Projectile) event.getDamager()).getShooter();
}
for (PotionEffect effect: playerHurt.getActivePotionEffects()) {
if (effect.getType().equals(PotionEffectType.SLOW) && effect.getAmplifier()> 200) {
double damage = event.getDamage();
if (damager instanceof Player) {
((Player) damager).playSound(damager.getLocation(), Sound.BAT_DEATH, 1, 1);
((Player) damager).sendMessage("Vous venez d'attaquer un joueur protégé par une §7Pierre de Stase.");
}
damager.damage(damage);
playerHurt.playSound(playerHurt.getLocation(), Sound.ANVIL_BREAK, 1, 1);
event.setCancelled(true);
}
}
}
}```
I can't figure out why :/
Gonna use 1.16.5+
yes
you never declared what "damager" is in that code block
when you do a local variable, it only works until the }
so basically, move the declaration of "damager" to the top of the method and it will work
oh ty
you declare "damager" and then you close the code block with }, rendering the variable useless again
You can't access labels outside of the box where it belongs basically
Also look into anti-nesting patterns
LivingEntity damager;
if (event.getDamager() instanceof LivingEntity) {
damager = (LivingEntity) event.getDamager();
} else {
if (! (((Projectile) event.getDamager()).getShooter() instanceof LivingEntity)) {
event.setCancelled(true);
return;
}
damager = (LivingEntity) ((Projectile) event.getDamager()).getShooter();
}
for (PotionEffect effect: playerHurt.getActivePotionEffects()) {
if (effect.getType().equals(PotionEffectType.SLOW) && effect.getAmplifier()> 200) {
double damage = event.getDamage();
if (damager instanceof Player) {
((Player) damager).playSound(damager.getLocation(), Sound.BAT_DEATH, 1, 1);
((Player) damager).sendMessage("Vous venez d'attaquer un joueur protégé par une §7Pierre de Stase.");
}
damager.damage(damage);
playerHurt.playSound(playerHurt.getLocation(), Sound.ANVIL_BREAK, 1, 1);
event.setCancelled(true);
}
}```
Like this ?
Yeah I will, sorry 4 ur eyes :')
this message formatting 💀
How do I get how much health an item has decreased using the PlayerItemDamageEvent event?
ok i'm blind
if (event.getEntity() instanceof Player player) { send message }
no
if you arent using like 1.16 or higher no help from like a lot of us
Hello guys, how i can get default time potion in ticks from bottle after brew?
I'm tried read potion meta but i'm don't find default time.
PotionMeta meta = (PotionMeta) item.getItemMeta(); // here not found default time
I mean, if it's a mob that's hurting a player, i have to check if it's a player, and if it's the case i'll send him the message, but if it's a projectile, then i have to check if the thrower is a player :)
no workie
ChestGui menu = findMenu.get(p.getUniqueId());
menu.getInventoryComponent().setItem(new GuiItem(item), 1, 1);
menu.update();
what lib is that
to me: yes
it looks so confusing
thx I'll take a look at it... someday(TM)
also im too deep at this point so now i kinda have to
that's me and ACF lol
hey!
i got a .db file in my ressouces which i want to save in the plugin data folder, if not existing (on plugin start). my first question is, how do i do this?
my second question is how to access the .db file after saving it?
thy for your help ❤️
i have no idea how that lib works so i would probably recommend going to their discord at https://discord.com/invite/RXmy4HdR4x
Still same problem
whats going on?
most of the time you would need a lib/api to interact with it
@echo basalt do you know the 1.17 way of doing this
public ItemBuilder skullTexture(String texture) {
if (!(this.meta instanceof SkullMeta))
return this;
PlayerProfile profile = Bukkit.createPlayerProfile(UUID.nameUUIDFromBytes(texture.getBytes()));
PlayerTextures textures = profile.getTextures();
try {
textures.setSkin(new URL(TEXTURE_URL + texture));
} catch (MalformedURLException e) {
e.printStackTrace();
}
profile.setTextures(textures);
((SkullMeta) this.meta).setOwnerProfile(profile);
return this;
}
how does illusion appear wheni was about to ping him
hmm so i dont use reflection often but what could cause a NoSuchMethodException when the method is indeed in the class?
SwagCraftKit kit = this.kitMap.get(player.getUuid());
Method applyPregameEffects = null;
try {
applyPregameEffects = kit.getClass().getMethod("applyPregameEffects");
if(applyPregameEffects != null) {
applyPregameEffects.invoke(kit, player);
}
} catch (NoSuchMethodException | SecurityException e) {
System.out.println("No such method for kit " + kit.toString());
e.printStackTrace();
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
``` ```java
public void applyPregameEffects(Player player) {
Potion invisibilityPotion = new Potion(PotionEffect.INVISIBILITY, (byte) 0, 9999999);
player.addEffect(invisibilityPotion);
}```
this?
if that can set a player heads skull texture yes
ye
can i have it
thanks
is the issue that its using SwagCraftKit instead of BatmanImpl which is implementing SwagCraftKit
idk im not sure since if it wanted SwagCraftKit that would be getDeclaringClass and not getClass but also it says extends instead of implements so
🅱️ruh what a useless feature smh smh
if I wanted the parent class I'd just get the declaring class
there seems to be no method to get the implementing class
I guess lol
so I guess I cant do this with reflection
pain
@quaint mantle You always have the same freedom regardless
Nothing is stopping you from modifying the code
Nothing is stopping you from modifying the code
do you have an example for me?
I’m back in 3 hours and can test it out
uh call a method from a class implementing something
ok
It’s a little hard to from my phone.
but i got to school in 15 minutes so
class A {
}``` ```java
class B implements A {
public void myOwnMethod(){}
}```
and I want to call myOwnMethod
Yea i’ll just dm you the stuff no worries.
and I have B stored in a hashmap of A's
i normally use hikariCP, i can send an example in a few
Tag me rq so i can look in previous tags to find u @vapid grove
i msged u
so I did java A b = hashmap.get(...); // reflection that didnt work, whooo
well its telling me it never exists
when its clearly there lol
idk I feel like the reflection aint reflecting hard enough
cast a to b 🤔
@molten hearth is it in a parent class?
anyone know what the format for Bukkit.getVersion() is
its not even invoking it, its not finding the method
@molten hearth is it in a parent class?
uh what parent class its just in its own class implementing another class
I noticed when I do getClass it shows the class its implementing and not its own
important difference between implements and extends here
@molten hearth That’d be wrong, but you’re using getDeclaredxxx right?
yeah, getDeclaredMethod
private void setupKit(Player player) {
if(!this.kitMap.containsKey(player.getUuid())) {
this.kitMap.put(player.getUuid(), SwagCraftKit.DEFAULT);
}
SwagCraftKit kit = this.kitMap.get(player.getUuid());
Method applyPregameEffects = null;
try {
applyPregameEffects = kit.getClass().getDeclaredMethod("applyPregameEffects");
if(applyPregameEffects != null) {
applyPregameEffects.invoke(kit, player);
}
} catch (NoSuchMethodException | SecurityException e) {
// Your exception handling goes here
System.out.println("No such method for kit " + kit.toString() + " with class " + kit.getClass().getName());
e.printStackTrace();
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}```
You’d need to use it on the parent class if ur accessing a method from that
some SwagCraftKits have the method and some don't so im just checking it here
only the class implementing SwagCraftKit has the method tho not SwagCraftKit itself
its not even a class its an interface
is there an option to intercept incoming packet through bungeecord plugin api?
ew ew ew
honestly IF s cool and all
but there are some things that can better done
I fucked up and I realised SwagCraftKit is an enum and not the SwagCraftPlayableKit class I meant to use
I'm working on my own menu engine which shares a similar structure to IF but there's a lot more abstraction
and a lot of room to expand on
dynamic placeholders, animations
similar how all collections share a few methods but u cant instantiate collection cuz its an interface
It’s exactly as i said.
interface with a bunch of default empty methods that can be overriden
just so the subclasses don't need to override empty code blocks
ahh alright wait so
now I see that its printing java.lang.NoSuchMethodException: me.paradise.swagcraftsg.kits.kit_impls.BatmanImpl.applyPregameEffects() instead of the parent interface
although the method is still not found kek
atm the code is ```java
private void setupKit(Player player) {
if(!this.kitMap.containsKey(player.getUuid())) {
this.kitMap.put(player.getUuid(), SwagCraftKit.DEFAULT);
}
SwagCraftKit playerKit = this.kitMap.get(player.getUuid());
SwagCraftPlayableKit kit = this.kitImpls.get(playerKit);
Method applyPregameEffects = null;
try {
applyPregameEffects = kit.getClass().getDeclaredMethod("applyPregameEffects");
if(applyPregameEffects != null) {
applyPregameEffects.invoke(kit, player);
}
} catch (NoSuchMethodException | SecurityException e) {
// Your exception handling goes here
System.out.println("No such method for kit " + kit.toString() + " with class " + kit.getClass().getName());
e.printStackTrace();
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}```
I guess ill try Class<? extends SwagCraftKit> clazz = this.kitMap.get(..).getClass();
its uh still not found apparently
how does your class inheritance look like that u need to do reflection on your own code anyways
private void setupKit(Player player) {
if(!this.kitMap.containsKey(player.getUuid())) {
this.kitMap.put(player.getUuid(), SwagCraftKit.DEFAULT);
}
SwagCraftKit playerKit = this.kitMap.get(player.getUuid());
SwagCraftPlayableKit kit = this.kitImpls.get(playerKit);
Class<? extends SwagCraftPlayableKit> kitClass = kit.getClass();
Method applyPregameEffects = null;
try {
applyPregameEffects = kitClass.getClass().getDeclaredMethod("applyPregameEffects");
if(applyPregameEffects != null) {
applyPregameEffects.invoke(kit, player);
}
} catch (NoSuchMethodException | SecurityException e) {
// Your exception handling goes here
System.out.println("No such method for kit " + kit.toString() + " with class " + kit.getClass().getName());
e.printStackTrace();
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}```
I mean I just cant be bothered having 1 method on like 30 classes when only 2 classes use it
uh
put it on the interface like a command call
default just be boolean ... return false
and make it return true if its implemented
boom problem solved
which you then wouldnt need
yeah but then I have another useless method lol
I mean these are like survival games kits
public interface SwagCraftPlayableKit {
SwagCraftKit getKit(); // enum
void applyEffects(Player player); // potion stuff
void registerListeners(Player player); // event stuff
void giveInventory(Player player); // give items
void registerGlobalListeners(); // event stuff that's called beforehand
}
but it does 😩
I just do uh this.kitImpls.put(SwagCraftKit.BATMAN, new BatmanImpl());
and it even notices its using BatmanImpl
and im BatmanImpl I have java public void applyPregameEffects(Player player) { Potion invisibilityPotion = new Potion(PotionEffect.INVISIBILITY, (byte) 0, 9999999); player.addEffect(invisibilityPotion); }
What is being printed out @molten hearth
@molten hearth the method is public u don’t need declaredmethod
when I loop through the methods
it literally prints applyPregameEffects as one of the methods
but still throws NoSuchMethodException
Initializing kit for player xSpeziato
No such method for kit me.paradise.swagcraftsg.kits.kit_impls.BatmanImpl@42fd1ad5 with class me.paradise.swagcraftsg.kits.kit_impls.BatmanImpl
java.lang.NoSuchMethodException: java.lang.Class.applyPregameEffects()
at java.base/java.lang.Class.getDeclaredMethod(Class.java:2675)
at me.paradise.swagcraftsg.kits.KitChooser.setupKit(KitChooser.java:43)
at me.paradise.swagcraftsg.kits.KitChooser.initKits(KitChooser.java:73)
at me.paradise.swagcraftsg.match.Match.setPhase(Match.java:33)
at me.paradise.swagcraftsg.match.MatchStarter.startMatch(MatchStarter.java:76)
at me.paradise.swagcraftsg.match.MatchStarter.lambda$startCountdown$0(MatchStarter.java:58)
at net.minestom.server.timer.SchedulerImpl.handleTask(SchedulerImpl.java:92)
at net.minestom.server.timer.SchedulerImpl.lambda$processTick$3(SchedulerImpl.java:56)
at org.jctools.queues.MessagePassingQueueUtil.drain(MessagePassingQueueUtil.java:39)
at org.jctools.queues.BaseMpscLinkedArrayQueue.drain(BaseMpscLinkedArrayQueue.java:638)
at org.jctools.queues.MpscUnboundedArrayQueue.drain(MpscUnboundedArrayQueue.java:23)
at org.jctools.queues.MpscUnboundedArrayQueue.drain(MpscUnboundedArrayQueue.java:63)
at net.minestom.server.timer.SchedulerImpl.processTick(SchedulerImpl.java:53)
at net.minestom.server.timer.SchedulerImpl.processTick(SchedulerImpl.java:39)
at net.minestom.server.timer.SchedulerManager.processTick(SchedulerManager.java:19)
at net.minestom.server.ServerProcessImpl$TickerImpl.tick(ServerProcessImpl.java:280)
at net.minestom.server.thread.TickSchedulerThread.run(TickSchedulerThread.java:24)
applyPregameEffects
registerGlobalListeners
registerListeners
getKit
giveInventory
applyEffects
wait
wait
wait
equals
toString
hashCode
getClass
notify
notifyAll```
yeah, i have two hashmaps, one maps an Enum -> Player and one Enum -> Class Instance implementing SwagCraftPlayableKit
Then calling Class<? Extends BatmanImp> batmanpimpclass.getClass()
@molten hearth no
uh
good question
I changed that so many times
atm its java SwagCraftKit playerKit = this.kitMap.get(player.getUuid()); SwagCraftPlayableKit kit = this.kitImpls.get(playerKit); Class kitClass = kit.getClass();
I was testing without the extends stuff
Ur ide must have been mad about that raw type
I mean it complained about getClass being called twice
I assumed it was just being picky
Well yes, but it’s not really needed when it’s public. As you said
Plus getMethod returns the method even if it’s in parent classes.
As long as it’s public
No
It does not
I can attest my knowledge to that.
Atleast not private parent class functions*
so loc.getBlock().setType(Material.AIR) dosent update for the client like if a place a block next to it it will update or if i relog
@near night version?
1.19.2
if you want to change the block use sendBlockChange
what dose that do?
How would I check if a player died from fall from a player attack? Like the “[player] died whilst trying to escape [killer]” message
Would p.getKiller() return a player if the playerdeathevent damage cause was fall?
it send a fake block change, it could change a grass block to stone block untill it gets updated or they relog
Kinda dumb
wdym kinda dumb?
He is wanting to break something by setting it to air, his code should work.
no
Just do setType(Material.AIR, true) if the other thing does not work
Usually setType should wrok tho
ok thx
so I noticed im getting java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "kit" is null at me.paradise.swagcraftsg.kits.KitChooser.setupKit(KitChooser.java:39) at me.paradise.swagcraftsg.kits.KitChooser.initKits(KitChooser.java:68) at me.paradise.swagcraftsg.match.Match.setPhase(Match.java:33) at me.paradise.swagcraftsg.match.MatchStarter.startMatch(MatchStarter.java:76) at me.paradise.swagcraftsg.match.MatchStarter.lambda$startCountdown$0(MatchStarter.java:58) at net.minestom.server.timer.SchedulerImpl.handleTask(SchedulerImpl.java:92) at net.minestom.server.timer.SchedulerImpl.lambda$processTick$3(SchedulerImpl.java:56) at org.jctools.queues.MessagePassingQueueUtil.drain(MessagePassingQueueUtil.java:39) at org.jctools.queues.BaseMpscLinkedArrayQueue.drain(BaseMpscLinkedArrayQueue.java:638) at org.jctools.queues.MpscUnboundedArrayQueue.drain(MpscUnboundedArrayQueue.java:23) at org.jctools.queues.MpscUnboundedArrayQueue.drain(MpscUnboundedArrayQueue.java:63) at net.minestom.server.timer.SchedulerImpl.processTick(SchedulerImpl.java:53) at net.minestom.server.timer.SchedulerImpl.processTick(SchedulerImpl.java:39) at net.minestom.server.timer.SchedulerManager.processTick(SchedulerManager.java:19) at net.minestom.server.ServerProcessImpl$TickerImpl.tick(ServerProcessImpl.java:280) at net.minestom.server.thread.TickSchedulerThread.run(TickSchedulerThread.java:24)
Kit is null
but its very clearly not null because I can print it me.paradise.swagcraftsg.kits.kit_impls.BatmanImpl@32dbdc65
still dosent work
Show code @molten hearth
Ur server is broken
private void setupKit(Player player) {
if(!this.kitMap.containsKey(player.getUuid())) {
this.kitMap.put(player.getUuid(), SwagCraftKit.DEFAULT);
}
SwagCraftKit playerKit = this.kitMap.get(player.getUuid());
SwagCraftPlayableKit kit = this.kitImpls.get(playerKit);
Class kitClass = kit.getClass();
System.out.println(kit);
for(Method method : kitClass.getMethods()) {
if(method.getName() == "applyPregameEffects") {
try {
method.invoke(kit, player);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
System.out.println(method.getName());
}
}```
I tried with a for loop instead lmao
ok only relogging fixes
updating block dose nothing
right clicking it works tho
@molten hearth just inline the declaration
idk the whole getMethod thing wasnt workin very well
also equals is stupid and shouldnt exist imo
why does java have to be special and be the only programming language on earth to use a method for comparing strings bruh
🥹
It isn’t the only one.
ive used python, js, php, cpp, go and none of them needed a method to compare strings
Just do kit..getClass.getMethod
[02:11:21 WARN]: at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:16)
[02:11:21 WARN]: at net.minecraft.world.level.block.state.BlockBase.a(BlockBase.java:155)
[02:11:21 WARN]: at net.minecraft.world.level.block.state.BlockBase$BlockData.b(BlockBase.java:1010)
[02:11:21 WARN]: at net.minecraft.world.level.chunk.Chunk.setBlockState(Chunk.java:588)
[02:11:21 WARN]: at net.minecraft.world.level.World.a(World.java:551)
[02:11:21 WARN]: at net.minecraft.world.level.World.a(World.java:513)
[02:11:21 WARN]: at org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setTypeAndData(CraftBlock.java:210)
[02:11:21 WARN]: at org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setTypeAndData(CraftBlock.java:195)
[02:11:21 WARN]: at org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setBlockData(CraftBlock.java:191)
[02:11:21 WARN]: at org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setType(CraftBlock.java:180)
[02:11:21 WARN]: at base.jar//net.picklestring.base.Base.damageBlock(Base.java:78)
[02:11:21 WARN]: at base.jar//net.picklestring.base.mm.DamageBlock.castAtLocation(DamageBlock.java:35)``` hmmm
Yeah you need to do that sync
how?
or dont go async
?scheduling
cant not go async cuz using a plugins api
I swear this is scuffed
if I do java try { Method applyEffects = kitClass.getMethod("applyPregameEffects"); applyEffects.invoke(kit, player); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } it throws NoSuchMethodException but if I do java for(Method method : kitClass.getMethods()) { if(method.getName().equals("applyPregameEffects")) { try { method.invoke(kit, player); System.out.println("invoked"); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } System.out.println(method.getName()); } it works
Just do that then i guess
Lol
i dont understand why it doesnt work but it is what it is I guess
getMethod requires the full parameter types to be passed
You are certainly not doing that
oh thats why copilot was insisting on passing Player.class to it
I thought that was an extra filter
sometimes its better to listen to your codev
When copilot is smart enough to solve it but the dev still fucks it up 
lmao
idk it seemed more logical to me to be an additional filter rather than a mandatory parameter
I mean, overloading exists
u think i have help or the money for copilot
broke
ik i asked before but sadly given answer cannot be applied to my scenario
i need blockbreakevent to respect fortune and silk touch
elaborate
isnt that by default?
uh no
well i can get drops based on itemstack
but not on enchants
blockEvent.getBlock().getDrops(itemInHand)
so you want to still have more drops when fortune and silk touch is applied or what?
I thought getDrops respected fortune I remember using it and it seemed to work fine
I was making an autosmelt modifier for an item and getDrops got the extra drops.
yessir
cant
its a rng check on the time of mining iirc
Just pass in the item cloned without silk touch and then get the drop amounts
That or simulate the fortune enchant with math
dont you have to run the fortune calc urself
No getDrops works for a fortune pickaxe AFAIK
ah
when i made my auto pickup stuff i just did the fortune myself because it was going over lvl 3
ill recheck
fortune 1000 crashing the server
You can find the formula used to calculate fortune on the wiki
public int getDropCount(int i, Random random)
this one?
what is the point of that
i think its ripped from NMS
?paste Send the full error
Also +1
public int getDropCount(Material mat, int fortuneLevel, Random random) {
if ((fortuneLevel > 0))
{
int drops = random.nextInt(fortuneLevel + 2) - 1;
if (drops < 0)
{
drops = 0;
}
return a(mat, random) * (drops + 1);
}
return a(random);
}
^ full snippet
Any ideas?
i'd appreciate if spigot api had a way to predict drops lol
I mean you can use the getDrops method
Just make a clone of the item stack and remove the silk touch enchant
is that the real count?
wut?
the real calculation
i found it to be (1 / fortuneLevel + 2) + (fortuneLevel + 1 / 2)
(1 / fortuneLevel + 2) + (fortuneLevel + 1 / 2)
and my pc dies
i found it on there
but wheres randomness to it?
there isnt
There is though
it would only be like 1/2 extra
in that code there isnt, my bad
?notworking
and trident is entity that already thrown
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
um the damage is still 8
i mean it dealt 4heart
and i want to make it dealt 1 or more
but i cant ;-;
there must be because you dont always get the same amount of drops
Make sure PlaceholderAPI is enabled
when i made it, i just made it to replace the default fortune system on mine its just always the same amount of drops for fortune level
So why don't you use the api like I told you to?
you mean the event?
because im hooking on a plugin that does certain things only on blockbreakevent
The BlockBreakEvent fires before the drops are calculated
i would happily implement it if it was open source or at least free as in price...
to override drops from blockbreakevent
reading that wiki page
dirty but theres no workaround as far as im concerned
So you plan on cancelling the event and setting the block to air and then manually dropping items?
I still don't see why you can't use the other event
weird question, has anyone ever experienced intellij making \'s the picture below?
What is it that you need to access from the plugin you're hooking in to
im making a custom enchant and the api is a fucking joke
its not even commented
but yea
it has action system
and it has defined list of actions linked to certain events
Random random = ThreadLocalRandom.current();
int fortuneLevel = ...;
double noDropChance = 2 / (fortuneLevel + 2);
int maxDrops = Math.min(2, fortuneLevel + 1);
int dropDelta = maxDrops - 2;
boolean shouldDrop = random.nextDouble() < noDropChance;
int dropCount = random.nextInt(dropDelta) + 2;
there might be a better way to do this
weird utf encoding?
i have no idea
and i have no idea how to change it
if i type it in code its
\
if i type it in settings or lok at paths its yen
I still don't see why you can't use the other event
change project to utf-8?
still yen symbol
How do I put a repeat for a specific thing and if it is left the repetition is canceled (the repetition is in time for example every second)
if i do thru normal bukkit listener then other enchants will be incompatible (thats how i do it right now)
?scheduling
How so?
So what is your enchant trying to do
just invalidated and its still yen
drop stuff to inventory on block break
Can you explain to me more about that?
Read the wiki
Sounds like you really should use the drop event
90% chance of BlockDropItemEvent -> give stuff
and remove the item
well i wish it worked
and it works
how can i change the last line of item lore?
until i add another enchant that triggers on block break for example
additionally, that plugin has the same exact enchant as mine and i know it uses blockbreakevent
so they must get drops internally
get the lore of the item. then get the last entry in the list and remove it, then add your new line
monkey logic
I'm already having trouble getting the last entry
You can use getDrops(item stack)
discord . gg/jetbrains (there is an Intellij part)
tyty
it respects fortune
but the drops aren't always the same
you should really just decompile the shitty plugin and reverse-engineer it
what about silk touch that too?
Yeah
💸
im doing it for someone
i'd have to buy it tho
hm might want to look in to some Java tutorials... anyways the last entry is the size - 1 since Java starts counting from 0
sure, i guess
some authors get mad over that you know tho
who gives a shit
indeed
I've literally made 80$ updating an obfuscated world gen that costs 10$ a license
Can I unduplicate in a different event because I didn't see that I could do it
and like 2 weeks later the author updated it
You have to track your running tasks yourself
lore.set(lore.toArray().length-1, "Durability:"+(customdurability-Integer.parseInt(durabilty)));
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 💀
so u get money for telling people ur better than them, sounds about right
maybe because you don't have lore
I couldn't figure out where I went wrong
I got commissioned by some client, not the owner
still
I make money by providing advanced services that involve exotic techniques
like client-sided blocks and entities
Also, by the way, lore.toArray().length -> lore.size() 😛
or updating obfuscated code that uses nms :)
Why are you turning it in to an array. Also you can't set an index if it doesn't exist
im trying to remember if i ever showed you my curernt project illusion
for reverse engineering i'd charge 10x more tbh
otherwise I couldn't find a way to replace the last line
I wouldn't remember either
I charge 1.5x the rate if I'm working on obfuscated code
fair, btw, have you ever worked with particles?
You need to check if it has a line before trying to replace it
I know
not vfx stuff
we have a vfx artist
10$ per deobfuscated clas
that does work for marvel
there is
There isn't one. That's what the error is saying
but there is
yea see i had a really obscure thing happen to me the other day
I'd be responsible for saving that tower's data on the db
Code doesn't lie. You've done something wrong
i have this code that projects a david's star made from particles into the world, but if im using the fabulously optimized client it prints out a hexagon
any idea why
um
thats my reaction too
isn't the middle of the star of david, a hexagon?
yea but it was the size of the outer ring
it might be culling particles outside of a range
and the wrong color to boot
so on the vanilla client it's all fine
but on a modded client it's fucked?
sounds like a client issue :p
no like the confusing thing is, that hexagon has no right to exist
hm
i remember that particle distance is hardcoded and particle count is a packet limitation
if it works on vanilla & optifine, that's not on you
particle count is hardcoded to 65k
or 16k below 1.9
particle distance is hardcoded to idk
sphere of 32 blocks around ur camera
ye something like that
Another code that adds a lore line is working, so it has to assume it, right?
goofy thing about particles is that they render in the void
of course they are
jetbrains discord is dead so im just gonna reinstall intellij
urgh
it'd be a big ass packet if you could bundle 15k particles in a single packet
RIP packet queue
even async doesnt save 1k x 1k particle box spawning particle per block per 2 ticks
i need what feels like 20k packets to spit out a smooth symbol
this is when you should consider workload distribution
?workload
I never remember the command
?wd-s
ok fuck it
the issue is that particles dont have a 'delay' for spawning
so it would transmit the particle in chunks
but they have a delay for vanishing
you can use that delay
and some particle culling code
i dont think they do?
Show all of your code
do achieve smoother, more performant goals
like
they stay there for a hardcoded amount of time
ah thats what you mean
im using the ColorDustTransition particle which is roughly that
yeah
might be an idea to check if spliting the workload over a few chunks would help
fuck got no class, gtg home
*frames
ye that might be the issue
each xyz pos has a long hash
this
so we have like a Map<UUID, Set<Long>> hashes
the set evicts after like 10 ticks
and if the particle is in the set, it's not sent
Lore
complete noob here, Nag author(s): '[(redacted)]' of '(redacted)' about their usage of System.out/err.print. Please use your plugin's logger instead (JavaPlugin#getLogger)., just following a yt intro tutorial, what should be used instead of System.out.println()?
Please use your plugin's logger instead (JavaPlugin#getLogger)
(i have no idea what that means)
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.
ok, thanks
code in other file
List<String> lore = new ArrayList<String>();
lore.add(".");
meta.setLore(lore);
code that changes lore (not changes)
List<String> lore = new ArrayList<String>();
lore.set(lore.size(), "Durability:"+(customdurability-Integer.parseInt(durabilty)));
meta.setLore(lore);
what lore list?
The list you named lore
olivo and imillusion thx for help
they both have names
Why can't my maven resolve this dependecy? Im hosting it with github packages here : https://github.com/tazpvp/NR-Core/packages/1749311
do you have the repo?
No, Im unsure of the github pkg repo to use
why dont people use Arrays.asList or Collections.singletonList for lore
Bc they are uninformed
I do. :3
the dependency will only work if you add the repository
What repository is needed for this? Github docs don't say..
Probably jitpack or smth
Im not using Jitpack,
try the url u posted, or maybe that url without the numbers at the end
Well that's embarrassing. Thanks 👍
np
❓❗️
cant u just test that
the player death event getKiller method can only return a player
Check if the killer was a player.
you want the EntityDamageEvent, check if the players health is 0 then send the death message by default set the death message to null
How can I get an item by it's key(eg: minecraft:dirt)
Material#getKey()
Alternatively if you want to lookup by name. Material#matchMaterial()
Both codes are in separate file so how can I do the same thing over the variable? and saved it to the main file and tried it again same error
what are you trying to do?
.
how can I check players ping with api
so you have 2 files, with 2 different lore lists that you want to add to an item?
I tried it once it was p.spigot().ping or something
yes
declaration: package: org.bukkit.entity, interface: Player
?jd-s
does the first lore list you add to the item actually serve a purpose? or is it just meant to be blank
serves a purpose
what does it do?
which?
both
edited durability of the item is shown in the description
couldnt you just add the durability and lore in the first one and then change it on the second one?
setting to a new list
I forgot to mention the 2nd, I was going to use the 2nd to show the damage it did to the sword.
I've already told you what to do
.
tip for the people: dont look into the CraftMetaItem#addLore method
There’s a lot of nms shit u are just better off ignoring.
sorry i didn't see
that
thats in craftbukkit right?
or i didn't understand ;-;
you fucking what
i mean wtf is safelyAdd
if (lore == null) this.lore = null
the fuck
why
what the fuck
i absolutely hate that
welcome to the impl
@Overridden
boolean equalsCommon(CraftMetaItem that) {
return ((this.hasDisplayName() ? that.hasDisplayName() && this.displayName.equals(that.displayName) : !that.hasDisplayName()))
&& (this.hasLocalizedName()? that.hasLocalizedName()&& this.locName.equals(that.locName) : !that.hasLocalizedName())
&& (this.hasEnchants() ? that.hasEnchants() && this.enchantments.equals(that.enchantments) : !that.hasEnchants())
&& (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore())
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
&& (this.unhandledTags.equals(that.unhandledTags))
&& (this.hideFlag == that.hideFlag)
&& (this.isUnbreakable() == that.isUnbreakable())
&& (this.hasDamage() ? that.hasDamage() && this.damage == that.damage : !that.hasDamage());
}
wondering what @Overridden is
im gong to murder someone
have fun
i have so many questions
Velocity packets sent their X, Y and Z as a short which have a maximum value of 32767. Minecraft then divides this by 8000.0 to get a double value of velocity, which results in just under 4.1, giving a maximum visible velocity of 4.1. This means that any velocity over 4.1 gives incorrect positions and it will mess up the client.
``` Does anybody know a way to outplay this issue?
Its not an issue, it's minecrafts maximum velocity (without teleporting)
how to make a double jump ? like player velocity ?
- allow flight like in creative mode (theres a method for that)
- cancel entering flight mode
- adjust the velocity of the player so that the y value is positive
you only need to teleport the object thats moving fast
wym cancel entering flight mode
way i detect is is using the enterFlightMode event or whatever its called
so u need to cancel it or theyll start floating
only way to find a pressed spacebar in the air afaik
when to allow it ?
on join of player
well how often do I need to do this and do I just teleport it to the same location as it already is?
and 2. will this be laggy?
honestly depends on whats moving
is there an other way to making a double jump ?
again, as far as I know, no
Like just adding like force from bootom to top
arrows(bullets)
ah well
Like in unity
MAKING them jump is easy
the issue is getting the input for the jump
like mentioned above, double jump is just setting the y velocity positive to whatever u start a jump with
if its bullets why not raytrace them instead of actually firing them
and give a particle trail where they moved
uhm now you are confusing me lol
I planned to give it a particle trail anyways
well if what youre planning on doing is a bullet, you can 'raytrace' - drawing a line into the direction the player is looking from their head - to determine the bullet path and checking for the first intersection with hitbox or terrain, then use particles and that direction vector to draw the particles for the path
what if a player places a block in the path when it has already calculated the path
cant
thx
yeah but the bullet is flying
very very fast
thats why i suggested doing an instantaneous check instead of messing with teleports
yeah but it takes like 2 seconds max on very high range
and in this 2 seconds, something can happen
(sniping from skyscrapers for example)
and also, there would be no bullet texture with the raytracing
ah i see. My suggestion then would be to create a task with a repeat rate of once per tick moving the bullet forwards with teleports, and a maximum repeat count so that u dont calculate it into the great void.
Keep in mind that since it isnt actually moving you still need to check the crossed distance for blocks or entities hit.
You need to do it this way or otherwise the bullet would not get rendered correctly by the clients.
Does anyone know where in the Spigot.jar (server jar) where it handles player authentication with mojang? I want to implement my own custom authentication for it to be more secure
Sounds like offline mode with extra steps
well now you went back to arrows right?
cuz you said you wanted a projectile
Do you know where exactly it authenticates?
but i was like 'a bullet moves with 1km/s anyways so just raytrace it'
well but what if I just send projectile teleport packets every tick that do not change the position noticably at all?
while still using velocity
a normal sniper is having a speed of 800m/s btw
if ur velocity is higher than 4.1 - which i assume is per tick - its so fast it will noticeably change location. If its slower, just give the normal particle
err
oops
i mean just make it a normal projectile
that was the wrong table lol
brain no work brain no do that. Anyways, teleport if the velocity is too high and just make it a projectile otherwise
so your approach would be to make a normal arrow or teleports for normal bullets and for my snipers use raytraces
essentially yes, but not for the reason you might think. I like minimizing code, and the raytrace can be done in a single line, while the teleporting bullet entity to accurately get position is not only more complicated, but also more prone to errors
the 4.1 velocity would be 60 m/s
which would be half of the speed of a normal gun
how about this
make a raytrace and check if the distance is < 20m
*over 20m
and check if it hit anything
if not
spawn the projectile
for normal guns i mean
no one reacts that fast
hmm I don't know about that one
well youll need a raytrace anyways either way
not for normal bullets
thats cuz a teleporting entity doesnt cross the space in between
so you need to trace from the old to the new location to check if it hit anything
I mean with raytraces
you dont
remember that particles and entities have a maximal render distance
which is very low for particles
like
31 blocks
its hardcoded btw
yeah so you will not see the raytraces
theyre internal geometry
you could spawn in a bullet entity but that would defeat the point of doing the raytrace in the first place
like the long one
hmmm
well you think using the normal terminal velocity sucks too?
that would be unrealistic asf wouldn't it
normal guns are 800m/s
well as said, I'd use raytraces for fast bullets and raytraces + particles for slow ones
mainly cuz u cant really react to something that fast so the overhead would be pointless
this would be a tenth of that
well but the whole deal is seeing the projectile
as a third party player
then go with the scheduler teleport short raytrace thing
you cannot see particles over range even using zoom
ur only option is to spawn in either a projection or an bullet entity
hmmm
well now im thinking, is it better for my gun system to actually see bullets going "slowly" or them being instant and realistic
no I have not looked at it by now
its fairly easy actually
I did not even know that was a thing for bullets
well like, the gun system is for a rp server aiming to be as realistic as possible, but I clearly do not know if it would be more fitting and cooler to have "slow" projectiles or realistic(the raytracing part would be here) and instant shots
like would it be a better experience?
I'd suggest fast particles and doing the projection, since it actually gives the feel of a real weapon, but its hard to tell without playtesting.
Here's how you'd do the projection to make bullet trails visible:
Then, for each player watching you calculate the vector from their camera position to each sample location.
Normalize those vectors, multiply by 16 (particle weirdness reasons)
Add those vectors to the watching player's location, and keep track of the results. Keep in mind that doing math on vectors changes them, so you just need the original list of normalized vectors.
spawn in a small but bright (maybe a silver) particle at each of those locations.
Bullet trails visible regardless of distance.```
the problem is, this is a big thing to try out lol
do you have an example?
that does not work with projection
can whip it up give me 2 minutes
public Set<Location> projectionPoints(Player observer, Location bulletTrailStart, double trailLength){
//constant, sampling count, maybe change this depending on player distance. Dont change beyond this point.
final int STEPS = 10;
Location playerLocation = observer.getLocation();
//Vector for stepping along the trail
Vector direction = bulletTrailStart.getDirection().multiply(trailLength/STEPS);
//Does not exceed Steps+1 in size, therefore 1 as load factor.
HashSet<Location> projectionLocations = new HashSet<>(STEPS+1,1.0f);
//Do not modify input
Location currentTrail = bulletTrailStart.clone();
for(int i=0;i<STEPS+1;i++){
projectionLocations.add(playerLocation.clone().add(currentTrail.toVector().clone().subtract(playerLocation.toVector()).normalize().multiply(16)));
currentTrail.add(direction);
}
//Project at the locations of the return set
return projectionLocations;
}
@orchid gazelle
untested but i dont think theres issues with it
if theres any its probably in the vector math
so this just returns all points where I need to spawn particles for the selected player right?
why can't I just spawn the particles at the general trail?
well i mentioned above
particles do not get rendered beyond 31 blocks distance
32 actually but its better to say 31
so you need to project the bullet trail into that area around the player to make it visible
and how does this bypass it?
well then the players cannot see the trail if it is more than 31 blocks away
smh where is the limit hardcoded?
maybe can do something with reflections or something
if it is done serverside
you what
you said return false so i found it really weird
^
well so you basicly take the location of the particle 50 blocks away, and render it so it looks like it is 50 blocks away but it isn't lmao
well
everything in games pretends to be exactly x distance from the camera
what if for example a glass block is in the way of for example vector 1
on your sketch
jnak
u could add a check if the vector intersects a non transparent block but i aint writing all your code
yeah thats for sure
just wanted to ask
how it would work
but I understand now
ray trace from either player to trail or trail to player, check if block is there
could be on any of the 3 projects that consist of the server jar
keep in mind to tell the raytrace what blocks you consider transparent
by default its only air
and its variants
cave air best
and this is not gonna be lagging when 50 players look at that trail and it calculates the vectors every tick?
and 50 players shooting
math is really really fast
i can render 20k particles at once without issue
youre projecting a few hundred at most
ur fine
completion time?
instant. it starts lagging shortly after that
well its a shit load of particles getting calculated for a shit load of players
like at around 30k
well yes but
each ray trace equals one particle, unless you draw the full line
which actually would make the math a lot simpler im dumb
that aside even with this inefficient method ur rendering like 20 particles max per player so being generous and saying theres 50 players you have like 1000 partikles
if everyone shoots a sniper rifle at once
(Here's the easier way: Project start and end point of the trail, draw a line between them, spawn particles on it)
well then you got 50k particles being calculated
no TOTAL
if you take the 1000 particles and calculate them for every player
uh
20 traces per player on average
50 players
so like even with this
1k particles MAX
50 shooters, 50 receivers, 20 particles
do u really recon you will have
- 50 players in the same area
- all shooting a long-range weapon
- in the same tick
this is an edge case you dont need to cover cuz its so exceedingly rare
exceedingly rare?
its not that unrealistic
for example take gangwars
25 against 25 players
almost a 0.01% chance that will happen
you do realise there are 20 ticks in 1 second
spamming the shooting button
thats not how math works
there is no chance all 50 of them will be able to time that so perfectly
is now