#help-development
1 messages · Page 25 of 1
color codes?
well then you're just making a hacky workaround to something you can already do properly
InventoryHolder is not the best. Comparing instances is the proper way to do it.
the proper way is probably comparing instances of the inventory, people also do inventoryholders but its technically a misuse of the api although it wont cause any issues
Yeah well until you deal with delegates and views
java.lang.IllegalStateException: Asynchronous command dispatch!
at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:16) ~[pufferfish-1.18.2.jar:git-Pufferfish-72]
at org.bukkit.craftbukkit.v1_18_R2.CraftServer.dispatchCommand(CraftServer.java:882) ~[pufferfish-1.18.2.jar:git-Pufferfish-72]
at xyz.praydev.event.SpawnBossEvent$1.run(SpawnBossEvent.java:74) ~[CustomEggs-1.0-shaded.jar:?]
at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftTask.run(CraftTask.java:101) ~[pufferfish-1.18.2.jar:git-Pufferfish-72]
at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[pufferfish-1.18.2.jar:git-Pufferfish-72]
at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[pufferfish-1.18.2.jar:git-Pufferfish-72]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mm m spawn SkeletonKing 1 " + player.getWorld() + "," + clicked.getX() + "," + clicked.getY() + "," + clicked.getZ());
Anyone know what is causing this?
?scheduling
502
my brain doesn't work for this do u have any other solution lmao
pdc is the correct approach
?pdc
he talked to me
pdc wasn;t for you
huh
how long would it take to do this?
minutes
do u know how to do it? ^^
yes
u have time to do it?
and do you want to do it?
taken directly from that wiki page...modifiedjava ItemStack itemStack = ...; NamespacedKey key = new NamespacedKey(pluginInstance, "args"); ItemMeta itemMeta = itemStack.getItemMeta(); itemMeta.getPersistentDataContainer().set(key, PersistentDataType.STRING, args[1]); itemStack.setItemMeta(itemMeta);
that would put the data in the pdc
"args" is correct there?
Then in your interact or click event you read it from the PDC
thats what you want to store isn;t it?
args[1]
yes
reading is ```java
ItemStack itemStack = ...;
NamespacedKey key = new NamespacedKey(pluginInstance, "args");
ItemMeta itemMeta = itemStack.getItemMeta();
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
if(container.has(key , PersistentDataType.STRING)) {
String foundValue = container.get(key, PersistentDataType.STRING);
}```
pluginInstance?
your plugin
if your doing this in the class which extends JavaPlugin, you would use this
else
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
where do I say what to do if he clicks on it?
I know that i have to use action.... and stuff..
yes, that is old code, use teh getSaturation/setSaturation on teh player
food level and saturation are different
saturation is how long you stay sated
food with zero saturation would fill you up, but instantly start to decrease
the higher the saturation level, the longer before your food level drops
you have to cancel teh consume event and reduce the item count yourself
you are doing the math now
of course you can
get the ItemStack
its teh actual ItemStack you are eating
Uhm, so rn, I was going to check for every single thing I get from the config and report and error in case it doesn't find it, the thing is, is there no other way of doing this? Seems like DRY to be doing this like 15 different times...
not a clone so you can reduce the amount
getItem().setAmount(getItem().getAmount() -1)
the event has nothing to do with teh ItemStack
its just returning teh ItemStack
YOU reduce it
Hello, how can I change the build output of my plugin?
you don;t leave it for the event to do, you are canceling that
teh
it doesn;t matter, you are just reducing it in the Listener
rip

