#help-development
1 messages · Page 1637 of 1
Yes runnables for cooldowns is a bad idea. Use timestamps instead.
It could be as simple as that:
public class CooldownManager {
private final Map<UUID, Map<String, Long>> cooldownMap = new HashMap<>();
public void setCooldown(UUID userID, String cooldownName, long cooldown) {
cooldownMap.computeIfAbsent(userID, key -> new HashMap<>()).put(cooldownName, System.currentTimeMillis() + cooldown);
}
public long getTimeLeft(UUID userID, String cooldownName) {
long stamp = cooldownMap.computeIfAbsent(userID, key -> new HashMap<>()).getOrDefault(cooldownName, 0L);
return stamp - System.currentTimeMillis();
}
public boolean isCooldownOver(UUID userID, String cooldownName) {
return getTimeLeft(userID, cooldownName) <= 0;
}
}
I put a 1.8.9 map in a server 1.16.5 map and a few chunks are loaded and the map is half bent, can you fix it somehow? sorry for my english die Chunks wollen also nicht geladen werden, aber alles funktioniert in 1.8.9
Ew timings v1
Hm ok so 3% of your tick is too much? For how many users?
Show some code and we can see if there are some low hanging fruits optimization wise
?paste
Ill just read the code from top to bottom and throw my 2 cents in.
First:
Block block = player.getTargetBlock(new HashSet<Material>() {{
add(Material.AIR);
add(Material.WATER);
}}, 5);
Anonymous initializer will clutter the ram with thousands of anonymous classes if you do it like this. Make this Set an private static final EnumSet for optimal performance.
private static final EnumSet<Material> MATERIAL_FILTER = EnumSet.of(Material.AIR, Material.CAVE_AIR, Material.WATER);
Hello, is there a way to handle exception in console?
how do i NOT make display names italic
Next:
You can just use the spigot method to get the distance squared between two locations:
Location locA;
Location locB;
double distanceSq = locA.distanceSquared(locB);
if(distanceSq > 1024){
return;
}
(in 1.17.1)
You can remove formatting with §r
"§rTotem Of Teleportation"
like this then?
Those lines kind of make no sense to me:
BrokenBlock brokenBlock;
if (time == -1) brokenBlock = new BrokenBlock(block, time);
else brokenBlock = new BrokenBlock(block, time);
Because in the end brokenBlock will always be just a new BrokenBlock(block, time)
lmfao what is the point of the if statement, if both outcomes run the same line 😕
BrokenBlocksService can be reduced like this:
public class BrokenBlocksService {
private static Map<Location, BrokenBlock> brokenBlocks = new HashMap<Location, BrokenBlock>();
public BrokenBlock getOrCreateBrokenBlock(Block block) {
return getOrCreateBrokenBlock(block, -1);
}
public BrokenBlock getOrCreateBrokenBlock(Block block, int time) {
return brokenBlocks.computeIfAbsent(block.getLocation(), loc -> new BrokenBlock(loc, time));
}
public static void removeBrokenBlock(Location location) {
brokenBlocks.remove(location);
}
public boolean isBrokenBlock(Location location) {
return brokenBlocks.containsKey(location);
}
}
computeIfAbsent gets the Object from the map or puts a new one in the map and then returns it if it does not exist
anyways, i got a question
does InventoryDragEvent cover hotkeying items from one slot to another?
hi
I had something like this
protected final Map<UUID, Long> cooldowns = new HashMap<>();
public boolean hasCooldown(int secondsIfNotDefault) {
long time = secondsIfNotDefault == -1 ? 5 : secondsIfNotDefault;
if (cooldowns.containsKey(p.getUniqueId())) {
if (cooldowns.get(p.getUniqueId()) > System.currentTimeMillis()) {
Utils.message(p, "§cPlease wait " + (cooldowns.get(p.getUniqueId()) - System.currentTimeMillis()) / 1000 + " more seconds!");
return true;
}
}
cooldowns.put(p.getUniqueId(), System.currentTimeMillis() / 1000 + time);
return false;
}
Playing Intellij 🤣🤣🤣
sure
There is probably something you can do in the BrokenBlock class but ill play some games with the boiz
i was just learning java
I bet you prefer Microsoft Word.
manupulationg variables
no
nah notepad for life
playing MovableObjectApi with the boiz, pog
notepad..
This or bust
no, eclipse 4life
sus
sublime text 😳
i am coding in my book with a pencil
im coding with my imagination
i was serious
when i said i wasn't
chalk and rocks
yeah
it is an interesting experience
chisel my code into marble
best ide is paper and pen
vim is eh
it’s one of those things that i can see the advantage of but like
yes
i need muh auto completions
coding without feels powerful
it is god tier shit
vim wins
clash of clans
yes that one
like at school we have to use python IDLE and like it is so nice when you happen to remember methods
you feel like a pro
its like spoonfeeding here
guys check out the new and improved
without your IDE
lmao
offline editor
😍
on discord
like the good old days 😦
gosh your using discord to code now? what a legend
yeah
:{
discord is way betteer then intelliJ
oh because of that his code looks like that
how about compiling on discord?
dw just compile with your uh brain
...
make all methods static so there is no need to instantiate classes 
not even private
Bukkit.BroadCastMessage(new PlayerEnum()[0].GetPlayerEnumTypeResult().HIT.GetDeadText());
it is
on both sides
:(
wrong
what
boolean discord = true;
System.out.println(discord ? !discord ? discord : !discord : "true");
pubilc clas smain{}
pulick statik viod main(sTRING[] args){
System.out.pritnline)"work plsplspls");;;
}
how you get colors?
```java
code here...
```
#yea
-lmao
+test
System.out.println(true)
i was learning java
- big minus
+ but also a huge plus
why mobile discord sucks:
- no color formatting for code blocks
- pressing "enter" just creates a newline
- the chat section is bugged af
also i cant see the formatting cuz im on mobile sadge
dont worry it looks like a rainbow on crack
he says on spigot official discord
i need to learn java first
honestly, use intellij, and install the minecraft development kit plugin
so i will learn java easily
the plugin will generate a spigot plugin template for you
and intellij's autocomplete is top notch
u cant write spigot code without knowing how to code..
eclipse >
u should learn java first
visual bukkit
just learn the basics of programming, such as functions, ifs, loops, switch statements, etc
and java will come by ez
lol
you have not mastered java
I was learning java
so okay
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.
how can i get a Players instance by their world?
wdym? what if there are multiple players in the world
thats not my question
ah got it
Player player = new Player();
yeah, also spigot has probably one of the best javadocs ive ever seen, https://hub.spigotmc.org/javadocs/bukkit/index.html
package index
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.
"hacking"
nothing
hacking famous communities will be hard since they are fameous and you are probably not the only one who every attacked them
also you would have to go over social engineering instead of finding any Vulnerabilities in their code
social engineering? I would use vulnerbilities
easier than finding vulnerbilities
but not efficient
they will have like many avs and managers
so social enginering will not work until they are normal people
not celebs
i would've loved to see their faces
webcam hack?
boring
?
inject pegasus
if you want to hack people without getting fbi on doorstep, i suggest starting with hacking techs support scammers, its so funny
and its so easy
why? i need help at hacking the NASA with my Player.dll
you mean ethical hacking?
👀
i already have their IP
the what
whose
"127.0.0.1"
lol
will ddos them now to doom
:/
OOOOoooOoooooOoooooOOOO
WOW HOW DID HE DO IT
😂
Player.dll is the key
i am godcipher
if you wanna hack ethically seriuosly go to kali linux
he is god
i've STARTED my dll and let the Player walk around their servers to break the blocks of thei firewall
its allowed as long as there are no help questions
but seriously, hacking tech support scammers is ez af
- get a virtual machine
- make a RAT and disguise it as passwords.txt
- scammer makes a copy, thinks they've struck gold
- now you have access to their computer
- or use wireshark to get their IP address
injected my WaterWall then
literally everybody here
😳
nms pog, it makes my brain go yes
it makes my brain goes brr
don't we all?
me, i need to find a way to loose my remaining 3 brain cells
loop Bukkit.getOnlinePlayers() if(player.getWorld().equals(YourWorld.class)
why this no work
i was learning java
you have to loop that code
another server software?
not literally the word "loop" in th code xd
i did, read the loop keyword
for loop Bukkit.getOnlinePlayers() if(player.getWorld().equals(YourWorld.class)
i want to get the world over the player instance
but before i need to get the player over the world instance
to get the world
System.out.println(Player#getWorld());
doesnt work
System.out.println(yourPlayer.getWorld());
doesnt work either
i think you are trolling
did u write it with the #?
says its null
probably not online
how do i make toto7735 online
i think you cant help me
i will come back later to troll someone else
i want money
xDDD
toto, you are being trolled
how the turntables
godcipher is trolling you hah get baited
this is the strangest conversation ive ever seen
also, pro tip when making plugins, my build configuration for intellij is
- new jar application
change the build path to the plugins folder for my test server
/reload ingame
make your own custom plugin which compares the plugin version
if its a newer one, reload automatically
nah i am literally one of the most active people in this channel
to shit on others
and helping them afterwards
heh think of all the people you trolled
pubilc clas smain{}
pulick statik viod main(sTRING[] args){
System.out.pritnline)"work plsplspls");;;
}
pls help psl pls spsl spsls
try to add a ;
no problemo
:/
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply.
LMAO
Hey, what would be the best way to call several fake BlockBreakEvents without lag or errors so other plugins can listen to it.
The regular bukkit BlockBreakEvent
When storing data in SQL, is it possible to put tables inside of tables? Also, is it considered bad practice to do so?
there shouldnt be a lag or error
and if you call it the other plugins will automatically listen to it
Not sure if this is the right place, but anyone know how I'd download a particlelib in eclipse for my plugin?
👌 ty
Could someone help me understand this:
public static class ModuleComparator implements Comparator<Module> {
@Override
public int compare(Module arg0, Module arg1) {
if (Minecraft.getMinecraft().fontRenderer.getStringWidth(arg0.getName()) >
Minecraft.getMinecraft().fontRenderer.getStringWidth(arg1.getName())) {
return -1;
}
if (Minecraft.getMinecraft().fontRenderer.getStringWidth(arg0.getName()) >
Minecraft.getMinecraft().fontRenderer.getStringWidth(arg1.getName())) {
return 1;
}
return 0;
}
It takes a list and sorts it my string length so the longer words are the first ones, but I just dont understand how it works.
you don;t access that yoruself, you use it as a Comparator in a TreeSet/Map
If the width of arg0 is greater then arg1 it returns -1
a comparator sorts objects using -1, 0, 1 to signify which is less/more
why does it repeat the if statement twice tho
no
What is it then
Okay yea I was mixing some stuff up with the T
But Comparator<Module>
Comparator is a class right?
No
its an interface
But why do I need to specify the <Module>
it has to know what class you will be passing
What is the logic behind the code tho, is the list taking elements 2by2 and just compares them or like whats the system
In the code the compare method just asks for 2 arguments and compares them with each other
the logic is exactly as in the compare method. when an item is added it is compared to the current list contents until it finds its slot.
Potions arent under material.
You can.
Potion p = new Potion(PotionType.INSTANT_HEAL, 2);
ItemStack item = p.toItemStack(1);
Example.
When storing data in SQL, is it possible to put tables inside of tables? Also, is it considered bad practice to do so?
No you can’t put a table inside a table
Well you could take the contents of a table and insert into another assuming the tables have the same types
Though you can utilize different tables and create relational tables or whatever the term is for that
Is there a good way to get the direction of an entity facing
like i can getYaw
but i wondered if there was an enum or something
Getting the vector or just how the entity is facing?
myeah i just need it so they are facing like NORTH, SOUTH, EAST, WEST
Entity#getFacing saves your ass I think
Lmao
Hmm thought it was 0 - 360
huh
👍
kotlin???
👀
im gonna assume u mean that as a K
realises he intended to learn kotlin and forgot about it
Oh I missclicked lol
haha
Yeah altho you should be doin kotlin my guy 😉
I still do Java but that’s cause I am masochistic sort of 🥴
Terrible truth disclosed, but yeah anyways is it that drone thing you’re working on right now?
Oo
Intriguing
Hmm same
The first time a yt vid's sponsored section has been useful xD
Lmao
hey
👋
how to use PlayerConsumeEvent?
please tell
?eventapi
what tp write after Player consume event
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.plugin.java.JavaPlugin;
public final class MyPlugin extends JavaPlugin implements Listener {
@Override
public void onEnable() {
// Plugin startup logic
System.out.println("Welcome to my server!");
@EventHandler
PlayerItemConsumeEvent.
}
@Override
public void onDisable() {
// Plugin shutdown logic
System.out.println("Bye");
}
}```
?paste
oh lmao
Do you know Java?
@EventHandler
public void onPlayerConsume(PlayerItemConsumeEvent event) {
// Do shit here
}
but whatever cause it literally explains it here: https://www.spigotmc.org/wiki/using-the-event-api/
@ivory sleet they call me an artist
If you're talking about yaw someone said it above... Its not 360. its -180 to 180
I said that
example?
but the jd said 360 - 0
?spoon
Spoonfeed a newbie for a day and they'll come back with more questions. Teach them to find their own answers and you'll both be better off: you won't get stuck answering the easy questions and they'll be much more productive than before.
Exactly what jeff posted...
@EventHandler
public void onPlayerConsume(PlayerItemConsumeEvent event) {
Player p = event.getPlayer();
if(event.getItem().getType() == Material.ENCHANTED_GOLDEN_APPLE)
event.setCancelled(true);
}
Always has been
🤷
ruined my pic 
Thats always been minecrafts yaw positioning.
i wish North = Positive X
Wait untill you have to calculate the actual position... Degress NorthWest etc... xD
event has a red line
?paste
🥴
what have you done?
me?
yeah
Import PlayerItemConsomeEvent
Show the error then.
LMAO
.-.
?
You said you knew a bit of Java
You can't put a listening method in your onEnabled method
new class?
?learnjava You need to at least know basics
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.
Move the listener method out of the onEnable method and in the onEnable method register the listener
ok
private BlockFace parseDirection(double yaw) {
if (yaw <= -135 && yaw >= 135) return BlockFace.NORTH;
else if (yaw <= -45 && yaw >= -135) return BlockFace.EAST;
else if (yaw <= 45 && yaw >= -45) return BlockFace.SOUTH;
else return BlockFace.WEST;
}
Does this seem right?
?paste
Looks like it can be static but yeah
true
this will do nothing no?
no
with bread
disappear?
ok
How can i save this File in a dictonary?
enFile = new File(getDataFolder(), "en.yml");
This doesn't work :/
enFile = new File(getDataFolder(), "lang/en.yml");
or
enFile = new File(getDataFolder(), "/lang/en.yml");
First is fine
However you need to ensure the parent file (directory) exists
Then create the file
👍
how to take a certain amount of experience from a player?
Easy
Is it bad practice to make one of these tables in SQL for each of your players? Each table storing 500-5000 rows of data? https://i.imgur.com/SxpprZF.png
Or is there a better way to organize all of that data
tables should not be created per-player
your players uuid should simply be part of the primary key
I'm trying to make a PvE gamemode plugin and I'm using default mob spawners. One of the spawners is for slimes but, while the Y level will be fine, they will still only spawn if it's a slime chunk. Is it possible to force a chunk to allow slimes or force a spawner to still spawn slimes even if it isn't a slime chunk through the Spigot API?
no, don't think so
so basically create a column which points to another table which stores their data instead?
give me an example of the data you store in that table
so I can maybe give an example
// Card UID, Card name, Card Stars, Card description, Card Attack, Card Defence, etc
//
// Card Skin data
// Card UID, Skin 1, Skin 2, Skin 3, Skin 4, Skin 5
//
// Card Pile Data
// Player UUID 1
// Card UID 1
// Skin ID, Rarity, Amount```
Each first line = table
and for the card pile data, the 3 indented lines would have been tables
so you basically have a card which has all the stats mentioned in the card data table
yes
then a table that holds each available skin for the card
yeah how much they own
the skin data stored here:
// Player UUID 1
// Card UID 1
// Skin ID, Rarity, Amount``` would point to the skin data table
oh, yea
tho why is the rarity in there
how does that correlate to the player owning the card
because the same card can have multiple rarities
Ah, but then amount seems problematic there doesn't it ?
// Card Pile Data
// Player UUID 1
// Card UID 1
// 1, 1, 1
// 2, 1, 1
// 2, 2, 1
example
I was thinking total amount would be calculated based on each amount within the Card UID table
Since there are quite a lot of combinations of skin id, rarity, card IDs
Yea I guess, but then yea your player UUID would just be a collum in the table
not the table itself
how can I pick up and give a certain amount of experience to a player?
Yeah since you can't put tables inside tables, like someone mentioned, my above design won't work.
Trying to figure out another way to do it
how can I pick up and give a certain amount of experience to a player?
SignChangeEvent
player#setExp()
Thanks
take this away?
you can get amount of exp then set it what do you want
what is normal creeper explosion radius?
1725 is like level 30. if a player has 2000 experience, is it possible to take only 1725?
Your async is not constructed until the sync is, so your sync runs first
pls do not spam if someone know he/she will answer
How would I fix that then?
create the sync inside teh async after it runs
player#setExp(player.getExp() - value)
thanks
What do you mean by that?
?paste
So guys
im tryinna make a totem of dying
it wont work
i am trying to make it kill me when i take damage if its in my hand
Use player#damage() instead of setHealth
Idk use player.damage(player.getHealth())
this will work
Yes
then
I think so
how to register item?
you must put #getExpToLevel()
100 lvl
and 1395 must be double ( maybe )
int
setExp must be double but #getExpToLevel() Int
You got a Nullpointer, spawnLoc is null (Line 37)
it still doesnt fix the
totem of dying problem
its supposed to kill you when you take damage
Why are you using CraftPlayer
Hi, is there some way to catch exceptions from all classes of my plugin?
i dont want 😄
Then what is your goal
no reason
i just forgot to remove it after trying something
By any chance, is there any way to set a config value without getting all the comments lost?
saving it correctly
How?
is it a custom config or your config.yml?
speak
config.yml
use #saveDefaultConfig to save it
so i am trying to work out what "angle" one location is from another
then the values are defaulted no?
👀
nope
huh
it saves the config on the default config
instead of rewriting it
saveDefaultConfig will do nothing
As config.yml already exists
so where is your problem @opal juniper
is there a wae to check if player is in air?
it will
and?
im trying to do the spinning
check the block below them??
flying? or just in air?
Hm?
air
the check block below 🙂
yeah it does not replace the config with the newly created one
so the comments stay
so get block at player location y-1?
saveDefaultConfig is only for copying the default config from the jar to the plugin folder
player.getLocation().substract(0, 1, 0) i hope that workd
yup also check arround bc a player can still get on a half block
Not for saving the config after you modify it programatically
help
Just checked that, it does not save anything
huh then i confound smth
then use the PrintWriter
Isn’t it for saving also
No
The hell is that XD
Lol nice method name then
You will need to use a 3rd party API to keep comments
Or wait for spigot to update SnakeYAML
Which has already happened
no
Then it should save comments
Myes
Did he?
how do i make a class only require 1 out of 2 params of a method, i want the second param to be for other uses in another class
Uh last time checked it was the second latest version of snake yaml
well im wrong then
Create a second constructor that only takes 1 param
:/ ok
Or allow null for the second param
This beginner Java tutorial describes fundamentals of programming in the Java programming language
System.out.println or getLogger
Varargs works if both are the same type
Or you want to deal with casting from Object
spigot prefers getLogger
JavaPlugin#getLogger
ik its called overloading but
i forgot how to do it
this()
oh then your instance depends on the passed parameters
so it automatically depends on the argument that i gave it and go to the one that uses it??
yeah
so if one uses ItemStack and one uses Material it adapts to Material if I use Material.STONE
because of that you cant have 2x the same method with the same name with the same parameters and a different return type
yooooo technology
The compiler is smart
how i can grow seeds?
when oop:
getServer().getPluginManager().registerEvents(new MainListener(this, new RecipesManager(this), new Method(this)), this);
fuck the naming btw ill change it
plant it, dump water on it, wait a few days
xd
thanks
hey
i am trying to create a directory in the plugins folder but it won't work
public class Initialise
{
public static String IEDirName = "something";
public static File GetDirectory()
{
File PluginsFolder = new File("plugins");
String[] Files = PluginsFolder.list();
for (String File : Files) {
if (File == IEDirName) {
File IEDir = new File(IEDirName);
return IEDir;
}
}
File IEDir = new File(IEDirName);
if (!IEDir.mkdir()) System.out.println("Failed to create directory.");
return IEDir;
}
}```
i am kinda new to making plugins
hey, so my async task just wont run at all. I checked, and there is nothing that is cancelling it. Any help?
private void addManhuntWin(Player player){
UUID uuid = player.getUniqueId();
System.out.println("Starting task");
Bukkit.getScheduler().runTaskAsynchronously(manhunt.getMain().getPlugin(), new Runnable() {
@Override
public void run() {
manhunt.getDatabase().addManhuntWin(uuid);
int wins = manhunt.getDatabase().getManhuntWins(uuid);
System.out.println("Running task. WINS = " + wins);
}
});
}
Only the "Starting task" prints out
um what is that
Idkmaybe log it out instead
it says it gets the folder the plugin's files may be located in but does it create a folder if it doesn't already exist?
uh wdym
manhunt.getMain().getPlugin().getLogger().info("Running task...");
ok
Idk if sys out works asynchronously, should do but doesn’t seem like it does for you
sys does work async (tested earlier). But idk why this specific task doesnt run. all of the others run though
No but you can use !file.exists and file.mkDirs
Did not find any workaround with that
Maybe your database calls kills the thread
What r u trying to do?
To save the config without losing the comments
okay
Oh right, I believe the newest versions of spigot actually does that but if you’re using something older you might have to use an external yaml lib
i'm looking for the same 😔
Hmm I use Configurate, but it’s arguably bloated although engineered by knowledgeable people
I'm on 1.17
how to access a param of a method from another method
how can I pick up and give a certain amount of experience to a player?
1725 is like level 30. if a player has 2000 experience, is it possible to take only 1725?
returning it
am i being stupid, i have an entity called
droneEntity and i am calling this:
droneEntity.getLocation().setYaw(90) but nothing happens
do i have to teleport it?
yes
sorry i am a bit rusty at java i guess but
java: method getPlugin in class org.bukkit.plugin.java.JavaPlugin cannot be applied to given types;
otherwise how would it change
it just rotates it... idk
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class Initialise
{
public static String IEDirName = "something";
public static File GetDirectory()
{
File pluginFolder = JavaPlugin.getPlugin().getDataFolder();
if (!pluginFolder.exists())
pluginFolder.mkdir();
return pluginFolder;
}
}```
my method is an event btw
what exactly are you trying to do
i will take the 30 minutes i took to get the idea to explain it
its a mess
basically
i want to get a param in an event in another class
in another method
what?
either i am too tired to understand that
or you are too tired to explain it correctly
public void fuckeryfuck(BlockDamageEvent e, ItemStack item, String key, boolean bol, String matchMat) {
so
the String key
i want it in another class
is this your event method?
yes but i wont register iit
I want to execute method when I right click diamond sword, which event should I use?
PlayerInteractEvent
ty
so its not
ok
there is no other way than just passing it 2 times
wdym
the method i want it in
is an event
so basically
i want an event method param in another event
what
what
only one event exists at a time
and only one will exist at a time
You cannot have a callback for multiple ones
mine are for different purposes
yes i know
but the one im getting the key from exists when a player join
so it shouldnt be a problem
right
so you get a String when a player joins
I need some help with the PlayerItemMendEvent, i try to modify the amount a item will be repaired buy a half.
But the setRepairAmount ist some kind of broken.. As example if i do event.setRepairAmount(1); the item is instantly repaired and the event will be called quite often...
Does somebody already used that event ?
I have used it yes 🙂
Do you know why the item will be repaired instantly for the example above ?
I mean doesn’t the repair amount represent half of the amount or something
Believe there’s a detailed explanation in the javadocs
?jd-s
I already read the docs.. but it doesn't helped... Maybe i don't understand it or something else...
getRepairAmount returns the amount of the damage which will be repaired, so i did getRepairAmount / 2 and set that amount as new repairAmount.
But this also repaired a lot more (also i got kicked), so i tested it with event.setRepairAmount(1); and the it will be repaired instantly.
If you just by default print out the value?
print the repair amount and the experience orbs amount
how do i check if a player is holding a certain item? 🤔
PlayerInventory#getItemInMainHand iirc
If i only print the values there are correct, as example the chicken will return a repair amount between 0 and 6.
The experience orb will return 3.
But as soon i use event.setRepairAmount(1); the Event will be called like 100 times.
Hmm that’s really odd
yea 😅
Might be a bug
is it ok if i repeat 30 lines of code for like 5 times and only change a few things
its not normally but
in my case its rly hard to find another way
like uh
WAIT
i think i got a solution
I would love to know if that is a bug.. if so, i could cancel the event and manually repair the item 😅
By your explanation it definitely sounds like one
Could you setup something to verify that it’s actually firing crazy amount of times
Like a second event callback of that event type
Okay, then i will manually repair the item and open a issue.
Could you setup something to verify that it’s actually firing crazy amount of times
Sure give me a second.
I've been messing around with Bungeecord 1.7-1.8 and 1.8 players are vanished for 1.7 players, is there a fix for this by any chance?
?paste
This won't work.
I am trying to kill the player when they take damage if the player is holding a specific item.
@ivory sleet
Yea it will be called quite often 😅
https://paste.md-5.net/ajirexulic.md (Just copied a part of the output)
I now have two events:
https://paste.md-5.net/gaverewume.cs
I killed ONE chicken 😄
help please
At first.. you asked 3(!) minutes ago... so why do you ask again ?
Also you don't give us more information, what don't work ?
Do you added debug messages to tested if your code will be executed ?
yeah it is being executed
but the player isnt taking damage
The whole code (the damage part) will be executed or the event ?
whole
this is the part that doesnt work
Try to use .setHealth(0) instead of you damage(getHealth) part.
i want to avoid players from joining the server while doing something that lags the server. im not sure if i should use onPlayerJoin, onPlayerLogin, onPlayerPreLogin, or something else. also idk if i should just cancel the event, or kick the player, or disallow the login, or what. what should i do?
also, for the kick message, how do i construct a Component object?
works. thanks.
How do I cancel item durability change?
Which event is called with
bomb.getWorld().createExplosion(bomb.getLocation(), 3f);
@EventHandler
public void onEntityInteract(PlayerInteractAtEntityEvent event) {
event.getPlayer().sendMessage("hey");
}
this sends "hey" twice
how can i make it only send it once
only do it for one hand
so just if its the left hand, return?
?
yes
nvm
Is there anyway to force a player to move in a certain direction without using setVelocity or teleporting ?
Uhm. No. Moving is exactly that.
Okay
I mean... you can mount him on an armorstand and move this one i guess
So I'm using the REL_ENTITY_MOVE packet, what would be the steps I need to take in order to get the deltaX, Y and Z of the entity? (Have not rlly worked with packets be4)
Oh that's a good idea, thanks !
is there a way I could check if the clicked item is from an inventory and not the player's inventory? Lets say I have a book in my GUI and player has a book in his inventory, only detect book click from the GUI with setting localized name nor display name?
so i know this isnt exactly about about spigot but im very desperate. im using this https://github.com/ronmamo/reflections library to scan for all classes in a package
the problem is that not all are found, just a few.
my code looks like this
Reflections r = new Reflections(packageName);
Set<Class<? extends LitCommand>> commands = r.getSubTypesOf(LitCommand.class);
System.out.println("found " + commands.size() + " commands");
am i doing something wrong or is there a better way to do this, a way that actually works?
Why do this?
u askin me?
Yeah
to register commands
Feels like it would be much easier just streaming through an instance of every command and then register it so some lookup
i dont want that plugin.yml bullsht where i have to list all the commands, also i dont want to register the commands manually. so i wrote this epic annotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EzCommand {
String cmdName();
String usage() default "";
String description() default "";
String permission();
String[] aliases() default {};
boolean hasPermissionByDefault() default false;
}
i did that, thats the ez part
but i need to scan the package for all the commands i want to register
and i dont know an ez way to get all the classes in a package
Unorthodox but what do you pass as package name and what do you mean by just a few
here it says to use version 7
https://worldguard.enginehub.org/en/latest/developer/dependency/
but here there is only up to version 6
https://maven.enginehub.org/repo/com/sk89q/worldguard/
anyone knows where to get the 7?
well with package name im refering to a string. i have around 30 commands but only 9 register and i dont see a pattern why these 9 but i think its always the same
Yes Idk either, don’t have much to go on right now
I meant what is the string content
No what’s the actual package name you’re passing?
me.derwand.epicplugin.cmd.cmds
Okay looks alright on that front
How about you show me the base class and then one class that got added and one that didn’t
sure 1 second
so this one got added
package me.derwand.litessentials.cmd.cmds;
import me.derwand.litessentials.cmd.EzCommand;
import me.derwand.litessentials.util.LitCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@EzCommand(
cmdName = "test",
permission = "lit.test",
description = "just for testing",
usage = "/test"
)
public class TestCmd extends LitCommand {
public TestCmd(String name) {
super(name);
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
return null;
}
}
this one not
package me.derwand.litessentials.cmd.cmds;
import me.derwand.litessentials.cmd.EzCommand;
import me.derwand.litessentials.util.LitCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.management.ManagementFactory;
import java.util.List;
@EzCommand(cmdName = "mem", permission = "lit.mem")
public class MemCmd extends LitCommand {
private static final double MB_SIZE = 1048576d;
public MemCmd(String name) {
super(name);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
double jvmMax = Runtime.getRuntime().totalMemory() / MB_SIZE;
double jvmUsed = jvmMax - Runtime.getRuntime().freeMemory() / MB_SIZE;
double systemMax = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize() / MB_SIZE;
double systemUsed = 0d;
sender.sendMessage("§6MB jvm memory used, max: §a" + (int) jvmUsed + ", " + (int) jvmMax + "\n§6MB system memory used, max: §a" + (int) systemUsed + ", " + (int) systemMax);
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
they both extend litcommand so they both should be found
litcommand is some garbage thing i wrote 3 years ago or something
Oh it’s fine not reviewing code here
Read up (:
Anyways do you import or reference the 9 classes that do get added anywhere
As opposed to the 21 others
nope
i was thinking maybe they get optimized out because they arent used at all
but they dont
And all classes are in that package of yours?
yes all the commands i want
Yeah cuz it won’t scan transitively
Because you’re using the system class loader
You probably have to MainPluginClass.class.getClassLoader() and do it from there
i did that but now it finds 0 commands
is getChunkSnapshot an expensive method?
i added a peek and nothing shows up
public Set<Class> find(String packageName) {
InputStream stream = LitEssentials.class.getClassLoader()
.getResourceAsStream(packageName.replaceAll("[.]", "/"));
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
return reader.lines()
.filter(line -> line.endsWith(".class"))
.peek(System.out::println)
.map(line -> getClass(line, packageName))
.collect(Collectors.toSet());
}
Try ClassPath.from(MainPluginClass.class.getClassLoader())
.getAllClasses()
.stream()
.map(ClassInfo::load)
.filter(cls -> cls.isAssignableFrom(LitCommand.class))
And then do whatever u want
Might be LitCommand.class.isAssignableFrom(cls)
I never remember which one to invoke it on
k ill try both
when i use ItemMeta#setDisplayName() it makes it italic
how can i make it not do that
Not particularly I believe
could someone help me figure out what in the world is going wrong? i keep getting this error and i've reworked my plugin.yml/pom, but nothing's changing
https://pastebin.com/4ycg8Z7K
okay it kinda does something now
Hmm what if u use JavaPlugin#getClassLoder instead
nono the class loader thing works now
Make sure your main: in the plugin yml is spelled exactly how it is in your hierarchy.
it does find my things now, but i still get an error: https://paste.md-5.net/verequqocu.md
Actually getAllClasses might be picking up every class
ye there are things like hashmaps n stuff
would it be src.main.java ---- then my stuff, or just me.affinity.xyz.Main ?
Filter the ClassInfo#getName by getting the package
because i've tried both lol
And then yeah
Second one
Hello i'm trying to create NPC but i have a problem, if i spawn an EntityPlayer with packets, with UUID of a connected player, the model of the entity don't spawn. It work fine if i used another UUID.
Someone already have this problem ?
i have this code now
List<Class> commands = ClassPath.from(Essentials.class.getClassLoader())
.getAllClasses()
.stream()
.map(ClassPath.ClassInfo::load)
.filter(cls -> cls.isAnnotationPresent(EzCommand.class))
.peek(System.out::println)
.collect(Collectors.toList());
but im still getting this error: https://paste.md-5.net/oduvoyevat.bash
how to give out experience? giveExp() does not work
i just used another class thats not the main pl class and it found (all?) commands, but i still get this error when collecting: https://paste.md-5.net/xibusifuci.md
Try what I said earlier btw
Oo pog
thanks alot guys
That was some effort for me also but yeah cool it works now
finally i only have to declare my commands in a single place
excuseee mee
🥴
why edit multiple files when u can just add an annotation
@EzCommand(
cmdName = "test",
permission = "lit.test",
description = "just for testing",
usage = "/test"
)
Cuz it’s not very object orientable imo
quick to throw some commands together, i always forget to either register them or to put them in the plugin.yml
what do you mean
Yeah well frankly same but I have IntelliJ yelling at me the class is unused then
i think object orientation makes sense in certain places and in others it doesnt
ye but intellij also shows an option to ignore unused warnings when annotated by a specific type
If you want annotation based commands just use ACF lol
ACF is bloat
Well considering that annotations are metadata merely we still have the ability to create powerful abstractions with classes, I guess inheritance works also with annots but it’s quite limited as annotations are constant.
it sure can do more but i just need it the simple way, i didnt know it would be so much trouble to figure this out
Yeah well I believe reflections should have worked but apparently not
i've restarted my server and rebuilt the .jar with changes but no dice. could my pom.xml have anything to do with it? https://pastebin.com/qvH0vqDB
Nobody know about npc skins problem i send earlier ? :/
Can you bump it xD
coded red does some stuff with npcs... not sure if it's what you need tho
This one
how can I change the amount of experience for a player?
I would highly recommend and strongly advocate you to use citizens instead of doing it yourself, it handles everything literally for you.
Player#setExperience I believe
there is no such thing
no
Yes
error
Yeah but i like try to do thing by myself ^^, and the npc work, i have juste a probleme when two EntityPlayer is rendered in client, one cannot be seen :/
It can be a NPC and a Player with same UUID or two NPC with same UUID, i can see juste one
this changes the scale, but I somehow managed to change the experience
How can I get clicks on a BoundingBox I created myself?



