#development
1 messages · Page 129 of 1
that might work
Well right clicking doesn't do anything
It might
I just dont want the player to know that there is a sign there
you can right click signs tho
🤔
Can you explain more about the end goal
I smell xy problem
the root component of each line can have a valid run_command action, and the server checks for that when you right click a sign
I have a texture that shows on the sign. and the sign has a invisible texture, so only the image shows. But when the player hovers over the image they see the sign hitbox
So called "adventure maps"
Does this AtomicBoolean look good for you?
public boolean unlinkContainer(@NotNull Container container) {
Location containerLocation = container.getLocation();
AtomicBoolean isAnyRemoved = new AtomicBoolean(false);
_hopperRepository
.findByContainerLocation(containerLocation)
.forEach(hopper ->{
boolean isRemoved = hopper.removeContainer(containerLocation);
isAnyRemoved.set(isAnyRemoved.get() | isRemoved);
});
return isAnyRemoved.get();
}
IntelliJ recommended this over using a local variable which obviously did not compile. Does this do what I want?
it should
why not use something like an item frame? No hitbox
oh you mean with a resource pack?
yeah
Probably because of font glyphs
I dont want the nametag thing where it moves with the player
mmh can't you turn that into a Stream and use filter/anyMatch/etc?
Item frames can be set to keep name visible right? You could use them the same as signs if thats the case
map + anyMatch(is true) I'd think
Given that you don't want short circuiting
oh or filter
I don't think because if I do that, anyMatch will stop on first true, won't it?
cause it's stream
I don't think so, I think it's only when you look at it, but I could be wrong
it might work, the name you see when hovering over is of the item that's inside
also, how do I rotate a sign from code?
setRotation?
not a thing
it definitely is
Make sure you're importing the right Sign interface
the second one from the screenshot above
I hate bukkit
ah, I had org.bukkit.block.Sign
is there any built in methods for turning a yaw into a BlockFace rotation enum?
nevermind
No I mind
How can I store an object of MyClass into PDC?
honestly I'd just serialize to json and store it as a string
by the way, what is the recommended way in java to serialize to json? is there a built in way in the java base class library?
Does PDC automatically deserialize?
I don't think so, if I serialize to json, I will have to deser it too
Wait I'm thinking of NBTTags. If I give a list or int or string to NBTBase will it converter to NBTString, NBTList, NBTInt and so on?
there isn't but gson and jackson are the most widely used libraries, gson is already part of spigot api so you might as well use it instead
I mean you have Serializable but that’s not for json
please for the love of yourself don't use java's Serializable API
🥲
I use json-simple
Moshi :3
Jackson works if you are knee deep into that
When you read a value from a persistent data container, is the entry removed from the container. Or have I done something stupid in my code?
not, is not removed

Ahhh, then I've done something. Ughhhh, well, thanks 🥲

stfu lol

:>

Could someone make little code review? :>
Yes
ok
mf put the entire ass license as header 💀
oof lmao
Gradle plugin :<
200 lines just for that
I thinking about change to mit license
but YOU can change the text?
just get a smaller paragraph of that
this is the only part that's actually needed as header lol
and maybe a title
no not maybe, that's what the license itself says lol https://github.com/MaxWainer/framework/blob/bb244a25172c353baf5307c179255409396b8bc2/orm/src/main/java/dev/framework/orm/example/ExampleRun.java#L177-L188
SPDX identifiers ftw
oh
MIT gang
Just know my D is like a anaconda
truncated
Hello! Recently I was wondering if a server-side mod for fabric that allows me to make scripts exists. I need something like Skript, but for fabric servers. Preferably something up-to-date.
If you know something like this feel free to DM me.
you might try carpet-fabric mod by gnembon, it has the scarpet scripting language, but you'll have to check and see if it can do what you want it to. It's an amazing mod and there's a number of videos and tutorials about it.
https://github.com/gnembon/fabric-carpet
Yea, and gnembon is now a senior dev at mojang
I've downloaded Spigot code from their official repo (https://hub.spigotmc.org/stash/projects/spigot/repos/craftbukkit/browse), but it seems that their pom.xml is configured to use some jars I don't currently have.
Where and how exactly can I get these jars?
not really sure if this would help, but try running buildtools for 1.18.2
did you run the applypatches script?
mmh you need to run bt and then run the applypatches script pointing to the decompiled classes dir
man this is ancient
I'll try this
I did absolutely nothing besides hit the download button on their codebase repo and open it in my IDE
(sorry for the ping)
yeah this is so badly explained lol
it's like "you need maven and buildtools"
but it doesn't tell you shit under the actual "compilation" section
First run buildtools, then cd into each repo and do this
well, "each"
idk
I actually don't even need to compile the code, I just need the intellij highlight and ctrl clicky clicky to work, I'm just doing some field investigation today
it's easier to build paper lol this is too convoluted
After running the buildtools like PulseBeat suggested there's only 50% of errors remaining, I'm wondering if there's some "buildtools" equivalent for Bukkit too
Why does it even use "bukkit"? 
because it builds on top of it?
I think it is because Spigot depends on CraftBukkit which depends on Bukkit
Bukkit is the API (lots of interfaces), CraftBukkit is the implemention of these interfaces (for the most part), and Spigot just adds some things to it
Though I have no idea why does CraftBukkit jar doesn't come with Bukkit shaded in it
presumably for a clean dependency tree
like the actual project depends on the other actual project
hmmm, but the buildtools actually built the final jar, correct? Shouldn't craftbukkit shade bukkit for it to work?
Bukkit is the api so doesn't it shade craftbukkit?
they can coexist as separate jar files and so long as both are in the runtime classpath they will work fine
The other way around
Are you sure? Spigot is the api and it shades (use to) bukkit
the implementation ships the API
Bukkit -> CraftBukkit -> Spigot -> Paper
the API doesn't know jack about the impl being there
CraftBukkit -> Bukkit -> Spigot -> Paper
what? no
craftbukkit ships bukkit
Craftbukkit is the base, the rest are api
my -> meant "is a dependency of" or "is used as base for"
Then you have to flip the entire thing around


