#help-development
1 messages · Page 2185 of 1
remove it in the inventory close event
It is why
lol
youre removing it before the inventory is closed
no matter what, the inventory close event always fires tru
remove the uuid in the inventory close event
ok
The inventory close event fires AFTER render
So you’re adding it and removing it before the inventory close event checks if it’s there
So it’s never there by the time it’s checked
lol
np
openInventory closes all existing inventories (firing the close event) and then opens the new one (firing the open event)
also pls tell you you stopped cloning and using the setter to set the set
ok
What
oops not even that
Good
it is 5:45am
uh so im trying to get a villager to lower his prices down to 1 paper/emerald once he is healed but the villager somehow doesnt change his price at all
public class ChangeTradeEvent implements Listener {
@EventHandler
public void onCure(EntityTransformEvent e){
if(e.getTransformedEntity() instanceof Villager){
Villager villager = (Villager) e.getTransformedEntity();
List<MerchantRecipe> recipes = Lists.newArrayList(villager.getRecipes());
for(int j = 0; j<recipes.size(); j++){
MerchantRecipe mr = recipes.get(j);
List<ItemStack> ls = Lists.newArrayList(mr.getIngredients());
for(int i = 0; i < ls.size(); i++){
ls.set(i, new ItemStack(ls.get(i).getType()));
}
mr.setIngredients(ls);
recipes.set(j, mr);
}
villager.setRecipes(recipes);
}
}
}```
^here's my code
I finally got it working! :D https://streamable.com/5u7i44
That's beautiful
Idk but that looks great
how do I tell maven that it should save the plugin at X path?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>(your path here)</outputDirectory>
</configuration>
</plugin>
put it inside <plugins>
thank you
I use
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<outputFile>C:\Users\You\Path...\plugins\YourPlugin_v${project.version}.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>``` all the time
Is it the like doing the same thing?
Since you have to shade spigot anyway you can just add <outputFile>C:\Users\You\Path...\plugins\YourPlugin_v${project.version}.jar</outputFile> to the maven shade plugin instead of adding the hole maven-jar plugin
Never shade Spigot
So all of your plugins are 50mb+ filled with useless classes that will prevent your plugin from loading
Ok
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>```
This means it's not shaded?
No
a scope of provided prevents it shading that resource by default. You have the shade plugin though, so you are telling it to shade
unless you specify what you want shaded
Can someone have a look over my pom I think it's a bit weird
https://paste.md-5.net/otadelezez.xml
anything I should change?
Hey. I saw that classes like Sound or EntityType implement the Keyed interface. I wanted to use the key for serialization but could not find a method to get a sound or entitytype from namespacedKey. Is there a method yet that i havent found or should i implement one myself?
show all oyur code
then theres already a variable named player defined in the scope
as it says player is already defined
if ((sender instanceof Player player)) {```
you are defining player twice
you dont need to set the main class as the executor
and checking after you cast it anyway lol
just remove Player player = (Player) sender;
what the fuck
code first echeck error log after? lol
if(!(sender instanceof Player)) {
...message
return;
}
Player player = (Player) sender;
i think this will do
in newer java versions java x instanceof Class y defines a new variable
if (!(sender instanceof Player player)) {
return ...;
}
// player
this also works sometimes
for some weird reason, occasionally i cant access player after a statement like that
like sometimes it compiles and other times it doesnt
Is there a way to replace a file in a player's resource pack, or like set his resource pack to a custom one, play a sound from it and set it back to is own resourcepack?
or what would be a good way to play a custom sound to him
if you're using player outside of the if statement you are doing it incorrectly anyway
remove the player bit
you are defining a variable which is not of type Player
logically doesnt make sense
yeah but only in the scope of the if statement not in the surroundings right
public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
if ((sender instanceof Player)) {
Player player = (Player) sender;
player.sendMessage("§cThis command for only players."); //doesn't make sense but whatever
return false;```
yeah
well the inner scope
first check then cast
i think thats still what hes trying to do
🤷 anyone knowing something about the keyed interface and how to get enum constants from namespaced keys?
Anything in the console?
?jd-s
java.lang.ClassCastException: class com.destroystokyo.paper.console.TerminalConsoleCommandSender cannot be cast to class org.bukkit.entity.Player
you are casting console to player
meaning your instanceof check isnt correct
looks fine to me
Show the whole command class as it is right now
als long as he only uses player in that if
if ((sender instanceof Player)) {
Player player = (Player) sender;
player.sendMessage("§cThis command for only players.");
return false;
}
Player player = (Player) sender;```
you are checking instanceof, returning then casting
Player player = (Player) sender;
so sender will always be console
you are casting the sender to a player when the sender is not a player
if (!(sender instanceof Player)) {
instead
change this whole thing
if ((sender instanceof Player)) {
Player player = (Player) sender;
player.sendMessage("§cThis command for only players.");
return false;
}
to
if (!(sender instanceof Player)) {
sender.sendMessage("§cThis command for only players.");
return false;
}```
if(sender instanceof Player) {
Player p = (Player) sender;
//do stuff
} else {
sender.sendMessage("You have to be a player!");
}```
Is there in any way to convert 1.17 to 1.18 world without making the buildings fucked up or something?
save the buildings in a worldedit schematic then
Too big, it will crash the server
how big
2k x 2k
oh shit I mean save them by chunks if u want
unless the whole 2k x 2k is occupied in every space
does anyone know how to format numbers with prefixes? e.g: 1,000 into 1k
I'll try save it to schematic part by part
Does anyone know how to play that to a player? https://youtu.be/DzhhlHw2q2o?t=186
✔️ It's time to crown the SCARIEST SOUND in Minecraft... 👑
5️⃣ My Top 5 Series Playlist: https://www.youtube.com/watch?v=d2_9Z4ygwjs&list=PLX_aRMYRR9a6lU6tG1raGL2na2jwrTWoj&index=2
👉🏻 Facebook: http://www.facebook.com/mrcubey
👉🏻 Twitter: https://twitter.com/Cubey_YouTube
🎬 JOIN MY TEAM: https://cubezoneserver.enjin.com/
💎 Special Mentions:
• ...
./sound ig
Guardian sound
no its an effect
not sure if it has arguments
Player.playSound?
oh ./effect
Or smth
it will show the guardian on the screen though
and the sound?
yes
you gotta find the right enum effect
there is no effect.guardian
Effect.monument ?
no im on the mc wiki
Sound.ENTITY_ELDER_GUARDIAN_CURSE
found it for u
@iron glade
damn, the world has a custom terrain so I can't do the schematic part by part
its more hassle
well atleast you can preserve the buildings
sometimes compiling with utf is iffy
you have to always copy paste it in where, with the translate you can make a static translate method and statically import it wherever you need to
Thanks I'll try it <3
you can place blocks between the buildings height and width and save em into the schem
public static String format(String s){
return ChatColor.translateAlternateColorCodes('&', s);
}
this is my method
in a Utils class
It plays the sound but not the effect of this rotating thing around the player
kinda tedious doing per building but it will save u a lot of headache since restoring it is not that hard anymore
I think the effect thing is a particle.
Particle.MOB_APPEARANCE
I'll try it
Dumb question but how do I display that particle to the player?
ahh spawnParticle
Player#spawnParticle
works, thanks ^.^
I wonder If you can change the guardian face particle with resource pack.
i havent programmed in long time
how do i find the output directory for my project
using intellij
i just compile and it says the location
do i need to add an artifact to the module
it's target, you can right click and click open in explorer
its not
"target" is the output for the compiled classes
you have to create a jar artifact in module settings and then it'll create a new folder in the directory called "out"
Is there a way to play this specific sound to a player? https://youtu.be/DzhhlHw2q2o?t=367
✔️ It's time to crown the SCARIEST SOUND in Minecraft... 👑
5️⃣ My Top 5 Series Playlist: https://www.youtube.com/watch?v=d2_9Z4ygwjs&list=PLX_aRMYRR9a6lU6tG1raGL2na2jwrTWoj&index=2
👉🏻 Facebook: http://www.facebook.com/mrcubey
👉🏻 Twitter: https://twitter.com/Cubey_YouTube
🎬 JOIN MY TEAM: https://cubezoneserver.enjin.com/
💎 Special Mentions:
• ...
just do what i do
play around with the /playsound command in game
try to find the sound you want
that sound doesn't have a clear name mapped to it
its gonna be somewhere under ambient cave
ok
wait no
unfortunately there's only 1 cave sound
and yes it is randomized
Sound.AMBIENT_CAVE
bruh#
does anybody know why this is happening?
it says its too large
add L to the end of it
.
thanks
yeah java doesnt like implicit conversions
String numAfter = String.format("%,d", num);
is the number too big, or is the keyword wrong?
d isn't a double
what should i use then
a double
num is a double
try %f
it uses scientific notation
can i force it to use regular notation?
Double.toString still returns the scientific notation
How can I return nothing as a tab complete for my command? Say it's a command like /msg Person and then they type whatever they want, how can I just make it blank
If I return null then it's the automatic name option things
that's a setting in the server properties
Return an empty list
im pretty sure you can cancel the tab complete event
Just return empty list
Yea I'm gonna do that
I can't exactly tell every user of the plugin to disable that setting in server properties lol
Inconvenient much
Hey I'm getting this error when trying to use my PlayerJoinEvent listener: https://pastebin.com/h0RiFC32
Here is the code for the PlayerJoinEvent Listener:
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if(config.contains(p.getUniqueId() + ".joinMessage")) {
e.setJoinMessage(customMessage.colourize(Objects.requireNonNull(config.get(p.getUniqueId() + ".joinmessage")).toString()));
}
}```
Any ideas would be greatly appreciated
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.
just saying
path is null probably
what's line 24?
.joinmessage
you have a typo there
capitalize the M
Use FileConfiguration#getString
np
Use NumberFormat or maybe BigDecimal
maybe should be like
if (cmd.getName().equalsIgnoreCase("bilgi")) {
if (!(sender instanceof Player)) {
sender.sendMessage("§cThis command for only players.");
return true;
}
Player player = (Player) sender;
if (player.hasPermission("ServerOperator")) {
//code
}
}```
So what's you want to do?
get a player as an argument?
do Bukkit.getPlayer(args[0])
args[0] being the first argument
assumign that it is a correct name of a player you will get the object
if the name doesnt belong to a player it will be null
make sure to check if it is null and tel the player teh correct syntax
Yep ^
then, if you add a tab completer you can have it suggest all the names of online players
it automatically does that actually
as a default tab complete
its toggleable in server.properties
thing is, that tab complete also comes up for any argument
(if the tab complete isnt overrided)
player.hasPermission("ServerOperator") == player.isOp()
really no need to send ur ENTIRE file
including imports and stuff
it's more something like
Player target = Bukkit.getPlayer(args[0])
here you get the player and assign it to a variable
if (target == null){
player.sendMessage("Incorrect syntax! /command <player>");
}
make sure to check if the player is null
because if args[0] does not equal a name of a player
target will be null
then you just tell the player how to correctly use the command
if target isn't null
if (target == null){
player.sendMessage("Incorrect syntax! /command <player>");
} else {
//DO SOMETHING COOL
}
use the target variable whenever you need to
already over
anyone knows how to make a better looking "N" with dimension 7x5?
can you see a channel help-building here?
This is general so who cares
welcome to #help-development
i do
but anyways
we are developers
we cant do anything else than that
what are blocks? code blocks?
yes indeed
um guys, i m tryna add a custom inventory but my click events are returning when checking if its the same inv
What do you have so far?
public RewardGUI() {
inv = Bukkit.createInventory(null, 9, "Daily Rewards");
initializeItems();
}
the contructor
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
e.getWhoClicked().sendMessage("Clicked");
if (!e.getInventory().equals(inv)) return;
e.getWhoClicked().sendMessage("You clicked on an item!");
e.setCancelled(true);
int[] bgSlots = {0, 6, 8};
for (int slot : bgSlots)
if (e.getSlot() == slot) return;
e.getWhoClicked().sendMessage(e.getSlot() + "");
Util.reward(
(Player) e.getWhoClicked(),
Util.getPlayerRank(
(Player) e.getWhoClicked()
)
);
}
the event
and it is registered, it just returns on equal check
you could make the top left and top right to half stones
and remove some stairs so it looks less bend
I'll try
can i pass this in the task parameter on runTaskLater() to delay execution in a certain part in my runnable?
its probably not the same inv then
i mean it is, as i call the same inventory when i want to open it
probably not. e.getInventory() is the whole inventory (top and bottom) while your inv is just the top one
compare the top inventory with yours
you mean as the runnable? just if your class is implementing Runnable
or what do you mean
uppercase bukkit
isn't something underlined in red for you?
Change the incorrect syntax message to whatever you like bro
I just put it there for example
^
Did some debugging
It says cant pass the event as its null (after line 4 in the func)
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
e.getWhoClicked().sendMessage("Clicked");
e.getInventory().forEach(x -> e.getWhoClicked().sendMessage(x.getType().toString()));
//its executed till the above line, and here it throws a error
e.getWhoClicked().sendMessage("Clicked--");
the syntax is correct, you should tell the executer that this player is not online or smth like that
[15:29:48] [Server thread/ERROR]: Could not pass event InventoryCreativeEvent to RewardsPlugin v1.0
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:2611) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3483-Spigot-42b6152-9cc7d76]
at net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot.a(SourceFile:18) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3483-Spigot-42b6152-9cc7d76]
at net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot.a(SourceFile:7) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3483-Spigot-42b6152-9cc7d76]
at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:31) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3483-Spigot-42b6152-9cc7d76]
at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3483-Spigot-42b6152-9cc7d76]
at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:157) ~[spigot-1.18.2-R0.1-SNAPSHOT.jar:3483-Spigot-42b6152-9cc7d76]
You can use getOfflinePlayer and then check if the player is online so the user can have more clarity
because if the user just doesn't exist at all a "player offline" message is a bit misleading
it isn't too big of a deal though
That's why I use "Can't find that player" haha
Then again, the inverse is also true
yes because #forEach loops through the ItemStacks which can be null
you want to use InventoryClickEvent#getView#getTopInventory
Oh
Well, the player is just not there (on the server)
but I know what you mean
can someone help me with dependancy injection im punching my fucking head right now
why should he use getOfflinePlayer with a name?
getPlayer and checking for null is the best solution here
no need for getOfflinePlayer
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
yes ive read that
so whats the question
is this what im supposed to do?
yes
?main
if(!e.getView().getTopInventory().equals(inv)) return;
is same as well
and how would i get the plugin?
what do you mean?
like im trying to run runTaskLater(plugin, runnable, delay)
what would i put in plugin
then the inventories aren't equal
your plugin instance
I mean the contents are tho
its just basic code
not sure for what the equals method is checking
like main?
Uhm I got some clue
nvm thats not what i thought it is
public PluginMain pl;
this.pl = pl;
}```
well, its in NMS
since the equals method of CraftInventory refers to the one of the IInventory impl
yeah i did that
and then i use pl?
in your PluginMain
do
MyClass something;
something = new MyClass(this);
}```
Yep I know
it compares the NMS IInventory
has anyone else been having issues with Windows 11 freezing
been happening quite a lot recently
import?
what is "something"?
is it imported
you don't need to store it
only if you want to use it in the future
the instance
like
CountdownInt countdownInt;
maven?
maybe he is new to java
shouldn't be doing spigot realistically
but how can they create a whole command executor class while being new
well if you dont know whats to do, you start with minecraft
but minecraft need an good java basic
its pretty simple
if you know whats an if is
So is importing something
in your Main class
do that
val CountdownInit = myInstance
ig
i dunno sorry, i really hate kotlin
lol
myInstance being..?
since the equals method of CraftInventory refers to the one of the IInventory impl
oh aha, didnt see
lemme do it in java
public Main plugin;
public CountdownInit(Main plugin) {
this.plugin = plugin:
}
}```
```public class Main extends JavaPlugin {
public CountdownInit countdownInit;
public Main() {
countdownInit = new CountdownInit(this);
}
}```
translate it in kotlin
bad syntax but its work
yeah i know basic java syntax ill convert it
alright
anyone know how to get the nms Level object
i converted what u sent to kotlin, now how would i do to get the plugin instance from the countdownInit class?
nvm
which method?
example
spigotMethod(plugin, param, param);
will be like
spigotMethod(this.plugin, "im cool", "idk");
in the class CountdownInit
it seems to not shoot any errors, thanks a lot
coming from functional programming and being an amateur to oop, this hurt my brain so much lol
np
lolll
wow never seen that
ah
guess im having to deal with some kotlin stuff now
oh fuck
dont use lateinit
i hate kotlin
should i set it to null instead?
Hi, I'm trying to figure out why my entity randomly stops ticking. In the net.minecraft.world.entity.ai.control.MoveControl class public void tick() stops being called and my entity freezes. I've profiled and found nothing that is freezing the server. Everything continues as normal but my entity freezes for a few seconds.
same things
o
i have a love hate relationship with it
it helped me a lot with copying directories
instead of having to write an entire output stream or however yall java people call it
alright
how nice
omg kotlin is so bad
where its say null
looks a lot like js to me
or from java to kotlin
havent seen much kotlin tho
Would say dart looks more like javascript + java
its like java code represented through javascript syntax
Anyone know if theres a website for nms mappings?
this obfuscated shit is killing me
i dont think so
Mojang mappings
And yes there are some websites
But they mostly just show the change throughout different versions, I’d recommend using some sort of remapper when you develop your project, much more convenient (gradle with paperweight or maven with specialsource)
I wish this plugin was using paperweight but it seems their using spigotmc:minecraft-server
can i hide team prefix with team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);?
This is a life saver https://nms.screamingsandals.org/
End your pain friend...
is that a compile error?
Please paste some more code
Maybe your code is outside the scope or something or maybe you have return on the above.
I actually meant the code above if (args.length....
You wrote your if under return true; which makes it unreachable.
The code ends at Return
Also... Your Permission Check does basically nothing 😅
Scoreboard scoreboard = getServer().getScoreboardManager().getMainScoreboard();
Objective objective = scoreboard.registerNewObjective("test", "dummy", ChatColor.YELLOW + "Dev server");
objective.setDisplaySlot(DisplaySlot.PLAYER_LIST);
Score score = objective.getScore(ChatColor.GOLD + "A" + ChatColor.GREEN + 1);
score.setScore(1000);
for (Player player : getServer().getOnlinePlayers()) {
player.setScoreboard(scoreboard);
}
For some reason my score is still 0 when i log on the server?
try not setting it to 1000
maybe like 10
do you actually know what setting the score does.?
That looks better
no i'm still new to plugin development
it basically sets its position on the scoreboard
you use score as a value if you're using vanilla scoreboards
0 = top of the scoreboard
anything above 0 is presented chronologically downwards on the scoreboard
hmm
when both my account join they still get '0' as their score
because im like 90% sure you cant have a score as 1000
nevermind
its the opposite
0 is at the bottom
and all scores above 0 go upwards
see the red numbers on the right
that is what setScore does
so if you want to show a line at the bottom of a scoreboard set it's score to 0
or 1
I actually once saw scoreboard with all 0 scores and it has 10+ lines.
and displaying an objective
he probably wants to set the number to something bigger which is done by packets iirc
can't send files here?
not if you are not verified
?paste
"tk/sourcenetwork/ProvaPlugin has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0"
How to install?
I use java18
me?
1.12.2
lastest
1.12 doesnt have java 18
yes
Ok, thanks
so i can't display a score next to a player name in tablist?
or is it
like very hard
main scoreboard
i doubt it
just teams or not
i think it does
you cant add dummy scores to tablist i dont think
i mean like
ones that have text
oh
those are for sidebar
a server i play on does it
show a screenshot of it?
you can sort the teams by a "score"
can't send files :/
JDK intelij: java18,17,16,15,13,11,1,8
Your have a code under a return statement, so it's unreachable, because the code stop at the return.
Which one should I download for spigot 1.12.2?
yea so i have 0 score
as the yellow number
and i need to set it to a number but don't know how
Place the return in the correct location
probably packets aswell
enlighten me on how to do dis
pls
?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.
It is a simple java syntax
ty
It doesn't seem like getConfig().getString("music.2volt.desc"); will find this string. Am I missing something?
- isn't required there
Is that breaking it?
It should look like this
music:
2volt:
desc: "Test"
Maybe
Alright I'll try
It still doesn't seem to find the desc
can anybody suggest a inventory gui plugin
as in api?
?stash
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
you probably return anywhere before
so its not reachable
show us your code
?paste
- magic 8-ball says* before the code you just showed

line 53
} else {
player.sendMessage(ChatColor.DARK_GRAY + " " + ChatColor.BOLD + "⬛ " + ChatColor.GREEN + "Player's Authority Status: " + ChatColor.GOLD + "Not Operator");
}
}
return true; // <--- anything past here isnt reachable
if (args.length == 1) {
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
player.sendMessage("Incorrect syntax! /command <player>");
} else {
target.sendMessage(ChatColor.AQUA + getName());
}
}
hey guys, I made the following class to gradually increase a player's knockback, the problem with that code is that it knocks the player to the direction they are looking at, not like natural knockback where it knocks based on the direction of the hitter when he hit, the second problem is that it stops knocking back more once it reaches 9 blocks of knockback, how can I fix these problems? ```cpp
public class Knockback implements Listener {
byte heatValue = 0;
@EventHandler
public void onPlayerHitPlayer(EntityDamageByEntityEvent event){
if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
heatValue++;
event.getEntity().setVelocity(event.getEntity().getLocation().getDirection().multiply(heatValue));
}
}
you need to get teh Vector from the attacker to the defender, not getDirection()
do you have any idea what that method is called?
- use the damagers direction
- you probably want to normalize it
- why are you increasing heatValue everytime there is a hit?
- what about the +9 blocks knockback issue
sample code for you to pull apart and use```java
public void setTarget(final Projectile projectile, final Location targetLoc) {
final Vector velocityVector = targetLoc.toVector().subtract(projectile.getLocation().toVector());
velocityVector.normalize().multiply(projectile.getVelocity().length());
projectile.setVelocity(velocityVector);
}```
what's the purpose of normalizing it?
ensures the vector has a length of 1
1 = 1 block, so multiply for whatever knockbak you want
- cuz I want the player to get knocked back more each time they are hit
but you do know that will apply for any player to be hit
like all players?
yes
yeah I understand that
if you hit me 10 times, the next hit on any player will throw him 11 blocks
I might narrow it down later to a certain tool, maybe like wooden shovel
and make it reset each time a player dies
the latter is still to be researched
so its player based and not global for everyone?
smash
then I can narrow it down
alright
yeah something close to that
.
?paste
Can someone help me adding a new sound to minecraft? I have everything i need but it doesn't show up in minecraft
May have to use packets
declaration: package: org.bukkit, interface: World
Ohh
I'm not sure then
Add it to sounds.json
look at this
Did you add it to sounds.json?
How set color leather armor?
Get the meta
any ideas how to add a simple delay for placing blocks
declaration: package: org.bukkit.inventory.meta, interface: LeatherArmorMeta
That players place?
Yes
yes
So a player can place a block every () seconds/ms
Ohh you mean a cooldown
Yea
Can't help you past that sry
When they place a block and u allow it, add them to a map<uuid, long> with currentimeinmillis
now it shows up, but it doesn't play any sound
Then when they try to place again check if they're in the map
And check if the time in millis - map.get(player) > your cooldown in ms
If it is, allow to place and update the map
Else just cancel
Alternatively, you can add them to a set and schedule a runnable to remove themnafter x ticks
if i were to make custom mobs and want to keep em within a certain radius, what would be my approach?
I got the knockback how I wanted, but it knocks the player back to the opposite natural knockback direction, how do I reverse this movement / snippet: event.getEntity().setVelocity(event.getDamager().getLocation().toVector().normalize().subtract(event.getEntity().getLocation().toVector()).normalize().multiply(heatValue)); is there a method to reverse it? and if so where should I place it?
should i check if they are within a radius everytime they move?
Well u control where they walk right?
you want them to keep inside a bounding box?
reverse the direction subtract one from the other
so change getEntity to getDamager and vice versa?
yep
any thoughts or should i just do the ladder?
hold on
this may help
Oh alright
possibly set the target semi randomly near the center and set the navigation to that target whever they get close to or over the line you dont want them to cross
That looks fun, should I just use a radius to check if they've crossed over their line?
you could stop their movement when they get close, then reverse it a bit and possibly let them walk back a bit in order to make it look more natural
as if they themselves decided to walk back
move event
np 😄
maybe make your own event which you fire whenever the entity, which you want to restrict, moves. thats probably the best way to keep the code clean in that
perhaps, I'm a messy code enjoyer 😛
its nice having events which you can convey extra information with. possibly give the custom event the bounding box the entity is not supposed to leave
Oh yeah totally, I was just making some humor 😛
😄
can I store hashmap into an FileConfiguration
and if I can how can I get it from config
yes
getConfigurationSection(path).getValues(true)
Unless you just added it, then its still in a Map form
a Map added to the Config is not converted to a MemorySection until you save/reload
a bug
I just throw it through this method to ensure I get a Map ```java
/**
* If loading from file the Maps in the data
* will be stored as a MemorySection not Maps.
*
* @param entry MemorySection or Map to check.
* @return Map containing the serialised data.
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> castToMap(Object entry) {
if (entry instanceof MemorySection) {
return ((MemorySection) entry).getValues(true);
} else {
return (Map<String, Object>) entry;
}
}```
I tried that and it didn't work, it now knocks back the entity to a fixed direction event.getEntity().setVelocity(event.getEntity().getLocation().toVector().normalize().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue));
it should reverse the direction. This code calculates the vector between two Entities
else just multiply by a negative value
-heatValue
I will try that
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
Anyways did you register the listener
Is* 
They probably didn't
As is tradition
hey mike
Sup
I know it isn't related to spigot but can anyone help me with js?
?eventapi
Sure
I'll send the problem in dm if that's ok?
Never heard of it. I've been tempted to use some of those APIs eventually. Haven't gotten around to it yet tho
Alright
dw
olivo? and you?
did you ever used that api?
nope did not work either, pretty sure there is something we are missing, cuz the entity is always knocked back to the direction of my initial hit
it will be knocked back away from the hitter
Nothing wrong with the code. It has to be however you are implementing it
but why is the direction fixed
it worked fine with that snippet, just in the reverse direction, so I just did -heatValue
but it always knocks the player in a fixed direction, which happens to be the direction of the first hit
you get teh correct direction by either subtracting the damager from entity or vice versa
each will give opposite directions
if you always go one direction you are not doing it correctly
you are not recalculating the vector
is there any way to add input barter for the piglin
when I changed them in places of each other it broke it and knocked in a fixed direction
what I sent is the only method in code
Your implementation of that snippet is wrong. show how you are using it
public class Knockback implements Listener {
int heatValue = 0;
@EventHandler
public void onPlayerHitPlayer(EntityDamageByEntityEvent event){
if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
heatValue++;
event.getEntity().setVelocity(event.getEntity().getLocation().toVector().normalize().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue));
um
this is the snippet that "should" work but doesn't
no ; after heatValue++
I must be blind
I meant in the code
not what I pasted
Hi i create a plugin with custom block for my server but i want to my block can't place can you help me plz?
Here is my code : https://paste.md-5.net/riwiyogoca.java
The knockbqck direction is gonna be away from the origin of the world
yeah thats not going to work
GetLocation.getDirection.normalise
you normalized the event.getEntity().getLocation().toVector().normalize()
so like that event.getEntity().setVelocity(event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue));
yes
lemme try that
so the normalize method made it that it knocks back in a fixed direction?
yes, it was calculating the Vector from near 0,0,0 to your other full location
Extend javaplugin
also
registerEvents(Join, this);
wtf is that supposed to be
and put the event registration into your main class into your onEnable
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new YourEventClass(), this);```
Hi i create a plugin with custom block for my server but i want to my block can't place can you help me plz?
Here is my code : https://paste.md-5.net/riwiyogoca.java
What do you exoect to happen with this code
This code doesn't make much sense
I want the custom block can't place
Did you give it to yourself?
Yes
Also listen to the blockplaceevent
Check if the item in hand is similar to your item
If it is
Cancel event
Okay thx ^^
Note: they will be able to place it using a dropper
I can disable that?
yes with blockdispenseevent
check if the block is a dropper
check if the item is your item
then cancel
it works great, thank you very much, but after it reaches 18 blocks of knockback it stops there and doesn't get any higher, is it possible to take it beyond that or is that some final variable I can't change?
Maybe there is a max velocity
is velocity the only thing that alters kb?
Well kb is just modifying the players velocity
How far back the player goes depends on their velocity
There is no set number of blocks
seeing that it stops at 18 blocks, it must be the maximum velocity right?
18 blocks is the result of the max velocity I understand that
I will also check if a kb enchantment on a sword alters that too
Wait.. I used high kb enchants and players moved more than 18 blocks
because I know for a fact kb 1000 sends the entity so far
Yeah
Well print the velocity you're setting
And see if it stoos going up at some point
Or maybe you need to add a bit more to the y value
if that's the case, I will have to rely on gradually higher kb enchantments
Try adding some more to the y value
how tho? my code doesn't have an x or y value
So they take longer to hit the ground, thus more time to fly back
it takes a vector
have I been using only the x parameter
I already have .subtract
I can't add it
I get an error
or do I do new Vector(0,1,0)
yeah that worked
yeah just so we see if it goes beyond 18
oh it sent them like 7 blocks high
maybe 1 is too big of a value
Yeah ik but did they go more than 18?
wait now it's back to normal
weird
lemme see the max and get back to ya
oooh I know why it sent them so high up at first
the /tp anti-vulnerability misses with the code for some reason, so I always have to wait before I hit an entity
try Integer.MAX_VALUE 
:)
Lmfao imagine just constantly going up
nope still 18
You still fly up a few blocks?
nope, only if I hit shortly after /tp
Can i see where u set the velocity?
the code you mean?
Yes
event.getEntity().setVelocity(event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).add(new Vector(0,1,0)));
should I pump the number to 2 and see what happens?
aight
Is there a lib for making custom crafting recipes?
Spigot api😂😂
yup still 18 blocks and no change in the vertical velocity at all
or down
Then something is wrong
Not sure what
Print the velocity before you set it
yeah maybe the .add is not in the right place
It is
set the Y of the applied vector
Yeah u can alsl do this
Maybe the y is negative
so .setY(?)
Set the y to 1 or 2

oh to the vector
.
event.getEntity().setVelocity(event.getEntity().getLocation().toVector().setY(2).subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue));
event.getEntity().setVelocity(event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector().setY(2)).normalize().multiply(heatValue));
?
oh after multiply?
Ye
because you still have the file open somewhere
or the directory
nothing that I can see
hm. anyway, it simply means that maven couldnt delete that file because windows is weird again. it can however overwrite existing files so shouldnt be any problem
so the build is done?
depends, did it say BUILD SUCCESS at the end?
Is updating a player's compass pointing location known to be buggy when you do it on player join? The compass location coords seem to be set correctly but it doesn't point in the right direction until I right click on the compass.
I think I probably need to trigger an inventory update of some sort so it updates on the client side, but not sure how (I tried Player#updateInventory, no luck). Any advice would be appreciated 🙂
[Spectaculation] Task #206 for Spectaculation v0.0.1-HEALTH generated an exception
java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source) ~[?:1.8.0_333]
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source) ~[?:1.8.0_333]
at java.util.Formatter$FormatSpecifier.print(Unknown Source) ~[?:1.8.0_333]
at java.util.Formatter.format(Unknown Source) ~[?:1.8.0_333]
at java.util.Formatter.format(Unknown Source) ~[?:1.8.0_333]
at java.lang.String.format(Unknown Source) ~[?:1.8.0_333]
at me.superischroma.spectaculation.util.SUtil.formatNumber(SUtil.java:152) ~[?:?]
at me.superischroma.spectaculation.entity.SEntity$3.run(SEntity.java:125) ~[?:?]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot.jar:git-Spigot-21fe707-741a1bd]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot.jar:git-Spigot-21fe707-741a1bd]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot.jar:git-Spigot-21fe707-741a1bd]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-21fe707-741a1bd]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-21fe707-741a1bd]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-21fe707-741a1bd]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_333]
wat does dis mean?
yes
what's SUtil line 152
I did not arrive, can you help me to write thith plz
My custom item code: https://www.toptal.com/developers/hastebin/orulivonuv.swift
I'm sorry to disturb you
I didn't write a listener, i think
Ps: I don't know java I'm trying to learn
what are you trying to do, and what of that isn't working?
still 18 :///
Print the vector
can you please define some variables so that this code doesn't look like a bunch of circles
I'm trying to create a custom block, but I'd like it not to be posable. Searching I managed to create the customization block but not making sure it doesn't arise
I don't know if what I'm saying means anything. Sorry I don't speak English at the base but French XD
you should listen to BlockPlaceEvent. Then check if the placed item is your custom block. If yes, cancel the event
How :/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
you should probably start with something a bit easier than custom items though if you never used the event api
I'll try to get there x)
Example
Entity source = event.getDamager();
Entity target = event.getEntity();
Vector sourceVector = source.getLocation().toVector();
Vector targetVector = target.getLocation().toVector();
Vector difference = sourceVector.subtract(targetVector).normalize().multiply(2).setY(2);
source.setVelocity(difference);
make code that doesn't look like a rap battle pls :)
do a sout(event.getEntity().getLocation().toVector()) ?
Save whatever your setting the velocity to in a vector variable
And print it
Then set the velocity
Hello, I'm trying to loop all entries of a SQL table but I have a problem : When I do a while(result.next), the algorithm goes to the second entry and forgets the first. Has someone an idea. Sorry for my bad English.
rap battle lmao
man's packing
Vector v = event.getEntity().getLocation().toVector()); sout(v) event.getEntity().setVelocity(event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector().setY(2)).normalize().multiply(heatValue));
like that?
wait 1m lemme get it
public static Map<Integer, String> prefixes = ImmutableMap.of(
7, "k",
10, "M",
13, "B");
public static String formatNumber(double num){
int length = Double.toString(num).length();
String numAfter = String.format("%,d", num);
for (int i : prefixes.keySet()){
if (length > i) continue;
if (length < i && length > 3){
String prefix = numAfter.split(",")[0];
if (prefix.length() == 1){
prefix += "."+numAfter.split(",")[1].charAt(0);
}
numAfter = prefix + prefixes.get(i);
break;
}
}
return numAfter;
}
this @tender shard
and which of those is line 152?
Vector v = event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2);
sout(v);
event.getEntity().setVelocity(v);
@carmine valley
String numAfter = String.format("%,d", num);
%d is for integers
you have a double
use %f instead of %d
thats it?
but i wanted the health to be in 2m format
2m format?
use NumberFormat then
no, it would then show 2,000,000.000000
then what do I do?
wait which method shows that?
this.entity.setCustomNameVisible(true);
this.task = new BukkitRunnable()
{
public void run()
{
entity.setCustomName(ChatColor.RED + statistics.getEntityName() + " " + ChatColor.GREEN + SUtil.formatNumber(entity.getHealth()) +
ChatColor.WHITE + "/" + ChatColor.GREEN + SUtil.formatNumber(entity.getMaxHealth()) + ChatColor.RED + "❤");
}
}.runTaskTimer(Spectaculation.getPlugin(), 0, 10);
}
}``` this one shows the health of a mob like the display
and this once shows the format
I find that:
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
NBTItem nbtItem = new NBTItem(event.getItemInHand());
if (nbtItem.getBoolean("IsCustomItem")) {
event.setCancelled(true);
}
}
but when i put that on my listener he doesn't work
Its for @tender shard o @humble tulip or another guy we can help me
I also hit the player with a knock 2 sword and still 18 blocks
https://www.spigotmc.org/wiki/config-files/ Okay so I'm looking into making a config file for my plugin but I need a little bit of guidance on this because I'm not sure I'm making sense of the article. Down below where I'm doing the "custom configurations" it implies I should put all of my own config stuff in Main.java because that's the class that extends JavaPlugin... But my issue with that is that in order to write to-and-from the config I would have to somehow get data from other classes passed back up TO the Main.java since I can't access these methods outside of Main.java.. Would it not make more sense to make my own Config.java or something in that area?
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
RIP no
don't use NBT
Bruhhh...
?pdc
PDC > NBT
pong
I replace NBT by PDC its that?
no of course that's not it
you should really learn basic java, then learn the basics of spigot, and THEN you should do your custom item plugin
and then you can eat pizza
I know it's just that I'm stuck on this only this
hey guys, any idea why it only knocks the player back up to 18 blocks and then stops increasing the knockback after that? here is the code and the console output```cpp
public class Knockback implements Listener {
int heatValue = 0;
@EventHandler
public void onPlayerHitPlayer(EntityDamageByEntityEvent event){
if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
heatValue++;
Vector v = event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2);
System.out.println(v);
event.getEntity().setVelocity(v);
// event.getEntity().setVelocity(event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2));
}
}
}
console output: https://prnt.sc/x-kAXp-0ViJd
tf