#development
1 messages · Page 141 of 1
i will go try this now very much appreciated man
np lol, best of luck
okay so, what is the code that i put in the other class
for what
im having not good brain moment
explain and I'll explain
send a snippet of what you currently have
or just explain it rq
bc if you're just trying to get the instance of you're plugin you just have to do Discord.getInstance()
im trying to get my .getConfig() to work in Disc class
ok
public final class Discord extends JavaPlugin {
public static Discord instance;
public static Discord getInstance() {
return instance;
}
private static Discord main;
@Override
public void onEnable() {
Discord.getInstance().getConfig() lol
okay so what i was doing wrong was not calling on discord for my .getconfig
i had the answer for most of this XD
also why do you have 2 instance variables? main and instance
I suggest learning a little bit about objects and instance methods, can prob find a 20m vid on YouTube that would explain it all, you said you were new to this so that'd prob help you
sorry about my grammar I'm horrible typing on mobile haha
Yeah I'm going to finish this little first plugin and then look up some more java basics
need some more practice or knowledge before going onto a second one
it's always nice to practice but know why things work or when something works but you don't know why that is the best time to learn
i honestly understand my other code but the instances and some of objects
but it's all part of the learning process
java is object oriented, trust me it took me forever to understand but that's because I tried learning when I was like 13 lol, I'm sure you can pick it up in a few days
I tried at 13 also but 4 years later it is so much more understandable
i wouldn't mind explaining things however it's 1am and I have to be up early tomorrow, if you want help tmr feel free to ping me and I can try to explain objects
things actually makes sense
alright i will keep it in mind if you don't mind pings, you are very knowledgable and helped alot ty v much i appreciate the help!
dad is a software engineer so he's been trying to teach me since like 10 years old but I started learning on my own like 8 months ago and omg it all makes sense
feel free to ping me whenever, pings exist for a reason haha
some perfer not to but i will if im needing help!
probably will take a break for a while tomorrow been at this plugin for about 7 hours
how i can cancel a runnable?
cancel();
.cancel();*
If you're in the scope of the runnable it's just cancel
im creating a crafting api and this dosnt work
can someone understand why?
public boolean canCraft(PlayerInventory playerInventory) {
boolean canCraft = true;
for(CraftItem craftItem : craftItems) {
if(!playerInventory.containsAtLeast(craftItem.getItem(), craftItem.getAmount())) {
canCraft = false;
}
}
return canCraft;
}```
public class CraftItem {
public ItemStack item;
public int amount;
public CraftItem(ItemStack item) {
this.item = item;
}
public CraftItem(ItemStack item, int amount) {
this.item = item;
this.amount = amount;
}
public int getAmount() {
return amount;
}
public ItemStack getItem() {
return item;
}
}```
how do you use it?
Am I missing something or why would this not delete the world file?
(The world path is correct, it's also unloaded, and no it's not the main world)
final File worldFolder = new File(Bukkit.getServer().getWorldContainer().getPath() + "/" + it.getName());
final boolean result = worldFolder.delete();
for(GameRecipe gameRecipe : Main.getAllRecipes()) {
if(gameRecipe.getCraftedItem().getItemMeta().getDisplayName().equalsIgnoreCase(itemStack.getItemMeta().getDisplayName())) {
if(gameRecipe.canCraft(player.getInventory())) {
player.getInventory().addItem(gameRecipe.getCraftedItem());
for(CraftItem craftItem : gameRecipe.craftItems) {
ItemStack itemStack1 = craftItem.getItem();
itemStack1.setAmount(craftItem.getAmount());
player.getInventory().removeItem(itemStack1);
player.sendMessage(ChatColor.GOLD + "Crafted: " + gameRecipe.getCraftedItem());
}
return;
}
}
}```
Ohhh I didn’t see the getConfigurationSection, thank you!
@abstract marlin So, when the sign is created, save its lines somewhere and then get those lines, replace everything you need, and set them on the sign without updating them on your storage.
when using the "EntityDamageByEntityEvent" event, how can i get the item that was attacked with?
Attacker#getInventory#getItemInMainHand ?
how i can update an actionbar?
thats what i am using right now, just wanted to know if there was a better way
No, is not
Send a new one
new BukkitRunnable() {
@Override
public void run() {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
}
}.runTaskTimer(plugin, 20, 20);
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));```i tried this, but dont works 😦
String message;
new BukkitRunnable() {
@Override
public void run() {
message = "&cTe quedan un total de &4&l" + plugin.getCounter().getLives(player) + "&c vidas";
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
}
}.runTaskTimer(plugin, 20, 20);
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));```
i tried this but dont works too xd
I get an error when reassigning the string value
void runTaskTimer(@NotNull Plugin plugin, @NotNull Consumer task, long delay, long period)
throws IllegalArgumentException, IllegalArgumentException```
Returns a task that will repeatedly run until cancelled, starting after the specified number of server ticks.
plugin - the reference to the plugin scheduling task
task - the task to be run
delay - the ticks to wait before running the task
period - the ticks to wait between runs
IllegalArgumentException - if plugin is null
IllegalArgumentException - if task is null
set the delay to 0, and you can remove the second player.spigot().sendMessage
Hey I wrote that code that stops a server if there is no player online for 60 seconds. But I don't get why the server does not stop after 60 seconds when the player rejoined and then left again. I hope someone can help me.
Thread waitTillStop=new Thread(() -> {
try{
sleep(60000);
}catch (InterruptedException e){
throw new RuntimeException(e);
}
if(Bukkit.getOnlinePlayers().size()<1){
Bukkit.shutdown();
}
});
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event){
if(Bukkit.getOnlinePlayers().size()<=1){
waitTillStop.start();
}
}
dont use thread sleep, just schedule a bukkit runnable to run after 60 * 20 ticks
It still doesn't work
for (Player player : Bukkit.getOnlinePlayers()) {
String replacedPlayerCount = PlaceholderAPI.setPlaceholders(player, "%bungee_" + tpSign.getTargetServer() + "%");
if (tpSign.getLines().length == 0) return;
if (tpSign.getLines().length == 1) {
sign.setLine(0, tpSign.getLines()[0].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 2){
sign.setLine(1, tpSign.getLines()[1].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 3){
sign.setLine(2, tpSign.getLines()[2].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 4){
sign.setLine(3, tpSign.getLines()[3].replace("{player_count}", replacedPlayerCount));
}
sign.update();
}```
TpSign is a class which countains Location blocLocation, String TargetServer and String[] lines
I told you, remove the forLoop, bungeecord placeholders are player independent
when set to null it doesn't work at all
i save the lines of that sign when it's created as a TpSign and whenever it's edited
hmm looks like the method doens't use the OfflinePlayer at all
you know that return exits the method, right?
Signs:
'30':
sign_location: world -10 72 202
id: '30'
target_server: lobby
lines:
- '{player_count}/5'
- test be like
- ''
- ''
yea ...
Alright, show your full code
on Enable
Common.runTimer(20, () -> {
final File file = FileUtil.getFile("signs.yml");
if (!file.exists()) return;
final SimpleYaml config = FileUtil.loadConfigurationStrict(file);
if (config.getConfigurationSection("Signs") == null || config.getConfigurationSection("Signs").getKeys(false) == null) return;
config.getConfigurationSection("Signs").getKeys(false).forEach(s -> {
final TpSign tpSign = TpSign.getSign(s);
if (!(tpSign.getSignLocation().getWorld().getBlockAt(tpSign.getSignLocation()).getState() instanceof Sign))
return;
Sign sign = (Sign) tpSign.getSignLocation().getWorld().getBlockAt(tpSign.getSignLocation()).getState();
String replacedPlayerCount = PlaceholderAPI.setPlaceholders(null, "%bungee_" + tpSign.getTargetServer() + "%");
if (tpSign.getLines().length == 0) return;
if (tpSign.getLines().length == 1) {
sign.setLine(0, tpSign.getLines()[0].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 2){
sign.setLine(1, tpSign.getLines()[1].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 3){
sign.setLine(2, tpSign.getLines()[2].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 4){
sign.setLine(3, tpSign.getLines()[3].replace("{player_count}", replacedPlayerCount));
}
sign.update();
});
});
should i use pastebin or use these embed kina things?
if (tpSign.getLines().length == 1) {
sign.setLine(0, tpSign.getLines()[0].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 2){
sign.setLine(1, tpSign.getLines()[1].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 3){
sign.setLine(2, tpSign.getLines()[2].replace("{player_count}", replacedPlayerCount));
}else if (tpSign.getLines().length == 4){
sign.setLine(3, tpSign.getLines()[3].replace("{player_count}", replacedPlayerCount));
}```
use a `for (int i = 0; i < tpSign.getLines().length; i++)`, this way all lines will be set, not only the last one
oh yea i m dumb i just noticed that
I'm not sure how return behave on a forEach loop, so I suggest to either replace it with a normal for loop or to find out
return will exist the whole method ie onEnable i guess to stop the for loop there was a method like break or something i also forgot
okay imma test it out .. thanks alot for helping this much @dense drift ❤️
alright so it acts like a continue
Well do some checks, see if it can find a TpSign by that name, if there is a sign at that location
Does anyone know what could be causing Jedis IO locks
yea ❤️ thanks
Np
well, generally you usually need at least 2 connections with redis (for pub sub), one for receiving and one for publishing, idk exactly what you're doing but you ought to use a JedisPool instance (since normal Jedis instances will be blocking)
EDIT: also why you might wanna favor lettuce or redisson as they have concurrent designs for you as opposed to jedis where you almost kind of have to do that step yourself
Cool, thanks for your help!
Thank you for your help. I changed what you said but I still have the same problem. Could not pass event PlayerQuitEvent to plugin v1.0.
Thats just the default message telling you on what event is an exception, send the error.
And the code?
you're not initalizing shut anywhere
because you're using it and I assume you don't want it to be null?
It doesnt
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if (!(commandSender instanceof Player)) {
Msg.send(commandSender, "&cOnly players can use this command.");
return true;
}
//checks if player has permission if not, send message, if does, sends a different message
if (!(commandSender.hasPermission("discord.discord") )){
Msg.send(commandSender, "&cYou do not have access to this command.");
return true;
} else {
//send message to player from config.yml
Msg.send(commandSender, link);
}
Player player = (Player) commandSender;
return true;
}
how would one make an argument to this, replacing
String[] strings with String[] args makes the command not work so
The name of the argumente on method definition doesnt matter.
if (args.length == 0){
Discord.getInstance().reloadConfig();
this what is not working
args returning red
cannot resolve symobl
the if statement is very bland with it just check length not for specific word i know
because args doesn't exist I presume
Yeah but is there a different way to state it to work?
Do you have String[] string or String[] args on your method?
string [] strings because it won
wont work the otherwise
command makes exception without strings there
That is the issue, you are trying to use args, but the parameter is named strings
Anyway to get around this maybe? Sorry lol
If you define it as strings, then use strings.
so my if statement would change to
if (strings.length==0)
yes
bro it's the littlest things this is aggrovating xD, tysm much appreciated for your time!
Not to rag too much, but issues like this would probably be resolved faster and smoother if you learned java before jumping into plugins.
you've ragged your last rag
Oh shit
na im jp, I'm watching java basics videos, just a lot more fun to code plugins
as projects
No worries just thought I'd toss it out there to save some headache in the future.
Oh you are 100% right so ty
Just use this.
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
And yes this will work
Sure
Turns out there is a client server desync with the player's offhand when attempting to put an item in it and the action has been cancelled.
on the clientside in survival the item shows up in the player's offhand but its visual only. in creative the item is put in the player's offhand and its not a ghost item.
such fun
not sure if its been fixed in 1.19 but its there in 1.18.2
don't bother with creative mode, it's a cesspool of inventory-related bypasses, both the server and the client make many assumptions when the player is in creative
im more bothered about the item showing up in the offhand as a ghost item tbh
you can try sending an inventory update, don't know if that works for offhand stuff
err Player#updateInventory?
tried both as regular and in a task and neither made a difference
-_- ig ill deal with it, glad that it wasnt an issue with my code atleast it was just a ghost block
kinda scared me cus i tried many times to cancel the event when it was that action and the item kept coming back
ive have other desyncs with the offhand
stupid
ig ill deal with it fornow, not crucial for the plugin to work, just irritating.
anyways, i got my crafting gui plugin to work, while fixing some issues with clicking the output slot and it deleting the items.
and they should all be fixed™️.
Quite a difficult question which I need help going through.
So currently I'm working with chunks but I want to get an array of chunks.
This array will have chunks which are in a 3x3 in the actual mc world.
For Example: Array[(-1,1), (0,1), (1,1)] and so on. It should end up in a 3x3 chunk square.
- I will need this to be a function that can be used multiple times and get a new set of 3x3 chunks that haven't been used beforehand
Now I'm sort of new to chunks, I know how they are arranged but I just can't get the idea in my head of how to grab all of these chunks in an array. Can anyone help?
Does someone know which repository or dependency slf4j logger is located?
I've always just imported it without adding anything, but can't now for some reason
Is there a way to know either:
- How many hearts of damage
Player#damageactually will do (as protection cancels some of it out) - or how to prevent protection from affecting
Player#damage?
Atm the workaround is to just do Player#damage and then after that, do Player#setHealth, but the issue is that damage indicator plugins would show an incorrect value (since it only detects Player#damage)
Oh wait I can just do Player#damage(0.0) and then call EntityDamageEvent 🤔 (and Player#setHealth)
you could so some math
idk the protection formula but you can get the prot level the player has and then do the math with the damage you want to do
but then I'd have to invert that to find the damage I'd need to put in the parameter 🥴
Atm I'm just doing 0.1 damage and calling a fake event (then doing #setDamage)
Same for me
https://www.browserling.com/tools/all-hashes <- alternative
Uhh didn't know mc resourcepacks used hashes but hashes aren't related to minecraft, so yes it will (as long as you use the correct one)
Don't know which algorithm mc uses
oh does it use SHA1?
ah then this will work
👍
right click strings, refactor, and name it args
well thats the only thing I can think of
that or doing some hacky stuff
"".split("-") returned an array with length 0 or 1? xd
Size would be dependent on how many splittable chars are available
1
or more
it will never be 0

does this fix my command throwing an error?
whenever i change it to args
here wait lemme test it and show you
you're skipping one somewhere and refactoring it will change all occurrences
I think i had another problem yesteryday
ohhhh gotcha
i definitely was missing one
send the error message as well as the code that threw the error
if it throws error this time im testing it
no it was my atttempt at a reload command that threw it
it worked just fine with refactor
I couldn't ever figure out how to put the if statement into my command for the reload
couldn't think it through
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!(commandSender instanceof Player)) {
Msg.send(commandSender, "&cOnly players can use this command.");
return true;
}
//checks if player has permission if not, send message, if does, sends a different message
if (!(commandSender.hasPermission("discord.discord"))) {
Msg.send(commandSender, "&cYou do not have access to this command.");
return true;
} else {
//send message to player from config.yml
Msg.send(commandSender, link);
}
Player player = (Player) commandSender;
return true;
}
}
the comments are to double check i know im writing
and a habit im starting lol
can you put a comment on what's given to error, I'm on mobile so it's more tricky to view
oh lol
I couldn't quite wrap my head around it
reload as in?
oh
you can wait if you are going to be back at your computer at some point
did you get it or still no
no I couldn't get it to work
I'm in bed lol, have to be up early
oh gotcha it's fine dont worry about it xD
so is there a way you can guide me without fully teling me?
you can dm me also so we dont spam this chat
with my dumb questions
if args[0].equalsIgnoreCase("reload")
that's you're if, also check if args.length > 0
check length first
and then just do Main.getInstance().reloadConfig()
yeah I have that stuff
and what's the error
It's like the positioning of it
in my command executor
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!(commandSender instanceof Player)) {
Msg.send(commandSender, "&cOnly players can use this command.");
return true;
}
//checks if player has permission if not, send message, if does, sends a different message
if (!(commandSender.hasPermission("discord.discord"))) {
Msg.send(commandSender, "&cYou do not have access to this command.");
return true;
} else {
//send message to player from config.yml
Msg.send(commandSender, link);
}
Player player = (Player) commandSender;
return true;
}
}
like how to put it where
try to avoid else statements and use the return at the end of an if statement
delete your only else case and put a return at the end of the if above and put the code at the bottom, after getting the player. it doesn't really matter where but it will work at the bottom
if that's not the issue , try to do it with your thought process and send me the "wrong" code and I'll try my best to explain how to fix it
if not I'll respond when I wake up
LivingEntity#getEquipment returns a nullable component, when exactly would this be null, since I presume an entity will always have an inventory
Probably because some entities simply cant hold items, such as Bees
You're welcome!
your'e*
yesn't
Does anyone have a good example to parse expressions in a String?
I would like to make a plugin that allows to define conditions like {playerVersion} > {proxyVersion} to then evaluate and see if it's valid.
Right now would I like to have the following conditions supported:
x < y- Check if X is less than Yx <= y- Check if X is less than or equal to Yx > y- Check if X is larger than Yx >= y- Check if X is larger than or equal to Yx = y- Check if X is equal to Y (Should also allow string comparison)x != y- Check if X is not equal to Y (Should also allow string comparison)
Currently have this mess of a setup right now: https://paste.helpch.at/ipoqitolul.java
x.toInt() < y.toInt()
can someone send me a good tut for changing blocks with packets? i cant find a solution online
@loud sorrel what exactly do you want to do
the is a method on the player to send a packet to change a bunch of blocks
i want to change one block for the player w nms
don't use nms
You could throw an exception if type is null/invalid @somber gale
Edit: nvm, I see you have a check in there
i want to only do it for specific people tho
either use the method on the player to change it on the client or use protocol lib
how would i do it w packets tho
idk the method name but its like player#changeBlockOnClient(Location, BlockData), the method name is wrong and I can't check it but it takes in a location and block data
and it will send the packet
actually, i changed it a bit. how would i edit the furnace contents w packets instead
you can probably get the block data from a furnace and send it to the player, I'm not 100% sure on how you'd do exactly what you want
it doesnt exist
pretty much lmao
let me check for it
I'm on mobile the method is named different to what I said but it takes q location and block data
I haven't used it much so I don't remember the name
yeah let me check
declaration: package: org.bukkit.entity, interface: Player
d;spigot Player#sendBlockChange
void sendBlockChange(@NotNull Location loc, @NotNull BlockData block)```
Send a block change. This fakes a block change packet for a user at a certain location. This will not actually change the world in any way.
loc - The location of the changed block
block - The new block
there ya go
Im trying to make a class instance based on a string like this: Class<?> cls = Class.forName(args[0]); Mineral mineral = (Mineral) cls.newInstance(); MiningManager.spawnMineral(mineral); but the thing is that when I create new instance I cant pass the parameters of the constructor, any idea?
I believe you have to get the constructor and use that. Class#getConstructor
d;jdk Class#getConstructor
public Constructor<T> getConstructor(Class... parameterTypes)
throws SecurityException, NoSuchMethodException```
Returns a Constructor object that reflects the specified public constructor of the class represented by this Class object. The parameterTypes parameter is an array of Class objects that identify the constructor's formal parameter types, in declared order. If this Class object represents an inner class declared in a non-static context, the formal parameter types include the explicit enclosing instance as the first parameter.
The constructor to reflect is the public constructor of the class represented by this Class object whose formal parameter types match those specified by parameterTypes.
1.1
parameterTypes - the parameter array
SecurityException - If a security manager, s, is present and the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of s.checkPackageAccess() denies access to the package of this class.
NoSuchMethodException - if a matching method is not found.
the Constructor object of the public constructor that matches the specified parameterTypes
there we go. I forgot what the command was
d;jdk constructor#instance
public T newInstance(Object... initargs)
throws InstantiationException, InvocationTargetException, IllegalAccessException, IllegalArgumentException, ExceptionInInitializerError```
Uses the constructor represented by this Constructor object to create and initialize a new instance of the constructor's declaring class, with the specified initialization parameters. Individual parameters are automatically unwrapped to match primitive formal parameters, and both primitive and reference parameters are subject to method invocation conversions as necessary.
If the number of formal parameters required by the underlying constructor is 0, the supplied initargs array may be of length 0 or null.
If the constructor's declaring class is an inner class in a non-static context, the first argument to the constructor needs to be the enclosing instance; see section 15.9.3 of The Java Language Specification.
If the required access and argument checks succeed and the instantiation will proceed, the constructor's declaring class is initialized if it has...
This description has been shortened as it was too long.
initargs - array of objects to be passed as arguments to the constructor call; values of primitive types are wrapped in a wrapper object of the appropriate type (e.g. a float in a Float)
InstantiationException - if the class that declares the underlying constructor represents an abstract class.
InvocationTargetException - if the underlying constructor throws an exception.
IllegalAccessException - if this Constructor object is enforcing Java language access control and the underlying constructor is inaccessible.
IllegalArgumentException - if the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion; if this constructor pertains to an enum class.
ExceptionInInitializerError - if the initialization provoked by this method fails.
a new object created by calling the constructor this object represents
Get the constructor and then pass your arguments to Constructor#newInstance
mmm ok
i try thanks
Like this? Class<?> cls = Class.forName(args[0]); Constructor<?> constructor = cls.getConstructors()[0]; Mineral mineral = (Mineral) constructor.newInstance(player.getLocation(),MineralType.MINERAL, true); MiningManager.spawnMineral(mineral);
No
damn
cls.getConstructor(Location.claas, MineralType.class, Boolean.class)
wait is it static?
or you mean cls..getConstructor(Location.claas, MineralType.class, Boolean.class)
cls*
but the whole thing is ok right?
More or less
net.minecraft.network.chat.TextComponent is apparent now gone in 1.19, does anyone know what the new alternative is?
thank you!
anyone know why this happens? https://github.com/srnyx/Server-Expansion/issues/1
either your server does a lot of reading from the disk/loading data/cpu intensive calculations and that number is accurate, or whatever is computing the mspt is averaging like say the mspt of 100 ticks, if it doesnt have the data from 100 ticks it could give an incorrect result, it is most likely the first option tho as it is hard to miscalculate mspt
when i do /papi reload it goes back down tho
wdym? the server expansion does
i just restarted the server: https://srnyx.likes.cash/java_JRBWnWAoTB.mp4
There is no time to wait! Ask your question @restive crypt!
It happens that I am wanting to put in the BelowName the placeholder of the Tag of the "DeluxeTags" plugin but it does not work for me, it does not appear or anything like that, do the placeholders not work for this place or what?
i have no idea what papi does internally but i can give you my best guess
when you reload it, it flushes all its cache and it has to first go and read all the jar expansion files from disk then it has to actually load that code which can take a little bit of time which gives a large mspt
the high mspt isnt from reloading its just like that when the server starts
im not saying its your code im guessing its papi since it completely reloads itself
it goes back to normal when papi is reloaded
wait
so its bad until you reload papi and then it fixes itself?
are you sure mspt is being reported correctly?
no
https://www.spigotmc.org/resources/tabtps-1-8-8-1-19-show-tps-mspt-and-more-in-the-tab-menu.82528/
i recommend using that and check your mspt against its numbers
if the mspt was that high im 99% sure that the tps wouldve gone down too
yeah so it is most likely calculated wrong, i dont have experience with papi but is your own code calculating it or is it something else?
i didnt write the mspt thing btw, someone else wrote it and i just made my fork to change other things
can you show me where it is being calculated
i think its here
i got my plugin to work fully, configured message and reload it ingame, project 1 done
what you said was correct
personally i dont like how it is written, thats just my opinion tho its hard to follow. id suggest check tabtps first to verify your numbers and if you want i can make a way to track mspt if yours isnt working
ayy lets go, good job!
...
personally i dont like how it is written, thats just my opinion tho its hard to follow.
yea i dont rly understand it either
ok i did /mspt and the 1 minute values are: 4.5/0.7/193.4 (avg/min/max)
the placeholder is showing 238, and even after the 1 minute values from /mspt go to 3/2/15, it still shows 238
are you using tabtps?
essentials
are you using the paper api or spigot api
paper
I'm not really sure if this is the way to do it lol. Basically I coded a program which basically hosts an API server that accept requests and respond with a JSON. The only issue is keeping it alive. Currently, I use an infinite loop: https://github.com/MinecraftMediaLibrary/youtube-dl-rest-server/blob/2988c396b73f3af9becfa5eea5a4d108c1d7cc93/src/main/java/io/github/pulsebeat02/RestServer.java#L16
Is that the proper way to keep it alive? The thing is that if I don't add the while loop, the program just ends and the server won't be there.
And it works lol
i havent tested it but in theory it should work
to not spam the channel I uploaded it to GitHub https://github.com/Sammster10/Java-Utils/blob/main/minecraftUtils/TickUtils.java
hopefully it us simple enough to use lol
I wonder if there's a good library for such stuff...
I've also altered my aproach... Not sure if this is better...
err are you making a plugin of your own? or configuring a server/plugins? because for the latter then #general-plugins/#general-plugins-2 is where you should be asking
yeah that's okay - though usually you want to have something like
final var reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
while (!reader.readLine().equals("joe mama"));
or some other shutdown signal from elsewhere instead
also if Spark has any lifecycling/shutdown sequence to be performed before the program quits, do!
Oo I see
your welcome
looks like this works, ty!
altho it doesnt contain the different timings like the old method (1m, 5m, 10m), but it doesnt matter since i didnt use em
one thing i noticed is that when papi is reloaded (and i assume also when server starts), for the very slightest second (not noticeable unless ur literally watching the mspt as it reloads) it shows a huge number like 92688686942E, i just fixed this by adding a check if the mspt goes above 1,000,000 it'll just show 0
In the ProxyPingEvent, do I need to set the protocol too, if I change the Protocol name using Protocol#setName(String)?
And if I have to, would setting it to something like -1 work, or what should I set it to?
Another question: Can I obtain the player name from said ProxyPingEvent? Or would I need to do some tricky workarounds (i.e. do requests to the Mojang API or whatever)?
String getName()```
Get the requested username.
the requested username, or null if not set
shapeless recipes with stack support just dont work
the only logic step would be to sort the ingredients list by amount
I can edit it, it's because my array starts at 0s, I can edit it tho
honestly let me know what I should add and I'll do it
ima use it for myself as well so give me ideas lol
I legit created the code and left bc I had to go to practice, never tested it so that explains the issue(s)
should have the same placeholders as tps
i don't use papi I just work with the bukkit api
you'd have to create your own implementation of that
however I think that's fairly simple
i think u would need to implement the calculations tho
like 1m, 5m, 10m
oh yeah I got you
also the issue of it being a huge is number easy to fix I just thought of it
done, let me know what you think. I also changed it so it will fix MSPT being a big number at first https://github.com/Sammster10/Java-Utils/blob/main/minecraftUtils/TickUtils.java
o also there is colored placeholders
look at my fork to see what i did
wdym
also use the lastest version of the class, its on github
idk if you pushed your code or not tho
i did
your MsptUtils class is the old one
unless its a new link which i doubt
no?
i got shapeless recipes to work
oh u mean ur old one
i meant for the color
i added color to ur old one
yeah haha, id suggest using the new one i made, i also fixed a bug just now so if you switched to it get the latest one off my github
could u add colored mspt placeholders?
nvm
yeye i remembered now
@viral moth its not changing:
i just now copied the stuff over
ok try using my new one
i switched it to now actually exclude 0s and it will now affect the front of the array rather than the end so it will tract the latest second rather than the second that happened 10mins ago
wait i think its something to do with my color thing
cause its only happening with color
a low mspt is good and shouldnt be red lol
it has an E at the end
sometimes, which i will check now
ok i fixed this, it was using tps color logic
after i reload papi it shows the big numbers
but then goes back to normal
if needed i can push my code
nope it was my issue
no no the color was mine
no like i did debugging
basically the first element in the array was always > one billion
lol
bc that is the current epoc, and it got changed at the end of the tick to actually be the difference in ticks rather than the time it started
so now i just ignore the first one
use the thing i just pushed (i puched again to fix a divide by 0 issue) and then push your code and explain the issue
o
yea i already had that (intellij told me to add it)
also u left in debug msg on line 55
ss it
done
in the for loop can you add this System.out.println(mspt); under this line if (mspt == 0) continue;
and ss the console when it does a big number
actually
that might crash your server if you calling anything bigger than a few seconds
im not having that problem, youre calling the one second one right
so it happens at the start... hmm
like when you first reload it right?
or am i mistaken
yea
like just the first 1-2 seconds i think
yea first 2 seconds
try what i added
its not the best but it should fix all issues, if the tick took longer than 1mil ms, skip it
ok now its rly long decimals instead of big numbers
except only on the 2nd second
isnt there a decimal formatter
yee
is it all good now?
also i switches some stuff to use nanoseconds instead so it will give a result in ms but will track the timings more accurately
nope still long decimals
new DecimalFormat("0.00").format(mspt).substring(0, 3);
prob a better way to do it
but that should delete the extra decimals at the end
and ye the /1m was for the nano seconds to convert the result to ms lol
new DecimalFormat("0.00").format(new BigDecimal(mspt).setScale(2))
use that instead
bc for the other onw you would lose decimal points if its is over 10mspt
'BigDecimal.setScale()' called without a rounding mode argument
its no longer changing lol
its just frozen
shiii i forgot
setScale(2, RoundingMode.FLOOR))
my b
that method should be deprecated/removed imo and should require people to use setScale(num, RoundingMode.NONE)
formatting go brr
tsym for ur help sam!!
np
https://github.com/Iridium-Development/IridiumColorAPI how does this api work 
Guys does this throws an error if the string args[0] isnt found as value in EnumClass? Im still a bit confused on if they throw errors even on comparations if(EnumClass.valueOf(args[0]) != null) because it says Condition 'PlantType.valueOf(args[0]) != null' is always 'true' so means if the value doesnt exist it doesnt return null?
valueOf doesn't return null, it throws exception if it doesn't exist
d;jdk Enum#valueOf
public static T valueOf(Class enumClass, String name)
throws NullPointerException, IllegalArgumentException```
Returns the enum constant of the specified enum class with the specified name. The name must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
Note that for a particular enum class T, the implicitly declared public static T valueOf(String) method on that enum may be used instead of this method to map from a name to the corresponding enum constant. All the constants of an enum class can be obtained by calling the implicit public static T[] values() method of that class.
1.5
enumClass - the Class object of the enum class from which to return a constant
name - the name of the constant to return
NullPointerException - if enumClass or name is null
IllegalArgumentException - if the specified enum class has no constant with the specified name, or the specified class object does not represent an enum class
the enum constant of the specified enum class with the specified name
If i had a level system in which each level has his own format, would it be better to:
- "parse" the format, which means add the colors (per char) or whatever the format is, every time the placeholder is required
- parse all placeholders and save it in a map and get it from there when placeholder is required
what do you think?
(parsing the placeholder means setting the colors in each char as &a1&d0&b0 as multiple colors is an option)
how different are the "formats"
different? well 1 is plain color which is "&a"+ level or "&a" replaced in format which can be modified by owner like "{LEVEL}{SYMBOL}"
and the other can be many colors which are added every character like &a9&b9&d9 and also replaced in format "{LEVEL}{SYMBOL}"
How do I get a player's keybind for dropping items?
What for? I mean you can try to use PlayerDropItemEvent
so id separate that and just go from there for a lot of customization
what? xD
the question is should i preload formatted or doing live on placeholder required
you cant, i assuming you want to display the button like "click Q to select" in a gui but if their keybind is A i assume you want "press A to select"
Figured it out
It is possible
Can anyone tell me if my code can be shortened down or if it's good? https://pastebin.com/YJz5NUGf
what jdk version are you using for your project?
Eclispe OpenJdk 18
Sure
What new switch cases?
uses lambdas
You can use key bind text components to display it
d;adventure KeyBindComponent$Builder#keybind
@@NotNull @@Contract("_ -> this")
KeybindComponent.Builder keybind(@NotNull @NotNull String keybind)```
Sets the keybind.
4.0.0
keybind - the keybind
this builder
switch (args[0].toLowerCase()) {
case "creative", "survival", "adventure", "spectator" -> sender.sendMessage(colorize("&b&lTL &b&l &4You need to pick a player."));
default -> sender.sendMessage(colorize("&b&lTL &b&l &4You need to pick a gamemode."));
}
sender.sendMessage(colorize("&b&lTL &b&o: &4/gamemode [creative,survival,adventure,spectator] [player]"));```
```java
if (args[0].equalsIgnoreCase("creative")) {
p.setGameMode(GameMode.CREATIVE);
p.sendMessage(colorize("&b&lTL &b&o: &aYou've set your gamemode to &e&o" + p.getGameMode() + "&a."));
} else if (args[0].equalsIgnoreCase("survival")) {
p.setGameMode(GameMode.SURVIVAL);
p.sendMessage(colorize("&b&lTL &b&o: &aYou've set your gamemode to &e&o" + p.getGameMode() + "&a."));
} else if (args[0].equalsIgnoreCase("adventure")) {
p.setGameMode(GameMode.ADVENTURE);
p.sendMessage(colorize("&b&lTL &b&o: &aYou've set your gamemode to &e&o" + p.getGameMode() + "&a."));
} else if (args[0].equalsIgnoreCase("spectator")) {
p.setGameMode(GameMode.SPECTATOR);
p.sendMessage(colorize("&b&lTL &b&o: &aYou've set your gamemode to &e&o" + p.getGameMode() + "&a."));
} else {
p.sendMessage(colorize("&b&lTL &b&l &4You need to pick a gamemode."));
p.sendMessage(colorize("&b&lTL &b&o: &4/gamemode [creative,survival,adventure,spectator] [player]"));
}```
does the same thing
(that has nothing to do with lambdas)
I'm getting this error "Enhanced 'switch' blocks are not supported at language level '8'"
you need to switch your project's jdk version, let me check rq what version it is
for this line java case "creative", "survival", "adventure", "spectator" -> sender.sendMessage(colorize("&b&lTL &b&l &4You need to pick a player."));
also im changing other stuff lol, got bored so i figured i clean it up
14 I believe
Iij tells you some info about each version
would post a ss but no perms lol
Fyi, make sure you use a higher or equal version for your server
lmk if that code works, in theory it should do the same thing
kk
gonna test it rn
if you need me to explain what i changed i can
mainly i removed duplicated code and used switches over if else statements
A member of staff has requested I move your message to a paste,
Most likely because it contains a config/error/code snippet.
SO sam
/gamemode works with it telling me the gamemode
but /gamemode creative just returns that I need to specify a player
try that
delete it
For me it just says it's useless
it auto imported it
you can specify a Local when calling string#toLowerCase()
it auto specified but i deleted it
ah
anyway
now it's telling me that
an internal error
let me copy the log
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at me.darklife12345.serverplugin.commands.specialcommands.Gamemode.onCommand(Gamemode.java:42) ~[NSC-0.6.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[purpur-api-1.19-R0.1-SNAPSHOT.jar:?]
... 17 more```
i think i already know it
yeah
if (modifySelf) player = (Player) sender;
else {
player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
sender.sendMessage(colorize("&b&lTL &b&o: &4This person isn't online"));
return false;
}
}``` this is the fix
ill just send the whole code
hold up
im trying to write code without testing it more often so i can think of problems before they happen, currently im still failing but thats why i dont mind helping with this stuff lol
Well it works for the player who executes it ...
But you cannot execute it at other people
/gamemode creative <player> just makes you in creative
even if that person isn't a person or is offline
modifySelf = args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase("self"));
replace modifySelf = true with that
wait
modifySelf = args.length == 1 || args[1].equalsIgnoreCase("self");
its just a bunch of repeated stuff deleted, functionally it works the same but is just easier to read hopefully
lmk if it works
you added this line?
like
this is your code?
d;spigot Gamemode
public enum GameMode
extends Enum<GameMode>```
GameMode has 4 fields, 3 all implementations, 4 methods, and 1 extensions.
Represents the various type of game modes that HumanEntitys may have
d;spigot GameMode#valueOf
public static GameMode valueOf(String name)
throws IllegalArgumentException, NullPointerException```
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
name - the name of the enum constant to be returned.
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null
the enum constant with the specified name
Yeah I added that line
Btw, you can just do valueOf
instead of a switch statement
take the argument, make it all caps and do valueOf
true, and just catch the error
bruh
I did that in the beginning
why did u change it
I didn't
i did
oh
not him
Og code
no
I will do that for ever
why use an api
I can just copy and paste literally 3 lines of code
and boom
public String colorize(String msg) {
return ChatColor.translateAlternateColorCodes('&', msg);
}```
well whatever im not going to force you to do it
ill refactor it for him when im done lmao
https://paste.helpch.at/eninoxivih.java current code, i dont think i fixed the issue but test this
i also am now using the api directly lol
now the code is WIDE
np
you understand the version i maade right?
if you do thats great, if now i dont recommend using code you dont understand
Basically enhanced switches and a boolean
yeah thats what i changed but like looking at the code can you understand the logic
Yeah
Trying to get a players keybind for dropping items, this is what I have rn but it doesn't work Component.keybind("key.drop").keybind() I assume I have to specify the player somehow? This just returns key.drop atm
Messed up haha
it is possible, just cant get it to work
Nvm its not possible
ur right
Yes, you cant get it, but you can display it to them
ok so can someone tell me because i am either stupid or nowhere is written
when we use Bukkit#dispatchCommand and execute some command for some player
does that trigger some command event and which?
is any event ever triggered actually?
most likely, logically it should, look for an event that gets triggered before firing a command and test it, best wat to figure it out lol
So i've made some announcements by default that are a configurable string, however i want to add a timer option to these so how would I go about doing that with adddefault?
Runtasklater
Bukkit.getscheduler().runtasklater() iirc
Yes
like a value to be configured
Get time from config, convert it to ticks and viola
I'm trying to get the time in the config
in a subheading of each announcement
to make each time configurable differently
Bukkit.getScheduler().runTaskLater(this, new TimerTask() {
@Override
public void run() {
for(Player allplayers : Bukkit.getOnlinePlayers()){
gconfig.getString("Announcement1");
allplayers.sendMessage(A1);
}
}
}, 0, 20L)
im being stupid
sorry for ping also
why is this giving error
thats the arrow i believe?
Bukkit.getScheduker().runTaskLater(this, () -> {}, 0, 20L);
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
//your code
}, 0, 1);```
example
so for timer task how would the top line look, i had it just a second ago and deleted it
Bukkit.getScheduler().runTaskLater(this, new TimerTask() -> {
basically, any interface that has only one method can be replaced with a lambda, an TimerTask() is an interface, so rather than you having to make a new instance and override the method, the lambda is short hand for that
() -> [} replaces
new TimerTask() {
@Override
public void run() {
}
} ```
ohhhh
in this case yes, a lambda can take the place of any interface with one method
oh i think what i was doing wrong was closing the parentheses at the top
no
no i meant before
I was definitely closing parentheses with the lambda before
before the bottom line
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
System.out.println("hi");
}, 0, 20);```
run that code
it will print out "hi" to the console one time every 20 ticks
so get an understanding of a basic example, and then modify it to what you need
the task timer fixed it, i had runTaskLater
Bukkit.getScheduler().runTaskTimer(this, () -> {
for(Player allplayers : Bukkit.getOnlinePlayers()){
gconfig.getString("Announcement1");
allplayers.sendMessage(A1);
}
}, 0, 20L);
run task later is a different method
it only takes one number at the end, so just 20 not 0, 20
delay and ticks it says
Bukkit.getScheduler().runTaskTimer(plugin, () -> {}, how long to wait before starting the task for the first time, the time period to wait between executions of the task);
run task later doesnt repeat something every X amount of ticks, so it doesnt need the last arg
So using runTaskTimer I do need it right?
I sound stupid whenver i get into this chat xD, i swear i've learned some basics
is your goal to repeatedly do something over and over or just do something once at a later time
It's repeatedly
then you want runTaskTimer
so i do use two numbers
thank you, i will read up on that
also can you answer the question i had before lol
reply to the question so ik what youre referring to
.
have you used the config file before?
yeah I used it in the last one to configure my discord message
just simple /discord
want me to tell you the steps or do you want me to give you the completed code
Wait ill send what i have
getLogger().info("Starting up...");
if(!(folder.exists())){
folder.mkdir();
getLogger().info("Creating new directory...");
if(!(file.exists())){
try {
getLogger().info("Creating new file...");
file.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
getLogger().info("Found your config.yml...");
}
}
config.addDefault("Prefix","&7Soapzy's Timed Announcements | ");
config.addDefault("Announcement1","This is an automatic broadcast that hasn't been edited.");
config.addDefault("Announcement2","You better edit this broadcast or you a lil on the rainbow side.");
config.addDefault("Announcement3","Change the broadcast, this is a threat.");
config.options().copyDefaults();
saveDefaultConfig();
getCommand("timedannouncements").setExecutor(new TACommand());
so basic
create directory and file
and adding the messages
but i want like a subheading called timer for each announcement, 1,2,3 that they set for each one to go off in different intervals
ok for one, the default config file is safe to use, bukkit makes the dir and handles all the checks
2, i know this doesnt seem related, but do some research on maps
the config and maps use key value pairs
they both follow that same idea
alright thats all you need to tell me, ill look at it and hollar if i have a problem
I seen some stuff about maps but wasnt sure if it was right
because a key has a value but you could have a key that returns a value but the value it returns can also be a key
I don't understand this lol but my way seemed to work
learning about key-value pairs is very useful
basically just do plugin.getConfig()
bukkit makes sure the file exists
if not it makes it
if the dir doesnt exist it makes it
youre doing it twice since its being done 1 time already by default
so i can just do plugin.getConfig() instead of the whole if statement i did
yes
Anyone good enough with Configurate to know what I would need to do if I have this configuration setup?
conditions:
- type: '<'
key: 1
value: 2
- type: '>'
key: 2
value: 1
I'm fine with having to deal with a List<Map<...>> here. Just can't quite figure out what exactly I need to do to actually obtain this..
youre using bukkit's configuration api?
Anyone good enough with Configurate to know what I would need to do if I have this configuration setup?
I assume I need to use childrenList() here as that returns a List<? extends ConfigurationNode> and I could then turn it into a map...
Actually... Now that I think about it could I simplify this to a String list...
ye, idk if this is to any help but by default configurate does register a map, and list type serializer
do you think a string list is doable to set timer on a message
so lemme example real quick
Announcement1:
Time:
simple as that basically
is there any way i could modify the font that is used, and sent, when checking for a placeholder?
Trying to essentially insert a specific unicode, though they are mostly outside of the default font to avoid people being able to copy-paste them in chat.
so %bondrewd_guildmenu% will return a unicode from the default font tho the actual one i need is inside say guild font file.
Seeing as it returns just a basic string ill assume not but
24.06 02:22:54 [Server] ERROR Could not load 'plugins/original-TimedAnnouncements-1.0-SNAPSHOT.jar' in folder 'plugins'
24.06 02:22:54 [Server] INFO org.bukkit.plugin.InvalidPluginException: Unsupported API version 1.19
24.06 02:22:54 [Server] INFO at org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers.checkSupported(CraftMagicNumbers.java:375) ~[paper-1.18.2.jar:git-Paper-"072f54c"]
24.06 02:22:54 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:149) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
24.06 02:22:54 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:415) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
24.06 02:22:54 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:323) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
24.06 02:22:54 [Server] INFO at org.bukkit.craftbukkit.v1_18_R2.CraftServer.loadPlugins(CraftServer.java:418) ~[paper-1.18.2.jar:git-Paper-"072f54c"]
24.06 02:22:54 [Server] INFO at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:288) ~[paper-1.18.2.jar:git-Paper-"072f54c"]
24.06 02:22:54 [Server] INFO at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1164) ~[paper-1.18.2.jar:git-Paper-"072f54c"]
24.06 02:22:54 [Server] INFO at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:316) ~[paper-1.18.2.jar:git-Paper-"072f54c"]
24.06 02:22:54 [Server] INFO at java.lang.Thread.run(Thread.java:831) ~[?:?]
got this error but i have the spigot 1.18.2 dependecies
nvm i had the wrong version in plugin.yml lol
nvm again, got the same error except 1.18.2 wasn't supported on my 1.18.2 server lol
yeah it's just 1.16, 1.17, 1.18, 1.19 etc, excluding the patch version
wait so what's the fix
my last plugin was the same thing, however, it worked
plugin snapshot is 1.18.2 spigot and server is 1.18.2 paper
just type 1.18, not 1.18.2
ye
also is paper any different than spigot coding?
Im just curious if I might as well just use paper or not
it adds a ton more API, like mob goals, pathfinding, safe item/entity serialisation, lots of expansions around things like tags, particles, worldgen i think and other stuff, full JSON components support
it has way too many changes for me to list them all
But does it change simple code in anyway or just add
or just tell me if i might as well use it
instead of having to explain xD
it adds on top of spigot, but it adds a lot lol, you are not losing anything by targeting paper
and the majority of people run paper anyways
alright thank you
You might even say it seems unbelievable
Some might suggest it be a scam
"Too good to be true" Some say
Any good way to check if a player is already inside a GUI? Using Triumph Gui
I only want this to run if a player is not already inside the GUI
if ((event.getClick() == ClickType.DROP || event.getClick() == ClickType.CONTROL_DROP) && reward.isAllowBulkBuy()) {
bulkPurchaseGui.open(player, shop, reward);
return;
}
Hey peeps, I have a problem with my chatcolors in my plugin, using maven:
pom.xml: https://paste.helpch.at/detigeqofu.xml
When I try install/ clean install:
https://paste.helpch.at/yinalikona.css
HexUtil code:
https://paste.helpch.at/emonahatut.java
don't use that StringUtils class
Just Utils then ?
just use the normal replace method
I don't know what that is, I got the code from here like 1,5 years ago
lol
And I haven't touched coding or anything in like 1 year cuz of school
So does anyone know a Fix lemme know please
reload maven?
Can someone help me please.
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/youfi/IdeaProjects/JoyChat/src/main/java/me/reverse/joychat/utils/HexUtil.java:[4,44] package org.apache.groovy.parser.antlr4.util does not exist
[ERROR] /C:/Users/youfi/IdeaProjects/JoyChat/src/main/java/me/reverse/joychat/utils/HexUtil.java:[28,28] cannot find symbol
symbol: variable StringUtils
location: class me.reverse.joychat.utils.HexUtil
[ERROR] /C:/Users/youfi/IdeaProjects/JoyChat/src/main/java/me/reverse/joychat/utils/HexUtil.java:[48,29] cannot find symbol
symbol: variable StringUtils
location: class me.reverse.joychat.utils.HexUtil
[INFO] 3 errors
[INFO] -------------------------------------------------------------
this is the full error
HexUtil
Change the StringUtil import, I believe it should be the one from apache text class
d;spigot StringUtils
public interface Strider
extends Vehicle, Steerable```
Strider has 2 methods, 2 extensions, and 19 super interfaces.
Represents a Strider.
Strider ?
This was the old import
but this also doesn't worl
work
but the StringUtils isnt the same as StringUtil from bukkit
help
I have the repository but it still doesnt work
Add them to a list when they open gui. Remove them from the list when they close the gui
I'm using java 18 btw
HELP
WHAT
tempCost = tempCost / reward.getMultiplier();
tempCost is 10 and the multiplier is 1.001. After this runs 64 times the tempCost is still 10, can someone explain this?
Can you show the full code?
..
for(int i = 1; i <= amount; i++) {
sold+=tempCost;
tempCost = tempCost / reward.getMultiplier();
tempSellPrice = tempSellPrice / reward.getMultiplier();
}
logger.info("3: Multiplier: " + reward.getMultiplier());
logger.info("3: TempCost: " + tempCost + "TempSellPrice: " + tempSellPrice);
reward.setCost(tempCost);
reward.setSellPrice(tempSellPrice);
Send your Pom xml
Paste Services
When asking for help with a config/menu/code issue please use our paste bin:
(we prefer it over pastebin.com)
• HelpChat Paste - How To Use
Did you declare temp cost as an int? Try making it a double
Chances are it’s being rounded up
It's already a doublke
Hmm
package me.darklife12345.psp;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.HashMap;
import java.util.Map;
public class OnPlayerJoin implements Listener {
Map<String, Long> cooldown = new HashMap<>();
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (p.hasPlayedBefore()) {
Bukkit.broadcastMessage(p.getName() + " has joined again");
} else {
Bukkit.broadcastMessage(p.getName() + " hsa joined for the first time.");
cooldown.put(p.getName(), System.currentTimeMillis() / 1000 + 900);
}
}
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent e) {
Player p = (Player) e.getEntity();
Player d = (Player) e.getDamager();
if (cooldown.containsKey(p.getName())) {
if (cooldown.get(p.getName()) > System.currentTimeMillis()) {
long timeleft = (cooldown.get(p.getName()) - System.currentTimeMillis())/1000;
d.sendMessage(ChatColor.RED + "This person is protected from damage for " + ChatColor.YELLOW + timeleft + ChatColor.RED + " minutes.");
e.setCancelled(true);
}
}
}
}```
so I have this code
and I wonder why
It won't cancel damage
@untold plinth
hm
do you really believe that a number divided by 1000 can be greater than the number itself?
cooldown.put(p.getName(), System.currentTimeMillis() / 1000 + 900);
means
cooldown.put(p.getName(), 1,000,000 / 1000 + 900); = 1000 + 900 = 1900
when checking
if (cooldown.get(p.getName()) > System.currentTimeMillis()) {
it means
if (1900 > 1,000,000) {
that will probably, at least in this universe, never be true
I am not good a math ok
you dont need to be good at math to know that 1 thousend is less than 1 million
you explained it weird
so uh
replace
cooldown.put(p.getName(), System.currentTimeMillis() / 1000 + 900);
with
cooldown.put(p.getName(), System.currentTimeMillis() + 900);
kk
will won't work as desired as you'll only have 0.9 seconds of invulnerability
I need 15 minutes of it
cooldown.put(p.getName(), System.currentTimeMillis() + 15 * 60 * 1000);?
yes and no
yes, should work
no, well, try to use ( ) to make sure
even when multiplications are done first
use ( ) to dont confuse your self
cooldown.put(p.getName(), System.currentTimeMillis() + (15 * 60 * 1000));

ok gonna test it out 1 more time
What's the benefit
names can change, uuid's can't
as mentioned, its a suggestion, not benefits at all as you are not saving data
so shouldn't affect at all
but its always recommended to use uuids
oh hes not saving data
indeed, he isn't
he's using the hasPlayedBefore
no, thats not storing data
prob in cache
but still not saving data
you are using minecraft data instead, which already should track connections
so uuid should be the same, even if you change names, hasPlayedBefore should return false
however, you'll lose the invulnerability if you reconnect with a different name
who's gonna do that
it is possible (if someone actually wants too), so its just better to work with uuid's
Also what's the file in servers that store player data so I can clear it and make sure it tells me I joined for the first time?
then you are sure that it can't happen
oh yeah true
^^^^^^^^^^^^
Ok it works now but java long timeleft = (cooldown.get(p.getName()) - System.currentTimeMillis())/1000; shows up in seconds
ofc, that's what you did there
why the weird plus 900
left milliseconds time / 1000
is seconds
if you want 14m 20s
you'll have too google and find a method for that
10000
10000 what?
Divide by 10000?
??
words dont need description
a picture is worth more than a thousand words
bruh what is your actual question?
lmao
ok sir first remove the weird 900 in player join event
second in the damage event, your cooldown.get(p.getName()) > System.currentTimeMillis() check makes no sense like even 1 milli second past your join time its still gonna pass
Wut you talking about ; - ;
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (p.hasPlayedBefore()) {
Bukkit.broadcastMessage(p.getName() + " has joined again");
} else {
Bukkit.broadcastMessage(p.getName() + " hsa joined for the first time.");
cooldown.put(p.getName(), System.currentTimeMillis() + (15 * 60 * 1000));
}
}```
did you skip the whole chat where math was explained to me
900 is not 1 milliseconds
thats 900 milliseconds or 0.9 seconds
wouldnt work either, but its not 1 millisecond
it works now
I suppose you want to make players have a certain spawn protection
so you first in on player join put cooldown.put(p.getName(), System.currentTimeMillis()); (keep everything in miliseconds for sanity)
and then in damage event, you want to calculate the timeleft by this:
long timeLeftInSeconds = (cooldown.get(p.getName())-System.currentTimeMillis())/1000;
and the check:
if(timeLeftInSeconds > 420){
event.setCancelled(true);
}
ok duh
yes and it works
I already have the working code
ok

