#help-development
1 messages ยท Page 2122 of 1
what is the issue i forgot
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can use that command!");
return true;
}
Player player = (Player) sender;
// /heal
if (command.getName().equalsIgnoreCase("heal")) {
double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue();
player.setHealth(maxHealth);
player.sendMessage(ChatColor.GREEN + "You were healed");
player.playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER , 1.0f, 1.0f);
}
// /feed
else if (command.getName().equalsIgnoreCase(("feed"))) {
player.setFoodLevel(20);
player.sendMessage(ChatColor.GREEN + "You were fed");
player.playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER , 1.0f, 1.0f);
}
//spawnmob cow 5
else if (command.getName().equalsIgnoreCase("spawnmob")) {
if (args.length >= 2) {
try {
EntityType entity = EntityType.valueOf(args[0].toUpperCase());
int amount = Integer.parseInt(args[1]);
for (int i = 0; i < amount; i++) {
player.getWorld().spawnEntity(player.getLocation(), entity);
}
} catch (IllegalArgumentException e) {
player.sendMessage(ChatColor.RED + "That is not a valid entity");
}
} else {
player.sendMessage(ChatColor.RED + "(!) /spawnmob <mob> <amount>");
}
}
return true;
}``` like that?
what
no
you need do detect for tab not command
I need minimize final jar
java.lang.RuntimeException: java.io.FileNotFoundException: plugins\EndBot\tokens.txt (The system cannot find the path specified)
I am getting this issue when trying to open the text file
File file = this.getDataFolder();
File textFile = new File(file,"tokens.txt");
Scanner scanner = new Scanner(textFile);
Put the file in the right folder, lol...
I had resolved the issue a few days ago but it seemed to have come back and idk what i changed
and which folder is that?
The exception tells you exactly where it expects the file
Try
if(!this.getDataFolder().exists()){
this.getDataFolder().mkdir();
}```
after the java File file = this.getDataFolder();
I got this and I don't understand what to do from here. im trying to get auto complete for my command.
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.List;
public class spawnmobTabCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("spawnmob")) {
}
return null;
}
}
i am guessing it considers the jar as the data folder
yes nice start
what do you want 2 do?
just read the text file
if you want do like
/spawnmob <mobtype>
then arg length is one will detect <mobtype>
is there any reason to not use minimizeJar?
if (command.getName().equalsIgnoreCase("spawnmob")) {
}
This is useless unless you register this completer for multiple commands.
Several. One: Reflections wont be detected and might try to load classes that are not on the classpath.
how can I build a text file into a jar? or is that not possible
package com.ytg667.myplugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.List;
public class spawnmobTabCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> r=new ArrayList<>();
if (command.getName().equalsIgnoreCase("spawnmob")) {
if(args.length==1){
//your check here
}
}
return r;
}
}
put it in resources
you can use filter include
i was told specifically not to put it under resources
wdym?
must put it under project root
why?
Just throw it in your projects root. Or if you use a proper setup: in your resources folder. Jar is just a zip file.
so i can gitignore it
you can try ignore it
when args.length == 1 the word should be a mob right? it args.length == 1 should be the first word in the command right?
put in resource can let the file be put in jar
Take a look at StringUtil.copyPartialMatches for the tabcomplete
yes but first arg
Do you use maven or gradle?
and 2 would be the amount?
maven
ah well i guess im stuck with a 2mb size
Then put it in the resources folder
then just do it lol
You can use the plugin.yml to load dependencies on runtime instead of shading all your stuff in
isn't it plugin.yml?
oh
ok i get ur point, so why did someone else tell me to put it in project root and defiantly not in resource folder
you can just add your mob type in r arraylist with my code
is that if i was using gradle
oh right..
Because he is a bob that doesnt use maven i suppose
for ur plugin?
hm ok
mhm but im just going to not shade the big dependancies
ohno not BOB!
:)
is there a way to add every single mob in the game to the arrayList or do I need to add each one manually?
yes ofc
just do r.addAll(Arrays.asList(EntityType.values()));
It will add all exists entity type
ok
and if you want only mob you need filter
wtf-
<dependency>
<groupId>pw.chew</groupId>
<artifactId>jda-chewtils</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>club.minnced</groupId>
<artifactId>discord-webhooks</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.75</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-alpha.9</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
no instance(s) of type variable(s) exist so that EntityType conforms to String
oh I forgot
sorry
wait
List<String> mobNames = Arrays.stream(EntityType.values())
.filter(EntityType::isAlive)
.map(Enum::toString)
.map(String::toLowerCase)
.toList();
Arrays.stream(EntityType.values()).map(Enum::name).toList()
sniped
ah nice that's what I think
List<String> mobNames = Arrays.stream(EntityType.values())
.filter(EntityType::isAlive)
.map(Enum::name)
.map(String::toLowerCase)
.toList();
If your ide tips you need set language level just do it
Are you good at maven?
Can u help me solve a problem?
Just a small note: For enums you should use toString() instead of name()
as it usually provides a more user friendly representation of the enum.
In this case it doesnt matter but in general you should enforce this behavior.
I hate dependency manager problems... whats the problem about? Maybe someone else has a solution.
https://stackoverflow.com/questions/72099018/maven-sub-module-final-jar-with-minimizejar-not-working
Use the minimizer in the parent pom
private static String emojify(String message) {
String[] split = message.split(":");
StringBuilder sb = new StringBuilder();
for (String s : split) {
sb.append(emojis.getOrDefault(":" + s + ":", s));
}
return sb.toString();
}``` is there anyway to maek this better??
or well, any simple-ish way?
why do you need to do that?
hm?
How can i stop a datapack overriding events?
If you want to have better performance then you should try using a prefixed tree.
Other solution: regex
I am confusing how datapack overriding event..
lemme explain
sure
first, wouldnt regex be far slower considering there are 500+ differnet emojis? second, wtf is a prefixed tree?
It doesnt override any events. Spigot events are completely abstracted away from minecraft.
Wait i made an animation half a year ago...
@EventHandler
public void portalPlayerEvent(PlayerPortalEvent event) {
if (event.getPlayer().getWorld().getName().equals("build")) {
event.setCancelled(true);
Player player = event.getPlayer();
player.setNoDamageTicks(40);
Vector vector = player.getLocation().getDirection();
if (vector.getY() >= 0) {
vector.setY((vector.getY() * -1));
}
player.setVelocity(vector.multiply(-1));
if (!playerCooldown.contains(player)) {
player.sendMessage("error!");
playerCooldown.add(player);
new BukkitRunnable() {
@Override
public void run() {
playerCooldown.remove(player);
}
}.runTaskLater(pl, 60);
}
}
}```
in a server without the datapack this works but in a server with that datapack it doesn't
how ever java @EventHandler public void portalEntityEvent(EntityPortalEvent event) { if (event.getEntity().getWorld().getName().equals("build")) { event.setCancelled(true); } } works on both servers
easy solution, disable the datapack
lol
easy solution no
what should it do?
I need it
stop the player getting tped to the other dimention
then you can just use EntityPortalEvent lol
Thats like 4 lines of code in spigot
getEntityType check it is player
Oh i see, but again would i need to iterate over all the emojis to find if there is a match for each char?
I think you don't need do change
I am using spigot ..
it was enough
i think thats the problem, if the entity is a player it just tps them?
anyways ill try ur solution
Nope you would build the prefix tree with the emoji list.
I use it to filter chat messages. Takes under 0.01ms for 1k words in the blacklist
yes that's a nice way to do with blacklist
but with emoji system idk
Dont use the PlayerPortalEvent to check for a player changing the world. There is the PlayerTeleportEvent that is fired even when plugins or datapacks tp the player.
oh I know
maybe is the datapack
teleport the player
not player enter portal
Ok but surely it still has to tp them when
ah
it tps them to the end
which ignores the main enter portal event ig
that's just what I think not meaning the fact
I mean if you have a fixed model like *emoji_type* then you can use regex to find all elements between '*'
After that you simply access a Map<String, Emoji>
Thats how PlaceholderAPI does it.
how can you see if they change dimensions then?
If the world of the target location is different than the world of the current location
noooo regex bad, we need to save 10ms of runtime!
ah makes sense
and then i just test the world they get tped to
not actually
nice
because he can have multiple worlds with the same dimensions
So does he want to detect dimension changes or world changes?
the correct way to do that is by using the envoriment
just use getEnvironment
i forgot the getter method
yes
he wnats dimensions
getFrom#getLocation#getEnvironment and getTo#...
and if the dimension is different it is supposed that the world is different too
PlayerChangeWorldEvent btw
k
ah ty
PlayerChangedWorldEvent
That's not important XD
so even if i try tp myself it would cancel
yes
i mean if its a event of its own probably better to use
What exacly are you trying to do?
just stop people going to nether or end in a specific world
bruh
what?
thats what we beeen talking about
you'll know why it won't be calles
doesn't work .
what is the issue
is the event fired?
I think a datapack is overridding it
and tps the player
private static final Set<String> NETHER_BLOCKED_WORLDS = Set.of("build", "spawn", "lobby");
@EventHandler
public void onTeleport(PlayerTeleportEvent event) {
String worldName = event.getFrom().getWorld().getName();
World.Environment targetDimension = event.getTo().getWorld().getEnvironment();
if(targetDimension == World.Environment.NETHER && NETHER_BLOCKED_WORLDS.contains(worldName)) {
event.setCancelled(true);
}
}
I would probably do this:
I have this as a tabCompleter and it doesn't work.
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> mobs = new ArrayList<>();
mobs.addAll(Arrays.stream(EntityType.values()).map(Enum::name).toList());
if (command.getName().equalsIgnoreCase("spawnmob") && args.length == 1) {
return mobs;
}
return null;
}
}```
I also have this in my main file `getCommand("spawnmob").setTabCompleter(new spawnmobTabCompleter());`
remove the dattapack then ๐ค
i need the datapack tho
then remove the specific function form the datapack
What i posted prevents the teleportation by the datapack.
and what does the datapack do?
custom end
yup thanks
Please help guys
why wouldn't it be 1
/command <auto complete here>?
yes
so it's args[0]?
yes
๐
just gotta add an extra test here ๐ฅฒ
it doesn't show up. the tabCompleter doesn't work and I get the default player autocomplete instead
outdated plugins be like...
it is not outdated
or plugins which don't bother with tab completion, EG multiverse
ye ikk
you mean that you have autoComplete in the command code instead of the tabCompleter class?
it is what i need to implement
I don't understand
It waste time using spigot way to create command
Oh well
Your harder to understand than mine.
But that more exactly.
how is an sound effect when you buy something in bedwars called?
this datapack is cursed?
think so
legit sends me the message before i even enter, and it removes the portal
@mellow edge https://hypixel.net/threads/bedwars-sounds.3495279/
What are the sounds bedwars use when you buy an item from the store?
THANK YOU VERY MUCH @golden kelp
xd you are welcome
I am working on my bw plugin and it's really weird if there isn't any sound when you buy something
I have this tabCompleter code: ```public class spawnmobTabCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
List<String> mobs = new ArrayList<>(Arrays.stream(EntityType.values()).map(Enum::name).toList());
if (command.getName().equalsIgnoreCase("spawnmob") && args.length == 1) {
return mobs;
}
return mobs;
}
}```
And this line of code in the main: getCommand("spawnmob").setTabCompleter(new spawnmobTabCompleter());
Im trying to make it autoComplete to any mob in the game but it doesn't work. can anyone help me figure out what is wrong here?
if (command.getName().equalsIgnoreCase("spawnmob") && args.length == 1) {
return mobs;
}
return mobs;
this is kinda redundant, even if it doesnt match ur condition, it will return mobs
I know the one below should be null i was just guessing because I didn't know what to do
both will be null if anyone of them is null, as both are same
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
List<String> mobs = new ArrayList<>(Arrays.stream(EntityType.values()).map(Enum::name).toList());
if (command.getName().equalsIgnoreCase("spawnmob") && args.length == 1) {
return mobs;
}
return null;
}
}```
yea thats better
but it doesn't work
so
there must be an error
i just don't know where and what it is
Did you register it
getCommand("spawnmob").setTabCompleter(new spawnmobTabCompleter());
if(block instanceof Openable){
Openable door = (Openable) block.getBlockData();
door.setOpen(true);
block.setBlockData(door);
}else{
player.sendMessage("No doors found");
}```It is suppose to open doors and if there is no door then it will give a message that there is no door , and when i try it , it says no door found even i am standing in front of a door
anyone?
๐ข
.
are u sure that the variable block is a door?
ugh okay i give up on trying to not use regex
how do i get a list of all text inside 2 chars
so like "afinjskdf :text: sdfunjlk :yue:"
why not use regex? its way simple
and it would return a list that is [text, yue]
honestly i just dont know what to do at this point
oh wait then
I got exactly what u need
private static String emojify(String message) {
String[] split = message.split(":");
StringBuilder sb = new StringBuilder();
for (String s : split) {
sb.append(emojis.getOrDefault(":" + s + ":", s));
}
return sb.toString();
}
``` rn i got this but it does not allow the user to have a : anywhere
:(.*?):
Use this pattern
yah, actually i found the error and fixed but still thanks
":(.*?):"
Java String
Would you like to share the solution? So if anyone has that problem in future they can refer to this
guys can anyone help me figure up why it isn't working?
Pattern pattern = Pattern.compile(":(.*?):");
if (matcher.find()) {
String[] result = pattern.split(str);
System.out.println(Arrays.toString(result));
}
@red sedge
I am sorry but I have never tried TabCompletion so
๐ฅ
have you registered it
why dont u try adding some print statements to debug it
yes
before returning, send the list to the player so u can see if it is full or not and then find the cause
aegs.length == 0
patterns are confusing asf
not actually
Kinda, but that should do it for u
Pattern pattern = Pattern.compile(":(.*?):");
if (matcher.find()) {
String[] result = pattern.split(str);
System.out.println(Arrays.toString(result));
//Use the array `result`
}
Cannot resolve method 'print' in 'spawnmobTabCompleter' what???
print isnt a method
?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.
sender.sendMessage(mobs.toString());
@harsh totem
private static String emojify(String message) {
Matcher matcher = pattern.matcher(message);
while (matcher.find()) {
String s = matcher.group();
message = message.replace(s, emojis.getOrDefault(s, s));
}
return message;
}
```?
You can use regex for replacements
my brain is about to crash
i would use indexOf btw
Whats your usecase
what's thatยฟ
you need to save it
like what are u trying to do
for it to update on the disk
^^
which is the method for that?
Function<MatchResult, String> replacer = result -> ...;
Matcher stringMatcher = somePattern.matcher(input);
String replaced = stringMatcher.replaceAll(replacer);
saveConfig() i believe
Don't use toCharArray create your own string parser using only binary and run it as an external program in Java
it still doesn't work but the file appeared
every thing that I outputed was exactly what it should be
but it still doesn't work
return is a problem then
Hey Guys How Can I Sett Skull to Zombie Head
You cant. Those are two different Materials.
ItemStack zombieHead = new ItemStack(Material.ZOMBIE_HEAD);
Then update to a version that is actually used by people and not some dusty ancient version from half a decade ago.
Looks scuffed. Shading in a jar makes no sense.
what i should to do?
Is it possible to create a config without doing it manually?
createDefaultConfig()
Gives me an IllegalArgumentException
Btw VK is vulnerable to CVE-2021-44228
What do you mean by "manually"?
print the whole stacktrace
^
ok, gimme a sec
maybe he want a config api
use the jar with -all in it
Not the entire exception, but I think this should be the most important part
java.lang.IllegalArgumentException: The embedded resource 'config.yml' cannot be found in plugins\Main-1.0-SNAPSHOT.jar
at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:193) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPlugin.saveDefaultConfig(JavaPlugin.java:180) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at de.firecreeper82.main.Main.createConfig(Main.java:23) ~[?:?]
at de.firecreeper82.main.Main.onEnable(Main.java:19) ~[?:?]
Add a config.yml to your jar
maven
btw this looks like shadowJar is not being run
ok
What do you do to compile the jar?
i use shadowjar and do relocate of packages
How exactly? Do you use the command line? Do you use the buildin gradle tasks?
all what i need is use api without individual plugin
just idea's build
and
tasks {
build {
dependsOn(shadowJar)
}
}
Ok. This means you can delete all gradle files because you dont use them. At all.
sigh

Hello everyone! I heard no async threads should use bukkit api. But is that related to YamlConfiguration class? I mean it's also a part of the api
This is the most beginner friendly way of building gradle projects:
And can I somehow use it outside the plugin? There are just too good methods to make own using snakeyaml
bro u're laughing that i dont understand all functions but you cant help me
ok..
Im not laughing at all. Im just a bit annoyed that people jump into Gradle without reading a very short, 5 minute article on how to use gradle in the
first place or what it actually does.
"7smile" and "can't help" never belong in the same sentence
YamlConfigurations are not thread safe as they are backed by just a simple HashMap.
But you can use them in async contexts as long as you only mutate it from a single thread.
yes. we learn from tutorials where it is not explained
that we must read gradle documentation
Thank you for explanation
You mean not simultaneously?
Why do you need to use YamlConfigurations in an async context anyways?
What is the best way to determine servers when sending redis publish / subscribe? I mean e.g. which server sends the message to the proxy and vice versa.
to save data in file while running the server without mini-pausing it if the saving takes too long
it can make gameplay worse with the thing I am making
I mean not to run the config operations in a single tick
The message you send can have all the fields you want to.
You can just send the sender in the message: (kotlin)
abstract class ServerMessage(val serverName: String) {
}
Or without any abstraction for simple messages:
data class ServerTextMessage(val serverName: String, val textMessage: String)
So, is this yamlConfiguration thing uploaded somewhere as an independent library?
And convert it to json (message object) and then send it as string will be good solution?
No you can just send the object as long as everyone uses the same Codec<>
I have this tabCompleter and when I use the command thw command works but the tabCompleter doesn't. I checked the variables and it says that when I use /spawnmob COW 5, args[0] is COW args[1] is 5 mob is the list of all entities and the name of the command is spawnmob. all of the variables are what they should be and yet it does not work. can you help?
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
List<String> mobs = new ArrayList<>(Arrays.stream(EntityType.values()).map(Enum::name).toList());
System.out.println(mobs);
System.out.println(command.getName());
for (int i = 0; i < args.length; i++){
System.out.println(args[i]);
}
if (command.getName().equalsIgnoreCase("spawnmob") && args.length == 1) {
return mobs;
}
System.out.println(args[0] + " " + args[1]);
return null;
}
}```
Wait, but what if wome other plugin is using it from the main thread at the same time? Will this cause problems?
If you create a new YamlConfig and save it then you are good to go. Thats how you should handle IO anyways.
so you mean I just shouldn't perform multiple operations on the same config object at the same time?
ok
thank you
I can't figure out why my plugin's soft dependencies are loading afterwards. In plugin.yml I have this
softdepend: [ ExecutableItems, SCore ]
yet both of those are loading first
loading before ur plugin?
problem is I need them loaded beforehard but my plugin loads first
Do depend then
problem is they are optional
I did test with depend and that did make them load first
softdepend should make them load first too, what is it saying to make you think yours is loading first?
server console shows it enables my plugin then afterwards runs all the other plugins startup messages.
In my plugin it's calling Bukkit.getPluginManager().isPluginEnabled(plugin)) and it's returning false since hasn't been enabled yet
Is it allowed to use # in a permission string?
I have a few other soft dependency plugins and they load first, it seems to be something special about this particular plugin that refuses to load first
Hack the PluginManager ๐
From an old project
impressive!
I know, this will make sure my plugin is enabled first
And it will disable last
SimpleReflection reflectedPluginManager = ReflectionProvider.reflect(Bukkit.getServer().getPluginManager());
Map<Pattern, PluginLoader> pluginLoaders = new HashMap<>(reflectedPluginManager.getField("fileAssociations").getObjectInstance(Map.class));
JavaPluginLoader javaPluginLoader = null;
for(PluginLoader pluginLoader : pluginLoaders.values())
{
if(pluginLoader instanceof JavaPluginLoader)
{
javaPluginLoader = (JavaPluginLoader) pluginLoader;
break;
}
}
javaPluginLoader.enablePlugin(this);
getServer().getPluginManager().registerEvents(this, this);
BukkitPluginManager bukkitPluginManager = new BukkitPluginManager(javaPluginLoader);
pluginLoaders.put(Pattern.compile("\\.jar$"), bukkitPluginManager);
reflectedPluginManager.setField("fileAssociations", pluginLoaders);
This is custom reflection btw, are you able to understand it?
is it possible to increase the amount of time particle stays
cuz it disapears instatly
mostly, that's above my skill level but I can see what it is doing
Ok if you understand Java reflection you will be good
Hey Guys How Can I Set "name config" When Player enter String(name) get message and change config?
OMG
I WORKED ON MY BEDWARS WIN CHECK FOR AN HOUR
and it works!
that stuff can get CONFUSING very fast
is there any way to create circle shape particle, by any formula or something?
worldedit has done it and some other plugins, so yeah
So i'm making a boss bar and i'm very confused cause this error has something to do with a skull:
- Get all teams
- Exclude the ones with 0 players
- If there is one left, then that team won
Simply move players from their team to the spectator team if they got final killed
It seems you have an error on line 7
import org.bukkit.boss.BarStyle;```???
It is a joke
Show us the code
I can't see what error you have unless I see what you did
There is no stacktrace outside Paper/MC there. is there no more to the error after line 32?
this is where i make the bar i think:
private BossBar countdownBar;
public Game_Manager(PluginName plugin) {
this.plugin = plugin;
this.team_manager = plugin.getTeam_Manager();
this.maps_manager = plugin.getMaps_Manager();
//items = maps_manager.getItems();
countdownBar = Bukkit.createBossBar("Countdown", BarColor.WHITE, BarStyle.SOLID);
}```
nope
my actual code is:
Oh no
no
no
no
no
Why
what?
Yeah i know about that
that are not public static final variables
why do you do that
Cause i'm not the only one working on this project so i didn't make those
Are you using intellij?
yes
if (team.getDeathPlayers().size() >= team.players.size()) {
for (GameTeam tm : gameTeams) {
if (tm.getTeamId() != team.getTeamId() && tm.getDeathPlayers().size() < tm.players.size()) {
System.out.println(tm.getTeamName() + " team was added to potential win");
temp.add(tm);
}
}
}
I am aware i can fix them
right click, refactor, rename
Just looking for the issue today since i can't wrap my head around that error
Not worried about names right now
idc if it can be simplified, it works
public void startCountdown() {
countdownRunning = true;
countdownBar.setVisible(true);
countdownBar.setProgress(1.0);
countdown = new BukkitRunnable() {
private int timer = 15;
private final double mathStuff = 1.0/timer;
@Override
public void run() {
//timer--;
if (timer == 0) {
this.cancel();
startGame();
return;
}
plugin.getServer().broadcastMessage("Game starts in: " + timer + " Second(s)");
countdownBar.setProgress(countdownBar.getProgress()-mathStuff);
timer--;
}
};
countdown.runTaskTimer(plugin, 0, 20);
}```
This is where i mainly use the boss bar
if(teams.stream().filter(Team::hasPlayers).count() == 1) {
// Win condition
return;
}
Thats fine
They probs did it when sending
I sometimes do that too
Yeah i replaced it when sending
NDA stuffs
Do you really need to question my methods?
I come here asking for help for an error i do not understand
Not to be judged
don't see an error here
can you please show more
What about this one?
Nothing
public void stopCountdown() {
countdown.cancel();
countdownRunning = false;
countdownBar.setVisible(false);
}``` this is my stop countdown
^
I think i do that somewhere else
not sure why it would act up when adding the boss bar
I also have no idea what class it would be erroring in
wait looping and modifying it.... No just looping and adding stuff
Do you get this error when running vanilla Spigot?
Don't think so no
Then its a Paper issue
well i haven't tried vanilla spigot with this plugin
Paper doing things async and you are fetching Players sync
But the plugin was working just fine before i added the boss bar
Then it errors when i run start countdown
Which is here
It may be the boss bar code causing issues, if your teams are holding a stale player object that Paper has already removed
um, no Teams stuff in there
yeah that's the thing
it shouldn't be erroring
the boss bar doesn't do anything with teams here
Do you reference ANY Player objects in yoru boss bar code?
Nope
Then I see no reason for your error. Test with Spigot and see if it still happens
Unless you count .setVisible
But that's just true and false
Eh. Doesn't need to be in my use case
Easier said then done
We are Spigot support here. So we need to know if this is actually a Spigot issue or a Paper one.
We see nothing in yoru code that could be causing the error so the only thign left is to test on Spigot
I'm aware of that but i can't just go and easily swap our entire dev sever over to a different .jar. And i can't just do a local server since running 2 minecraft clients + a local server + Inteliji + discord + firefox would quickly cap my computer specs
Can I detect when someone refreshes server list to send a different motd? I don't manage to see it in the docs (in skript I was able to do so)
I am currently waiting 5 minutes so i can do speak there
do you think it would be ok if I had my plugin send a message with the syntax of the command instead of it trying to auto complete it?
But i doubt they will help since i'm using the spigot API and not any paper api stuff
how can you place entire Buildings with a plugin?
Hmm, can u explain it a bit? I tried now to use serializationUtils and serialize/deserialize method, but It doesn't work for me.
Structure block api is pretty good
The error is showing a concurrent modification exception when fetching a GameProfile. You are running everything Sync and there is no mention of any of your code/plugin in the stacktrace. Looks like a Paper issue to me.
Yeah it is a paper issue. but what i'm saying is my plugin is not a paper exclusive plugin
It is designed using the spigot thingy and not paper
How in the world is that being triggered by a new boss bar
its not. Its nothign to do with your Bossbar
oh
probably you moved areas which loaded a chunk with a bad skull?
well my boss bar isn't rendering and it was triggered as soon as it should have
and i don't think there are any skulls placed
I guess i shall talk with the server owner and have them put the args in the server so i can find it
cause that will cause issues when debuggin
debugging*
It has to be a skull
I realized the error was as soon as my second tester joined the game
Maybe i shall delete their playerdata
If I have something like this:
effects:
- name: "ยง5Defence"
duration: 10
amplifier: 2
- name: "ยง5Speed"
duration: 10
amplifier: 2
If I do
Main.config.getList("Potions." + args[1] + ".effects")
How would I get the name or duration?
StringUtil.copyPartialMatches from the bukkit package will be able to write the same thing in one or two lines
wdym
// length checks and stuff
return StringUtil.copyPartialMatches(args[0], Arrays.stream(EntityType.values()).toList(), new ArrayList<>());```
assuming that the entity type is the first argument entered
you might even want to cache the result of that stream
If I send plugin message channel (own), that get info from proxy and I want to send chat message with that info to certain player should I do it on proxy, or send it again to the server and here send chat message?
Nothing, it won't load due to an error, the yaml format is wrong
example:
effects:
defence:
name: "ยง5Defence"
duration: 10
amplifier: 2
speed:
name: "ยง5Speed"
duration: 10
amplifier: 2
that is correct
ok, thx
^
in my opinion, the round trip to the server is probably best
most of your state, logic, all that jazz lives on the server
if you have anything that is appended to the message (idk rank or whatnot) you need the server most likely
unless you also fetch that on the proxy, but then you are doubling logic a lot
Is there a way for me to make it so that if I don't input any number it will only spawn 1 instead of giving me the error below?
else if (command.getName().equalsIgnoreCase("spawnmob")) {
EntityType entity = EntityType.valueOf(args[0].toUpperCase());
if (args.length >= 2) {
try {
int amount = Integer.parseInt(args[1]);
System.out.println(amount);
try {
for (int i = 0; i < amount; i++) {
player.getWorld().spawnEntity(player.getLocation(), entity);
}
} catch (IllegalArgumentException e){
player.sendMessage(ChatColor.RED + "That is not a valid number");
}
} catch (IllegalArgumentException e) {
player.sendMessage(ChatColor.RED + "That is not a valid entity");
}
} else {
player.sendMessage(ChatColor.RED + "(!) /spawnmob <mob> <amount>");
}
}```
Learn Java?
You can do that with some basic if else checks and that's the bad way to do that
So true lmao
Yep same here
uuuuhm my eyes
dont put all the stuff that wont cause an illegal arg ex in the same try block
im not
Constructive criticism isn't rude
how to freeze particles
Can I somehow have every Class that used a constructor implement a method/interface?
wha-
I want to have every class using a specific constructor implement an interface
is there a way to to force Bukkit.getOfflinePlayer(uuid) to do a web lookup like Bukkit.getOfflinePlayer(name) does when the player has never joined before? (when the OfflinePlayer from Bukkit.getOfflinePlayer(uuid) starts returning null for everything)
im still wondering which one does a web lookup cuz i searched in the decompiled code and didnt find it
Bukkit.getOfflinePlayer(name) seems to return the player regardless of if theyve joined or not
something like Bukkit.getOfflinePlayer(uuid).getName() when the player has never joined returns "null" as a string
I'm trying to make it so that it detects if the entity is valid and if the number is valid and if you don't put any number it only spawns 1 entity but when I use it in game the it doesn't give me the error messages that it should give.
if (args.length >= 2) {
try {
EntityType entity = EntityType.valueOf(args[0].toUpperCase());
try {
int amount = Integer.parseInt(args[1]);
for (int i = 0; i < amount; i++) {
player.getWorld().spawnEntity(player.getLocation(), entity);
}
} catch (NumberFormatException nfe) {
if (args[1] == "") {
player.getWorld().spawnEntity(player.getLocation(), entity);
} else {
player.sendMessage(ChatColor.RED + "That is not a valid number");
}
}
} catch (IllegalArgumentException e) {
player.sendMessage(ChatColor.RED + "That is not a valid entity");
}
} else {
player.sendMessage(ChatColor.RED + "(!) /spawnmob <mob> <amount>");
}
}```
pretty sure Bukkit.getOfflinePlayer(name) is deprecated for the very reason that it uses a web lookup, might be an idea to fork spigot and add a feature to it where if it cant find it, it saves it to wherever Bukkit.getOfflinePlayer(uuid) looks
its deprecated because names are no longer unique past a single session
how can I detect when someone is trying to put their armour off?
So, I am storing data in player PDC's
Is there a way to remove data from PDC's of offline players
it also lags the server a ton
what lol
Because of the server making a request to the mojang api to get data
yea
particles are client side i believe
When should I test my code ?
I've been working on a plugin for like 6 hours
but didn't try any of it on mc yet
How would I sort a list of objects according to an integer variable inside that object? So like
private int priority;
}
and sort a List<Test> from 0 to above 0 coming at first
#sort(<use priority as comparator>);
Idk how to
I made this
@Override
public int compare(Test o1, Test o2) {
return o1.getPriority() - o2.getPriority();
}
}``` but it doesnt owrk
as in it doesnโt sort them properly?
whatโs your code for the actual sorting
Debug.consoleWarn(itemStatsContainer.toString());
itemStatsContainer.sort(new SortByPriority());
Debug.consoleWarn(itemStatsContainer.toString());
well usually i do but my computer doesn't have that much ram and it's complicated to test while coding
args is an array, in order to check if there isnโt anything in an args [] instance you should use the args.lenght.
i have already fixed it but thanks anyways
๐๐
How Can I Use Economy On My Plugin? Its With API or something like that ?
thank you so much ๐
Don't Excuse My Amateurishness but How Can I Use that on my codes? I readed but dont get it...
add it to your dependencies
and let your plugin depend/ soft-depend on it in your plugin.yml
how do I get a player variable from a string of it's name?
Oh Okay, Thank You ๐
Bukkit.getPlayerExact("name here")
thx
how do i make a Player variable public to other classes ?
how can i create a spectator mode without using the actual gamemode? I want the player to be able to use items in the inventory but I want them to not be visible to the rest of the server and not interfere with any projectiles/block placing
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Saturation is used to "fast" heal when you have full foodbar. I assume that's the value per half a heart regenerated
I have this in my main file and when the plugin is turned on I get this error: the return value of "com.ytg667.myplugin.MyPlugin.getCommand(String)" is null
public void onEnable() {
// Plugin startup logic
getServer().getPluginManager().registerEvents(new TutorialEvents(), this);
getCommand("heal").setExecutor(new TutorialCommands());
getCommand("feed").setExecutor(new TutorialCommands());
getCommand("spawnmob").setExecutor(new TutorialCommands());
getCommand("spawnmob").setTabCompleter(new spawnmobTabCompleter());
getCommand("tphere").setExecutor(new TutorialCommands());
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[MyPlugin]: plugin is enabled!");
}```
Did you register the command in the plugin.yml
description: Tp's a player to you
usage: /<command> <player>```
heal:
description: Heals a player
usage: /<command>
feed:
description: Feeds a player
usage: /<command>
spawnmob:
description: Spawns mobs at a player
usage: /<command> <entity> <amount>
tphere:
description: Tp's a player to you
usage: /<command> <player>```
tphere has wrong spacing
good
I'm so confused on how DI works
I'm just trying to pass a player var from a command executor to a listener
pass it as an argument?
Well I need to use it in the listener
so pass it as an argument into the listener
like the targeted player
wdym
like youโre listening for an event?
and you want to pass your player into that?
No
I have a command that needs a player as of an arg, and I need to then use this player in my event listener
i donโt know what you mean by โuse this player in my event listenerโ
does inventory#getContents include slots that contain nothing?
events are supposed to be called by bukkit or somewhere else
you wouldnโt just use it as a function
well i need to change the targeted player's gamemode in my event listener
why does it need to be in an event listener?
because it is in a gui
I didn't code the listener yet though
public boolean onCommand1(CommandSender sender, Command cmd, String msg, String[] args) {
if(sender instanceof Player) {
Player player = (Player)sender;
if(cmd.getName().equalsIgnoreCase("gm")) {
if(args.length == 0) {
player.openInventory(inv);
Player play = (Player) sender;
}
if(args.length >1 && args.length <0 ) {player.sendMessage("ยง8[ยง2Kiwi pvpยง8] ยงfWrong number of arguments");}
else {
player.openInventory(inv);
Player p = Bukkit.getPlayerExact(args[0]);
if (p != null) {
String pName = args[0];
Player play = Bukkit.getPlayer(pName);
} else {
sender.sendMessage("ยง8[ยง2Kiwi pvpยง8] ยงcPlayer doesn't exist");
}
}
return true;
}
}
return false;
}```
this command
opens a gui
with 4 choices
and either changes your own gamemode, or the one of the targeted player
can I add a costum tag or something to a villager so I can detect that it's the right one
so i updated my development server and it needs to download the files and im at school and they have the endpoint blocked..... what can i do?
but to check which slot the player clicks on, I need that to be in the listener
to change the gamemode regarding of which the players clicks
ok so
Yes
Wait
No it doesnt
a listener listens for an event
when the event is called itโll pass the event along with extra information to that function
Persistent data containera
you would not give a player to the event
the event already contains the player who clicked
Yes, but I need to change the gamemode of the player put in the command's arg and not the one who clicks
then you would need to make a class for this
and make itโs constructor have your command arg
then use that in your listener
Godzilla had a stroke trying to understand the code and fucking died
Ok. That was a joke
I know ๐ญ
What are you exactly trying to do
this is bad, dont check the command in the command and create the listener for specific command
what
i like to have a different class for each of my commands
@trail oriole
yes this is what i mean
Also name the pointers what they realy are
For example target instead of p
Cool tips
I want to have a command that takes a player as an argument, then opens a gui with 4 items being the 4 gamemodes, then changes the gamemode of the targeted (arg) player to the one clicked on
Didn't try it yet, wanted to get done with this command before
like before testing it
and I don't have problems with the listener itself (yet), but with how to get the player from the command to the listener
both being in different java files
I set 3 variables. While doing the 2nd operation, it enters the variable I used before for the 3rd variable, how do I prevent this?
put the listener in the command is the simplest option
No
honestly I started java 2 days ago
๐
static abuse here we go
so not really
No
Im just trying to tell him to make a processor
a processor?
I can try
amd ryzen 5 like
InventoryProcessor
HashMap player inv
addInv
removeInv
hasInv
getInv
Hey Guys Can You Help Me Please I set 3 varible of Name, Healthi Type. Its like this
Please enter boss name
name
Please enter boss health
but When I do 2nd operation, it enteres the varible I used before 3rd varible, hwo do I prevent this But Its happening just on 3rd varible
no need to store inventories basically
Add the player and the inv to the processor
And in the listener check if hasinv and then getinv
@trail oriole also learn more java before coding spigot, it will be hard to help you if you dont know much java
Good luck!
the only thing im doing is making a custom inventory class which extends InventoryHolder and which has a listener in it to checks for clicks dynamically
Well how do I learn java without practicing ?
not
Watching tutorials doesn't help much
Yes i do this to
Im trying to make it simple
And I figured spigot would be a good way to practice ?
am i being dumb
if you dont have a basic knowledge of java, its not the best practice
i am?
Do simpler things first
Custom gui is hard in the start
after the getOnline.. ())
Nono
oh yeah i am
I know how to do and use gui's
Forgot a )
thanks
x)
You are trying to make one
The slots?
I can make the listener too
nope
The problem is only getting that player variable into the listener
Just open gui in cmd
And then see if the clicked gui in the listener has a title of blabla
Handle the slots
event.getplayer
event.getinventory.getname
You can set the holder
And check with instanceof
But it will be hard
you usually get a player variable by calling the getPlayer method on the event object
Anyway I can do this ๐ค
I'm trying to create the same listener for every event which I put in the list
I'm guessing this doesn't work cause of type erasure
But the player I need is not the one in the gui, but the one put in the arg of the command
I am wanting to know what the best way would be to protect certain blocks from damage.
I know that I can make a listener for breaking blocks and stop it there, but is that the best way to do it for lots of little areas (the area is 3x4x3)
You just open the gui to the player with command
In the click listener check if the gui is a gamemode gui
Oh
Target player
Aaaaa
I understand now
doesnt this work
private <T extends Event> PermissionManager() {}``` im bad at generics lol
i'm sorry if I am not clear
and then do the generic stuff in the body
I got it my problem
How would I change the custom texture id and the tag of an ItemStack
@trail oriole you need to add data with inventoryholder
If anyone can give him an example please help him, im with a phone
I want to do it for every one in the list, not manually specify
I am wanting to know what the best way
Search in spigot how to load schematic with worldedit
private <T extends Event> PermissionManager() {
for (Class<T> clazz : permissionsList) {
new AbstractListener<T>() {}
}```isnt this something?
what did you mean by add data to inventoryHolder ?
do you know what implementing an interface is?
good
does not likey
what is it saying
and change the <eventclass> to <T> too
where
in the createListener() method
generics aaahhh
basically I want the same thing to be performed every time for a bunch of listeners
is the abstractListene rinerface smth liek
interface AbstractListener<T extends Event> {
@EventHandler
void trigger(T t);
}```
but don't want to have to register a listener every time
How would I change the tag of an ItemStack
yeah
im not even sure if you could do it like youre doing
so then I want a list of events, then to go over them and create the same listener each time
as generics get erased on runtime
wfnweoufowefweofnswewee
no
mkay
I wouldn't do things that way
wehat do you want there?
me?
This looks like a really cursed way of registering listeners
^
?jd-s
why not do it like that ๐ค
that is the display name, not the tag
I've noticed that you have a habit of doing thing the hard way
Oh sorry I couldnt catch it
np
what tag?
lol quite possibly
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/PluginManager.html#registerEvent(java.lang.Class,org.bukkit.event.Listener,org.bukkit.event.EventPriority,org.bukkit.plugin.EventExecutor,org.bukkit.plugin.Plugin) you need to pass the class of the event you are listening for in one way or another, you cannot get teh class via generics though
That being said, generics can enforce certain things there
You can give custom tags to items and entities with commands, but I dont know how to do that in a plugin
thats pdc iirc
So really, use the method I linked to instead of using the built-in bukkit way of declaring listeners
So is there a way of doing what I'm trying to do?
?pdc
To some degree yes, but not exactly like that
right
Leme draw up some code how I think it may work
?
kk ty
this system may be useless
public abstract class AbstractHandler<T extends Event> implements Listener {
public AbstractHandler(Class<T> type, Plugin pl) {
Bukkit.getPluginManager().registerEvent(type, this, EventPriority.NORMAL, (x, evt) -> trigger(evt), pl);
}
public abstract trigger(T event);
}
Of course there will be people shouting that such code does not belong in the constructor but to those people: I challenge your to write it in your way and post it there so I can ridicule the "correct" way as there is no correct way
nvm, found a way
how to make villager no ai, 1.8 I can't find NBTTagCompound class
Did you import NMS
hey guys How can I perform an action 5 seconds after the event?
not really, is that a library
?scheduling
Are you sure that you should be using 1.8 without proper knowledge of miencraft internals (for reference NMS is the net.minecraft.server package, which is built into the server)?
thanks
That being said, in bukkit world the nms package is obfuscated
I found that
Ugh, that is such a bad argument
The real argument is that NMS is just pain; it wasn't written for use by plugins - bukkit was
then nope
is there any other way to make a villager no-ai
for example how hypixel did it in bw
1.8 does not have mojmap however
here are your functions:
a()
a()
a()
a()
a()
b()
b()
c()
c()
c()
aa()
ab()
have fun
!
https://helpch.at/docs/1.8.8/ here, go find it yourself
1.8.8 is old as hell and was compiled at a time where a search feature wasn't introduced in javadocs
I normally use 1.18 but now I need 1.8.8 for bw
but it appears that there is no pathfinding goal API there yet
that being said you might be able to emulate the no moving part via potion effect - albeit this is a REALLY cursed solution
Any update?
.
ah whoops skipped over, okay lemme look
what if I give him a slow potion of a lvl 255 or the max limit
no idea really
choose wisely
lol
As well as the class instance through the constructor
mhm but still the generic is required
this works fine to be clear
The issue was trying to create a series of listeners from a list of event classes
Are you sure that this works?
so that I could create the same listener for a bunch of different events without having to make a new method each time
Hm, then javac is generating bridge methods
that also works
Bukkit.getPluginManager().registerEvent(type, this, EventPriority.NORMAL, (x, evt) -> trigger(evt), pl); is still the way to do it
Because to listen for another event type X you just pass it's class
but you still need to provide the generic of the class
The reflection instance of the class yes, how else would you do it?
but isn't passing the generic in the whole issue in the first place?
trying to do a generic like that
Valhalla is not here there so generics can be ignored
Not the generic, the class instance
wot
Brain was temporarily fried
I am still confused lol
Basically generics are still in the same miserable state as they were 10 years ago: Effectively useless beyond compile time
You have to pass the concrete class instance
I get that much
but that still required a generic
So something like
new AbstractListener<Event>(eventClass, this) {
// ...
... I think
oh right
You can just ignore the generic after all
Or just not have the generic present at all in my AbstractHandler class
i mean
itโs possible to just use the generic in the interface trigger event as well
iโve used something like that at some point
Nah, that is not how java works - you have to pass the concrete instance of the class somehow or hope that you compiler generates bridge methods in the way you expect it to generate
donโt think youโre understanding
ik that types get erased at runtime
but the type of a parameter doesnโt
this is a phenomenon called bridge methods
That type wont get erased tho
Unless you are talking about something else where the generics do not matter at all
If a class derivative defines the type for its super class type parameter the type cannot go erased
I have a hard time guessing whether you guys are talking about java.lang.Class or generic signatures
how would i shade this in my gradle file? i cant find anything online https://github.com/tchristofferson/Config-Updater
yeah
iโm saying in this example it could be something like
Shade it into the jar you mean?
well i need to add something to my gradle file
Myes
You need to add teh gradle shadow plugin
And then you need to compile that plugin/lib via mvn install
Can someone recommend me a tutorial for creating teams and managing them
For a game like Bedwars
(syntax error probably because on mobile)
public interface Example<T>{
void trigger(T test);
}
And then you can add mavenLocal() to the repositories
i dont have/use maven
whenever something implements Example itโll have to profile itโs generic type
which in turn defines the param type
Okay yeah, then that only works if you use that as the EventExecutor, but not for the registering itself
i dont even know if i need to shade it i just wanna be able to use it
Then you are out of luck unless you find some repo that has that dependency
oh it's on ossrh apparently
I have a hard time beliving it however: https://mvnrepository.com/search?q=com.tchristofferson
i mean the handler idea doesnโt make sense in the first place
it's just a QoL thing
how would you have multiple event handlers in only one listener
you would have to define whatever you want to happen in that one method
unless you had a mapping or something between events and event handlers
but at that point why not just register it normally
QoL
https://repo1.maven.org/maven2/com/tchristofferson/ConfigUpdater/2.0-SNAPSHOT/ConfigUpdater-2.0-SNAPSHOT.jar apparently that lib is not published to maven central
Geol i have some issues too using your code, because i cannot use Boostrap boostrap on constructor
Its oblise me to either use BungeePlatform or SpigotPlatform class, because then i cannot access to the methods
๐ฎโ๐จ
I mean the biggest benefit with using EventExecutor over the normal Listener api is the fact that you can avoid reflective invocations
which was a huge benefit when reflection wasnt particularly optimized like it is today
Java 8 == shity reflections just dont use it if u use tha java version
mye
Basically you will have some something like this @sterile token
Bukkit launches SpigotPlattform -> Finds & Launches your plattform-independent plugin class
Bungee launches BungeePlattform -> Finds & Launches your plattform-independent plugin class
Method handles ๐
Hmn
Im have a nightmae in fact
You probably can use the service loader API for that if you want extra nightmare fuel
I almost finished the bedwars plugin
Oh in that case you could've just made the villagers be imprisoned instead of preventing them from moving
Clever map design can hide a few code design issues ๐
Why the reason of using prvate methods if then you can access via reflections ๐ค
watttt