#help-development
1 messages · Page 132 of 1
Why do people blindly hate on singletons
Depends on what you’re doing
Not always bad
people already sent it
dependency injection is used everyone in other projects, that's why I like to use it instead
yep works now
thx
di
it's a standard that major companies use
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Depends on what you’re doing lol
I saw dw, ty
private static MainClass instance;
public void onEnable() {
instance = this;
}```
```java
import static me.cringedeveloper.cringeplugin.MainClass.instance;
public class Cringe implements Listener {
@EventHandler
public void onCringe(PlayerCringeEvent event) {
instance.getServer().broadcastMessage(event.getCringe());
}
}```
Hey i am trying to sendSignChange if the sign is playced but the sign dont change his content why
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
How do I use Plugin Message to Send Player into another Server?
I tried this:
https://gist.github.com/TheMolkaPL/7623034
could you paste it ?paste
?paste
sry i needed it myself too lol
yessir
I have an extremely simple plugin with an event handler that just doesn't seem to fire & can't work out if i'm being completely thick;
BlockListener:
https://paste.md-5.net/dayuzujimi.java
Main Class:
https://paste.md-5.net/enugehenij.java
feel like im missing something obvious but i've looked at it over & over
Whats the problem
Unsupported class file major version 60
(While shading the plugin)
Help me? I've already tried to switch from java 16 to 17.
Why did you make a constructor like that
In event
nope
show the full error
probably you gotta upgrade your maven shade plugin
Well your event code seems right so perhaps maybe your plugin isn't being loaded?
to 3.3.0 or later
Prolly no difference
that's not the full error
hm
that's only one line
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
That doesn't matter afaik
@vocal pine
^
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
ye i needed the specific mcmmo instance (i thought; at least)
it does not
Not me
whats the best version in ur opinion?
Send console
what do you use?
It's not being loaded then, do you have a plugin.yml?
Sorry i was writing smth to print in onEnabled didnt know theres an easier way
the latest stable one, 3.3.0
ohh dude i think i know what it is 🤦♂️
version: 1.0
author: Euronite, sudura
main: games.tress.cropdrops.Cropdrops
api-version: 1.19
depend: [mcMMO]
author part right
This is not main class
Could be that yeah
Isnot your main class XPCrops?
Also true
sorry guys
i changed name of it cus person wanted me to push it as update to theirs
i just missed it here
Also put [] around the authors though
yeah lmao
oops
thank u sorry it was smth so stupid
totally blanked on the fact id changed it
thank you!
With the ConfigurationSerialization ,is there any possible way to exclude a certain property from being serialized into the config file, but still have it present in the memory?
if its your own object, yes
The use case is the following, I store (Doors). And the existence of hte door is in the config file.
But there is no need to keep track in the file if this door is also open or not
However when fetching it I would still need to have that value
how? And yes its my own object
Simply ommit that field when you serialize
But then when reading from the Configuration object, it will no longer exist
and It sounds silly to keep track of it in a seperate map
correct. you'd have to set a default when you deserialize
but if that is the only solution
But I don't want it to become serialized
I just want to store keep track of the open/close state in the memory, not the file
thats pointless
Well that is the goal , I don't know if you are familair with services and repositories, but my respository is interacting with the data storage (config) and stores it. So when reading data, it fetches it from there again
so maybe I have to write everything to a map only
If that is the only option :/
I have a class door, that door has a location and block data. and all of that needs to be kept upon restart
But the actual state of the door, is also important, only not for after a restart
Yeah but what you're saying doesn't really make sense, you say you don't want to keep the open/close state persistently but then you need it when creating the Door object?
Assuming a door is closed by default
And assuming upon onEnable*, I will close all doors
Then do exactly as I said
^
I'm sorry but I'm not following what you said then
Just set the state as false
Don't store it, and when you deserialize from the config just set that state to closed
You exclude the field in your serialize method
and set a default when you deserialize
Okay i see why you say it, but it's important that when I update somewhere that my door is closed, and when I fetch again by id the same door, it should know it's closed or open. Sorry for making it complicated
I just don't need it in my config file itself
but on runtime, that's where I need it
and that is also when I store it
Oh, don't return it from the config every single time
at runtime its a door
Yea that was what I was thinking, but so then I have to foresee a different map to store the data correct?
Yeah you'd have a list or map in memory that'd you'd check first, if it's not in there then get it from the config and then add it to that list/map
ah that makes alot of sense, but when storing, I guess it would be a good idea to then also store it in the config correct?
both config and memory*
if you don;t care about the open/close state at startup why do you need to know it at runtime?
Because when somebody closes a door, then I need to be able to fetch that closed or open state
I just don't need that value in the config
Because upon restart, it will always be false
But I think I know what to do
why is this wrong?
You need to define the generic parameter before the return type of your method
public <T extends Weapon> void registerWeapon(String name, Class<T> weaponClass) {
registeredWeapons.put(name, weaponClass);
}```
i made it like this and i don't get any error is this ok?
the red underline appears to be an error though 🤨
whatever parameterized types you're using for your registeredWeapons map doesn't support classes extending from Weapon as a value
yeah that's just because i needed to change the map value
i was concerned about the class thing
Ah. Then yeah, I suppose you don't need a generic type at all, lol
No need for the generic there. Wildcard is fine ;p
aloha everyone
I am currently structuring my API and would love to hear some feedback, opinions and improvements
I am asking first, to make sure people don't get angry at me stealing their time looking at something they don't actually want to look at, is that ok?
actually I can make a thread and ask there, then I don't spam this channel with a big file
I'd do it like this
private final Map<String, Class<Weapon>> registeredWeapons = new HashMap<>();
@SuppressWarnings("unchecked")
public void registerWeapon(String name, Class<? extends Weapon> weaponClass) {
registeredWeapons.put(name, (Class<Weapon>) weaponClass);
}
in IntelliJ when I create Comment using /** */ and install the package
It doesn't appear anywhere in the docs
Which docs?
first pic is API
second is in another plugin:
no comment visible + not even when hovering on the method
package docs I think its called
Oh the package docs need to be in a file called package-info.java
they are talking about the normal javadoc comments theya dded to the methods
and it will result in something like this?
Well I'll just blame IJ there because clearly it is at fault there
you have to "attach the javadocs" to your .jar or with an execution in the javadoc plugin
Or just export the source
can I use this with shade plugin?
I dont understand maven at all
so thats why im asking
Eclipse generates javadocs from the source even if the javadocs are not present, so it is easier to just export the source jars without bothering with the javadocs themselves
sure
Alternatively
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
oh dear god
i havent seen maven in so long
god gradle ticks me off
but im forced to use it for forge
🤷🏻♂️
As someone that is writing his own maven resolver, maven is an absolute pain
Well that isn't the casual usage
WHY the hell does the dependencyManagement block exist and why does the import scope exist
Maven version ranges are also absolute pain
everything is painful
🤔
4.0.0 is not included in the range of [3.0.0,4.0.0), so is 4.0.0-final or 4.0.0.0, but 4.0.0-alpha is included in the range.
It does make sense yes, but it also introduces a dilemma because people writing such ranges absolutely don't expect this behaviour
Yes
4.0.0-final is funnily enough also included in [3.0.0,4.0.0], which even fewer people expect
that makes perfect sense, versions with an "identifier" are always older than versions without
Actually 4.0.0-final and 4 and 4.0.0 have the same age
Only 4.0.0-sp is more recent
// Based on examples provided by https://maven.apache.org/pom.html#Version_Order_Specification
assertFalse(isNewer("1.0-rc", "1.0-cr"));
assertFalse(isNewer("1.0-cr", "1.0-rc"));
assertFalse(isNewer("1.0-ga", "1.0.ga"));
assertFalse(isNewer("1.0.ga", "1.0-ga"));
assertFalse(isNewer("1-1.foo-bar1baz-.1", "1-1.foo-bar-1-baz-0.1"));
assertFalse(isNewer("1-1.foo-bar-1-baz-0.1", "1-1.foo-bar1baz-.1"));
assertFalse(isNewer("1", "1.1"));
assertFalse(isNewer("1-snapshot", "1"));
assertFalse(isNewer("1", "1-sp"));
Being only a part of all the unittests I had to make
And then there is
assertTrue(isNewer("3.3.0-I20070605-0010", "3.3.0"));
assertFalse(isNewer("3.3.0", "3.3.0-I20070605-0010"));
where actually the opposite was documented. But whatever
oh yeah I only read part of that website. somehoe they expressed it very badly
first they say "all versions with a qualifier are older than the same version", then it goes to tell how this is not true, lol
oh no wait
actually it says what I said, something with "final" should always be older than just 4.0.0
Are you on the oracle site? That one is absolute bullshit.
yeah I couldnt find a better source
https://maven.apache.org/pom.html#Version_Order_Specification is the correct source
oh yeah those say otherwise
anybody know where i can find the help page for scoreboard methods? im trying to find it but all im finding are custom scoreboard plugins
nvm got it
Is there a way to see how long the player has been online for?
Like how long since they joined?
You could check the playtime statistic
Iirc that's a thing
It'll be like player#getStatistic or something along those lines
Found something that might be useful, thanks
It is possible to make a custom mob (nbt edited mob) spawn naturally without replacing a random existing mob?
declaration: package: org.bukkit, interface: OfflinePlayer
getFirstPlayed()
Works for Player, too.
TaskTimer
own conditional spawn systme
Is it possible to make music discs in a jukebox play on loop
or actually better question
is there a way to detect if a music disc is finished playing
or are the music discs just one fat sound effect
I noticed that there is a JukeBox#isPlaying() method but I need something like an event for when a jukebox finishes playing
anyone know a away to select 2 players inside a array without select yourself?
for loop and an if statement?
Get the results of Bukkit#getOnlinePlayers() and then just call #remove() for yourself.
Then do your random search for two people.
??
I mean, if you don't want to include yourself in the results. The best way is to just remove yourself from the results in the first place.
it's because it a matchmaker
and when paring i pick a random player in array
oh i understand now
i will remove on results
so in theory this will work?
Random rand = new Random();
List<Integer> newList = new ArrayList<>();
for (int i = 0; i < totalItems; i++) {
int randomIndex = rand.nextInt(list.size());
newList.add(list.get(randomIndex));
list.remove(randomIndex);
}
return newList;
can you explain what you are trying to do
because if totalItems is size of list List, newList will always be same as list
hey, I just was making a /suicide cmd and I made this code that has a hashmap and is used for confirmation. What I did was create the hashmap which its keys are a UUID and value is a boolean. So, I made code where it has an if statement asking if the key pUUID (A variable I have set up for the player's UUID) is null and if it is to put in the key pUUID true so it would not be null. then I sent a message explaining the confirmation and made a delayed task for 10 seconds to remove pUUID key and value from the hashmap so they would. Then there is an else statement killing the player and telling them they got killed just so they know 😉 I did this so they would have to type /suicide twice for a confirmation. For some reason, every time I run it, it just does what it would do as if it were null in the if statement. I am very new to spigot development and it would be nice to know what I did wrong. Here is my code:
public class Suicide implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String [] args) {
if (!(sender instanceof Player)) {
Message.send(sender, "&cOnly players can use this command!");
return true;
}
Player player = (Player) sender;
UUID pUUID = player.getUniqueId();
HashMap<UUID, Boolean> suicide = new HashMap<UUID, Boolean>();
if (suicide.get(pUUID) == null) {
suicide.put(pUUID, true);
Message.send(sender, "&fAre you sure? You will die and loose all of your items! If you want to suicide, type &c/suicide&f again. &8(This expires in 10 seconds!)");
new DelayedTasks(() -> {
suicide.remove(pUUID);
}, 10 * 20);
} else {
player.setHealth(0);
Message.send(sender, "&c&lYou have been killed!");
}
return true;
}
}
oop
lemme edit that
You're creating a map in the command. You need to have that map outside of your method.
ah ok
so like this?
HashMap<UUID, Boolean> suicide = new HashMap<UUID, Boolean>();
public class Suicide implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String [] args) {
if (!(sender instanceof Player)) {
Message.send(sender, "&cOnly players can use this command!");
return true;
}
Player player = (Player) sender;
UUID pUUID = player.getUniqueId();
if (suicide.get(pUUID) == null) {
suicide.put(pUUID, true);
Message.send(sender, "&fAre you sure? You will die and loose all of your items! If you want to suicide, type &c/suicide&f again. &8(This expires in 10 seconds!)");
new DelayedTasks(() -> {
suicide.remove(pUUID);
}, 10 * 20);
} else {
player.setHealth(0);
Message.send(sender, "&c&lYou have been killed!");
}
return true;
}
}
that is outside of class
oh ;-; so before the @Override?
Technically, it can be anywhere outside of a method, but for readability people put variables like that at the top of the class.
mm ok thx for the help :)
Hi I'm trying to ban words like "hell" but this raises the issue of such things like "hello" also get banned.
public List bannedWords = config.getList("banned_words");
@EventHandler
public void chatMessage(AsyncPlayerChatEvent event){
/* Getting our variables ready */
Player player = event.getPlayer();
String message = event.getMessage();
/* We need to get each item in the list and check if any of them are in the message! */
for (Object item : bannedWords){
if(message.contains(item.toString())){
System.out.println("BANNED < DEBUG");
}
}
Profanity filtering is not at all an easy task, you'll probably have to do some research on some algorithms that people have tried.
Or, if you just want to have a basic one, split the message by spaces and check if any of the words are in the list.
yeah I thought I could add like if(message.contains(item.toString() + " ")){ but that doesn't work if it's only the word byitself
that would work except a player could split a message. also my word filter is meant to combat against phrases too.
Well that's pretty complicated to really get right afaik, might do some research and see what others have done in the past.
right ok
I'll decompile some popular crap and see what they do (not copy tho)
For banned word detection you want a decision tree algorithm.
Then you can even add alias for certain character. like i -> I 1 l |
This has by far the best performance but is a bit trickier to implement than just a contains.
and still has false positives. For the example above, "prickle" would flag you
Nobody has perfected word filters
Yes true
There are some apis which use neuronal networks for really good filtering.
But those are mostly rate limited unless you pay.
*And you have the overhead for your rest calls.
At the end of the day, all you need is some simple filtering because inevitably someone will find a way around yours, but hopefully by that time, you'll have punished them accordingly
This is a terrible method, but what I do for chat filters on my server is I replace all of the bad words in the message with *s for the letters then say for the most common words like lets say grass I would change that to 3 asterisk thingies in red (&c) then I would do if the message contains gr&c(3 asterisks), replace that with grass. This only works for the most common words that you put in but after a few days of finding words that were blocked, I never had a problem again with that unless you send a not common word
<this is a terrible method>
lmao
it works if u are only using the plugin for ur server ig
uh so I'm trying to make a /spawn command and on it I want them to wait for 5 seconds without moving, like almost every plugin out there and I have a hashmap I am using but it wont let me use it in a different java class... does it need to be outside of the class I am mainly using it in to access it everywhere? or what do I need to do?
bcus it wont let me put it outside of the class
Can you already disable the nsa/stasi-style surveillance? Because if not then ill just let microsoft do the cleansing.
Thats a classic... normally i would hit this with a "?learnjava"
What you do is write a manager class which has only one instance and is dependency injected (through the constructor)
to other classes or obtained by using the singleton pattern.
NoChatReports. Both a mod and a server plugin.
whats this mean "dependency injected (through the constructor)
to other classes"
public class TeleportManager {
private final Map<UUID, Location> waitingPlayerMap = new HashMap<>();
public boolean isWaiting(UUID playerId) {
return waitingPlayerMap.containsKey(playerId);
}
public void setWaiting(UUID playerId, Location targetLocation) {
waitingPlayerMap.put(playerId, targetLocation);
}
public Location removeWaiting(UUID playerId) {
return waitingPlayerMap.remove(playerId);
}
}
Example for the manager class
You create a constructor in your Listener or CommandExecutor or whatever class you need the manager in
and pass it there.
so... where do I create the hashmap?
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
how do I force a command to be run like /pluginname:commandname instead of /commandname
prob shoulda used the info I got from solo learn while I learned it cus I never used it the whole time and just forgot cus I never used it ;-;
The latest registered command will be executed
Or do you simply prevent the usage of vanilla commands and use yours instead?
I see that the plugin Gringotts you need to type gringotts: before the command so I was wondering how to do that for mine
like in the auto complete all the commands come up with /gringotts:
Custom tabcomplete maybe
ohh... that took me a long time to get but so I'm making a new class with the hashmap and making variables in it that are public to remove and add stuff to it? Did I get it right or no?
that could be another solution actually. Is there a way to just disable tabcomplete for a command?
google java encapsulation
bro ur so unhelpful
Not only related to your current problem tbh
Well yes. But never ever make any data structure public. Not for Lists, not for Sets, not for Maps, Queues, Arrays. Just never make them public
and never write any getter or setter for them.
uh ok
And remember: This class should only have one instance and not a single more. Because if you create a new instance
then this instance will have a new map which is completely unknown to everyone else that has a different instance.
You can use a phonetic filter
This filter detects offensive English swear words based on if they SOUND like bad words on your list. This filter matches by phonetic patterns and can block bad words that have been purposefully misspelled. This is useful when you need to be sure a message in non offensive, such as TTS applications.
This one is fine
basically if it sounds bad, it's detected as a "bad word"
guy designed this for a TTS bot
im bored someone give me some ideas on how to make the most toxic annoying plugin
actually just revive my old thread #961763801869451335
There are apis out there that have an average of 100ms response time for this.
Phonetic filtering is probably the wrong approach for text that will never be heard.
bump
I don't think there's an event for that
Nor can one be implemented
Jukeboxes just... play
ElgarL, did you by any chance made one of the first cracked launchers?
I remember back in the day before I had the chance to buy it, there was this launcher named "Minecraft Launcher by anjocaido"
how do you check if a chunk is in simulation distance
no Chunk#isSimulated() or anything of the sort
runnable and check for isPlaying() to be false or smth
btw Choco, had the pr's related to the bucket events been merged?
ok i'll try to figure something out..
perhaps detect when a player right clicks a jukebox, then set an interval that will constantly check if the jukebox is playing
and if its not restart the music
I see, I'm so happy about them.
Thank you again for the contribution.
By the way, how may I contribute to the API?
I mean, what are the rules while contributing to the API.
Are we supposed to use mojang mappings to guide ourselves?
How may I contribute to the API?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
on here why do you put public Location and what is it like is it from org.bukkit or is it a java thing?
bump
Beyond that, you can work directly out of BuildTools. Fork the Bukkit and CraftBukkit repos on the stash, make a branch, make changes in the Bukkit and CraftBukkit folders, then commit and PR
The README of each project has details on expectations
to players not the server owner
oh
also use the dead thread
- So you can access it from outside the class 2) Because the other one makes literally no sense whatsoever
yea but when I put it in my IDE it gives me error
what do I import to make it work?
bukkit
its for a location in a world
The "public" does
o
ok
so
what is Location for
is it cus ur teleporting someone?
in ur code
tbh im just confused why all of ur variables have different uh prefixes in the manager bcus they are all editing the hashmap
I dont see how this correlates at all...
;-;
And those are not variables
"in the manager"
oh yea constructors why do those all have different prefixes like the first one is public boolean and the second is public void and the third is public location
boolean returns true or false
yea
void returns nothing and just "does" stuff
because you specify what you want your constructors to do
and Location is the returned object in the last method
Those are not constructors
bro I give up
?learnjava
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.
moment
I see
Please. You will suffer for months and not get anything done if you continue like this.
Learn the bare minimum of java before jumping into spigot
^
welp everything every tells me to learn with like sololearn didnt work
Learning java basics is honestly not that difficult
so I'll try here
If you can't learn from a structured platform what makes you think you can learn from us 
I use a 9 year old version of PwnFilter that I updated for 1.19. It uses regular expressions. There's a compiled .jar file and a comprehensive set of rules.
https://github.com/Bobcat00/PwnFilter
bcus I already have learned a lot from u
https://www.youtube.com/c/CodingwithJohn watch this guys videos, really helpful and nicely explained
uh ok
hey doods I'm tryna get the amount of caps in a string but what confuses me is when compiling I get an issue
my code is this:
int amount = 0;
for (char letter : message){
if (Character.isUpperCase(letter)){
amount =+ 1;
}
}
And what's the issue?
getting to that lol
initialize amount with 0
(from above)
String message = event.getMessage();
wdym?
you just edited the message
int has a value of 0
the error is for-each not applicable to expression type
in refrence to line: for (char letter : message){
message.toCharArray() or smth maybe
Strings are not iterable
I wish google had an API so you could easily make a bot to google things for people.
Yeah, toCharArray() it
are "unset" ints actually initialized to 0? if yes I didn't know that lol
sorry brainfart. Was programming in python yesterday
aren't they null?
that's what I thought so far
.
yeah i forgot to assign it 0 that's why I editted it lol
ah gotcha, I was talking about before u edited the message and it just said int amount
which, as I thought so far, should be null and not 0
yeah it did say int amount = 0; in my code. I didn't copy everything i only copied what was relevant, musta got rid of that.
aight
kinda irritated for a second haha
Though, a google search says ints are initialized to 0
Good practice to set it anyways
that's what I've been doing
just didn't know it's like that
Unless it's local var
But will result compile error
good to know.
does anyone have a code example of a static helper class for a plugin
for example Lib's Disguise is a plugin but if you add it as a maven dependency it uses a bunch of fancy static classes to interact with the plugin
i need to know how to create something like that where users cant mess with my plugin (as in hide it from autocomplete) but can use the API freely
i know i asked this question before but never really got a satsifying answer
Do what spigot does.
Define your API by using a bunch of interfaces.
Implement the API in your plugin and let the user only depend on your api.
This way the implementation is not visible for the user.
But thats probably overkill.
Just create a static facade pattern.
what is a static facade pattern
ah i see
nvm i looked it up
I'll probably do this
i wanna make my plugin look as professional as possible
wait actually im kind of confused
I get the whole creating interfaces and implementing part
but how would I create a static facade class in the API to actually interact with the plugin itself?
I would use Bukkit's plugin manager to get the plugin, but don't I need to cast the plugin to my own one that subclasses Plugin in order to actually do stuff with it? If I need to cast it, then my API will need to depend on my plugin
public final class MyAPIClass {
private static MyAPIInterface api;
private MyAPIClass() { } // Private because it shouldn't be instantiated
public static void setAPI(MyAPIInterface api) {
MyAPIClass.api = api;
}
public static MyAPIInterface getAPI() {
return api;
}
}```
That would be in your API. Then in your plugin all you would have to do is call MyAPIClass.setAPI(new MyAPIImplementation())
That's basically what Bukkit does. That's what the Bukkit class is. It has a setServer(Server) method that it calls in CraftServer's constructor
You could make use of the services API too, but imo that's a backwards use of it
what is a forward way then?
Vault is the prime example of how it's meant to be used
A service is something you expect other plugins to implement so that your own plugin can use it
Or at least in the case of Vault, allow other plugins to use as well
Ok and if you make an API
nothing is wrong with someone else implementing it
OCP and all
Whats the best way to check if a player is able to build in an area? (checking the ifCanceled() is not a possibility)
BlockCanBuildEvent can = new BlockCanBuildEvent(p.getWorld().getBlockAt(p.getLocation()), p, Material.AIR.createBlockData(), false);
Bukkit.getServer().getPluginManager().callEvent(can);
if (!can.isBuildable()) {
return false;
}
But i feel that there is probably a better way of doing this. And the only information im allowed here is the location of the player.
Anyone have any other ideas of alternative ways of doing this?
you should probably alos check the cancelled state
Not sure isBuildable checks that
Im checking the canbuild state elsewhere on the actual event
This check is me checking if they have permission to build to use a skill
I'd generally use the block place event over canBui;ld
I mean dont they work the same in terms of viability?
they do, kinda. But BlockCanBuild is fairly new. I'm not sure many protection plugins listen to it
Nah, BlockCanBuildEvent has been around since 2011
BlockCanBuild is 1.18+ iirc
so, it should be enough time. But yea overall is what im doing fine for Checking of they have build perms at their location?
I'd have to dig in the internals to see if a protection plugin not listening to this event would even trigger a false response
Thats why im asking, are there better alternatives?
Will a plugin listening only to BlockPlace affect this event?
tbqh, it's such an underused event, I'd be shocked if any plugin is using it
If not, I know some protection plugins will not return false.
oh hi Choco, i just realized who i was talking to 🙂
Yep thats my thoughts. I'd actually not even heard of this event until it was mentioned here, and I've written protection plugins 🙂
Lolol
Ive used it in React a while back with no real issues
But im trying to see if my "old habbits Die Hard" is going to continue
So the answer is, if its a modern updated protecton plugin that listens to this event you are good.
Older protection plugins its unknown, you'd have to test
Or if there are better ways
Or make a Pr to the plugin / Issue request to save my time
Mmm, ill stick with this for now until i get a report, but im glad that im not off my rocker
Thanks @eternal oxide / @worldly ingot for your insight.
Take care yall 🙂
Programming with multiple lines is for losers, check out my one line statement
case NEARBY_PLAYERS -> eliteEntity.getLocation().getWorld().getNearbyEntities(eliteEntity.getLocation(), range, range, range, (entity -> entity.getType() == EntityType.PLAYER)).forEach(entity -> entity.teleport(finalLocation));
ew
haters
Hold my beer
get with the new hotness
it's actually worse than you think
switch (target) {
case ALL_PLAYERS -> Bukkit.getOnlinePlayers().forEach(player -> player.teleport(finalLocation));
case WORLD_PLAYERS ->
eliteEntity.getLocation().getWorld().getPlayers().forEach(player -> player.teleport(finalLocation));
case NEARBY_PLAYERS ->
eliteEntity.getLocation().getWorld().getNearbyEntities(eliteEntity.getLocation(), range, range, range, (entity -> entity.getType() == EntityType.PLAYER)).forEach(entity -> entity.teleport(finalLocation));
}
RegisterAdvancement(AdaptAdvancement.builder().icon(Material.COOKED_BEEF) .key("challenge_eat_100") .title("So much to eat!").description("Eat over 100 Items!").frame(AdvancementDisplay.AdvancementFrame.CHALLENGE).visibility(AdvancementVisibility.PARENT_GRANTED).child(AdaptAdvancement.builder().icon(Material.COOKED_BEEF).key("challenge_eat_1000").title("Unquenchable Hunger!").description("Eat over 1,000 Items!") .frame(AdvancementDisplay.AdvancementFrame.CHALLENGE).visibility(AdvancementVisibility.PARENT_GRANTED) .build()).build());```
aw hell yeah
I can do better hold up
I think you can fit a couple more builders and builds on there
Same
I have like a 30 line one lolol
Its almost as bad as doing an If without the {}'s
Here you go fam
https://pastebin.com/zmHKz19H
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

very unreadable
I'd structure this differently honestly
public enum SearchContextType {
ALL_PLAYERS((context) -> {
return Bukkit.getOnlinePlayers();
},
WORLD_PLAYERS((context) -> {
Entity entity = context.getEntity();
return entity.getWorld().getPlayers();
}),
NEARBY_PLAYERS((context) -> {
Entity entity = context.getEntity();
double range = context.getRange();
Set<Player> set = new HashSet<>();
for(Entity target : entity.getNearbyEntities(range, range, range) {
if(target instanceof Player player) {
set.add(player);
}
}
};
private final Function<SearchContext, Collection<Player>> function;
SearchContextType(Function<SearchContext, Collection<Player>> function) {
this.function = function;
}
public Collection<Player> fetch(Entity entity) {
return fetch(entity, 0);
}
public Collection<Player> fetch(Entity entity, double range) {
return function.apply(new SearchContext(entity, range));
}
}
@Data
@AllArgsConstructor
public class SearchContext {
private final Entity entity;
private final double range; // can be 0
}
How do I make a post in the spigot forum?
why write many line when single line will do
it makes your code seem fancy
it's just more organized ig
just like placeholder code
you make individual code blocks whenever you declare your actions instead of in the big method that needs the result
bonus points if you get paid hourly
no joke your version seems way more confusing to me
It's more overengineered
but each enum declaration has its own implementation of how it fetches the players from a given context
the context is a data object
but why
considering I already covered all the cases I wanted this doesn't seem like a better solution
Instead of having to add to the enum, then locate the method, you just make the method inside the enum
it also prevents big ass blocks of code
also a bit easier assumes new entries follow the format you imposed
a bit how placeholderapi code is often split up into functions for bigger plugins
you can modify the context object to fit your standards
maybe make a context builder
with default values
Collection<Player> collection = type.fetch(
SearchContext.builder()
.range(20)
.avoidIf((player) -> player.getGameMode() != SURVIVAL)
.build(entity)
);
would be the end game result lol
sure it's a lot more abstracted but the end result ends up cleaner
you have a very weird concept of clean
it's diametrically opposed to mine
The idea is that the method shouldn't handle multiple cases
instead, it calls the handler of the selected case in specific
that isn't cleaner so much as it is more fastidious
the end result is the same, but it's better managed
I feel like your concept of better management is very subjective
Okay uhhhhh
Think of PAPI expansion code
it has a String onPlaceholderRequest(Player, String)
would you put like 25 ifs in there
or just make it fetch the value from a Map<String, Function<Player, String>>
if there's 3 cases? yes I would put 3 ifs
code exists in a context
you don't bring in a nuclear bomb to unjam a door
sure it's fine at a small scale, but the point is, eventually as it grows bigger and bigger, you'd end up writing the second solution
yeah, but if my first approach is always the most fastidious one I would still be writing the first release of my first plugin
this is what I consider awful
and yet it has become the industry standard in our little world, because it actually exists and works
I guess it's a speed vs quality thing
But honestly I'm obsessed with being fastidicious
don't judge me for googling the meaning
well you're not obsessed with spelling that correctly that's for sure
also if you think this chunk of code is bad you're weep tears to see what I'm currently working on
I remember that one livestream I saw
but hey, it will be out tomorrow and people will probably really like it
and how the code was barely readable because I was watching a 4k stream at 1080p
yeah still streaming
?
But
Wouldnt have to be like 1000 maps
Everytime they queue they will teleport a new world
Why would you send them to a new world???
Lots of servers just have them in the same world separated by 1k blocks or smthing so u cant see other arenas.
Some servers have systems to use the same arena for multiple fights at the same time by preventing you from seeing other players not in your fight.
IDK if this is that popular any more, but I know some used to paste them in on-demand using FAWE.
^
So there is much arenas in a world i assume
Actually yes it can be created by world edit
approach #2 fails a bit when you start placing blocks
You could allow fake blocks but stuff like lava would need to be emulated
block instanceof Chest is returning false, even though the block is a chest 100% as I can see it with my very own two eyes, and the print statement also prints that it is a chest
org.bukkit.block.Chest
yes it's that
the other one doesn't even have an inventory
Yeah the other doesn't hold inv
I was struggling with this on pumpkins
Hello!
I'm doing an interactive furnace inventory, tried this util created in a few minutes.... It works correctly but I can't set slot 3... How can I do it?
Util: https://paste.md-5.net/wivebuvozu.java
How am I using it?
@Override
public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
FurnaceUtil furnaceUtil = new FurnaceUtil("test");
furnaceUtil.addElement(1, new ItemStack(Material.STRING));
furnaceUtil.addElement(2, new ItemStack(Material.GOLD_INGOT));
furnaceUtil.addElement(3, new ItemStack(Material.DIRT));
furnaceUtil.build();
furnaceUtil.show((Player) sender);
return false;
}```
ouch, maybe it starts from 0
works
thank you guys
How to update bedrock version in geyser crossplay
public void setOnClickListener(InventoryClickEvent event) {
if(event.getClickedInventory() == null) {
return;
}
if(event.getClickedInventory().getHolder() == null) {
return;
}
if(!(event.getClickedInventory().getHolder() instanceof GUIHolder)) {
return;
}
}```
olive, excuse me a question.
How do I consume the event that the player (myself in the other class lmao) passed to me?
Since im creating an utilclass
https://paste.md-5.net/akoyamasuq.java
You just call that method from the listener?
I wanted to do something like this, I don't have an idea
Ah you want the consumer interface
addElement(int pos, ItemStack stack, Consumer<InventoryClickEvent> onClick)
huh... thank you! 🙂
When calling that method you can give onClick as a lambda function like the screenshot shows
No use the one from the event listener
i cant accept it, I need the InventoryClickEvent and I cant get it from the consumer variable
Yeah accept it in the event listener
So you have the InventoryClickEvent
You can store that consumer in a field
anyone wanna make a 50x20 block kraken out of armorstands
then go on, i will wait until you're finished
I've finished
show me
here you are
thats not 50x20
Even better
ahaha I will end up banned
how so
WORKS!
thank you!
u've just rescued a baby panda
let it free you monster
NO! tHey arE MinE!
How to prevent the inventory from closing with the resourcepack download/request in 1.16.5?
declaration: package: org.bukkit.event.player, class: PlayerResourcePackStatusEvent
not always sure if there is a resourcepack to install
thats the matter
Wdym?
That I wanted to make this plug-in public, so, I don't know whether in a server they have resourcepack or not...
I want to prevent it from closing the inventory at onjoin
Use that event to reopen your inventory after the resourcepack screen
im trying to listen on handshake packet with protocollib, but it says PacketType.Handshake cannot resolved to a variable
this ?
no?
handshake doesnt mean handshake
It's like motd refresh in server list (as i know)
ping*
is it possible to cancel screen shake when we use setHealth() ?
setHealth does not shake the screem
It gives adrenaline
Spigot setHealth does not give adrenaline
I dont think you can, maybe try to increase the health by different way
How
if your previous health is higher it will
?stash
I dont get it Elgar
There is no adrenalin applied when a player is healed.
I didnt say applying adrenaline
But it gives an screen effect
Troll
that is the CB code to heal, which calls java public void setHealth(float f) { this.entityData.set(EntityLiving.DATA_HEALTH_ID, MathHelper.clamp(f, 0.0F, this.getMaxHealth())); }
all that does is then send a packet to inform the client to set the health
I want to make the server appear offline from the real IP Address, yes it appears offline with this code, but it also denies connections from bungee. But I want them to join. How do I fix that?
You may try it first :l
Or may be it is setscaledHp
which to use, and why?
for(String name : structSection.getKeys(false)){
ConfigurationSection targetSection = structSection.getConfigurationSection(name);
}
``````java
ConfigurationSection targetSection;
for(String name : structSection.getKeys(false)){
targetSection = structSection.getConfigurationSection(name);
}
can u iterate sections directly then
yes
i have a data object im comparing to a configurationSection. Said sections are different from each other. I'm trying to find the corresponding section.
basically this in complex:
for every Section do:
get Section.id
compare section.id with data object
return section if it matches, otherwise continue
return null
Mh
Maybe you could trying something like this:
structSection.getKeys(false).forEach(structName -> {
String sectionId = structSection.getString(structName + ".id");
...
}
Sorry if it's weird, I'm on a smartphone
getConfig().getValues(true).forEach((key, value) -> {
if (value instanceof ConfigurationSection) { }
});```
u sure that shouldnt be false instead
Another way 👍
would probably work
im about 99% sure ill get a npe or something if i keep that true
you walk all contents not just the root
I'm sure this will work, I use this to make custom GUI
from your question it looked like you wanted an anonymous method to parse
well i have a specific structure, and i want to find the section the comparison object matches with
just blindly fishing for it wouldnt work
hence me changing that true to a false
or are the keys the absolute path
wait even if they are I'd have to do string manip on them, like cutting away the last part
iterating over the top level seems safer
how am i supposed to give a return from that
Explain exactly what you are trying to do
Find and return the configurationSection / key to that configurationSection (either works) that matches the data object passed to the method as a comparison object
no, I'm unaware how to do that. It would make things easier thats for sure
also
the passed data object might have additional values not present in the configuration, its supposed to ignore those
but it also means i cant do equals() on the config map and serialized map would i have it
You are not going to be able to simply search the config for that item. you need some kind of indexing
yea so what im trying to do atm basically is
public static ConfigSection findSection(dataObject cmp, FileConfiguration cfg){
for(String key : cfg.getKeys(false)){
ConfigurationSection checkSection = cfg.getConfigurationSection(key+"."+items);
if(compare(checkSection, cmp)) return cfg.getConfigurationSection(key);
}
return null;
}
//compare not implemented
maybe just
exclude the ip adress of the bungee
if u can get the ip adress from where the packet comes
you shoudl be able to just if(compare(checkSection, cmp)) return checkSection;
Why are you trying to find an item in your config?
no, because that's the part of the section that identifies it. I need the section above that
u can get it from the player itleast
thats for sure
but from the first packet
meeeeh
items, plural. I am using item combinations to identify which effect should be loaded (think alchemy)
maybe u remember this atrocity
ArrayList<ArrayList<ArrayList<ItemStack>>>
Just have your dataObject implement ConfigurationSerializable (and register)
you can control which Fields it stores in its Serialize method.
you can also then compare objects to find matches, like how ItemsStack.isSimilar() works
If your item implements CS it can then be easily put in and read from the config
i think in this instance its simpler to write the comparision instead of making a dedicated data class. I am using that list purely for the identification, and am also only using non-unique items (enchanted, lore etc make it return false), and im not storing the items
still, its something that might come in useful later
Hello ElgarL 🙂
Im trying to create a furnace that allow an item to be selected. Precisely I wanted to make on the left (Fuel and Combustion Side) two arrows and on the right the item that changes when the arrows are clicked following a list.
In your opinion, how do I update the inventory after changing item on the right?
Should I recreate and open the inv?
I created this class as Util:
https://paste.md-5.net/otagoqipup.java
Hi how can i give a id for a inventory, i save the contents in a hashmap with de inventory name, its give some Issues...
InventoryHolder
Hmm
Hey, does anybody know how to do this? As you can see, when I hover over the player list, I see some customisable text. I don't really have a code for now, I started by creating a ServerListPingEvent but thats about it
Thats pretty much it. ServerListPingEvent. Unless you use bungeecord.
Thank you for the response, but what method do I use? I've no idea what that list's name even is
If you hover over this icon then the server returns with a list of player names
which are on the server. I dont see a straight forward way to handle this with the spigot api. Let me take a quick look at the protocol.
The server responds with a simple json message.
This part is responsible for the text which is displayed.
You can set this by using something like ProtocolLib to
alter the packet before its being sent out.
^ Link for more infos
Thank you so much!
Hi i have having an issue with one my plugins. The plugin is developed in koltin. Can anyone help me if they have spare time 😢
What is the specific issue here ?
generally, just post the concrete issue and hope that someone can help you
don't damange mobs off your main thread
the server thread ?
you are spinning up a async task somewhere
in that task you damage entities
which is not supported
by not damaging them in an async task
either make the entire task sync
or create a new sync task to damage hem
mhm ?
Well that is fine
but scheduleAsyncRepeatingTask
means the repeating task is async
there should be a similar method without the async
np 👍
Is there a betterway to load player stats in a hashmap without a runnable for every players?
what do you mean runnable o.O
bukkit has a getplayers function. iterate the players it returns
Not that effective
Just slower i think
Yeh ofc but that isnt any difference than a runnable for each
actually
the overhead is much smaller
also runnables still get processed on the main thread anyways iirc so this is actually faster
I can split runables on each thread and core so not a problem
Why would i need to load an offline player ?
Huh?
how to remove that book in a fake furnace inventory?
You cant 😄
iiirc u cant since its a client thing
play 1.12 then
i think i messed up somewhere
lol
why it says binary
like i told you plugin something tottaly different
monkey plugin monkey plugin
how the fuck is possible that a char means 99
??
?
char isnt 99
char is like A
or B
...
char has an int value
'1' - '0' == 1
its better for performance
huh
oaky
still use interact event
Are you trolling?
Conclure, what is the best in your opinion?
You cant even use InventoryInteractEvent
Since it doesnt have a HandlerList instance
thank you
is anyone aware how i can filter out strings from log4j logs?
lets say LOL UWU gets logged but i wanna filter UWU so only LOL gets printed
One way is to append log filters or sth
Myeah, I think its possible to append a filter in code
Tho I dont have any pseudo code for it
But I used to do it when unit testing
@Override
public Result filter(LogEvent event) {
if (event.getMessage().getFormattedMessage().toLowerCase().contains("lol")) {
return Result.DENY;
}
return Result.NEUTRAL;
}
});```
Theres probably a way to do that as well with that callback method
i see no method to modify the message tho
does that LogEvent allow you to modify the message?
siuuu my parser believes 1+(1+1) is 22
ouch
Olivo help me pls
with?
@onyx fjord
Add an appender not filter
And iirc you might be able to cast to MutableLogEvent
do you have an example of how to do it?
You know the FurnaceGUI from earlier?
FurnaceGui (Util): https://paste.md-5.net/kociwedijo.java
FurnaceElement (Object): https://paste.md-5.net/oduzokadep.java
Well, I wanted to make it change right the age and make it dynamic....
I have no idea how I can make it bring the new value when it updates
AtomicInteger actualAge = new AtomicInteger(ConfigLoader.min_age);
furnaceGui.addElement(new FurnaceElement(actionElement.getIntPos(), true, actionElement.getStack(), click -> {
personUtil.getPerson(click.getWhoClicked().getUniqueId()).setAge(actualAge.get());
click.getWhoClicked().sendMessage(ConfigLoader.message_ageConfirmed);
inventoryManager.openNextInventory((Player) click.getWhoClicked(), plugin, personUtil, postProcessCommands, customConfigsInit);
}, FormatUtils.color(actionElement.getDisplayname().replace("%actualage%", String.valueOf(actualAge))), FormatUtils.loreListToSingleString(actionElement.getLore()).replace( "%actualage%", String.valueOf(actualAge))));```
look at the event listener
lol FormatUtils.loreListToSingleString
Collections
ik
I guess olivo has given up xD
So do you see that true?
It indicates a dynamic object. Whose meta data (Lore, Displayname) is updated within the event in the FurnaceGui class.
Simply, I wanted to make it update with the new value of the ActualAge variable but it doesn't.
FurnaceGui (Util): https://paste.md-5.net/kociwedijo.java
FurnaceElement (Object): https://paste.md-5.net/oduzokadep.java
public FurnaceElement(int location, boolean dynamic, ItemStack stack, Consumer<InventoryClickEvent> clickEvent, String... text) {```
So the placeholder is the problem
ye
Your code will only work once since you replace (and thus remove the placeholder)
so the next time it should update it can't find the placeholder
I wouldn't want to bring that placeholder into the FurnaceGUI class being that one a util...
How could I fix?
?
BlueJ 💀
IntelliJ 🌮
just use whatever u want
We used Netbeans 😎
i saw my profs code 💀
I didn't even know BlueJ existed
same
looks horrible
olivo, so about my little problem.
would you have any ideas?
You can store the original lore and displayname
My professor used Netbeans and everyone in class used IntelliJ, which he had never used. You can imagine how many issues kids had and he had literally no idea how to fix them.
looks horrible
we switched to codeblocks
i saw ij on the taskbar on my profs pc, why not use it then :/
yes, I got there and did that.
The problem is the placeholder.... How do I get the updated value from the util class?
It's more fun to use obscure IDEs to further confuse people
You pass it as a param
smh
is the thingy saying client message has wrong timestamp new?
It's recent, 1.19(.1?) I believe
I shouldn't do that since it's a Util that I created for generaluse but... I've lost the desire to do things right.... however thank you!
Timestamp is included in the chat messages
myes
hm? Why should you not use parameters in Util classes???
I don't know, I had seen this class in Phoenix616's lib and it worked without sending any parameters
https://github.com/Phoenix616/InventoryGui/blob/master/src/main/java/de/themoep/inventorygui/DynamicGuiElement.java
unfortunately, it does not have the furnaces....
I was asked to do so
bad luk
Time to fork
Just thinking about having to download the whole code and duplicate it in the proj to change that InventoryType.Furnace...
makes me lazy ahah
You know it's less work then rewriting the entire thing
I only have to do this one inventory with one up arrow, one down arrow, and the button to confirm the age....
Then I'm done
I have this code for a void world chunk generator in my plugin: https://paste.helpch.at/ekovirisah.java. However, I want to support 1.17+ version to be used and some of the methods from 1.18+ does not exist in 1.17. How would I go about doing this?
how tf is that 54 lol
wtf LOL
i fucked up few minutes ago by clearing token buffer by calling parse recursive lol
Maybe it just appended the complete sum and (2+2) together?
might have happened ye
mye actually im not breaking loop when i encounter () and parse parenthesis
Does yours have a panic attack if you give it negative numbers
should be skipping (internal expression).length tokens ig
no? negative numbers work fine
That's good
I only ask because differentiating between a negative and a subtraction operator
is something
ah my way to distinguish
Well the math is wrong but it took them atleast
ill probably switch to an indexed loop instead of looping over input.toCharArray
Should switch to RPN 
ah this not working lol
can i add column number in ij?
like somewhere in editor
to have an idea where to break line
nvm
its in right bottom
lol
hmm might do smth like this to dintinguish between a syntax exception and a recursive call to parse cuz parse clears the token buffer which i dont want when recursing
i miss the c++ style of default parameters tho :(
What is hasPanicked? Lol
indicates whether the prev expression failed
cuz normally at the end of my parse method, i clear the buffer and return the calculation
if i throw an exception earlier then the buffer isnt clear and next expression will be fucked up
can u make it swear if it panicked
I second this idea
Why not just clear it when the exception is thrown then?
mye just thought that too lmao
instead of doing this bs
my tokens should be a static field then smh
I would've thought you make a new Expression for each one
actually i should have a local tokenlist variable cuz recursive parsing fucks up with the main expression then tokens
nah
probably should be creating some kind of expression obj
Anyone, is it possible?
that are a lot of places lol
Make a method for it then? 
for what lol
For throwing the error and clearing the tokens
ah smh
private void error(String message) {
ExpressionParser.resetState();
throw new InputMismatchException(message);
}
i guess
yeah
Did you put @EventHandler above it
satan
Also true, shouldn't be static
public class RTPLoc{
private int count;
private int x;
private int y;
private int z;
private World world;
public RTPLoc(Player player,int count) {
this.x = player.getLocation().getBlockX();
this.y = player.getLocation().getBlockY();
this.z = player.getLocation().getBlockZ();
this.count = count;
this.world = player.getWorld();
}
//methods to get vaules later.
public int getx() {
return x;
}
public int gety() {
return y;
}
public int getz() {
return z;
}
public int getcount() { return count; }
public World getworld() { return world; }
}
my data class
so why the output is like this?
i dont want use minecraft Location
its too heavy to load up.
You have to make it ConfigurationSerializable
yeah i see
didnt really get it
but ill make it toString
didnt really understand what they meant there
hi, can i remove player's resourcepack (server)?
Send an empty resource pack
how?

