#help-development
1 messages ยท Page 109 of 1
if you thenAccept it runs back on the calling thread
Yep java CompletableFuture.supplyAsync(() -> { // code to query Bungee. return result; }).thenAccept((result) -> { // use result. });
I love CompletableFutures
yep I used them a lot just recently
I'm using them in my current project right now ๐
thanks, I was stuck lol
server didn't crash but I did
public InventoryGUI constructGameSelector() {
InventoryGUI gameSelectorGUI = InventoryUtil.createInventoryGUI(null, 54, "Game selector");
for (GameItem gameItem : gameItems) {
SpecialItem specialItem = new SpecialItem(gameItem.getItemType())
.setName(gameItem.getItemName());
BungeeCordUtils.playerCount(gameItem.getServerName()).thenAccept((result -> {
ByteArrayDataInput in = ByteStreams.newDataInput(result);
in.readUTF();
specialItem.setAnimatedLore(() -> String.valueOf(in.readInt()));
}));
gameSelectorGUI.setItem(gameItem.slot(), new InventoryItem.InventoryItemBuilder(specialItem::getAndSet)
.setAction((event -> BungeeCordUtils.connect((Player) event.getWhoClicked(), gameItem.getServerName())))
.build());
}
return gameSelectorGUI;
}```
completablefuture reminds me of doing a lot of async stuffs in javascript, lovely stuffs
not when it crashes me
Thread safety ๐
thanks
Those and promises are pretty analogous, only completable futures are actually good lol
so close to working ๐ฎ
Quick question; how would I get the fortune enchantment from containsEnchantment()? And also get the fortune level? It doesn't exist...
I also don't really want to use lore detection/getLore() either
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html
declaration: package: org.bukkit.enchantments, class: Enchantment
It exist ๐ค
LOOT_BONUS_BLOCKS
Nevermind, found it.
just in time lol
yeah bukkits namings for this stuff is pretty shotty
think its bc old naming in MC itself was pretty shitty too
Theres a wiki with all of the converted names
u gotta return true in the command executor
first do not use label to check command name
its unreliable and not for the purpose
instead check the command name
command.getName()
ah
your issue is this https://paste.md-5.net/orucuzoyul.java#L95
i need to return true; instead?
you are returning false at the end. To fix that, return true in the if statements
or change it to return true
adding an early return would prevent the end return from running if the conditions are met to run those blocks of code
To give a little bit of context, I am working on a Chat that has a cost limit to it's traversal and have implemented the A* algorithm (which at base works perfectly).
Now the problem;
When attempting to add costs to the block (aka mapping out a grid of blocks before-hand - so it is only done once for all players in the receiving range) the lag is upwards of 1000ms (1s) for every message within a 30 block radius.
The following is the code which causes that delay by mapping out the blocks within the radius
val blocks = HashMap<String, Int>() // Basic Location and Cost
for (x in (location.x - radius) until (location.x + radius)) {
for (y in (location.y - radius) until (location.y + radius)) {
for (z in (location.z - radius) until (location.z + radius)) {
blocks[BasicLocation(x, y, z).simpleLocation()] = when (Location(world, x.toDouble(), y.toDouble(), z.toDouble()).block.type) {
Material.AIR -> 1
else -> 2
}
}
}
}
Any recommendations on how to either remove the Location calls, or access it in an improved way (either native in Spigot or via an External API)
Side-Note: The call to this method is done asynchronously as to avoid lagging the main thread.
EDIT: The solution would be to calculate relative ChunkSnapshots and retrieve Block Types from that
like proximity chat?
Can someone explain
Yeah, with a custom cost depending on the block type (the code currently just uses a base example)
is there a way to create a lead from 2 points without using a mob on the end
VoxelGamesLibv2
MiniGameWorld
AthenaGM
You can search with "minecraft minigame framework" in Github.
for example less code repeating
Someone told me there was something let me reply it
its more clean especially if you lets say get player name a few times
String player = event.getPlayer().getName()
sometimes its extremally long
@onyx fjord
like i dunno 100 letters
idk if he replied to your original question
you ask for is why we make variables from stuff right?
I used block.getState(); but it didnt work. And the guy told me if i instance it, it will be work and i didnt get what is the difference
I know why we do that, but as here sometimes its not working
that too ig then
i have no idea either
why am I getting this as the player count?
BungeeCordUtils.playerCount(gameItem.getServerName()).thenAccept(result -> {
ByteArrayDataInput in = ByteStreams.newDataInput(result);
String server = in.readUTF();
int playerCount = in.readInt();
specialItem.setLore("Player count: "+playerCount);
gameSelectorGUI.setItem(gameItem.slot(), new InventoryItem.InventoryItemBuilder(specialItem::getAndSet)
.setAction((event -> BungeeCordUtils.connect((Player) event.getWhoClicked(), gameItem.getServerName())))
.build());
});```
why are you mapping out grids?
you only need distance
where are you pulling playerCount from?
SendAndReceive, broker and listener
all in that bungeecord package
I think this is what you were asking for https://github.com/KyTDK/NeoUtils/blob/master/api/src/main/java/com/neomechanical/neoutils/bungeecord/PluginMessageReceiver.java
what do you have set for playercount in the configs?
i think IJ having bad time with gradle properties
they kinda ignored ngl
i added this line org.gradle.daemon=false but daemon still starts
wdym?
this doesn't stop from a daemon starting, what this does is stops from having a long lived daemon process
still need a daemon to start up to actually do things
just means with that option it should end as soon as its done with what it is doing
Well PlayerCount in regards to message channel, either is the player count of a specific server or the player count of all the servers combined. But also this property can be changed arbitrarily as well by some plugins if you wanted to provide a false player count or whatever else.
I'm just getting the player count of a one server, I don't have any plugins modifying the player count or anything like that
what I don't understand from this code is why are you using message channels to get player count for this?
its for bungeecord servers
Assigning a cost value to specific blocks
I need to use the plugin messaging channel to get the player count of bungee servers right?
Hello. Why does the event drops the "cancelled" item anyways (it drops my item and the "cancelled" item)?: https://paste.md-5.net/ewofukagon.cs
[11:26:15 INFO]: [CustomEnchantments] 3
[11:26:16 INFO]: [CustomEnchantments] 3
[11:26:18 INFO]: [CustomEnchantments] 3
[11:26:19 INFO]: [CustomEnchantments] 3
[11:26:30 INFO]: [CustomEnchantments] 3
[11:26:31 INFO]: [CustomEnchantments] 3
[11:26:35 INFO]: [CustomEnchantments] 3
[11:26:37 INFO]: [CustomEnchantments] 3
no
You could use ServerInfo
enlighten me further
my feelings
give the full code for the method and not partial
since you specified items should drop, then that means if the code below that doesn't run, items will drop
since when did I say I was using bungeecord api?
also do again here
same thing as before, if the code below it doesn't run, then it remains true
you said it was for bungee servers
usually indicating the bungee server itself
_to get the player count of bungee servers _
anyways why is the plugin channel returning a random number?
probably because there is no player on the server you are trying to obtain information about
you don't only need a player on the server you doing something, but if you want information about the other servers using message channel you also need a player to exist there too
hold up let me get my alt on the server
not sure why you are insisting on using message channel for this
creating a ping packet to obtain server info is going to be the most reliable in this instance as it will still work even if there is no players on that other server
it runs
cause it print "3" to the console
as I showed before
event.setDropItems(false);
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), furnaceRecipe.getResult());
Main.getInstance().getLogger().info("3");
I want to get the player count for each server from the lobby
I've never heard anything about this Server List Ping thing
can you use plugins to require mods to join a server?
iirc the client sends a packet to the server telling the mods it contains
but im not sure if you can say directly 'connection failed - mismatching mods'
Yes you can do that
I am aware what you are trying to do, however as I said, if a player doesn't exist on the server you are trying to obtain information about then message channel will not work
server list ping has been part of MC for a long time now, its part of the protocol
the information returned when one is sent to a MC server, is the amount of players currently on it
even if its 0
What's the best way to implement a spawning system for entities based on specific spawn points?
So is this thing an event?
There is an event for when a ping is received
declaration: package: org.bukkit.event.server, class: ServerListPingEvent
And this is what you are referring to?
event is only handy for when one is received, not when you want to send such things
so to send such things, you need to implement it yourself which is really easy to do
And how does one do that?
no
not sure why you are saying no
no thats not easy
keep in mind not everything you want to implement is always going to be doable in a way that is within your current abilities of skill level
sometimes you will have to do some research and implement things yourself
Why isn't my gitignore working and why isn't 'git rm -rf build' fixing anything?
did you add the gitignore after committing the ignored files?
any ideas?
Iโd try removing the gitignore
Then delete the files
Then readd it
In 3 separate commits
git rm --cached .gradle/ .idea/
git commit -m "remove files gitignore missed"
git push -u origin main
its very possible u added files .gitignore got it for some reason
I just blasted the repository
what does this mean?
I am having a similar question like yesterday: What block-type represents the underlined font-type the best?
it means u probably ran git add . (or git add -A) before u created the .gitignore, idk
also possible ur IDE added it automatically before gitignore was created
if the gitignore existed since the beginning idk tho
a slab, doesnt matter what type
just do a polished andesite slab
ok thanks ๐
is there any better way to turn a sound name like ENTITY_GENERIC_EXPLODE into a "proper" sound name, like "entity.generic.explode" than this?
try {
Sound tmpSound = Sound.valueOf(soundName);
soundName = tmpSound.getKey().getKey();
} catch (IllegalArgumentException ignored) {
//throw new IllegalArgumentException("Unknown sound: " + soundName);
}
return new SoundData(soundName.toLowerCase(Locale.ROOT), volume, pitch, pitchVariant, soundCategory);
ahaha this explosion sound is sooo random
Hi guys im making sort of punishment plugin and i want to make tempban and i was wondering like could i use asnyc function to sleep the time while player is banned or something like that
and then when sleep ends it sends message to main function to unban him maybe ?
would that work properly and like is it maybe an overkill ?
Generally, you don't really "unban" them until they attempt to join after their ban expires
you'd store for example the uuid of the banned player as well as the timestamp of when their ban ends
when they attempt to join you compare the current time to the end of the ban timestamp
yeah i know that way of making it too
i tought to make it store username as key in json and value as timestamp
anyone know what the Moj map packet is to make a player sneak?
It's the entity metadata packet
ah sweet thanks
anyone free to help me wit some testing? i've got no friends (that are willing to help)
basically i just need to kill you a few times
ClientboundSetEntityDataPacket
There we go Mojmap name
any idea what the DataAccessor is
If format is always guaranteed to be like that, have you considered string manipulation?
So the exact field is:
protected final SynchedEntityData entityData
In the nms Entity class
yeah i already have the entityData just trying to figure out how to set sneaking to true. Theres either EntityDataAccessor or FriendlyByteBuf
for entityData.set()
ah awesome
It doesn't look like that's sending a packet but it does set the entity data for you
yeah ill just send the packet after
?paste
exception: https://paste.md-5.net/kurusewulu.sql
class: https://paste.md-5.net/asuvucodap.cs
why???
Yeah you're probably modifying the list you're looping
where??
where??
i was wondering guys
should i make utility for custom configs or just write manually few?
ah, sorry: https://paste.md-5.net/asuvucodap.cs
you're breaking the block as you are iterating over it
use a Concurrent collection
depends how many times you are using it
which?
i believe i will read data often from the yaml
i plan to store some data there (not alot i have use mysql for other propurses..)
oh my english
dont judge
if it makes your life easier, by all means go for it
ConcurrentLinkedDeque should be fine
finally got my system working, two completely different servers can see other players
[13:31:51 ERROR]: Could not pass event BlockBreakEvent to CustomEnchantments v1.0
java.lang.StackOverflowError: null
infinite loop Bukkit.getPluginManager().callEvent(new BlockBreakEvent(b, player));
It will break my tab and things, I think
Why is it infinite? b is an element of the list of blocks and I have a check in the start of the code
you are trigering your own BlockBreakEvent while still IN the BlockBreakEvent
I have to trigger the BlockBreakEvent in order to pass the 3x3 broken blocks through it
and you are triggering your BlockBreakEvent, which triggers another and so on
never ending
it triggers only if this is true: if(itemMeta.hasEnchant(CustomEnchants.BULLDOZER) && !blocks.contains(block))
Yes
then why is it infinite
because your blockFace is never null
it constantly adds new blocks and triggers new events
your blockFace is never null and your blocks is never empty
you just fire more and more events, infinite loop and a stack overflow
how should I do that then
what are you trying to do?
I have a pickaxe that breaks blocks 3x3. I want all of these blocks to be passed through the BlockBreakEvent
for what reason? you ignore the result of the event
if you just want to break them, break them
for interacting with the result (for other custom enchantments)
you don;t do anything with the result though
I do it in an other class
you just fire off an event and ignore it
thats not how you handle events
all you are doing is breakign blocks and ignoring the event result. so you still break teh block as its a fake event
?
the very first thing you should do, is as soon as you have finished using the blockFace, reset it to null.
so before yoru for loop
Then change the order you raise the event and you actually brak the block
myEvent = new BlockBreakEvent(b, player);
Bukkit.getPluginManager().callEvent(myEvent);
if (!myEvent.isCancelled()) {
b.breakNaturally(event.getPlayer().getInventory().getItemInMainHand());
}```
are dispensers "Directional"?
I'm trying to get the location where a dispenser would normally spawn an item
yes
thanks
I'm using ServerListPing to get the player amount of a server
Image
But I get the error above
If I set the port to 25565 it works
i have port forwarded
which error?
Why would I break the block naturally if it is not cancelled? Should I just call the event instead in this case?
this error https://paste.md-5.net/uxuyepahim.bash
I corrected the code
I am using pterodactyl btw
you only break teh block if the event returns not cancelled
if the event is cancelled it means some plugin is preventing you from breaking that block
Is it correct?
for(Block b : blocks) {
BlockBreakEvent blockBreakEvent = new BlockBreakEvent(b, player);
if(!blockBreakEvent.isCancelled()) {
if(player.getGameMode() != GameMode.CREATIVE) b.breakNaturally(event.getPlayer().getInventory().getItemInMainHand());
else b.setType(Material.AIR);
}
}
you only fire the event to notify other plugins to ask if any of them want to protect that block
no, you didn;t call the event
oh, yeah
So everything is in here, error at bottom https://paste.md-5.net/bizohivilu.cpp
did you remember to blockFace = null; before your for loop?
huh weird
blockFace = null; sure
I'm doing this in the BlockDispenseEvent:
Tasks.nextTick(() -> {
System.out.println("Adding bucket");
dispenser.getInventory().addItem(new ItemStack(Material.BUCKET));
dispenser.update(false, false);
});
but it just doesnt add the bucket? any ideas why it doesnt do anything?
(Tasks.nextTick() just calls the scheduler with runTaskLater(...))
it DOES print "Adding bucket"
your update is probably resetting it
Using the spigotmc library, how would one check if a provided username has an associated (purchased) minecraft account?
you have to query the mojang API
spigot doesnt have anything builtin for this
also you shouldnt be allowing cracked users anyway
oh so just ping the api endpoint of player?
yeah the thing is im making a simple whitelisting plugin and if a player inputs a dumb name that doesn't exist, the server whitelists it but i cannot remove it
so its annoying
hence i want to check before whitelisting
(cant upload an image of said scenario doesn't doesn't let)
you need to verify your account
?verify
idk
!verify
there is a channel
Usage: !verify <forums username>
why ?paste but not ?verify?
gotta create a furums username then yo
?paste
quiery ? statement !
it breaks only one block now for some reason
fixed it. calling update() fucks the inventory. without calling update(), it works
line 94 is pointless
oh and move ConcurrentLinkedDeque<Block> blocks = new ConcurrentLinkedDeque<>(); inside the BlockBreakEvent
it needs to be a local variable not a field
this.
You would be perfectly fine using a straight Set there
no need for any queue or concurrency
I used a List and got an ConcurrentModificationException
yes because you were modifying it while looping it
then use an iterator instead, or a concurrent collection
just a Set is all you need
your code is different now
so long as you move it inside the event
for(Item item : myCollection) {
myCollection.remove(item);
}
NEVER DO THIS ^^ unless you know it's allowed because the collection is concurrent
each event needs its own local collection
it still breaks 1 block instead of 3x3
paste yoru new code
code looks fine to me, so long as your getRelative is good
add a sysout of the cancelled state to see if its ever cancelled
you should not force custom enchants to be registered but instead use the meta's PDC instead to identify your custom enchantments
how do i change the part before the message in asynchplayerchatevent?
PlayerToggleCrouchEvent is whack
setFormat("%s > %s")
setFormat
first %s is the username, second %s is the message
setFormat("This is modified %s> %s")
E.g. look at this:
print(String.format("%s is %s years old", "mfnalex", "27"));
this will print "mfnalex is 27 years old
broadly to understand how to use setFormat, in this case to change the entire message's color
then set the format to this:
"%s > ยงa%s"
(of course you should use ChatColor.translate...... instead)
it's not even printed, lol
for(Block b : blocks) {
BlockBreakEvent blockBreakEvent = new BlockBreakEvent(b, player);
Bukkit.getPluginManager().callEvent(blockBreakEvent);
Main.getInstance().getLogger().info("blockBreakEvent.isCancelled(): " + blockBreakEvent.isCancelled());
if(!blockBreakEvent.isCancelled()) {
if(player.getGameMode() != GameMode.CREATIVE) b.breakNaturally(event.getPlayer().getInventory().getItemInMainHand());
else b.setType(Material.AIR);
}
}
wdym?
iirc theres no such method in asyncchatevent
event.setFormat(ChatColor.translateAlternateColorCodes('&', "%s > &a%s"));
sth like this
this would make the message green
then your code is not running. add a sysout earlier to see where its exiting
did you even register the event? ๐
ill play around with it a bit thanks
wrong item perhaps?
oh, I forgot that I've commented the line that registers the event, ty XDD
np! You can either use "&a" and run it through ChatColor.translateAlternateColorCodes, or directly use ยงa (section sign)
๐
happens all the time
1 sec, I had this listener unregistered
wait wouldnt that allow the player to color their message?
yes. If you don't want that, then you have to it like this:
event.setFormat("%s > " + ChatColor.translateAlternateColorCodes('&', "&a%s") + " %s");
oh wait
this is wrong
yeah anyway, you get the idea
you can translate teh whole format as its before teh %s is inserted
yeah, and then just add "%s" at the end WITHOUT translating it to alternate color codes
Any idea why this isn't working? error at bottom https://paste.md-5.net/bizohivilu.cpp
what's "UpdatePlayerCounts" line 35?
forgot this ```java
@Override
public String getHostName() {
return "172.18.0.1";
}
@Override
public Integer getPort() {
return 25569;
}```
It works perfectly now. Tysm, @tender shard & @eternal oxide ๐
is it even possible to change a message's color without allowing the player to do so ?
sure
wdym
as I said earlier
an object of ServerListPing used to get the amount of online players of a server
this will make all texts green
but only the message content itself, not the username
and it will NOT allow players to insert color codes themselves
WAIT
setFormat, not setMessage
sorry
i see
is there any reason to use ChatColor.translate over just inserting ChatColor.COLOR ?
no
I only used ChatColor.translate... so you can make it configurable
if you always wanna use a specific hardcoded color, you could also just do it like this:
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
event.setFormat("%s > " + ChatColor.GREEN + "%s");
}
which code?
oh
1 sec
it should work fine tbh
if it doesn't, then maybe the actual message contains ยงf at the beginning
well i just typed text in chat
print out event.getMessage() to console
then check if it contains the ยงf part
(it normally shouldnt)
send the code as text please
package io.github.moterius.Shards.EventHooks;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class EventHookPlayerChat implements Listener {
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event){
//the only reason this is here is a fuck you to microsoft
//playerChatEvent.setMessage(ChatColor.GRAY+playerChatEvent.getMessage());
event.setFormat(ChatColor.translateAlternateColorCodes('&', "&a%s")
+ "%s > "
+ ChatColor.translateAlternateColorCodes('&', "&a%s")
+ " %s");
}
}
ok gimme a minute pls
um thats an odd translate
well i tried modifying this
then it went looooong and i added some newlines
you got 4 times %s
you can only have two
first %s is the username
second %s is the message
any additional %s will fuck it up
now it just says Moteriustext in all green
String newFormat = "%s > &a%s";
event.setFormat(ChatColor.translateAlternateColorCodes('&', newFormat));```
that will only translate codes YOU put in newFormat
its translated before teh %s are replaced so it will not affect teh message
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event){
//the only reason this is here is a fuck you to microsoft
//playerChatEvent.setMessage(ChatColor.GRAY+playerChatEvent.getMessage());
char usernameColor = 'a';
char messageColor = 'c';
event.setFormat(
ChatColor.translateAlternateColorCodes('&', "&" + usernameColor) + "%s"
+ ChatColor.RESET
+ " > "
+ ChatColor.translateAlternateColorCodes('&', "&" + messageColor) + "%s");
}
do not mind the comment. github copilot wrote it haha
no wait
you wrote it
and I copy pasted it
yea i copy pasted it too
anyway, what I sent above makes the username green, the > white, and the message red
so adjust it to your needs
k
omfg some idiot on here gave me advice and it was so wrong. Because of them I spent hours on something utterly pointless
I hope this idiot wasnt me
never
but their answers had so much confidence as well
smh
people being overly confident is always a warning sign
me
I am usually not sure about stuff I do since years
yeah, hard to tell without any further details
do one character string take up more space than a char?
no they were quite clear
it can, depends.
ascii
striaight ascii no
k
those are not valid BlockFaces
why would front be EAST?
and if you want to use that crazy naming just create an enum
EAST is a valid blockface
yes but front?
front = east
I'm tracking the direction a thing is facing and this helps me test objects in every direction
I'm connecting parts of a sectional couch
seems pointless you already have cardinal directions with BlockFaces
but I need to know which direction is the "left" side of the object
left is always relative
exactly... but I need to get the blockface in that direction
where am I losing you here?
your plan to use odd names
Why is it odd?
a block can be placed in any orientation so your "front" could be any of the 4 cardinal directions when its placed
yes
is there an api method to capitalize a string (CamelCase) ignoring formatting codes?
which makes "front" pointless
no.
which gives you a BlockFace in getfacing
with that you always know which way a block is facing
what
so fake directional?
yes
then get teh attached face of the ItemFrame
the face is always the top
the direction is based on the rotation
this is a map that helps me map "front" "left" etc to minimize the amount of code I need to write when comparing different objects fake directions
Result:
What does the period and delay in runnables do?
delay is how much it takes for it to execute (first execution only) in ticks
period is the amount of ticks before it executes again
So if I wanted to create a runnable that updates a counter every 1 second I should put period to be 20?
yes
Ah ty
how do I fix this (ik it's just a warning but I get errors to console)
ok
check if it has an item meta
and that ^
also you can put them in the same check
just append them with || (has to be doubled) and nullcheck first
msaduh3g does your life phase thing mean that all the plugins have been loaded? https://github.com/JEFF-Media-GbR/JeffLib/blob/33217d2aaecf66a2b7e8fb0a80ed00f321cab1da/core/src/main/java/com/jeff_media/jefflib/ServerUtils.java
this right?
yes
but nullcheck first
if they have no boots on
it will throw nullpointerexception
also i recommend you use guard clauses for these kinds of checks
yes
wait no
sorry
do getBoots().hasItemMeta()
better than nullchecking the meta
if (player.getInventory.getBoots() != null && player.getInventory.getBoots().hasItemMeta())
im not sure, but if there is, it would do the same as nullchecking the boots
you'd still have to check for item meta
also if you dont want to execute anything if they dont have boots/boots dont have meta invert the check
and make it a guard clause
to reduce nesting
guard clause?
guys is there a seperate API to look up bedrock usernames and their validity?
instead of doing if (item != null) {code;} do if (item == null) {return;} code;
ofc with proper identation and al
but that makes it so your code isnt nested inside an if loop
also return; might not make sense in your context
it might have to be continue; or break;
ok
only 2nd
yeah 2nd is guard clause
Anyone knows how to disable dependencies logs?
ofc if you want to do stuff after the if even if item is null use the upper option
how do I use else with guard clause
In spigot at runtime or somewhere else?
Or more specifically: What dependency log are you referring to?
JDA(Java Discord Api)
if you want to do something if the item is null then dont use guardclause
just use it when you only want to do something if the item isnt null
If you have no idea about the concept, do not use it
return can be evil if you are unexperienced
yes
Especially if it is within a for loop
you'd use break; or continue; there
or whatever codeblock
I get an error if I use continue
It always depends. And then there are instances where you'd need to break of an outer loop and all these circumstances
no no no
dont use continue if you dont know what it does
continue is to stop execution of a loop iteration early
and go on to the next loop iteration
there's named for or whatever its called
?
It is perfectly fine to have code like
for (Object x : list1) {
if (x instanceof InterestingObject) {
InterestingObject couldBeInsterestingObject = (InterestingObject) x;
if (couldBeInsterestingObject.isReallyInteresting()) {
for (UninterestingObject z : couldBeInsterestingObject.getReferrals()) {
z.makeInteresting();
}
}
}
}
I'd guess you have to configure their logger. At best referr to their documentation and the documentation of the logging framework at play and it's implementation
I myself have no use JDA
its usually nicer to do
for (Object x : list1) {
if (!(x instanceof InterestingObject)) continue;
InterestingObject couldBeInsterestingObject = (InterestingObject) x;
if (!couldBeInsterestingObject.isReallyInteresting()) continue;
for (UninterestingObject z : couldBeInsterestingObject.getReferrals()) z.makeInteresting();
}
Only that it becomes tedious once you want to change it afterwards
One tiny change means that you gotta reevaluate all conditions
instanceof usually shows bad design patterns
i had a kind of big plugin some years ago
and it had like over 10 nested if loops
to just execute one line
it was hell to mantain
why
i use it to check if CommandExecutor is a Player or to check an entity type
Main reason why https://gist.github.com/Geolykt/9a13462a0d6029ed3fb629447fe6d834#file-autodeobf-java-L4094 I my most deeply nested code block I have
wow thats a long class
it depends on the usage, in SpigotAPI its hard not to use instanceof but if you use instanceof on your own objects it usually shows bad design patterns, thought your example was smth you made
can i create a plugin in vs code?
oh, the example was just to show that nested {} makes it harder to mantain/read
- guard clauses
I'd debate it myself
I'd debate that too
idk how its easy to mantain code that has like 40 spaces before it
?
Yes, but should you?
you can create a plugin on a basic text editor
You can even create plugins in VIM if you really want that
nano ๐
Although in that case Maven or Gradle is highly recommended
As long as it isn't VI
From my experience I can say: Easy
or the binary/hex of a class file
A lot easier than having 200 continues and break
imo no
you have the same amount of continue/break statements as nested ifs
but w/out the nesting
so you got everything vertically alligned
and you can see everything that makes the loop continue or break
much more easily
for (ClassNode node : nodes) {
if (node.superName != null && node.superName.equals("java/lang/Object") && node.interfaces.isEmpty()) {
if (node.fields.size() == 1 && node.methods.size() == 1) {
MethodNode method = node.methods.get(0);
FieldNode field = node.fields.get(0);
if (method.name.equals("<clinit>") && method.desc.equals("()V")
&& field.desc.equals("[I")
&& (field.access & Opcodes.ACC_STATIC) != 0) {
vs
for (ClassNode node : nodes) {
if (node.superName == null || !node.superName.equals("java/lang/Object") || !node.interfaces.isEmpty()) {
continue;
}
if (node.fields.size() != 1 || node.methods.size() != 1) {
continue;
}
MethodNode method = node.methods.get(0);
FieldNode field = node.fields.get(0);
if (!method.name.equals("<clinit>") || !method.desc.equals("()V")) {
continue;
}
if (!field.desc.equals("[I") || (field.access & Opcodes.ACC_STATIC) == 0) {
continue;
}
In this example latter might make more sense - but once you want to recycle the for loop to have multiple functions you cannot really do it - so you'll have multiple for loops
Another issue with latter is that most often you'll be negating everything a lot, which for the trained person isn't an issue I guess
again, using guard clauses vs nesting is very context based
How can I spawn a falling block with the exact gravity of a normal falling block, just reversed?
if you know the loop will only do stuff if it goes through all guardclauses
then you should use htem
However if you use if (condition) continue;, then readability gets completely thrown out of the window
i.e. a falling block that goes upward?
Gravity is kinda difficult to get right
imo its more readable than nested
the thing is falling blocks sped up
I guess it is a skill issue on my side then. My brain is trained to not read past the last )
eyy i got it
How can I make glow on other colors with packets?
Without using team colors?
I think teams will break my tab
the velocity should be 19.25/50
https://wiki.vg since I am lazy
or maybe i spam if oneliners too much
Sets whether the entity has a team colored (default: white) glow. nb: this refers to the 'Glowing' entity property, not whether a glowing potion effect is applied
Not possible
Protocol doesn't imply that it is possible that way too
no
so its impossible?
yes
;-;
unless I didn't read a memo or something
With that I meant a note or something of that sort
World world = event.getEntity().getWorld();
Location loc = event.getEntity().getLocation();
Vector entityVec = loc.toVector();
List<SpawnData> datas = new ArrayList<>();
event.setCancelled(true);
int distance = 5;
for (int x = loc.getBlockX() - distance, maxX = loc.getBlockX() + distance; x < maxX; x++) {
for (int y = loc.getBlockY() - distance, maxY = loc.getBlockY() + distance; y < maxY; y++) {
for (int z = loc.getBlockZ() - distance, maxZ = loc.getBlockZ() + distance; z < maxZ; z++) {
Location location = new Location(world, x, y, z);
datas.add(new SpawnData(location, location.getBlock().getBlockData().clone()));
location.getBlock().setType(Material.AIR);
}
}
}
for (SpawnData data : datas) {
Vector blockVec = data.loc().toVector();
Vector dir = blockVec.subtract(entityVec).normalize();
FallingBlock fallingBlock = world.spawnFallingBlock(data.loc(), data.data());
fallingBlock.setVelocity(dir);
}
```Am I dumb, or is there something wrong with this code (Most blocks just stay there)
Yes, UNLESS I made an error
did you made it? xd
Hi, can some one help me with this i have a inv that is named "Ban This Noob" and in that one i want so if i click emrald block i take money from player i did klikk on in "Sandtak". It does not happens anything if i click it now else that i take the block .It did work befor in 1.18 don't know when it did stop pls help and tag me
I cannot say that since to know that I made an error I need to know how to do it
itemstack.getType() is null
Hmmm
false.
you mean this line? " switch (e.getCurrentItem().getType()) {"
e.currentItem() is null (i.e. because AIR or whatever)
Likely caused by the player clicking outside the inventory
do you ever remove them?
no i click on the iten
even then players can click outside the inv
the thing is they just bump into other blocks and sit there
but they have no blocks to bump against
since they all got removed
So what exactly is the issue?
me?
blocks get shot, blocks stay in place
but the falling blocks appear?
I do not know why that would happen tbh
So basically the falling blocks instantly rematerialise?
nah, they fall straight back down
since their vel is stopped by the other falling blocks
wait
hold on
did a wopsie in that one
I'll show you my old res
which means that they instantly go back to their solid block state?
that's the result
they go up
then back down and become items
because they bump into other blocks
The ideal would be they all get thrown up
to the side
will my scoreboard or tab break ifi touch team colors for glow?
i want to use it
wdym
Isn't glow color depending on team color?
why would you want to use team colors in your scoreboards and tab was my question
i didnt write scoreboard plugin for mine
That it is used for glow is evident and already set up
??
then chances are that it is not using team colors
so glow is not using team colors?
tab and scoreboards allow using chat components
what is it depending on then?
sd jmnkybolni9dร0oxy+bcbmsDNFYDNs
,l jh
YES
Is team color depending on my display name?
I noticed that my display name is red and glow is also red
soo
And will my display name's color change if I change my team color?
xd?
what's the fuse time of a tnt that got exploded by another tnt
it will only break the scoreboard if you use the player name
How you could just use <colorcode><playername> and it'd be fine
hey guys, im trying to make an api inside my spigot plugin to connect to my website (made in js/html/css) to do some things releated to buycraft
whats the best to do that?
if its a web server use http requests
i wanna make it REST
yeah that is rest
could you give some guide
cause kinda new in making apis in java
yeah that one
this is a proj i did a while ago with it, its not amazing code quality but you'll get the idea
yeah you just have to shade it
That looks great ๐
wdym shade it
Bookmarking that website lol
ah ok
Same
do you use maven?
it's basically keeping the dependency in your plugin jar
so it is in your runtime environment
yep
If you're on a modern version you can just use the library loader feature
What version are you making the plugin for?
for buycraft
1.19.2
Then use the library loader
what about maven
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>4.6.4</version>
<scope>provided</scope>
</dependency>
That's all you need
then in your plugin.yml add:
libraries:
- "io.javalin:javalin:4.6.4"
1.17 I believe
alright
public Javalin app = Javalin.create().start(7000);
app.get("/giveKey", ctx -> {
})
i took this from the docs
but its saying app.get is not resolved
nvm
i was just dumb
forgot to put it inside the function
lol
so after i do that
i just call this class in the onEnable
and then i can fetch localhost:7000?
but wouldnt i need a domain
yep
so how would i do it
wait wdym you need a domain
like i need to fetch this api
localhost:7000 will work fine
from my website
so something like fetch("http://localhost:7000") will do?
if its local, yeah
its the same as any other ipv4 protocol
idk how your network is setup so i can't really tell you
so my server's hosted, and i want this plugin to be in there, and do stuff in the server for me
when the website sends a request to it
and the website is on another machine?
on the same machine as the server?
the website's host and the server's host are different
so idk if the machine is the same
yes it is different then
just port forward your rest api port and point the website to the server's public ip
how?
again, without the information of your network setup I can't tell you
treat this port exactly the same as your would your server port
i never did that before lol
minecraft server:
1.2.3.4:25565
api port:
1.2.3.4:7000
the website will fetch machines public ip:7000
25565 is for the minecraft server
you would use localhost:7000 if the website and server were on the same machine
but i dont know whether we can access the public ip of the machine from the vps
you can
and thats not possible
love it when im coding and i have no clue what im doin
me all the time, every day
have no fking clue how to handle this problem
Is there a way i can replace Material arguments that include "_" to just ""? if so... how?
only errors
could you give an example?
wdym by material arguments
Material.WHATEVER.name().replace("_", "")?
i did this:
board = manager.getNewScoreboard();
Team team = board.registerNewTeam("redTeam");
team.setColor(ChatColor.RED);
team.addEntry(p.getUniqueId().toString());
p.setGlowing(true);```
and its still glowing white
dunno if material has a displayname in the enum
im using vercel for my website rn
i am trying to make a /give command
looks like a shader issue
well yeah you set it to glowing
shader?
its a clientside issue
white boy
some setting fixes it cant remember
umm?
does it happen to all users?
it's a clientsided issue
what that means; if you have that setting on
anything glowing will be entirely white
i dont remember i setted that
yeah but it's not a spigot api issue thats for sure
yes
emissive textures maybe?
if you try without optifine i guarantee you the issue will be gone
clicked on emissive textures. thank you it crashed my launcher :D
lmao
problem solved: just dont play minecraft
lol im lost, how do i fetch the plugin's api from website now, cause my host doesnt give machine ip
two days of work ๐
I use material.getmaterial so yeah
if i make tempban is it enough to kick player on PlayerJoinEvent or should i do something else ?
๐ฅบ
i just disallow them to join in the prelogin event or whatever its called
rip
probably the best idea to not even let them join HAHA
send feedback to whom
๐
@charred blaze I think the setting is Fast Render, I remember having the same issue when I had it on
fast render?
no way
im getting 30 fps without it :D
lmao
rip
yeah optifine sucks with glowing effects
idek why
friends had the same problems while playing wynncraft
same tho, so i just rather leave it on
aaaa
no its not because of fast render or optifine
i checked other colors on my server
it is working
nice
@EventHandler
public void onClick(InventoryClickEvent e){
e.getCurrentItem()
}
in an InventoryClickEvent is getCurrentItem the item that was clicked on ?
so something is wrong with my code?
yep
what?
thanks
any resourcepacks?
No
that looks so funny for no reason
?? xd
Bro it's working on another server, why are you blaming my settings
Anyone knows how I can fix this? (Maven)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.250 s
[INFO] Finished at: 2022-09-03T16:09:13+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Malformed \uxxxx encoding.```
My pc crashed before while using maven
is that the entire log?
[ERROR] Re-run Maven using the -X switch to enable full debug logging.```
can anyone tell me why is this setting white glow?
board = manager.getNewScoreboard();
Team team = board.registerNewTeam("redTeam");
team.setColor(ChatColor.RED);
team.addEntry(p.getUniqueId().toString());
p.setGlowing(true);```
compiler probs shat itself on ยง
stupid computer, i can do that in atleast 20 seconds
xD?
wrote some stupid algorithm
20 sec
:D
of Fourteen does your interpreter work with order of operations?
parenthesis aswell?
can anyone help meee
not yet
that shit sounds complicated
Needs to be main scoreboard
Im using intelij somehow my cursor switched to a terminal insert mode, how can I put it back to normal ?
push insert
on ur keyboard

instead of getNewScoreboard do getMainScoreboard
Is it possible to change server port while it is running?
If you could it would involve kicking every player off t he network I imagine.
[clans] loaded class net.milkbowl.vault.economy.Economy from Vault v1.7.3-b131 which is not a depend, softdepend or loadbefore of this plugin.
[Clans] disabled clans plugin due to no vault api
getting this error whiles trying to import vault
@Override
public void onEnable() {
if(!setupEconomy()){
getLogger().severe("disabled clans plugin due to no vault api");
return;
}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
getLogger().severe("clans could not find vault plugin");
return false;
}
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
}
playerinteractentityevent
playerinteractatentityevent
whats the differen
where is the second bracjet lmfao
I have a private method to modify players and server packet so not a big deal
mightve just missed the end bracket ig
do you have a depend or soft-depend entry in ya plugin.yml?
nope
I mean you can have whatever method you like. You can't just switch ports with no disconnects.
code compiled fine, I probably missed one bracket whiles posting this code block
do I need one ?
ah right ok
depend: [Vault] same thing
that too
oh
so if i need more dependency I can use array ?
if you wanna add more just
depend:
- Vault
- PlaceholderAPI
- EssentialsX
- Blah
PlayerInteractAtEntityEvent
Represents an event that is called when a player right clicks an entity that also contains the location where the entity was clicked.
PlayerInteractEntityEvent
Represents an event that is called when a player right clicks an entity.
how do i do that?
.
still get error disabled clans plugin due to no vault api however the other one isn't showing up
Will it break my scoreboard?
It can mess things up yes
can i remove an item from all loot tables with the spigot api? or do i need a datapack for that
im trying to completely remove mending from the game
working with teams can be quite annoying
idk why but on my server worldguard is bugging out ive denied pvp but people can still pvp even tho it says "Hey! Sorry, but you can't PvP here.
and ive disabled fall damage but people still take it
Yep
yep to what
You can remove it with spigot
how do i force it to not mess up things?
Does the Spigot forum have an API?
Not that im aware of. Whats the usecase
Forums is just xenforo. So if they have any public api then that
can you direct me to a doc page i should look at to figure this out?
how would i check if a player has their swing fully charged
I wanted to make an integration with a bot for Discord, to deliver automatic roles to those who buy a premium plugin
nvm found an nms thing
and its not nms
lol
i just found so many useful methods in CraftPlayer though
Just listen to entity death event and modify loot table with LootContext
fixed my stackoverflow bug lol
anybody help ? ๐ข
What was the issue
made a nice deadlock by linking nodes to eachother
Whats โthe other oneโ
how about chest loot tables
this error no longer shows up
[clans] loaded class net.milkbowl.vault.economy.Economy from Vault v1.7.3-b131 which is not a depend, softdepend or loadbefore of this plugin.
Can you show the full error
Not too sure on chests tbh
that's the full error
someone solved it before
it no longer shows up
however it tells me that it can't reach vault api when I have vault plugin installed
this aint an error
its just a notification really
No the first error
i assume i would need a datapack but i cant find any info on how to actually modify the chest loot tables without mods
does anyone know how Block#getDrops() works
[15:30:46 INFO]: [Clans] Enabling Clans v1.0
[15:30:46 ERROR]: [Clans] disabled clans plugin due to no vault api
when applied on a fully grown patch of potatoes or carrots, it returns a collection with two itemstacks
1 potato (as expected)
and 2-4 potatoes
Uh do you have vault in your plugins folder lol
its like it returns both itemstacks where if you were to break it with a hand as well as with a fortune III item