#help-development
1 messages ยท Page 24 of 1
I just checked it
in onEnable you usually setup things like registering commands and listeners
alr
if you want to run it async you can use acceptAsync iirc
@gray merlin https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/java/JavaPlugin.html#onLoad()
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/java/JavaPlugin.html#onEnable()
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/java/JavaPlugin.html#onDisable()
declaration: package: org.bukkit.plugin.java, class: JavaPlugin
nvm
onLoad() basically gets called after your plugin instance was created
two of my players reported that they are lagging on join. screen prints loading terrain and lags...
so yeah, ofc it runs after /reload
I... I really don't know how one would enable or disable a plugin...
its not doing so on other servers
their pc's
I thought you just got the .jar, put it in /plugins and that's that.
what's your actual question? ๐
its not same on other servers
wait just a qucik question, why is intellij complaining?
It has a generic
so like
CompletableFuture<YourType>
You got me there. I don't know how one disables or enables a plugin, so I didn't know what onEnable or onDisable did. So my actual question would be: How does one disable/enable a plugin?
because you're using COmpleteableFuture instead of CompleteableFuture<?>
the server does that, you dont have to care bout that
Just do CompletableFuture<String>
you dont have to worry about that, the PluginManager does this for you.
Alright then, thank you.
in your case the type is CompletableFuture<String>, it is used for type inference. If you don't explicitly say only Strings or other types go in there, it will always default to a Object.
They want to probs know how to do it to others
No, no, I just wanted to get an understanding of what enabling/disabling is, but since it's something managed internally, I don't need to worry about it.
You should always use CompletableFuture<?> or CompletableFuture<Object> in the case that you do not want one specific
@rough drift @tender shard sorry, my discord crashed lmfao
okay, thanks! i didnt read the docs yet so I was confused
You can also call Bukkit.getPluginManager().disablePlugin(plugin) to disable
any ideas?
you can't do the same to enable
iirc there's a way to check worldborder distance
- Server starts
- It does internal stuff
- It loads your plugin's class
- it calls your plugins onLoad()
- it calls your plugins onEnable()
On /reload, it does the same except for 1 and 2
I see. We could in theory add a command to disable our plugin and stuff then.
ye
nerd
but you can't enable it back
wait, there's two "onStart" functions?
onLoad() and onEnable(), yes
anyone knows how to get the villager involved in a TradeSelectEvent event?
csnt register commands and listeners in onload ๐ญ
I see. So there's no need for me to re-route onLoad to onEnable or anything of the sorts.
no, you do not have to do that
when onLoad is used over onEnable?
before on enable
commandmap go BRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
edited my question
in 99% of cases, you should put your "onenable" logic into onEnable()
if you ever need onLoad(), that's a very rare thing
I got like 20 plugins on spigotMC and none of those requires the onLoad method
I'm using onLoad to create a subdirectory in my mod's folder, and subdirectories for each world inside it. Would that be a correct application for onLoad?
you can do that in onEnable
IG it's cleaner
Because it would also make sense to do that during "loading" semantically.
you really only need onLoad if you need some custom class loading things or similar
np
just put everything you have in onLoad at the "start" of your current onEnable method
then you are totally fine
it basically works like this
- CraftBukkit does new YourPlugin(...)
- CraftBukkit calls your onLoad()
- CraftBukkit calls your onEnable()
and on reaload. it does the same thing
Yep, I understood that. Oh, I will also have to apologise for the frequent questioning, I'm just starting out on plugin-making, and it's a huge relief from Forge, so I'm kind of excited, lol.
oh yeah alex
np lol
Another alex, hello!
hewo?
Should I use a BukkitRunnable in runTaskAsync or a normal runnable
a normal runnable
you can of course also use a Consumer<BukkitTask>
Runnable
im wondering, isnt a return required to stop at that moment?
but never use a BukkitRunnable i nthe scheduler
@urban grotto kekw
thats perfectly fine
smh
depends
if theres code after the event cancel as well
if u have further lines of code then no
do you want the further code to execute? No -> return, Yes -> dont return
aight
this for example would quit running the whole thing when someone "is doing weird things". If they don'T, it says "it's fine"
is there any efficient and quick way to load yml file to Map<String,String>() like ('gui.base.insert','a'), ('gui.base.remove','b')....
no
you'll have to parse the ConfigurationSection yourself if you want to get it as Map<String, String>
can you not use ConfigurationSection().getKeys() for that?
I've make research on YAML library itself but It only case content of yaml file to objects
no, it would only return "base" or "gui"
ok then I going to read file by myself
Is there a way to get a player's playerdata? I saw that player.saveAll returns void, so yeah.
What do you need to do with it?
moving the playerdata file around in directories.
lmao
No, no, that's incorrect.
Moving a player's data around through worlds.
It would be easier to just use the entire playerdata
Why do you need to do that?
It's the culmination of a very, very outdated version in a server I play with, alongside a giant amount of stuff that goes on there. It would take loads of time to explain the entire context, lol. I just need to have the player in different states across worlds.
could't you just get the playerdata folder and copy 'data' for selected player to another folder?
If you just have multiple worlds loaded in spigot you don't need to move the data around yourself
I thought i'd ask if there's a standard way to do it first.
In this very specific scenario I need to do it, unfortunately. It's not for spigot exactly, rather, thermos, which runs spigot plugins.
I can use saveAll to force the playerdata to be saved, right?
Yeah
Alright, thank you.
holy sh-t I didnt think of that
but does copying files would be safe?
i mean playerdata might constains some world properies
It contains the location
Other than that it's fine
Can't say the same for modded data
Yes, that won't be an issue
@rough drift i'm guessing something like this? i'm gonna test it rq, but i just wanna check with you just to be sure ```java
pl.closeInventory();
pl.sendMessage(String.format(plugin.makeMessage("messages.clanstuff.messages.prompt-string"), clanstuff[1]));
CompletableFuture<String> futr = new CompletableFuture<String>();
waitForChat.put(pl.getUniqueId(), futr);
try {
String yippee = futr.get();
clann.set("settings."+clanstuff[1], futr);
waitForChat.remove(pl.getUniqueId());
} catch (InterruptedException|ExecutionException ignored) {}```
yee
it will block the whole thread
so make sure to use a separate thread
new CompletableFuture<>().get() ๐ค
Well done, you've escaped the simulation
the other way would have been gitignoring .gitignore
anyways does this make sense?
class ChatChannel {
Set<User> joinedPlayers;
}
class User {
ChatChannel joinedChannel;
}```
instead of Set<User> consider map<UUID,User> to make it faster
User is probably his object that contains all that no?
never really worked with threads, will thius work?
Anyone knows how to get the villager involved in a TradeSelectEvent?
new Runnable() = () -> {};
but thread is runnable
yes
but less typing
and there's other things why you shouldnt really explicitly use Thread
alright, is there a way to run a runnable without a thread?
when you are running operation in thread some spigot calls like player.getInventory().setItem() will throw exceptions
maybe something like this
idk if its wrong
From what I can tell, your approach should be different although I'm not 100% sure what you're trying to accomplish.
Instead of creating a new thread for every time you want to wait for someone to chat, you should instead just track the state of a user (are we waiting for them to type it in chat, in a map) then listen for chat events.
what directory is plugins run from?
plugins
What is it called when a player is riding something? I know that the something has the player as the passenger, but what's the other way around?
Alternatively, how do I get the entity a player is riding?
you can get entitis from specific location and check if one of then has player as passager
var entities = loc.getWorld().getNearbyEntities(player.getLocation(), 3, 3, 3);
var ๐คฎ
That makes sense. Thank you.
My personal opinion is that var is underrated. In production code, sure, never. But for quick scripting, proof of theory, or similar, it's very much usable.
Figured, but thank you for the confirmation!
var is more handy than figuring out that kind of obejct a function returns
why is all the materials deprecated?
Yep. But in production code, I would never accept a pull request with it. I wouldn't want to lose type safety because of that, and it is a pain for further development and maintenance. I would allow it for unit testing, scripting, etc.
Only the old legacy materials are deprecated
Well in all companies I;ve ever been working var was always required in code style check
That's weird, but I guess everyone has a style.
but I'm working in as C# developer maybe in java people use diffrent approach
Funnily enough, I also develop in C#. There, I would only allow var in stuff like foreach loops and unimportant places where even the IDEA agrees that TS isn't needed
like for me it makes sence because in production you have classes like UserManagementAccountService
so it is better to write var service = new UserManagementAccountService() then UserManagementAccountService service = new UserManagementAccountService()
or dont give your class such a long name lol
I just realised, i've been saying "type safety", but I meant "type inference", in my head it made sense.
I'll correct everything lol, but still, I understand your point.
the thing i hate the most in java is that i could not make new instance of generic type
that's a one advantage that C# has
I got
java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchant cannot be cast to class org.bukkit.entity.Villager (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchant and org.bukkit.entity.Villager are in unnamed module of loader 'app')
when doing
@EventHandler
public void onTradeSelect(TradeSelectEvent event) {
// Fuck villager trading lmao
Villager villager = (Villager) event.getMerchant();
Player player = (Player) event.getWhoClicked();
event.setCancelled(true);
event.getView().close();
villager.setHealth(0);
}
Any clues why?
or you pass in an supplier with T as type
otherwise reflection
yes it could be done like that
Ah, yes! I was modding yesterday and tried to do that, and I was honestly just baffled that we can't do it lol.
Well you don't really know what constructor that generic type has
does materials have an id in a number value or something?
why did they remove it?
help, it's kinda urgent :CCC
(T) new Object()
Because since 1.13 there are no number ids
oh
I have an arraylist of strings. I remove the only item in it but the size is still 1?? https://i.gyazo.com/889ad558ef0ce95a02e1ee1ec04a433a.png how does that work
okie dokie
use isEmpty
still no
should I then make my own hash map for number ids?
this makes no sense ong
org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchant@5c ? xd
do someone know how to use only these decimals on double?
so it's an inventory? ๐ค
how could I get the actual villager from the event?
I have 2 lists, one with the name and one with the uuid. Bee dies, it removes it from the list but somehow the list is not empty and the size is 1 even though they're both literally[]?? https://i.gyazo.com/0a79c390359a34ce1d3e1e147b3b0da8.png
๐
round it?
No you should just not use them
use the material name
idk - seems inefficient
Map material name to an id in the file format
or you know use the existing nbt format that already does this
or schematic for that matter
is it possible to get a material by its name?
with a hashmap?
anyone knows how to get the villager involved in a trading? ๐ฆ
if you want
how else?
an array could work
maybe a list with indexes
which would be more efficient?
array would maybe take less memory
but other then that?
okay uhh it almost works
Did you forget to get()
did you call get on the future
yeahh
also please
your variable names
oh it's too late to change that
all my variable names are either weirdly shortened class names, something related to what im currently watching on youtube, just "lmao", "lol", "xddddd" etc
You will regret that later
I thought my variable names were terrible, but yikes that's worse
since you are using intelliJ i would like to introduce you to: right click on the variable -> refactor -> rename
jetbrains ides have excellent refactoring tools ๐
i've been coding for years, got used to it very quickly
if I have an inventory event how can I get the entity from there?
its just gonna bite you in the bum when you have bigger projects or are working with others on a single project
well, when I'm working with my friends I try to name them more normally
but I mostly just code alone because I hate when people go through my code
yeah it sounds like you're doing something very wrong
and then shamed of it so hard that you don't want other people to see
just code like any decent human being
no it's mostly just trust issues
instead of naming it "yipee" and not knowing what it means 5 years later
oh I'll probably move on a few months later tbh
it also makes it harder to build a public portfolio to apply for jobs
If I have a class A and a Supplier s = A::new, why is Java going to load A even if I never get the value from the Supplier?
It won't
It does
it only loads whenever you call get
No, I get NoClassDefFoundError
I mean
if A doesn't exist
you're referencing A's existence when initializing the supplier
which loads static values and all
The NoClassDefFoundError is caused by some import of something that is imported in A
๐ค
is 1.13+ API the same as the newest so if I code my plugin 1.13 it will work on any version above 1.13?
Only way to actually fix it, is by initializing the class that inits the supplier of A, only when you can be sure that A actually exists
bukkit is generally forwards-compatible
and backwards-compatible
it's weird
I mean A always exists but some classes that A imports might not exist.
usually yes but there might be rare circumstances in which stuff breaks
how would I know
test it on every version above 1.13?
trying it ๐
lmao
if it works on both 1.13 and latest its gonna be fine
ok ty
If I do it via reflection it works
Then A can't load during regular circumstances
thing with reflection is that you're not doing import statements directly
which doesn't try to init the class's static methods and all
Any reference to any class initializes its static methods
But why does importing a class initializing its static stuff
Even if I wrap that function in another class and just supply that it will throw NoClassDefFoundError
And A doesnt even have any static stuff
makes no sense
Me who has a class called "WalmartRaytracer" in my project 
If I serialize an Inventory object into JSON, will it have all of the tags existent in all the items, or is it not possible to serialize an Inventory?
yaay
Just serialize the contents
You can't serialize an inventory object itself
yeah, this is how I did it java List<Map<String, Object>> items = new ArrayList<>(); int i = 0; for (ItemStack it : p.getInventory().getContents()) { if (it != null) { Map<String, Object> ser = it.serialize(); ser.put("slot", i); items.add(ser); } i++; } config.set("items", items);
how do I know at which stage a crop block is being broken?
Crops extend ageable cast the block data to ageable and run Ageable#getAge
I see, I have to serialize each item individually. Thanks.
Thanks
Heyo, not sure if this is allowed as it's not stated in the rules. I would like to commission a super simple plugin to make it so that users can right click a horse with a stick and have it spit out their statistics in their chat.
If anyone is interested, send me a PM. I imagine this is pretty easy to accomplish! For a vanilla server, just to enhance horse breeding
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
Statics ?
damn I was beaten xD
Site is down
What you mean statics ?
@river oracle The cating to ageable breaks it somehow
speed, jump height, health
Oh
do {
do {
do {
do {
if (!var1.hasNext()) {
var0.pop();
this.tickRunningGoals(true);
return;
}
var2 = (WrappedGoal)var1.next();
} while(var2.isRunning());
} while(goalContainsAnyFlags(var2, this.disabledFlags));
} while(!goalCanBeReplacedForAllFlags(var2, this.lockedFlags));
} while(!var2.canUse());```
thats what im coming here for
can anyone let me know what this does
var1 = this.availableGoals.iterator(); btw
i think its filtering...
heya. im making a 1.19 plugin for the first time and experimenting with potion effects for the first time too.
Im tryna make a dragon head that when equipped, gives you keep inventory, no fall damage, haste 2 and resistance 3. However, im not exactly sure how to check if the head is equipped or uneqipped
itemStack.isSimilar
is there an armorequipevent?
Still trying to figure out why my empty arraylist is saying its got a size of 1 and isnt empty..
show more than 0 lines of code
are you modifying either of these lists between multiple threads?
@EventHandler
public void onHarvest(BlockBreakEvent event){
Block block = event.getBlock();
BlockData blockdata = block.getBlockData();
Ageable age = (Ageable) blockdata;
System.out.println("Block is " + block.getType().toString());
System.out.println("Is this wheat?"+ block.getType().toString().equals("WHEAT"));
int blockAge = age.getAge();
System.out.println("Age " + blockAge);
}
it thows a null eventexception error
You are most protbably not use the same lists when adding and removing
look at the screenshot, the first 2 messages are the values of both lists then I remove both items and its empty as u can see from the last 2 messages
but my isEmpty and size==0 return doesnt trigger
@river oracle am I casting it wrong ?
List<String> beeUUIDs = cadiaBees.hivePDCManager.getBeeUUIDS(container);
List<String> beeNames = cadiaBees.hivePDCManager.getBeeNames(container);
if(beeUUIDs.isEmpty() || beeNames.isEmpty()) return;
Show the exception
1 sec
You should check for instanceof before casting here anyways.
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-api-1.19-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-api-1.19-R0.1-
starting to feel convinces the plugin on the server int the one youre showing us
the first few lines @lost matrix
It is....
or at least the code you're showing us isnt the code youre executing
Full exception pls
?
too long it says
?paste
I need the "cause by" line
Caused by: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_19_R1.block.impl.CraftGrass cannot be cast to class org.bukkit.entity.Ageable
Should be clear
Grass is not Ageable
I need to check if it's a crop?
I got that jefflib thing @last temple but it doesnt have armorequipevent
whats the latest version of it? for me it says 3.3.0
You need to check if its Ageable. Before casting anything you need to check if the object you are casting is actually an instance of your cast target.
I found a method that returns that to me. It's Entity#getVehicle, thank you for the logic, though! I take it in high regard.
Ok, it's broken for a crop as well
First fix your casts, then recompile and check again for problems.
apparently theres an item in my array thats a blank string..so the size is 1
tf
There shouldnt be any spaces
public void setBeeNames(PersistentDataContainer container, List<String> beeNames) {
NamespacedKey hiveStoredBeeNamesKey = new NamespacedKey(cadiaBees, "hive-stored-bee-names");
container.set(hiveStoredBeeNamesKey, PersistentDataType.STRING, String.join(",", beeNames));
}
this is my method for setting it
public List<String> getBeeNames(PersistentDataContainer container) {
List<String> beeNames = new ArrayList<>();
NamespacedKey hiveStoredBeeNamesKey = new NamespacedKey(cadiaBees, "hive-stored-bee-names");
//Get stored bee names from metadata, separated by !*!
if(container.has(hiveStoredBeeNamesKey, PersistentDataType.STRING)) {
String[] storedBeeNames = container.get(hiveStoredBeeNamesKey, PersistentDataType.STRING).split(",");
for (String storedBeeName : storedBeeNames) {
beeNames.add(cadiaBees.colorUtil.color(storedBeeName));
}
return beeNames;
}
return new ArrayList<>();
}
and getting
if i was making an abstraction class and i need to store smthn like a location for example and the class works like: Class cl = new Class(loc); if i stored it in a private variable wouldnt it get overriden by the next time the class is called? then i dont see how to store data
Why do you return a new ArrayList there? Just return beeNames either way.
Why would it be overwritten? Every instance has its own fields...
It would never be null
public List<String> getBeeNames(PersistentDataContainer container) {
List<String> beeNames = new ArrayList<>();
NamespacedKey hiveStoredBeeNamesKey = new NamespacedKey(cadiaBees, "hive-stored-bee-names");
if(container.has(hiveStoredBeeNamesKey, PersistentDataType.STRING)) {
String[] storedBeeNames = container.get(hiveStoredBeeNamesKey, PersistentDataType.STRING).split(",");
for (String storedBeeName : storedBeeNames) {
beeNames.add(cadiaBees.colorUtil.color(storedBeeName));
}
}
return beeNames;
}
ive tried this with static variables which im assuming are different? are there certain variables that do and dont? the different types of variables have always confused me
?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.
still not the issue
i know java...
unfortunatly i do
Then why are you asking a very basic java question?
^
Like really basic
If you knew Java that wouldnโt be a question of yours
well it is
Hence, you donโt know Java
i do though thats the thing
You know some Java
static = class variable
non static = instance variable
i started java 1 1/4 years ago which id say is decent
Thatโs irrelevant to the topic at hand
It doesnโt matter when you started using something
well you are saying i dont know java
If you donโt understand key principles, you donโt know the language
ive been using java for those 1 1/4 years
Is this answer sufficient?
yes thank you
Youโve been using a language you donโt fully understand
thats truly unfortunate isnt it
Share your whole code pls
We cant make any sense of those bits and pieces
Itโs why you should make an effort to follow those resources and actually learn it
git
Do item and itemStack exist here?
Item is an entity representing a dropped ItemStack
If so, is Item one that is one-of-a-kind, and ItemStack the representation of Item that can exist in the world?
So... Item is the entity dropped, and ItemStack is... the one-of-a-kind item?
The logical implementation of item
Both are one-of-a-kind in their own scope...
the actual implementation of ItemStack in Bukkit is a little bit gray because its meddled in a lot of things
an ItemStack represents a Material, a Count, and NBT associated with that item
List<String> beeNames = cadiaBees.hivePDCManager.getBeeNames(container);
List<String> beeUUIDs = cadiaBees.hivePDCManager.getBeeUUIDS(container);
if(beeUUIDs.contains(bee.getUniqueId().toString())) {
Player hiveOwner = Bukkit.getPlayer(cadiaBees.hivePDCManager.getHiveOwner(container));
if (hiveOwner != null & hiveOwner.isOnline()) {
hiveOwner.sendMessage(ChatColor.RED + "One of your bees from the hive " + ChatColor.translateAlternateColorCodes('&', cadiaBees.hivePDCManager.getHiveName(container)) + ChatColor.RED + " has died!");
hiveOwner.playSound(hiveOwner.getLocation(), Sound.ENTITY_BEE_DEATH, 1.0f, 1.0f);
}
beeNames.removeIf(beeName -> beeName.equalsIgnoreCase(bee.getCustomName()));
beeUUIDs.removeIf(beeUUID -> beeUUID.equalsIgnoreCase(bee.getUniqueId().toString()));
cadiaBees.hivePDCManager.setBeeNames(container, beeNames);
cadiaBees.hivePDCManager.setBeeUUIDs(container, beeUUIDs);
List<String> beeUUIDs = cadiaBees.hivePDCManager.getBeeUUIDS(container);
List<String> beeNames = cadiaBees.hivePDCManager.getBeeNames(container);
if(beeUUIDs.get(0).equalsIgnoreCase("") || beeNames.get(0).equalsIgnoreCase("")) return;
Ok so if I check if the first item is "" it works but if I check if the array size is empty or size = 0 it doesnt return
Ah okay, so it's kind of the same as in forge
and Item I assume is like the placeholder that serves for itemstack to clone off it and have it be used in the normal items?
public List<String> getBeeUUIDS(PersistentDataContainer container) {
List<String> beeUUIDs = new ArrayList<>();
NamespacedKey hiveStoredBeeUUIDsKey = new NamespacedKey(cadiaBees, "hive-stored-bee-uuids");
//Get stored bee names from metadata, separated by !*!
if(container.has(hiveStoredBeeUUIDsKey, PersistentDataType.STRING)) {
String[] storedBeeUUIDs = container.get(hiveStoredBeeUUIDsKey, PersistentDataType.STRING).split(",");
for (String storedBeeUUID : storedBeeUUIDs) {
beeUUIDs.add(storedBeeUUID);
}
return beeUUIDs;
}
return new ArrayList<>();
}
public void setBeeUUIDs(PersistentDataContainer container, List<String> beeUUIDs) {
NamespacedKey hiveBeeUUIDsKey = new NamespacedKey(cadiaBees, "hive-stored-bee-uuids");
container.set(hiveBeeUUIDsKey, PersistentDataType.STRING, String.join(",", beeUUIDs));
}
First of all
hiveOwner != null & hiveOwner.isOnline()
->
hiveOwner != null && hiveOwner.isOnline()
You dont want to use a bitwise AND for boolean logic
?
Nevermind actually, I'll just assume it's the same as in forge and go on. If there's any issues i'll come back.
why not
that part works fine
@last temple would iot be something along the lines of
public void onClick(InventoryClickEvent e) {
Player player = (Player) e.getView().getPlayer();
if (!(player.getInventory().getHelmet().equals(DragonHead.head))) {
player.removePotionEffect(PotionEffectType.FAST_DIGGING);
} else {
player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 999999, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 9999999, 3);
}
}```
wdym?
they can have dashes though
Use a Set<UUID> instead of a List<String> and then use remove instead of removeIf
Where at?
The check of the slot. The click event is fired before the item is moved. So you need to check one tick later.
Before I was using remove and it wasnt actually removing from the list for some reason
ahh
This should have alerted you that something is wrong
Any easy way to double the amount of items dropped from a block break event?
yep
Yes. BlockDropItemEvent
how do I get thge clicked slot?
Are you using the right names? CustomName for both adding and removing?
the*
Yes
List<String> beeNames = cadiaBees.hivePDCManager.getBeeNames(container);
List<String> beeUUIDs = cadiaBees.hivePDCManager.getBeeUUIDS(container);
if(beeUUIDs.contains(bee.getUniqueId().toString())) {
Player hiveOwner = Bukkit.getPlayer(cadiaBees.hivePDCManager.getHiveOwner(container));
if (hiveOwner != null & hiveOwner.isOnline()) {
hiveOwner.sendMessage(ChatColor.RED + "One of your bees from the hive " + ChatColor.translateAlternateColorCodes('&', cadiaBees.hivePDCManager.getHiveName(container)) + ChatColor.RED + " has died!");
hiveOwner.playSound(hiveOwner.getLocation(), Sound.ENTITY_BEE_DEATH, 1.0f, 1.0f);
}
beeNames.remove(bee.getCustomName());
beeUUIDs.remove(bee.getUniqueId().toString());
Bukkit.broadcastMessage(beeNames.toString());
Bukkit.broadcastMessage(beeUUIDs.toString());
It removes the uuid but not the name
Then the name is not in the list.
As stated before: We cant make any sense of this convoluted, small piece of code.
Send the whole code.
ugh.
dont really like the idea of giving out my hundreds of hours worth of work but i guess.
well i hardly think we want to steal code that does not work
^
I have a serialized inventory in JSON (So, just all of the contents of the inventory in a map), and I was making the deserialization method.
I came across this issue though: I can't create a new instance of Inventory and put items into it, can I?
You need to let Bukkit create a new Inventory by calling
Bukkit.createInventory(...)
fk
Thank you, I would've never guessed.
This might come off as condescending, but I don't mean it that way, I would actually never had guessed or at the very least have taken hours to do so.
So, thank you!
if(e.getClickedInventory() == player.getInventory() && e.getSlotType() == InventoryType.SlotType.ARMOR)
hopefully this works
how could I read all files from selected directory from resources?
Usually throwing a few keywords at the javadocs tells you what to do.
?jd-s
I wasn't using the javadocs ๐
I was using... this https://helpch.at/docs/1.7.10/
But i'll switch to the javadocs if I can find the 1.7.10 version of it
Ah yes. Brand new software from half a decade ago
๐
I;ve seen that method but It only returns one file
It's been so long since 1.7.10... It's honestly scary.
Its not super straight forward. You need to traverse the jar file.
I can have multiple eventhandlers in one file right?
I keep forgetting
or I've never actually tried it
Yes every EventHandler method is being registered on its own
get the folder and loop over the files
Honestly the only time I haven't shared my code in order to improve it was when I was under an NDA, lol.
ok great
"from resources"
but how to get folder from resources?
Its happened before. Many times.
still. get the stream, fetch the resource names, loop.
?paste
? spigot web down?
@lost matrix files in question are gui/HiveGUI and HiveGUIListeners
https://paste.md-5.net/navajekure.java
Look at the copyResourceDirectory(JarFile, String, File) method. It lets you copy a whole directory from inside a JarFile.
oof
thx
tf
try now
works
๐
Print out the File and see if its the location you are expecting
Are you trying to load the image from inside your plugin?
owner can be null
That is not a File
Yep, I realised it was an unnecessary question and deleted it, apologies.
Currently testing:
- Kill a bee (listeners/BeeDamageListener)
- Open gui (gui/HiveGUI and gui/HiveGUIListeners)
Does the inventory slot count start at 1 here, too?
0
Oh, that's nifty, thank you.
Sry but im not reading a gui that doesnt use the delegation pattern. All those nested ifs are really obfuscating the code and im too tired for this rn.
idk just save the image into your plugin folder and load it from there
what does that even mean
Generally speaking, huge functions are impolite to the reader
Because you need to read the entire function to understand what it does
Having small functions that call more detailed functions allows the user to exit early
Which is polite
wasnt originally meant for other people to go through, i know what it all does so i didnt care
Well when you ask for help you basically imply others are gonna read it
would take hours to rename and change everything
Probably not
the entire code shouldnt be needed for this tiny issue anyway
Readability issues have bigger impact on productivity than what you may think
the issue is somehow it thinks the array has a value when it doesnt
I'm ngl reading code on mobile rlly is not easy
just care for your code from the beginning on
it makes perfect sense to me anyway
so i dont get how it could be "simpified" anyway
looks like it dont otherwise you wouldnt be here
Solution: just code 4head
Could you paste where you add, use and remove elements from the pdc pls?
consider to optimalize that
how
Optimalize
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
k so here im checking the entity name
and removing it from the list
but it doesnt remove it with remove, but it does with a removeIf which makes 0 sense.
Btw. Why are you using pdcs like that? Just store everything in your CustomHive when the chunk loads and
write the CustomHive inside the BeeHive when the Chunk unloads.
Create a CustomHivePersistentDataType. This way you only have a single point of failure.
it was originally all in the customhive then i split it out cause i thought it would be more simple using pdc and i was learning it so it seemd more fun
proving to be aids.
im trying to store as much as possible in the pdc
Well pdc is really nice if you treat it as a persistent storage medium and not like a memory one.
isnt that the same thing
...
back again, still have this weird hanging thing that not even thread dump works during
anyone have and idea?
its during a world generation
๐
its like a hang but with not much cpu/ram usage
If i could just remember the commands...
Is your disk full?
Like >95%
the only thing im storing in files is the location
nope
and in the object
the rest is in the pdc.
the world creation is the standard WorldCreator setup with an amplified world
This makes no sense. You should choose one. You wouldnt store 20% in sql 20% in mongodb and 60% in a file too.
my guess is certain biomes arent compatible with amplified
oh cave biomes thats probably why
The only reason im storing in files is so i know where to load the holograms and stuff.
on server load.
List<Biome> biomes = Arrays.stream(Biome.values()).toList().subList(0, Biome.values().length - 1);
->
private final List<Biome> biomes = Arrays.asList(Biome.values());
k
sublist is just to get rid of biome.custom
Working with PDC has proven to be a pain in the ass.
might just go back to the object and save/load with gson.
remove this line and check if it solves your problem
it was there before that
ill just comment it out ig for now
but wait how am i supposed to generate it then
the other things use it
so should i just do away with pdc then..
btw the "cwchunkmap" variable is a JSONObject
not map
i should probably rename that
trying to make it so each chunk has a random biome
maybe getting a world instance while its generating is a bad idea
Then for now just do this:
public class CorruptedWorldBiomeProvider extends BiomeProvider {
private final List<Biome> biomes = Arrays.asList(Biomes.values());
@NotNull
@Override
public Biome getBiome(@NotNull WorldInfo worldInfo, int i, int i1, int i2) {
return biomes.get(ThreadLocalRandom.current().nextInt(biomes.size()));
}
@NotNull
@Override
public List<Biome> getBiomes(@NotNull WorldInfo worldInfo) {
return biomes;
}
}
And see if it works.
Yes
Thats why i told you to remove the line for now
Is there a way to change the item you take in the EntityPickUpEvent
without touching the inventory
so...
If you want to react on loaded chunks you should listen to the ChunkLoadEvent and check if its a new Chunk.
Yes you can change the ItemStack of the picked up Item
If you set the itemstack on the ground in the class of Item it doesn't work
i want it to generate with random biomes though
Show some code
k
The code ive provided generates completely random biomes
That's a basic example
it loaded, im gonna go join it rq to see if its the way i want it
I even tried cancelling the event and cancel the cancellation with a delay of 2 ticks but still doesn't work, debugging I saw that the item actually changes, btw doesn't work .
This snippet looks like it should work...
๐ฅฒ
What do you suggest me
ok im switching back to the object and gson only. fuck pdc
one moment
Take care that I can't do it changing the item from the inv.
Since for my scope I need to change the actual itemstack you take from the ground.
yoo 7smile7 is back
ayo @lost matrix I beg you to make a tutorial on armorstand rotations and quaternions
I've been looking into it all night and I think I'm dumber now
@EventHandler
public void onPickup(EntityPickupItemEvent event) {
event.getItem().setItemStack(new ItemStack(Material.STONE));
}
nvm it says cannot create world with biome CUSTOM
@lost matrix
Then remove the biome
That's the same code
in theory you dont need quaternions in minecraft because you have no roll.
This is quite difficult to explain in a simple, non-mathematical way.
Maybe is the spigot version?
armorstand heads use euler angles
What version are you on? 
so you have roll
Won't you insult me?
I've been messing with it all night, even made a quick plugin
Well im glad it doesnt work then... sry
sidajdioasjaiojdajsio
btw
1.12.2

Ah thats not too bad
wdyw?
got nullpointerexception smh
First person who doesn't judge it
But anything below 1.13 is Bad either way
๐ฅฒ
oh saving stuff to file
Should work actually. Make sure the listener is registered. Do a clean setup so you can be sure that no other listener interferes.
forgor
It is..
Bad as in anoyying that is
I'mma actually import your code without any changes.
There is a fork that has an api for pathfinding. Otherwise: NMS
well yea im using nms
paper has pathfinding
i just generally dislike how its hard to specify goals for a limited amount of time
you can add, remove and set goals
?whereami
but pathfinders weren't made to be dynamic like that
ok found a way for it to work thx
I regret making this
why
how can i set a skull's skin using a skull value?
- I already use them
- There are no API for this event
- It's the first item I dropped, don't care that is a weapon
- Already tried 1 tick
debug it
already done
the result is that the item changes as it shoulds
but only in the console, not in the pratic
why do you need this?
It's a fingerprints plugin
I have all code I need, but this doesn't work, I would have cancelled and set the item manually using the sounds, but the animations when you take the item, can be made just from the original event
a sec
skull value?
public static ItemStack getHead(Player player) { ItemStack skull = new ItemStack(Material.PLAYER_HEAD); // Create a new ItemStack of the Player Head type. SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); // Get the created item's ItemMeta and cast it to SkullMeta so we can access the skull properties skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(player.getUniqueId())); // Set the skull's owner so it will adapt the skin of the provided username (case sensitive). skull.setItemMeta(skullMeta); // Apply the modified meta to the initial created item ItemMeta itemMeta = skull.getItemMeta(); skull.setItemMeta(itemMeta); return skull; }
no
@patent fox
not like that
using the skull value?
you want to read teh skin off an already existing skull?
uh
its not a player
what tp is that
You can create a Player profile and set it to the skull using setOwningProfile
tp?
Mine
public static SkullMeta setProfile(final SkullMeta meta, GameProfile profile) throws ReflectiveOperationException {
final Method profileMethod;
profileMethod = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
profileMethod.setAccessible(true);
profileMethod.invoke(meta, profile);
return meta;
}```
eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTJkZDExZGEwNDI1MmY3NmI2OTM0YmMyNjYxMmY1NGYyNjRmMzBlZWQ3NGRmODk5NDEyMDllMTkxYmViYzBhMiJ9fX0= Is the texture part
thats teh only part you need
public static GameProfile makeSkullProfile(String base64) {
final GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null);
gameProfile.getProperties().put("textures", new Property("textures", base64));
return gameProfile;
}```
For the blocks I don't have any problems to send you it
idk if com.mojang.authlib.GameProfile is considered nms
Using PlayerProfile ```java
/**
* Create a Skull with a texture using the new PlayerProfile
* Post 1.18.2
*
* @param id UUID to assign the skull.
* @param name a name for the skull
* @param texture a Base64 texture String
* @return Skull ItemStack
*/
public ItemStack getHeadByProfile(UUID id, String name, String base64Texture) {
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
PlayerProfile profile = Bukkit.getServer().createPlayerProfile(id, name);
try {
profile.getTextures().setSkin(new URL(getURLFromBase64(base64Texture)));
SkullMeta meta = (SkullMeta) head.getItemMeta();
meta.setOwnerProfile(profile);
head.setItemMeta(meta);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return head;
}
private String getURLFromBase64(String base64) {
return new String(Base64.getDecoder().decode(base64.getBytes())).replace("{\"textures\":{\"SKIN\":{\"url\":\"", "").replace("\"}}}", "");
}```
was that api in 1.12.2?
1.18.2
Should I consider it as a bug of spigot?
Technically even if I can't get any help for legacy versions, it's a bug, right?
Sometimes the "other ways" are limited
There are at least 2 ways every time, but this time Idk what to do else
part of the fun of signing up for legacy versions
Any aproach?
you should be skilled enough to find solutions to legacy bugs
If you use legacy versions is under your own responsbility
Maybe if I explain really quick the plugin, you might help me?
nope!
That's the point.
im not knowledgable in 1.12
๐ก
Dont use 1.12
so even if i tried to help
Forget that now!
Use 1.19
i wouldnt be able to
never
never
If you use legacy versions is your problem to solve the things
at minimum 1.14 imo but i still likely wont help lol
Imagine you're talking with someone that has 1.19 spigot version
don;t worry, the spigot forums were very popular around 1.12
Legacy versions == Not being helped most of the time
so your problem may be on there
It's wrote even in the download section
But if you help me at least..
๐ฅฒ
?
Okay, so why you are asking for help
what is this
I have more than 20 handlers
And i dont want to initialize by hand and call the method enable/disable
Not asking for help to fix spigot bugs, just help to get another solution
If you really want help move away from tha version
I think I'll just quit helping and start solving the problem before I get tired
could you create an interface with those methods in them?
No, because each handler has diff things
Imagine you're talking with someone that has 1.19 spigot version
well isn't that the point of an interface?
just for the shared enable/disable methods?
yes but if you use, you also have to initialize each manually
๐ค
So is the same thing hahaha
yes
yes thats fair
dont worry about that
they all have "Prison" as a paramater
correct?
and they all return of type "Handler" (you should seriously consider renaming that)
Wait wait
Each handler should contains enable/disable and also getters, setters and methods
So i dont want to do this with every handler:
void loadHandlers() {
CoinsHandler coins = new CoinsHandler();
coins.enable();
UserHandler users = new UsersHandler();
users.enable();
}```
So that why im doing reflections
void registerHandler(Handler handler) {
handler.enable();
...
}
Also need to manually initialize each handler!
๐
registerHandler(new CoinsHandler());
registerHandler(new UsersHandler());
Same thing hahaha
public enum HandlerType {
HANDLER_A(HandlerA::new),
HANDLER_B(HandlerB::new);
private final HandlerFactory factory;
public HandlerType(HandlerFactory factory) {
this.factory = factory;
}
Handler create(Prison prison) {
return factory.create(prison);
}
private interface HandlerFactory {
Handler create(Prison prison);
}
}```
now you could call HandlerType.HANDLER_A.create(prison)
But i dont want to get the handler obj
Because them i cannot call non handler interface methods
you're still registering them in the enum
true
Is more cleanner
Because i dont overload the main class
here is a similar pattern
heavily inspired by nms EntityTypes
now I could call DungeonEntityType.IRON_BEE.create(level, dungeon) and that will give me an "IronBee"
but idk if your handlers are meant to be singleton-esque
I mostly ue Di
But wait i cannot do the thing you are doing
your reflective way of doing things is too sloppy imo
because them i cannot call the getters/setters of the TestHandler
loopy?
yes you could?
public T create(Level level, Dungeon dungeon) {
return spawnFactory.create(entityType, level, this, dungeon);
}```
this gives me the type of the mob i want
if you used this with your handler pattern you would get an object of type TestHandler
what does javadocs say
Interactable materials include those with functionality when they are interacted with by a player such as chests, furnaces, etc. Some blocks such as piston heads and stairs are considered interactable though may not perform any additional functionality. Note that the interactability of some materials may be dependant on their state as well. This method will return true if there is at least one state in which additional interact handling is performed for the material.
my guess is yes
Is possible to generate getters via reflections?
generate? No. You can generate code with an annotation processor though
Though that's done at compile-time
oh ** yeah i forget that tho
etcetera
idk
thats what the jd says
you could always jsut.... test it out
its not a very complicated thing to do

i mean you read the docs yourself
someone know why splitting by . is not working?
thx
em.. i not much into regex, why the error apperas?
its faster
๐ ok
unsure actually
StringUtils.split(file, "."); ok, this should works
Bukkit.getScheduler().scheduleSyncRepeatingTask(Bedwars.getInstance(), () -> {
for (int i = 0; i < 600; i++) {
World world;
world = arena.getWorld();
int min = - arena.getBuildWidth();
int max = arena.getBuildWidth();
int xrandom = (int) (Math.random() * (max - min + 1) + min);
int zrandom = (int) (Math.random() * (max - min + 1) + min);
Block up = world.getHighestBlockAt(xrandom, zrandom);
Location loc = up.getLocation();
if (!up.getType().equals(Material.BED_BLOCK) && !up.getType().equals(Material.CHEST) && !up.getType().equals(Material.ENDER_CHEST)) {
world.playSound(loc, Sound.CHICKEN_EGG_POP, .5f, 2f);
loc.getBlock().setType(Material.AIR);
}
}
}, 600, 5);
Why is it prioritizing glass blocks? Wtf?
1.8.9
?1.8
Too old! (Click the link to get the exact time)
Speaking of super old versions, guessing it is no longer possible to make 9+ row GUIs now-a-days?
MC-108756 got patched a while ago; somehow only noticed just now
windows 10 was released exactly 1 day after java 1.8.8 believe it or not
yep, maximum is 54 slots
๐ฆ
You never could. At least without it looking janky af.
ik, but it still gets updates
1.8 not
well yea i guess
^ If you were willing to live with it looking janky, you could have 100+ slots
There were bugs that allowed for slots to overflow, but those have been patched.
๐ฆ giant ugly chest guis were surprisingly useful for things that didn't need much polish
anyways, at least its more consistent now
No one has any idea what your Mask is. Its not Spigot
Probably we
Possibly
Is Java engine caching strings? I'm currently adding the translations to my plugin so should I store translation's paths in some static field?
you have way too much hope
java engine
๐คฃ
well technically
yes they are "cached"
you are not wrong
they are held in the constant/string pool
until the garbage collector pulls up
Nope, they stay in the constant pool in JVM bytecode
as far as I know strings are catched in a function range
no Java does not cache for you
otherwise strings would be prone to memory leaks extremely easily
like when you make 2 string with same value in a function they are assigned to one pointer
let me clarify, strings that are referenced without being concatenated or anything
like a direct string in source code
similar to that translation path
"12" + v + "e" couldn't be stored in the constant pool
instead, "12" and "e" would be
Yes, this is the string pool
because strings are immutable
but you can bypass that by directly calling new String("test")
but it's not really a pointer, nor is it only limited to the function invocation
Lang.get("gui.base.insert.desc") well so everytime I will be calling this method new string will be created?
oke
what does itemstack#issimilar account for
it should be everything apart from stack size
Read the docs and find outโข๏ธ
thx for a real answer
๐คก
declaration: package: org.bukkit.inventory, class: ItemStack
I bruised a finger finding it in the docs 
wat
lol
Javadocs are your friend. I have them open in my browser 24/7
that's literally why they exist
whos mad?
you
no?
Thanks for the real answer as if my answer wasn't good
hoes mad
You could get an answer faster if u opened javadocs instead of asking here
ornns mad
I got an answer from the one dude in like 2 seconds
Yeah but instead of typing it here you could have gotten it instantly from the docs
Just annoyed at a question where the answer is free, online, and instantly accessible
Leave Britney alone!
I liked early 2k britney
Early 2k Britney would have used the docs ๐ค
is it possible to take an arg from a command and use it in a listener?
Commands are instant. Listeners are event triggered.
Store the data from the command somewhere, like in a map for the player or on the player
Hashmap?
ie, player issues command, store in a map against teh players uuid.
event happens and your listener fetches data for the relevant player from the map
it depends on what you need to store and why
so the players gets a book after using the command and the books name is the args[1] = player message. but I want to use it in a PlayerInteractEvent
I am making a GUI, and I am on the part where I need to check if the inventory clicked is the GUI in order to cancel the click event, but for some reason e.getInventory().equals(gui) returns false. Does anybody know why the inventory in-game is considered unequal to gui? https://paste.md-5.net/jidarotovo.java
then no need to store anything. You put teh info on teh book when you create it
wdym?
you store the data on the book in its name, so when you click the book, just get the name
yes but
ItemStack permpaper = new ItemStack(Material.PAPER);
ItemMeta papermeta = permpaper.getItemMeta();
papermeta.setDisplayName("ยง7ยป ยงe" + args[1]);
If it has coloring store it in the PDC so you can know it's your book
"ยง7ยป ยงe" + args[1] that's the name
isnt PaperMeta its own thing

or BookMeta
so not a book
Use the PDC and store whatever you want to use later in it to prevent anvil exploits.
paper and book but this is from a book
The simple way is to get teh papers name when its clicked and strip colors. The proper way would be store in its PDC.
?pdc
put Player p = (Player) e.getWhoClicked(); to the beginning and try
bruh
why not just check the inventory title
noooo

