#help-development
1 messages · Page 2033 of 1
The problem is that he created a while loop that checks for true instead of the boolean breakFree
no it changes the whole logic
your current code only sets it to true once
and once it once gets set to false, it stays false forever
I did if(e.getInventory().equals(mainGui)){ e.setCancelled(true) }
if you move it inside the loop, it can actually become true again
yeah but later on, it gets set back to true anyway
How can block equal material
@tender shard Read my last post.
no. where?
So that breakFree never true.
you set it to true once and then once it gets set to false once, it stays false FOREVER
when I run it again
Then It stucked
you don't run it again, it keeps stuck in the while loop
because you refuse to move the breakFree = true into your loop
in my main class I run it later
here I will change it and see
brb
also you can't change it from your main class, it's a local variable
Hey… organize your thoughts
ngl the whole code is a huge mess
@lime jolt you know how can’t your code break?
I've never seen so many duplicated lines
🙂
yes, that's another thing
that is big problemo
a block will never be equal to a material enum
But that’s important
what would I change that to then?
You all are missing the basics here.
He wrote this
boolean breakFree = true;
while (true) {
// Code Inside
}
```He made a while loop that checks **true**. This will **always** be running.
He should have instead done this:
```java
boolean breakFree = true;
while (breakFree) {
// Code Inside
}
getType().equal
getBlock().getMaterial?
Yeah
I will try that
getBlock().getType()
aright I will try
aright thanks I will try that
nah, he wants to do the opposite
he wants to loop while breakfree is NOT true
Hello ! i use Player#sendBlockChange and i want to rotate a furnace with block data
BlockData furnace = Bukkit.createBlockData(Material.FURNACE);
player.sendBlockChange(new Location(Bukkit.getWorld("world"),1386 ,4 ,1513),furnace);```
furnace spawn with blockFace to the north
Bruh,
boolean breakFree = true;
while (!breakFree) {
// Code Inside
}
Can someone help me with that? https://www.spigotmc.org/threads/cant-connect-to-mysql.550738/
yea but that's basically the same as their current version if he would have just moved down "boolean breakFree = true" into the loop. The biggest problem was comparing blocks with materials
Hm
Cast your blockdata to directional
okay 🙂
the IP or port MUST be wrong, or it's an internal IP that's not reachable, or it's firewalled or sth
And change blockface
I added the debugs and for some reason it's not detecting that I clicked something in the inventory
did you forget @ EventHandler?
Send it.
did you register your listener?
Hey
You need to detect name of gui
Not detect gui
No
Yes
why would someone use strings if they could just properly check for the inventory?
what does that even mean
add a debug text at the top BEFORE checking if the inventory is equals()
does this get printed when you click?
Hm
No
ok
Yes
The eventhandler is ready I think
Where can I see my port? I never changed it, so i thought ill use the default, but maybe something weird happend
If you can compare something smaller in value, why wouldn't you?
So problem is check
Also, a direct object comparison would be far more accurate than a string comparison.
Now it prints it
print out both inventories, tehy are probably not the same then
Check name is the best way I can think,
Otherwise you can check the item of inventory
wdym
System.out.println(e.getInventory());
If you only check inventory equal
and also print out the other inventory you're comparing to
What if you add something to inventory
That doesn't matter.
using strings to identify inventories might work but it's a very bad idea, other plugins might create an inventory with the same name, then you're fucked
nothing happens, it's still the same inventory
It's an instance of an Inventory. The inventory instance doesn't change.
exactly
Oh you’re right
it's the same as this:
Person a = new Person("mfnalex");
Person b = a;
b.setName("TangJin");
b is still == a now
It prints that I clicked inside an inventory but it doesnt print when I click inside the maingui
My fault
show your full event code pls
?paste
oh
full code
ok
it's a big big one
send the code where you open the inventory pls
Hm
In this image he did correct
hm that looks like it should work
ye me is confused
Uh
add this in your listener ad the very top:
System.out.println(e.getInventory());
System.out.println(e.getClickedInventory());
System.out.println(mainGui);
Show me where you register your eventlistener
ok
I guess you have to use getClickedInventory instead of getInventory
Yes
Do you think that's due to the Inventories being split into views?
Like top and bottom inventory?
Cause that used to work like that.
maybe, we know it when they send the output of the sout's
that makes no difference
== only work when memory location is same
it refers to the same object
[16:43:53] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@1c28b366
[16:43:53] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@1c28b366
[16:43:53] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@23996f3f
[16:43:53] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@1c28b366
[16:43:53] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryPlayer@45ab0f42
[16:43:53] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@23996f3f
``` it logs this idek what it is
Remember the inventory click event fires for every inventory.
Why there are 6 inventory
Can’t you just click once?
It should only log 3 inventory right?
Idk
?paste
@tender shard did you see that?
I'll try wat mfnalex said
That not same memory location.
I'll use getClickedInventory instead
see it
In this case
getInventory is same with getClicked
But different with mainGui
That’s weird.
yeah
my code is just broken
lemmie check if there's something wrong outside of this class
maybe it's not registered correctly
check the event's getView().getTopInventory() instead of the clicked inventory
hm
then it wouldn't print anything
oh true
If clicked is on top then it just output same
Yeah
yeah but it also should be the same as the mainGui so idk lol
the thing is
I think so too
but it isn’t lol
breh im so confused
nothing inside if (e.getClickedInventory().equals(mainGui)) is working
Because you are using .equals instead of ==
ur supposed to
Since when?
it does the same
equals() or == makes no difference
I mean im so stuck rn so Ima try what shadow said rq
yeah no difference
😛
That’s a little different.
If some object overwritten equal method then it works
it does the exact same thing
Ok, so @tender shard you were right about the top inventory. It's the correct instance.
Like string
yes but Inventory doesn't override it. CraftInventory does override it, but it's basically also the exact same thing
@pliant oyster Compare your mainGUI to the top inventory using InventoryClickEvent#getView().getTopInventory()
hm
alr
inventory.equals() is the same as Object.equals()
You know? CraftInventory extended Inventory
obviously, that's what it's for
it's the implementation of the Inventory interface
same as with CraftPlayer and Player
and basically anything in Spigot
of course it works, it makes no difference whetehr they use equals or == in this case
does anyone know how to "sendTitle" to everyone on server
Iterate over Bukkit#getOnlinePlayers() and use the built in sendTitle method in the player object.
.spigot().sendTitle
I don’t have pc for now
Bukkit.getOnlinePlayers().sendTitle
Uh
u sure that works?
That’s lambda
You don't need .spigot(). The Player class has a method for titles. Player#sendTitle()
You could always do it the old fashioned way.
for (Player player : Bukkit.getOnlinePlayers()) {
}
I uses spigot because I working on old version and newer too.
maybe bcuz the thing that runs openCratesMenuGui() is in a different class
I'm using a command to run that function
tangjin
does anyone know how to see if someone died?
Or you can still try use title to check
PlayerDeathEvent
the class that runs the function is in a different class
Hm
Is the instance of that class null?
Uh no
idk
There is a isDead method
Can you share how you are calling it?
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player){
Player player = (Player) sender;
CrateSystem crateSystem = new CrateSystem();
crateSystem.openCratesMenuGui(player);
} else {
sender.sendMessage("You must be a player to use this command!");
}
return true;
}```
Well, that looks fine to me. What's the openCratesMenuGui code?
it opens the gui
Did you register the command?
Can you share the CrateSystem class?
yes
So I am looking to get a spiral projectile trail with 2 particles opposite to each other, I've managed to do it but it's only horizontal and I want to make it change as the projectile changes, so I'll somehow need to account for the yaw and pitch. Any trigonometry experts have any ideas? xD
?paste
thank u
Is there any Packet for setting the player's pose? (Stop crawling/swimming)
Sorry, I don't think I caught the issue you are having here. Is the inventory not opening or is something else not working?
the inventory is opening
but everything inside the if (e.getInventory().equals(mainGui)) isnt
how do i pass a variable type as an argument in a method? I want to make it so i can use the same method but with different types
Did you do what I recommended earlier?
what
Change your comparison. Compare your mainGUI to the topInventory using InventoryClickEvent#getView().getTopInventory().
idk how to do that lmao
You don't know how to write an if statement?
I do
just that I have no idea wym
ohh
if (e.getView().getTopInventory().equals(mainGui))
like this
Yes
the InventoryClickEvent#getView returns an InventoryView which basically consists of two inventories
like when you right click a chest, the upper one will be the chest and the lower one the player's inv
it still doesnt work
Try the == comparison.
What's the output of your debug messages? Because they should be the same at that point.
System.out.println(event.getInventory());
System.out.println(event.getClickedInventory());
System.out.println(event.getView().getTopInventory());
lemmie re add them
if something is already == it will definitely be equals() too
there is no real situation in which equals will be false while == will be true
What about if it's overriden?
[17:14:12] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@755d3550
[17:14:12] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@755d3550
[17:14:12] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@755d3550
now it's working
what
yeah if you override it to simply return false, sure, but that's not a real situation
Output the mainGUI too.
my brain is not wokring rn
anyone know how to clear everyones inv
ok so
Player#getInventory().clear()
it prnts
[17:18:09] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@1cdb1a55
[17:18:09] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@1cdb1a55
[17:18:09] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@1cdb1a55
[17:18:09] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@7f019c5
``` now
thx
@tender shard You got any insight on this? His inventories should be comparing properly now, but aren't for some reason.
I have no idea :/
Non-static method 'getInventory()' cannot be referenced from a static context
if they return the same hashcode (e.g. if sout is the same) it should be equal()
You better not have copy pasted exactly what I sent.
of course you need a player object
wait
Could it be a difference between the method used to create the inventory? Creating an inventory with an InventoryType vs an inventory with a fixed size?
what
Cause in my testing, I'm setting a size and getting the proper comparisons.
I don't think that would be the issue
wanna see something funny?
double nan = Double.NaN;
if(nan != nan) {
System.out.println("This actually gets printed! Wtf!");
}
Then again, I'm storing the instance of the inventory in a map.
wana see something even funnier ```
boolean isTrue = true;
while(isTrue){}
Try making the inventory final.
uhh alr
same thing
honestly wtf is wrong with the code
can you show ur code?
?paste
hello! i'm trying to make a verification plugin and i need to store some data in a database (username, uuid, password etc..) I tried by doing this but it stores each "value" in a different row, how can i put those values in one row? (i made 3 methods for the username and the uuid and the password). ```java
public void setName(String name){
this.name = name;
PreparedStatement namePs = null;
try {
namePs = conn.prepareStatement("INSERT INTO users (username) VALUES (?)");
namePs.setString(1, name);
namePs.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}```
INSERT INTO users (username, uuid, password) VALUES (?, ?, ?);
yeah but i want 3 different methods
then setString(1, ame);
setString(2,uuid);
setString(3,password);
like 1 for each value
then use UPDATE users instead of INSERT INTO users
oh okay, thank you! imma try that
INSERT obviously creates a whole new entry 🙂
bruhh yeah
Does someone know how can I'll make a effect like this when I'll go over a Armorstand with my view?
fairly sure that's a mod only thing
what mod is that
Its not a mod
yeah that's what i was thinking too
if its not a mod what is it
I mean this is also not a mod
that's a texture pack
Yeah
yeah but that's more explainable
I can say its not a Mod
mhmm idk
not closing statements hmm ;-;
what server is that
?
origin realms does such hover-over things too
Use try-with-resources
But do you know how they made this?
Also you're supposed to cache PreparedStatements lol
idk how to send the thing
World of Wonders minecraft Themepark server
pretty new to mysql stuff haha
That’s at the driver level
You don’t manually cache them yourself
Isn't the point of a PreparedStatement that it precompiles the SQL statement or smthn?
A prepared statement is associated with a Connection, it doesn’t stand alone
?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.
The database driver can do the prepared statement caching but you’re not supposed to do it yourself
So uhh?
https://stackoverflow.com/a/56336447 @lavish hemlock
You’re trying to web hook between the MC client and server?
@pliant oyster @tender shard I figured out why the inventory instances were different.
Website sends a webhook request and Minecraft plugin picks it up.
didnt know you could call methods on an array
That error almost looks like you’re trying to connect like a player would
Wdym
Well I mean yeah
builder.addBotListener("context", new VoteWebHook(), "auth");
builder.setPort(25565);```
An array is just an Object
how can i get the server name in bungeecord config from a spigot plugin? something like Bukkit.getBungeeServerName()
@Override
public void onWebhookRequest (BotWebhookEvent event) {
Bukkit.getLogger().warning(event.getVote().getUserID().toString() + " has voted!");
}
}```
You can’t use port 25565 if the minecraft server is already using it
So use a different dedicated port than?
You’re going to have to implement some sort of data transfer between bungee and spigot server for that information to be obtained, and run a bungeecord plugin to do it with
Yes
Where do they have this?
@pliant oyster To solve your problem, you need to stop creating new instances of your GUI and instead use one instance of it instead.
i thought arrays were primitives
I see
Nah, they're references.
Keep in mind that's done with a resource pack.
ye but i mean the price thing
@tender shard I can't believe I didn't realize this earlier. If you have Inventories that you are creating in a class like that and then register events for that class using a new instance of that class. The listener will be tied to those instances. Of course it wouldn't have worked. You need the initial instance in the first place.
Think of it like this.
You need three things for a custom inventory to work. (In this specific setup.)
- The class
- The inventory
- The listener
Think of this as a sort of metaphorical "bundle".
So, now what happens when you create a new instance of the class? You get the following.
- The new class
- The new inventories
The bundle is incomplete because you don't get the new listener. That's why there is mismatches between instances.
¯_(ツ)_/¯
I don’t know anything about the library you’re using
Well do you know what packet id 79 is?
What version
hey so i know this isnt a discord bots help but i need help making a discord bot that works with my plugin
this is my code :
var sqlId = "'"+id+"'";
connection.query("SELECT UUID FROM " + linkTable + " WHERE linkID = " + sqlId, function (err, result, fields) {
if (err) throw err;
if(result.length == 0){
console.log("not found");
}else{
console.log(result[0]);
return result[0];
}
});
}````
and it returns this :
```{ UUID: '3e8eac9d-c886-47a1-937c-5f0dfdf6114b' }```
how can i make it only return the uuid value ...
Cast it to a UUID?
wdym?
WHAT
Read this #help-development message
A result set can return multiple things right? So you need to cast the result to the proper object type.
me or him
you. My bad
ok I have no idea wym
To put it simply. You need to change your current approach. You have a simple solution and a slightly more complex solution.
The simple solution is to create on instance of your custom inventory class and pass it around to wherever you need.
OR
The complex solution is to create an inventory manager that handles creating inventories and can keep better track of instances.
There is technically a third solution, but I think it's frowned upon.
listen man, does it seem like my brain is big enough to comprehend what you said?
Anyone?
Not the solution I was talking about, but that's how the manger would handle things.
I do. You know java right? I too get confused with the terminology from time to time, but when I re-read it, it usually starts to make sense.
yeah ish
I'm bad at translating verbal stuff into code if yk what I mean
Well, I'm not trying to spoonfeed an answer, but I can try breaking it down further.
would someone be able to help me with this
Ok. You know how instances work correct?
Inventory inv1 = Bukkit.createInventory();
Inventory inv2 = Bukkit.createInventory();
Inventory inv3 = Bukkit.createInventory();
All three of those are separate instances of the same class. They all have the same methods, but are different based on content and the memory address that's assigned to them.
yeah
You could always include your own equals method though if you make an abstract class or something
Think about what happens when you create an instance of something inside an instance of another object.
In your case, you are creating an instance of Inventory inside your CrateSystem class.
Let's say you did this multiple times.
yup
Instance one of CrateSystem will have an inventory instance with it's own ID.
Then in another it will have another instance with another ID.
according to console
[17:53:56] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@22e1f12d
[17:53:56] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@22e1f12d
[17:53:56] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@22e1f12d
[17:53:56] [Server thread/INFO]: org.bukkit.craftbukkit.v1_18_R1.inventory.CraftInventoryCustom@6cbecd29
CrateSystem crateSystem1 = new CrateSystem();
CrateSystem crateSystem2 = new CrateSystem();
CrateSystem crateSystem3 = new CrateSystem();
something I am doing is changing mainGui right when I click it
Yes, do you see how the last one is different?
yeah
Why do you think that is?
it was changed
Not quite
That instance wasn't changed. Instead you are now dealing with a new instance.
maybe cuz I did
mainGui.setItem(10, emeraldOreItem);
mainGui.setItem(12, diamondOreItem);
mainGui.setItem(14, goldOreItem);
mainGui.setItem(16, ironOreItem);
``` right before the player opens it
Which is because you created a new instance of the CrateSystem class to open the GUI to the player.
That new instance will have different instances of the Inventories created inside.
Which is what you see in console
Now, how do you solve this?
The simplest solution is to just have one instance of CrateSystem.
There is nothing wrong with that. Even if you set the contents after you opened the inventory, you would just need to call Player#updateInventory();
yo, does anyone know what this means? java com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Illegal double '23e516' value found during parsing
Exactly what it says. A double can only contain numbers.
Likely an issue with whatever method is parsing the data.
Or the way it was implemented into your project.
but i'm not using doubles
What are you using then?
WTF
since when did playerupdate inventory exist
never heard of that
I thought it automatically updates bruhhh
It does for the most part, but there are times when it needs to be called.
Just depends on what you are doing.
If you set the items first, then open the inventory, you don't need to call updateInventory().
You would want to call it if the inventory is already open and you want to change items inside it.
so this should fix it?
would anyone know why warped fungus isn't registering as a material?
It's not going to fix the issue you are currently facing. That method has a usecase which doesn't apply here.
What version of spigot are you depending on?
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>remapped-mojang</scope>
</dependency>```
brO
Check your import.
import org.bukkit.Material;
And you ran BuildTools normally?
yup
what's gonna fix it
Only thing I can think of is an issue with maven. Have you tried restarting intelliJ? Or invalidating caches and restarting?
i've restarted multiple times, don't know how to do the latter
it is different?
File ---> Invalidate Caches
I normally clear these.
Btw I know now how they made this system
resource packs
Wdym by use outside?
And Raytracing
Kinda hard todo
idk I thought thats what u meant
do I update the inventory when the player clicks it?
inside the InventoryClickEvent
Not unless you are changing the contents of the GUI when they click an item.
breh
ok so
I'ma try to use my brain here
for a moment
the first 3 logs is the inventory that the player has opened
and the 4th log is the mainGui inventory
are they not the same inventories?
What does the output say? If they do not have the same output. Then no, they are not the same.
Does someone here knows how raytracing is working with spigot?
the first 3 are the same and the 4th one is different numbers
but why arent they the same?
the inventory that the player opens is the mainGui
I N S T A N C E S
wtf do u mean by that
That is not a bleb-friendly word!
I thought you knew what they were. I even asked that at the start.
And you said yes.
Also, no I can't ?jd you because instances are a basic concept of Java itself.
Yeah I knew what they were now I have no idea wtf u mean by that
?jd @pliant oyster
oh wait
I thought jd is learn java
LMDFAO
well either way
dont do either one on me
speak in bleb friendly language
So, you do understand that every time you create a class like this:
MyClass clazz = new MyClass();
You are creating a new instance of that object.
Ok, now. You understand that applies to EVERY single thing in Java correct?
It also applies to this:
Inventory mainGUI = Bukkit.createInventory();
my english is asking what is bounce
A variable refers to an instance of a type.
Similar to a reflection. It will bounce off a wall.
(Alternatively, it can also refer to a primitive value, AKA a number like int i = 0)
thanks
ye
I never called them instances or stuff like that tho so I didnt know what he meant when he said that lmao
Ok, that clears some of my confusion up. 😛
Another synonym: ricochet
That's what I was trying to think of .-.
The variable is just used to access the internals of the object.
It's more correct to say the members of the object.
A member is any element that is nested within a class.
i.e. fields, methods, and inner classes.
Although, you don't need a variable to refer to an inner class, just an instance of an inner class.
Actually, you do if you're using a non-static inner class.
True
Anyways. Referring back to my original statement. What happens when you have instances inside of instances?
Potential for mismatch.
idfk
yes.
Now, every time you create an instance of CrateSystem, it is also unique.
oh
Combining the two together will create something even more unique.
so it opens a different inventory
Yes
Yes!
well how do I get it to be the same one lmfao
fuck sake
DI isn't very complicated
Either way
The easiest way I can explain it is that
it's not a bleb-friendly word
Instead of having your objects create instances of other classes
You create an instance in your main class, then create a getter for it. Use your main class to call that getter in other classes.
You pass a dependency (instance your class requires) to your class's constructor
Here's a code example
public class ReallyCoolCommand implements CommandExecutor {
// The instance of your main class.
private MainClass plugin;
// The constructor
// Require the constructor to take whatever class you need as a pramenter.
public ReallyCoolCommand(MainClass plugin) {
this.plugin = plugin;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
plugin.whateverMethodsExistInThatClass();
}
}
eh
w/o DI
public class Example {
public Example() {}
public void announceExplosion() {
// The problem here is that we might not want a Bomb, we might want a Nuke or Dynamite instead!
Explosive exp = new Bomb();
exp.explode();
System.out.println("kaboom");
}
}
w/ DI
public class Example {
private final Explosive exp;
// This will now allow us to use any kind of explosive.
public Example(Explosive exp) {
this.exp = exp;
}
public void announceExplosion() {
exp.explode();
System.out.println("kaboom");
}
}
And this is how you would use the DI version:
new Example(new Bomb()).announceExplosion();
new Example(new Nuke()).announceExplosion();
ig that works?
Basically, DI helps us to untether our code
Does anyone know what plugin or how they configure in the anarchy so that people start transfer in a separate place and then fall into the overworld?
We depend upon the superclass (Explosive) rather than the concrete type/implementation (Bomb)
lemmie try to use my brain rq
Don't ask why I decided to use terrorism explosives in my example.
Cause you are chaotic neutral.
Another example of DI is what Shadow mentioned, which is using DI over something like a Static Singleton.
Sounds accurate
instance of what
That's the benefit of DI. It can be anything you need.
my friend is downloading intellij for the first time and is getting harassed by this window saying they have to get a jetbrains license
Use the community edition instead.
ah ok
is there a different way
Unless he has a school email, then the community edition will work just fine. It has like 92% of what the Ultimate Edition has.
Yeah but it's unpreferable. DI is the cleanest, most maintainable way to do it.
what are the other ways lol
Static singletons :p
fuck sake
I'm gonna write a blog post on dependency injection just so I have something to copy-paste :p
I need shadow masters version
Dependency inject these nuts in your mouth
shadow idk how to call the method without create a new instance of it
fr
A simple DI example:
public class InjectedClass {
public InjectedClass(App app) {
// Do staff with app
}
}
public class App {
private InjectedClass injected;
public static void main(String[] args) {
this.injected = new InjectedClass(this);
}
public InjectedClass getInjected() { return this.injected; }
}
Correct me if im wrong
No that would just be a getter
For it to be DI, you'd have to pass InjectedClass to something else
Idk if you need mine specifically. Maow's example is what it needs to look like.
It's just an example though.
@lavish hemlock now its correct? - Sorry for tag
https://minecraft-heads.com/custom-heads/decoration/50905-stack-of-newspaper
there is a command to get the head. if i have the data then how do i chagne a player head to the one i want
Yeah, pretty much
This example is the one you'll see the most
There is two ways. GameProfile or NMS.
NMS?
It also depends on what value you are taking from that link. If it's the mojang link, use GameProfile, if it's the base64 value, use NMS.
im not taking any valuse from the link
`
`
/give @p minecraft:player_head{display:{Name:"{\"text\":\"Stack of Newspaper\"}"},SkullOwner:{Id:[I;-963021313,-1681963191,-1745649695,-970650732],Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmQ1YjU4ZDZlN2Q0Y2Q5ODdkMDgxYjkxZWZlMDllZTBkMjA3OGYwZGI0M2Y1MGQwYTZjZjNiMzI3NzBhZWE0ZiJ9fX0="}]}}} 1
this is the command to get the head
it need a command block
You can do it via command too
this is a command block
just exeucte __ /give @p minecraft:player_head{display:{Name:"{"text":"Stack of Newspaper"}"},SkullOwner:{Id:[I;-963021313,-1681963191,-1745649695,-970650732],Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmQ1YjU4ZDZlN2Q0Y2Q5ODdkMDgxYjkxZWZlMDllZTBkMjA3OGYwZGI0M2Y1MGQwYTZjZjNiMzI3NzBhZWE0ZiJ9fX0="}]}}} 1__ directly on game...
i want it so. if a player places a player head on a diamond block it changes to the newpaper head
how would i do thjat
newpaper head? what that
newspapter head
You need to apply the texture to the block when they place it down.
how do i do that?
?jd
Listen for the BlockPlaceEvent, create the player head with the custom texture, and then update the blockstate.
create the player head with the custom texture
that is what i dont know
He explained here...
yea, i know how to make a player head
So??
but i dont know how to set a texture
I dont udnerstand you lmao
or update the block data
That its from the documentations
You cannot have everything served on the table. You have most of the time to read the docs
public static final Material PLAYER_HEAD
BlockData: Rotatable
im still lost
Deprecated.
all usage of MaterialData is deprecated and subject to removal. Use BlockData.
but if the only block data is rotation
then how do i do it
Use the block state
how can i set the break stage of a block?
where
I'm so confused on how to do this
sendBlockDamage
thansk!
will i need to send it each tick?
because the player can be far from the block
What do you need? Tell me so i can try helping you
ok so I'm trying to call a method from a different class without creating a new instance of it
the thing shadow told me idk how to do
Send your classes on ?paste please
Make the constructor take an instance of whatever class you need as it's parameter.
?paste
when I do that, In the main class I need to change the registerEvents thingy
send class code so i can help...
wait
Yes. You just need to pass a variable into it at that point. Instead of a new instance.
Like this you have to do it
public class InjectedClass {
public InjectedClass(App app) {
// Do staff with app
}
}
public class App {
private InjectedClass injected;
public static void main(String[] args) {
this.injected = new InjectedClass(this);
}
public InjectedClass getInjected() { return this.injected; }
}
a variable of the class?
Ble look at my example
The variable name you use to reference the instance you are creating.
in that one, you're creating a new instance of injected class
I dont think you can pass constructors params without creating a new instance?
thats the thing
You can
I need to do that without creating a new instance
rlly?
Because you cannot declare static constructor
If you already have an instance somewhere, pass it through
when i use this in different blocks, the first one is set to normal
The main problem is that i cannot help if i dont see his code. I dont understand what he is doing
1 pitch = 16 blocks, right?
You can only use teh sendBlockDamage on one block at a time
well then what do I put inside this parameter
What's it asking for?
it says I need crateSystem
and how can i send for multiple blocks?
You would have to handle packets yourself
so now I create a variable of CrateSystem?
np then
Pass in an instance of CrateSystem then. If you already working inside that class, use the this keyword.
k
ugh, whyyyy? https://paste.jeff-media.com/?2ef2642d75926ef1#GqsvnVQYDcjADoLsirwUnSTJocrmmomounQD1N62PrHk
Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.
so I have to create a new instance?
instance
Give me a few so I can explain this clearly.
alr
What did kacper's turtle ever do
I needed a hostage...
why won't this compile D:
pom.xml: https://paste.md-5.net/bodugaxobe.xml
error: https://paste.jeff-media.com/?2ef2642d75926ef1#GqsvnVQYDcjADoLsirwUnSTJocrmmomounQD1N62PrHk
(It worked fine yesterday, lol)
Visit this link to see the note. Giving the URL to anyone allows them to access the note, too.
I think we need to cover the basics again.
// Declaration of an object.
// The object is null at this point.
private Object obj; //This is an example. This object can literally be anything.
// Object instantiation.
// At this point, the object is no longer null.
obj = new Object();
```The name you give the object is your **reference** to that object. It also acts as your reference to it's specific instance.
So when you call obj.whateverMethod(), you are accessing a method within the object.
Now, what if you need multiple objects? Java allows you to do that. You just need to create a new instance with a different name.
```java
Object obj1 = new Object();
Object obj2 = new Object();
Now, you have two separate instances of the same class. What you do with each one now is up to you. Whatever you change in obj1 with it's internal methods will not affect obj2.
Another neat perk of java is the ability to pass object instances into methods.
So if you have a method like this:
public void myCustomMethod(Object object, int value) {
object.whateverMethod(value);
}
You would call the method and pass in your instance that you created earlier.
myCustomMethod(obj1, 12) //The number I chose is arbitrary.
breh
what do I put inside the parameters tho bcuz I have to but a cratesystem in there and I cant do that without creating a new instance of it
Run -X and see the full exception
You put whatever it asks for. If you don't want to create a new instance, then you need to pass one through that you have already created.
ugh fixed it by using maven-shade 3.3.0-SNAPSHOT instead of 3.1.0. It's just weird because yesterday it worked fine and I didn't change any dependencies or similar stuff in the pom lmao
If it's in another class, then you need to pass it through however many subclasses you need.
do I create another constructor of it in the main class then
You could create a getter for that object in the main class.
idk how to do that lmfao
Is there something to register permissions?
At this point I might just have to tell you to learn java. .-. Getters are also basic.
registerPermission?
declaration: package: org.bukkit.plugin, interface: PluginManager
Ye I haven't learned java fully before spigot but still
I didn't expect it to be this complicated to just use a method without creating an instance of it
Well, therein lies the problem. You don't actually know java. :3
Lmao I don't need to fully know it
Uhm like make custom permissions like pluginname.dothis.thing
to do stuff like this
Yea, but you need to know the basics.
The basics cover things like this.
?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.
You can define custom perms in plugin.yml
I'm like one of those ppl who learn by spoonfeeding
And the check them anywhere with gasPermission
Is that really learning though?
yes
bcuz I understand how it works when I get the answer
ofc I can learn java and use my time on that but it would take much longer for me to learn
But there are multiple ways to achieve the same result when it comes to programming. How will you differentiate between them if you don't actually understand the concepts behind what you are writing?
I do lmao
I only write stuff that I understand
You've demonstrated that you don't actually know the terminology though. I've been trying to explain to you that the issue you are having doesn't require a complicated fix. However, I'm also using some of the basic jargon. Don't you think it would be far more beneficial for you to at least learn that before just jumping straight in?
No
Is there any Packet for setting the player's pose? (Stop crawling/swimming)
It will take much longer to learn the entire language it self
I would have to use something once and then I learn how to do it
Idk how to create getters and setters bcuz I never did it before
I'm not saying you need to learn the entire language. You just need to learn the basics.
No one here knows the entire language.
Not to mention that it's constantly changing.
.
I would have to use it once to learn how to do it
how to i apply a texture onto a player head
why havent i found this before
perfect hashing of two integers with no collisions
so cool!
Am I doing anything wrong here? Im just trying to get discord-token, but when I change the config it still gets the old token
you need to save the config
you also have to reload the config using reloadConfig()
You need to reload the config if you make changes manually.
if you're changing it inside code
or reload it inside the code if the changes were made externally
Can I just add reloadConfig at the beginning?
yes
but normally you want to have a reload command
that's why commands like /<command> reload exist
just to trigger the reload of the configuration files and other thingies
if you ever upload this to github, don't forget to remove your token from the config 😄
Yea I know
is there any perfect hash method of hashing a three int values
what is a "perfect" hash method?
hash which has no collisions
How can I get the text from the anvil that I entered?
It still doesnt work with configReload :(
you could bitshift your numbers to turn them into one number, depending on long your numbers are
the first answer puts three ints between 0.255 into one int
if your numbers are larger, you can probably do the same thing with longs
what's the largest number you'd have to store?
i thought i could do some arithmetic like a * 100 + b * 10 + c but i don't know the limits of c
that's the problem
well are they integers?
an int is 4 bytes, a long has 8 bytes so that'd only work for 2 ints
but that wouldnt work
can't you just use a string to represent them
and you would need to use longs
How can I get the text from the anvil that I entered?
String.format("%d,%d,%d",a,b,c); lmao
i don't care if they're reversible or not
declaration: package: org.bukkit.inventory, interface: AnvilInventory
Thanks
what do you even need the hash for? that would be helpful to know
im preparing for an exam, and its in c++, you can't use STD libraries there so i need to design how to do this as fast as i can
i have bunch of values that are tied together, map would be great in this case
hey, im new and trying to get into spigot coding. Is there any way for me to figure out where a flying entity hits the ground?
lemme try bitshifting
I think you'll have to calculate that yourself 😄
that would probably be laggy, but you can always do some raytracing with some movement events if you use paper
i guess thats above the level for a newbie then 😄
as said, if you have 2 byte ints, it'll fit into a double with bitshifting. if it's 4 bytes, you'll have to use a byte array or sth but obviously that won't reuslt in "a number"
well the coding part is easy, it's just that you have to know about maths, vectors and stuff
what do you need it for?
just doing some random stuff to learn. So im making a pig launcher that explodes on impact 😄
was thinking about that i could check when it stops moving on the y-axis if that is possible
well you can just wait until the pig hit the round, then make it explode
pig.isOnGround()
did not find that one, thanks
I thought you had a pig flying through the world and want to know the location where it will eventually touch the ground like 20 seconds later or sth lol
you can check entity's velocity if it moving
but that would involve more than that probs
fair enough lmao
yea, i did that first but couldnt get it working for some reason. Was a good while since i deleted that tho
what if it the pig was yeeted with RPG to the wall?
yeah that'd of course be different. I'd probably do it like this:
- once pig launches, monitor it's velocity
- once Y velocity goes negative, check on every tick if the velocity is now lower than last tick
- if yes: kaboom
but that won't work when a pig hits a wall while still going upwards
does "air restistance" exist in mc? like does an object get slower automatically, or not?
i don't think so
if it doesn't exist, then it's easy - just wait until either X or Z velocity changes and kaboom
yeah but that's something else I guess 😄
i'd just print out the velocity of my pigs in every tick and then see if there's a certain pattern in X or Z velocity decrease
or alternatively simply get the nearby blocks of the pig
if they are all air, it's proooobably still flying lol
.
wdym? it's a valid material
unless you're using an outdated MC version
Material.WARPED_FUNGUS works fine on 1.16+
yeah the api-version must be at least 1.13
having no api-version inside the plugin.yml results in material type compatibility mode for older versions of minecraft (specifically for supporting older plugins)
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>remapped-mojang</scope>
</dependency>```
do you get an error when running the plugin or on compilation?
scope should be classifier
that's pom.xml
no
no?
oh yeah
that's what you mean
I thought you said he should do <scope>classifier lol
yeah the scope should be "provided"
^
it's in my ide
and remapped-mojang belon gs into <classifier>
click the maven reload button after you fixed your pom.xml
i got that working. Problem is that they explode right when they spawn, because they stand still right in the beginning
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>```
you have to run buildtools
you haven't run it to get the remapped jar
run the command from the blog post
(replacing 1.18.2 with 1.18.1)
is there like a way to delay it or something?
Delay the check from starting for a tick
Wat
maven as in maven?
mb
Or maven as in spigot?
can a ConfigurationSection be cast to a Map<String,Object> somehow?
simply casting it throws a CastExc
The only "legal" way of obtaining it is via mavenLocal
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
If you obtain nms from a repository it is probably not legal
that won't give you the remapped jar so it's kinda useless for NMS
That initself is fine, as long as you do not declare another repository that provides it
oh woops
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
is this
the code from this dudes solution doesn't seem to be valid anymore. would anyone know the work around
are you using remapped NMS?
yes
what version exactly?
you already got it?
yup
kk
mfnalex can u help me with something, just don't ?learnjava me lmfao
Temptations rising
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.
ah
L
rip
people bullied me until i switched to java 17
@pliant oyster what you need help with
ur just gonna ?learnjava me lmfao
so would anyone know the new way to get playerConnection?
it's called connection.connection
package de.jeff_media.jefflib.internal.nms.v1_18_R1;
import lombok.experimental.UtilityClass;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.Packet;
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
@UtilityClass
class NMSPacketUtils {
private static Connection getPlayerConnection(final Player player) {
return ((CraftPlayer)player).getHandle().connection.connection;
}
public static void sendPacket(final Player player, final Object packet) {
if(!(packet instanceof Packet<?>)) {
throw new IllegalArgumentException(packet + " is not instanceof " + Packet.class.getName());
}
getPlayerConnection(player).send((Packet<?>) packet);
}
this is what I'm using to send packets to a player, so yeah instead of playerConnection, call connection.connection
im just trying to get the player's client version
nah i wont lol i remember the struggle of getting lj'd
well do u still jet lj'ed?
still hella stuff i dont know either so
i probably would but i dont do much with spigot anymore so
ye then u prob will get lj'ed while trying to help me as well xD
ask your question
nrn
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
It’s not ?learnjava :p
Kotlin or Java?
?paste
oh my god I am literally so stupid
public static Map<String,Object> asMap(final @NotNull ConfigurationSection section) {
final Map<String,Object> map = new HashMap<>();
section.getKeys(false).forEach(key -> {
map.put(key,section.get("key"));
});
return map;
}
find the error
lmao
((CraftPlayer)null).getHandle().connection.connection.protocolVersion; iirc
okay
not the null obv
but ye
Well yeah, you are String.valueOfing the components
nope, protocolVersion doesn't exist
at least not in the Connection object
I'm using remapped
new ComponentBuilder().append(blah).append(blah)