.
Craftbukkit is the library bukkit is the api to access it... so why wouldn't Bukkit (depend or shade) on craftbukkit?
where craftbukkit is the library?
Bukkit is completely separate from craftbukkit
craftbukkit is a server implementation of bukkit, that's literally the description of it
Bukkit is an API. There are several implementations of bukkit. The primary one is craftbukkit. However, Glowstone is an implementation of bukkit that doesn't use any mojang code.
Ah Ok. Always thought craftbukkit was the server implmentation that bukkit was accessing.
bukkit and craftbukkit devs are different.
anyway, back to my point, how can I get Maven to download and/or recognize the bukkit jar that should have been there
post your pom
this is the error message
Oh you're talking about that, now this message definitely was stupid lmao
I thought it was a plugin 🥲
haha, I'm exploring the CraftBukkit code cause I'm really interested in the way it handles event listeners, I was going to understand the system built to dispatch the events, and use it as inspiration to build my own event listener system
spigot-api forks bukkit and adds some things, idk spigot even hosts bukkit anymore
I can suggest you look into this one maybe https://github.com/KyoriPowered/event, bukkit's event handler is very odd
I'm not making a plugin, I'm trying to get maven to recognize all CraftBukkit dependencies so I can explore them with Ctrl + B (or ctrl + click)
I'm aware of that, though, funnily enough, for my use case, the way it was build better fits with that I'm trying to accomplish
I am bad at vector math
I am trying to create a function that will duplicate custom regions. I get the cardinal direction the player is facing and taking an input I multiply the direction vector by the distance (in this case 20) and then apply that vector to the region points.
But it seems that I'm getting the wrong number after the first region is moved.
First teleport is an original region, the second is the first cloned and the third is meant to be a clone of the first but it has a Z of 8014 instead of 34
(20 blocks away)
Clone Command: https://paste.helpch.at/awicosiqoz.java
Region: https://paste.helpch.at/oralezuhap.java
edit: The clone of the second teleport would be at origin 16.5, 65, 14.5
d; spigot Vector#multiply
@NotNull
public Vector multiply(@NotNull Vector vec)```
Multiplies the vector by another.
vec - The other vector
the same vector
Someone had the great idea to make vectors mutable, so you should only multiply it once
that screws with me because the vanilla codebase doesn't do that
so a bukkit vector is mutable while a nms vector is immutable
🤗
I calculate a value like this Math.sin(Math.toRadians(value)) where value is 180 degrees, but get the value 1.2246467991473532E-16 from it when it should be zero. When I then parse the result to a string turns out as 01.2246467991473532. Is there a way to fix this, apart from rounding the result?
By turning it into a string using formatting options
String.format(number, ".%9") or something. idk exact code but it's on stack overflow somewhere
Ok then, thanks
How can I listen on sugar cane breaking event when it is breaking because another one is broke under it?
So there is a 2 tall sugarcane, I break the bottom one: bottom will fire BlockBreakEvent and BlockDropItemEvent, but what will fire for others?
I found that BlockDestroyEvent is actually fired, but there are no list of items to be dropped, but I want to manipulate the items to be dropped. How can I do that?
(I use Paper API)
Block.getDrops()
thank you
👍
Is it a good decision to use it though?
Does it take into account that a player may have luck or any modifier that would increase drop yield? 🤔
Block.getDrops(ItemStack)
I saw that too but I don't know who is breaking, not included in the event AFAIK
Well you could just check if above blocks match the block you're breaking and remove them manually.
yeah I thought about that but that is not a general solution
so I would implement it for sugar canes, but I don't know all the types of other blocks that can do the same stuff
maybe cactuses
Well the break or interact event would be the only point you can check the player and held item. The other wvents are blocks only.
well the BlockDropItemEvent is fine too because then the final list of dropped items are there, I would need something like that but for indirect breaks
do they work all the same way as sugar cane?
Those all break upwards.
Breaking downwards is; vines and I think lichen
and glow berries
1.18 addition
Ah ok
Is there a fast way to apply new versions of a plugin while developing? currently I do:
gradle clean build, then copy jar file manually to plugins folder**, stop server, start server again, wait until reloads.**
the bolded part takes a lot, can I help on that?
Theres a thing called hotswap, but for some things you still have to restart the server
I usually click on the restart button from IJ and it waits for the server to stop and then start it again
I guess plugman reload is bad 😛
(it works in most cases though but I heard its bad so I am trying to avoid)
he's not talking about plugman
I know
idr the name
but there is a plugin which detects file changes
and reloads plugins
That’s hot
wouldn't that have the same issues as plugman tho?
idk
¯_(ツ)_/¯
I mean plugman works fine for plugin development purposes as long as something doesn’t noticeably break
tru
I mean hotswap could potentially also cause some weird side effects 
also true 🥲
and iirc hotswap only works if u dont add any new methods/classes
so its useful for testing some minor things ig
sad clean coder noises
yeah tho dcevm makes it a bit more powerful dkim
https://github.com/JetBrains/JetBrainsRuntime/releases/tag/jbr17b135.1
has options with download links jbrsdk_dcevm-17-PLATFORM-bVERSION.tar.gz, which when using with the VM argument -XX:+AllowEnhancedClassRedefinition enables alterations to the body of a class.
👀
this one i think u can add methods
idk about classes
Can someone check if I implemented this method well?
https://paste.helpch.at/qoceqipiji.cs
this.hopperActivator.activateHoppersInChunk(chunk, items);
may touch items (reduce itemstack amount or remove items altogether), and since if I modify items they will still drop, I had to redo the block break feature manually with the remaining drops.
Edit: change link to contain other method too
othats nice
oh also in dcevm there's -XX:+AllowEnhancedClassRedefinition, maybe that'd work too
¯_(ツ)_/¯
maybe i just wasn't using it correctly
lol
yeah well im not a dcevm expert myself so ye
why not
good question
plugman and dcevm are fine in development
the problem is when u use them in prod
issues will start to occur
🥲
Is this the correct channel to ask for assistance when it comes to creating plugins?
yep
Am allowed to send an open source project and ask someone to help me understand the concept so I can use that concept for something else?
I'm Emily
hi
😃
https://github.com/ArtFect/BlockHighlight
This person created a way to highlight blocks for players using debug/game_test_add_marker without making any modifications to the client. My understanding of coding plugins is to basic to able able to try and understand how the things work?
I simply want to use this idea, and make a command that highlights a blocks.
For example
/highlight x y z
.
Ive been starring at this plugin for hours and cant seem to understand how on earth this person was able to do this
this is the actual highlight code
https://github.com/ArtFect/BlockHighlight/blob/master/src/main/java/ru/fiw/blockhighlight/PacketUtil.java here are the PacketUtil methods
and highlight.getColor() is Color.RED.getRGB() for ex
this also uses ProtocolLib
what it does is it sends a Custom Payload packet with the channel debug/game_test_add_marker, and it serializes the marker (aka the block highlights) into bytes (ByteBuf) and sends it to the client
Thank you, ill see what I can do. You helped alot
np :D
do you think the blockPosToLong is necessary?
yes, thats part of the info that gets sent to the client
instead of 3 integers, it just sends 1 long
hm
it seems to be under MIT license
well
are you going to use ProtocolLib?
alr, it should still be similar though
so i'd recommend just coding it based off of PacketUtil and sendBlockHighlight
alr 👍
basically just trying to understand how he did things, then do it from scratch
wont be using the plugin anywhere, just self study proposes
Heyo anyone used jackson serialization and know how to register a way for serializing enchants? I keep getting com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot find a (Map) Key deserializer for type [simple type, class org.bukkit.enchantments.Enchantment] when trying to convert an itemstack to json
Paper has an API for serializing itemstacks
What different ways do clients send credentials to authentication servers? I assume the primary way is form data, for an app I made I had it send using a Basic authorization header, the server then sends back a token that the client can send in all future requests using a bearer header. Is there a standard way?
Anyone have any idea how to keep a message on the bottom of chat? (Through packets or something else?)
Is making own events for domain model use cases a good idea for better code design?
domain model?
my code's own model
generally events are clean if you have multiple things being done in a single listener
So I guess?
I mean sure, although a disadvantage with having some sort of general observer implementation is that in the long term it can become a bit hard to figure out what units depend on which event. (Of course you could ensure a single method registers possible observers (which is easy to do as long as the code base hasn’t grown colossally large))
Does anyone know if it's here or another channel where I could request a relatively simple mod made that I'm willing to pay for?
thanks
Hello, how can I subscribe to event when a chorus plant gets destroyed and it is dropping its items? For example I have chorus tree, I hit the bottom block and the others get destroyed automatically. I get the event for the bottom block but not others. How can I receive other events?
hi #minecraft can u help me
go to minecraft channel then?
i m
this is #development
i asked u to help me , on #minecraft
bro patience is a virtue
XD
what are you talking about
Looking for discord support?
HelpChat is a Minecraft plugin and development support server and is not affiliated with discord in any way.
If you require support from discord, we recommend you to visit their official support website at https://support.discord.com
On this website, you can read their FAQs, or open a support ticket if necessary.
@rugged nymph read this 
is there an example somewhere for using intelliJ debug mode on a plugin in a remote server? (and possibly live-updating changes)
Hey yall https://ci.extendedclip.com/job/Vault-Expansion/ hasn't been rebuilt since 2020, meaning it's missing all the bugfix commits in october 2021 @ https://github.com/PlaceholderAPI/Vault-Expansion/commits/master
would someone be able to trigger a build there (and/or push to any other ecloud distribution thing, idk how papi's infrastructure works at all)
0 bugs
@mental cypress 
How would I get the players message from AsyncChatEvent (text only)?
Done @dense drift @frosty quiver
event#getMessage()
int time = Integer.parseInt(Main.instance.getConfig().getString("time"));
p.sendTitle(Format.chat("&5Test Title"), String.valueOf(+ time), 1, 20, 1);
}
Some1 that can confirm if it works? The "time" int need to be a subtitle
sendSubtitle?
Can't remember what the actual params are, but if you Ctrl + P on the method it'll show the required params
what about getInt? no need to use parseInt every time...
oh alr
d;spigot player#sendtitle
void sendTitle(@Nullable String title, @Nullable String subtitle, int fadeIn, int stay, int fadeOut)```
Sends a title and a subtitle message to the player. If either of these values are null, they will not be sent and the display will remain unchanged. If they are empty strings, the display will be updated as such. If the strings contain a new line, only the first line will be sent. All timings values may take a value of -1 to indicate that they will use the last value sent (or the defaults if no title has been displayed).
title - Title text
subtitle - Subtitle text
fadeIn - time in ticks for titles to fade in. Defaults to 10.
stay - time in ticks for titles to stay. Defaults to 70.
fadeOut - time in ticks for titles to fade out. Defaults to 20.
Yea but i can better do it in 1 line than 2 lines
thats an adventure method, Frosty
eee
and my question was if i get the subtitle now xd
Yea the second param is a subtitle
When in doubt
but if you Ctrl + P on the method it'll show the required params
or ctrl click on the method and it'll take you to the implementation which usually has javadocs attached
Yes but you still have to make it a String
String time = String.valueOf(Integer.getInteger(Main.instance.getConfig().getString("time")));
p.sendTitle(Format.chat("&5Test Tile"), String.valueOf(time), 1, 20, 1);
}
wait
i can now remove in the subtitle String.valueOf right?
'cause i got it in my string alr
Make your time variable an int, and use getInt for the config, then just use the valueOf in the method
Your IDE should also be yelling at you right about now that you're using unnecessary methods
Which IDE not what version
com
com?
I'm trying to make a custom item in spigot 1.8, and it says "Unknown command" when I run the dommand, help please ;-;
This is where I created the item
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class ItemManager {
public static ItemStack axeOfJustice;
public static void createAxe() {
//Axe of Justice
ItemStack item1 = new ItemStack(Material.STONE_AXE, 1);
ItemMeta meta = item1.getItemMeta();
meta.setDisplayName("&k&6Axe of Justice&k");
List<String> lore = new ArrayList<>();
lore.add("");
lore.add("&7The Axe of Justice is a weapon once used");
lore.add("&7by the &cOwner &lqHydro &7himself.");
meta.setLore(lore);
meta.addEnchant(Enchantment.DAMAGE_ALL, 1000, false);
item1.setItemMeta(meta);
axeOfJustice = item1;
}
}
This is the commands file
import me.qhydro.customitem.items.ItemManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.Main;
import org.bukkit.entity.Player;
public class Commands implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player1 = (Player) sender;
if (label.equalsIgnoreCase("giveaxe")) {
player1.getInventory().addItem(ItemManager.axeOfJustice);
}
return true;
}
}
I can send plugin.yml and the Main.java file
did you register the command?
send it
I smell a kek spigot tutorial
This is the Main.java file
package mq.qhydro.customitem;
import me.qhydro.customitem.commands.Commands;
import me.qhydro.customitem.items.ItemManager;
import org.bukkit.plugin.java.JavaPlugin;
public class CustomItem extends JavaPlugin {
ItemManager is = new ItemManager();
@Override
public void onEnable() {
getCommand("giveaxe").setExecutor(new Commands());
ItemManager.createAxe();
getServer().getConsoleSender().sendMessage("&9Hybrid Items has been started.");
}
@Override
public void onDisable() {
}
}
plugin.yml
main: me.qhydro.customitem.CustomItem
name: HybridItems
version: 1.0
author: qHydro
api-version: 1.8.8
commands:
giveaxe:
is the plugin enabling?
plugin properly enabling or you getting any console errors?
Unknown command. Type "/help" for help.
On enable, not when you run the command
There's your issue then
The issue is your API version @quasi kraken.
As you aren't using 1.13 or higher, you don't put api-version.
Find more information about how your plugin.yml should be structured here: https://www.spigotmc.org/wiki/plugin-yml/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I'm using the Paper AsyncChatEvent event#originalMessage() returns a net.kyori.adventure.text object which is json. I was wondering if any one just knew how to get the content from the object. If not I'll probably just use the AsyncPlayerChatEvent from spigot
I presume it returns a Text Component? or can you provide the object it returns.
Also are you using 1.18 @thorn cape? as it seems like it returns a Component, where you should be able to component#text().
By following the java docs for the 1.18 asyncchatevent for original message, you get a component object that you can turn into a text component.
that method does not exist
youll probably want PlainComponentSerializer or just use the spigot event if you dont care about formatting
yeah #text isn't a thing. I'm using 1.17 but it does return a Component
@kind granite I'll check PlainComponentSerializer, and I don't care about formatting just need the raw input 😄
I'll probably just use the spigot event then, thanks for the input.
why not?
you can set api-version: 1.13 so 1.13+ recognize it but it's ignored in versions older than 1.13
plugins prior 1.13 should not have that field at all!
spigot will apply all sorts of class loading hackery to ensure the plugin using old API works fine on 1.13+ if the field isn't there
as long as i remember ( i remember i read it some where) some things dont work if you dont specify the api version
Materials afaik
mainly materials, but some other enums as well
and "don't work" wildly depends on what you're doing
and that means you're doing it wrong
👍
It doesn't show up when I do /plugins
Can you provide your console log for the error via the paste slash command?
If it doesn't show up in /plugins then it's either not in the plugins folder or there is an error when it tried to load
So my custom join/leave and staffchat plugin are loading, but the custom items are not
The console will show the error that caused it to not load
No error at all
Is it in the plugins folder?
Yeah
Find in the console where it tries to load in the plugin and find the error there
ctrl + f in the latest.log is a quick and easy way to find it too
Getting an error from another one
I'm telling you, you must have a error, and if not you are writing or compiling incorrectly.
but i can't work out how to do this with generics
it's just public void setValue(ArrayList<T> value) {}
i've tried adding
public Class<T> getType() {
return this.type;
}
```to the `ArrayMonitor` class
so you set the type when you make it
generics 
but i can't seem to substitute that in for TYPE here new ArrayList<TYPE>(List.of(value.split(","))))
what in the hell
Um
can you show the code for ArrayMonitor
Because I have no idea what this is supposed to do
arraymonitor basically just sets a redis value every time there's a set operation
so i'm overriding ArrayList<T>
there's nothing else relevant
no, i actually only override public T set(int index, T element) {} and then i have my ownsetValue method i showed above
Ok
Well first off consider implementing List rather than forcing it to a specific implementation
I still don't really get what the problem is though
If you have an ArrayMonitor<Integer> then T = Integer and so setValues must take an ArrayList<T>
yes but how do i get java to know it's an ArrayMonitor<Integer>
where?
it'll know as soon as it's created
ArrayMonitor<Integer> blah = new ArrayMonitor<Integer>();
as i said above
i'm retrieving it from a hashmap
of type HashMap<String, Monitor>
where Monitor is an interface that ArrayMonitor implements
Then there's no way of knowing at compile time
Unless you as the developer know from the context
again
as ive said i did
public Class<T> getType() {
return this.type;
}
in the arraymonitor class
Yeah that doesn't change anything
Not at build time anyway
Generics only exist for the compiler
At runtime, they don't exist
And so <arrayMonitorType> won't work
well then i need a switch statement
🤔
match relieved
shut it
something like
sure works tho doesnt it
scala 😩
but the arraylist will neither contain booleans nor bytes?
just keep it unchecked, there's really no better way
i mean yeah this gives me many errors
wdym
you cannot cast strings in a list to any other type randomly
Mainly because .split() is returning a String[] and you're expecting that to magically turn into any other type
ArrayMonitor or ArrayMonitor<?>
Unbound not unchecked*
If you're looking for a way to arbitrarily parse Strings into different types that's a whole different issue without a great solution
so it's not easy to reverse this.value.toString() for private ArrayList<T> value;?
even if i know the T
not trivial, no
well i need to do that
I mean if you know all the types then sure, write the parsing logic manually
Boolean.valueOf, Integer.parseInt, etc
But for any arbitrary type this is pretty much impossible
toString might not be enough then either
toString is not designed for serialisation so yeah
literally anything else would be better
what would you recommend for serialising more complex types like this?
the reason it's a pain is im forced to use redis
which stores strings
JSON if you want user friendly formatting, otherwise Java persistence API might actually be the easiest option
it's not human readable but it just works
in most cases
can't say anything i've read so far about JPA makes any sense
java.io.Serializable 😵💫
Problem?
still can't really find any examples that make sense to me, for doing it easily with multiple types like ArrayList<Boolean>, Char, ArrayList<Float> etc
If anything take an ObjectMapper type or w/e and let the client provide a (de)serialization function
look I'm pretty much having to guess the context
But afaik the types will always be known
ObjectInput/Output stream can input or output an arbitrary Serializable object, which all the JDK types like Boolean and Char are
yeah im seeing that in examples like https://www.geeksforgeeks.org/serialization-in-java/ but it's really not making any sense in a practical way
ObjectInputStream whatever = whatever
Serializable value = whatever.readObject()
ArrayMonitor<?> monitor = map.get(idk)
List<?> valueList = (List<?>) value;
monitor.setValues(valueList);
Roughly what needs doing
It's not pretty but should work
Or the ObjectMapper thing or JSON, the end result is the same
Just to make it clear: I don't think there is a "safe" way to know the (unknown) types at compile-time, so you're going to have to cast unsafely eventually
Yeah I'm 99% sure there's no "proper" way of doing it
what's wrong with
return this.type;
}```
that does not help at compile-time
^
Storing the class is useful if you need to know the type at runtime, which you may need to
But it won't stop the fact that you need to do unsafe casts sooner or later
A member of staff has requested I move your message to a paste,
Most likely because it contains a config/error/code snippet.
bru
Wrong reaction
xd
I meant to do 
lmfao
you don't need the switch statement
The point of using the serialization api is that you don't have to explicitly specify any types lmao
It's arbitrary
.
the switch statement won't change the type of what the stream reads nor the type of newValue
^
Boolean?
mistake
Try it and see ig
you might also need to add base64 into the mix, idk if redis allows binary data
i tried adding
public void setValue(ArrayList<?> value) {
this.value = (ArrayList<T>) value;
setRedis();
}
inside ArrayMonitor<T>
they may be different types, that can't be known at compile-time, that's why you ought to "unsafely" cast eventually
yes
and this is ok?
looks about right I suppose
@chrome briar you can ask here too 🙂
Might wanna make a separate private / package-private method which takes the unsafe list
So you don't accidentally call it with an actually unsafe list
I tried everything, i gave up lol
that sorta makes sense but i'm not sure what you really mean when it comes to coding it
btw thanks a lot, and Emily, for your help

