If I have a file for a specific command and I set in the main that the executor of that command is that file so it wouldn't matter if I check inside the file if the command is the command I wanted, right?
like now I have a check in the start of the file that checks what command was run but I don't think I need it because the executor is for only one command
#help-development
1 messages · Page 2130 of 1
don’t use Objects.requireNonNull
Hi! How can i get the percentage equal to a max and a number? Like i have max 100 and i have 10 as the inputted number, obviously the percentage it should return is 10 but sadly i don't remember the math formula behind this
that’ll just throw an exception if it is null
FDIPOAJDOIASJDOIASJDOIASJHDOIASDHA
yes
i roared wtf
LMAO
TagParser
it's just the number inputted divided by the whole..
(input / max num) * 100
this
if the max is 100
and you'll need to multiply it by 100 like deotime said if you want it to display as a percentage. mb
ty
but yeah it's not complicated math lol
yeah i've already fixed that but thanks to both
ik but i always forget the formula
- your event might not be registered
- use event.getWhoClicked is always going to be a player so dont check it
- if the clicked inventory is null itll cause an exception
- if the item on the cursor is null itll cause an exception
possible to make an arrow not hit any entities and just make it phase thru them?
also you're checking the item on the players cursor
not the actual item they clicked
Is it possible to make a projectile invisible without ProtocoLib, and if so, how?
send an entity destroy packet
A what sorry? I've never really dealt with packets
You aren't the first one
I made a basic tutorial on spigot
Should help you get to your answer
Ok, thank you :>
about the entity destroy packet specifically, it tells the client that receives it that the entity no longer exists
so basically the client forgets about the entity, as if it was killed, logged off, etc
spigot will still be aware of it however, and will cause the projectile to still work
Ahh, I see. That makes sense
I looked on google how to make custom enchants and they told me to do a custom lore, so it would work by checking the lore of the item, and checking if it contains the custom enchantment then doing the effect if true right ?
Yes
that seems fair, but how do i add it into an enchant table afterward ?
in some code there's so much bad stuf that i dont want to respond
best way is to just add your own enchants makes all the enchantment table stuff so much easier
you can make your own enchantment wrapper
Hold up I have a video
it goes over how to make your own enchantment wrapper idk how good the guy is at java its been a while since I touched a custom enchant wrapper
https://www.youtube.com/watch?v=wd1FUOT-BJY I'm not sure how good these guys practices are but I recall this being the video
Learn how to create Custom enchants for Minecraft :)! I will "attempt" to teach y'all how to register custom enchants as Minecraft enchants! Hope y'all enjoy the video :D
----- Support me & more -----
Patreon:
https://www.patreon.com/codedred
Donate to me :)
https://www.paypal.me/CGMax
Join my discord:
https://discord.gg/zMzXSgk
------ Li...
oh lol cope
what do i do ethuethoeqjej
thanks lmfao
and the lang file is what shows the actual enchantment name on the client
so the only way would be to have a resource pack that replaces some useless enchantments with what u want
idk when custom resource packs were introduced but you could prob force a resource pack for that
hold up
custom enchants with lore and a command to add the custom enchants
would that work ?
Yeah
why does it say that there is not such thing as SelectionScreen. was the name changed because my tutorial is old?
okay thanks a lot yall
if it says theres no such thing
take the hint
nice
following youtube tutorials the greatest evil there can be
I've tried you learn nothing lmfao
i get what you're trying to say but they're not all bad
to start with they aren't bad
but you might get stuck into a tutorial hell
where you can't do anything without them
or without a support discord
by the constant learn java harassment I recieved here I stopped asking for help and learned the greatest lesson
java
I learned with spigot API which was extra awful but it kept me interested at least
why it does not see my dependency
well you have spaces in the group id
and double check it's a part of maven central
yeah find otu what repository that's a part of @kindred valley because that groupId isn't in maven central
well you're not checking if the command is equal to the input cmd
im not familiar to maven can u explain like your explaing to a dump
that wasn't the problem
if(cmd.getName().equalsIgnoreCase("wands"))
he wouldn't need to do that if he's setting hte comand excecutor
really
have I been doing that for nothing ?
yes
I have a file for each command so I don't need to check this
well me too and i'm still checking it lmfao
how would i open a gui on right click on a custom entity ? (citizen npc)
does citizens not fire a interact entity event
idrk never used it, you could also listen for the packet kekw
believe it has a "NPC" metadata or something
then yeah just do that
well i think citizens makes it persistent
nah only if the entity is despawned
use an event to check if the player is right clicking and check if the player is right clicking this specific entity
they probably just re-add it on the start
if the server restarts the entity is respawned to my knowledge so the metadata is set again
yea
Am I dumb
dont know
they have an entire api on their wiki
IDK are you?
then yes ur dumb go read the wiki
lol
this me
It says I have to use maven
well except thats a panda and I'm clearly a polar bear
if you're not already using a dependency manager then stop being not smart
if you're using gradle that's fine
as for needing to use a dependency manager, not really, but do it?
i'm using eclipse 😅
yes.. that's fine lol
maven is a dependency manager, you can use it in literally anything
even notepad++, though there's no native support
"or Gradle for experts," well that's rude
I have no idea what maven is
i just started eclipse and built my plugin
Do I need to restart the whole java project to implement maven ?
no
do you have a domain
don't make your groupid that nonsense, the tutorial says it's fine but it really isnt
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens-main</artifactId>
<version>VERSION</version>
<type>jar</type>
<scope>provided</scope>
</dependency>```this ?
if you don't have a domain, make it like me.frenchkiwi or something, or if you plan on having a domain, reverse that so frenchkiwi.com becomes com.frenchkiwi
no that part is fine, leave that, we're setting up maven for your project
I have some domain names but do I need to create them in cloudflare to use maven ?
I get an error null in the console for a command that just returns an Inventory variable and nothing else but I don't understand why.
import com.ytg667.myplugin.items.ItemManager;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class Wands implements InventoryHolder {
private Inventory inv;
public void wands() {
inv = Bukkit.createInventory(this, 9, "pick a magical wand");
init();
}
private void init(){
ItemStack fireWand = ItemManager.fireWand;
ItemStack dragonWand = ItemManager.dragonWand;
ItemStack lightningWand = ItemManager.lightningWand;
inv.addItem(fireWand);
inv.addItem(dragonWand);
inv.addItem(lightningWand);
}
@NotNull
@Override
public Inventory getInventory() {
return inv;
}
}
``` this is the Inventory
so I can use anything ?
if you have a domain that you plan on putting a portfolio on or something, reverse that domain and put it there
i dont know where to get help for this
why is this throwing an exception on my client when decoding the tag?
(source: https://github.com/orbyfied/carbon/blob/master/carbon-util/src/main/java/net/orbyfied/carbon/util/nbt/CompoundObjectTag.java)
all im doing is populating a CompoundTag and then writing it indirectly (for reading i just read a compound tag) i use CompoundTag.TAG_COMPOUND as type id so i dont understand why this is throwing an exception
the null is from getInventory()
Well i may will but what's the link between a java project and my portfolio ?
there's no link, it's just standard maven convention
the idea is to let people know immediately who the project is by
for example, my groupid is me.schooltests, because I own schooltests.me
this Inventory file is called inside my command which is called in the main file
and the plugin.yml
and that's where my website will be hosted, rn it's just linked to a VPS I use
This is the groupID right ?
yes
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class Wands implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
System.out.println("You must be player to execute this command!");
return true;
}
Player player = (Player) sender;
com.ytg667.myplugin.inventories.Wands gui = new com.ytg667.myplugin.inventories.Wands();
player.openInventory(gui.getInventory());
player.sendMessage(ChatColor.GREEN + "Please make a selection");
return true;
}
}
``` this is the command
wdym
well do you plan on putting an actual website there for professional use lol
Well I plan on making this website a portfolio website with all my random projects on it
KiwiPvp
make the artifactid kiwipvp then
It was there already
was it lowercase
no
I don't understand what the problem is
no
send a pic of what you're looking at rn
ight what's the current version of your plugin
it's the pre alpha v0
lmao
thsoe settings are fine, just hit create
that's fine
oh so I just need it to return wands() and not inv
what do i do next ?
spigot-1.8.8-R0.1-SNAPSHOT-latest
what
@eternal night what do you want
caught you
hehehe
so you just put this.inv instead of just inv? how would that make a difference?
send me the citizens website you're on @trail oriole
so your code is exactly like mine
Citizens has an extensive API for working with NPCs. Make sure you always are using an up-to-date build of the CitizensAPI to ensure that your plugin works with the latest release of Citizens.
oh
I know what a constructor is I just didn't realise because i'm used to hear it in my language
not in english
@last temple but it does work now
and I dont have a constructor
import com.ytg667.myplugin.items.ItemManager;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class Wands implements InventoryHolder {
private Inventory inv;
public Inventory wands() {
this.inv = Bukkit.createInventory(this, 9, "pick a magical wand");
init();
return inv;
}
private void init(){
ItemStack fireWand = ItemManager.fireWand;
ItemStack dragonWand = ItemManager.dragonWand;
ItemStack lightningWand = ItemManager.lightningWand;
this.inv.addItem(fireWand);
this.inv.addItem(dragonWand);
this.inv.addItem(lightningWand);
}
@NotNull
@Override
public Inventory getInventory() {
return wands();
}
}
does anyone know how to make a plugin using regions?
ok
like worldguard ?
like world edit where you use the axe and make a region
https://paste.md-5.net/giquvemuci.xml just copy paste that into pom.xml
exactly
dude
i need to learn
will you just do it lol so I can explain
i did it
all right, so basically how maven works, is that you have dependencies
@last temple thank you very much and sorry if I annoyed you a little
repositories are remote places that you can fetch dependencies from, and Spigot API is on their own repository, and Citizens API is also on their own repository
you in that, you have a repository id'ed spigot-repo and citizens-npcs, for the two different dependencies
ok
the scope is provided, meaning it'll be on the class path when the plugin is ran
i'm dead confused lmao
because spigot will load your plugin into the same place with the spigot api & citizens api, so it's all available
what part don't you get tho, so I can elaborate on it
isn't the spigot api already available from the build path ?
well that's meant to be removed
maven is a complete replacement for whatever you've been doing before
how you've been building plugins is far from recommended
100%
yikes, what is that error
Missing artifact net.citizensnpcs:citizens-main:jar:2.0.29-b2544
all right, change the b2544 with SNAPSHOT
another question. How do I make a scoreboard, that I can change the score of the thing on the board
see if that works
I just hoped the build number was apart of the maven version but ig it's just SNAPSHOT
fixed
so like if I have "team 1: 0" I could easily change it to "team 1: 1"
ok neat, remove the spigot jar from the eclipse build path
ok
what's the error ;-;
go into your plugin class
it's probably a source code error
look in the entire branch, there's probably that error X somewhere else too
yikes why are your classes lowercase
what
classes are meant to be named LikeThis not likeThis
because it's convention
lmao
no
what am i supposed to do her
ight then refactor change that to fr.purpleyounoob.kiwipvp
to check if its empty
ideally package & maven groupid are the same
Does the Tablist support ChatColor using setPlayerListHeader?
oh i can just remove the item != null part
as for the error, hover over KiwiPvp that shows the error X and see if anything pops up
Can I Increase damage of player without event?
i don't think so
how do I execute a command from 1 file in another file?
well you can execute a command from a player
I want a command from my plugin to be executes in an event
But executed by a player or the console ?
player
oh wait
nvm
i'll just copy the command itself
well the plugin seems to work anyway so idrc, I have a last question
any future api I want to use from plugins, I'd need to add them as dependencies in the maven pom.xml is that it ?
these statements are inherently oxymoronical
youll need to figure out if an armorstand that doesnt wear armor returns null or air
and then it'll just work with the plugin as some sort of other build path dependency thingy
Yes, but how are you building it @trail oriole
exporting
Exporting what
Like show me what u click
I use IntelliJ so Idrk how it works on eclipse but want to make sure you’re using maven to build
the entire java project, so i'd click on export the file named KiwiPvp
Right click on KiwiPvp at the start of the project outline and click Run, see if there’s a maven package option
run as maven build ?
if(item != null && !item.getType().isAir()) return false; @arctic moth
Or anyone who uses eclipse and maven if u could help him run the package goal on eclipse
i got it right the first time and then my brain started going in circles
I don't understand what the problem is. this event doesn't work.
if (event.getClickedInventory() == null || (!(event.getClickedInventory() instanceof Player)) || event.getCurrentItem() == null) { return; }
else {
Player player = (Player) event.getWhoClicked();
if (event.getCurrentItem().equals(ItemManager.fireWand)){
player.getInventory().addItem(ItemManager.fireWand);
player.sendMessage(ChatColor.GOLD + "You now posses the power of fire!");
} else if (event.getCurrentItem().equals(ItemManager.dragonWand)){
player.getInventory().addItem(ItemManager.dragonWand);
player.sendMessage(ChatColor.LIGHT_PURPLE + "You now posses the power of the dragon!");
} else if (event.getCurrentItem().equals(ItemManager.lightningWand)){
player.getInventory().addItem(ItemManager.lightningWand);
player.sendMessage(ChatColor.YELLOW + "You now posses the power of lightning!");
}
event.setCancelled(true);
}
}```
event.getClickedInventory() is never going to return a player
?paste
I didn't say it would
you kind of did
ah okay that’s not running the package goal
ah
Ugh
@worldly ingot do you still use eclipse
or did u ever, was that someone else
maybe it was optic
No, you need to learn lol
well maven and all to use one api
all this for nothing much
seems complicated to me
Actually no
I do, yes
Choco will you tell him how to run maven package with eclipse
I’ve got him to setup the maven with eclipse but idk how to build it properly
Right click the project, Run As -> mvn build...
well i have an error
we did that and it failed
(the one with three dots)
Yeah, once you do that it should bring up a wizard
In the "goals" text field, put "clean package" or "clean install"
?paste
What Maven import do I require to use CraftPlayer stuff and sheit like that?
?paste
but is this how you export the maven file or should I continue the old way of exporting
i'm trying to check what inventory is opened in an OnClick event and I get this error Non-static method 'getInventory()' cannot be referenced from a static context from this line if (Wands.getInventory().equals(event.getClickedInventory()))
https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-2-release.534760/ see the nms usage examples
second post
public Inventory getInventory() {
return inv;
}```
not static
Add static
I'm probably being stupid and overthinking but why tf is this while loop infinite
https://paste.md-5.net/fomahuqiza.cs
(dont)
Wands.getInventory() isnt static
nor should it be
you need an instance of "wands"
wrong block you use the relative for
so how do I check if its equals to another inventory?
no
thank you
np
Thanks :>
gah Lmao I feel so stupid lol I just realized the logic flaw xD
like this? Player player = (Player) event.getWhoClicked();
import com.ytg667.myplugin.items.ItemManager;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class Wands implements InventoryHolder {
private Inventory inv;
public Wands() {
this.inv = Bukkit.createInventory(this, 9, "pick a magical wand");
init();
}
private void init(){
ItemStack fireWand = ItemManager.fireWand;
ItemStack dragonWand = ItemManager.dragonWand;
ItemStack lightningWand = ItemManager.lightningWand;
this.inv.addItem(fireWand);
this.inv.addItem(dragonWand);
this.inv.addItem(lightningWand);
}
@NotNull
@Override
public Inventory getInventory() {
return inv;
}
}
we have all been there 😅
ok
so where are you instancing this
in an event OnClick
so save that to a field somewhere
and then check if that field is equal to the clicked inv
wdym save it to a field
@crisp steeple can I just make this class public instead of private?
i meant
the inv
the class is public
the inv is private
private Inventory inv;```
you already have a getter for it
i do not want to be rude but it doesnt really seem like you know what youre doing
i would probably look more into static vs non-static
Inventory inv = new Wands().getInventory();
like that?
and then compare to this?
@crisp steeple I just didn't understand what you meant im used to working in my language and not english
sorry
my bad
That will work yes
But the Inventory.equals() will not work
The way Inventory overrides .equals() is super stupid, you need to compare all items or an nbt tag stored in an item or something. Equals won't work
Any simple way of removing a certain amount of a item a player is holding?
From the item stack they have in their main hand?
yeah
Hey is there a way to get the short uuid from a player?
if you store that somewhere yeah
ItemStack held = p.getInventory().getItem(p.getInventory().getHeldItemSlot());
held.setAmount(held.getAmount() - Whatever);
p.getInventory().setItem(p.getInventory().getHeldItemSlot(), held);
my advice would be
Thanks = )
make a listener inside the Wands class that checks if the clicked inventory is equal to this.inv
and then go from there
Np 🙂
will the item disappear if its value is set to 0?
you have item.remove
righty
righty, thanks
I believe there is a way to "get highest block"
1.18 Chunked Chunks is wack
Hi
Does anyone know about weird behaviour when trying to send a ProxiedPlayer a message with an url that contains a "#" character?
The ClickEvent seems to get removed from the message while anything else, like the HoverEvent, remains.
It always works, when trying to use any other url without a "#" character.
Problem is that I need to keep that character included inside the url.
TextComponent translateButton = new TextComponent("§9§lDeepL");
translateButton.setClickEvent(new ClickEvent(
ClickEvent.Action.OPEN_URL,
"https://www.deepl.com/en/translator#auto/en/hi"
));
translateButton.setHoverEvent(
new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new Text("§7Translate")
)
);
proxiedPlayer.sendMessage(translateButton);
Any way I could make Hostile mobs (in my case Creepers) passive while near a certain player?
cancel its target event, unless you want to mess with AI
this looks like what I needed, thanks
I doubt this is a bungee issue, maybe the client doesnt support #? I note you are mixing legacy codes in text components, dont do that
you can dump the json with ComponentSerializer to check what is being sent to the client
how can i use config in spigot
what do you mean
you dont have a variable called plugin
if this is your main class just remove the plugin. part
otherwise, learn java
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.
is getInventory.getItemInHand == getItemInHand
yes
what's the max size of a stringlist in yml
iirc by yaml specification unlimited, but in java since lists only go to integer max value in terms of size that probably ought to be it
2147483647 I'd assume
so this
i've been reading the DI tutorial like 15 times now and i'm still confused on how to use it lmao
Well you need to understand methods, constructors, classes and objects in Java before properly being able to understand dependency injection
and those are quite fundamental concepts in Java and generally speaking object orientation
Sorry for tagging but i have a picture that i want you to take a look and give your opinion if possible
Well i started learning java with spigot, I believe I made a lot of progress in a week but I don't know the really fundamentals of java
I think that its better to start with the fundamentals of java
So its easy to code
Like i'm not sure how java works in depth, although the plugin i'm making for my server works well and I'm proud
But you have to practise aswell
Well you need to practice to get good
Yeah
I thought spigot would be a great way to practice and stay productive
Just to know
okay ?
What do you think people?
about ?
looks good
im trying to create a command that knocks people back in relation to their orientation from a source point and am getting weird stuff from the operation that I wasnt expecitng
so this is an intermediate abstraction that abstracts over your SocketChannel implementation?
That picture is how i will design the nio library
Like with my friends we want to get a better idea
myeah I mean personally I wouldnt spend too much time designing
start by making a mediocre, intermediate, working-state design
then refactor
Our goal is to design a simple NIO client(s)-server for sending/receiving packet
its useless if it doesnt work anyway
Good point
use whatever tools needed to get it to work first and foremost
then make the design clean and robust and decoupled and what not
good luck :3
Allright thanks
Infact at the moment that design looks okay
Thanks that what we want to know
whats the best way to get the logs directory?
Are yo using a plugin?
isnt just the server directory resolved by logs or sth?
yeah its called logs
no? im making 1
i need to get the /logs directory
specificaly latest.log
If you making a plugin get plugin folder and then do "../"
I dont know if it works
yeah but servers can have different paths
Use relative path
yeah thats the thing idk what relative path would work for this
theres .getInstance().getDataFolder().getAbsolutePath() but that doesnt help
Get relative path from your plugin folder, and then do: "../../logs"
its not in the same folder as the plugin folder
oh
I mean the plugins folder can be located somewhere completely else
so itd be .getInstance().getDataFolder().getAbsolutePath() + "../../logs"?
Yeah try
ok ty
"../" does nothing it just shows up as "../" when i broacast the path
Oh
Im idiot
"../" only works with absolute path?
Im confused now
😂
@dry forum Try this
// One
File file = getServer().getWorldContainer();
sout(file.getPath());
// Two
sout(new File(".").getAbsolutePath())
well i found a work around if it doesnt work not the best but :p "logs" + File.separator + "latest.log" ill try that 1 sec
The second one, its the best solution
1st solutions prints "."
2nd prints "/home/container/."
for (InventoryUIElement element : elements) { // NPE WILL NEVER HAPPEN SINCE SUPERCLASS CHECKS IT. IDE PLEASE SHUT UP. love this comment
Jerelfa calling absolutify on it wont do anything
well
it will turn it into an abs path
but it doesnt help in your case
Path.of(".").resolve("logs").resolve("latest.log") would be enough tho
Well, I mean, at that point just do Path.of("./logs/latest.log") lmao
./ is for relative path right?
mye probably fine in most cases, tho idk how well the of factory method handles (different) path separator chars
file format?
I mean you could opt for sth similar to how spigot does it (idk if its directly inherited from mojang) but ye
I mean for logging, spigot dumps the latest log in a normal text file, and then it compresses log files that aren't the absolute latest
or am I misunderstanding your perhaps
Question 🙂
when writing a command
how does the blockpos args get passed
one by one in the array? or just one object in the array and I have to parse it
im assumming one by one
Like, does this work (in onCommand)
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
❤️ thank you
How to group each element of an array by 2 using lambda because the common for (int a; bla bla) looks really ugly?
Isn't there a java fasutil class for that
BooleanIntImmutablePair
or Mutable pair if you want that
now, I have another question 🙂
is there a way to run a task in milliseconds
technically yes
if you schedule a task in lets say a scheduled executor service
and then perhaps sync the task on the server thread on execution
oh all right, is ther a special way to do that or just a synchronized block
oh not the bukkit scheduler
i get it ig thanks
i've mostly messed with mods and we don't generally have to mess this much with threads, just simple server/client checks in world class
ScheduledExecutorService service = Exeucutors.newScheduledThreadPool(1,new ThreadFactoryBuilder().setDaemon(true).build());
service.schedule(() -> {
Bukkit.getScheduler().runTask(plugin,() -> {
//TODO
});
},10,TimeUnit.MILLISECONDS);
ofc it wont be 100% accurate
but thats as accurate as you can get
😅 virtual threads where are you
yeah no worries, altho client and server side can be annoying sometimes
Is there any way you recommend in testing plugins?
testing in terms of ?
setup a server in your pc and shoving clients on your pc into it
myeah well there's paperweight userdev
altho not for spigot
else its pretty simple to write a task for that using gradle
yeah gradle is at its best significantly more configurable w/o 3rd party plugins
Will apply for doing something like this:
{"value-1", "value-2, "value-3", "value-4"}
So each value correspond to next value so:
value-1 = value-2
value-3 = value-4
Why not just a map?
new BukkitRunnable() {
@Override
public void run() {
coolDownMap.remove(event.getPlayer().getName(), event.getPlayer().getUniqueId());
event.getPlayer().sendMessage("removed you from cooldown list");
}
}.runTaskLater(Main.plugin,15L);
can someone please say wtf is wrong with this? it runs coolDownMap.remove instantly when i get a instance of runnable instead of 15 ticks later
and not the sendmessage?
exactly
seems like the runnable isnt the cause then
no errors saying player is null?
no
what event is that
well it seems pretty unlikely that you have a javaagent or something executing that line specifically for no reason
pretty sure the only other alternative is that you arent using the map right
if i remove the runnable that sout prints the map with my player inside it
Because i will have a method like:
void send(Object sender, String path, Object[] placeholders)
did you even read the mapname?
presumably for a cooldown
and you're completely sure its removing it instantly and not just a very short time?
have no other clue what else it could be then
So then when sending would somethin like this:
send(sender, "path.test", "{key-1}", "value-1")
So each element should be group by 2
yes im sure
a delay and the time to actually run it later
the runnable is fine
idk really know why
it calls sendmessage later
so its fine
i think you just have to be removing it or not placing it somewhere else
it doesnt make any sense otherwise
if you want to be completely sure just make a method called test1 and test2
put the remove from hashmap in test1 and the sendmessage in test2
there is another way
then put bukkit.broadcastmessage(system.currenttimemillis) infront of both
and see if theyre different
what does that prove
before i get a instance of runnable there is already a value inside the map
and after getting a instance map is empty
i think you should try what i suggested and see what it says
dont know exactly what you're doing since you havent sent code but it doesnt seem possible to happen at all with what you're describing
what
get the world of the player who sent the command is in
is this check good?
if(!(coolDownMap.containsValue(event.getPlayer().getUniqueId())))
also its fine right?
coolDownMap.put(event.getPlayer().getName(), event.getPlayer().getUniqueId());
player.getLocation().getWorld()
oh that has a world reference? nice!
im not sure why you would put their name and their uuid in a map
seems pretty redundant
name to show the list uuid to check
iirc remove() returns a value of null if nothing was removed you could check the value of that
can you show the full thing of whats happening
you would have to be overwriting the key somewhere or deleting it somewhere else
i still recommend you try what i suggested because the current scenario you're describing is not possible (without very strange javaagents and such)
bruh char limit
?paste
oh wait @noble lantern what if the command is meant to be run in command block
xD
not sure about command blocks tbf

😔
there could possibly be an event that executes when a command block is run
google like CommandBlockEvent spigot and something should show up
ok im just gonna have to assume it makes it up to here because i cannot read all of the stuff before that
BlockRedstoneEvent or EntityChangeBlockEvent
🤨
and check if its block data/state is a CommandBlock from there should be able to tell what command its executing
doesnt seem like 15 to me
i changed it to 1
why
like 10 seconds before i send the code
debug
also that if statement is fine
and the reason you cant read stuff before that is its some fancy math
I want to keep the command inside the command class for now i think, i'll see other options
alright im gonna do a legendry thing
if you make a spigot command a commandblock should be able to run it if thats what you meant
ok
This isnt related to your issue but
im not even sure whats going on here
why are you sending a message to something that isnt a player
i dont think the cows need to know they were frozen by an admin
burchard i figured it out.
sender instanceof BlockCommandSender block
and it has it 😄
wtf
i mean that it has block#getWorld that i can use
ik
never heard of BlockCommandSender lmfao
i googled it and it appeared in a 2012 forum
ill have to add that to my api now to handle block command senders damn
ok
just ignore them smh
me neither
makes sense i guess
now ill need onBlockSend
indeed it does
tbf i forget command blocks are in the game 80% of the time
if you are running a server its a good way to hook into plugins as staff can easily handle them
well then the player going to use that wand and his whole chat will be spammed
or worse tps drop
seems like everything isnt fine then
how about you just remake your cooldown since this clearly isnt working
so its fine now
now i just have to remove the cooldown
ok then
omg
bruh
you dont believe
but the thing hapening is
idk actually it just seems cursed again
quick question, why event is pink and have a pink underline in intellij?
its a keyword
no it isnt
so
i thought it was highlighted
no
so it stops spamming
but at the same time allows
you cant just hold right click with wand and fill the chat
so that little if statement is not doing its job
bruh
bruh
i just got it
PlayerInteractEvent is getting called so fast that coolDownMap.put dosent have time to put user inside a map
i dont think thats it my guy
99% its that
that is not how threading works
well it is almost
its just not
you can have multiple of same event running at the same time
thats not how that works
nope
sooo
you're saying if my method take like 5 min to execute completely other events wait in a queue?
HM
so if a event take like 12 second to run then server print a warning message of server not responding ?
believe the timeout is 20 seconds
server is .... ticks behind
but pretty much
1 last try
lemme see
alright
now more chance of my idea
because i put the map.put line on top
and now i can only spam 3 times
before it was 7
lemme see if my method can crash the server
ill just put a 20k for-loop
probably wont
why?
20k is not a lot in terms of computing
putting your entire method into it?
no
pink underline is when somethings running async doesnt it, while the variable was declared sync
theres only a handful that are actually async
well yeah
like PlayerAsyncLogin or some shit like that and the CHatAsync one
the ones marked as that obv
hover over it and see what it says
nothing
no error
just basic things about the variable
like any other one
but i guess that stackoverflow one is correct
alright
successfully crashed my own server
good for you
alright i gave up
not going to paste another 300 lines from stackoverflow just to make a cooldown for a private plugin
why use runnables for cooldowns anyways
idk maybe because i dont know anything else?
system.cureenttimemillis
What would be the best way of handling inventories for configs 🤔
Just serializing them or is there something better 👀
check the time milli the user used the thing at then check it against the current milli time when you need to check if theyre in cooldown
HM
Pretty sure I have a cooldown thing actually, I don't feel like going through a lot of code to find it though
i used bukkitobjectoutputstram and then encoded in base64
hope dosent use too much cpu
works pretty well
if you wanted to store the itemstacks those already are serialized in bukkit
your solution currently is the most resource intensive
so you dont have to do anything weird
because the .runTaskLater?
Yea, pretty much.
Store inventory in config & load + add to inventory as needed, cached of course lol
yes, your opening a task for every player who uses that item
@dusk flicker
would it just be
FileConfiguration config;
config.set("a", new ItemStack(Material.STONE));
?
good point but that item SHOULD get in cooldown after first use
dont ask me about configs
lmao
?tryandsee
I'll just do that lol
shit I missed an opportunity to TAS optic
HashMap<UUID, Long> cooldowns = new HashMap<>();
// on use
if(System.currentTimeMillis() - cooldowns.getOrDefault(playeruuid, 0L) < cooldowntimemillis) return;
cooldowns.put(playeruuid, System.currentTimeMillis());
@civic dagger
inb4 it breaks lol
thanks imma try it rn
@dusk flicker
a:
==: org.bukkit.inventory.ItemStack
v: 2975
type: STONE
seems like it works lol
yeah
didnt work
only work when you spam like 30 times
and it blocks like 5 of them
whats ur full code
what are you setting the cooldown time to
3000
tested with 300 too
ok
exactly every 5 use
it block 1
better than nothing i guess
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(event.getItem() != null) {
if(event.getItem().getItemMeta().equals(PlayerFreezerItemStack.getFreezeWandItemStack().getItemMeta())) {
if(System.currentTimeMillis() - coolDownsMap.getOrDefault(event.getPlayer().getUniqueId(), 0L) < 500) {
event.getPlayer().sendMessage("cooldowncheck");
return;
}
coolDownsMap.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
if(event.getPlayer().hasPermission("playerfreezer.wand")) {
its the start
https://gist.github.com/graywolf336/8153678 i found this class
serializes inventories to base64 and back
after that all is same as before
alright
fixed it
almost
at first you can spam like 10 then you can spam 3 each time
what exactly isnt working
the if statement
if(System.currentTimeMillis() - coolDownsMap.getOrDefault(event.getPlayer().getUniqueId(), 0L) < 500)
whats not working about it
it blocks it
is it not cooling down properly?
blocks what
you can at max use the item 5 times
the message
wait
its like this:
you used the item
you used the item
you used the item
you used the item
you used the item
blocked for 500ms
you used the item
you used the item
you used the item
you used the item
you used the item
something like this
each time you can use the item for multiple times
check if the player actually has a cooldown
if theyre inside of the map
because you're just resetting the cooldown
every time they click
hm
if(coolDownsMap.contains(event.getPlayer().getUniqueId(){
if(System.currentTimeMillis() - coolDownsMap.getOrDefault(event.getPlayer().getUniqueId(), 0L) < 500) {
event.getPlayer().sendMessage("cooldowncheck");
return;
}
}
inside a else that belongs to the same if statement
show the code
show the code
if(System.currentTimeMillis() - coolDownsMap.getOrDefault(event.getPlayer().getUniqueId(), 0L) < 1000) {
event.getPlayer().sendMessage("cooldowncheck");
return;
} else {
coolDownsMap.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
}
sorry for bad indent, discord...
yes i do
reworded
thats why i said "just as expected"
ok
now add my change
check if the player is inside the cooldown map
but remember to put the coolDownsMap.put(event.getPlayer().getUniqueId(), System.currentTimeMillis()); outside of that
replace if(System.currentTimeMillis() - coolDownsMap.getOrDefault(event.getPlayer().getUniqueId(), 0L) < 1000) with your change?
no dont
^
yeah because its getOrDefault
no its not resseting
because if statement blocks it
wait im reading this wrong
a plugin that always spawns in the lobby, if it runs out the server exits
what is the name of the plugin?
HELP
PLS
PLS
HELP ME
?kick @hard lake ask normally
Done. That felt good.
wow
what
now he have to wait 10 mins lol
