#help-development
1 messages Β· Page 791 of 1
4.5 works perfect
where
that not a serializer
i know
serializers looks like
serializer is in a differnt class
i just told it to make my class work with the sirializer and it gave me this
// example in pseudo code
class CustomItem implements ConfigurationSerialization {
public CustomItem(Map<String, Object> data) {
}
public Map<String, Object> serialize() {
Map<String, Object> data = Maps.newHashMap<>();
return data;
}
}
List<CustomItem> items = Lists.newArrayList<>(); // Items repository, can you either Lists or Maps
// pd: If you working with map, you should either saves the keySet() or values()
void reload() {
for (CustomItem item : (CustomItem) getConfig().getList("any-path", new ArrayList<>())) items.add(items);
}
void save() {
getConfig().set("any-path", this.items);
getConfig().save8);
}
Thats what i use i have implemented in my kit preview
If you dont add the default in the getList(), them if your any-path list is empty will be an NPE
@valid burrow i hope it helps you, if need something let me know please
whats the main difference in:
make db connection -> do stuff once -> close connection <= and repeat for each one thing/action
make db connection on start -> do stuff continuously -> close connection on disable <= only once per plugin disable/enable
You donβt make and open a new connection constantly
yeah
you just maintain the connetion opened
Because connection re-opening is an intensive operation
yeah seems weird but has its fundaments
cuz he told to keep making new connections and closing them
most video coding doesnt have good programming things
so if I want to open and close it on server enable/disable i dont really need to make any utility methods for disabling / enabling in db manager utility class, yeah?
atleast minecraft ones
what?
lets say I want to make utility class for db management
I dont really need to make methods for making and closing connection if Im gonna do it just once on plugin enable or disable
well, in my case i do a class manager for the db where i declare my mongo collections, opening and closing connection. And also catching exceptions
Then each repository manager which hand a specific data collection
oh you use SQL right?
I will most likely
Collections is the same as tables from sql
they are for agrouping data things, they allow to separate the things
well at first I want to add them by hand for stuff like custom items
because you dont mess player data with mini game data for example, there you use different tables or collections depending the db engine you use
stuff like player stats would be changed or created on player's first join automatically
yeay what i do is the next
For big problems i use a mix of persistent db (Mongo or Mysql) + cache database (Most of time, i use Redis here), because each data loading all time is recursively intesive too
But for smalls plugins, you can catch data using caffeine for exampke
may I ask what catching data is
Player joins:
Ask to cache if the data exists, if not exists in cache ask to database. If database, doesnt have any data you create the player data in the cache and finally inser the player data to database
if you have mysql why use redis for cache when mysql can cache also?
no ide, i didnt experiment huge things with Mysql im not fan of SQL dbs
ah
sorry if i sound inexpert there
cache allows to keep data in memory, not asking all time the db
I assume you need to make your own cache maker methods by hand?
because each data asked and returned from db is more than intensive than a connection opening or closing at the same time
db access is VERY slow
you either play around simple things a maps, arrays
But proper caches is for example Caffeine and there some more
cache is anything that holds the data in memory, a Map
You dont directly work over the db, you update cache
also when always using db every data fetch must be done async. Because mc has only 1 thread, so it blokcs the server operations until the data is retuned from db
Any data you have in memory is "cached data"
Cache is temporal data in memory, what ever you store tho
A variable is cached data, because its keep inside the memory (RAM talking about pcs)
So what a cache does, is mantain data in memory, but what happen if server goes down? Well data is losted
if its on some other host, possibly, but if its on the same host no its not slow at all especially if you are using unix sockets
yes it is
dont all use unix sockets for dbs connection?
no most use TCP
even if on the same host it's a magnitude slower than accessing memory
yes but redis is not memory only
okay so cache is like screenshot of current data state yeah?
you still have to communicate with redis
also mysql just like redis can store in pure memory too
mostly
okay so I have cached data and db, how do I edit stuff now?
since I get how to read it, from cache
you edit cache
so, to say DB access is slow is not true especially when MySQL is quite capable of handling literally millions of accesses without you noticing any slow downs. Most people who notice issues is because they actually don't know how to setup a DB like mysql IE, their configs are not using ideal values
and when I close server cache gets updated to database?
I mean I should make it like that?
@storm crystal
Basically to summarize:
Cached data refers to any type of data that is stored in memory to be used at some point in time. This cached data is of a non-persistent type, that is to say that if you close your program it will be lost.
On the other hand, databases are known to be persistent storage. That is to say, they always store the data that you send or delete, if you ask them to do so.
Is it more or less clear?
sorry, it didnt copy paste
you push your cache data to your db
it is
okay lets say
it is probably more accurate to say cache data is readily accessible data. Doesn't have to be in memory only although this is the most common type people refer too
that I want to store this into a database
how would I cache this?
Map of arraylists that would have maps?
easiest way in Java without external applications, is to create an objectt map
you would turn that data there, into an object
and keep that object in a map
ideally it would at some point save back to the persistent storage if there is changes to it
is it very bad of an idea to make method that would save cache into db during server uptime?
there is various ways of implementing when you want to save the ddata
you can save it only when it changes, you can do periodically
or even at shutdown
or do all of those
@storm crystal
What is done is to do the following, when a user connects, his information is searched in cache.
If it exists in cache, it proceeds with the rest of the logic. For example show a message in the chat that such a player with x rank entered the server.
Otherwise (if it does not exist in cache), it will query the database to see if its record exists. If it exists, it will put it in the cache until he disconnects or is kicked.
If it does not exist in any of the sides, it proceeds to create its cache and proceeds with the other actions. Asynchronously, its insertion in the database is generated.
Once the player is disconnected or expelled, the cache sends this information to the database. And leave that information a while longer in case he reconnects.
In case of updating, it works on the cache information in case it is a very important change, it sends it to the db immediately. Of course, from time to time the cache requests to the database the information to keep the information updated.
I think i more or less explained the base i could be wrong ofc. If someone else disagrees let me know please so we all learn more πͺ πͺ
so I could make a method that would take into input wanted variable (like let's say Player's rank) in cache, and if it doesnt exist it would make query to database to find such variable and return the value?
yeah!! exactly
in case it doesnt exists in the db, the rank or player data will be created in the cache
But yeah you more or less getting the idea
like taken from standard template of a newly joined player?
like if I had formatting style in chat of "[Lvl] <Player>: Message" and if player joins and there is no Lvl of that player in both cache and db query then it would just create default equivalent which would be Lvl.1 under that player's UUID to use
sorry for not answering fast but im wrriting an essay while helping for school hhehe
fair im patient
more or less esactly that
Let me explain as a user and custom options right?
DuskTaler conenct the server for firs ttime, data is asked to cache doesnt exists? true, will ask to database. Exists? no well so create a custom object for the player in the cache
Player chats, does he has on join chat disabled by default? We check it in his object created before, so far it will be true because its a new player. In case he has already played before it wont be true, it will be the value returned from cached data
Do you understand more or less?
so that how would an example method to grab data look like?
well yeah operations on Maps and Objects but that's kinda semantics
Data will be first returned to cache, then grabbed from there data you will use
But fully accurate your example you fullly understand it hehehe
to ensure that it would be kept up to date?
practice makes you better
in my case for ensuring that right? I just load and save data on db when player joins, left or get kicked from server
And every some amoutn of time in case server goes down, you will have less data losses
so on player leave I'd take this player and return his currently edited data to main cache that'd get saved to plugin to ensure that it wouldnt be lost?
like in case of heavy traffic or something
1m i wil ltranslate that
yeah, i talk spanish nativly in case you dont understand me thats the reason
I try to do my best for getting understand haha
No problemo xd
Not sure what you tried to asked on top, but what i understand. Is that if the user disconenct the cached data is saved to the db and stays in the cache for some time. Why still in cache? Because player can reconnect usually went your conenction goes down for some seconds
well save player data to cache when they leave to ensure that less data will be lost ye?
not in the cache itself, mainly in the database
oh okay
because cache contains temporal data
database is what persist them, for not loosing them when the mc server or app goes down
so it would be:
player leaves -> his cache is added to database -> cache is reloaded
?
temporary
temporal is something else
oh right
yeah im no the best but you get it heheh
also the cached data is saved to database every x time
well they are kinda synonyms I get what you mean
Id use temporary when I want to say that something is not permament
because temporal is in relation to eternity which is kinda abstract
and not many people know temporal
perfect, i had to go but more or less you understand the logic
If you want them i can help you more about this
like Scheduler?
yeah exactly
Remember this
always when working with dbs calls ASYNC operations
yeah cuz mc works in 1 thread so it could clog server operations
its perfect best wishes and good night my mate. Just tag me for any other help
exactly you already get it hehe
mhh im having a bit of an issue, i need a custom block placement system but of course if i just set a block at a location it might include the player, but this has many variables so is there like idk a utility method that checks if a player shouldnt be able to place a block at a location because it intersects with the player
You can easily check if the bounds of a block intersect the player
Or any entity for that matter
Create a bounding box for the block and then check if it intersects the players bounding box
yeah im doing that
but its returning false
lol
when the player is standing right in it
Block block = event.getClickedBlock();
BlockFace clickedDirection = event.getBlockFace();
Location newBlockLocation = block.getLocation().clone().add(clickedDirection.getDirection());
Block newBlock = block.getWorld().getBlockAt(newBlockLocation);
BoundingBox blockBoundingBox = newBlock.getBoundingBox();
if(blockBoundingBox.overlaps(event.getPlayer().getBoundingBox()) || event.getPlayer().getBoundingBox().overlaps(blockBoundingBox)) { // always false
return;
}```
someone help me
?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!
i need help with setting up a server setup
Block#getBoundingBox depends on the type of the block
Air probably returns a box with 0 size
Use BoundingBox.of(block)
can someone rq just help with a custom recipie plugin, i got the code but i dont know how to actually give the player the custom item.
can someone help me with luck perms
wdym by give?
if its registered they should be able to craft it without any additional code
What is mirroring my console output? So many commands they duplicate, a player types one command it duplicates in the console and is very hard to keep up with.
How do i make my plugin support multiple minecraft versions?
What is mirroring my console?
using methods that all versions u want support
maybe u have 2 processes running somehow?
did u restart
What processes exist is it a plugin?
Try removing plugins
Even BuycraftX fetches twice.
Delete em?!
u literally just said ok to that
BRO
HOW CAN WE KNOW??
did u restart ur server
remove ur plugins one by one till it stops
oh you were talking restart my server?
???????????
I have methods that support most, but I think it is with the API version or Java version
So i deleted all my plugins and the problem still continues
java is backward compatible
thats ur problem
so ur telling me u have 0 plugins?
go ask minehut idk
did you restart ur server yet?
probs some minehut misconfiguration shit
I t hoguht it was only frontward compatable
wtf
jk
What about the API?
idek what the api version is for lmao wait for someone else
whats a better program than vs code for c sharp?
im having a lot of issues; after an hour messing with chocolatey, then finding out i need to patch it to have old commands back to install scriptcs ... now its just bad
just c worked great
yeah for c, c++, js/ts, and go it works
What even is forwards compatibility?
Isn't that just future-proofing?
Bukkit/spigot plugins are a good example of being forward compatible
Isn't that what python doesn't have
It just means to an extent it should work in later versions
So future-proofing basically
what is the modern fancy way of achieving custom breaking times for blocks in 1.20+
But that basically also implies backwards compatibility
So basically either term in nonsense
(disregarding compatibility for older clients)
Backwards compatibility for the future
Well backwards compatibility means a plugin built for a new version should also work for a old version
Which is obviously not the case
Yup
That would be impressive
Whatever
And impossible, unless seperate jars for versions or some magic
It isnt impossible per say, just your jar size would be a bit hefty with mostly compatibility code more then anything lol
Beta 1.7.3 bukkit even does events differently than modern bukkit
The classic class with empty methods
Doesnt mean you cant have two different classes for events depending on version
Yeah
I never did that so idk how
You'd also have to register them in seperate ways, soo
Easiest way is with an enum manager
A what
You use enums to invoke the appropriate class needed. You can make enums hold the value of classes
So its called an enum manager
Hmm
Bukkit changed so much
Y_TYPE(1) {
@Override
public X createInstance() {
return new Y();
}
}, Z_TYPE(2) {
@Override
public X createInstance() {
return new Z();
}
};```
Hmm
That is one way here is another
Y_TYPE(1, Y.class), Z_TYPE(2, Z.class);
int id;
Class c;
public Type(int id, Class c) { this.id = id; this.c = c; }
public static X createInstance() throws Exception {
return c.newInstance();
}```
The first way is more ideal as no exceptions
But as you can see enums can hold classes as a value lol
right so actually another issue im having is detecting when a client is breaking a block during a PlayerInteractEvent
cancelling PlayerInteractEvent leads to the break event not firing
Ah
which is where im having an issue lol, I need to cancel the interact because i implement custom logic when the block is left clicked (which conflicts with vanilla mechanics), but also i need to keep vanilla breaking mechanics
could be but im not sure what data im exactly looking for or from which classes tbh
Well the client reports when player starts breaking a block
So that means where interact is called the data for such should also be present
Now you know something new enum manager lol have fun with that 
Also an enum can have more then one class for value too
So you could just have enum of version, each version contains the appropriate class values
I gotta do that fr
you can also just use a Supplier instead of overriding a method for each entry
Depends which way you want to do it but yeah. Here is example of using supplier method
enum Type {
Y_TYPE(1, X::new), Z_TYPE(2, Y::new);
private int id;
private Supplier<X> supplier;
private Type(int id, Supplier<X> supplier) {
this.id = id;
this.supplier = supplier;
}
public X createInstance() {
return supplier.get();
}
}```
Its a shame we canβt have generic type params on enums
What do you mean?
Oh right would have to change it to have a normal class for that
Instead of enum it would be
public Type(int id, Class<? extends X> c) { this.id = id; this.c = c; }
Yeah, I suppose one could use a sealed class or sth right, to make it enumish
But yeaa :)
Can I make a spigotmc resource private? So I can only see it?
why would you post it then
Sure, report it to have it removed lol
So meant like making a "tiktok" private. In this case I want to delete a resource but I also want to save it for myself in case I want to build on it in the future or something instead of deleting it completely
is it possible to save whole HashSet to yml file
I got HashSet which contanis few locations per chunk
and now trying to save it but file ends up empty
What is the problem with just leaving it as it is?
I have a defunct resource currently that i havent touched for a few years now
same
I am free to update it at anytime and for the mc versions it still works for those people can still download it if they want
There is no advantage or different features you obtain if it could be private
Just ignore the resource and leave it there. Come back to it when ever
okey
You have no obligation to respond to comments on it either lol
sorry π
You're trying to save every single block in every single chunk in a .yml file? If that's the intention I suggest a database that's way to much information for a .yml
Doesnt that defeat the purpose of an enum
Probably yeah lol
I mean there are enum semantics where its allowed in other languages
Well ig an enum is just a fancy class lol cant see many usecases where a generic would be useful though?
I mean it depends on the approach uβre taking
Like in the case of rustβs Option and Result enum, having type constructors is absolutely life saving
Is it possible to change the nametag of a player to a color gradient via packets?
(or other methods?)
Dont think overhead nametag can be coloured
You can do a team name though
Definitely ways to spoof it
Ive Seen Other servers with this Feature, but i dont know how they do it
Have you tried display entities?
Could also use an armor stand as well
Hi
I want to display several unicode characters, but some of them (those whose charcount is 2) are displayed separately.
e.g. \u26CF which is pick emoji displays correct, as β but
\uD83D\uDD25 which is fire emoji displays as οΏ½οΏ½.
How could I make it display as π₯?
they simply might not be part of the font the client uses
so you would need a resourcepack with your own font that includes them
no, minecraft displays it correclty
but not from plugin
Try \u1F525 instead
intellij says its wrong, but ill try anyway
Not sure why intellij will report anything with unicode characters lmao
There isnt really a wrong character code except if you go outside the bounds
yup
yeah that is not a single character as far as the jls sees it
α½ is \u1F52 and 5 just stays
it'll be \u1f52 as a single escape and separately the character '5'
Weird it does that since that is the official unicode point
what happens if you just.. stick the fire emoji in there
Β―_(γ)_/Β―
jls only allows up to 4 hex digits after \u
intellij translates it to \uD83D\uDD25
Hmm wonder if you just shoved the raw byte in there instead
Is your encoding set correctly?
i have utf-8
it should give you the option to "replace unicode escape with character"
alt enter
not that it should be any different but, you never know i suppose
UTF-8 Encoding:
0xF0 0x9F 0x94 0xA5
The raw encoding of that emoji if you want to try some other methods
Well the other way i was thinking would be to reference the character code point directly
And then have that method just stick in the string its needed in
StringBuilder.appendCodePoint(int) :^)
same output :(
still... the same
Java sure is being stubborn -.-
Character.toString(0xF09F94A5)
If that dont work i will be home in an hour and can find more solutions lol
Lol
i dunno, just doing sendMessage("\uD83D\uDD25") seems to work fine for me https://i.imgur.com/7zNKwr9.png
make sure you are compiling with utf-8 encoding, in gradle it's options.encoding = "UTF-8" in the compileJava task, idk where you'd specify that on maven
i am
proof or it didn't happen
i mean the server should run with that too, that's great, but that's only half the story
everywhere i have utf-8
how are you compiling your project exactly? what do you click or run to build?
running maven package
you need to tell maven in the pom.xml about the encoding
google "maven compile with utf-8"
as i said literally
do you have the compiler and resources plugins applied?
yes
ehhh
how would I disable putting an item in ANY CONTAINERS AT ALL? like I know how to disable from taking out but not putting in
Cancel click event if clicked inventory is a container inv
isn't that taking it out tho? I want to stop from putting it in
Click event is fired for both
is there any way to apply it to ally inventories except the players main one?
you will never account for every way to prevent transfering
If the clicked inventory is not a player inventory, cancel it
so many ways, hotkey presses, mouse click, item on cursor clicks, pressing q
Also if the event is a shift click and the top inventory is not a player inventory, cancel it
Hoppers too
if you mouse over an empty slot in an inventory and press a hotkey for one of your item slot it will swop the slots but you won;t get an item click for your protected item
Minecart hoppers io
Which are also weird
There should be a pickup event for both
The click event will fire in my example, but it's really hard to recognize it's trying to move your specific item
you would also have to detect in the drag event too
should this events in class work:
https://pastebin.com/mBFpj964
Does it throw concurrentmodificationexception?
i cant uderstand, because i dont know, how to register this eventhandler
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Don't use snake_case for your constructor arguments
Why is everything static, when you have constructor.
If you were to create two different objects, with different variables, the second one would override the first one.
im new in programming so i dont really now all what im doing
so i dont need static in my class
well, in that case
!learnjava
what is the command
?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.
why is your main class called Main?
it is important?
?main
I am struggling to understand what you tried to do
Do you just want to overrite all skeletons ?
i want to make class or interface or maybe smth else, which will be have and events handlers and my custom mob class
because i will have at least 5 more skeletions, so i dont want to write 5 different classes for every skeleton
where event handlers will be different only in one parameter
so i want to create class which will be have event handler
like i have biomeList, which is biomes in which skeleton will spawn
donβt make ur spawnSkeleton method static
There's much more wrong with what they tried to do
now i have interface
Auf cause
I don't see why you'd need interface
To interface duuh
Do u know what an interface is
interface is like template
smth like this
public interface SkeletonHandler extends Listener {
void spawnSkeleton(Location location);
boolean isSkeleton(Entity entity);
@EventHandler
void onArrowHit(EntityShootBowEvent e);
@EventHandler
void onEntitySpawn(EntitySpawnEvent e);
}
Lol
Thats false
Don't think this is how you would do the events.
ohh
so they have access to the events
But
listen pls
No
i have two skeletons: desert and overgrown(only for now, in future it will be more than 5 skeletons)
and i want to create the same events for first and for second, which will be different only in one List<>
Use abstracts
abstract class?
I think what you would want is: have a map of your abstract skeletons - the skeleton type in PDC -> AbstractSkeleton instance
then have one listener class and you would delegate the events to each skeleton based on the type
So you register the listeners only once and can actually use the variables in the skeleton classes
Default interface methods 
yeah
not registering million of classes in main class
okay, i will read about what is static and when use it
ok
its ok to rename in project name?
?static
Depends
Probably good resource for the static
Yes
But anyways, I think you're doing good job already, seeing you have guard clauses
Def. better than some ppl who come here and
abstract class CustomSkeleton
class Skeleton1 extends CustomSkeleton
β¦
but then i will have two classes: OvergrownSkeleton and DesertSkeleton, yes?
yes, that was just an example
and i need to register this two classes?
What did bing change
If you do this, the no
ohh, really
ty
Illusion Search Index - Static (aboose)
Static is a keyword in Java that modifies the behavior of variables and methods. To understand static, we need to review some basic concepts of object-oriented programming.
Classes and Objects
A class is a blueprint that defines the structure and behavior of an object. A class specifies what fields (variables) and methods (functions) an object will have, and how they will interact with each other.
An object is an instance of a class, created with the new keyword and a constructor. A constructor is a special method that initializes the object with some initial values or logic. For example, we can use a constructor to inject some dependencies into the object.
An object is a bundle of data and behavior that follows the structure defined by the class. We can think of an object as a box or a package that contains some information and actions. The information is stored in the fields, and the actions are performed by the methods.
When we pass an object as a parameter to a method, we are actually passing a reference to the object, not the object itself. A reference is a pointer that indicates where the object is located in memory. This way, we can avoid copying the whole object, which would be inefficient and wasteful. This is also known as "pass by reference".
Static Variables and Methods
Static is a keyword that indicates that a variable or a method belongs to the class, not to a specific object. A static variable or method is allocated in memory only once, and can be accessed by any object of the class, or even without an object.
A static variable is also known as a class variable, because it is shared by all instances of the class. A static variable is initialized when the class is loaded, and remains in memory until the program ends. A static variable is not affected by the garbage collector, which is a mechanism that frees up memory by deleting unused objects.
A static method is also known as a class method, because it can be invoked by the class name, without creating an object. A static method can only access static variables and other static methods, because it does not have a reference to a specific object. A static method is useful for performing general operations that do not depend on the state of an object.
Static variables and methods are designed for constants and utility classes, which are classes that provide some common functionality without creating objects. Static variables and methods should be used sparingly, because they can cause problems such as memory leaks, concurrency issues, and tight coupling.
The only exception to this rule is the singleton pattern, which is a way of ensuring that only one instance of a class exists in the program. A singleton class uses a private constructor and a static variable to store the unique instance, and a static method to return it. A singleton class is useful for managing global resources or state, but it should be used with caution, because it can introduce hidden dependencies and make testing difficult.
TL;DR - Valid usage of static in:
- Constants
- Utility classes
- Singletons (when dependency injection is impossible)
Examples
Here is an example of a utility class, with a constant:
public final class MyUtilityClass { // final to prevent inheritance
private static final int NUMBER_OFFSET = 100; // constant value, permanent
private MyUtilityClass() { // Private constructor to prevent initialization
}
public static int offsetNumber(int original) {
return NUMBER_OFFSET + original; // static method accessing static variable
}
}
Here is an example of a lazy singleton (lazy means it is only initialized when needed):
public class MySingleton {
private static MySingleton INSTANCE = null; // static variable to store the instance
public static MySingleton getInstance() { // static method to return the instance
if(INSTANCE == null) { // check if the instance is null
INSTANCE = new MySingleton(); // create a new instance if null
}
return INSTANCE; // return the existing or new instance
}
private MySingleton() { // private constructor to prevent external initialization
// optional: check for duplicate instances
if(INSTANCE != null) {
throw new IllegalStateException("Duplicate instance");
}
}
private int currentNumber = 0; // non-static variable to store some state
public int getOffsetNumber() {
return MyUtilityClass.offsetNumber(currentNumber++); // non-static method accessing static method and non-static variable
}
}
Here is what NOT to do (unless you're a clown):
public class Circus {
private static PlayerManager playerManager; // static variable to store a non-constant object
private static SomeOtherManager someOtherManager; // static variable to store another non-constant object
private static String status = "broke"; // static variable to store a mutable state
private static int money = -1; // static variable to store another mutable state
public static PlayerManager getPlayerManager() { // static method to return a non-static object
return playerManager;
}
public static int getMoney() { // static method to return a non-static state
return money;
}
public static String getStatus() { // static method to return another non-static state
return status;
}
public static SomeOtherManager getSomeOtherManager() { // static method to return another non-static object
return someOtherManager;
}
}
Ye, you would register just one listener
And create your 5 skeleton instances, each with different parameters
WHY are you reposting this
I think Illusion will be mad
Itβs not a repost
How do I like save a variable of a block, like so the variable wont change even after the block changes
Why?
And what variable?
Because my event is delayed and sometimes it shows wrong info
??
what is it then
For example if someone quickly breaks and placed a block it will show the placed block (onblockbreak event)
I told bing to refine and extend it
No?
Get the stuff from the event
Ok my friend is tripping then idk, ill check logs when im home
ur singleton creation is not thread safe :kappa:
Is illusions?
where
Z
Here u go. - Bing:
One possible way to make a singleton in Java is to use a static nested class that holds the instance of the singleton class. This way, the instance is created only when the nested class is loaded, which is lazy initialization. The nested class is also thread-safe because the class loading mechanism ensures that only one thread can load a class at a time. Here is an example of how to implement this approach:
public class Singleton {
// private constructor to prevent instantiation
private Singleton() {}
// static nested class that holds the instance
private static class SingletonHolder {
// create the instance as a final static field
private static final Singleton INSTANCE = new Singleton();
}
// public static method to get the instance
public static Singleton getInstance() {
// return the instance from the nested class
return SingletonHolder.INSTANCE;
}
}
This is one of the shortest and thread-safe ways to make a singleton in Java. There are other ways as
that is thread safe yeah
Even better
One of the shortest possible and thread-safe ways to make a singleton in Java is to use an enum. This approach has serialization and thread-safety guaranteed by the enum implementation itself, which ensures internally that only the single instance is available, correcting the problems pointed out in the class-based implementationΒΉ. Here is an example of how to use an enum to create a singleton:
public enum Singleton {
INSTANCE;
// other fields and methods
}
To access the singleton instance, you can simply use Singleton.INSTANCE. This is also the recommended way of implementing singletons by Joshua Bloch, the author of Effective JavaΒ².
Source: Conversation with Bing, 15/11/2023
(1) Singletons in Java | Baeldung. https://www.baeldung.com/java-singleton.
(2) Singleton Design Patterns - Javatpoint. https://www.javatpoint.com/singleton-design-pattern-in-java.
(3) Java Singleton Design Pattern Best Practices with Examples. https://www.digitalocean.com/community/tutorials/java-singleton-design-pattern-best-practices-examples.
for extra points you can do
public class Singleton {
private Singleton() {}
public static Singleton getInstance() {
class SingletonHolder {
static final Singleton INSTANCE = new Singleton();
}
return SingletonHolder.INSTANCE;
}
}
:^)
Canβt disable previews on phone
<https://baeldung....>
Not putting in that effort
fair
sry for ping. smth like this - https://pastebin.com/im5akHNA ?
your phone is weird then lmao
you are not zoomed in are you?
that happened once on my phone where it zoomed in slightly
ah iphone
why does it look so pale?
figures
if(!isInBiome(skeleton, e.getLocation().getBlock().getBiome())) return;
won't work, gotta continue instead.
oh ty
same for the other loop onArrowHit
Does spawn entity trigger the Spawn Event?
I beleive it does
i will check
just put a check to see if what is spawning is not your custom skeleton
Anyways, this won't work 'cause you ignore the skeleton types.
Best would be a map "string" -> "type insatnce"
For every event, you'd just get the skeleton type from the entity, get the skeleton instance from the map and use that to do your custom thingies
wait, that is what you're doing
it will work, just can be more efficient
I had the same issue before, but instead of closing that menu it closed the keyboard making me unable to type
class in a method
damn
never used those I have no idea on how they behave
anyway, how can I make a gif show itself on a spigot resource that's hosted by imgur?
Try really hard
100% success rate
Just insert image and put in the direct link?
What is the link?
Thread safety is for weirdos
why the fuq is this so loud
Idk i am not at full volume haha
then
what do I do?
bruh
why the v tho
oh wait
its probably to combat their own unique identifier generator
just remember to check on your images like once a year
do they auto-delete them?
does spigot even allow gifs?
also look here
Just cause u can doesnβt mean ur allowed to π€ͺ
Image
insert it as media?
A gif is an image
both don't work
you are using the correct editor in spigot right?
the gif doesn't play
what does that even mean?
Wha tlink shadow?
there is two different editors for creating the resource page
one is the fancy one
wait wat
the other is the manual one
it ain't playing normally as well
Blame imgur
I was just testing it
Ahh k
it working in event
Use smth else
bruuuh
Shouldnβt supply the gif huh
bruh it works
I see the issue
XD
aaaand it stopped working
I don't get it
remove the character just before the extension
not sure why the extra character gets added
did you clear caches? or tried to
and the page just crashed
do a force refresh
just use the manual editor
you literally work in the editor
probably because the preview is javascript
which works from your system and not the server
what manual editor?
ain't tis
a manual editor?
There is a rich editor and a bb code editor
how do I access it?
Wrench in the top right of the input box
uhh
There's a size limit of like 4.5MB for attachments iirc
gifs tend to exceed that limit very often
but it's hosted externally
if you use no compression XD
Doesn't matter. Content is proxied
mine is 157
Just a tad large
157mb?
yep
Makes sense
does anyone know how to send action bars my method isn't working
Show
Player#spigot#sendMessage
and ACTION_BAR for the type
or smthg like that
Donβt
how do you not know how to compress it?
o.o
Show code
I found some websites online
I was thinking about the video editor
Looks fine
needless to say, the video editor wasn't very helpful
I selected a lower frame rate bruh
something tells me this is larger
for losing frames
ah wait, it converted it into a mp4 for some reason
( if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return;)
with that
that prints "Entity spawned"
But when i right click an entity
i get both
messages
How is the PlayerInteractEvent running
(with a check for the action) as i said)
?interactevent
The PlayerInteractEvent may be called once per hand. If you only want code to be executed once, you can check the result of https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerInteractEvent.html#getHand(), then decide functionality.
For example, only executing code if the main hand was used:
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND) { // * if the hand used is NOT the main hand:
return; // do not progress past this point |
}
// provide functionality
}
It says right there
read what i just said lil bro
And
I mean, you can just read
?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.
Good Luck reading those docs then π
Comparing enums with equals haha
Works but looks sad
Not at all
?paste
it's completely normal
The test of the code
it does
Still looks sad
Of course
Now
.
?paste
He was asking about the action
You learn first.
Not only hand
that is not my issue at all.
?paste
Thank you
try adding a check if they right clicked air
for the block
if they did, don't do anything
I did
oh wait
OH
lemme try that
I guess that fixed their problem
Yes i suppose so
like if a program onjava 16 it could run on virtual threads
π
'
That only fixes it for when there's no solid block behind the entity
?paste
so check for an entity in front of the block
the entity disappears
o.O
in the other PlayerInteractEntity event
that i have
so maybe i know the issue
it's probably because playerinteractevent is called after playerinteractentity
in spigot's code
Not sure though, just a guess
nah im pretty sure the threads are backwards compatible, so like new Thread() just creates a new OS thread
which is the old behavior
Yeah or well βplatform threadβ, uβre completely right
ig thats a more appropriate name
is that the official
name in java
official terminology
I wanna say yes cuz I touched those 2 days ago, but unsure lol
Yea
does anyone know why this isn't working?
public class FireDash implements Listener {
@EventHandler
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
Player p = event.getPlayer();
int i = event.getNewSlot();
ItemStack item = event.getPlayer().getInventory().getItem(i);
if (item != null) {
Objects.requireNonNull(item.getItemMeta()).getDisplayName();
if (item.getType() == Material.DIAMOND_SWORD {
if (item.getItemMeta().getDisplayName().contains("Β§6Β§lORANGE Β§bΒ§lΙ’SWORD"))
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("Β§eFIRE DASH!"));
}
}
}
}
The event is cancellable so the item has likely not yet moved
Fetch it from the getPreviousSlot()
alr
Also donβt do requirenonnull
i try create custom block with armorstand but why does it darken if it is inside blocks, how can I change this?
Lastly identify items via PDC tags not their name
hmm weird still doesn't work
don't pay attention to the lack of texture I was too lazy to make 3d textures for testing
?paste
Lighting
https://paste.md-5.net/laxijozewo.cs - this code
Disable gravity and turn em upside down or smth
Well gl then
Is it true that you can make model 3d ItemStack?
i mean like this
but with "textures"
to make it look like a real block
not player head lol
Yeah at that point no software is forwards compatible unless it literally does not change
hey if someone could help it would be epic, it still doesn't work
?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.
Post new code too
lmao i just realize this chat turned into a discussion. Why people dont like to first learn java?? instead of trying to code without any knowledge and then getting mad because they are told to learn java first
bcs its the hard part
but you have to do it
The problem here is not even in java. Before creating any programs, people need to develop the mindset to βeasilyβ switch from java to api
otherwise the api will become "language 2"
yeah thats totally true too
its what happen to me, i dont have huge knownlgedges about the api itself. But i have more knowledges in plain Java, like good practices, organization, conventions and many others things
I personally studied both Java and bukkit api
although I later regretted the decision to make the rtp plugin for half a yearπ₯Ά
I did it for 5 months
after 2 years refactoring
and now again
Im in a point where i dont regret about learnt to code plugins. Because i was forced to learnt a coding language, so there i seen i was capable for creatings things on my own. And now im working hard on personal proyects not even related to minecraft itself, mainly market place products. Which they are sell in the real economy of programming and software
i think i found a bug
PlayerInteractEvent runs with PlayerInteractEntityEvent if i remove the entity on PlayerInteractEntityEvent
what?
The translator mistranslated it, I meant I wish I had learned Java first and then only the bukkit api. That's the reason why it took me 6 months to make my first plugin.
yeah lmao, i was what happened to me. I made the same mistake try to code without first learning Java itself or dedicating more time to plain Java
@whole lintel forget wha ti have said, i was wrongly
can you re-explain what issue you are experimenting?
Well
i basically
remove an entity
when a player clicks it
then i print something when the player right clicks a block
and something gets printed when a player right clicks an entity and also when they right click a block
well, i would have to check the docs
Give me 5 i will check those events and we will realize if its a bug or not
?jd-s
So?
sorry i couldnt check i was distracted from the chatting in general chat
I'm using git inside eclipse. Anyone know if its possible to remove that project name before /src/main/...? Because on github it created everything inside that directory (nobody wants that)
?stash
public class Orange Sword implements Listener {
@EventHandler
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
Player p = event.getPlayer();
int i = event.getPreviousSlot();
ItemStack item = event.getPlayer().getInventory().getItem(i);
if (item != null) {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
String displayName = meta.getDisplayName();
if (item.getType() == Material.DIAMOND_SWORD && displayName.contains("ORANGE SWORD")) {
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("FIRE BLAST!"));
}
}
}
}
}
can you explain what isn't working exactly
no console errors
wait
the action bar
there is a space in your class name
no way
how did that compile
@arctic shuttle what editor are you using
lol
how did that compile
how
the space in the clsas name
it should give you like million warnings
loll
He probably didnβt
ok
by reversing your if statements
it makes your code 99% faster if you return early
aye, little white lies never hurt anyone
It's actualy 100%
hmm still isn't working
You somehow seemingly managed to compile with a space in a class name, I think your problem is somewhere else tbh
Hey guys, so I've been working on a video player project and I have come up with an optimized block placing method with the help of this blog: https://www.spigotmc.org/threads/methods-for-changing-a-massive-amount-of-blocks-up-to-14m-blocks-s.395868/
The only problem I'm having now is the client can't seem to render the blocks fast enough. When playing the video it only renders the center of the screen most of the time and the rest is just a mess of squares of outdated blocks.
I am using the second method from the blog by updating the block directly from the chunk. I am using nmsWorld.sendBlockUpdated(blockPos, blockState, blockState, 2); to send block updates to the player. Is there a way to send all the blocks at once? Or is there something I can do with the client to get it to render the blocks faster?
Here is the full method for reference: https://paste.md-5.net/bojejisacu.cpp
you can't manipulate how fast the client updates the chunks
public BukkitTask playAnimation(List<TeleportData> teleportDataList, Entity entity) {
currentIndex = 0;
int delay = 50;
BukkitRunnable runnable = new BukkitRunnable() {
@Override
public void run() {
if (currentIndex < teleportDataList.size()) {
TeleportData teleportData = teleportDataList.get(currentIndex);
entity.teleport(teleportData.toLocation());
currentIndex++;
// Check if more iterations are needed
if (currentIndex >= teleportDataList.size()) {
// Animation is complete, cancel the task
this.cancel();
}
}
}
};
// Schedule the BukkitRunnable to run repeatedly at the specified interval, then return the runnable
return runnable.runTaskTimer(FabledCore, delay, 1);
}```
This playAnimation function sstarts a bukkit runnable, and in another class i need to run the playAnimation method a number of times in a for loop. How can i ensure the for loops awaits for the bukkit runnable to end before proceeding with the next iteration ?
Is it possible to optimize the block updates so the server doesn't have to send every single block individually?
Hey all, I'm dipping my toes for the first time into plugin development. I'm trying to upgrade an existing abandoned package. However, when I try to run the plugin, the console gives back the following error: JavaPlugin requires org.bukkit.plugin.java.PluginClassLoader
I've been Googling all over, and it seems there can be multiple causes for it. I'm using IntelliJ IDEA with Maven to package the .jar file.
OOSAKAAAA
OMGGGGG :333
Can you send your pom?
I am not sure if spigot has a method, but there is a packet for multi-block change
It might be the use of PaperMC:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
--snip--
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.tealcube.se.ranzdo.bukkit</groupId>
<artifactId>methodcommand</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
</project>
I did see that in nms but I can't seem to figure out how to use it
Please paste it https://paste.md-5.net/
if you need help with paper should prob use their discord
further paper plugins tend to be incompatable with spigot so running a paper plugin on spigot may cause issues
you should prefer just creating plugins for paper, perhaps using like the paper lib that some person made
Why are you making a paper plugin instead of spigot?
so it would still work on spigot servers, but you can get some of teh paper features
I'm not sure yet if that is the cause, AFAIK I don't even see the dependency being used.
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>```
paper builds ontop of craftbukkit and spigot
certain org.bukkit things may be exclusive to paper
see if its fixed if you switch to spigot
Thanks all!
can someone help me ? qwq
why not just use a timer task
would that make the for loop await for the timertask to be over ?
well you could just have some kinda timer task that stops after some amount of iterations
how could i implement that ?
public void playCinematic(Player p, String cinematicName) {
ArmorStand armorStand = p.getWorld().spawn(p.getLocation(), ArmorStand.class);
armorStand.setVisible(false);
armorStand.setGravity(false);
p.setGameMode(GameMode.SPECTATOR);
List<TeleportData>[] cinematicMotionDefinition = cinematicsBundler.getCinematicMotionDefinition(cinematicName);
if (cinematicMotionDefinition != null) {
for (int i = 0; i < cinematicMotionDefinition.length; i++) {
List<TeleportData> keyframeMotions = cinematicMotionDefinition[i];
if (i == 0) {
if (!keyframeMotions.isEmpty()) {
TeleportData firstTeleportData = keyframeMotions.get(0);
Location firstLocation = firstTeleportData.toLocation();
armorStand.teleport(firstLocation);
p.teleport(firstLocation);
p.setSpectatorTarget(armorStand);
}
}
// Play the animation for the current keyframe motion
BukkitTask animationTask = motionProcessor.playAnimation(keyframeMotions, armorStand);
try {
animationTask.getTaskId();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
}```
this is the method with said for loop
Hello, I wanted to know how I could create a custom block
what do you mean with custom block?
that you can put as a title above the block or that when interacting with it it does certain things, etc...
u create a listener for the PlayerInteractEvent. Check if the player is interacting with a block, then check if the player is interacting with your custom block -> add your custom code
is this how you get the newly held item?
for example like this:
@EventHandler
public void onPlayerInteract(final PlayerInteractEvent event){
final Player player = event.getPlayer();
if(event.getClickedBlock() == null) return;
final Block block = event.getClickedBlock();
if(block.hasMetadata("your custom metadata")){
// ...
}
}
Hmm
mmmmmmmmmmm
Wonβt persist btw and i am not sure normal blocks have metadata?
why is the limit a mere 4.5 mb
Cause
they have metadata
just not PDC
though metadata doesn't persist
you can set a custom metadata
?blockdata
Huh i never knew
where is mfnalex's library
?custombloxks
do you want the data to persist?
Learn about CustomBlockData here:
https://www.spigotmc.org/threads/custom-block-data-persistentdatacontainer-for-blocks.512422/
if so ^
the block metadata persist
No
with FixedMetadataValue
No
The metadata is only deleted when the block is placed and destroyed again
Use an external source π
Doesn't work π
Proxydoxy
I recall the metadata API having some memory leak issues, at least with entity metadata. Would just stick to PDC tbh
Not with that attitude
I'm mad because I've been trying for way too long to do something so easy
Just use a video
Yeah it do be like that sometimes
Just make multiple posts and tell the user to flip between tabs
Use PlayerProfile


