#help-development
1 messages · Page 2006 of 1
world.getEntitiesByClass(Item.class).stream().filter(i -> i.getItemStack().getType() == Material.SOME_TYPE).forEach(Item::remove)
Nice
i have 16g Ram r5 3500 x and 2060 nd running 1 server and 3 mc is hard
I didn't realize getEntitiesByClass existed
is there a sympiler way
Yes
for (ItemStack item : world.getEntitiesByClass(Item.class)) {
if (item.getItemStack().getType() == Material.SOME_TYPE) {
item.remove();
}
}```
Simpler but longer
im guessing thats 1.18 then
oh that's easy ok
does anyone know how temporary players and sockets work using protocollib?
I think I accidentally just deleted everything
Hold the fuck on
nvm it just bugged out
thank god
💀
How would i make it so all the enderchest have the open animation at all times? Have been on it a while and it is driving me crazy.
probably gonna have to use packets for that iirc
np
Ye i have been experimenting with that but cant get it to work
no wonder. my online status is set to offline
oh 👉👈🤌
There's a blockstate updating packet iirc, you'll want to prevent that from being sent if it's an enderchest being closed.
Who need help? - Cuz i see a tag
i will check that out
ItemStack is deprecated. what to use instead?
ItemStack cannot be deprecated
?
but I cannot find a deprecation annotation or notice there
Prob its your IDE
Yea idk, whatever you are doing. ItemStack in the spigot API is not deprecated
I rember that when using Eclipse i was always having warnings, etc. And them when i changed to Intellij Idea i started to enjoy more the pugin development
well, i might have seen something wrong, but thats what intellij decompiled from the maven sources for me ```java
/** @deprecated */
public ItemStack(@NotNull Material type, int amount, short damage) {
this(type, amount, damage, (Byte)null);
}
/** @deprecated */
@Deprecated
public ItemStack(@NotNull Material type, int amount, short damage, @Nullable Byte data) {
this.type = Material.AIR;
this.amount = 0;
this.data = null;
Validate.notNull(type, "Material cannot be null");
this.type = type;
this.amount = amount;
if (damage != 0) {
this.setDurability(damage);
}
if (data != null) {
this.createData(data);
}
}```
So in my opinion eclipse = yeath
those are the constructors
not the entire class
the concept of damage is no longer applicable
this has been this way for a while
Yeah, agree
ok
well, then why the heck did a tutorial that i had once set the damage and then 10 lines further not? ||(short) 15||
because the tutorial is trash
Well, an outdated tutorial either kept up to date or is useless
not all items have the concept of durability
Do you have experience when settings player permissions on bungeecord?
I didnt find any tutorial
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/Damageable.html#setDamage(int) is used for durability
declaration: package: org.bukkit.inventory.meta, interface: Damageable
and what perms on bungee o.O ?
Yeah im trying to do a custom permissions plugin for bungee
Im done from Spigot side. Now i need bungee side
I mean, on bungee you can only handle bungeecord permissions
I already know
Oh you do it via event?
can I replace a broken block in a blockbreakevent with another block? i was cancelling the event and setting the block, but that causes durability damage to not be taken for the tool
I thought its was like spigot that you have PermissionAttachment, and others utillities
or can I simulate tool damaging by calling a method or similar
You could just wait a tick and then set the block to something else rather than cancelling the event
He can prob set the block to air?
i've thought of that too but the result would look kinda weird
And thanks for the info
kill05, try setting the block air and them replace it with what ever you want
You really wouldn't be able to tell the difference
also i'd rather be able to do this since i like that cancelling doesn't let the player through the block
now that i think about it
You could try manually adjusting the damage of the player's tool.
what should i consider? unbreaking enchant and?
Ah, someone already suggested that.
...
...
Pretty sure that's all, @misty current unless there's plugins adding custom enchants.
i guess i could call an itemdamageevent and see the outcome of it
or whatever the name is
That event wouldn't run if you cancel the blockbreakevent surely.
yes that's why i want to call it myself so if any plugin manipulates how much does an item get damaged, my plugin can adapt
Ah, you said call the event. Yep, sounds decent.
You can call the event
Don't forget to spawn block breaking particles!
luckperms on the servers and then database to save?
oh yea else it would look pretty weird
No i dont like to depend on other plugin
In doing my custom
Because i didnt find any plugin that allow me to have global groups, with bungeecord and spigot permissions at the same time
why bungeecord permissions though?
Because we use bungee plugins
how to set a block on fire
is getType deprecated in 1.18
no
Enum<Material> itemType = event.getCurrentItem().getType(); //Method invocation 'getType' may produce 'NullPointerException'
?jd can help you
no i meant for itemTypes
it states that the method will produce that
HOWEVER
If I fix it, or dont, it never works
Check your code prob you are doing something wrong when you coded
The fact that now that ive migrated my plugin to 1.18, and my ClickEvent isnt working
That's just IDEA telling you that the return type is nullable
It's not deprecated
But, clickDetection isnt working now
public class ClickEvent implements Listener {
@EventHandler
public void clickEvent(InventoryClickEvent event){
Inventory inv = event.getClickedInventory();
if(inv != null){
String Title = inv.getType().getDefaultTitle();
Player p = (Player) event.getWhoClicked();
if(Title.equalsIgnoreCase(ChatColor.DARK_RED + "Challenges")) {
Enum<Material> itemType = event.getCurrentItem().getType();
Did i do sometihng wrong here or
Also, you don't need to do Enum<Material> :p
Just do Material
and should probably keep var names lowercase
true
Also you haven't given us your full code
true
how to set a block on fire (like tnt)
true
pretty sure there is a material for fire
you just set the block to the fire type iirc
public class ClickEvent implements Listener {
@EventHandler
public void clickEvent(InventoryClickEvent event){
Inventory inv = event.getClickedInventory();
if(inv != null){
String Title = inv.getType().getDefaultTitle();
Player p = (Player) event.getWhoClicked();
if(Title.equalsIgnoreCase(ChatColor.DARK_RED + "Challenges")) {
Material itemType = event.getCurrentItem().getType();
if(itemType == Material.POTION) {
if (EmeraldsPlugin.jp.getConfig().getBoolean("Challenges.BlockDamage")) {
EmeraldsPlugin.jp.getConfig().set("Challenges.BlockDamage", false);
PluginFuncs.sendGlobalMessage(ChatColor.GREEN + "The challenge, Block Damage, has ended.");
} else {
EmeraldsPlugin.jp.getConfig().set("Challenges.BlockDamage", true);
PluginFuncs.sendGlobalMessage(ChatColor.RED + "The challenge, Block Damage, has started!");
}
me.emerald.emeraldsplugin.ui.Challenges.getUi(p);
}else if(itemType == Material.ROTTEN_FLESH) {
if (EmeraldsPlugin.jp.getConfig().getBoolean("Challenges.Hunger")) {
EmeraldsPlugin.jp.getConfig().set("Challenges.Hunger", false);
PluginFuncs.sendGlobalMessage(ChatColor.GREEN + "The challenge, Hunger, has ended.");
} else {
EmeraldsPlugin.jp.getConfig().set("Challenges.Hunger", true);
PluginFuncs.sendGlobalMessage(ChatColor.RED + "The challenge, Hunger, has started!");
}
}
me.emerald.emeraldsplugin.ui.Challenges.getUi(p);
}
}
event.setCancelled(true);
}
There
?paste
Hello]
hello
i need to know the registry changes in 1.18.2 idk where to check
https://gist.github.com/UntouchedOdin0/4c145998b1b3fd00441dd806768e863b where am I going wrong? I can't seem to set the right locations :/
Variable name should always be un lower case
No problem just something to keep hen programming
Hello, I can't save schematic, even file doesn't get created, any help/advise?
https://paste.md-5.net/iraluziqiy.js
Oh, before I forget
getServer().getPluginManager().registerEvents(new ClickEvent(), this);
This is what is actually getting the event to register
whats the entire stacktrace?
Schematic Iteration Problem
what is line 49 in class "save"?
BukkitWorld weWorld = new BukkitWorld(p.getWorld());
appears to be null
Block#setType()?
lol
nice!
e.getBlock().setType(Material.FIRE);
right click and rename
Can you help in making it not null? Because I don't know what to do anymore
ye, this should do it
i can't see where the rename button is lol
refractor?
oh yea
try using the world of one of the locations, instead of the player
mhm
better?
what about ctrl +alt + L :D
I dunno what that is
doesnt work
My formatting is already perfect, bruv
even i know that
cap
I've been trying to work out where I'm going wrong with this code and I can't work out how to fix it but Idk where I'm going wrong 😔
send it
ctrl + alt + o pretty usefull too
removes unused imports
alt f4 pretty useful as well
My imports are already perf- nah I'm kidding
It makes me honestly angry that I get thrown by these stupid fucking things
Ah yeah, I use that one actually
it's sick
Hey.. so how would I get the title of getClickedInventory?
its suppost to return Challanges
but returns Chest or CHEST
still null
I can learn the worldedit api ok-ish but i can't work out how to add these block vector 3 locations later on
can I get an instance of an item in a player's inventory so if I modify it it changes in the player inventory too? looking at the implementation of PlayerInventory, getting items returns a clone of the original itemstack
Ive tried:
event.getClickedInventory().getType.name();
event.getClickedInventory().getType.getDefaultTitle();
None work however
Is there a way to actually get the name of the inventory? The name is Challenges.
Dont tag, be patient...
*patient
Sorry!
well, how do you get these locations
I'm just going crazy 🥲
oh thanks
Can you show the name of a custom enchantment on the item?
?
Or is that entirely client sided?
player.getOpenInventory().getTitle()
Why dont either compare full Inventory oject? isnt better?
gimme a sec jeez i had forgot the name of the method
i've just sent him what he asked
probably it would be better to check for the actual object
np
dont tag...
Its not allowed
I rember i get muted for 1h for tag people
Who are you tagging?
?
also, final question: How would I give a permisson to a person, and do permissions save?
Just use a permission plugin for that. (LuckPerms is the standard) It’s not worth the hassle to set permissions manually.
I prefer making my own personally
I mean LuckPerms has a good api in case you wanna have a good permission "library"
Just use Vault lol
I get that, I really do, but if you don’t know how to register everything properly, it can cause big issues. Especially if you are creating a plugin for the general public. I’d at the very least look into the API LuckPerms provides as you can do a lot with it.
Alright, ill do so.
How would I protect an item from being renamed to be used for malious purposes?
My thing is based on itemName
When right clicking to use
So how would I make it so that even if they renamed an item
They cant use it the same
Don't use the name to detect your item
Use the PDC instead.
Also, world exists
apos1.getWorld().getName() returns world name aka world
Share your code
I’m pretty sure the #save method requires a File object, not a String.
It wouldn't compile if that were the case
maybe it takes a file path too
tbh i would just use the #save method that takes a File
ty
If i have an armorstand class that runs a gui class (w events inside of it), am i still supposed to register the gui class in my main class?
hey, ive seen this tutorial https://bukkit.org/threads/how-to-make-an-item-glow-with-no-enchant.374594/ but in the constructor of Enchantment there have been some changes in the last 7 years and it requires a NamespacedKey and not an int anymore
how do i need to do that now?
Same thing just use your NamespacedKey
how do i get that?
You can just make one
how?
?jd-s
Found out and fixed it, it was because of shade plugin from maven
Use it's constructor
new NamespacedKey(this, "whatever");?
If i have an armorstand class that runs a gui class (w events inside of it) on right click, am i still supposed to register the gui class events in my main class?
It's because you're not verified
that’s whether it’s unsafe or not
Meaning can it go above the vanilla maximum and can it be applied to stuff it normally can’t
Are there any tutorials on how to make a key crates?
so... the enchant i want to apply is custom and for getItemTarget() it returns null. what should i use?
true or false
true
how do i get the item someone just clicked from InventoryClickEvent? tried to use getCurrentItem() but that returns null
getCurrentItem()
read again and then try again
getCurrentItem() and then make sure the clicked slot does not contain null
what's the fastest way to see if a plugin is running on bungeecord?
but when you click the item, you take it into your hand and then you dont have anything in that slot
Its on the cursor after the event fired. (If its the right action)
So you have to call getCursor() on the next click event to get the ItemStack currently on the cursor.
ok
Check if PluginManager#getPlugin(String name) does not return null
I tried isPluginEnabled, let me try that
It's made marginally harder by the fact that i don't know exactly what Geyser would even be called
Hey \o
I have no idea how hex colors work, but I'd like to iterate through most of them to achieve some color changing leather armor.
Does anyone have a tip for me?
NMS with gradle
i know how to translate them when they are in the format #ffffff
rgb is 3 integers each going from 0 to 255
or in hex from 0x00 to 0xFF
If represented as a single integer then those 3 integers are bit masked
besides each other.
This will result in all values from 0x000000 to 0xFFFFFF
Thanks, let's see what I can do with that 👍
could you theoretically extend the piston push limit with a plugin?
without to much coding of moving the blocks manually of course
Use the Bukkit Unsafe instead
Just incrementing this int by 5 will look a bit weird. If you want to have smooth translations then you should
represent rgb as a 3D vector [r, g, b] and slowly change pitch, yaw (and length)
Is there an event for cancelling swimming faster? This -> https://static.wikia.nocookie.net/minecraft_gamepedia/images/8/84/Swimming_Steve.png/revision/latest?cb=20190919172717
Try if sprint toggle is called
Ok ty
smile go particle thing plis?
what
That could be really janky though
If they have sprint toggled on clientside it would just be choppy as hell wouldn't it
if i have a Custom Enchantment and then create a new instance, is that another instance than the instance created in onEnable when registering it?
Yes. I dont... every time you create an instance its a new one
It should be a singleton
^
But doing it by extending the Enchantment class is clunky to say the least
Cannot recommend
yeah, but when i need it anywhere else, it is easier than getting it again from the main class
pls dont...
No it's not lol
Just make it a singleton with a static getter or something if you must
can i use switch case for item stacks? i mean insted of a long list of if else for checking item stacks, how can i use switch case ?
No, you can't use a switch for that
Neither. You should use a map instead.
But you really shouldn't need to
You could do an instanceof but it is just a waste of memory imo
Try to minimise the amount of allocations
So yeah, you should use singletons
Look into functional interfaces and then use something in the neighbourhood of
Map<Integer, Consumer<InventoryClickEvent>>
the constructor asks for a Player
yeah so how do i
Jesus, you coded that plugin, you should know what you are doing
cos i cant j type player p or p or whatever
You should refractor your listener
I am almost certain that you should not pass a player there
aaa, i can't understand this stuffs, thanks but i'll keep that weird if else xd
give us the constructor of SpawnGUI
It may be right - but right now you have a player tied to an event which does not sound correct
think its an inv tho
Especially because this appears to be the onEnable method
its made to open an inv on armor stand right click
Then you shouldn't register you event listener in the onEnable method
just ping if answer to me
But it is more conventional to generalise event listeners to a point of it not being tied to a specific object
?help
selfrole Add or remove a selfrole from yourself.
cleanup Base command for deleting messages.
embedset Commands for toggling embeds on or off.
info Shows info about CafeBabe.
licenseinfo Get info about Red's licenses.
mydata Commands which interact with the data CafeBabe has about...
set Commands for changing CafeBabe's settings.
uptime Shows CafeBabe's uptime.
findcog Find which cog a command comes from.
names Show previous names and nicknames of a member.
userinfo Show information about a member.
listcases List cases for the specified member.
reason Specify a reason for a modlog case.
permissions Command permission management tools.
?paste ?
ty
thats the SpawnGUI class
i was doubting already if i had to register it or not in my main
But the events are j not working
the onlick event & dragevent
oh i got the same method name twice dumb
What are the callers of the constructor of your SpawnGUI class?
Sorry, this is kinda new for me so i don't really know
Inventories etc r new for me
whats your sql statement?
Eclipse or IntelliJ?
Welp, then I do not know the shortcut to show the caller hierarchy
Anyways, my suggestion is to remove line 27 and to change line 23 to public SpawnGUI() {
If you have any compiler errors that pop up, let me know
Shut, do as I say
You can still call openInventory afterwards, but for that I need to see what compiler errors the change causes
theres no errors
does anyone know any shorter method of doing this?
File file = new File(fileName);
if(!file.exists()) {
try (
InputStream inputStream = DiscordSpigotUpdateBot.class.getResourceAsStream("/" + fileName);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
) {
String line;
while((line = bufferedReader.readLine()) != null) {
bufferedWriter.write(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
oh perfect! Then we solved you issue
basically I just wanna write a resource to file
And how am i supposed to open the inv then
Call your openInventory method
You're not closing your resources in this
Yes. Several.
but then im just going back to my old code
of course I do
it's a try with resource block
it auto closes them
not in the constructor
declaration: module: java.base, package: java.nio.file, class: Files
Call the openInventory method where you want to open your inventory
Just not in the onEnable method and the constructor...
oh forgot to mention, it should work with java 8 too
legacy people
Files#copy is J8
-.-
At least I think so...
oh yes
It is
Most of Files are since j7 iirc
90% of my projects are Java 8 lol
It is, and stupid android is holding us back
my condolences
Maven Import Issue (Don't wanna interrupt convo)
Files.copy is so weird
if it wasn't for android noone would use J8 ad there wouldn't be any libraries for J8
it takes a CopyOption but that class doesn't have any public members
Nah I would still use Java 8
I can never remember how the class is called
StandardCopyOptions
I don't like the module system
How do i access an inv from another class in my current class
You know that your IDE has a hotkey to show the class hierarchy?
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
does android still use java 8?
No
you can just ignore it ?
Not really
Nope :)
That’s the spirit
Even when not using modules, you're still restricted by them
It doesn't use java anymore anyways
Without any context: yes
It never did
They went from DEX to ART iirc
n uh what am i supposed to do w that
The only time you are restricted by modules is if you fuck with jdk internals
Nowadays, they just recommend using Kotlin as the source lang since it better suits their API
E x a c t l y
that was for mfnalex
if you fuck with jdk internals you are doing something wrong
oh oops mb
Not exactly
wdym?
pretty often
There's a lot of features that JDK internals provide
In eclipse you can just press F3 on CopyOptions and it will show you the classes that implement copy options
e.g. the Javac Tree API, ConstantPool, CallerSensitive, etc.
And that you should not access because most users run JREs
JDK internal != JDK exclusive
"90% java 8"
does the JRE bundle javac apis ??
JDK exclusive shit is JDK tools and APIs (Attach API, JVMTI, etc.)
No but said API allows you to create stronger compiler plugins :)
With Oracle's pussy-ass public API, you can only do introspection
No modification
Problem is that, iirc, all JDK tool APIs are restricted by modules, even the public parts
does anyone knows what types of exceptions the exception handles catches?
the (t, e) ->
aby?
Except perhaps anything not instanceof Exception
then any throwable
\n
LinkedList vs LinkedHashmap?
Yes
that occurs whilst submitting a task on the executor?
Those aren't comparable
Now?
They're completely different data structures
Arent Linked all the same thing?
No. Later.
While execution
oki
if i have a inventoryclickevent listener and check if that inventory is equal to another inventory, does it say its equal if the inventoryclickevent has removed or rearranged items in the inventory?
LinkedHashMap has almost the same runtime complexities as HashMap
Oh Linked things are diff?
I know this is a dumb question but how do u space messages out, like making them on different lines
LinkedList has almost the same runtime complexities as ArrayList
LinkedList is a doubly-linked list (dynamic array), LinkedHashMap is a map (dictionary) that retains insertion order
I thought they were the same
This has already been answered
So they will be used on Queue systems?
send it in multiple messages
Wither use the new line character \n
or send multiple Strings after another.
No, Deque is for queues
In conclusion Linked thing are diff?
Well, yeah
Allright thanks
LinkedLists are trash. The only use case is O(1) insertion/modification while iterating
like that?
I know but they have key Linked and i confuse them
Only similarity is that they're collection types (and even then, Map is not a Collection)
😕
idk
they are. And nowadays they are as good as an arraylist for iteration
sendMessage(x);
sendMessage(y);
sendMessage(z);
thats car to carpet
Not me, but many people confuse them. And say they are the same
The only thing it has going for it is that it is easily resizeable
won't that just send multiple messages?
Yes
No they are not. 2.5 to 5 times slower depending on memory spacing.
or C and Crack cocaine
many packets lol
Yes, that was what I meant
Relatable
Nah those are at least tangentially related
ins't that what you wanted?
Since most C programmers are on crack
oh
Otherwise, why would they be coding C?
C with Java? Hmn
you only realize how convenient the builtin config methods in spigot are when you only have plain SnakeYaml in a discord bot
why the hell did you use snakeyaml
no
for easy config files
just use org.json:json but not snakeyaml
Just throw everything into Gson or Jackson. Latter even supports yml
Json configs 🤡
Isn't that lib outdated?
json is a pain to edit
Here's an even easier solution:
Just hardcode it 🙂
🙏
awesome idea!
the hell is toml?
For everything i use SnakeyYAML its not so difficult lmao
A beautiful, beautiful language :)
it is maintained, so not outdated by my standards
Looks like a shity ENV file
e.g. systemd files are toml
SimpleJSON is though afaik
Lies
Uhh no
u wanna start a fite?
The best language is LUA
System = ENV file
Roblox developer detected
is this like json or something kek
negative acknowledgement
the best language is ((((((((((((((((((((((((
LUA
))))))))))))))))))))))
I cant use any bungee commands even though I have * perms on bungee, till yesterday I could
yes
I have a friend that its develoer of FiveM
FiveM is modded GTA 5 multiplayer
- doesnt exists on bungee
I mean I do have the perms set to true for my plugin as well
...why would you react to your own message?
true
I agree
php its the best shity things
Idk why the still mention to learn it
They should be taken out from the world
Like? Give a single example in 5 seconds.
I added setPermissionMessage("test") to the command but its still saying unknown command
bruh
Shity sintax, you cannot do it modular, many things
Learn Visual basic for that
Use lots of jumps. Makes the code robust.
Sorry but VB is not as bad as Assembly lol
VB is better than C?
No I can understand it lol
oof. No.
I just understand that it's awful
what happens to the client if i sent an uknown packet by him
It's filled to the brim with terrible historic decisions
The stack table probably
Throws it away
ARM would be easier to learn but I can't really run ARM
An goto statement complicates computing the stack table attribute by a lot
Excuses
goto makes your code horribly unmaintainable
Excuses!
That is true
Well, it'd be harder to track which locals may not be initialised and which are
Actually
I would love to use C# for doing plugins
Its better for using Sockets
But
J1.5 exclusive iirc
It no longer does anything
goto is reserved but unusable
This guy is a troll bot for sure
It was replaced with invokedynamic
No
Goto is usable at a bytecode layer
Excuses!!
jsr was for finally blocks
so if i write a plugin that sends some custom packets and a mod to read them, the client would not crash, right?
Ah
using spigot and fabric
Why use custom packets
invokedynamic just came out of nowhere lol
If you have a mod then you can accept whatever packets you want
Use that one packet mojang added for this purpose
Technically you can emulate goto statements with while (true) loops and break; and continue;
Yes, JVM subroutines existed primarily because of finally blocks
C# sockets are better than Java
They eventually made it so that finally blocks are now just inlined wherever they're used
.prepareStatement("SELECT * FROM es WHERE something=?");
statement.setString(1, getConfig().getString("example"));
ResultSet results = statement.executeQuery();
results.next();```
I haven't figured out how to compile C# on my system yet, so I cannot comment on that yet
They have pretty much the same approach. Java just has so many more libraries for that type of stuff.
Maybe he is a linux only user
i want to deal with sounds
Somebody help?
You can easily communicate with client mods using Plugin messaging channels
In C# you have already built in librariers when using Multi client against Java that you have to implement your own multi cliente...
How would I find a public function based on a string?
EX: String is named BasicKey, and im looking for public static ItemStack BasicKey
Reflection
k
On runtime? Then reflections.
how do i check for players in the server?
google common is included inside spigot jar?
- weird column name "something"
- Whats the issue?
Yes, that is Guava
You should do a while (result.next()), if not it will just return the first result
Thanks
May I ask how those entirely work? They seem a BIT confusing.
Should I send my code?
?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.
Agree, as always
- for testing
- I get error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'something''' at line 1
I was already given a site, asking for a bit of explanation on what they do exactly
I dont agree. Reflections are not part of the basic java skillset.
public class Items {
public static ItemStack BasicKey(){
ItemStack item = new ItemStack(Material.TRIPWIRE, 1);
ItemMeta iMeta = item.getItemMeta();
iMeta.setDisplayName(ChatColor.GREEN + "Basic Key");
iMeta.addEnchant(Enchantment.DURABILITY, 1, true);
ArrayList<String> iLore = new ArrayList<>();
iLore.add(ChatColor.GOLD + "A key! can open a basic crate.");
iMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
return item;
}
}
Im trying to find "BasicKey" based on a command argument.
Thats the issue.
But why use reflections when you are just starting?
I mean
Organization and ease of access?
Generally you just avoid them altogether
Reflection is quite slow
Use a map
Ah
Or whatever
Looks like you have quite a bit of ' signs in there.
It's only really for when you need to do something dynamically
ur verbose
I agree
you never add lore
Are you sure?
Yes
Im looking my spigot maven dependencies and doesnt contain Guava
Contains google common
Because it's a transitive dependency
transitive?
It's a dependency of a dependency
Yea lol
I wouldnt expect your answer sorry
What
Nerd fight!
No I meant

