#help-development
1 messages · Page 744 of 1
i never would ever think that i would say that labels sometimes results in more readable and cleaner code
in the i loop add a cells[i] = new Cell[size];
i managed to remove 5 lines of useless checks
that is, if I take an element with cells[51][51] will it be null?
just by adding label for outer loop
i still haven't found a use for labels
arent they null by default
Objects are null by default Java doesnt populate objects with garbage values
then fill the i loop with cells
like in C/C++
otherwise it's null at the first index
There's also Arrays.fill
not sure
cool trick i've stolen from stack overflow like one year ago:
if you want an easy one liner to loop backwards from array's size, not index, you can use
while (size --> 0) {}
it looks like a real operation, its readable, one line, no more size-- in the while loop itself, neat
yea it is
yea its technically while (size-- > 0) {} but it looks cleaner when you make it an arrow
you just need to grab size in a var beforehand
I found a problem with the delux menu inventory hiding plugin, can you help me? The problem is very simple, when someone opens the "shop" gui with deluxemenu, his inventory does not appear, but he takes the items thrown on the ground into his inventory and disappears when he closes the "shop" gui.
Plugin source : https://pastebin.pl/view/e33d116c
Pastebin.pl is a website where you can store code/text online for a set period of time and share to anybody on earth
What I want to do is to hide the inventory when the market opens
i would assume some version missmatch
how to make player hit entity using plugin?
Player#attack
ty
Will there be an attack animation of hand used?
i believe so, but im not entirely sure
no
another question... how to change weapon/damage of attacking entity using player#attack
hmmm i need something like entity.dealDamage(damage)
does command executor run if i dont have permission in the server?
or it doesnt execute it at all
?
entity.damage
Has to be a living entity
so... how to get damage of an item? Damageable#getDamage() returns durability damage...
Attributes
oh.. Item.getItemMeta().getAttributeModifiers().get(Attribute.GENERIC_ATTACK_DAMAGE)?
ok thanks
Then you can to use Material#getDefaultAttributes
is there any ways to keep a plugin that extends a NMS class can maintain multi-version compability?
like the constructor of ServerPlayer.class changed in 1.20.2
can i use some method to make it runnable for both 1.20.1 and 1.20.2?
Heyo, I need to know what portals are linked (or will be linked)
I do not mind NMS
I don't even know where I should begin with this
i still can't figure it out how to get damage of an item using
leftItem.getType().getDefaultAttributeModifiers(EquipmentSlot.HAND).get(Attribute.GENERIC_ATTACK_DAMAGE)
it returns [AttributeModifier{uuid=..., name=Weapon modifier, operation=ADD_NUMBER, amount=5.0, slot=HAND}]
amount=5.0
?
If you dont want make your brain melt just use viaversion.
yeah but it returns Multimap and i don't know how to get amount from multimap
leftItem.getType().getDefaultAttributeModifiers(EquipmentSlot.HAND).get(Attribute.GENERIC_ATTACK_DAMAGE).forEach(el -> {
damage = el.getAmount()
})
```?
One key, multiple values
oh, so the other way around
It's basically a cleaner Map<K, Collection<V>>
that does sound useful
i have a few usages of collections as values
i'll see if i can simplify them
Usually the easiest solution is to shadow (all) your NMS dependencies (include a prefix in the package pertaining to the server version), implement logic for each NMS version (in individual classes, which you will switch between when you determine the server’s version) & un-apply the shadowing when compiling your plugin
can you give an example?
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
if (this.preventItemPickup.containsKey(player.getUniqueId())) {
event.setCancelled(true);
}
}
dont work help
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
Wild guess would be this thing is in a Class that is also a CommandExecutor and you create two instances of it
You are missing an import ?
missing the Map?
I can give you the full version if you want.
package divan2000.menuaddon;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.ItemStack;
public class EventListener implements Listener {
private Map savedInvs = new HashMap();
@EventHandler
public void onGuiOpen(InventoryOpenEvent event) {
if(event.getInventory().getHolder().getClass().getName() == "com.extendedclip.deluxemenus.menu.MenuHolder") {
Player player = (Player)event.getPlayer();
this.savedInvs.put(player.getUniqueId(), player.getInventory().getContents());
player.getInventory().clear();
}
}
@EventHandler
public void onGuiClose(InventoryCloseEvent event) {
if(event.getInventory().getHolder().getClass().getName() == "com.extendedclip.deluxemenus.menu.MenuHolder") {
Player player = (Player)event.getPlayer();
if(this.savedInvs.containsKey(player.getUniqueId())) {
player.getInventory().setContents((ItemStack[])this.savedInvs.get(player.getUniqueId()));
this.savedInvs.remove(player.getUniqueId());
}
}
}
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
if (this.preventItemPickup.containsKey(player.getUniqueId())) {
event.setCancelled(true);
}
}
public void giveAllInvs() {
Iterator var1 = this.savedInvs.keySet().iterator();
while(var1.hasNext()) {
UUID uuid = (UUID)var1.next();
Player player = Bukkit.getPlayer(uuid);
player.getInventory().setContents((ItemStack[])this.savedInvs.get(uuid));
}
}
}
I don't know what you mean.
this.preventItemPickup
you are trying to access a field called preventItemPickup
that field does not exist
What I want to do is I want to prevent him from picking up the item on the floor.
okay ?
the class literally does not have the map you reference
shouldnt the ide tell you
Oh, I see
eclipse 😭

Eclipse tells you...
My bet you created the Map in your main class and copy/pasted code
given that material is no longer an enum, is it still fine to use Material as key in mappings, or should i use the strings representing the materials?
It's fine to use
k
Also it's still an enum
That PR hasn't been merged yet
Also it doesn't even change material anymore, it just deprecates it
for how long is the mat enum gonna be deprecated (along w/ other enums)?
at least one major version i recon
Probably forever
MD doesn't intend to remove things unless they become a maintence headache
See: Material data
How do I load classes from inside the jar? Currently I've got this (without exception handling), but it throws a ClassNotFoundException on Class#forName(). The class it can't find does exist and the path shown in the exception is the same as the path to my class.
fun registerListeners(plugin: Main) {
val packageName = plugin.description.main.substring(0, plugin.description.main.lastIndexOf('.')).replace('.', '/') + "/listeners"
val jarFile = JarFile(plugin::class.java.protectionDomain.codeSource.location.toURI().path)
val entries = jarFile.entries()
while (entries.hasMoreElements()) {
val entry = entries.nextElement()
val name = entry.name
if (name.startsWith(packageName) && name.endsWith(".class")) {
val className = name.dropLast(6)
val clazz = Class.forName(className, true, plugin::class.java.classLoader)
if (Listener::class.java.isAssignableFrom(clazz) && clazz != Listener::class.java) {
registerListener(clazz.getDeclaredConstructor().newInstance() as Listener, plugin)
}
}
}
this is kotlin?
It is indeed kotlin
usually classes are loaded using classloaders on java, idk on kotlin though
I'm not really sure either but I'm getting the classLoader from the main class that extends JavaPlugin
i think i know what's wrong but im not sure
you've used / as a path separator
Class.forName() expect package path not file path
you need dots instead of / probably
^
is there a simpler way than
for(Material m : Material.getEntries) m.toString.equals(key)
to check if the key is a string that would get accepted by valueOf ?
That was it, thank you
I had tried many other ways, and the first one had me replace all dots with slashes
well that's probably because for jarfile retrieval you do need normal file path
unless its inside the plugin's .jar file
in other words, are included by plugin's classloader
whats the point
i dislike try/catch
oh does it throw when the string is invalid?
yes
if you want to load .jar file from outside the plugin's jar file boundaries you need to use URLClassLoader or something custom, but for simple cases (when you want to read something from the plugin's jar file itself), Class.forName() does well
I'm pretty sure I used that in the first place, but the path was invalid because it contained a colon character
Because of C:\
AH FUC
i just hit F4 on material
But I'm glad it works now
but.. why
someone told me that try/catch is to be avoided when possible
that's true, try catch is kinda expensive, but sometimes its inevitable not to use it
not here
bukkit api is a big nms hack so i wouldnt be surprised if that would be impossible to do, but I guess you've found an optimal solution
Question:
If I had a list for allowed-worlds in my Config File and I wanted to allow users to specify * or all as the first item in the list, to allow all worlds by default, is it as easy as doing:
allowedWorldList = getConfig().getList("allowed-worlds", null);
if(allowedWorldList.get(0) == "*"){
allowedWorldList = getServer().getWorlds();
}
Or am I missing something?
you can call contains i think
Kind of inefficient doing it that way but it would probably work if you convert those worlds to their names
Ah yeah that I forgot but just more asking if that is the correct way to do it.
i mean
it would check if the first entry is specifically "*"
but contains would check if its anywhere
depends on what behaviour u want ig
hello can you help me I'm trying to create a cliam plugin for claime in 16x16 but it makes me a fool who can help you?
RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(World));
org.bukkit.command.CommandException: Unhandled exception executing command 'claim' in plugin ShopCountry v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchCommand(CraftServer.java:987) ~[paper-1.20.1.jar:git-Paper-196]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:889) ~[guava-31.1-jre.jar:?]
at com.sk89q.worldedit.bukkit.WorldEditPlugin.getInstance(WorldEditPlugin.java:501) ~[ShopCounty-1.0-SNAPSHOT-all.jar:?]
at com.sk89q.worldedit.bukkit.BukkitWorld.<init>(BukkitWorld.java:117) ~[ShopCounty-1.0-SNAPSHOT-all.jar:?]
at com.sk89q.worldedit.bukkit.BukkitAdapter.adapt(BukkitAdapter.java:123) ~[ShopCounty-1.0-SNAPSHOT-all.jar:?]
at me.shopcountry.claim.Commandclaim.onCommand(Commandclaim.java:27) ~[ShopCounty-1.0-SNAPSHOT-all.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
... 23 more
Make sure to softdepend or depend on WorldGuard
(and worldedit)
build.gradle
repositories {
mavenCentral()
maven { url "https://maven.enginehub.org/repo/" }
maven {
name 'Bukkit'
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
}
dependencies {
compileOnly "org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT"
compileOnly 'com.sk89q.worldguard:worldguard-core:7.0.0'
implementation 'com.sk89q.worldedit:worldedit-bukkit:7.2.9'
}
in your plugin.yml
name: ShopCountry
version: 1.0
main: me.shopcountry.ShopCountry
api-version: 1.19
depend: [WorldGuard]
commands:
claim:
description: "claim"
unclaim:
description: "unclaim"
Now add WorldEdit to depend
depend: [WorldEdit, WorldGuard] like this
Yes
console
[17:58:57 ERROR]: [WorldEdit]
**********************************************
** /!\ SEVERE WARNING /!\
**
** A plugin developer has included a portion of
** WorldEdit into their own plugin, so rather than using
** the version of WorldEdit that you downloaded, you
** will be using a broken mix of old WorldEdit (that came
** with the plugin) and your downloaded version. THIS MAY
** SEVERELY BREAK WORLDEDIT AND ALL OF ITS FEATURES.
**
** This may have happened because the developer is using
** the WorldEdit API and thinks that including
** WorldEdit is necessary. However, it is not!
**
** Here are some files that have been overridden:
**
** 'World' came from 'ShopCountry (file:/home/container/plugins/ShopCounty-1.0-SNAPSHOT-all.jar)'
** 'EditSession' came from 'ShopCountry (file:/home/container/plugins/ShopCounty-1.0-SNAPSHOT-all.jar)'
** 'CommandManager' came from 'ShopCountry (file:/home/container/plugins/ShopCounty-1.0-SNAPSHOT-all.jar)'
** 'Actor' came from 'ShopCountry (file:/home/container/plugins/ShopCounty-1.0-SNAPSHOT-all.jar)'
**
** Please report this to the plugins' developers.
**********************************************
Might be
Don't shade WorldEdit
Ur redis wrap lib uses a different netty version
Could also be for a valid reason. Older methods and whatnot.
Not impossible id presume
what do I do
Altho feels like a different error would yield in that case, no?
not shade worldedit
change implementation to compilrOnly in your build script
for worldedit artifact
or <scope>provided</scope> if using maven
> Could not find method compilrOnly() for arguments [com.sk89q.worldedit:worldedit-bukkit:7.2.9] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
i have error when i do this
compilrOnly 'com.sk89q.worldedit:worldedit-bukkit:7.2.9'
fix my typo
yes
yes
thanks is working
if i catch the same event in 2 different plugins is there a way to make sure 1 of them catches it first
Set different priority
@fresh templetHandler(priority=...)
Sorry for ping ig
thx
does 1 have a higher priority or 2
like what way does it go
higher first or lower first
its not a number
higher = called later
how to set ItemMeta in minecraft 1.20?
its an enum
Same way you have done it for years
ah thanks
if i only set the priority in one of them will the one with priority be called first or the one without
which ones are there
yes
thanks a lot
aka if you change the state of an event under monitor priority, I'll break your kneecaps
in game
Clearly we just need more priorities
oh thank good in game
Hear me out
LOWEST, LOWER, NOT_QUITE_AS_LOW, LOW, BELOW_AVERAGE, NORMAL, ABOVE_AVERAGE, HIGH, NOT_QUITE_AS_HIGH, HIGHER, HIGHEST, and MONITOR
should add Bedrock at the start
Why is not quite as high after high when its not quite as hide
For the same reason not quite as low is lower than low
It's lower than low but not quite as low as lower
Make sense?
should just make it bedrock, diamond, gold, iron, copper, coal, stone, wood
but at that point you cant really change anything anymore anyways
so what difference is it gonna make
Gotta make sure your monitor is after the other plugins monitor
BigDecimal for priority
When the inventory is hidden, the player's armor is also hidden, what should I use?
if you look at the foot, the armor set disappears and comes back when you close the market
what
gui already belongs to the deluxe menu, so it won't appear on it
It uses the top inventory plus the player's inventory to show its contents
And if this specific GUI doesn't then it likely just does it for all inventories as a precaution
utf8 read as txt
it was always like that
its alrdy visible not scrolling? XD
what ide do you use?
I mean it's an app
It probably contains the app then
My inventory hiding plugin hides all slots, including armor slots, that is, it takes the background, it takes the armor to the background, so I don't want it to be hidden, I don't want it to be hidden, can you write me syntax or playerArmor ... what should I use?
I like ur background
You could send packets idk what packet or how that'd work but it's a worth a shot
does anyone know how to get the first part of the command?
What do you mean get?
split on space
send the code idk how to write it
i dont have an idea of how
"Java split string"
https://www.baeldung.com/string/split
Google is your friend :)
how i install bukkit in replit to create one plugin
how do I create an anvil that falls from the sky but doesn't do any damage when it lands?
FallingBlock has methods to set damage
Why would you run bukkit on replit
i got that so far
alr ill see thx
Hi guys, can someone help me with something?
I want to compile my minecraft mod but it's not working.
This is the output:
17:22:23.382 [DEBUG] [org.gradle.launcher.daemon.server.exec.ExecuteBuild] The daemon has finished executing the build.
17:22:23.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
17:22:23.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
17:22:23.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
17:22:23.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Where:
17:22:23.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Initialization script 'C:\Users\alces\AppData\Local\Temp\ijresolvers1.gradle' line: 208
17:22:23.380 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
17:22:23.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
17:22:23.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] A problem occurred evaluating initialization script.
17:22:23.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > No signature of method: org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.whenReady() is applicable for argument types: (SetupUtpTestResultListenerAction) values: [SetupUtpTestResultListenerAction@da9f2887]
Possible solutions: whenReady(groovy.lang.Closure)
17:22:23.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
17:22:23.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
17:22:23.381 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
5:22:23 PM: Execution finished ':classes :testClasses --debug'.
so then thatll get the first part of the cmd with no args?
No need to check if starts with /
oh
In my method it gets both command and args
String[] split = event.getMessage().split(" ");
String command = split[0].substring(1); // Remove the leading "/"
String[] args = Arrays.copyOfRange(split, 1, split.length);
so itll know if its a cmd?
oh
It's only triggered on commands
mb
I sent a friend request, I will send you a message shortly, thank you very much
Don't take help in dms
Ask here and wait
i'm trying to set up kotlin in my plugin, when i build it using intellij, the kotlin stdlib is inside the main output jar as other .jar files so it doesn't get loaded, what should i do?
using maven
There is a plugin for Deluxemenu that hides the player's inventory when the deluxemenu guis opens and restores it if the player closes the guis.But there are no updates, I found 2 errors and no other errors:
- The armor on the player also hid this undesirable
- When a player dies or is killed with the deluxemenu gui open, their inventory does not drop and disappears
Original java file of the plugin :
package divan2000.menuaddon;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
public class EventListener implements Listener {
private Map<UUID, ItemStack[]> savedInvs = new HashMap<>();
@EventHandler
public void onGuiOpen(InventoryOpenEvent event) {
if (event.getInventory().getHolder().getClass().getName().equals("com.extendedclip.deluxemenus.menu.MenuHolder")) {
Player player = (Player) event.getPlayer();
this.savedInvs.put(player.getUniqueId(), player.getInventory().getContents());
player.getInventory().clear();
}
}
@EventHandler
public void onGuiClose(InventoryCloseEvent event) {
if (event.getInventory().getHolder().getClass().getName().equals("com.extendedclip.deluxemenus.menu.MenuHolder")) {
Player player = (Player) event.getPlayer();
if (this.savedInvs.containsKey(player.getUniqueId())) {
player.getInventory().setContents(this.savedInvs.get(player.getUniqueId()));
this.savedInvs.remove(player.getUniqueId());
}
}
}
@EventHandler
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
if (this.savedInvs.containsKey(player.getUniqueId())) {
// Oyuncunun market açıkken alınan eşyalarını iptal et
event.setCancelled(true);
}
}
}
?paste
how would i trigger auto gg mods?
Yeah i know that but the issue is that i cant use the any of my event which extends MenuEvent
You’d have to look at what the mods trigger on
Why do you use it like that? DeluxeMenu has an api for this type of things
Consumer<? extends MouseEvent>?
Wait could i send my sample?
Sure ig
would be better hehe
@FunctionalInterface
public interface MenuAction {
void run(MenuEvent event);
}
Thats how looks my action interface
But my "issue" is that i throws syntax error with any of the events extending MenuEvent
Can you snow it
I think what i exactly need are called: lambda typed arguments
Yes
1m my vm connection went down fkg remote coding
Im not sure why, because if i check the MenuClickEvent it extends MenuEvent
Is it supposed to be a lambda function
yeah i know that
oh yeah
Yes should be lambda
I was told this thing specific are lambda typed arguments
I mean why are you even having it, why not just (event) ->
because i need to create 2 consumers, one for drag and other for click
With this, you can use any of them without using different code
Just replacing its type of the obj in the lambda
Seems like unnecessary extra steps
na its good dont worry about, just need to find the issue hehe
I remember i made it work but not sure where*
It would make sense if you were casting click event to menu event
But you cannot other way around
what?
.
How can you be sure that it will be MenuClickEvent but not some other MenuEvent
In that lambda
will add actional logic for checking it
That is why it's throwing
what?
Yeah but compiler doesn't know that
"Typed lambda expressions" are lambda expressions in which the compiler can infer the types of the arguments, meaning you don't need to specify the argument types explicitly. This is possible because the compiler can deduce the type based on the context in which the lambda expression is used.
Here's an example of a "typed lambda expression" in Java:
List<String> names = Arrays.asList("John", "Maria", "Peter", "Sophia");
names.forEach((String name) -> {
System.out.println("Hello, " + name);
});
In this example, the lambda expression ((String name) -> { ... }) is a "typed lambda expression" because the type of the argument name is automatically inferred as String due to the context in which it's used. It's not necessary to specify String name explicitly; the compiler can deduce it.
Using "typed lambda expressions" simplifies code writing by eliminating the need to explicitly repeat data types when they are obvious.
hee?
the events that appear there all subtypes of MenuEvent
I just 100 it was working like this before somewhere else
Because i have seen it in another library but cant find it. It was where i initially take the idea
Your interface is defined as MenuEvent, not menuclickevent
You can't expect it to 100% be MenuClickEvent without instance of check
That is what compiler is complaining about
You can do (MenuEvent event) -> {
If (event is MenuClickEvent)
}
yes that how it works, because if i do it as menuclickevent then you are oblise to only using that one
🤔
Or just use generic consumer as already suggested
so a consumer<MenuEvent> ? Is the same im doing with a functional interface 😂
Consumer<MenuClickEvent>
but that cant vary the event bro
I need to have multiple of them
let me use the translator this is too much messy
Seems like you are missing inheritance fundamentals tbh
You can't be sure MenuEvent will be instance of MenuClickEvent, idk what is not clear here
That is what compiler is complaining about
You can just make it MenuEvent, and inside of lambda do a cast
It happens that I need to make a functional interface that accepts any sub object of an Object (MenuClickEvent, MenuDragEvent are sub types of MenuEvent). And I need to do it with a functional interface, this way using the same action you can create it for the click or for the drag.
Do I understand?
You can also make it be generic
wtf
dont do that lol
but why do u type construct at method level?
What?
Its for my menu action system
My goal is to use the action as a "lambda typed arguments"
ur doing it wrongly tho
oh could you help ?
well
I seen in another menu system they did this its was where i taken the idea but cant find it the code
it doesnt make much sense to begin with that u enforce urself to use higher order functions
triumph gui prob
or if
I have been researching for a while about menu apis, precisely how to comfortably create the actions to the items.
Re searching I found a very interesting way using lambda typed arguments, where they used a functional interface with a parent object and sub types.
That way at the moment of creating the action, you could use the drag or click. Something like that
MenuItem item = new MenuItem(stack, (SubEvenType event) -> {});
I finddd where i taken the example 💪
@ivory sleet sorry for tagging
oh so u overload withListener(lambda) with different callback types
oh right
i think Goski miss understand what i was trying to do or i explained too bad
prob not
Id do it like
@FunctionalInterface interface InventoryClickCallback {
void onClick(InventoryClickEvent event);
}
void withListener(InventoryClickCallback callback) {
}
etc
hmn but not exactly how i would like
u dont wanna have a <T extends Blah> void onClick(T e);
rright, so would be MenuEvent instead
ugh
Like my initial code
But the IDE complains that MenuClickEvent is not sub type of MenuEvent
Thats what fucking me up
make MenuClickEvent derive MenuEvent
sorry to bother, but I still need help in my thread, thank you. it would mean a lot
how does MenuItem constructor look like
send MenuAction
current one?
yes
link me
Also nice yo see you again in the stuff i miss you a lot my friend 🤝
This one conclure
So far gpt is saying everything should work
yeah you cant assume its always gonna be MenuClickEvent
right
but why?
If MenuClickEvent and MenuDragEvent are sub types of MenuEvent
🤔
thats the issue
(MenuClickEvent event) -> ...
only works if void run(MenuClickEvent event);
Hmnn
right i seen it working
But im sure this guy of the repo updated the code but no the sample
Hello! using #performCommand() and passing /buy throws unknown command, any solutions?
Have you typed it without slash?
Yeah I tried just passing "buy"
How can I change drops of a block if a specific player breaks it? I saw that the BlockDropItemEvent doesnt allow adding new drops
And you can write /buy in game?
Do I really have to drop the item naturally into the world?
what slash?
Yup
Well i changed it to use Player's #chat function and chat("/buy") works
I dont get why performCommand won't
Yes
Or change the existing items
BlockDropItemEvent the block is type air for me even though it was a diamon ore ist that normal?
Yeah I see it says in the API
Hi, I am writing a plugin that uses custom heads that I create, but the heads lose their name and lore when placed
I'm using the PlayerProfile interface and I have persistent data types
Store it in the pdc of the placed head
Yes
Ok so I'm on the right track. I need to check if the placed head is the same one I created
That's where I'm stuck
?blockpdc
Learn about CustomBlockData here:
https://www.spigotmc.org/threads/custom-block-data-persistentdatacontainer-for-blocks.512422/
alright I will. thanks!
You don’t need block pdc
@tender shard btw if I click on the update checker link it brings me to morepdc
Heads are tile entities
I don’t understand your issue
Currently trying to find a way to check if a player hit the head of a zombie when using melee attacks.
Any tips that will save me some time?
Ray trace and see where it hits the bounding box
Does someone know what the PlayerAdvancementCriterionGrantEvent is? Its not in the spigot api and it firest constantly...
Sounds like paper api to me.
Yeah I'll ask on their discord thx
If I want to fork spigot, do I need to get permission first?
No, Spigot is GPL.
So I can juts decompile the jar and fork it, also redistribute it right?
More or less. Just don't redistribute/label your fork as Spigot as that would be a copyright violation.
Also, just download the source off of stash. No need to decompile.
Okay, thank you very much, of course wouldn't be doing that
Yeah, I'll release it as Spigot2 instead 👍
Bro what the fuck doesnt make sense my issue
i cant understand why because MenuClick is a sub type of MenuEvent
Do you need to downcast it?
im not downcast, its something from java which not most know
they called lambda typed arguments
Works for functional interfaces
I rmb I'd just type event -> ....
Not menuclickevent event ->
i cant
menu event is abstract
i have seen thats posible what im doing but now now why now id doesnt work
basically in context there's no way of knowing if the MenuEvent passed is of type MenuClickEvent
Why, if im telling MenuEvent? Isnt suppoused by inheritation
Im still not sure how it worked
I'm back. My issue is that I don't know how to get the data out of the placed head
get the head and then the pdc
I'm sorry, I don't know what you mean
what data do you want from the head
he want to get pdc data if im not wrong
yeah that holds the display name and lore, right?
placed heads dont save name or lore, only way to get that is if you save it there
not how it owrks
hmm. I know this is possible because I've seen it done. when I place and break a custom head the display name and lore disappear
you should create a pdc for it where you save the name and the lore
I'm thinking of making a custom tile entity api
but not undderstand what Saidy wants to do
If yoo could be more specific it would better
sigh
yes I have the display name and lore stored when the head is created in a persistent data container.
When you place a skull you're placing a player head tile entity with the data of the skull owner
Tile entities do not track what itemstack they originated from
So.. the original item is lost to time
You need to track the original item in the skull's pdc
got it?
uh- there will be quite a few of them since they drop from mobs
yeah so just make a really simple one that works for all ofthem
completely lost. I'm sorry >_<
thanks though
ok. I think what I need is the value of the placed head.
does this code succesfully resets a map while keeping some of it right
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
public class MinecraftMapReset extends JavaPlugin {
private static final String WORLD_NAME = "MinecraftMap";
private static final String BACKUP_WORLD_NAME = "MinecraftMapBackup";
private static final int RESET_INTERVAL = 5 * 60 * 20; // 5 minutes in ticks
@Override
public void onEnable() {
getLogger().info("MinecraftMapReset is enabled.");
backupWorld();
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> resetWorld(), 0L, RESET_INTERVAL);
}
@Override
public void onDisable() {
getLogger().info("MinecraftMapReset is disabled.");
}
private void backupWorld() {
World world = Bukkit.getWorld(WORLD_NAME);
if (world == null) {
getLogger().warning("World " + WORLD_NAME + " not found.");
return;
}
World backupWorld = Bukkit.getWorld(BACKUP_WORLD_NAME);
if (backupWorld != null) {
backupWorld.save();
Bukkit.unloadWorld(backupWorld, false);
}
try {
File worldFolder = world.getWorldFolder();
File backupWorldFolder = new File(Bukkit.getWorldContainer(), BACKUP_WORLD_NAME);
if (backupWorldFolder.exists()) {
FileUtils.deleteDirectory(backupWorldFolder);
}
Files.walkFileTree(Paths.get(worldFolder.getPath()), new SimpleFileVisitor<Path>() {
i'm not sure it runs or nah
?paste
half the code isn't even there
Keep in mind that world files might be saved on another thread so I'd try deleting after like 5 seconds
or operate with a copy while the other one deletes
idk what to do, i wanna make a plugin but now idk what to do
even any proyect
im out of ideas
I want to make a script in the plugin (skript) in which when I type the command
"""/command <player>"""
it spawns a custom npc mod npc on top of the player's head and stays there until i give the command again,
Plugins used: SQuery, Skript
Version Minecraft :1.7.10
help plss
1.7.10 and you're posting in a channel meant for development with the Spigot API (supposedly in Java)
ask in the SkUnity discord, but i doubt you'll get support on such an old version
thank you
how do i get a player profile from a string?
example string please
?
to what method
sorry to ask this but, what is a method? today is my first day coding in java so idrk much
you should probably learn a little more java before using spigot
like atleast what methods arguments, constructors etc are
its ok i know enough
what is a method
not everyone knows that!
which is exactly why I reccomended sitting down and learning some basis
if you want to become semi-profficent in the basics it would take idk 2 weeks maybe if you go hard at it, otherwise just learn some lingo and throw together some basic non spigot projects and then try spigot again
ok but how do i make a string a playerprofile
im making a skin thing
the argument
the only thing I can think of is
Bukkit#getPlayer(String)#getPlayerProfile()
so the string is a player name?
?jd-s
so basically
declaration: package: org.bukkit, class: Bukkit
say i set the arg to notch, although notch hasnt joined my server, i still can set my playerprofile to notch
but idk how to make it notch
?nocode
It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.
you should probably be using Bukkit#createPlayerProfile(UUID) instead of Bukkit#createPlayerProfile(String)
public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, String[] args) {
if (sender instanceof Player p){
Object username = p.getName();
if(args.length == 0){
p.sendMessage("§cPlease set a skin to set!");
}
else{
String arg = args[0];
if (username.equals(arg)){
p.getPlayerProfile().getProperties().clear();
}
Bukkit.createProfile(arg).complete();
PlayerProfile profile = p.getPlayerProfile();
profile.setProperties(Bukkit.createProfile(arg).getProperties());
p.setPlayerProfile(arg).getPlayerProfile();
p.sendMessage("§aSuccessfully set skin to" + arg + "!");
}
}
return true;
}```
there is no such thing as setPlayerProfile
oh
is that a paper thing?
idk
looks like chatgpt tbh
// Object username = p.getName();
Why are you setting teh username to an object
when getName returns string
just because String extends Object doesn't mean you have to use object
probably because chatgpt
no, i made a version in skript-reflect and now im tryna make it with java
none of this code makes sense
this is why AI sucks
please again IK you will ignore me, but please learn basic java syntax and rules
there are so many things wrong with this code you could fix within a day or two of learning java basics
ok
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
here are some resources
https://www.w3schools.com/java/default.asp you can also use w3schools
even though It sucks for any level of complexity
the formatting reeks of chatgpt
i used kody simpsons tutorials and intellij fixes
Hi
youtube tutorials are more often than not going to reinforce bad coding principles be weary
not your fault just giving a heads up
imo the slippery slope with youtube tutorials is moreso not understanding what your writing vs the actual code being written itself
you dont understand it for a while then it all suddenly clicks is my experience
hey i can use same events in listener class?
most likely not necessary, but show some code so its more clear what you're asking
It’s not about the code, I’m just changing someone else’s code and I wouldn’t like to interfere with the code written by a person, but to make my own event
yeah, but you probably shouldn't
How much Java should I learn to code spigot
I mean just do it properly
atleast be confident in the basics
you can call a method at the top of the event listener method, then write your code in the method so it will not interfere.
can I listen to these events one by one with the same level of priority?
nWhat do you mean, really?
Hello, do anyone know how to add potion effect to a potion ?
public static ItemStack healPotion() {
ItemStack item = new ItemStack(Material.POTION);
return item;
}
My plugin is in 1.8.8*
?paste
I made an addon to hide inventory using "onguiopen" and "onguiclose", but it also hides the armor on the player, how can I fix it, that is, when "onguiopen" it is saved and deleted in "hashmap", when "onguiclose" the inventory is restored, how can I make it save only inventory slots in "hashmap"?
Hey, I'm experiencing a problem, my "savedItems" list for some reason is null when my code reaches end(), which ends the game and gives the player back it's initial inventory before the game had begun
https://paste.md-5.net/tubinirepi.cs
I'll do it and lyk if it fixes it
Why does it get nulled though?
Yeah Im thinking
it shouldnt get nulled
Im doing it somewhere accidentaly i think
I did, the debug messages return the list of itemstacks before the end() method
I'm testing it out
Now to think about it yeah ur totally right hashmaps would be a lot better
Than lists with a map
Lists with a pair*
How can i change the color off a potion ?
what's the packet to make an entity glow?
that's really helpful man especially when the only things that come up for "glow" are particles
and how do i do that
My favourite minecraft website
Is it possible to make a potion itemstack splash ? (1.8.8) i am chearching for ages please help
First result on google https://www.spigotmc.org/threads/giving-a-splash-potion.267328/
Read the forum posts ._.
Didn't get this result, it work so thank you so much!
I want to open iron doors and trap doors with a specif item . My Item check works fine but if I set the door Open it does not open:
public void open(Block block) throws IllegalStateException {
Openable openable = (Openable) block.getBlockData();
if (!openable.isOpen()) {
openable.setOpen(true);
block.setBlockData(openable);
} else {
throw new IllegalStateException("Block is already open");
}
}
u prolly need to call this after opening it https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/BlockState.html#update()
okay thanks
How can i apply a potion to a new entity ?
Is it possible to make the entity my splash potion*
i dont understand what u mean
Kody simpson
Is he good
i learned with him
do u mean u want ato add multiple effects to the same splash potion?
i want this potion to be launched when i right click with a item ```java
Potion pot = new Potion(1);
pot.setSplash(true);
pot.setType(PotionType.INSTANT_HEAL);
pot.setLevel(2);
ok so whats the problem
you would prolly need to construct an itemstack from it
and spawn it as Item
Create a ThrownPotion entity
but id just use PotionMeta tbh
nah wanna spawn a splash potion with these effects i need to go
yea i know...
.
It's a projectile so you can launch it
?conventions
same
Oh boy
In all tutorial videos they types something how to know what that thing is
watching?!
Yeah I don’t quite understand that question
You can use the javadocs
?jd-s
Thanks dude
Why I use this code will give all changes to ScoreBoard for all players
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
List<SerializeScore> scoreboardLines = QUEST_SCOREBOARD_MAP.get(player.getUniqueId());
Scoreboard playerScore = player.getScoreboard();
clearScoreBoard(playerScore);
Objective questScore = playerScore.registerNewObjective(SCOREBOARD_NAME, Criteria.DUMMY, "进行中的任务");
questScore.setDisplaySlot(DisplaySlot.SIDEBAR);
if (scoreboardLines == null) {
return;
}
for (SerializeScore score : scoreboardLines) {
questScore.getScore(score.getName()).setScore(score.getValue());
}
}
I want to change only this one player's scoreboard
They likley all have the same scoreboard
Is there any good way to copy a scoreboard and put it back in set?
I understand if they are all of the same class
package me.kurtu.main;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
public class main extends JavaPlugin implements Listener{
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onEnchant(EnchantItemEvent event) {
if (event.getEnchantsToAdd().containsKey(Enchantment.MENDING)) {
event.setCancelled(true);
}
}
}```
I coded a plugin that blocks the repair spell, but it doesn't work. why
How u guys learn this much stuff 🥵
Because mending will never be in an enchanting table
by default anyway
Can anyone help me send a respawn packet with protocl lib?
I found this code online, but it's giving an error 'Field index 0 is out of bounds for length 0' for the line writing to the world keys. How can I figure out what I need to write and where?
I'm struggling to find the information I need in here
wiki.vg does not reflect what protocollib sees anyway, you'd need to check the source with the actual packet java fields
Isn't it just better to check actual code of NMS to see how it instantiates this packet and provides the parameters that needed?
probably
That isn't Mojmap
If you stuck somewhere in NMS and there is absolutely no info on internet and wiki then you may have to read the actual code that represents it, I suggest to have always a remapped buildtools folder in your projects, so you can search about stuff there
I usually do like: grep -rnw ./buildtools/ -e 'new Packet...'
Then get the line, read the source and see how it works
No as long as you're not interested in chunks and regions
Molding Devs mostly rely on reading/modifying codes rather than just asking, because mojang doesn't provide them anything at all
And as md5 mentioned, if there is a way to do it in spigot, that would be a better decision, because spigot is made to simplify things
Yeah I can't do it within spigot
IS there a quick way to revoke all advancements of a player (like the revoke everything command)?
?paste
For some reason a player's death location only updates when they receive a respawn packet
I need to change a player's death location on the client without killing them
Why
because "https://paste.md-5.net/tejezanacu.cs" if i pick a fish dont rieve it?
Because I need to change the direction of a recovery compass
I see
as that is the only compass which works in the nether and overworld
well there is also the lodestone compass
but that changes the nbt data when you update the direction
So setLastDeathLocation doesn't update the compass
meaning it reappears in the hand which looks wack
no
I have to do that, and then send send a respawn packet afterwards
Ah yeah I see it in the docs
yeah
There is a setcompass method
that's a regular compass
I use it for bedwars
it does not work in the nether
I need my compass to be crodirectional
oh
good question
wait there's a respawn method?
hmm, I can test it but I suspect it might cause some bugs
I saw this warning somewhere
which makes me wonder where in wiki.vg that actually is
cause maybe there's more info there
Yeah, block hit-boxes also gets mixed
mmm
Bukkit should cancel that if player is alive
Right so it wouldn't work anyhow
Or maybe
I'm just stuck on figuring out how to send this packet is all
Just try to read what's in there:
CraftPlayer->Spigot
because "https://paste.md-5.net/tejezanacu.cs" if i pick a fish dont go?
Ok it's quite long
there is this line lmao
entityplayer1.c.a(new PacketPlayOutRespawn(worldserver1.aa(), worldserver1.ac(), BiomeManager.a(worldserver1.A()), entityplayer1.e.b(), entityplayer1.e.c(), worldserver1.af(), worldserver1.z(), (byte)i, entityplayer1.gm(), entityplayer1.ar()));
You should mojmap
Yes, as coll says, mappings is the key to find these stuff
Run buildtools with --remapped flag

