if(!player.getWorld().hasStorm()){
player.getWorld().setStorm(true);
}
if(player.getWorld().hasStorm()){
player.getWorld().setStorm(false);
}
``` Is something incorrect about this, that it doesn't disable the storm when there is one
#help-development
1 messages · Page 1505 of 1
"dun"?
Don't
Lol
Like say i have a shield in hand when I interact with a block
I can't cancel shield use
player.getWorld().setStorm(!player.getWorld().hasStorm());
coding tip to invert booleans
whats the difference? it looks he same to me
because im searching everywhere and there's not much
its the same result but cleaner
will this disable the rain? bc currently thats the error
what are you trying to do
well you right click the item, and if its no rain it will turn rain on. but if it is raining it will turn it off
rn it doesnt turn of the rain when u click it again
show the entire code
we can't rule out anything if you're just gonna show the part where it toggles storm
its a lot....
please don't tell me it's full of if statements
send the entire class
yeah
have you put the @EventHandler annotation abovei t
yeah
because it wont work if you dont
Is there a way to delete a worlds chunk and have it regenerate?
I expected a few hundred lines from what you were saying
my main file is 400 rn u said main class. and i wasnt going to do that lol..
# pseudo
on playerinteractevent:
if player doesn't have myItem: return
player.setPlayerWeather(player.getPlayerWeather() is WeatherType.CLEAR,
if true WeatherType.DOWNFALL
else CLEAR
)
@sacred vector
also your code is really messy
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.
oh no that part isn't done, im adding it to the config to toggle if you want it enabled or not
ye
.isBlocking() i think of HumanEntities
Delayed
so do i cast the player to HUmanEntity?
ye, i know shields would always have something like a 250ms delay
Thought Player Is-A HumanEntity
Still, you don't need the ==true because it will still check if it's true. if(!getConfig.getBoolean("Some boolean")) { Is to check if it's false.
Packets brrrr
Need help, how i get a string from a class command to another class (but the string is args[0])
I'm the best programmer 10/10
lol
one of my personal fav methods https://cdn.rackdevelopment.tech/img/TxYzihryOO.png
Dependency Injection would be the best way.
👍
Dear god wtf is that I hate u
jesus christ that method name ifIronDoorThenGetBlockUnderTheDoorIfNotThenReturn
didn't know you could do
fuckyou
.fuckyou()
.fuckyou();
Prob what setBlock command looks like ngl
I fucking hate u
does continue go to the next iteration loop or does it break the entire loop
Return returns
Yea end everything
NamespacedKey.minecraft("sharpness") does not work
Deprecated i think
no, protection and unbreaking worked for me
i just figured out that the reason why it wasn't working is that i forgot to add the two to the list
i was being an idiot
the problem was so simple
lol
does anyone nkow how i can make a .yml file come with the plugin other than it being config and plugin
Search create custom config spigot
i did htat and opera crashed
Add as part of <include> if maven
i had too many tabs open
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
in that
well damn
U put static
but there's a getter for it
Whhyyyyy
what was i supposed to do
try not to abuse static
oh
Pass instance to other classes using constructor
read the messages above
lol
what do i do
:/
first i was told to do singleton method then i'm told to pass it to other classes
wtf
Don't use static please
for plugin instances, both are valid methods but the latter is arguably better
otherwise, you should NEVER use static
What’s wrong with static?
electricity
lol
Nothing is wrong with static if you understand when to use it
doesn't really matter here tbh, but it just makes people feel better to not 😛
Ah ok.
there are some cases where its useful
like utility methods
arguably some things which suppose to belong to a plugin instance
Lol, it is plenty useful
just dont abuse it
Yeah
what od i do
I am trying to make a plugin that give different effects to the player on consumption. However when I eat any of the foods it give me all the effects that are listed within the program. Rather than just giving the individual effects. If someone could check to see what is wrong I would greatly appreciate it. Thanks.
plugin instance method can be static
Don't make blanket statements on things you should/shouldn't do not knowing what someone is doing 😄
create a class that contains all of it and then make getters?
which are non-static?
then make the stuff accessible using constructor?
No but it is true. In his case specifically static should not at all be used as the visibility can be lowered down to its own specific instance
which promotes OOP concepts
and i dont want to go into a full explanation about it
so thats why i just say "dont use it"
¯_(ツ)_/¯
No pass through constructor of other classes the plugin instance
cause most beginners just like
dont know how to use it correctly
and later on they will learn how to use it correctly
then getInstance().getCombatList() etc etc?
have you tried else if, though I dun think that's the main problem
yep
@quiet hearth ItemStack#getMaterial
that is actually the first thing i tried believe it or not
i'm not sure if intellij is broken or not
but it's just showing up errors
and i'm sure i did nothing wrong
which is why i just resorted to "abusing" static
not knowing that it's actually a very bad practice
getMaterial instead of getItem?
🏖️ resort
speaking of resort i went on an outing yestrday iwht my family
who cares
U need to pass in the instance to the other classes via constructor and make a field in that class to set that in the constructor then use that field wherever u use the instance
Sorry I can't explain it well XD
getInstance() method or get the plugin by class' constructor (pass plugin as argument)
U know what I give up
Ok
Did u not read what i said
@quiet hearth
Why are you comparing the the ItemMetas instead of just the Material?
Also store some variables so you don't have to keep re-getting them
I have this ```java
File file = new File(pluginFolder + File.separator + subPath + fileName + ".json");
File filePath = new File(pluginFolder + File.separator + subPath);
filePath.mkdirs();
if (!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(main.toJSONString());
fileWriter.flush();
fileWriter.close();
What's pluginFolder =
needs a bit fixing up
what he meant was
public class BestPluginInTheWorld extends Plugin {
onEnable{
.....new BestListener(this),....
}
}
I see you used File.separator, but why not in the rest of the places?
Is it just me, or did 1.17 break hex colour support
Idk
It's JavaPlugin not Plugin?
its a placeholder
he was just giving an idea
Ok I got rid of checking the metas, but is there a way of making a potion effect variable then editing its values later in the code
Lol
referring to the conversation a bit ago about static, just asking because I use static methods a lot in my plugin for stuff like casting specific spells and starting repeating tasks, why is it bad?
If I understand you correctly, no
Then what did you mean by storing variables
static use is case-by-case tbh, if you think that variable is subject to the instance of the class, then doesn't make sense to use static
It's not considered OOP. There are plenty of valid use cases for static though (I use it a ton for utility classes)
Player and Item or the Item's Material
Player player = event.getPlayer();
Material material = event.getItem().getType();
Store those above all your if checks
this.pluginFolder = this.plugin.getDataFolder().getAbsolutePath();
Yeah jtx I can't help u
aw
This sounds dumb, but it might have something to do with getting the absolute path. I don't use that in mine. Just use the getDataFolder()
worth a try
ah alright ty
nope doesn't work
Can you share your repo or more code surrounding that?
public class JsonHandler {
private Volzo plugin;
private String pluginFolder;
public JsonHandler(Volzo plugin) {
this.plugin = plugin;
this.pluginFolder = this.plugin.getDataFolder().getAbsolutePath();
}
public void writeJSON(String fileName, String subPath, String object, String value) {
JSONObject main = new JSONObject();
main.put(object, value);
try {
File file = new File(pluginFolder + File.separator + subPath + fileName + ".json");
File filePath = new File(pluginFolder + File.separator + subPath);
filePath.mkdirs();
if (!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(main.toJSONString());
fileWriter.flush();
fileWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
What are you passing into to writeJSON? This should be working fine with the right inputs
jsonHandler.writeJSON("playerData", "data","t", "w");
Make sure you add an extra File.separator in that case here:
File file = new File(pluginFolder + File.separator + subPath + fileName + ".json");
to
File file = new File(pluginFolder + File.separator + subPath + File.separator + fileName + ".json");
That appears to work for me. What do you get as a result?
So apparently Player.getItemInHand() is a deprecated method, is there a reason it is deprecated/is there an alternative?
there's two hands now, so there's a getItemInMainHand and getItemInOffhand
it works
ah
thanks
For future reference, if you ctrl+click into a deprecated method, it usually tells you the replacement or reason it is deprecated. Or even hover over it (at least in Intellij)
it looks like getItemInMainHand is not a method, at least in event.getPlayer which returns a Player object
See my previous comment, it specifically mentions they are in PlayerInventory
What are you trying to do?
Set an NBT tag which indicates that the block cannot be broken by a player who is not an operator
?paste
java.lang.IllegalArgumentException: Cannot make player fly if getAllowFlight() is false
player.setAllowFlight(true)
How do I download 1,17 from the website
the server link
?buildtools
?bt
do i replace the buildtools with server?
with server.jar
What's the difference between setFlying and setAllowFlight?
No you use build tools to build the jar
Ok
so I did that and opended it
one allows them to fly one sets them as flying
lmfaoo wheres the file at im so lost
You can't download the server jar directly. You have to build it with the build tools
Could we hop in a vc rq? I just want to screenshare
Steps:
1. Place the BuildTools.jar file into an empty folder.
2. Open gitbash or which ever console program you prefer.
3. Type the command to run build tools and make sure to enter the version you want. (version 1.17 requires java 16)
Please don't DM me, follow the directions listed
hey guys how do I loop trough all the numbers in a multiplication (example: 2x2 = 2, 3, 4) (example: 3x3 = 3, 4 ,5 ,6 ,7 ,8 ,9)
Why the bold?
Does anyone know how long you have to wait to remove a NPC for its skin to always show? I have tried 50 ticks but that works only 75% of the time.
//example 8*12
for(int i=Math.min(8,12); i <= (8*12); i++; {
// System.out.println(i);
}
so for example for 4*19```
for(int i=4;i<=19;i++) {
sysout(i);
}``` would that be it?
pretty sure there is no real good way to do that besides maybe looking at citizens' implementation but i can't really exactly remember how they do it. but all I know is that even their implementation doesn't always show the skin even with their entity tracking implementation
No that loops from 4 to 19 inclusive
oh ye i see mine is shit
forgot to multiply lol
i was never really able to figure it out on my own yet either
thank you so much 😄
Np
What is the new package for net.minecraft.server.v1_16_R3.Blocks.AIR.getBlockData()?
net.minecraft.world.level.block.Blocks.AIR.getBlockData() shows AIR cannot be resolved or is not a field
How come when I do /fly and on the ground while having fly enabled it apparently false
you have to setAllowFlight to true...
I did
Show new code
setAllowFlight(true) is the method that allows you double jump to enable flying.
if its false you can't fly
send your pom.xml i guess
I don't use builders
that makes sense
Won’t be mapped, so AIR is now likely a random letter variable
Figures... Mojang is always breaking things.
yeah if you want to use deobf class/field/method names you need to dev against the deobf and remap with the specialsource maven plugin
Nah that was spigot
LMAO
literally not mojang
Ok same for spigot then. Always breaking things LMFAO
You should read the entire 1.17 post
You can use a Mojang mapped version and then remap it on compile
But that won’t support reflection strings and whatnot
mixins 😌
If only
Any on player death event?
What
well is there any event that gets dispatched when a player dies?
Have you looked at the docs? https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/PlayerDeathEvent.html
Oh, its in org.bukkit.event.entity and not org.bukkit.event.player
oh god
I mean, there's a search bar
Yes, it subclasses the entity death event
My Intellij also gives all the events for players when you type PlayerEvent. Gotta love a good IDE
I'm setting killstreak to 0 by default but it stays at null ```java
public static Map<UUID, Integer> killstreak = new HashMap<UUID, Integer>();
public void addToKillstreak(Player killer) {
UUID uuid = killer.getUniqueId();
killstreak.put(uuid, 0);
if (killstreak.containsKey(uuid)) {
int kills = killstreak.get(uuid);
kills++;
killstreak.put(uuid, kills);
} else {
killstreak.put(uuid, 1);
}
}
killstreak.getOrDefault may help you here
That’s not possible
getOrDefault either returns the value in the map, or the default
might of fixed it
Unless you explicitly put null into the map
map.merge(uuid, 1, Integer::sum) mmmmmmmmmm
That is also useful
oh no
that's like 8 out of 9 lines condensed into 1 lol
PlayerDeathEvent getEntity() returns the person who killed the player right
No it returns the dead player
Player#getKiller
hey guys when i do for(int i=0; i<totalLength;i=+1) { it loops everytime but it never does + 1 (I've tried with i++) doesn't work either
+=1
Should be +=
or ++
Is totalLength > 0
int totalLength = 10;
do you have a break;
nope
i=i+1;
e.getPlayer().sendMessage("normal: "+ String.valueOf(i));
for(int _i=Math.min(data.getLoc(), data.getLoc()+fish.getLevel().lenght); _i <= (data.getLoc()+fish.getLevel().lenght); _i=+1) {
_i=_i+1;
e.getPlayer().sendMessage("not normal: "+ String.valueOf(_i));
if(i== _i) {
if(cursor.loc == i)
{
label = label+ChatColor.BLUE + "|";
}
else
{
label = label+ChatColor.GREEN + "-";
}
}
}
if(cursor.loc == i)
{
label = label+ChatColor.DARK_BLUE + "|";
}
else
{
label = label+ChatColor.RED + "-";
}
}```
the player.sendmessages are just for debugging
For loop with no break, infinite loop danger
For loop with no break is pretty common
it says its 0
even with this code?
as in, wat does this code print? 0 too?
Doesn’t just importing a class that doesn’t exist throw class not found
Its not importing
Oh right
Hence why the top one works. I just don't know why the bottom one doesn't for some reason
Duh
When handling an AsyncPlayerChatEvent, what is the best way to retrieve information about a player synchronously and then use that data to set the chat format?
no
Don’t know, check if the 1.9 check is somehow passing
I can't when the class loads it errors
Are you sure you haven’t imported something
But if I comment 1.9 out it will say its missing 1.10 lol and so on up to 1.17
And this is why I never let two NMS versions exist in the same class
None are imported
normally when I do this I would have loaded n.m.s.%s.***, if you get what I mean
which works all the way up to 1.16.5
1.17(+) uses net.minecraft.network.sth i forgot
I reflectively load a NMS Adapter class based on version
This code is old lol... And I don't want to sit here for a few hours doing reflection
sooo??? anybody knows?
it could be worth the time ngl
My other plugin uses reflection but I would have to recode over half this plugin to use reflection.
private void initializeNMSAdapter() {
String version = VersionUtils.getServerVersion();
try {
adapter = (NMSAdapter) Class.forName("me.jishuna.challengeme.nms.NMSAdapter_" + version)
.getDeclaredConstructor().newInstance();
getLogger().info("Version detected: " + version);
} catch (ReflectiveOperationException e) {
getLogger().severe("Server version \"" + version + "\" is unsupported! Check the plugin page for updates.");
getLogger().severe("Plugin will now be disabled.");
Bukkit.getPluginManager().disablePlugin(this);
}
}```
Works for 1.16 and 1.17, and I assume anything else
ANYONE WANNA HELP?
did you make sure you replaced with newly compiled plugin and reloaded the server?
try this
for(int i=0; i<totalLength; i++) {
e.getPlayer().sendMessage("normal: "+ i);
for(int _i=Math.min(data.getLoc(), data.getLoc()+fish.getLevel().lenght); _i <= (data.getLoc()+fish.getLevel().lenght); _i++) {
e.getPlayer().sendMessage("not normal: "+ _i);
if(i== _i) {
if(cursor.loc == i)
{
label = label+ChatColor.BLUE + "|";
}
else
{
label = label+ChatColor.GREEN + "-";
}
}
}
if(cursor.loc == i)
{
label = label+ChatColor.DARK_BLUE + "|";
}
else
{
label = label+ChatColor.RED + "-";
}
}
I'll try
I only changed the ++ and removed the String.valueOf
cuz for string concat not neccessary
I'l ltruy
Please rename _i at some point too
Yeah, that is painful to read. Pretty sure the standard is to go i->j->k, or make it more specific to what you're actually doing
I J K are generally only for the value in a for loop
yup, but never _i
Descriptive names should be used otherwise
cool kids uses .forEach
Or just go full manual obfuscation and name it iliiliiililiii
wat if the first person who popularized the use of i intended it to be roman numeral
ngl that looks pretty clean
at least you do not have this
god knows what is above
Nope, apparently we can blame fortran for their limited integer variable naming
Don’t catch generic exception
Replied to the wrong message
Java has ReflectiveOperationException for convenience
doesn't this just contradicted catching generic exception
lol
LOL
ReflectiveOperationException tells the reader that this code can throw various exceptions because of reflection
Exception tells the reader it could throw any dang exception under the sun
oh, you meant generic as in Exception
Yes
does it work?
Whats worse is the error doesn't say the exact line... its just says the line the creates the class.
Any object that implements comparable has compareTo
Uggg so annoying. I've tried moving the method around the class, using switch instead of 'if', etc... I can't figure out why one method works and the other causes a class not found exception.
wat I mean is, is there a method that compares versions, like 1.8.9 < 1.9 sth like that
analogous to compareTo
wait, can you actually just compare the string...
You would have to write your own to compare them without the string
you can wtf
surprise how no one said string comparison works, but the solutions here solves 1 == 1.0 so are better
nvm im dumb
string comparison doesn't work
How would I make it so that a player can't dismount a mount, but if they try it ticks up a counter?
Use the dismount event
tried but canceling doesn't cancel the dismount
Iirc it’s cancellable, if not just mount them again a tick later
Or even the same tick may work
I tried that but tbh could just be my spaghetti code that I made 6 months ago and so now I'm recoding it.
i think someone else had the same issue a bit ago and for some reason it desyncs so the player dismounts client-side but not server-side
Makes sense
The client doesn’t wait for the server to tell it it’s allowed to dismount
You could probably just send a mount packet back
What
When a player dismounts the client just assumes it will succeed, you could probably fix this by sending a mount packet back when you cancel the event
Or you could just not cancel it and manually mount them again
I don't think it does assume it though
I don’t see why it wouldn’t
Because I've had situations where i can't dismount because the server is lagging/crashing
95% sure it does wait for a packet
if you cancel an event it stops running the listener at that line right?
Nope
[How to make sign gui for input string WITHOUT PROTOCOLLIB? :D] Hello! I was making it yesterday and I tried to make it by searching for threads and resources (API) and most of them were using protocollib. I tried to make with a non-protocolib api, but I encountered several problems. And I flew for as long as four hours. And I cried. How do you simply create a signgui (If the player closes it, he can get the string written on it.) without protcolib? it uses PacketPlayOutBlockChange and PacketPlayOutOpenSignEditor First of all, I can open the sign on the API I'm using. But I can't get a text message when I close it.
[Not an answer to your question D:] Hello! I don't know!
how to continue a for loop when you get out of a for loop inside of it???
but only if you exited the first one before
that sounds like bad code structure to me
mhm
so that's my code for(int i=0; i<totalLength; i++) { for(int _i=Math.min(data.getLoc(), data.getLoc()+fish.getLevel().length-1); _i <= (data.getLoc()+fish.getLevel().length-1); _i++) { if(i== _i) { e.getPlayer().sendMessage("_i: " + _i); if(cursor.loc == i) { label = label+ChatColor.BLUE + "|"; break; } else { label = label+ChatColor.GREEN + "-"; break; } } } if(cursor.loc == i) { label = label+ChatColor.DARK_BLUE + "|"; continue; } else { label = label+ChatColor.RED + "-"; continue; } }
but you could use a boolean outside of the loop and set to true when you break
ooh good thinking
Hello, saterday I updated my plugin to 1.17 but some users are getting these errors, when they type /shop it should open the main inventory but here it crashes the server, is this a problem with the plugin or the server?
?paste holy fuck
thank you 😄
wrong channel
hmm, the one where you can get help for your server maybe
Well, idk if this is a problem with the server or the plugin so thats why I posted here, but I will move it
If you didn't make the plugin it doesn't go here
Well, Im the dev
loll
So, is this a server issue or a issue from the plugin?
It looks to a server issue to me but can't say that for sure
They're both on spigot 1.17 servers if you need that.
public class EntityDamageListener implements Listener {
private KitSelector plugin;
public EntityDamageListener(KitSelector plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
final int combatTagTime = this.plugin.getConfig().getInt("combatTagTime");
HashMap<UUID,Integer> combatTagList = this.plugin.getCombatList();
public static void onInterval() {
Map<UUID,Integer> tempCombatList = new HashMap<>();
for (UUID id : combatTagList.keySet())
{
int timer = combatTagList.get(id) - 1;
does anyone have any idea why this is producing "cannot be referenced from a static context"
(combatTagList line)
nvm
i didn't notice method was static
it looks like for some reason it's trying to get the first argument even though there are none??
you could see what happens if you put /shop (something)
beeeeecause it's static and the other stuff is not?
we would need the code to proof that
I have a waterfall server to which I want to connect the server with mods, I was able to connect this server but players on client forge are kicked from the server because the server detects that they have pure minecraft , is there anyone able to help me?
Main.getPlugin(Main.class) wow that's a really good way to get the instance!!
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (hasAccesInWorld(player)) {
if (args.length == 0) {
if (player.hasPermission("EconomyShopGUI.shop")) {
GUIShop.openMainShop(player);
} else {
player.sendMessage(Lang.NO_PERMISSIONS.get());
}
} else if (args.length == 1) {
boolean found = false;
for (String section : plugin.getShopSections()) {
if (args[0].toLowerCase().equals(section.toLowerCase())) {
if (player.hasPermission("EconomyShopGUI.shop.all") || player.hasPermission("EconomyShopGUI.shop." + section)) {
GUIShop.openShopSection(player, section, 1, disableBackButtonWithShopSectionCommand);
} else {
player.sendMessage(Lang.NO_PERMISSIONS_TO_OPEN_SHOP.get());
}
found = true;
break;
}
}
if (!found) {
player.sendMessage(Lang.NO_SHOP_FOUND.get());
}
} else {
return false;
}
}
} else if (sender instanceof ConsoleCommandSender) {
if (args.length == 1) {
Player p = plugin.getServer().getPlayer(args[0]);
if (p != null) {
GUIShop.openMainShop(p);
} else {
SendMessage.infoMessage(Lang.PLAYER_NOT_ONLINE.get());
}
} else if (args.length == 2) {
Player p = plugin.getServer().getPlayer(args[1]);
if (p != null) {
boolean found = false;
for (String section : plugin.getShopSections()) {
if (args[0].toLowerCase().equals(section.toLowerCase())) {
GUIShop.openShopSection(p, section, 1, disableBackButtonWithShopSectionCommand);
found = true;
break;
}
}
if (!found) {
SendMessage.infoMessage(Lang.NO_SHOP_FOUND.get());
}
} else {
SendMessage.infoMessage(Lang.PLAYER_NOT_ONLINE.get());
}
} else {
return false;
}
}
return true;
}
private boolean hasAccesInWorld(Player player) {
if (disabledWorlds != null && (!disabledWorlds.contains(player.getWorld().getName()))) {
return true;
} else {
player.sendMessage(Lang.COMMAND_DISABLED_IN_WORLD.get());
return false;
}
}
?paste
holy shit
is it not?
it's a terrible way
well first of all the main class is named Main
second of all you're not doing dependency injection
third of all you should make a getInstance method if you're set on using a static singleton
since getPlugin is generic too...
like this ? 😭 ``` static Main getInstance;
public void onEnable() {
getInstance=this;
best way to learn
then like that ? ``` static Main instance;
public void onEnable() {
instance=this;
getServer().getPluginManager().registerEvents(new FishEvent(), this);
getServer().getPluginManager().registerEvents(new RightClickEvent(), this);
}
public static Plugin getInstance() {
return instance;
}
that's a lot of messages for very little information
sorry
but im trying to get this done
so for this code it says its not right ```BossBar bossbar = Bukkit.createBossBar("BossBar", BarColor.GREEN, BarStyle.NOTCHED_10, BarFlag.CREATE_FOG);
no idea whats wrong
what's the actual error
@sage swift I've seen a couple of messages from you and you don't come over too helpful. For your own pleasure, I would like to ask you to not respond if you are not willing to help out here in a normal manner
are we in a manor? (the message above used to say "in a normal manor")
uh oh discord police
gecko how long you been coding for ?
1 day at least
damn 😳
@quaint mantle Could you summarize your issue?
its says the arguments are not applicable for the constructor
what are you trying to do with the bossbar
Where does it say this?
if you're just creating it, it should not be erroring
BossBar bossbar = Bukkit.createBossBar("BossBar", BarColor.GREEN, BarStyle.NOTCHED_10, BarFlag.CREATE_FOG);
bossbar.setTitle(ChatColor.GREEN + "That Close to catching the fish");
bossbar.setProgress(data.getScore()/fish.getLevel().winScore);
bossbar.setVisible(true);
bossbar.addPlayer(e.getPlayer());```
if you want a screenshot: https://gyazo.com/0728d65cb6dc0a80c0b78694190422f0
then clearly it's either an old version of spigot or something else is wrong
I got the 1.16.5 so I don't think that's the problem
if you remove the line does the error persist elsewhere
well yeah
What exact parameter in createBossBar gives you the error?
I see you are importing from BossBattle
You have to fix your import and import from the right package
lol
yes sorry for lying D:
about my name
and how do I remove my bossbar from the player once I'm out of the method
bossBar.removePlayer
there aren't any methods to remove it from the player?&
I think this can help you out: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/boss/BossBar.html
declaration: package: org.bukkit.boss, interface: BossBar
Eventhough it is the documentation of 1.17, it is still very similar
how could i make a real time 5 mins delay for this event
@EventHandler
public void onHoldingShift(PlayerToggleSneakEvent event){
Random random = new Random();
int rannum = random.nextInt(99);
int z = rannum++;
if(z==1) {
Now I'm encoding the itemstack in base64 but it has very long text size, is there any way to adjust it?
Using a scheduler is the way how I would approach it
I did this because I needed to store the item data in the database.
ok ty
Either use a repeating scheduler to keep track of a timer or just delay the scheduler by 5 minutes
Both should work, but it also depends on how you would like to make it work
I have heard lots of times before it is not recommended to save the entire ItemStack as a string
What I did is only save everything that is necessary to retrieve the ItemStack object back from your database
Like this right? ItemStack{GRASS_BLOCK x 3}
You can make an object in Java that holds this necessary data
Then you can use GSON to convert the object into a string
Okie thank you
You can optionally convert this GSON into base64, but this is not recommended for bigger strings, because then the string becomes bigger than the actual GSON
And then just save the string in your database and deserialize it to the object in Java once you need it again
In the object you can even make a static method or whatever which builds back an ItemStack instance
You add them to a map<player,long>
Using current time millis then you calculate next time they do it
yes thanks, im finding it out
A task is a no go for something 5 minutes long
Runtasklater is definitely not horrible tho
i made this
if(cooldowns.containsKey(player.getName())) {
if (cooldowns.get(player.getName()) > System.currentTimeMillis()) {
long timeleft = (cooldowns.get(player.getName()) - System.currentTimeMillis()) / 1000;
return;
}
}
cooldowns.put(player.getName(),System.currentTimeMillis()+300000);
inside of the
@EventHandler
public void onHoldingShift(PlayerToggleSneakEvent event){
Random random = new Random();
int z = random.nextInt(101);
if(z==1) {
do i have to put any thing else in
Check if there in the map in togglesneak
And I recommend you use Threadlocalrandom.current().nextInt
or double rand = ThreadLocalRandom.current().nextDouble(101)
like this ?
What are you even using it for?
There’s a 1% chance of this happening whatever you’re trying to do
idk u told me to
give player item
yeah no, use the pastebin
?paste
So why are you making it a 1% chance to give the item?
Yea haha I’m just confused
There is a 1% chance that if statement will run
i made 20 copy of them so it actually 20%
20? Why
and it go from 1 to 100
like % giving item
or loop it
No don’t loop here
someone said that loop could make server go nuts
someone just lied to you
wish i meet you earlier
i typed from 1 till 100
Lol jesus bro, no you really will never have to do that
btw
this is the end of that 100 list
if i put the cooldown here
inside the onSneak event
will it actually make a cooldown
or it just go nuts
And that loop would be pointless it doesent do anything in this case. You want to check before you run any code btw
So at the top of the event
You do your cool down check
"how to make a mess in 10 minutes"
I don’t think the tutorial made you type out 100 different if x==whatever
i think that out
You just over thought
im nuts
ok
so, i am trying to make a custom recipe with the event: PrepareItemCraftEvent, but it only works when i drop single items in the slots with rightclick
this is my code:
public void onCraft(PrepareItemCraftEvent e){
System.out.println("ran");
//used to track how many slots have diamonds, if 4, we go!
int diamondCount = 0;
for (int i = 0 ;i < e.getInventory().getMatrix().length; i++){
try{
if (e.getInventory().getMatrix()[i].equals(new ItemStack(Material.DIAMOND))) diamondCount++;
} catch(NullPointerException nex){ }
}
System.out.println(diamondCount);
if (diamondCount == 4) e.getInventory().setResult(Items.COMPACTED_DIAMOND.getItem());
}
so, it doesnt work when shift clicking, and this is the first time that i am creating custom recipes, so i really have no idea how to do this..
Yw
Spigot API already has the ability to add custom recipes. No need to use the event
yes, i just found out, thats for replying though
but, is it possible to , for example: i have a square as recipe, can i register that recipe as a square, or do i need to make 4 recipes, one for each possible square on the craftingtable?
shaped recipes already account for that, you can just leave the 3rd column and row empty
ah, thatnk you, that was my question :)
god darn this has just become a whole lot easier
yeah lmao sometimes messing with the craft event can be really iffy
yup
for(Field f : packet.getClass().getDeclaredFields()) {
System.out.println(f.getName());
f.setAccessible(true);
System.out.println(f.get(packet));
f.setAccessible(false);
// }``` this code prints the values of all the fields and WORKS, but for some reason:
```if(pl.getInteractionManager().getValue(packet, "action").toString().equals("INTERACT_AT")) {
return;
}```
```public Object getValue(Object packet, String name) {
Object result = null;
try {
Field field = packet.getClass().getDeclaredField(name);
field.setAccessible(true);
result = field.get(packet);
field.setAccessible(false);
} catch(Exception e) {
e.printStackTrace();
}
return result;
}```
doesn't work. anyone have ideas? ive been struggling with this same problem for 2 days now.
the getValue returns null btw, but i cannot figure out why
oh lol
How can I make something like, This reload took ...ms?
You can do it in the spigot itself idk how to do it outside of it. I recommend just not reloading :3
huh, i want to make a reload command
to change things without restarting the server
and it will only reload my plugin
not the entire plugin
and only reload the necessary things
when you are talking about reload, do want to represent changed classes ?
like, your plugin was recompiled/has changes?
or just reload configuration
no no, i mean i want to do something like reinitialize the config value
yeah reload configuration
but i want this
long startTime = System.currentTimeMillis();
do reload
long timeTaken = System.currentTimeMillis() - startTime;
ah alright, thanks
Thx
Hi everyone, is using custom events a good practice for performance ? And more over, i find difficult to understand if getPluginManager().callEvent() does it sync or async
the method does both. Calling an event using that method while off the main server thread will fail if the event requires to be called on main thread.
So if the event is specified to be async it will be called in an async manner without blocking the main thread, otherwise it will be sync in the main thread ?
no, the caller of the callEvent method has to call off main thread for off main thread events etc
What is the way to add the remapped jar to the m2 repo?
Like most methods it depends on the caller.
--remapped
So for example, if i have this code in a CommandExecutor class, which i guess is called by the main thread, will this event be runned in the main thread ? And more over, does the command function wait for the event to finish before going further ?
case "recent" -> plugin.getServer().getPluginManager().callEvent(
new RequestRecentXEvent(playerUUID, world.getName())
);
lmao - should have guessed
It will be waiting
Code runs linearly when it’s just one thread
And what happens if in the event handler i've set it to handle it in a runTaskAsync ?
Does it still wait ?
Nope
Is this good practice to use events for async operations or are there better ways ? Like calling runTaskAsync not in the event handler but before spawning the event
No generally no need to
Doing small operations like sending a message async and what not is most likely going to hurt performance. Async operations are good for io, big operations like sorting a big list or something like that. But I doubt it’s going to help you in your case as the consumer of the event needs to additionally handle the async execution of the event which might involve the need of using some sort of lock mechanism and what not.
Ok, thanks for your kind answers. Would you generally recommend using events for super-frequently refresh operations or are there better methods ?
Is it more frequent than the player move event?
No, it is not. I guess your question already answers my question.
Yeah and of course if performance is a real problem then you can always try doing it async or using a custom event bus to adjust it.
What do you mean by a custom event bus ? Sorry if i bother, but i'm just new to spigot programming in general
Uh something like luckperms, they don’t use the spigot event api, they have their own event system.
Is it just another thread pool with a queue for events inside ?
Uh I think the biggest difference is that it might not use reflection, I shouldn’t say too much as I haven’t looked at it myself.
Mmmm.. is this worth it tho ? I think the main reason they've done it is to abstract themselves from platform-specific runners, or am i missing some benefits ?
Yes that’s it but if I am correct Lucko has probably optimized it also
Allright, thanks. Just to be sure i understood correctly, it isbetter to run runTaskAsync directly and inside calling the event, than handling it with runTaskAsync on the event handler, so the command or everything else wont have to wait a little bit more
That depends
It comes with the cost of enforcing async as I mentioned above might have other cons
.
Yeah, we are actually using async for mostly everything related to updating a ConcurrentLinkedList, which of course is expensive itself.
As we keep track internally of some data in order for the plugin to work
Well, I for sure don’t know much about your plugin so do what you think is best. You can always change it later.
Thank you, you helped me a lot to understand more of what is happening under the hood of spigot.
i have custom recipe with using meta in ingredients, and this recipe was added to knowledge book. With clicking on recipe i've wrong recipe. How i can fix that?
https://imgur.com/rxu027O
How can i check if player is placing spawn eggs in water?
I cant check if e.getclickedblock is something cuz that returns null
check PlayerInteractEvent
get block
e.getclickedblock returns null when clicking a spawnegg on water
are you using PlayerInteractEvent?
Yep
are you checking action how right click on block?
ye
are you checking if block isn't null?
you can't click water
I can with spawn eggs
it swings hand
and spawns the entitys where i clicked
its like clicking on the block
as far as the api is concerned, you can't
you can't
okay
you may need to do your own raytrace
raycast, yep
No idea what is raycast
searching for blocks in a straight line
google.com for you
Search: Raycast spigot
I have some Questions:
How do i rename an item in a gui?
Is there a Event when player opens inventory?
And: How can i make, that it opens an enderchest when player executes a command?
🙁 Help me please o.o
- Get the item, rename it, set it back 2. InventoryOpenEvent 3. Implement CommandExeucutor, get the sender, safety cast it to a Player, call openInventory iirc.
Tysm!!
OpenInventory iirc?
is that the Enderchest?
Is it possible to add my own packet listener into NMS? Without ProtocollLib because it's not updated
yup, opneInventory
PacketListener?
Yes
check first guide of creating this
yes
Yes because I need to inject it towards a channel handler
you have to inject the player into a reader
true
Yes I know, but how/where?
in Reader/Writer
Which class is that?
its in your listener
just create a class with a few methods, i'll provide an example found on yt
Ok show me
Tysm for your help!!
I have only to find out how to do that with the enderchest x
xd
Now I have a question. I can to create variable recipe with one NamespacedKey(something like any axe recipe)?
define variable recipe
That is not possible
yup
that would be a ComplexRecipe
which is not up for implementation by plugins
so no; you can not change the product of a recipe based on the ingredients
ah, that isn't possible?
Thanks, how to use it?
this is an example, you have to adjust it on what you have supposed to use
k, that's time for copy-paste method ;D
u need to know how the fields are called inside a packet and then adjust the code
You could do it with the PrepareItemCraftEvent in theory
Yes I know the fields
i can not
But then if the packet is sent there is no player online
or i can...
to send a packet you must have your player connected
I only want to listen
So the player pings the server then the server will send PacketStatusOutServerInfo, but I want to catch that
okay, dunno if a pipeline exists just for the server...
Object Oriented Programming?
I think the server also has a pipeline, but how to find that?
i'm trying to find that
Ohhh I think I understand, if the player pings the server it will first send a handshake and then the packet?
I am sorry, but idk how to change the name of the items in the gui? Is there a way to change the item meta
*?
Nah I mean if you click in the multiplayer list on "refresh"
item meta change
Then a packet will be send to the server, and then the server will respond with PacketStatusOutServerInfo
ItemMeta meta = item.getItemMeta();
meta......;
item.setItemMeta(meta);
should be PacketIn then?
sendPacket() can send a Packet<?> so In and Out
tyyy!!
And how does that know which item?
check spigot javadocs about ItemStack
Hm, but how can I catch the packet then?
simply request in google: ItemStack spigot
that is more useful, than ask a question every time
For example https://www.spigotmc.org/resources/pingapi.3829/, this is outdated and does not work anymore, but this is what I mean
can't do that with ServerListPingEvent?
And iirc is enderchest?
I started with this, but that is broken since 1.17
do not use packets for 1.17
that is very bad choose
They are though
They are
but Packets better, but harder
it isn't
so i just use packets. they're currently better
Use prefix and suffix to avoid flicker
this is what i'm doing. but with packets lol
something like that:
https://imgur.com/Wf7IpkJ
Why
texture packs
and special chars
There is already an API for prefix and suffix
that can be without texture packs
okay, i don't like it so i prefer packets
Also https://www.spigotmc.org/threads/packet-listener-using-netty-tutorial.69772/ will also not work because there is not yet any player online
or any string
what... you have to use texture pack
how u display the image
I see why MD put that in the update message now
for displaying image - yes, for displaying any other - no
oh ye that's correct
This is also interesting https://github.com/InventivetalentDev/PacketListenerAPI/tree/1e645029f7dd285c097b37d1b60834235cce90db, but I don't know which part I need
lmao u can use the available api, i don't preferer. what is your problem?
if you have TagAPI with using Packets on 1.17 - call me😉
what's tagapi?
something like that, but without using Scoreboard + TEam
resourcepack doesn't count
on 1.17 PacketPlayOutScoreboard or something like that is broken
1.17 is out from 2 days ago
2-3
and i don't think the packet is broken
we just have to know how to use they. cause they're changed
all network system in 1.17 is remaded
yes. we have to understand how the new system works
You know you don't have to use packets
PacketDataSerializer - now the fear of every NMS'er
lmao u can use the current LIMITED api
i prefer use nms to do all what i want
?
but i dont gonna hate you for what u've choosen
do you know why API is always better than packets?
because API doesnt friggin change every version
or at least that much often as like
NMS
API that uses packets
ye, true, but i like to use nms as they change every version
The API itself has very little changes either way...
If the API is so limited add things yourself lol
SkullMeta#setOwningPlayer
does not work with MHF_Exclamation as offline player, it returns a Steve head. Is there a way to fix?
it is not
i'm doing. using nms lmao
I have a question, how do i make, that the enderchest safes the items in it?
then let me ask you this. Why are there still deprecated Materials in the Material enum?
did u set the meta to the itemstack?
because spigot wanted them for long term compatability and so older plugins are compatible with newer ones
with 1.17 i've remade all possible to remade NMS in my API
Meaning that they are trying to create little change
compatibility maybe, dunno
there is honestly no point, and no reason to do what you are doing
exactly. with fewer major changes between api's there will be more compatability
so that means the api is reliable, and wont change as much
as NMS
Tell it to the creator of ProtocolLib
lmao
ProtocolLib != Spigot api...
My API != Spigot API too
the current API is okay for what most of the ppl do. but for someone is not enough then they gonna use nms
ProtocolLib has a different goal too...
Also, you are freely able to use any version of the lib as long as its supported in your mc version
and Spigot API is focused on making sure
packets have undergone changes no less than NMS in 1.17
that plugins run stable
?
I mean sure, but how is that related
lmao
o.o
and also wdym by no less than NMS in 1.17
an example to use nms: i did the system used in murdermistery to show died players. With the current API that is not possible.
Show dead players in what?
tablist?