Yea lol*
surprised you don't have guava in your maven local
My b
lmao
I don’t reply to the message, I see the confusion there
🥲
Should be installed?
Wait
What should I do to check a results?
Conclure is better than me tbh
import/build enough projects and eventually it will find its way there 😛
But I'm still like 2nd or 3rd
bump
I think that if you install a dependency it should install their transitives? Hmn
sometimes
but generally yes
in this case it should put Guava there, in fact running buildtools should have done it
how to reapir it>
that is why I am surprised it isn't installed in your maven local XD
Guava does have some handy utilities though
like it has mechanisms already for caching stuff
And if you wanna get all the results when doing a "SELECT * from table WHERE something=?", you should do it inside a "while" if not, only first result will be catched.
public void query(String query) {
PreparedStatement statement = getConnection().prepareStatement(query);
ResultSet result = statement.executeQuery();
while (result.next()) {
logger.log(Level.INFO, result.getString("field-1"));
logger.log(Level.INFO, result.getString("field-2"));
}
}
It's based off of Guava's caching, it's supposed to be better
I for my part really like it
public static Function getItem(String item){
HashMap<String, ItemStack> itemList = new HashMap<>();
itemList.put("BasicKey", BasicKey());
if(itemList.get(item) != null){
return (Function) itemList.get(item);
}else{
return null;
}
}
Any way I can make this more efficient?
Don't make a new map each time
Function...?
Raw typed even
I have to
If you're a developer, you can contribute to the QuickShop code! Just make a fork and install the Lombok plugin
God dammit lombok
why? I really dont see what the map does.
Hold on, ill send full code.
public class Items {
public static ItemStack getItem(String item){
HashMap<String, ItemStack> itemList = new HashMap<>();
itemList.put("BasicKey", BasicKey());
if(itemList.get(item) != null){
return itemList.get(item);
}else{
return null;
}
}
private static ItemStack BasicKey(){
ItemStack item = new ItemStack(Material.TRIPWIRE, 1);
ItemMeta iMeta = item.getItemMeta();
iMeta.setDisplayName(ChatColor.GREEN + "Basic Key");
iMeta.addEnchant(Enchantment.DURABILITY, 1, true);
ArrayList<String> iLore = new ArrayList<>();
iLore.add(ChatColor.GOLD + "A key! can open a basic crate.");
iMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
iMeta.setLore(iLore);
item.setItemMeta(iMeta);
return item;
}
}
Can someone explain to me how do I use vectors to spawn block on top of location of event block?
Block.getRelative
Still makes no sense. You just create a new map, put an ItemStack in there and get it again...
If I place the hashmap outside of getItem however, .put errors
You need to learn about scope
Scope..?
But currently your method does literally the same as
public ItemStack getItem(String item) {
return BasicItem();
}
Im adding more items later on.
Wait
I want to be able to return the correct function based on the item String.
So that I can get the item requested
every time I read this, it always makes me think of 360 no scope from CoD
I smell a learnjava coming
This is a very important part of java
I have been learning java thats the thing lol
How else will that entry level position open
because I do not want to work hard
Yeah but you wanna get paid good
you need to be 25 with 30 years of experience to be overqualified
I spent 3 years building knowledge, and I have 5 days of experience.
Fuck I'm only 23 with 13 seconds of experience
hm since yaml supports anchors, etc... does it also allow to concat strings? lol
Oh ye fun fact
sth like
prefix: &prefix "https://something/"
something: *prefix + "something"
There's this thing you can do called a YAML bomb
I am legit so confused how I'm going so wrong lol
but what's the syntax for it
a: &a ["lol","lol","lol","lol","lol","lol","lol","lol","lol"]
b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g]
i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]
hm seems like simply concatting strings is not possible with yaml
^ This expands to 3 gigabytes or smthn
can you listen for block stripping?
It's also possible in XML
or do you have to check it urself with interact events
<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ELEMENT lolz (#PCDATA)>
<!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
<!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
<!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
<!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
]>
<lolz>&lol9;</lolz>
Interact events I imagine
you can get paid pretty decent for some entry level jobs. Maybe not at first, but after a while generally you can.
I need it for plain strings though, not lists or anything
lol
I'll just use a regular %placeholder% or sth
yeah i guess
In computer security, a billion laughs attack is a type of denial-of-service (DoS) attack which is aimed at parsers of XML documents.It is also referred to as an XML bomb or as an exponential entity expansion attack.
can you check if an item is an axe or do i just check for the name of the material
Hmm
same for logs
Lesse
This is why you don't support recursive macros
Logs have a tag
always hilarious how some small prank turns into a serious thing
check the material or material name
I normally just do name().endsWith("_AXE")
aight thanks
sad
no there's only tags for MINEABLE_AXE
I would prefer an EnumSet that is filled with axes once and then used for contains()
probably you could use nms to check for that but its pointless
But what if mojang adds a new axe
yeah me too but sometimes you gotta use the name
Like when?
e.g. when you have 1.15 users and cannot use Material.NETHERITE_AXE
Delete them
of course one could just create a set at startup
How can I set a players health to maximum using attributes
hey im having trouble setting a value to my config.
im trying to do
player.getUserFile().set("cooldowntoggle", !player.getUserFile().getBoolean("cooldowntoggle"))
player.getuserfile returns a yamlconfiguration
my problem: it doesnt set it. i know that my other code functionality works because i can set the value manually through the file
setHealth(getAttribute(maxhealthything).getValue)
getAttribute isnt a thing
p.getInventory().addItem(foundItem);
This correct to give a person an item?
Note: fundItem is an ItemStack
*found
yes
do java records support clone() ?
Why wont it give it then?
Seems to just.. not work
When doing it
private static final EnumSet<Material> AXES = EnumSet.copyOf(Arrays.stream(Material.values())
.filter(material -> material.toString().endsWith("_AXE"))
.toSet());
This would be version agnostic, no?
it doesnt work for some reason
hello guys how can i take money(TNE) by using CommandExecutor
what
No idea what TNE is but usually by using Vault
player.setHealth(getAttribute(GENERIC_MAX_HEALTH).getValue); isn't working
I am trying to get a villager to open another gui but for some reason this isn't opening the new gui, the openNewGUI() work with another method of opening it up but this specifically doesn't work. If you can explain why this isn't working I would appreciate it!
@EventHandler
public void OpenGUi(TradeSelectEvent event) {
event.setCancelled(true);
openNewGUI((Player) event.getWhoClicked());
}
im trying to take money from the guy by 1 command
used commandexecutor but dont know how to do
Then use Vault
what is vault
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
String item = args[0];
if(Items.getItem(item) != null){
ItemStack foundItem = Items.getItem(item);
p.getInventory().addItem(foundItem);
}
Any reason why the player isnt receiving the item? Before you ask, no, getItem is working, I tested that out.
Its just the giving that isnt working for some reason.
yeah that's what I normally do too if I need it more than just once or sth
well not exactly this, but basically the same 😄
but shouldn't you use name() instead of toString() ?
Sure. Doesnt make a difference here but usually you should use name() for enums
Attribute.GENERIC_MAX_HEALTH
i know this thing, i want player to perform a command by using 1 command
Add a sysout in there to check if its called.
I mean if player performs the command i made, it will execute another command
I did, thats the odd thing.
I did sysout checks n everything.
Its reaching it, just not running.
if (sender instanceof Player p){
it's saying required type is double
Thats bad practice. But search for dispatchCommand in the javadocs
Unless thats incorrectly done
?jd
ayone?
Dont use data like that. When the player joins -> load all data into classes and variables. From then on you dont touch the file.
When he quits then you save the data again.
So there is an open PR for this, but it was made in 2016 and had changes requested in 2021
@lost matrix Just a note: p.getInventory().addItem(foundItem) when using in system, returns: "{}"
So uhh... it may be a bit dead
Which is perfect
The return map is the items that failed to add
Show the whole code please
k
Here is the item im trying to get:
private static ItemStack BasicKey(){
ItemStack item = new ItemStack(Material.TRIPWIRE, 1);
ItemMeta iMeta = item.getItemMeta();
iMeta.setDisplayName(ChatColor.GREEN + "Basic Key");
iMeta.addEnchant(Enchantment.DURABILITY, 1, true);
ArrayList<String> iLore = new ArrayList<>();
iLore.add(ChatColor.GOLD + "A key! can open a basic crate.");
iMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
iMeta.setLore(iLore);
item.setItemMeta(iMeta);
return item;
}
Here is the command:
package me.emerald.emeraldsplugin.commands;
import me.emerald.emeraldsplugin.EmeraldsPlugin;
import me.emerald.emeraldsplugin.Items;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class SpecialGiveCommand implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
if (sender instanceof Player p){
if(p.getName().equalsIgnoreCase("AnEmerald")){
if(args.length > 0){
String item = args[0];
if(Items.getItem(item) != null){
ItemStack foundItem = Items.getItem(item);
System.out.println(p.getInventory().addItem(foundItem));
p.getInventory().addItem(foundItem);
}
}
}else{
p.sendMessage(ChatColor.DARK_RED + "Invalid permissions to use this. You must be an administrator to use this.");
}
}
return true;
}
}
Also, I tested getItem, it works
As it DOES return the item
Oh, and here is the setExecutor
getCommand("specialgive").setExecutor(new SpecialGiveCommand());
Is the itemstack amount 0
It doesn't seem like it, but that's the only real guess I've got
new ItemStack(Material.TRIPWIRE, 1);
shouldnt be
wait does the command run at all?
what exactly is the problem?
^
yea bu
sysout the ItemStack before you add it
Sure
add debug statements
is the players name equal to AnEmerald?
is Items.getItem(item) != null ?
what does your System.out.println print?
hold on, im testing 7smile7's thing..
I am like 99% sure it doesn't even get to the System.out.println
what is the command line's command
i mean
i want command line to execute the command
@lost matrix ```java
ItemStack{TRIPWIRE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"green","text":"Basic Key"}],"text":""}, lore=[{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gold","text":"A key! can open a basic crate."}],"text":""}], enchants={DURABILITY=1}, ItemFlags=[HIDE_ENCHANTS]}}
10.03 21:24:19 [Server] Server thread/INFO ItemStack{TRIPWIRE x 1, UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"green","text":"Basic Key"}],"text":""}, lore=[{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gold","text":"A key! can open a basic crate."}],"text":""}], enchants={DURABILITY=1}, ItemFlags=[HIDE_ENCHANTS]}}
Prints this sucessfully
Bukkit.getConsoleSender() or sth
Then the ItemStack is added
depends on where he is printing that out
sounds suspiciously like another log4J-style problem in the making
Yet its not giving it to me
At all
Which is the weird thing
Cause it should be right?
System.out.println(p.getInventory().addItem(foundItem));
what does this print?
the sout you already had included
It prints {}
I already told 7smile7 that
That means that i got added
yeah exactly
So then where is it being placed? In the void?
you said you have checked all the if() clauses right?
Yes
In the players inventory
what's the exact command you're typing in the chat
print out all contents of the player's inventory after it was added
/specialgive BasicKey
just to be double sure it actually got added and if yes, into which slot
I mean if it is sysouting the result of addItem
Then obviously the if statements aren't the issue
How do I send images?
verify
Im trying to send the fact, that my inventory is empty.
just do for int i = 0; i < inv size; sout(i +" -> " + inv.getItem(i))
sth like that
wait a sec does sender instanceof Player p initialize Player p = (Player) sender ?
yes
lul
paste a lightshot link
I would use
public void printInventoryContent(Player player) {
System.out.println(Arrays.toString(player.getInventory().getContents()));
}
instead
Trying now

