#help-development
1 messages Β· Page 1996 of 1
:{
Hibernate and jOOQ
Note that all SQL libs are fucking gigantic
So I would recommend library loading when using them
btw
if i would do that
for my main class
what do i even name the interface
and how do i prevent them from just
actually
IEntitySerializerContextHolder
Regex files
Integer#parseInt()
25.604 chars long
https://github.com/matthiasgoergens/Div7/blob/master/regex7
if you compress it it will be much less probably
how can i use a variable from the main class in another package ?
https://i.imgur.com/W3xnbL0.png
What do i pick here?
How? The conventional or the unconventional way?
the better way :)
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
the minimum java version you want to support
ok so 1.8 usually?
if you want to support MC older than 1.17, then yes
if you use maven or gradle, don't choose anything
huh? why that?
eclipse automatically fetches the target version based on the maven pom or the gradle build script
well but "nothing" is not an option in the screenshot
Does anyone know the answer to this?
yeah, what I wanted to say it doesn't matter as as soon the project is refreshed it will be overwritten
okay so if i have an event involving an entity, if i save the entity to the hashmap, when i go to fetch the entity from the hashmap later, will it get that exact entity, or just an entity of the same type. for example if i tried to teleport that entity, will it try to teleport that entity specifically, or just any entity of the same type
he's wondering if all cows are the same
i mean in terms of data and stuff
yeah
Yes but use a uuid instead
entities have a location iirc
Storing an entity might cause issues
Speciesist >:(
So when you are trying to get the entity
Just get entitt via bukkit I think then use that
?
I dunno, my design process is primarily instinct
gg
Is there a way to set a skull's texture to an in game player without NMS?
ty
another thing
can you check when an item is renamed with an anvil?
Hi.
Why player.getWorld().rayTraceEntities(player.getLocation(), player.getVelocity(), 10) return null and not RayTraceResult if I'm looking at player?
I guess InventoryMoveItemEvent would be better?
as whenever any entity or block tries to move
Thatβs for hoppers
ohk
https://i.imgur.com/9PHYvGT.png
something's not working...
just gonna use inventory prepare event
https://github.com/2Hex/EntitySerializer code reviews? :OOOO
if i would execute createKingdom(k).onException(/* ... */) would the onException ever fire, cause im surrounding it with a try catch
Hello, I was making a simple command which shows information about my plugin i get this error from intellij
Non-static method 'sendMessage(java.lang.String)' cannot be referenced from a static context
I tried to
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CoreCommand {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("core") && sender instanceof Player) {
Player player = (Player) sender;
Player.sendMessage(ChatColor.GREEN + "CrackedCore by" + ChatColor.WHITE + "v1shy!!!");
} return true;
}
}
player.sendMessage
Not Player.sendMessage
no
only handleException would fire
is 1.18 too new or something im lost
and then the exception would disappear probably
and if i would do createKingdom(k).whenComplete((void0, throwable) -> /*...*/) the throwable will always be null too?
?bootstrap
Bootstrap Jar
The main spigot-1.18.jar is now a bootstrap jar which contains all libraries. You cannot directly depend on this jar. You should depend on Spigot/Spigot-API/target/spigot-api-1.18-R0.1-SNAPSHOT-shaded.jar, or the entire contents of the bundler directory from your server, or use a dependency manager such as Maven or Gradle to handle this automatically.
Please read the release notes for further information: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/#post-4305163
throwable being notnull indicates an exception happened executing the future
and im wondering if an exception would occur if it will be thrown instead of handled by the onException
Hey im using 1.18.1 spigot and im trying to change the name above the player, #setDisplayName(); doesnt seem to do the job, any ideas?
thats for chat name
oh, then is there a method for the overhead name?
ohh ok ty
there is no method, you probably want to use either scoreboards or packets
is there a forum post for how to do it with packets or such? ive new to them but have nms
i dunno for 1.18
anyways im wondering if a future completed exceptionally (calculation failed) if the exception will be thrown instead of handled by onException?
I would like to be able to send message to players with op to remind them to leave review on plugin if they didn't do it already ?
fourteen depends
idr if whenComplete runs regardless of exception caught or not
tho iirc it does
Those placeholders's don't work for free plugins. Free plugins can be downloaded without an account, so there is no way to add variables like that without a system that injects them upon upload. Which is currently not available.
thus it basically would run
oh yes I forgot you don't need account
but still it would be nice if that worked with logged in users
Either way Spigot placeholders are a bit meh
They're just another DRM that, to anyone who is at least semi-competent, is easy to bypass.
Well actually
I would rather call them a counter-attack
(Even then, staff here said they're not completely used for bans bc someone can frame another user via replacing them)
is CompletableFuture#onException even doing anything?
or does the exception needs to happen when calculating the result?
lemem try
well nothing seems to be printed
I'm surprised that this compiles even
You need to use player.sendMessage() not Player.sendMessage() @rapid rock
yea
Omfg chat isn't that far behind now smh
lol
yeah i realized that
it happens
Anyway, I'm trying to make a "dolphin circle" of 3 dolphins going in a circle moving with a player in the middle. I'm thinking along the lines of having them riding an invisible entity like an arrow or something then having those go around in a circle by settings its velocity but how would I go about updating that for when the player moves? Would I literally have to move it on PlayerMoveEvent every time? Because wouldn't that be laggy as hecc?
Any ideas?
lol try catch seems to work but neither CompletableFuture#whenComplete nor #exceptionally seems to do anything when throwing exception
considering the dolphins are moving already, why don't you make a bukkitRunnable that does change their position relative to the player?
bc whatever you use to make them move has to be updated frequently
Hmm running that every half second or so would be more efficient than updating constantly to move event?
that is because 0 / 1 is computed before the method is invoked
it would be but it would look blocky
this however seems to work
however i believe it is simpler to do it on a runnable, even if it is once per tick
the advantage of a runnable is that it only runs once per tick per that player
yes, because 0 / 1 is evaluated after the .supplyAsync method is invoked
playerMoveEvent hooks into all players moving
Yeah, that's true. I'll have to see what sort of performance impact it'll have
I'll have to listen for when players collide with the dolphins (other players) as they're meant to take damage if they do
cant you do that in the runnable too? Check for nearby players
then run collision checks
I could, happy to try whatever to get it working at this point xD not sure how much of a performance impact it'll have
Since multiple people might be using the ability at once
so this is exactly the same?
I'm also looking at making a weak spot being revealed for players but only for 1 player and while their bow is drawn, should I do something similar as well? Register a BukkitRunnable and when the bow is no longer drawn or has been fired, end the runnable? I'm thinking of having an xp orb represent the weak spot to be shot by a bow
Just worried about spamming the hell out of the player with packets lmao
no
well the second one wont print the result
just figured out how it works
#thenAccept only executes when the future didnt complete exceptionally
hey, is there like a way to add a bukkit runnable inside a bukkit runnable
or is that bad practice or smt
i put a bukkitrunnable.runtaskLater() inside a bukkitrunnable.runtasktimer() and it didnt work
is there like another way of doing this?
lol sqlexception doesnt want to get handled by future
huh?
not meant for you
oh sorr y
Im using this to make particle circle
for (int degree = 0; degree < 360; degree++) {
double radians =
Math.toRadians(degree);
double x = Math.cos(radians);
double z = Math.sin(radians);
location.add(x, 0, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 1);
location.subtract(x, 0, z);
}
What would happen if i did this?
for (int degree = 0; degree < 360; degree++) {
double radians =
Math.toRadians(degree);
double x = Math.cos(radians);
double z = Math.sin(radians);
double y = Math.cos(radian);
location.add(x, y, z); location.getWorld().spawnParticle(Particle.END_ROD, location, 1); location.subtract(x, y, z);
}
```?
Hate phone copy and paste
i think i dont have to throw exceptions but instead return a CompletableFuture#failedFuture
doesn't #whenComplete handle exceptions
how r u combining them
im having a Storage interface with method like #loadUser which do database stuff and when they catch an exception, they will throw an RuntimeException(innerSqlEx)
that isnt caught by CompletableFuture#exceptionally cause it didnt occur when calculating the future's result
thats odd
Anyone?
i cant rethrow the exception cause Future#exceptionally wont catch it
lemme just add throws clausule and remove the catch
then handling exceptions in the delegate
which will return a failed future instead of printing stacktrace
π lol
this looks weird lol
CompletableFuture.runAsync(() -> {
throw new RuntimeException();
}).exceptionally(t -> {
System.out.println(t);
return null;
}).join();
this worked just fine
ye but problem is the code that throws and the code that catches are seperated
so #exceptionally wont trigger
can u show me?
this is the actual implementation which will throw exceptions, the runtimeexceptions are a temporarily fix
https://github.com/FourteenBrush/MagmaBuildNetworkReloaded/blob/master/src/main/java/me/fourteendoggo/MagmaBuildNetworkReloaded/storage/impl/SqlStorage.java
and this is the delegate which will handle exceptions
https://github.com/FourteenBrush/MagmaBuildNetworkReloaded/blob/master/src/main/java/me/fourteendoggo/MagmaBuildNetworkReloaded/storage/DelegatingStorage.java
github weird lol syntax highlighting gone
im at looking at returning a failed future instead
now it'd work fine if you'd later chain it with
.whenComplete or .exceptionally
and
if you really wanna log
then just do it like
Conclure (ping for help) β Today at 4:33 PM
Cf.do(() -> {
try {
action.do();
} catch (Exception e) {
logger.severe(e); /////////////
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw CompletionException(e);
}
}```
conclure ping for help do i need to include that too
kekw
hmm ye
in the delegating thing?
private <T> CompletableFuture<T> makeFuture(Supplier<T> supplier, String errorMessage) {
return CompletableFuture.supplyAsync(() -> {
try {
return supplier.get();
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new CompletionException(e);
}
}, executor);
}```
I'd would advice you not to log in the delegating class
but do it in the lowest level classes, such as in your connection listener for instance
are you sure that the exception is given to the future and thats its not a global thing?
as you then can be more specific about plausible exceptions
wym?
that #exceptionally will even fire
ye that would be a db error
oh yeah btw fourteen
you might wanna use something like
interface ThrowingSupplier<T> {
T get() throws Exception;
}
assuming your delegate actually throws checked exceptions
ah ye
you always have such genius ideas lol
but what would that change if i create that kind of supplier vs a normal one?
so i can do it like this?
well
that means a no i guess
Okay I am just curious, what would happen if this object were to be created?
Build results are outdated for requested compile scope.
Subsequent incremental build will compile files for changed sources and remove obsolete results of the previous build.
when tryna compile
StackoverflowError
alright ty
interface ThrowingSupplier<T> {
T get() throws Exception;
}
interface StorageTool {
UserModel loadUser(Id id) throws Exception;
}
class SqlStorageTool implements StorageTool {
@Override public UserModel loadUser(Id id) throws Exception {
throw new SqlException("rip");
}
}
class StorageAdapter {
final StorageInterface delegate;
StorageAdapter(StorageInterface delegate) {
this.delegate = delegate;
}
<T> CompletableFuture<T> makeFuture(ThrowingSupplier<T> supplier, String errorMessage) {
return CompletableFuture.supplyAsync(() -> {
try {
return supplier.get();
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new CompletionException(e);
}
}, executor);
}
CompletableFuture<UserModel> loadUser(Id id) {
return CompletableFuture.supplyAsync(() -> {
return this.makeFuture(() -> this.delegate.loadUser(id));
});
}
}```
@tardy delta
or sth
wrote that on phone again?
nope
xd
x)
Say I want to have a directory in which multiple configs of the same kind can be placed, but I need to (very often) read values from anywhere within all of them - Is there an easy way to make them all act like one single config which I can call?
well
if its configs
then a single read should suffice
else it sounds more like arbitrary data that you store during runtime for persistency
i get it, thanks conclure π
Well it is something like from crackshot's weapons directory in which multiple fileconfigs of the same kind can be created
sometimes im stupid, i was combining a whenComplete and exceptionally and wondering why the exception wasnt being handled
and each one can have multiple sections which are used to define the properties of the weapon you get
yeah but why do you need to read them very often
well ok I can just store it all into ram
but it needs to keep the structure
so what would be the best way of combining lots of yaml configs into one hypothetical file
well
you dont combine them into one file
but you just read the content of the files
mhm okayy
how can I get the current tick of the server? (The actual tick, not TPS)
if a java.sql.Connection is closed, is the corresponding PreparedStatement closed too?
i dont think it gets automatically closed
but any of the methods would probably end up throwing an exception
Is there a raw getter for a resource's latest update description from Spigot? Much like getting a plugin's current version, but for the description instead
then i got two preparedstatements in the same method
you need to do a http(s) request for that
afaik nope , theres no nice api for that
although do you mean the version of the plugin or what?
what do you need it for?
so yeah a normal request where you filter out the content you want would be needed Corals
Yea exactly, what url should I enter
to compare how much time has passed compared to the tick i have saved
the plugin url
So I have to filter one myself huh
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
if the plugin is on spigot site
maybe you can find some nice rest api
try {
final Field currentTickField = Bukkit.getScheduler().getClass().getDeclaredField("currentTick");
currentTickField.setAccessible(true);
final int currentTick = currentTickField.getInt(Bukkit.getScheduler());
@misty current
idk
nope
Yes, like this, but for the latest update description, not only the version
spiget API
i dont know if you can even reach that with a web request
one last question, should i prefer doing this compared to using the current unix time? i feel like unix would be unsynced with server ticking
just get the list of updates, and from the latest one, get the "description" part
Did not know about spiget, what a handy tool. Thanks!
np!
Is there a good way of making a loot table or is it just RandomInt and doing % on the RandomInt?
as bungeecord doesnt really have a server /main thread
hm
so something like this public void clearLists() { getProxy().getScheduler().schedule(this, new Runnable() { @Override public void run() { Donate.clearDonateList(); Donate.clearOtherList(); } }, 1, 1440, TimeUnit.MINUTES); }
yeah was about to send this too
Is ChatColor.translateAlternateColorCodes more efficient than String.replace()?
It just does the work for you
No point not using it
ProxyServer.getIntsance().getScheduler().schedule(plugin, Runnable, int, TimeUnit)
ProxyServer*
No ()
Hello everyone! I am trying to make a snowball that sets freezing ticks to 140 upon hitting an entity. All Iβve accomplished so far is create a custom item stack of snowballs so they can be told apart from regular snowballs. Iβm struggling with how throwable projectiles work and how can a projectile hold data such as if the snowball is freezing or not.
also without the typo in getInstance lol
XD
Does anyone work with Paperweight here?
I am gonna cry
chatcolor thing does some looping π
efficient? it's only doing some string stuff, no need to worry about which of those is "more efficient"
Hey :)
Do you know if there is any event fired when a player crash ?
crash? wdym?
When a player crash, it will not fire PlayerQuitEvent
then it wont fire anything else
WELL
PlayerQuitEvent will be called
still
once they timed out
one question, should i prefer doing this compared to using the current unix time? i feel like unix would be unsynced with server ticking and be kinda unreliable
Dude I think a ChatColor translation is the least thing you should worry about
I will bet money even Hypixel does that lol
oh he was saying that no quit event was fired
@misty current I can tell you Skript by you saying unix time
depends on whether you need the actual time passed, or the time in ticks passed π
i used to, but that's the actual name
at least afaik
I know :>
i remember yesterday you said oh no a mh guy
Wait
lol
ah nice
Hi, is it possible to set commands outside the main class?
Of course
Yep
I am so mad that I linked my Spigot account on here
It made my nickname so lame
I haven't been called this name in 4 years
not that bad
what do you mean? registering them or implementing the interface?
in both cases yes
Ah, then do I need to do something extra other then just type the onCommand function?
you need to implement commandexecutor
in the class where you wanna put the code the command needs to execute
what is the right way to allow players to place blocks but not open chests, or any type of container
so what would be best way to cancel Runnable in bungee?
Iβll try to rephrase:
What event gives me both the item that was thrown and the projectile that was spawned?
cancel PlayerInteractEvent
listen for playerinteractevent
but if i cancel player interact event, they cant place blocks
the schedule(...) methods returns a ScheduledTask that has a cancel() method
only cancel it if the clicked block is one of those special blocks like chest, etc.
or maybe just cancel the InventoryOpenEvent if the inventory holder is a block?
Like so? (this is my class)
public class MyListener extends JavaPlugin implements Listener, CommandExecutor {
e.g. you can do
if(clickedBlock.getState() instanceof Container) // Now cancel PlayerInteractEvent
is this your main class
no this is a listener class that I want to put a command in
hm
you can't extend JavaPlugin outside your main class
does 1.18.2 have nms changes
oh I thought this was mandatory for the onCommand method?
its not
https://i.gyazo.com/thumb/1200/f68a7fb6dd0eeaefdbe13e0a30d0f390-jpg.jpg
Any way to actually like get this thing away as this wont load at servers π¦
System.out.println("Config Loaded");
saveConfig();
System.out.println("Config Saved");
getCommand("core").setExecutor(new CoreCommand());
System.out.println("CoreCommand has been enabled");
getCommand("helpop").setExecutor(new HelpOPCmd(this));
System.out.println("HelpOPCommand has been enabled");
getCommand("god").setExecutor(new GodCommand());
System.out.println("GodCommand has been enabled");
getCommand("day").setExecutor(new DayNightWeatherCommand());
getCommand("night").setExecutor(new DayNightWeatherCommand());
getCommand("weather").setExecutor(new DayNightWeatherCommand());
System.out.println("DayCommand has been enabled");
System.out.println("NightCommand has been enabled");
System.out.println("WeatherCommand has been enabled");
``` is what causes the thing
you just need to implement commandexecutor
for commands
that background lol
it was pretty random ngl π
Those are warnings. It won't prevent it from compiling.
those are warnings
it compiled but loading throws nullpointer error
it just says that it might be null because getCommand is nullable
thats because u didnt register commands in plugin.yml
You likely don't have the commands in your plugin.yml then.
it will only throw a nullpointer when you didnt register your command inside the plugin.yml file so you can basically ignore it
How do I make my spigot plugin backwards compatible?
oh yeah i forgot to register
i registere only 2
you can just use a holder or a final temp variable, like this
Holder<ScheduledTask> scheduledTaskHolder = new Holder<>();
scheduledTaskHolder.value = ProxyServer.getInstance().getScheduler().schedule(main, () -> {
if(!player.isConnected()) return;
scheduledTaskHolder.value.cancel();
}, 1, TimeUnit.SECONDS);
Thank you
ok thanks
i am trying to work with mongo and i'm trying to disable logging with this code
((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver").setLevel(Level.ERROR); i have found in a stackoverflow post.
However, this code throws a classcastexception:
Caused by: java.lang.ClassCastException: class org.apache.logging.slf4j.Log4jLoggerFactory cannot be cast to class ch.qos.logback.classic.LoggerContext
I was wondering why was it the case, I have tried googling about this issue but i had no success
Depends on what your plugin does, but you will probably want to start with a multi module setup. Then you can code for each version individually as the API is really neither forwards or backwards compatible in every aspect.
i guess it's because minecraft does soemthign with the default logger but i have no idea how to make it work with minecraft bs
so this should work?
public class MyListener implements Listener, CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage("Command executed");
//dont mind the actual command
if (label.equalsIgnoreCase("cRefresh")) {
players.clear();
for (Player p : Bukkit.getOnlinePlayers())
players.add(p.getUniqueId());
sender.sendMessage(players.toString());
}
return true;
}
}
no need to implement Listener
^
that's for event listening as the name says
Also make sure to register the command obviously
the plugin is stupidly simple, only acouple chat things made for 1.18 but I want it to work on 1.16 and 1.17, is there a way I can do this?
yeah I want to listen to events later on in this class, is that not possible?
having a listener and a commandexecutor in one class sounds messed up
because it's kind of a mess else
ah
I mean of course you can do it, if it somehow belongs together, but normally you wouldn't do it
If the methods you use are available in older versions, then it might just work out of the box. You would just need to set your api-version in your pluign.yml to the oldest version you want to support. But again, it really depends on what your plugin does.
I just need the command to reset a list, hence it would be convenient
thanks π
does 1.18.2 have nms changes?
yes
depends on what part you refer to
ofc never versions have more stuff in it
Is there a way of editing a loot table?
Does anyone know how to use Paperweight?
did they change the obfuscation
Compared to?
it automatically changes on all classes that were changed
on older versions i coould use "nbttag.getKey()" now i need to use smth like "nbttag.a()"
you have to use mojang mappings
That's because of the mojang mappings.
how do i use them
(for 1.18) How can I get default chunk generation and use it with another seed?
- I know I can create custom BiomeGrid, but it is not supposed for default generation
- It is kinda deprecated in 1.18
there is some other thing in 1.18 instead BiomeGrid but it is difficult to make use default algorithm too
and how can I set current generation type to another
if there is stuff for that (like interfaces to implement)
it works now, thanks for the help :D
is there a way to make an item be held up like when you hold a crossbow?
wdym by that?
you mean the loading animation or the direction the item is facing?
like how it renders while a player holds it without doing anything
i wanna have an item that is held like this
probably with animation packets
frick
animation packets should be pretty easy with protocollib if you don't want to mess with nms code
personally I like raw nms code
same here
they are not actually
there are tutorials on yt
for me they are
easy stuff is well documented
actually i am not sure if the right packet is the one i said
Some parts of nms is like an ancient overgrown mangrove jungle, not always trivial
does anyone know?
ok :/
btw
whats wrong with stuff that were in my api packagae
i dont see the problem with them
https://www.spigotmc.org/threads/1-9-fake-bow-draw-animation.140234/ hm apparently you can't really fake it, looks like the client just trashes the packet if the player is not holding a bow
not sure if i misread something
o but how to improve it
Expose interfaces
or something with a valid animation
Instead of exposing implementation
This feedback I gave you is of course a bit towards the enterprise and professionalism direction
So if youβre just creating an average spigot lib, then it doesnβt matter that much
good
just don't go too far in the enterprise rabbit hole
Anyone know how loottables work?
is that right or should i create the cache using the syncrhonizedMap?
oh wait
Cache it
but like i would have to make a factory pattern for that right
As the method simply wraps the map
alright thanks
Depends 2Hex
Theyβre much better than direct instantiation
As it decouples instantiation and creation
Like when I worked on a semi-professional project then I pretty much used static factory methods and sometimes factories whenever I creates new objects because it really helps decoupling
is there any way to get internal crafting inventory of player
not player's inventory
but the crafting's inventory inside player's inventory view
what does async mode means in the context of executors? arent they considered to be running on another thread?
player.getOpenInventory() works if player doesnt have any inventory opened
but is there any way to have that instance directly
are we talking about the fork join pool?
ye
in that case it just switches execution priority
normally they have a last-in-first-out order
forkjoinpool has a boolean property to toggle that
such that it can become first-in-first-out instead
so basically what i gotta do is:
make a factory that will produce something like this:
Interface object = new ObjectThatImplsInterface();
then the user will only have access to the interface methods
which is better if you want to make some sort of event based system
2Hex uh
I'd do sth like
^
i thought it would be fifo so the tasks are executed as quickly as possible but probably because its a forkjoinpool it uses lifo?
becausse the tasks are split into smaller tasks π€
by default fjp uses lifo
uh well
not necessarily
fjp is better at distributing tasks than cached thread pool
but it cannot simply tear down a runnable just like that
like wut lol
afaik no? Where?
oh nvm
PlayerInventory and crafting Inventory are different
they're split up
i would love to set items at that inventory
even if the player opens chest or any other container type
How can i make waves with particle?
does ArrayList#sublist modify the array
if so is there anyway i can do the same function without modifying it
then study them...
probably something like sin(xy + t)
iirc no
actually, lemme plot something
I click on the spigot mc server and curves is the first thing I see
you can https://tryitands.ee
btw conclure in case of my class EntityHolder, how would i name the interface
and if i make an interface named Holder, i must make it generic, cuz a holder can be many stuff
a sec
Where
and how can I do it without modifying the array
solved it via NMS and moj mappings: ((CraftPlayer)event.getWhoClicked()).getHandle().inventoryMenu.getBukkitView();
this would always return player's inventory view no matter if container is opened
sin((x * x + y * y) * time)
new ArrayList<>(list.subList(from,to)); or sth @red sedge
I think there is a better way of doing it
What is time
but that's one
A variable that is proportional to the time passed
ah nice
Best way:
IntStream.range(from, to).mapToObj(list::get).toList()
In ticks?
It can be anything
in whatever
The faster it increments the higher the frequency of the waves however
Ticks might be too fast
or iirc there's clone on a sub list
Does anyone know how to move an entity to a player?
Entity#teleport(Entity)
Entity#teleport(Location)
well then i am too used to kotlin
how are you so fast at typin
well I want it to move not to teleport
well I dont blame you
yes, teleporting moves the entity to another loc
if you mean walking thats an entire other can of worms
yes
If you want to make it pathfind to another entity that's gonna be hellish
Though actually
Depending on what entity it is
just implement A*
You could just set its target
oh oh
oh yeah
I want it to work for all entitys. Also items
So sin((xxy*y)*0.5L) will make less waves than 2.0L?
in case u didnt see that since its flooded
then implement an A* pathfinding algorithm
Actually, my formula is flawed
How can I do that?
My library has pathfinding built in but it does ignore gravity
You can use google
dam red, anything that you haven't done that wouldn't be copying redlib?!
It should be sin((x * x + y * y) * k + time) instead. k dictates the between waves frequency and must be a constant. Time is an everyincreasing variable and is proportional to the frequency of high and low at a certain point
not the only thing you copy :troll:
i mean
All code ever written is derivative of RedLib
great point, i do like making command libs
no its derivative of borpa
That's what I need
Oh cool
Just use a website like https://c3d.libretexts.org/CalcPlot3D/index.html and play around with the formula tbh
Thanks!
Probably overkill to use the entire library just for this small function
Feel free to just copy+paste the code you need
Credit is appreciated but not required
So I would need some suggestion what would be best solution for my problem with ThreadPool
public ExecutorService ex = Executors.newFixedThreadPool(10);
So I am using 10 ThreadPools and hikaricCP mysql
So problem now which I have is that for example if player votes on some web sites and he gets reward of coins which is added thru this thread pool
Server will run for example 5 reward one for each vote which will run /Coins add %player% 5
that will then run mysql code but problem is all of those reward will run at same time and on the end player will end up getting one reward
because multiple task in mysql will override each other
So what would be best solution to keep track if there is already task with that player in pool HasSet and then make another thread which will collect tasks and when player is removed from HashSet add that player and next task to pool?
Thanks so much!
ofc
public static final double K = 1.0;
public void makeWaves(double x, double y, int k, long time){
double waveThing = Math.sin((x*x*y*y)*k+time);
spawnParticle(particle, waveThing, 1);
}
```?
Im on phone so probably missed something
Not quite. You also need to update the position of the particle afterwards
And it should be x * x + y * y, not x * x * y * y as you want it to be proportional to the distance from the center (which in this case is assumed to be 0/0 - so change accordingly)
Ah ye i didnt see you put a +
And y should be z in minecraft space really
@grim ice just an example,
but here the api user would first use for instance
EntitySerializer serializer = EntitySerializer.create(this);
and then they can do whatever they want with the serializer...
interface EntitySerializer {
static EntitySerializer create(Plugin plugin, StructureManager structureManager) {
return new SimpleEntitySerializer(plugin,new EntityHandler(structureManager, new StructureFactory()));
}
static EntitySerializer create(Plugin plugin) {
return create(plugin,plugin.getServer().getStructureManager());
}
static EntitySerializer create() {
return create(JavaPlugin.getProvidingPlugin(EntitySerializer.class));
}
Plugin getOwner();
Serializer<Entity, NamespacedKey, EntityHolder> getHandler();
}
class SimpleEntitySerializer implements EntitySerializer {
final Reference<Plugin> plugin;
final EntityHandler handler;
SimpleEntitySerializer(Plugin plugin, Serializer<Entity, NamespacedKey, EntityHolder> handler) {
this.plugin = new WeakReference<>(plugin);
this.handler = handler;
}
@Override @Nullable Plugin getOwner() { return this.plugin.get(); }
@Override Serializer<Entity, NamespacedKey, EntityHolder> getHandler() { return this.handler; }
}```
Center is player
x*x+z*z?
Yeah (but let's ignore that)
That what
It's not really relevant how the waves are set up
Well it is, but you get the gist either way
How can I get an entity a player is looking at?
but doing Serializer<...., ...., ...> is too long and ugly and exposes how the api works
ur hiding that, but showing the other
no its an interface
ik
it exposes what, not how
public static final double K = 1.0;
public void makeWaves(double x, double z, int k, long time, Player p){
double waveThing = Math.sin((x*x+z*z)*k+time);
spawnParticle(particle, waveThing, 1);
}```
?
isnt there any other way that isnt that ugly
but if you want, you could obv create a shorthand interface like interface EntityHandlerSerializer extends Serializer<Entity, NamespacedKey, EntityHolder>
and then return EntityHandlerSerializer
@quiet ice
but like, I'd just return Serializer<Entity, NamespacedKey, EntityHolder>
should be p.spawnParticle()*
What Mike said, reverse the map so its entity, player so you dont itterate through the map a lot
Wait
didnt realize you responded to his message
Sorry for ping lol
that would error since handler expects an entityhandler not a serializer interface
It seems that you do not understand plotting
even though it implements it
then change it ?
But I am too lazy to explain
then u cant do this
yes u can?
u cant return a subclass from its parent class tho
u cant turn a parent class into a subclass is what i mean
obv if u wanna use sth like the example EntityHandlerSerializer you'd have to expose that instead of just Serializer<..., ..., ...>
u cant return the serializer interface when the type is EntityHandlerSerializer
Can you Simplify it?
the concretion must implement EntityHandlerSerializer
thats a mess
yeah, well I'd just stick with the Serializer interface
sure its long
but its a high abstraction which is nice
ok
why i geting nothing on this String from a nbt value
public static ItemStack setNBTValue(final DeanGuns plugin, ItemStack item, String key, String value) {
net.minecraft.server.v1_12_R1.ItemStack itemStack = CraftItemStack.asNMSCopy(item);
if (itemStack == null) return null;
NBTTagCompound nbt = itemStack.getTag();
if (nbt == null) {
plugin.sendMessage("null");
nbt = new NBTTagCompound();
itemStack.setTag(nbt);
nbt = itemStack.getTag();
}
nbt.setString(key, value);
String value1 = nbt.getString(key);
plugin.sendMessage("value1:" + value1);
itemStack.setTag(nbt);
item = CraftItemStack.asBukkitCopy(itemStack);
return item;
}
public static String getNBT(DeanGuns plugin, ItemStack item, String key) {
net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
final NBTTagCompound nbt = stack.getTag();
plugin.sendMessage("value:" + nbt.getString(key));
return (nbt != null && nbt.hasKey(key) ? nbt.getString(key) : null);```
im gonna pull since my local version is a mess now lmao
π₯²
ill fix it now
its alright, yep i got it working nowπ
basically you'd need to have something like
makeWaveMomentarily(xCenter, zCenter, yMin, t, size):
for (x)
for (z)
x2 = (xCenter + x);
z2 = (zCenter + z);
spawnParticleMomentarily(x2, sin(x * x + z * z + t) * size + yMin, z2)
makeWavePersistent(xCenter, zCenter, yMin, size):
t = 0;
schedule:
makeWaveMomentarily(xCenter, zcenter, yMin, t++, size)
@dire salmon
Just note that this is highly pseudocode since I cannot be arsed to write compileable java code there given that I never worked with particles
Stop trolling
ident based π
Im not trolling :(
True
You are. I am saying that this is pseudocode and you ask what method to call
Like jesus, this won't compile anyways!
Heck, this won't run even with eclipsec
I dont know what pseudocode is
that wont work anyways btw
its actually impossible i think
there isnt a shorthand
there is
So i call nothing or what?
which is?
First of all you gotta understand what I sent you
interface EntityHandlerSerializer extends Serializer<..., ..., ...> {}
class SimpleEntityHandlerSerializer implements EntityHandlerSerializer {
//TODO
}
interface EntitySerializer {
static EntitySerializer create(Plugin plugin, StructureManager structureManager) {
return new SimpleEntitySerializer(plugin,new SimpleEntitySerializerHandler(structureManager, new StructureFactory()));
}
static EntitySerializer create(Plugin plugin) {
return create(plugin,plugin.getServer().getStructureManager());
}
static EntitySerializer create() {
return create(JavaPlugin.getProvidingPlugin(EntitySerializer.class));
}
Plugin getOwner();
EntityHandlerSerializer getHandler();
}
class SimpleEntitySerializer implements EntitySerializer {
final Reference<Plugin> plugin;
final EntityHandler handler;
SimpleEntitySerializer(Plugin plugin, EntityHandlerSerializer handler) {
this.plugin = new WeakReference<>(plugin);
this.handler = handler;
}
@Override @Nullable Plugin getOwner() { return this.plugin.get(); }
@Override EntityHandlerSerializer getHandler() { return this.handler; }
}
2hex
ic
All i see different here is no {}
for (x)- No return types
:schedule:- No variable types
- No access modifiers
Are you sure that the block represents an analoguepowerable?
makeWaveMomentarily(xCenter, zCenter, yMin, t, size):
for (x)
//returns nothing
for (z)
x2 = (xCenter + x);
z2 = (zCenter + z);
spawnParticleMomentarily(x2, sin(x * x + z * z + t) * size + yMin, z2)
makeWavePersistent(xCenter, zCenter, yMin, size):
t = 0;
schedule:
//returns this?
makeWaveMomentarily(xCenter, zcenter, yMin, t++, size)
i tried checking for REDSTONE_WIRE material but that doesn't even call anytime
How would I be able to play this as a title?
play-title:
- "&c&lP L A Y !"
- "&c&lP L A Y !"
- "&c&lP L A Y !"
- "&c&lP L A Y !"
- "&c&lP L A Y !"
- "&c&lPLAY!"
- "&e&lP&c&lLAY!"
- "&c&lP&e&lL&c&lAY!"
- "&c&lPL&e&lA&c&lY!"
- "&c&lPLA&e&lY&c&l!"
- "&c&lPLA&e&lY&c&l!"
- "&c&lPLAY&e&l!"
- "&c&lPLAY!"```
I tried this https://paste.md-5.net/ezolabibud.java but it only plays the first one cuz of me using cancel(); but removing it just makes it loop through it all endlessly.
I put this inside run() in my BukkitRunnable?
that is probably a bukkit moment then
By using a bukkit runnable
Look at the paste.. thats what I tried doing
it also doesn't work with REDSTONE_WIRE
Yeah it is
Yeah but you play the first message and then you cancel the runnable. Do you only want to display the first message?
Okay, according to the material enum redstone wire is analogue powerable, but redstone redstone is not
I doubt they want that based on their config.
Wait... You even start one runnable per line and let them run all at the same time,,,
But bukkit has been strange from time to time, so Β―_(γ)_/Β―
but even with the REDSTONE_WIRE check it doesn't do anything
Geol?
as in crash or just not doing anything?
Want it to loop through all the lines in the config
Just doing nothing if you are talking to me
and do sysouts print anything?
Then do that. Just increment a counter in the runnable and use it as the next index
i don't have any sysouts
then add a few just to be extra sure.
The fact that if it is redstone is throws an exception is normal, but if it is an redstone wire it is strange
it doesn't throw anything, it just doesn't do anything at all
block.getBlockState().setBlockData() is basically a NOP
(if block is a bukkit block)
then how do i do it? π
I don't get it?
my goodness
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/Block.html#setBlockData(org.bukkit.block.data.BlockData) documentation is bliss
declaration: package: org.bukkit.block, interface: Block
it doesn't do anything either this way
π€·
Not a hard concept. Incrementing a counter isnt that complex.
even with redstone_wire?
yes
And the sysouts do get called?
hello! so im developing a spigot plugin and in the plugin it has custom items which have custom textures . So far this has not been a problem (managing to put custom textures via a resource pack) but ive gotten stuck when it came to armor. So does anyone know how to make the armor look different? below ive attached some images of the item json files and what it looks like in game like shown in game it still shows up on the player like netherite armor
so wait wait
i tried adding a sysout at the end
and it works
so there is a problem updating the block i guess
As in fully works or just the sysout working?
There is a separate file for armor textures
the sysouts are working
the block updating are not
Anyone?
What exactly is your problem?
Yes
This
Don't bother
Aight
Basically spoonfeeding here, but there's comments.
https://paste.md-5.net/pixinezufo.java
y = sin(x * x + z * z + t) should already be enough info
Ok
I have no idea what is going on then
I certainly do not see any issue with the code
sin?
yes i am aware although i do not know how to code it do you know the code i need in my json to change it bc i have added in the model/armor folder the template for the armor
Math.sin
but is the part of the power correct?
Here is most of it. The rest should be trivial:
public void sendLines(Player player, List<String> lines) {
new BukkitRunnable() {
int index = 0;
@Override
public void run() {
if (index == lines.size()) {
cancel();
return;
}
String line = lines.get(index);
player.sendActionBar(line);
index++;
}
}.runTaskTimer(plugin, 1, 1);
}
Math.cos should also work
What that things?
Basic trigonometry
I dont think that the correct sintaxis
Of course it isn't the right syntax
Nothing you can do with json files there.
The model of armors cant be changed. Only the texture.
So having multiple armors is sadly not possible.
in my mind yes
uh wait! I tried using a command to set the redstone power of a redstone wire and it doesn't work either, so there must be a problem within my other plugins i guess
ah ok well ty for the help
sin, cos and tan, takes 2 paameters...
Yes
XD
What kind of sin are you using? 2 params makes no sense
Like. Sin is just a one dimensional function f(x)
oh thats what you meant, thanks
Corrector its wrolikgn romg
pretty sure in java the input needs to be in radians
Idk what happen
Are you drunk or just using a phone?
Doesnt make sense. Just take degtes
Not in degrees. In most cases in programming, radians are used.
about abstraction in the api package
Ahh that why
Honestly... its not that important unless you plan on changing the underlying implementation in any way.
nah man u cant tell me its unimportant after spending all that time π
In my api im between using interfaces or abstract classes. Recommendations?
jk
How to update ItemStack in player's inventory?
For e.g. I want to change it's displayName
getItemMeta().setDisplayName() isn't working
well nothing is important except that the code works if u think about it, but ur not gonna feel good and no one is gonna feel good about ur code if u just follow that statement
If you can tell me the main difference between those then ill tell you why one makes more sense than the other.
Player#getItemInHand().blabla?
Not in hand
You need to add the ItemMeta back on the ItemStack.
Isn't working too
I was told that for building api classes i should use interfaces
public void replaceItemName(CustomPlayer customPlayer) {
if(getCooldown() == 0) {
ItemMeta itemMeta = getItemStack().getItemMeta();
itemMeta.setDisplayName(Utils.colorize("&fSword | &aCan use"));
getItemStack().setItemMeta(itemMeta);
customPlayer.getPlayer().updateInventory();
} else {
ItemMeta itemMeta = getItemStack().getItemMeta();
itemMeta.setDisplayName(Utils.colorize("&fSword | &cWait"));
getItemStack().setItemMeta(itemMeta);
customPlayer.getPlayer().updateInventory();
}
}
show the getItemStack() method
public ItemStack getItemStack() {
return itemStack;
}
This ItemStack is in a field. Dont do that. Get the ItemStack from the players inventory.
Why not just get the item the player is holding and then work off of that? Or if you just need something from the inventory, iterate over the inventory till you find what you need to edit.
π€
hm, okay, I'll try
#help-development message can some1 can help me with that?
Update to 1.14+ and use pdc π
Or use the nbt api
which is why the word "and" was used
i just want solve my problem
how can i make my map be thread safe
either by synchronising on the map while iterating or just using ConcurrentHashMap
Are you trying to implement your own Map?
@EventHandler
public void roleMenuEvent(InventoryClickEvent e) {
if(e.getClickedInventory() != null) {
Player player = (Player) e.getWhoClicked();
if(guiManager.createRoleSelector(player).equals(e.getClickedInventory().getHolder())) {
e.setCancelled(true);
}
}
}```
how could i Disable taking items from inv? I have sth like this but it's not working
nop
new PropertyMalformedException().printStackTrace();
Is this the correct way of throwing a custom exception?
use CHM really
ok
no
i just realized too
?learn java
so NVM
what was the command?
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
thank you
throw new PropertyMalformedException("Some message");
how would i use getWorld() in a command
i think Bukkit.getWorld();
Just like you would use it everywhere else
Bukkit.getWorld(String)
soo... did anyone knows?
what would i put as a string
the name of the world?
of tge world folder
how could i get inv name?
?jd
declaration: package: org.bukkit.inventory, interface: Inventory
look at its javadocs
code review :O https://github.com/2Hex/EntitySerializer
That's working
Thank you!
for(int degree=0;degree<360;degree++){
double radians = Math.toRadians(degree);
double x = Math.cos(radians);
double z = Math.sin(radians);
location.add(x, 0, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, 0, z);
}
so i can't get inv name?
don't think inventories have names*
Nah
They do
i mean title
Wait
titles are tied to the view
declaration: package: org.bukkit.inventory, class: InventoryView
Pretty sure it doesnβt work still
@quiet ice i use this to make normal circle
is there a way to make the waves thing from here?
I could be wrong
so what am i doing wrong i comparing these invs?
Your checking if the player is equal tk the person opening the inventory?
createRoleSelector might just create a new inventory
I never worked with particles so I do not know
GUIManager guiManager = new GUIManager();
@EventHandler
public void roleMenuEvent(InventoryClickEvent e) {
if(e.getClickedInventory() != null) {
Player player = (Player) e.getWhoClicked();
Inventory inv = e.getClickedInventory();
if(inv.equals(guiManager.createRoleSelector(player))) {
e.setCancelled(true);
}
}
}
}```
this also don't work.
also, if that is just for a circle, it can just be y + sin(t) * k where as t is something proportional to time and k just a constant size factor
what do you mean "it doesn't work"? it doesn't cancel the event? are the inventories really equal? does it only sometimes cancel the event, or never?
yes it doesn't cancel event
I bet your "createRoleSelector" method creates a new inventory every time?
You want to create a circular wave from one center outwards?
Inventory roleSelector = Bukkit.createInventory(inventoryOwner, 9, "Wybierz rolΔ");
ItemStack glass = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
ItemMeta glassMeta = glass.getItemMeta();
glassMeta.setDisplayName(ChatColor.WHITE + "Wybierz rolΔ");
glass.setItemMeta(glassMeta);
ItemStack policeButton = new ItemStack(Material.BLUE_WOOL);
ItemMeta policeButtonMeta = policeButton.getItemMeta();
policeButtonMeta.setDisplayName(ChatColor.BLUE + "Policja");
policeButton.setItemMeta(policeButtonMeta);
ItemStack criminalButton = new ItemStack(Material.RED_WOOL);
ItemMeta crminalButtonMeta = criminalButton.getItemMeta();
crminalButtonMeta.setDisplayName(ChatColor.RED + "Kryminalista");
criminalButton.setItemMeta(crminalButtonMeta);
roleSelector.setItem(0, glass);
roleSelector.setItem(1, glass);
roleSelector.setItem(2, glass);
roleSelector.setItem(3, policeButton);
roleSelector.setItem(4, glass);
roleSelector.setItem(5, criminalButton);
roleSelector.setItem(6, glass);
roleSelector.setItem(7, glass);
roleSelector.setItem(8, glass);
return roleSelector;
}```
yeah you create a new inv everytime, so you they will never be equal
i want to make this but in a circle around the player
ok so how could i compare these?
ill try to make it in command block so you can see an example
Alright. Might not be too complicated.
So step one:
Create a method that creates a circle around the player with a certain radius and height.
did
Format it and send it again pls
but i will still create new inv
wha?
whats the easiest way to format money?
store what players have one of your inventories opened
Use a Map<Player, Inventory> or something similar to get the which player currently has an open inv
something like this right?
then remove them from the list again when they close the inv
I'd just use an ArrayList<UUID> or HashSet<UUID>
unless you still need the inventory later again
then go for a map
Depends on how you want to format it.
1230.5 -> 1.23k
4111322 -> 4.11M
Like this?
no just 100000000000 -> 100,000,000,000
DecimalFormat
I'd just use String.format
public void roleMenuEvent(InventoryClickEvent e) {
if(e.getClickedInventory() != null) {
Player player = (Player) e.getWhoClicked();
Inventory inv = e.getClickedInventory();
if(Objects.requireNonNull(Objects.requireNonNull(inv.getItem(0)).getItemMeta())
.getDisplayName().equalsIgnoreCase(ChatColor.WHITE + "Wybierz rolΔ")) {
e.setCancelled(true);
}
}
}```
lol i done sth like this
Okay so I'm sorry to bother yall but, what would you use Databases for, in what case and what are the positive/negative sides of using one in a plugin?
Pros)
- It's a database
Cons) - It's a database
particle thing
what's the problem?
Is it a good idea to use it to store information when a player joins get data, and when a player disconnects save data
the lower table should always have the current identifier of auto_increment
auto_increment will only be changed if you actually use it
but is doesnt
i am
if you manually inserted 1, 2, 3, then auto_increment is still at 1
no, it was automatic
that is not the whole table, i am only displaying the id column
I set some other value to something to test it
If the information must be readily available flatfile and loading it fully into memory might be better but a localhost connection will always be fast so no issues on that side
it does not report the current auto_increment, might that have to do with some values (not all) in the checked table being null?
what does this show?
SHOW TABLE STATUS FROM `DatabaseName` WHERE `name` LIKE 'TableName' ;
this should also show it:
SHOW CREATE TABLE `TableName`;
what do I use as "name"?
name
show this pls
couldve just asked me to show the creation sql .-.
Aren't you using RedLib
Use FormatUtils.formatMoney
Okay so, what would you guys choose, MySQL or MongoDB?
same
basically everyone has access to mysql
but only some people have access to mongodb
also "mongo" is a german insult for disabled people lol
uuuuh never heard of it. I am german xd
"Du Mongo!"
nope
weird
Is MySQL okay for loading player data when he joins and saving it when he disconnects?
never in my entire life
Okay so quick question, we're trying to modify a plug-in a friend gave us, however when we try to compile it. The console keeps asking us to add a ';' here. Any clue as to why it keeps tossing this error?
maybe it's just in NRW
Yes
well i can believe, yall are weird over there
what's above the hashcode method?
Would you mind taking a second to give me like a good course that I can follow to learn MySQL?
so i basically started making a bedwars plugin with togglable event handler but i quit because it was getting too messy. what is the best way to start going and in what direction?
What do you mean?
show the code above line 37
.-.
is there any way to remove the .00 at the end? my server doesn't go into the decimal place
just use String.format
How would I spawn an npc using nms?
Could just replaceAll("\\..+", "")
But I would keep it
Because otherwise you end up with just 1M for everything between 1 million and 1.999 million
something like this @quiet ice
how did you do that with comand block?