Yes
?nms
ty
ok great
done that
entityplayer1.connection.send(new ClientboundRespawnPacket(worldserver1.dimensionTypeId(), worldserver1.dimension(), BiomeManager.obfuscateSeed(worldserver1.getSeed()), entityplayer1.gameMode.getGameModeForPlayer(), entityplayer1.gameMode.getPreviousGameModeForPlayer(), worldserver1.isDebug(), worldserver1.isFlat(), (byte)i, entityplayer1.getLastDeathLocation(), entityplayer1.getPortalCooldown()));
so that's the repammed version of the respawnpacket packet which is sent in the respawn function
ok great I think that's given me what I need
How do I change the dimension though?
where can i look for collaborators to work on a project ? i would love to make a team since i have a great idea in mind
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
it will be something open source and non paid, does it still count as a service ?
Sure
thanks ! :)
why doesnt gradle support java 21 😭
Are you on the latest
oh dear lol
and now i need to redownload java 17 once again
so I've got the respawn packet 'working'
hooray
unfortunately it removes everything in the hotbar
and glitches when moving
it's like it's teleporting you lol
i think i did something like this before
on like 1.15
How do I actually change the dimension here?
right
it still seems to think the item is there
but I can't see it
ah
probably cause client doesn't think it's there but server does
Is there a way to just send an update death location
Or does the protocol not have that
why tf does minecraft run on tcp
this is such useless transport protocol for a game
udp should be used
bedrock runs on udp
no I don't think so
I think there's just the respawn packet
since there's no need for a client to be guaranteed that server sent data is correct
End of the day it doesn't really matter
Anyone know how i actually change the dimension here?
At least lets us do things like bundling packets together if necessary
Hi, my problem is i want to deactivate (normal) advancements and atm I'm handling the playeradvanceementdoneevent and revoking the first criteria again directly. This means that the advancement can be achieved again and again but is revoked directly which is why it doesnt show up but it seems unefficient that for example the every time a wood is clicked/picked up it hast to be revoked again and again but I cant seem to find a better way
Thx in advance
How do i get the default /help menu style in vanilla?
Isn't there a spigot.yml setting for that
but then my custom advancements wouldnt work or am i wrong
you can turn off advancements from the server config
but not easily in your own plugin only
maybe they will, try it out I guess
🤷
Yeah I mean I think they will as its just client packets but do I have to do it through spigot.yml or can i do it through my plugin?
You can probably do it with code
Should I use a varchar or a text type in mysql to store an encoded itemstack?
when the player dies or is killed, the "armor slot" and "off hand" items that I have separated from the hashmap are dropped, I just want them to be dropped in the hashmap, can you help me? : https://paste.md-5.net/ajemagaxun.cs
Alright, thanks
You can convert from and to with BukkitObjectOutputStream
Am I correctly storing the blob? XD
@Override
public <S extends Emblem> Promise<S> save(S entity) {
return database().executeAsync("INSERT INTO Emblems VALUES (?, ?)", ps -> {
ps.setInt(1, entity.getId());
byte[] encodedItemStack = InventorySerialization.encodeItemStack(entity.asItemStack());
ps.setBlob(2, new ByteArrayInputStream(encodedItemStack));
}).thenApplyAsync(p -> entity);
}
Just store the byte array
Yeah why is such a Mess working with ítems outside spigot yaml seriliazer?
?
Because items suck
Not as bad as mine 😎
Could You help me with this?
I know You already helpme too much
Nah busy atm
It's okay np
Methods to go to and from bytes for various things could be added tbh
What are the best way for doing platform independent code. It's mainly abstracting right?
Only problem is somehow getting the data version in there
yes
k
guys
does bukkit have an abstraction for events that have an entity that has an inventory
ok wait nvm
I think PlayerEvent is good enough
nah im just making a util method
Alr
so i pass an event theough it
but i might just make it so u have to event.getEntity() or /getPlayer
Then you gucci :)
Another way is to pass a Supplier<extends Entity> or Function<super Event, extends Entity>
Dk what exactly is going on but yeah depends on what exactly ur needs are
But do you guys think its gonna be noticeable in any way I mean it should run through pretty quickly right? I dont want do disable anything in configs in case of other modes that need it.
how does the function one work
super Event?
🤑
well that just assumes you have some event object of type Event already
But as said
would it be extend?
If you dont need those lambda types dont use them
oh you dont litterly mean event do u
I do
Oh that part
Its because an object of type Function<Object, Player> should be passable
if event is an object of type Event
then you should be able to invoke
Function<Object,Player> as much as
Function<Event,Player>
Wdym how
im so confused
so like
if I were to pass in idk EntityDamageEvent how would that work
Never said you should
…
the Function interface?
Yeah thats the Function interface
no like
Its used in Optional#map CompletionStage#thenApply
Stream#map
etc
why would I use that function
what would it be used for
if it was super Event extend Player
I mean anything
There are really a lot of things
Everything depends on what design you wanna use when you write your infrastructure
Why 😡 i was told by a dev this must work and have it done too before