canceling the event does not stop your code running. YOUR code still takes effect
Reading this is giving me a headache even tho I've been taking ibuprofen
He literally told you the answer
Just cancel the event and reduce teh stack size as I've told you
cancelling an event just tells spigot not to make any changed due to the event. Your listener is not the event. it's just code.
yes, cancel event, reduce stack size, increase food level and saturation
yes
Does anyone have any examples of FileConfiguration implementations?
a hearty meat pie shoudl give way more saturation than an apple
What for
Are you making like a toml version
Hmm, sure, toml is the simplest and easiest to understand afterall.
true
Just implement it
your ide will tell you what to override
its pretty self explanatory
Sure, but I don't know what each method does, and it would be easier for me If I had some sort of example for this.
hmm
?configs
See this wiki page on how to use custom configuration files: https://www.spigotmc.org/wiki/config-files/
I see.
how do I get this location?
second image
I want the location of the shulker being held by the armorstand
or more accurately, I want the pufferfish to spawn directly on the shulker shell item held by the armorstand
I think you need to guesstimate it
Relative to a known location of the armour stand
it is going to spawn at random pitches, yaws, and xyz cords
the shulker item will always be pointed away from the item, however, as shown in the image the shell is about 0.5 behind the armorstand and roughly 2 y cords above the armorstand base cord. But the xyz cords are changing
just get the item in teh players hand then
Is there a way to create an empty dummy player?
Doesn't even need to exist in the world, I just have the object.
Thanks.
yes but not a beginner thing. It uses NMS and is version specific
I see, thanks.
Read this thread https://www.spigotmc.org/threads/player-right-hand-location.168219/
so long as you don't adjust the bodyPose you should be able to calculate the hand position
question..
so I have an itemstack.
I then pass the itemstack into a function which sets PDC keys on it
then back in the main function, I set the itemmeta and add the item to my inventory
does it save the changes I made to the PDC?
pdcManager.setCustomHive(customHiveItem);
customHiveItem.setItemMeta(customHiveMeta);
return customHiveItem;
public void setCustomHive(ItemStack itemStack) {
NamespacedKey customHiveKey = new NamespacedKey(cadiaBees, "custom-hive");
if(!(itemStack.hasItemMeta()) || itemStack.getItemMeta().getDisplayName() == null) return;
ItemMeta itemMeta = itemStack.getItemMeta();
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
container.set(customHiveKey, PersistentDataType.INTEGER, 1);
itemStack.setItemMeta(itemMeta);
}
It's not actually setting my value
setCustomHive method is fine, however, test hasCustomName()
oh no methodf. I thought there was
I dont see hasCustomName
ignore me then. I'm thinking of something else
I also tried changing my setCustomHive to return an itemstack
customHiveItem.setItemMeta(customHiveMeta);
customHiveItem = pdcManager.setCustomHive(customHiveItem);
return customHiveItem;
I dont see why this isnt working
Yeah it reaches it
theres nothing wrong with the pdc code
Ayo I'm struggling a bit with armorstand math
Let's assume that I want to rotate an upright item set on an armorstand's head
I can set the Z angle to 315º (-45º) for the item to be upright
but rotating the head on the Y axis breaks because of roll
Is there any simple way of rotating X Y and Z angles to negate the roll effect?
Basically getting the item to rotate around the Y axis as if Z was 0
https://haselkern.com/Minecraft-ArmorStand/ idk if this will help
Create poses for Minecraft armor stands in a breeze! Free, fast, open source.
are you trying to make it rotate in a loop de loop?
no
new 1.19.1 player chat event?
private UUID hiveUUID;
private String hiveName;
private UUID ownerUUID;
private Location hiveLocation;
private List<UUID> holoUUIDs;
private List<RewardItem> rewardItems;
private List<String> beeNames;
private List<UUID> beeUUIDs;
private int beeAmt;
private int honeyAmt;
private HiveLevel hiveLevel;
private HiveStatus hiveStatus;
private Boolean beesBeingRenamed = false;
Gson should be able to work with all these right?
its creating a blank json file when i save
or do I need a custom factory for the location?
It won't be able to serialize a Location, but aside from that, assuming all your other classes (RewardItem, HiveLevel, and HiveStatus) contain fields that are also serializable, should be fine
If RewardItem contains an ItemStack, it won't serialize either
It does...
so I need a custom factory?
do you have a link to a good tutorial? I haven't done it in a while
Well, in general
bump
Not overly complicated to implement. You need a class that implements JsonSerializer and JsonDeserializer, then you can register an instance of it in a Gson builder with registerTypeAdapter()
Gson gson = new GsonBuilder()
.registerTypeAdapter(ItemStack.class, new MyCustomItemStackSerializer())
.build();```
i think ive seen a plugin where they just convert items to like base64 or smth
Something like that
like a plugin that a can use the api of?
You could, but that uses a JsonReader and JsonWriter, which means you have to work with very, very primitive Gson which can be faster but is excruciatingly annoying
The former two interfaces make it a bit nicer to write serializers/deserializers
Custom gson serializers/deserializers
oh wait
from SO
public class StudentAdapter implements JsonSerializer<Student> {
@Override
public JsonElement serialize(Student src, Type typeOfSrc,
JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.addProperty("name", src.name);
obj.addProperty("school", src.school.id);
return obj;
}
}
its that easy?
yes
then there’s a method you need to call on the GsonBuilder instance
but that’s it
How could I get the GENERIC_ATTACK_DAMAGE value of an itemstack?
Or check if the GENERIC_ATTACK_DAMAGE value was modified in some way, shape, or form
ItemMeta
So if the GENERIC_ATTACK_DAMAGE value is in the itemmeta it's been modified correct?
I heard that it won't be in the ItemMeta if it's the default value
might be the case
Alr thanks
guys, with a custom jsonserializer I am unable to simply obj.addProperty("itemLore", src.getItemMeta().getLore());
guessing its because lore is a string
Or would I do obj.add("itemLore", (JsonElement) src.getItemMeta().getLore());
Is there a way to listen for when the warden sniffs
bump
seems to be bound to entity metadata
I don't see anything
There's only so much you can do with spigot
custom entities weren't something that should be in spigot by design
yeah but is there a plugin for nms custom enites for 1.19
closest thing you have is mythic mobs
danm
I HAVE
except i believe it uses nms
because bukkit is DUMB and STUPID
and ive not fully tested all use cases so there's that
lore is a List of type String
Yes
I think I got it
by making a JsonArray instead and adding the lore to it.
ah yeah
You need to make the List a JsonArray first, pretty sure the only way is to iterate and add to a new JsonArray(), then you call add with the new populated JsonArray
oh
I did that
well it seems I’m late
Stupid question
How can i incrase the animation speed of End Crystals? So they spin slower/faster
Or is it only client side for crystal rotation speed
clientside
server wouldn't bother

maybe?
wtf
didnt even think of nms ngl
wth would time be thats a big ass number
0 - 1m
@carmine nacelle
hello
public static final class ItemStackJsonSerializer implements JsonSerializer<ItemStack>, JsonDeserializer<ItemStack> {
@Override
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(CraftItemStack.asNMSCopy(src).save(new CompoundTag()).getAsString());
}
@Override
public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
String asString = json.getAsJsonPrimitive().getAsString();
CompoundTag compoundTag = TagParser.parseTag(asString);
net.minecraft.world.item.ItemStack nmsStack = net.minecraft.world.item.ItemStack.of(compoundTag);
return CraftItemStack.asCraftMirror(nmsStack);
} catch (CommandSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
}```
this is an item stack json serializer
i will warn you
this is untested for most items
@Override
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) {
if(!(src.hasItemMeta()) || !(src.getItemMeta().hasDisplayName())) return null;
JsonArray loreArray = new JsonArray();
for(String loreLines : src.getItemMeta().getLore()) {
loreArray.add(loreLines);
}
JsonObject obj = new JsonObject();
obj.addProperty("itemType", src.getType().toString());
obj.addProperty("displayName", src.getItemMeta().getDisplayName());
obj.addProperty("itemAmount", src.getAmount());
obj.add("itemLore", loreArray);
return obj;
}
does the one I just made look fine?
BUT, i have confidence it will work because it literally uses nms' method for saving items to files
it would not account for any item meta thats unique to stuff like banners, armor, etc
mine or yours
this could also be easily converted to reflection
yours, vivian
because I dont have the tags?
well you would need to serialize all possible item meta types
Yours does that?
i mean
but it's what it uses internally
i mean it would, you would just need to know item NBT
i do use it for saving/loading player inventories btw
well that's fair, it just wouldn't be pretty kekw
Well I won't be able to test it until I come up with one for locations but ill say TIA
why not just make the NBT a blob and store it in a database 😢
well the blob is unnecessary since NBT is quite literally a string
but why are u storing it in config files instead of a database
I don't know, maybe it hates you?
How would you register this? @glossy scroll
?
same way Choco showed you Vivian
oh
how can it hate me.
its important
it needs to be TypeHierarchyAdapter
i forgor why
new Gson(registerTypeHierarchyAdapter(ItemStack.class, new ItemStackJsonSerializer()))
oops
thats completely wrong
new GsonBuilder().registerTypeHierarchyAdapter(ItemStack.class, new ItemStackJsonSerializer()).create()
TypeHierarchyAdapter registers for all subtypes
^
so anyone knows?
what is instance
It probably doesn't need to be a TypeHierarchyAdapter
literally Hopper
theres 2 i think
org.bukkit.block.Hopper
Gson gson = new GsonBuilder()
.registerTypeHierarchyAdapter(ItemStack.class, new ItemStackSerializer())
.build()
Cannot resolve method build
oh
hmm
BlockState*
"Hopper extends BlockState, InventoryHolder"
no i meant
BlockData is immutable
well actually
it is mutable
it just gives a copy
well it's immutable in effect xd
that is not the point tho
The returned object will never be updated, and you are not guaranteed that (for example) a sign is still a sign after you capture its state.
Returns:
BlockState with the current state of this block.```
i believe it is a copy
I have a BlockState (Hopper block state) and I'm currently attempting to edit it's inventory and update.
but it just doesn't update.
the array I'm providing IS the one I want
but you update it
but setContents on the inventory is not working
so it should be ok
i know im just saying
Martoph, a location serializer should be simple right
:(((((
yes a location serializer in incredibly easy
write primites x, y, z, pitch, and yaw
and a uuid (string) world id
literally it
oh
this is so stupid
I thot so
public static final Gson LOCATION_GSON = new GsonBuilder()
.registerTypeAdapter(Location.class, (JsonSerializer<Location>) (src, typeOfSrc, context) -> {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("x", src.getX());
jsonObject.addProperty("y", src.getY());
jsonObject.addProperty("z", src.getZ());
jsonObject.addProperty("pitch", src.getPitch());
jsonObject.addProperty("yaw", src.getYaw());
return jsonObject;
}).registerTypeAdapter(Location.class, (JsonDeserializer<Location>) (json, typeOfT, context) -> {
JsonObject jsonObject = json.getAsJsonObject();
return new Location(null, jsonObject.get("x").getAsDouble(), jsonObject.get("y").getAsDouble(), jsonObject.get("z").getAsDouble(), jsonObject.get("pitch").getAsFloat(), jsonObject.get("yaw").getAsFloat());
}).create();```
well i mean
you still need an adapter i meant
that code is apparently from nov 2021 so
Whats wrong with anonymous classes
yea i should specify
(idk shit about them)
this is for my niche use case
you may need to alter as necessary
meaning write the world name and then use Bukkit.getWorld
anonymous classes are what he did there, where he was able to put the serializer code right into the body instead of declaring a new class
world uuid pls*
or i mean a much easier way to serialize locations if you dont care about rotation is
convert them to vectors
then you dont need a type adapter
Ugh, Bukkit is inefficient.
yea that would be better, admittedly didnt know they had uuids 😬
well theres nothing wrong with them
@Override
public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("worldUUID", src.getWorld().getUID().toString());
jsonObject.addProperty("x", src.getX());
jsonObject.addProperty("y", src.getY());
jsonObject.addProperty("z",src.getZ());
return jsonObject;
}
anon classes cannot be instantiated outside that very statement
hows that
^ the reason I was like "yikes" is because it'll clutter your GSON-declaring class (your plugin class, probably) with serializer code, when it really should be in a separate class
Oh
looks good to me, as long as u dont care for rotation
if you wanted to get really technical you could use getLeastSignificantBits and getMostSignificantBits
what the hell
instead of deserializing a uuid from a string
its honestly personal preference idc
nah just keep it a string, don't worry about what he said- you'd do that type of thing if you were storing in binary form
you just use UUID.fromString or new UUID()
when life gives you lemons, you throw them at people.
@Override
public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
UUID worldUUID = UUID.fromString(jsonObject.get("worldUUID").getAsString());
double x = jsonObject.get("x").getAsDouble();
double y = jsonObject.get("y").getAsDouble();
double z = jsonObject.get("z").getAsDouble();
Location newLocation = new Location(Bukkit.getWorld(worldUUID), x, y, z);
return newLocation;
}
or make lemonade.
WOOO IT SAVED LFG
if you dont care about the world (i.e. it is stored somewhere else)
just use Location#toVector
and save that
then Vector#toLocation
no
you dont need typeAdapter for Vectors
[
{
"hiveUUID": "a9715339-642d-4908-b6a6-540fb284fc7b",
"hiveName": "???????????C????a???d???i????a ?????H???i???v?????e??????????",
"ownerUUID": "e42b60b0-c35a-462f-a2b4-b1a9980f399e",
"hiveLocation": {
"worldUUID": "423cf54e-8122-4586-b34f-9d5b70594b30",
"x": 133.0,
"y": -60.0,
"z": -389.0
},
"holoUUIDs": [
"46aad801-0ecf-4836-8e21-5251ae834e8e",
"f9fde4e2-f31d-4c86-bfd7-86ac0c4e77c1",
"b3304f5b-e7f6-4f89-bd1c-0f34fd4854ea"
],
"rewardItems": [],
"beeNames": [
"???B???e?e"
],
"beeUUIDs": [
"e87eb370-db05-401a-b007-5b1e137f446e"
],
"beeAmt": 2,
"honeyAmt": 0,
"hiveLevel": {
"hiveLevel": 1,
"maxBees": 1,
"maxHoney": 5,
"cost": 0,
"rewardChance": 0
},
"hiveStatus": "PRODUCING",
"beesBeingRenamed": false
}
]
wottf
im satisfied with this i suppose, idk why its turning some of my stuff into weird characters lmao
hiveName: ???????????C????a???d???i????a ?????H???i???v?????e??????????
wtf
because gson works very nicely with vectors
Yeah idk
its actually...
#25ec0dH#2eea0ci#37e80av#3fe609e #48e407L#51e206e#5ae004v#62de03e#6bdc01l#74da00
yes but then he needs to either store Vectors in the class, or write vectors in JsonObject
it just doesn't make sense
its hex coded text.
Why is it doing that
I have no clue
you shouldnt have 2 serialization things going on at the same time
make sure you have .disableHtmlEscaping(), but that shouldn't be the cause
it's a string with hex codes I presume
yes
but its just a string right?
yes
ok
That didnt change it
weird af
It was working fine when I was saving it in a yml
are we sure it's saving like that, and it's not just your text editor
gui-name: '#c35bfb⋯#b65ff8「#a963f6C#9c67f3a#8f6af0d#826eedi#7572eba #6776e8H#5a7ae5i#4d7ee2v#4081e0e#3385dd」#2689da⋯'
this is how that same thing looks when saved in yml
this is good point
im using N++
send the file
now i see §
ah that's what it is
why do you even have to store the UUID of the holograms?
cause my holos save to file also
its packets
n++????
WHAT?
notepad++
legit the best text editor