?
package me.darklife12345.psp;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import java.util.HashMap;
import java.util.Map;
public class OnPlayerJoin implements Listener {
Map<String, Long> cooldown = new HashMap<>();
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (p.hasPlayedBefore()) {
Bukkit.broadcastMessage(p.getName() + " has joined again");
} else {
Bukkit.broadcastMessage(p.getName() + " hsa joined for the first time.");
cooldown.put(p.getName(), System.currentTimeMillis() + (15 * 60 * 1000));
}
}
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent e) {
Player p = (Player) e.getEntity();
Player d = (Player) e.getDamager();
if (cooldown.containsKey(p.getName())) {
if (cooldown.get(p.getName()) > System.currentTimeMillis()) {
long timeleft = (cooldown.get(p.getName()) - System.currentTimeMillis())/1000;
d.sendMessage(ChatColor.RED + "This person is protected from damage for " + ChatColor.YELLOW + timeleft / 60 + ChatColor.RED + " minutes.");
e.setCancelled(true);
}
}
}
}
bro why are you posting your whole class every time
just put what you changed or something
I was showing deleted user that I already have the code
but we know it does xd
and he's tryna explain something that is invalid
because he wants to do his famous thing
after posting the random large snippet hes gonna go
😮 Combat Protection
dont get me wrong thats just cute
i dont get whast your point here
he's mad at me
because he posted something like "do you get it now" earlier and I said no
thats cool i didnt say anything bad?
and personally i spammed clip for my first plugin code
ok im sorry
ok
but your pfp makes people's day worse by making them break NNN
turn on compact mode
wat dat
discorsd
oh alr that makes sense
https://imgur.com/a/Q8KM86J
Instructions unclear
nuked my pc instead
How would I add a message at the end of the cooldown
you can't
with your current code
you have to "heavily" modify it
and save a bukkit task instead (prob)
; -;
your code is simple, thats what it does
but what you just asked for is a bit more complex (for starters)
as it requires to modify his code (a lot)
it's my code though
ik
his code
you need to make a runnable/task