public method takes List<T>, internal method takes List<?>
right i see
i don't really get the advantage of passing it to a private method
Aside from the extremely unhelpful error message, looks fine
If your public method takes <?> then you (or someone else) could accidentally pass a List<String> when you have an ArrayMonitor<Integer>
It's not a necessity but the private public thing means you only bypass the safety when it's necessary, making it harder for accidental bugs
ohh i see
that makes sense now
wait but then if i do something like
public void setValue(ArrayList<T> value) {
setValueInner(value);
}
then i still get the error
that's the safe method
For the deserialization you use the unsafe method
i.e setValueInner
yeah
ok sweet, thanks
should i use a "wrapper package", or prefix each package name?
like i have a package called redis atm which conflicts with the real redis package
so should i name it myapp.redis or should i make a package myapp and put all my packages in there
All your classes should typically be under a reverse domain name package
eg me.bristermitten.projectname.blah
How can i check if a boolean inside a list in my config is true or false? Right now i am using this```java
if(Main.getPlugin().getConfig().getBoolean("help") == true) {}
Config file:```yaml
help: true
fly: true
vanish: true
But i want to change it to be like this in the config:```yaml
Commands:
- help: true
- fly: true
- vanish: true
And then i also need to change the .getBoolean() thing. But how do i do that and check if for example help is true or false inside the "Commands:" list?
for booleans you dont need to do == true/false btw, just do (bool) for true and (!bool) for false
Get the commands list with getStringList, split at : , the first part will be the command and the second the boolean
but why a list tho?
I'd do this: yml Commands: help: true fly: true vanish: true and in the code: ```java
if (Main.getPlugin().getConfig().getBoolean("Commands.help")) {}
you can also do this, but it makes it more complicated for no benefit
sorry for ping gaby
didn't mean to
🥲
gaby wtf
I GAVE THEM A SOLUTION FOR WHAT THEY ASKED FOR
Ohh... That's what i thought about. Just forgot that you don't need - before it...
for (String command : config.getSection("Commands").getKeys(false)) {
boolean bool = config.getBoolean("Commands." + command);
}```
With this you can add as many commands as you want
:respect:
Hmm. Yeah, so if i use a - it makes it a stringList instead of a boolList?
well there is no bool list.
Yeah, i just kind of call it that... xD
and if it would've been a thing it would've looked something like this:
boolList:
- true
- false
- false```
U can simply use this https://helpch.at/docs/1.12/org/bukkit/configuration/MemorySection.html#getMapList-java.lang.String- (in case dictionary), but better solution will be sections
seems like Mutable has a T generic
and since MutableBoolean sets that to boolean
I think it'd be setValue(Boolean value) maybe?
¯_(ツ)_/¯
i need a setValue(Object value) though
how come?
it's suggested by intellij
i tried using generics
but it seems i need to use Object then cast to what i want
what error do you get when u try using this?
you can't use generics here because MutableBoolean already set it to a Boolean
and you're using Boolean instead of T?
what's Monitor?
try doing ```java
public class BooleanMonitor extends MutableBoolean implements Monitor<Boolean> {
// ...
@Override
public void setValue(Boolean value) {
this.value = new MutableBoolean((Boolean) value);
setRedis();
}
}
the only error i get is this one
when i do
Monitor<?> monitor = monitorMap.get("m1");
monitor.setValue(monitor.deserialise(value));
huh
lemme try experimenting in my ide
wait what
so the class itself has no errors?
it's just that part?
the point is i'm not sure of the type here
that's why i wanted to use Object
then cast within the class
ill test in my ide
seems everything will work if i can figure out how to override the public void setValue(Object value) method
it is possible that this is actually impossible though
is monitorMap a Map<String, Monitor<?>>?
i'm relying on the fact that java knows which monitor to run the methods from, once i retrieve a monitor from the map
yes
i wonder if this is something more doable in kotlin
no I don't think it makes a difference
gimme a min
i'm wondering if this is the case
as in it's impossible
no
and i'll need to use instance of or something like i did before
okay i got it working
i think
not sure if this is how you wanted, but this is the best way that I can think of
then ```java
Monitor monitor = monitorMap.get("m1");
monitor.setValue(monitor.deserialise("a"));
but for getValue, you'll have to cast
unless
the problem with not extending from MutableBoolean is that i want all the methods exclusive to that type
wdym
well
that are not in Mutable<Object>
u can just copy it over
not so easy when i have like 20 of these D:
make ur own MutableBoolean
but setValue and getValue has to be Object
and it has to implement Mutable<Object>
wait what
wdym
i have IntMonitor extends from MutableInt, DoubleMonitor extends from MutableDouble etc
ohhhhhhhhhhhhhhhh 💀 💀 💀
there is one bad way which sorta abuses java's type erasure and that's to make the map Monitor<Object> and just cast everything to Monitor<Object> and suppress IJ's warnings
but
but i'd prefer this, as it should only take about a minute for each
or less
why do u have 20 tho
🤔
that wouldn't fix 'setValue(Object)' in 'monitors.BooleanMonitor' clashes with 'setValue(T)' in 'org.apache.commons.lang3.mutable.Mutable'; both methods have same erasure, yet neither overrides the other anyways
which one?
since the one i linked i tested
Monitor<Object>
i'm trying to actually test any of this
but it keeps running classes im not using
so i have a package monitors with the interface and all the classes
and on all the classes i've written @Ignore except ArrayMonitor and Monitor
and it just gives me errors from the ByteMonitor class???
it's running code not even inside that package
wtffff
IDE? and provide what you are running
realised this isnt what you are actually meant to do to ignore classes, but dont see why it's running everything
intellij, and that code is the test
it's doing :test --tests "MiscTests"
So did you tell it to run the tests or run the projects.
it's running misctests
What library are you using for the Tests.
Junit
Next to the line number click to the right and it should offer a message to run tests that way
Give me a moment, as I am on my phone but that should work to run individual tests for methods
same thing
idk why it's running the task compileJava
which presumable tries to compile everything
Because the project name is MiscTests? I’d presume it is running the project which is everything.
i'm just trying to execute the code i sent above
which only uses one class and one interface
i dont want it to run everything thats the point
Stackoverflow answer: https://stackoverflow.com/questions/52025648/run-junit-test-with-intellij#58973119
just copy & paste it to a different project
even if i literally make
import org.junit.jupiter.api.Assertions;
import org.junit.Test;
public class TestTests {
@Test
void shouldShowSimpleAssertion() {
Assertions.assertEquals(1, 2);
}
}
it STILL runs my whole project
?????
ok, so that's what ive been asking to change
could you show me how to make the test only test what i need please
this one
I mean your tests literally test your production code
.
So obv it needs to compile the actual source as the test source depends on it
this is what i did to test ur code
Also that test there will always fail
the classes used in my test don't give any errors
it's obviously not the case that you cant test some classes when other classes are giving errors
i know lol
i literally just want to run tests on some classes and ignore the rest
So they pass with other words? That’s good for you (;
in intellij lol
i.e. they compile
Well did you run the tests as well?
....yes
Alright, anyways if you really wanna avoid a recompile of your entire system, you might wanna divide your system into smaller subprojects/modules
i think you're misunderstanding what i'm saying or dont know how to use junit (i dont either)
orrrr this
bro im not doing some dumb workaround for a standard test
no offense it's just
i want to do it the proper way
going forward
I mean you literally shouldn’t avoid compileJava
It’s crucially necessary for you
if you're actually telling me i can't run tests on any part of my project because i have a missing { in one file in one package, then you clearly dont know how to use junit
or delete the other files (or comment them out and delete all their usages)
Like if you wanna test your code, obv ti needs to be compile-able
junit isn't the cause here
i'm not testing the code that i cant compile lmao
that's the whole point
there is no reference to any of that code
in my tests
or the classes used in my tests
bruh can literally anyone else respond
if you run gradle build, just because spigot might not use some of your code doesn't mean that it can have errors
you are clearly misunderstanding
same thing here, except that instead of spigot it's junit
No, like even if you have the class com.dkim.FinalizableAbstractFactory which does not compile, but is still in source, then of course you won’t be able to run tests for the source
because junit isn’t some magical wizard that can figure out every little interdependence of every unit you have
The task compileJava is fundamentally integral to pass in order for the tests to run, that’s just how it works, even though your test might not depend on the entire code base, but only the compiling parts
If some parts still don’t compile, it won’t run the tests as it can’t for sure know whether the failing parts are crucial to the actual compiling parts that you’re essentially testing
And yes this is ofc caused by IntelliJ (possibly gradle) in principle, altho for good reasons, you could in principle go and compile the test src for yourself and then run the tests but that’s just masochistic
so, basic possibly stupid question with gson, I'm trying to make a file, and writing an User Object (a class I made (name : string, id : int, age : int, money : int)) on it, but when I open it, its just blank.
Lil Code here:
https://paste.helpch.at/umagolexuz.cpp
tried also just using primitives
the same
never mind just had to ask fucking copilot to do it
🥲
🥲
what
yes
Can't wait to see the complaints about why people are forced to open source their code because it's written by "copilot" lol
u have to OS code generated by copilot?
Not currently. But it's not your code if it's generated by ai lol
but that also means it's not someone else's code 
Technically it would mean it's github's code
The training samples are from OS repos, but the generated code isn't necessarily generated from them, depending on context and what you do exactly it can come up with something that is not out there
It can stitch things together or, yes, copy code from existing repos
It also generates from samples from your own code
It highly feeds and depends on existing context, yeah
It's scary sometimes
Annoying mostly
can agree
I just want them to add function to do suggestion with a shortcut similar to ctrl + space
Instead of constantly suggesting
You can do that already?
As far as I know, only open that side bar
Disable live completion suggestions and use the "Open Copilot" thingy
Yeah that's not what I mean though, I mean like the current way it suggests but manual
It definitely needs more configuration on the plugin side of things
Which should be trivial!
Yeah, then I would turn it back on
i have a class i'm extending from with a method i want to override
override fun addAndGet(operand: Int): Int {
this.value?.add(operand)
logValue()
return this.value?.toInt() ?: 0
}
```however, `this.value` is nullable as the class needs to be able to be instantiated without a value, then set one later. i can't change the return type to `Int?` as the method i'm overriding returns `Int`
what's good practice for this? ?: 0 is a temp fix
give it a default value
ah yes
smart
or else i could do return this.value?.toInt() ?: throw NullPointerException("Value is not set")
well what happens if the method is called before the value is set initially?
somethin like that
well right now it just returns 0 and does nothing
and what would you like it to do?
or define it as lateinit and just make sure you set it
feel like a default value is the easiest way to go
like, if you don't want someone to call the method before the value was set, you should throw an exception
lateinit sounds like a good approach ig
it's literally what lateinit is designed for
is it? i can't guarantee that the value will be set though
so i'm a bit confused
as to what it actually achieves
like sure i hope it's set before they try and do operations on the value
but how is that different
how come you need to be able to instantiate it without a value?
it's in the spec i was given, not certain tbf
maybe i'll just remove that
unless you can explain the lateinit thing or why it helps
Only difference would be that lateinit will throw an error if you access it without initializing it
what's the appropriate way of accepting a parameter when i want to immediately change its type? i have a parameter to my class value: Int that i run MutableInt(value) on
right now i'm doing
class IntLogger(private val intValue: Int) {
var value : MutableInt = MutableInt(intValue)
}```
i never use intValue again
i just want to be able to instantiate with a regular int
what youve got there is fine
ok thanks
i'm really confused about extending actually
class IntLogger(private val intValue: Int) : MutableInt(), Logger {
i'm trying to extend from the class MutableInt
but it's making me initialise it
then whenever i try use methods from MutableInt, it just thinks the value of my IntLogger is 0
if i initialise it with MutableInt(intValue) then it just wont change when i change the value of IntLogger
this seems bizarre, why would i want two "versions" of my object here? i just want one IntLogger instance that can access the methods from MutableInt
there you're creating a logger that is a mutable int
mutableint is a class itself
logger is just an interface
which is quite a strange way of doing what you're trying to achieve
what is the end goal?
i'm trying to make my own MutableInt, where i override all the setter methods to log the value change
the way it's working now, there's one value returned by logger.getValue() (defined in IntLogger) and another returned from logger.intValue() (not defined in IntLogger)
i know 🙂 this is a trivial explanation, i'm confident of that though
i just need to get this extend working
are you familiar with calling methods on super
yes
do that
inject a logger in the constructor
shim each method and log to that logger
this is v confusing
yes
except you don't need to override methods that just call the super
override fun serialise(): String {
return super.toString()
}``` does basically nothing
and you don't need the value variable, that's defined in super too
but the value in super is Int, my value is MutableInt
your value doesn't exist
the class itself is a mutableint
we're only shimming the mutableint class, we don't care about what's happening in the class itself
ok i think i get it
also don't implement logger
wdym?
logger is my own interface
it should write to a logger, it is not a logger itself
oh
be aware that can be very easily confused for java.util.Logger which does something slighly different
is it good practice to name your own class Logger when java also has a Logger
is this correct btw?
yeah
thanks
BetterLogger
i'm trying to make my own serialisation method for ArrayLogger<T> which extends ArrayList<T>
however, i can't seem to get it to work since ArrayList has no getValue() method
val targetStream = ByteArrayOutputStream()
val out = ObjectOutputStream(targetStream)
out.writeObject(super.getValue()) // write our serialised object to the output stream
val serialisedValue = targetStream.toByteArray() // get serialised byte array
out.close()
targetStream.close()
Base64.getEncoder().encodeToString(serialisedValue) // encode byte array to String with B64
```like i just want to do this
what even is an ArrayLogger?
just a class i've made which writes to a logger everytime a set operation is made
so i'm overloading set, add etc in ArrayList
why are you serialising for logging
that seems like a bad idea
in fact why do you even need that, it sounds like a very backwards debugging technique
info(x.toString()) ?
i was trying to abstract some details but maybe not helpful
the logging is using redis
which only stores strings
so i need a serialise and a deserialiseAndSet method for ArrayLogger
dont think this is consistent
sorry i have complicated it
i know that it needs to be serialised
this method works except for when i switched to super
when i was just storing the value in ArrayLogger, it worked fine
but i can't do super.getValue()
so i have no idea how to serialise/deserialise it
explain what you're trying to do from a high level
i'm trying to create a class (let's call it ArrayLogger) that overloads any method inside ArrayList that updates any of its value
to do what?
and if that happens, i write the new value to a Redis DB
which has to be serialised to a string as that's all redis takes
orm?
well im using jedis
ill be honest im not all that familiar with redis in general but you really ought to be wrapping this stuff in some kind of manager class
but how can i do that if i can't even get the value of the arraylist
you can
how?
wdym
how can i get the value of the arraylist
when there's no super.getValue() method
When you create your project, make sure you select 'On Startup' and NOT 'On WorldLoad'!
^ In your case ofc
Well, you should haha
Uh huh
load: STARTUP means the plugin will enable before worlds are loaded on the server
load: POSTWORLD means it will enable after all worlds are loaded but before the server fully starts
@quasi kraken if there's an error please send it
There's no error.
I fixed it.
Never used postworld so didn't knowed the difference lmao
Oh alr
no idea what you mean tbf
fun getValue() = this
this and super are the same object
that will give me an ArrayLogger<T>
super is used to access methods defined in the superclass, but still refers to itself
ArrayLogger is an ArrayList
good old liskov substitution principle
if you really want to be pedantic about the return type being an ArrayList then fun getValue(): ArrayList<T> = this
i believe its from a generic interface
i replaced your getValue() with mine and it broke the serialisation
so it must not be equivalent
i mean
replaced mine with yours
i have so many questions
why are you trying to serialise stuff
what is the purpose of putting all this stuff in redis
to start with I don't think extending the types you're supposed to store is good design
how would you approach overloading the methods?
dont do that
either don't do it at all or make use of kotlin's by delegation/proxying
inclined towards the first option
How could i disable taking out items, putting in items, dragging items from my gui?
Current code(Not Working):
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
if (!e.getInventory().equals(inv)) return;
if(e.getCurrentItem() == null) return;
if(e.getCurrentItem().getItemMeta() == null) return;
if(e.getCurrentItem().getItemMeta().getDisplayName() == null) return;
e.setCancelled(true);
Player player = (Player) e.getWhoClicked();
if(e.getSlot() == 22) {
player.sendMessage("test");
}
}
That indenting 
why?
Are you asking me?
no. them
👍
why the indentation xD
i'm still quite confused by what you mean here
i looked into it but couldnt figure out why it's applicable
as in the delegation bit?
yeah
or any other way to approach it
i have an API that updates the value of this class
so surely i need a setValue method
since arraylist doesn't provide one
setting an arrays value to another array doesn't make sense
like when would you ever do that
why do you need that method
when i have a wrapper class that's monitoring something, and that instance starts monitoring something else
setting a list's value to another list is not a list
at that point its more of a list container
that's what it is
what you have there is effectively a mutable reference
for primitives, that works
for lists that does not
which is why the approach youre taking is not suitable
i dont see another approach
what is the end goal
what are you trying to achieve by logging mutations and storing them on a redis server
it's just for fun mostly, like a telemetry service
everything else works just stuck on arraylist
having fun much? 🥲
yeah mostly tbf
what the fuck is your code
tilted, obviously
Have you tried using print statements/logging to find if the function is returning when it shouldn't be? that's where i'd look first
if (!e.getInventory().equals(inv)) return;
Check for the name of the inv
Cause i think he can't find the inventory to cancel the items dragging etc
what's the correct way to implement a global variable that's used between multiple classes? i have a single map accessed in my main loop but also in the Ktor REST API
i was planning on making the methods @Synchronized
companion object?
is it just as simple as
and when i update it in either, they both change?