yes
KEKDOUBLEYOU
anyways
emoji fail laugh at this user
your notepad++ encoding is wrong for that json file
emoji fail?
that's why it can't read the section symbol unicode
How can I change it
and it shows as that weird thing
Oh
Hmmmm
Idk what one I would want
I tried converting to all the different options and nothing changed
can someone join a leave a 1.19 mc server real quick i wanna test a plugin
it is
public void loadHives() {
File file = new File(cadiaBees.getDataFolder().getAbsolutePath() + "/hives.json");
if(file.exists()) {
Reader reader = null;
try {
reader = new FileReader(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Gson gson = new GsonBuilder()
.registerTypeHierarchyAdapter(ItemStack.class, new ItemStackSerializer())
.registerTypeHierarchyAdapter(Location.class, new LocationSerializer())
.disableHtmlEscaping()
.setPrettyPrinting()
.create();
List<CustomHive> hives = gson.fromJson(reader, (Type) CustomHive[].class);
for(CustomHive hive : hives) cadiaBees.hiveManager.addHive(hive);
}
}
class [Lcom.squallz.cadiabees.objects.CustomHive; cannot be cast to class java.util.List ([Lcom.squallz.cadiabees.objects.CustomHive; is in unnamed module of loader org.bukkit.plugin.java.PluginClassLoader @639c9c75; java.util.List is in module java.base of loader 'bootstrap')
at com.squallz.cadiabees.managers.configmanagers.ConfigManager.loadHives(ConfigManager.java:67) ~[?:?]
wat
List<CustomHive> hives = gson.fromJson(reader, (Type) CustomHive[].class); this line is the error
ehm
Type listType = new TypeToken<ArrayList<CustomHive>>(){}.getType();
REEE ANONYMOUS CLASS REEEEE
jk
ily in the gayest possible way
but its erroring on something kinda unrelated now
whats the probleem
[
{
"hiveUUID": "a1455d0e-7466-47d9-989d-f5f2939f9d58",
"hiveName": "???????????C????a???d???i????a ?????H???i???v?????e??????????",
"ownerUUID": "e42b60b0-c35a-462f-a2b4-b1a9980f399e",
"hiveLocation": {
"worldUUID": "423cf54e-8122-4586-b34f-9d5b70594b30",
"x": 138.0,
"y": -60.0,
"z": -379.0
},
"holoUUIDs": [
"33449cc6-63d0-4a51-a4b6-f7093470feaf",
"390166f1-2946-4ac8-bb9e-3099769de6c1",
"4837653b-47ed-4f0b-962d-e7eb7864c547"
],
"rewardItems": [],
"beeNames": [
"???B???e?e"
],
"beeUUIDs": [
"1b4682e9-4c41-4a92-b466-23651abd5999"
],
"beeAmt": 2,
"honeyAmt": 0,
"hiveLevel": {
"hiveLevel": 1,
"maxBees": 1,
"maxHoney": 5,
"cost": 0,
"rewardChance": 0
}
}
]
So this is my file
im loading it
error
[00:32:27] [Server thread/ERROR]: Error occurred while enabling CadiaBees v${project.version} (Is it up to date?)
java.lang.NullPointerException: Cannot invoke "com.squallz.cadiabees.objects.HiveLevel.getMaxHoney()" because the return value of "com.squallz.cadiabees.managers.HiveLevelManager.getHiveLevel(int)" is null
hm
It shouldnt be erroring because... getMaxHoney should be returning the "maxHoney" for the hiveLevel in the json
getHiveLevel is null
yeah but it should be...
shouldnt*
weird.
[00:38:56] [Server thread/INFO]: LEVEL: 1
Bukkit.getLogger().info("LEVEL: " + hive.getHiveLevel().getHiveLevel().toString());
sussy
why are you using the Integer wrapper?
wdym
Also, why are you calling #getHiveLevel() twice?
so
its just bad naming
package com.squallz.cadiabees.objects;
public class HiveLevel {
private Integer hiveLevel;
private Integer maxBees;
private Integer maxHoney;
private Integer cost;
private Integer rewardChance;
public HiveLevel(Integer hiveLevel, Integer maxBees, Integer maxHoney, Integer cost, Integer rewardChance) {
setHiveLevel(hiveLevel);
setMaxBees(maxBees);
setMaxHoney(maxHoney);
setCost(cost);
setRewardChance(rewardChance);
}
public Integer getHiveLevel() {
return this.hiveLevel;
}
public void setHiveLevel(Integer hiveLevel) {
this.hiveLevel = hiveLevel;
}
public Integer getMaxBees() {
return this.maxBees;
}
public Integer getMaxHoney() {
return this.maxHoney;
}
public Integer getCost() {
return this.cost;
}
public Integer getRewardChance() {
return this.rewardChance;
}
public void setCost(Integer cost) {
this.cost = cost;
}
public void setRewardChance(Integer rewardChance) {
this.rewardChance = rewardChance;
}
public void setMaxBees(Integer maxBees){
this.maxBees = maxBees;
}
public void setMaxHoney(Integer maxHoney) {
this.maxHoney = maxHoney;
}
}
the getHiveLevel in my HiveLevel class is just the numeric value.
can you elaborate
Integer is not the same as int
boxed type vs primitive type
and every object can be null
i usually use them interchangeably 😓
you... shouldnt
you should do that only when need
example
when retrieving data from database and the null represents empty data
yes, if your integer needs to be represented as null then use the boxing
otherwise use primitive
where should I change it..
Integer -> int
well
public class CustomHive {
private UUID hiveUUID;
private String hiveName;
private UUID ownerUUID;
private Location hiveLocation;
private List<UUID> holoUUIDs;
private List<RewardItem> rewardItems;
private List<String> beeNames;
private List<UUID> beeUUIDs;
private int beeAmt;
private int honeyAmt;
private HiveLevel hiveLevel;
private transient HiveStatus hiveStatus;
private transient Boolean beesBeingRenamed = false;
I use int in my custom object
WHAT IS THAT
boolean = true, false
Boolean = true, false, null
yea you have a big problem with using box types unnecessarily
omg
you need to convert these to primitive
I thought the capitalized version was primitive
no...
capitalized version is a wrapper object
is that my issue?
could be
where is this
in your code
hold on
now that I changed my stuff to ints
it no longer lets me call #tostring
also
is there a better way to do what I just showed
it looks like cheeks but it works
public String replacePlaceholders(String inputString, CustomHive customHive) {
String returnString;
HiveLevel hiveLevel =customHive.getHiveLevel();
returnString =
inputString.replace("{NEXT-HIVE-LEVEL}", String.valueOf(hiveLevel.getHiveLevel()))
.replace("{NEXT-HIVE-COST}", String.valueOf(hiveLevel.getCost()))
.replace("{NEXT-MAX-BEES}", String.valueOf(hiveLevel.getMaxBees()))
.replace("{NEXT-MAX-HONEY}", String.valueOf(hiveLevel.getMaxHoney()))
.replace("{NEXT-REWARD-CHANCE}", String.valueOf(hiveLevel.getRewardChance()))
.replace("{BEE-AMOUNT}", String.valueOf(customHive.getBeeAmt())
.replace("{HIVE-LEVEL}", String.valueOf(hiveLevel.getHiveLevel())
.replace("{HIVE-NAME}", String.valueOf(customHive.getHiveName())
.replace("{HONEY-LEVEL}", String.valueOf(customHive.getHoneyAmt());
return returnString;
}
ohg
Takes a string input and replaces the placeholders with real values
its so I can have configurable messages.
ok for one thing that method looks like it could be static
i personally would opt for String.format
I tried that, but I get the same result.
javadocs are always confusing to understand
String.format("The hive level is %d", myInt)
i mean not really
that would produce "The hive level is 3" if myInt was 3
for me cause im stupid lmao
And I could do this for each placeholder?
yea so you could do somehing like
String.format("The hive level is %d and it has %d bees", hiveLevel, numBees)
would say "The hive level is 3 and it has 2 bees" if numBees was 2
if you did String.format("The hive level is %d and it has %d bees", numBees, hiveLevel)
you would get "The hive level is 2 and it has 3 bees"
gotcha
Can someone skim through this rq and lmk if theres anyhting i can imrove on.
no and you SHOULDNT
==
bro what
== cannot be applied to int
heh
yes it can
wat
are you doing
y lmao
primitives literally are there so you can use ==
^
== cannot be applied objects
no it is nit
I double checked the main file, and the listener is registered. I also have the gui's class implement listener. Also, the system should only print the error message I made if it recognizes the event, right? Would you mind explaining your subclass theory a bit more?
don’t call your main class that you extend, MainClass. call it like SpawnerPlugin
@somber hull
?main
Kotlin is glorified Java but better
ur blind, quite clearly
obviously only knowing Java won't let you read Kotlin code
it's a different language
to read Kotlin code u must learn Kotlin
is it possible to convert World#getTime() to a date format that the SimpleDateFormat would work on?
EX: World time is 24000 so if the SDF was set to HH:mm the output would be 00:00
ALr, i thought in that case it would be fine
multiply world#getTime by 3.6 and you have the seconds passed since midnight
why 3.6? because there are 86400 seconds in a day / 24000 ticks
So each game tick represents 3.6 seconds in a day
or each game second represents 72 seconds in a day
Is there a way to force the model inside an item frame to stay loaded?
I once again come with another stupid question
I need to store an ArrayList<String> into a String for PDC, then return it back as an ArrayList<String>
public ItemStack setStoredBeeNames(ItemStack itemStack, List<String> beeNames) {
NamespacedKey storedBeeNames = new NamespacedKey(cadiaBees, "stored-bee-names");
if(!(itemStack.hasItemMeta()) || itemStack.getItemMeta().getDisplayName() == null ) return null;
ItemMeta itemMeta = itemStack.getItemMeta();
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
container.set(storedBeeNames, PersistentDataType.STRING, String.valueOf(beeNames));
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public List<String> getStoredBeeNames(ItemStack itemStack) {
NamespacedKey storedBeeNames = new NamespacedKey(cadiaBees, "stored-bee-names");
if(!(itemStack.hasItemMeta()) || itemStack.getItemMeta().getDisplayName() == null || itemStack.getItemMeta().getPersistentDataContainer() == null) return new ArrayList<>();
ItemMeta itemMeta = itemStack.getItemMeta();
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
if (container.has(storedBeeNames, PersistentDataType.STRING)) {
List<String> beeNames = new ArrayList<>();
String beeNameString = container.get(storedBeeNames, PersistentDataType.STRING);
if(beeNameString.contains(",")) {
String[] beeNameArray = beeNameString.split(",");
beeNames.addAll(Arrays.stream(beeNameArray).toList());
} else {
beeNames.add(cadiaBees.colorUtil.color(beeNameString));
}
}
return new ArrayList<>();
}
this no worky. Translation: returns nothing
Does anybody know what is causing e.getInventory.equals(gui) to return false? I don't know what is causing the inventories to be unequal. The event is registered, and I also tried using getClickedInventory but got the same result. https://paste.md-5.net/jidarotovo.java
Hey, im having trouble getting the amount of a specific itemstack in a player's inventory. I can remove 1 just fine, but I need to get the amount they have if they have more than one. Ive seen plenty of threads about a normal material, such as Material.COBBLESTONE, etc. but not a custom itemstack with custom values.
Thanks!
let's assume that the gui is equal, what can disprove they're equal?
if you call the method again it will overwrite the existence gui
and since they're different it will return false.
bukkit has methods for that?
it has a method to get an item in a persons inventory, but not to return the amount of that specific item
just
I am the only one testing this, and the gui comes back unequal on the first test.
int amount;
for (ItemStack item : inventory.getContents()) {
if (item != null && item.equals(yourItem)) {
amount += item.getAmount();
}
}
uh?
hm
are you using the same listener instance?
I am not sure what you mean by that.
how do you open the gui
I open it through a command
well show me the command
so you're instantiating the class to open the gui every time
and the gui will always be different, unless gui is defined as static.
and even then it will be different if more people execute it
that doesnt work, i tried putting it into a static method and its just returns null because "ItemStack item" is null
fixed
check it again
I'm sorry
ItemStack can be null sometimes
soooo
just checking for it will fix it
kk lemme see
still doesnt work
https://gyazo.com/0111d14ab9936b8684ebf7673193d01c <- inventory method
https://gyazo.com/d36fcb065a0ddf84514f9ff077e283da <- method to check @vestal dome
weeeirrd
yeah, the method for checking checks if they have greater than 1 of the item stack after they get the amount
unless the way i made the method is just broken
but i would assume it would be with the InventoryUtils method and not the method that checks the result
its probably me inventory method just not returning the amount but idk how to fix it so it would
my guess is the item isn't equal
if it wasnt equal then this else statement https://gyazo.com/7e9b336817aec8bc77518a4386372d2e wouldnt either, but the else statement fires even if i have greater than 1
whats your issue I can probably help
im trying to make a static method that returns the amount of a specific itemstack in a players inventory
not a material
the itemstack has custom attributes added to it so i need to check if its an itemstack
What if you only have 1 coral
equals equaits the amount of item as well
I'd reccomend using isSimilar
it disregards stack size
Oh yeah that too
ok lemme see
I'm hella sleep deprived didn't even spot it
I work best late at night lol
I got out of bed
1am-3am are the sweet spot
To make clientside map canvases
lol
It's 8 am
I work best late at night surprisingly
Same
I have issues with concentration so the calmness really helps
I can sip on my tea in peace
Thing is I've been working with no days off for the past few months/years
that didnt work
are you sure its the same item with 100% certainty
is the item data the same
it just runs the else statement as if i onyl have 1 in my inventory
yes
10000000%
Sout both items
i give the items in a command and they're the exact same cause if they werent the else statement wouldnt fire
my next question would be why aren't you checking for the custom data instead of similarity
I feel like it'd be more precise to just check for that specific data
I've had issues where 1 item had those legacy color codes on its name
And the other had components
isSimilar said they're different
yea I prefer to check specific values on items i usually ad like a byte pdc or something
stdout both items and make sure they are exactly the same
don't assume
just stdout it
That 1 byte tag
hmhm I love my 1 byte PDC tags
I say we ditch databases and only use PDC from now on
Anyone here a particle math wiz
Store an entire skyblock island in player pdc
Lol these are the times I wish I could do 3d math but I'm hopeless
you probably could if you used Mfnalex's more data types
I suck at it
I wanna make a looping particle helix, ive done it before but I forgot how
Except for quaternions and euler angles
I'm good at math I just haven't had to learn it yet
that would be a terrible idea please do not
That shit makes me mad
by done it before I mean I found a chunk of code and slightly modified it.
I say we do it anyways I'd like to see how much lag that could cause
I made satanic cows with async particles out of pure nms
having fun with particles, that’s amazing
if they werent the exact same, then the else statement wouldnt fire because they both require red corals, it has to be an issue with getItemsInInventory# method but i dont know what the issue would be
let me see the other code your talking about
Cows would fly like blazes and shoot fireballs
?paste
Should I just use ParticleLib to spawn my particles isntead of the PlayOutBlahBlah
https://paste.md-5.net/bebebuhaxi.bash <- actual event
https://paste.md-5.net/liweheyahi.cs <- getItemsInInventory#
Both worky
code looks fine all it'd seem is the items aren't the same i'd reccomend stdouting them and hand checking all the values
It still calls equals
I remember looking at internals
And it was like
isSimliar is pretty much just equals without the stack size iirc
thats what docs say atleast
public void equals(ItemStack other) {
return isSimilar(other) && amount == other.amount;
}
Writing code on mobile is tiring
kek
I don't even bother typing code whiule I'm on mobile
I just try to explain it
what how would i use that
Just showing internals
thats the equals method for item stacks
isSimilar is good for checking for similar items disregarding the item amount
yeah i changed it to isSimilar and it still doesnt work, and i know fs that the items are the same
I don't think they are 😉
bro if they arent the same then why does the else statement fire if its legit the same thing just if its only 1
they wouldnt stack if they werent the same either
true are they stacking in different slots?
nope
send a screenshot of your inventory
I'd just add debug statements to my loop and see where its not going through at tbh
its hard for me to help you considering all I'm seeing is that the items aren't the same
Wuat
LMFAO
I"M SO STUPID
It's the only point of failure
BRO
Unless we tripping
imillusion
look at this take a good hard look at whats wrong
int amount = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item != null && item.equals(itemStack)) {
amount += item.getAmount();
}
}
return itemStack.getAmount();```
We're blind
you need to return your amount value lmfao
Like
xD
I gotta put my glasses on after that
omg we are both idiots
Dude it's 8am and I've been doing nms for the past 16 hours
lemme see if its fixed now lmao
I'm not stable enough
bet thats fun
lol I've been working with shitty minigame code I'm redoing
too bad its proprietary or I would share lol
Minigame is written in nms
I have fake blocks and fake entities and all
lmfao
❤️
we are all stupid
hey man u clearly know more than me so dont put urself down
the server I work for has a multi-server linking api where all players interact and can see across different servers
very neat
It comes at the cost of having no friendd
Some mf asked me for a full syncing plugin
I wish I could say I have no friends, but I have too many to say that 😥 I can only say it as a joke
Asked for 10k, dude hasn't got back to me yet
lol
I made an entire game-engine from scratch its pretty nice
the map system we have is also really cool
Who needs maps
true not me 😂
Neither me
when's the last time you played bedwars
🤡
is this good stats #general message
Few years ago
Okay go take a shower
what
Sweaty mf
It's a bit wrong of me to call other people sweats honestly
I can only click 5cps :P i can never reach full potential
I'm a 5cps legend I used to play HCF and actually did pretty well for clicking so slowly
I have a disorder that makes me physically sweat 20x more than the usual person
So I'm a literal sweat
I work out sometimes
I'm not just a plugin dev
I code my friends and families programs to make boring stuff easy
I think my top accomplishment is this reminder app for my mom who is a specialist at a school she has to send out lots of reminders and I completely automated it 🥲 had to bundle 4 platforms together
eww this guy does more than minecraft
not me
I'm a professional plugin maker
don't even have a working website
Every time I go about starting a massive project I try to do everything else and end up getting overwhelmed and stopping development. Would planning every small thing in advanced help me pace myself? I could have like 3 tiers of importance and I do them all in order? Starting from easy stuff like storing player data and scoreboard to mines, private mines, robots, custom enchants and so on.
at least I can say I interned at a school and fixed their printer
I enjoy coding a lot of stuff. My brother was going to have my automate some of his financing but didn't give me any website information to do it with so I just told him to F off
break it down into steps and try to add new core functionality every week
Just make a bunch of small plugins than combine them it always keeps me more on task
I have a massive project that I've been working on over the past 1-2 months and I'm still doing steady hours because:
1 - it's fun
2 - it's organized
3 - team overlooks development with weekly meetings and I don't want to disappoint
The single most important principle is to finalize and finish stuff, even though it may not be perfect in your eagle sharp eyes.
In my case it's a zombies minigame
Yeah, my best work is by far the stuff that is a fork of another plugin. I get the base where all the stuff I'd stress over having done already and I can work on the new ideas I get
So the first thing I made was a game system (initializing and disposing games)
then a zombie spawning mechanism
then gun mechanics
then points, then doors
then perks
Yeah
you break it into small objectives / features and fully implement them
You only start another feature once the feature you want is completely implemented
ok mate now ive got another issue 😂 removeItem# was removing all the items of that stack in their inventory before, but now its not 😬
But make sure that all dependent features are already done before starting work
So if I'm making a perk machine, I expect to have a points system make
And a perk system so that you use the machine and something actually happens
Yeah this is something I do poorly, I end up having 50 broken features instead of having five working
After having all the guns done and points
then I can make a mystery box
type thing
It's also annoying when I have to make methods for getting basic stuff
But it's more important to have working stuff than just "done" stuff
It's why I usually prefer to work with existing code bases
basically you need internal planning
and to follow an order of operation
based on what's relied upon the most
I usually build up my API before i even start a project's main concept
Yeah
well if you build an API then you could literally work on perks before points
which is especially nice if 2 things rely on each other
I never understood the concept of making an external API
I usually make an api and call it internally type thing
instead of having an api layer and an internals layer, the internals are the api
I like external API's on servers where your plugins are going to be the main thing used otherwise I see little to no point I rather just shade it
would making classes such as "PlayerData" and making 50 comments with methods I need to make, then make all of them.
//get tokens
public void getTokens() {
}
//set tokens
//get player level
you'd end up with 2k lines
Typically your API is all interface, minus some utility implementations
Then your internal is all actual implementation
why would you comment it
just make the methods bro
Which works just fine
raytrace, get hit point, create particle line between
Comment before making it
always comment before proceeding
To know what I need
My classes are usually marked up a shit ton
i mean i comment stuff but not every single thing
if im making a getter or setter or whatever i know what it does lmao
I usually leave myself an outline before I implement especially if I need to come back or I forget
and id hope anyone else would
Honestly that might be a good idea for me
if hit point is null, just make a line between start and start.add(start.clone.normalize.multiply(range))
Exactly what I'd do
with bigger projects it gets insanely tough to deal with even simple stuff as well
ig
I tend to build the full backend before even having listeners
you can actually get some Methods called get that have specific return reasons
I have a full skyblock core that has 6 listeners
like I have getAdapter methods that return specific parts of the spigot API that i've wrapped
I like to explain why its there what it does for all other users of the API
fair enough
Yeah, if you can, ideally have the code explain itself
yeah getters and setters are self explanatory, i was just curious tbh
Comments are far from pure good although necessary sometimes, even if explanatory code could be used
still relatively new to coding
I feel like when your collaborating even if the code can kind of explain itself I prefer to leave an explanation for others
There are tons of issues with comments
whatever can't be explained through the variable naming, shall be commented
getTokens() is self explanatory
If you have a backend an entity relationship diagram is nice
incrementRound() can do some underlying operations so it should be documented (cleaning entities, wiping scores type thing)
Not only variable naming, but naming of everything
Issues also arise when I need to implement another big feature to work on another. Like player levels to get player level
This is tame but it arises that I get massively sidetracked with something unrelated which takes days
You only start working on a feature if all underlying systems are fully implemented
you gotta think about how it'll roll out before actually writing code
I'd say I do a 1:10 planning:developing ratio
sometimes up to 7:3
I spend a lot of time planning because I can't concentrate for shit
1/10th development or planning?
1:10 and 7:3 are very different dynamics LOL
I spent 5 hours planning a system that took me about 25 minutes to code
Plan twice develop once
even pulled up the pen & paper
the minecraft notebook
unrelated question
am I the only mf out there collecting minecraft merch?
write your development planning in a book and quill
I've only ever done that for the endless halls in wow lmfao
I got mousepads, mugs, books
I create notepad++ files that literally outline how the API should end up
or the endpoints of the REST api
utterly ridiculous
I just outline it in my head than write it if its super big I'll write it on paper
visual demos need writing in paper
or paint
like for zombie spawning
I had to make it so it would only spawn zombies in spawn points close to the map region the player was at
but that map region also had to be unlocked
But doors have to work bidirectionally as the map has 2 paths
Write lots of TODOs 
then never complete them
So I had to design a door system that connects 2 regions
How can I setup mappings for nms?
then a whole api to parse doors based on overlapping wg regions
Whenever you have time available for a project, spend it all on planning
Oh worse I've got TODOs I've completed but never removed
I've tried everything I've found online but my mappings simple do not work
I just use the paperweight plugin
it's quite simple
on gradle groovy