#help-development
1 messages · Page 1379 of 1
put it in a method
oh
you have to do it in a scope (method, init block, constructor, static init block)
.. yes
23490 iq problem solved by Rack
dont bully its 3am
then go to sleep
Bullies
xD
lmfao
wyhat
Which event is fired when the player right clicks a respawn anchor? (except playerinteract)
I would imagine only that
package standard.plugin.skills;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@SuppressWarnings("ALL")
public class ValorSkill implements Listener {
public void onHit(EntityDamageByEntityEvent e){
if (e.getDamager() instanceof Player) {
if (!(e.getEntity() instanceof LivingEntity)) return;
Player player = (Player) e.getDamager();
if (player.hasPermission("bskills.valor")) {
player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 60, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 60, 2));
player.sendMessage("Il tuo valore ti conferisce potenza!");
}
}
}
}
``` Why doesn't it give the effect to the player?
I don't see anything wrong
I use IntelliJ
so you added that yourself
I did
yeah thats very true
Well we will find that out
but one problem at a time
Remove the supress warnings
and what warnings is it giving you
oh I figured out the problem alone
pro coder
How do you get warnings for writing a string in another language
I don't know
its probably unknown vocab word
Does IJ give warnings for spelling?
Is there a quick way to get the spectators of a certain entity? (Spectator mode -> left click kinda spectate)
(to Coll1234567 because automoderator): yes
and also I don't think so, other than if you track it yourself or iterate through everybody and get their spectator target
which i was trying to avoid 🤔 i guess its the only way then
Any easy way to delete the tree trunks of a tree? I'm not too worried about the leaves considering they'll just decay.
Set them to air?
I personally use the BFS algorithm for that, though any flood filling algo will work (provided it is applicable in 3D space)
Gotchu, thanks
But you def need some limitation for that or else you will decay whole forests.
Of course, but you'll realise that as soon as the server OOMs
I mean if you step the algorithm each tick you wont have that problem. You will just discover a slow crawling virus that slowly eats through all connected forests ^^
even then, you have to be aware of large oak trees
Btw i used A* for that which worked quite well
As they have disconnected logs as far as I know
I think they are always touching at least diagonally
And you probably won't destroy whole forests as trees rarely have logs touching
I'm just wondering, is there a way run spigot plugins on a 1.17 snapshot? I've had a look but this is literally the only information I have found, which is very vague.
https://www.spigotmc.org/threads/snapshot-1-17.489818/
How could/would you go about building it for a custom version? Do you need to somehow build spigot using the 1.17 snapshot jar?
You would need to build it against the 1.17 jar and make all the changes needed for it to work
Which is likely a lot
Yeah, especially after the last few snapshots that basically changed the entire game
yeah
They did not change anything within the code structure back
Correct
I think your biggest bet are the bukkit reimplementations for fabric
Just be aware that they are going to run ... not well
I don't think they would even support 1.17
kinda sad the caves and cliffs update was delayed
package standard.plugin.skills;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.List;
public class AuralSkill implements Listener {
@EventHandler
public void rightClick(PlayerInteractEvent e) {
if (!e.getPlayer().hasPermission("bskills.aural")) return;
if (!(e.getPlayer().getHealth() <= 4)) return;
/*21 line*/ if (e.getClickedBlock().getType().equals(Material.AIR)) {
List<Entity> entities = e.getPlayer().getNearbyEntities(10, 10, 10);
if (!(entities instanceof Player)) return;
((Player) entities).addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 70, 2));
((Player) entities).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 50, 10));
}
}
}
``` Why does line 21 give NullPointerException in console?
is it to me?
Yes, Java 15+ has helpfull NPEs per default, really nice for debugging
I would bet absolutely nothing that e.getClickedBlock() is null though
Yes
You should null check it and/or check the click action
Also I recommend isAir to account for cave air
Like they're all saying, check for nulls but also compare enums with == and not .equals
and would this even work correctly?
List<Entity> entities = e.getPlayer().getNearbyEntities(10, 10, 10);
if (!(entities instanceof Player)) return;```
entities is a list of Entity

I didn't even notice wth
also, type signatures are erased at runtime
You're also giving a list of entities potion effects
don't know if that would work either
It won't
yeah i figured
The cast will throw a CCE
might wanna loop through entities and check if they're a player and give them the effect
exactly
though entities can be given those effects but I doubt that's what you want to do
Only LivingEntities
right
I probably won't get it to work, but still I'm interested and it's worth a try, do you know where withing the source is minecraft's source located? Here's a tree of the BuildTools folder: https://paste.md-5.net/viqunowago.sql
/how it works
i have no idea
you probably need the switch --generate-source
is that a buildtools option?
yes
yeah it did
i guess it cached stuff
Is that the source on line 790? https://paste.md-5.net/cugahivuwa.sql#L790
in that dir
yes
Hey, there is a way to create custom advancement with a plugin ?
Because datapack is horrible
Yes, but i want to create "unique" advancement with a different name everytime
You basically just have to write the Json via code
Earlier in the day i saw this https://github.com/Roxeez/AdvancementAPI
But i don't know how to use it lmao
thanks you I'm going to see this
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply.
thx
so Im making a life steal sword which should transfer hp from the entity being damaged the the player doing the damage but it wont work, here is my code ```public static void onAttack(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player) {
Player attacker = (Player) event.getDamager();
if (attacker.getInventory().getItemInMainHand().getItemMeta().equals(ItemManager.lifesteal_sword.getItemMeta())) {
attacker.setHealth(attacker.getHealth() + event.getDamage());
}
}
}
I have no idea whats wrong
is it annotated?
?
@eventhandler
yes its annotated
Is it registered
heres the full code ```public class MoreSwordsEvents implements Listener {
@EventHandler
public static void onAttack(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player) {
Player attacker = (Player) event.getDamager();
if (attacker.getInventory().getItemInMainHand().getItemMeta().equals(ItemManager.wither_sword.getItemMeta())) {
LivingEntity victim = (LivingEntity) event.getEntity();
//Do something
victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER,100, 3));
}
if (attacker.getInventory().getItemInMainHand().getItemMeta().equals(ItemManager.ice_sword.getItemMeta())) {
LivingEntity victim = (LivingEntity) event.getEntity();
//Do something
victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,50, 2));
}
if (attacker.getInventory().getItemInMainHand().getItemMeta().equals(ItemManager.lifesteal_sword.getItemMeta())) {
attacker.setHealth(attacker.getHealth() + event.getDamage());
}```
have you tested to see if the event is being called?
Also, comparing meta requires the durability to match
Try a few debug Sysouts I guess
how do I do that, total noob here?
Which probably isn't the case
does the wither effect get applied?
yes, for the wither sword the wither effect is applied, and for the ice sword, slowness is applied
k
how do I check if the event is being called?
so its literally just the setHealth thats not working?
I think so
add a sysout just before the setHealth
k
@young knoll, this is a great API, but there is a another, because i need to put NBT tags to the "Material", and i see nothing on the web.
Wow, never mind, i click on the documentation button and i saw this so my problem is fixed thanks you
I figured it out, It was the item meta after all
anyone know the method to get a list of entity namespaces?
so a list that contains minecraft:arrow down to minecraft:zombie
actually wait ill just see how it done in vanilla
EntityType.values() i think
yup thats it thanks
anyone know how to check if a player is holding a specific custom item? I need an effect to be applied when the entity damaged by entity event is triggered and the player is holding the item
Use the PersistentDataContainer of an ItemStack ItemMeta to tag and identify custom items.
how do I do that? kinda a noob here srry
I will see if I can figure out what in the world the post is talking about, thx
Does anyone know what the Vec3D field represents in PacketPlayInUseEntity?
The exact position the entity was clicked at iirc
{
Bukkit.getScheduler().runTaskAsynchronously(Main.instance, () ->
{
final String url = "jdbc:mysql://"+database_entity.server+"/"+database_entity.database+"?autoReconnect=true&useSSL=false" +
"&autoReconnect=true&useUnicode=true&characterEncoding=utf-8"; //Enter URL w/db name
try
{
Class.forName("com.mysql.jdbc.Driver"); //this accesses Driver in jdbc.
}
catch (ClassNotFoundException e)
{
System.err.println(ChatColor.RED+" jdbc driver unavailable!");
result.accept(null);
return;
}
try
{
Connection connection = DriverManager.getConnection(url,database_entity.user,database_entity.password);
if (connection!=null && !connection.isClosed())
{
result.accept(connection);
return;
}
result.accept(null);
} catch (SQLException e)
{
result.accept(null);
}
});
try this
and swap "database_entity" varables with your sql data
Oh no
Still don't understand it. Could you please tell me what is going on here so I have a basic understanding.
https://paste.md-5.net/sitodilita.java Is what I use
should this work: utils.createItemByte(inv, "terracotta", 14, 1, 45, "Confirm", "Click here", "to create", "your recipe!");
(14 is the byte id (color), 1 is the amount of the blocks and 45 is the slot of the inv its in)
I mean we don't know what your utils method is
Why do you pass a string rather than a Material
Also you can do meta.setLore(Arrays.asList(loreString));
Also you can do meta.setLore(Arrays.asList(loreString));
@young knoll where
Where what
where should i put this line of code
In place of the loop you currently use
thx
Alright so basically, I need to get the first ChatColor from a string, this would usually be easy with regex but i would also like to support hex colors
so its a bit difficult
what naming convention is that
looks c#-rpy
@outer crane yes i've started my programing adventure with C# so now i'm struggle with switch to Java naming
to me the most weird thing with java naming is start method name with small letter
but this chunk of code i've send is pretty old, so my varables are not longer eyebleeding
you can also start with capital letter if you want to
as long as its consistent in your project
lowerPascalCase is the most common one, yeah
well there is a reason for is
if you see PascalCase.camelCase() then you know it’s invoking a method
if you see someVariable.field then you know it’s a property of that object
UserType.I.like(this);
Whats the default reach distance on multiplayer?
are those estimates?
yes, because the scenario changes those numbers as they are not exactly constant
when in combat you can have a reach of 6 blocks sometimes
i don't think it's an estimates.
this is what the wiki says
It negotiates with the server
server, movement, hackclient...
why do most (hacked) clients care so much if it's 3.05 or 3.06 then?
it doesn't negotiate, just it depends on the scenario you are in. Building wise, yes it is 3-4 blocks, combat it is a bit different, and this is just assuming we are not including equipment being in the players hands
that is for blocks
the wiki says 4.5 blocks?
for breaking blocks
oh sorry I should've been clearer, I meant combat reach
within my 7 seconds of googling I was unable to find a reach distance for players, although I recall hypixel making a thread about it
maybe find that and take a look
combat reach can be as far as 6 blocks in some situations
hight ground, low ground etc
but normal, without any movement on an equal y etc. its 3
3.4 was the highest i could reach without any ado
So I have a few custom config, Is it better to handle them in different class, so each custom config has different class or on the same class? Using enums like this https://paste.md-5.net/dasiruzono.java.
if you're gonna use that approach then you may want to consider storing by <ConfigType, File> instead rather than writing giant switch statements and adding more fields the more configs you write
not to mention you're also missing breaks in your switches
I made a wrapper class for the configs that uses direct map access
Not really sure if a second copy of the data is worth the slight speed increse
is there a way I can create a custom creature spawner than spawns a mob with certain keys in it's PersistentDataContainer?
i've tried adding the keys to the PDC on the spawner and the spawn egg but any spawned mobs don't have the keys
or any kind of tag I can use on the spawner that is carried over to the mobs spawned from it
is there a way to know from that event that the mob came from a particular spawner?
yes
other than SpawnReason.Spawner?
I can determine if it came from any spawner from the event, but is there a way to see which spawner it came from if there are multiples? I basically want to store custom data in the spawner that will effect the mob that is spawned
ah sorry I see it now. Perfect event
What do you mean by that, can you explain it further?
item = new ItemStack(Material.GOLD_SWORD, 1);
List<String> lore = item.getItemMeta().getLore();
lore.add(CustomItemId);
item.getItemMeta().setLore(lore);
why
is thiis broken
am i stupid
CustomItemId is a string
how would i sort a hashmap<OfflinePlayer, Double> in descending order
im trying to make a /bounty top command
show it
The hashmap in itself can not be sorted. You need to iterate over each element and sort the keys relative to their values using the Entry<Key, Value>
how do i do that
use a TreeMap
what do i do with a treemap
You can specify a comparator
This would only work if the keys would be compared if im not mistaken.
Oh nvm. Its a comparator that accesses the map and links the key to its value. Looks expensive.
Not really as you only call teh comparator when you want to sort. Not much different to teh Collections.sort
Still add and remove is O(log(n)) . Not terrible but not great either. And each time a value us changed it has to be resorted.
But its probably the simplest solution.
?paste
i get this error
this is the line 60
bounties.put(to, bounties.getOrDefault(to, 0.0) + amount);
Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer cannot be cast to java.lang.Comparable
your treemap is defined incorrectly it seems
public static TreeMap<OfflinePlayer, Double> bounties = new TreeMap<>();
probably so bad
huh
yea
You don;t also have one in the local scope?
nope
will need to see code
not related but line 62 should be Player top = to.getPlayer();
oh ok
lastly to fix your error stop storing the whole OfflinePlayer object and only store their UUID
how would i get the name of an uuid
you would get teh offline player object when you need it
Can someone help me in #help-server
public void joinMessage(Player player) {
Events.subscribe(PlayerJoinEvent.class)
.handler(e -> {
CompletableFuture<Integer> globalPlayers = bc.getPlayerCount(server1() + server2() + server3());
player.sendMessage(ambientColour() + CC.STRIKETHROUGH + "-----------------------------------");
player.sendMessage(mainColour() + "Welcome to " + serverName() + "there are currently" + globalPlayers);
player.sendMessage(mainColour() + "Discord" + secondColour() + discordLink());
player.sendMessage(mainColour() + "Teamspeak" + secondColour() + teamspeakLink());
player.sendMessage(mainColour() + "Twitter" + secondColour() + twitterLink());
player.sendMessage(mainColour() + "Store" + secondColour() + storeLink());
player.sendMessage(CC.GRAY + CC.STRIKETHROUGH + "-----------------------------------");
});
}
this is all im trying to do using helper but for NO reason its not working
That supports lilypad?? 👀 that's a fuckin surprise
yeah
its really good I use it in all my projects, makes stuff alot cleaner
*all my projects as of late
I think that you're not supposed to call it like that, I think you're supposed to call it like you register events
Alright idk if someone pointed this out but
like e.getPlayer()
Make the left type Map
I don’t remember what that law/rule is called but it’s a thing
that helper thing is neat though 
hmm its still not working :/
public void joinMessage() {
Events.subscribe(PlayerJoinEvent.class)
.handler(e -> {
CompletableFuture<Integer> globalPlayers = bc.getPlayerCount(server1() + server2() + server3());
Player player = e.getPlayer();
player.sendMessage(ambientColour() + CC.STRIKETHROUGH + "-----------------------------------");
player.sendMessage(mainColour() + "Welcome to " + serverName() + "there are currently" + globalPlayers);
player.sendMessage(mainColour() + "Discord" + secondColour() + discordLink());
player.sendMessage(mainColour() + "Teamspeak" + secondColour() + teamspeakLink());
player.sendMessage(mainColour() + "Twitter" + secondColour() + twitterLink());
player.sendMessage(mainColour() + "Store" + secondColour() + storeLink());
player.sendMessage(ambientColour() + CC.STRIKETHROUGH + "-----------------------------------");
});
}
this one isn't working either
public void onJoin() {
Events.subscribe(PlayerJoinEvent.class)
.handler(e -> {
Player player = e.getPlayer();
player.getInventory().clear();
player.getInventory().setItem(4, selectorItem());
});
}
You need to register?
no
Not law of Demeter
I don’t remember
Just learned about law of Demeter tho
Pretty cool
I mean it’s a pretty weird principle sometimes
Hmm I guess it’s a good way to protect you from yourself just like normal getters and setters
Arguably loosely couples your code but rly I just access fields sometimes tbf
can someone please help me
What would be the best way to restrict int? Using Math.min/max, break the loop on to high input ? String s = response.getInput(1); int in = Integer.parseInt(s); if (response.getDropdown(0) == 0) { for (int i = 0; i < in; i++) {
Do you call that method ZoiBox? Because the EventSubcriptipnBuilders aren’t something you wouldn’t just put in a method precisely
wdym, the method is called when an event happens
No shit, but not if you never introduce it in the first place
but I do
So you do call your method onJoin?
what I have here should work
but it doesent
Depends
it should
If you don’t call your method joinMessage() then there’s no way it would work
ok where do you want me to call it
It’s not like the spigot event handler methods where they automatically get called though even that requires registering. Try to call that method joinMessage() in onEnable or smtng
ok
After all you need to make sure the subscription is actually introduced not only declared in code
it works
WTF
why is that not in the docs
I worked with another event api and you dont do that
it's common sense though, code doesn't run if it isn't called
u do exactly what I have and it jus tworks
ik that
but another I worked with its legit the exact same
but it does it for you
so I assumed
Another one yeah, well maybe if Luckos helpers would visit all of your classes with some bytecode manipulation or reflection/smtng then maybe it could get itself aware of never called methods but unfortunately it doesn’t
ik I just thought better of it
No it’s common sense as jochyoua said
IK
Just saying you shouldn’t be expecting that in libs
Well unless it’s actually explicitly mentioned somewhere
how do i make another config file thats json for a plugin?
Could use gson
does scanner work in spigot console? or is it only used for java console
It works for any InputStream I think?
aight thanks
how do i get this depend https://www.codota.com/code/java/classes/com.mojang.authlib.GameProfile
use maven
i am
you could add spigot server jar as a dependency
but i need the depend for it
as opposed to the api only
i dont know where to find any of them
well actually authlib is a mvn dependency on its own
just google it and you'll find the details
ive tryed everything on google i cant find it could u send a link
you have to reload the maven project
same thing
i dont even see one
i click on it and it still dont see it
dude you add it to ur pom.xml
the link
?
whats this?
...
Well Idk but why not use the Base64 encoder provided by java itself
how to vanish players from non admins?
why is line 24 (getting an instance of bungeechannelapi) throwing a null pointer exception?
plugin is null
i'm aware of that but how can I fix it?
make it not null
ok
hey how do i check if player has written alias or command?
PlayerPreProcessCommandEvent I think or smtng
oh so no CommandExecutor class
The executor is the command processor but that event is fired before any executor has the chance to deal with the command input
oh ty @tribal sparrow
@ivory sleet
anyone about to help me out with armorstands and rotating blocks with cursor?
how would i get the blocks (armorstands) to move in a straight line and not just rotate
can you please help me with the api thing, the way you said, on enable, works fine but when its a different event then it doesent work because its not "on enabke"
@crude charm
change it to this
public SelectorManager(Hub plugin){
this.plugin = plugin;
bungeeChannelApi = new BungeeChannelApi(plugin);
}
I fixed it
its something else
but I debugged
and its my shit code
lmfao
@tribal sparrow
use the cos function with different radius
i don't know how to work with cos function, is there a good way to learn how the location xyz works?
question: if I do:
Bukkit.getServer().getScheduler().runTaskLater(plugin, code, 1)
Am I sure that the code will be executed AFTER the event finished triggering? (and applied all the changes on the environment; e.g: if it's an PlayerItemDropEvent, the dropped item will be on the floor, if it's a PlayerItemDamageEvent, the item will already been received the damage, etc)
And how about:
Bukkit.getServer().getScheduler().runTaskLater(plugin, code, 0)
Same question than above
I wanna do "after hooks" for events
you can't schedule a task 0 ticks after
soonest as possible tho
the scheduler just queues the task to run on the next tick
well, it could be scheduled at the end of the current tick no?
no, the tick has already been called
you can time it it should be the same
So Im trying to make is when an player kills a cow he gets poison and blindness for 1 mins i tried but coding is new for me and im learning
i dont completely understand the question
oh sorry i see now
yes it will execute after the event has been processed
okay cool, thanks!
what have you tried so far
ok just a sec
what if it is called from a thread? (not on main thread)
the schedular only works on the main thread
uhm no
unless you have your own implementation, then it's up to how you code it
show code
@EventHandler public void onEntityKill(EntityDamageByEntityEvent) { if (event.getEntityType() == EntityType.COW) {
you need to name your parameter
I have got this much so far
public void onEntityKill(EntityDamageByEntityEvent event)
so the EntityDamageByEntity is the type, you need to have a name for the actual instance of that
OH ok
Use EntityDeathEvent instead maybe?
Ok I will try both
public void onEntityKill(EntityDeathEvent event) {
if (event.getEntityType() == EntityType.COW);
event.getEntity().getKiller();```
so I have got the killer
Hello
That's an If statement, you need { } instead of ;.
how do I detect that it is a player or other entity
I'm checking the velocity on the 3 axis + the length of an arrow dispensed, it's always the same, however it never shoots to the same place, does anyone know which parameter affects the randomness of the arrow ?
event.getEntity().getKiller(); already return Player, and will return null If it's not Player I guess.
public void onEntityKill(EntityDeathEvent event) {
if (event.getEntityType() == EntityType.COW) {
event.getEntity().getKiller();
return Player```
Like this?
and type
send.message and all
No
You can't return something
learn java
Oh, I suggest you to learn java first.
Any youtube channel you can suggest?
yes, dont start with bukkit or mc tutorials
start with actual java programming basic tutorials
No sorry, I usually use website or something.
ok
whether its video format or interactive (i recommend), or text
Udemy has great courses on Java
i recommend interactive stuff because you can actual experiment and do stuff hands on
Yea I had a subscription but my father used that
Bruh Im Indian
LOL
The free Java class by Rob Percival is very good
hahaha
xD
here's the proof that you can use basic implementation of bukkit schedulers in threads: https://i.imgur.com/8jgc1bS.png
oh and if you wonder why some syntax ain't pure java, it's because it's beanshell, but it compiles to java with reflection and stuff, it worked in my java code as well (was lazy to restart whole server, recompile everything etc)
package standard.plugin.skills;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class AdrenalineSkill implements Listener {
@EventHandler
public void onProvoque(EntityDamageByEntityEvent e){
if (!(e.getEntity() instanceof Player)) return;
if (!(e.getEntity().hasPermission("bskills.adrenaline"))) return;
if (!(((Player) e.getEntity()).getHealth() <= 10)) return;
((Player) e.getDamager()).setNoDamageTicks(0);
}
}
``` Why does the damager don't get the "combo duel" thing?
Bukkit.getScheduler().runTaskLater() still executes on the main thread. IT's only if you actually call an async method, it will run on a diff thread
thus why it's a scheduler
i know
that the point of my thing
being able to call sync stuff from async
anyway it doesn't answer my question tho
I never said you couldnt, I'm just saying it still executes on the main thread
yeah ik that
but i still wonder now
whether there is a diff between scheduling in 0 or scheduling in 1 ticks from a thread has a difference
i think it does, because if you schedule from the thread, the current tick hasn't necessarily finished processing
right @drowsy helm
afaik when the tick has happened, the scheduled tasks are executed. You cant execute it on the same tick if the scheduled tasks have already been done
I'll have to do some testing though
I mean, I want the damager to be vulnerable to setNoDamageTicks(0) but it doesn't work
how can I check if a Block is a falling block?
anyway better than this ?
switch (block.getType()){
case SAND:
case GRAVEL:
case ANVIL:
case CONCRETE_POWDER:
return true;
default:
return false;
}
}```
block.getType().hasGravity(); @quaint mantle
cheers
how do i check if clicked block is a chest?
tried e.getClickedBlock instanceof Chest
block.getType().equals(Material.CHEST)
how would I get the location of a falling block when it lands then?
yeah, also i need to get the chests contents
Im using this
public void onFallingBlockLand(EntityChangeBlockEvent e) {
if (e.getEntity().getType() == EntityType.FALLING_BLOCK) {
REMOVAL_BLOCKS.put(e.getBlock(), System.currentTimeMillis());
log("Scheduled " + e.getBlock().getType().toString() + " to be removed after " + DURATION + "s");
}
}```
the problem is that it adds it to the map when its placed and then puts air block when it lands
but I wanna only wanna add the location of the block when it lands
if(block.getType().equals(Material.CHEST))
{
Chest chest = (Chest)block;
for(int i=0;i<chest.getBlockInventory().getSize();i++)
{
ItemStack itemStack = chest.getBlockInventory().getItem(i);
}
}
try this
it gives an exception
this is how i do it
if (event.getAction() == Action.LEFT_CLICK_BLOCK && block.getType().equals(Material.CHEST)) {
Chest chest = (Chest) block;
for(ItemStack chestitem : chest.getInventory()){
if (chestitem.getType() == Material.TNT){
tnt = tnt+chestitem.getAmount();
chestitem.setType(Material.AIR);
}
}
works, thanks
how do I get location of falling blocks when they land
if you know what block you need to see where landed, wait a bit then get location of block
oh wait
hm
@quaint mantle those falling block are creating by plugin?
check if it's still falling block and get coords
last coords is the landing position
First of all
I don’t remember how bukkit ips work but I would sure as hell not show it
Two try a decimal format
It's a local IP it doesn't matter.
Alr
Would you tell me how i do that?
Okay
String#format
I didn't find anything good so I used replace(".0", "")
if its a string just use String.format
You could also split it by . and only keep the first value in the array
or if its a double/float cast to an int
^ this
DecimalFormat decimalFormat = new DecimalFormat("0.##"); .... decimalFormat.format("20.0"); should work just fine too.
no just regularly placed, Im creating a plugin that removes blocks x seconds after they're placed and theres an edge case with falling blocks falling and not getting removed from their new location
It's too much writing I'm trying to make code cleaner and easier to read
Mhm
What's not clean about formatting decimals with an object that's called DecimalFormat 🤔
String.format("%02d", number) is easier to read
Okay
set amount to zero
Chest chest = (Chest) block.getState();
for(ItemStack chestitem : chest.getInventory()){
if (chestitem != null && chestitem.getType().equals(Material.TNT)){
tnt=tnt+chestitem.getAmount();
chestitem.setType(Material.AIR);
}
}
If you set it to zero it might bug the inventory in 1.8
sure it does. probably need to update inventory
oh
make sure its the itemstack from the inventory and not a clone
You are getting the state of the block so you are not operating on the chest in world. You are operating on a clone
trying to operate on the chest was throwing an exception
if you make changes to teh state you must perform an update when done update(true)
chest.update(true); ?
cast to an ItemFrame and setVisible(false) https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/ItemFrame.html
yeah, it's still not working
i saw that if i add an item to an inventory, the inventory will update
i will try that
how do I find the landing location of a falling block
how
like if I have
public void onFallingBlockLand(EntityChangeBlockEvent e) {
if (e.getEntity().getType() == EntityType.FALLING_BLOCK) {
// Stuff
}
}```
do I just do an else ?
yeah so to remove an item from an 1.8 chest, you need to remove the item and then add an air item, and that will update the inventory
lol just duped tnt
(Possibly a noob question) how would you allow players to add items from their inventory to a custom gui?
if you open an inventory for them
really depends on how your inventory implementation is structured
they will be able to remove/add items to it
ye but I used a java tutorial to make a custom gui and for some reason I couldn't add any blocks to the custom gui
I mean normally you'd disallow player manipulations for your GUI
Any better ways to get the uuid from an offline player ?
First of all Player extends OfflinePlayer, not the other way around
but I mean you could use OfflinePlayer#getUniqueId
Okay so, the block change event activates once when it begins to fall and a second when it lands, how do I get the second location?
Well yea I'll do that
also if you use getOfflinePlayer(String) wrap it in a future because it will make a request to mojang services
You already have a database. Just store the name alongside the UUID you already store and have a simple getter.
The method you use works just fine too but would make a URL request in the case the player never joined before to build the OfflinePlayer.
alternatively use uuids and dont bother to use getOfflinePlayer(String) instead use getOfflinePlayer(UUID) because the latter wont make a request
Yea I already store uuid name reason and time on database I did not want o use any more MySQL since that class will be heavy as hell
Always use UUID when you can. Names are volatile
Looks like user input though, which I always think of weird to require
Players will always be banned on uuid tho so no problemo on that :p
Bukkit.getOfflinePlayers() will return every known player to the server. No lookups
theres your cache
🙃😅
yeah although its a collection, I thought of something like a lookup map
Would it make sense to get uuid from database to compare to uuid in database to delete itself ? :p
uh wym?
idk why, but it detects all the tnt in the chest, deletes it and it counts only a small amount
like for 1000 tnt it counts 104
sure
how are you counting it
for(ItemStack chestitem : chest.getInventory()){
if (chestitem != null && chestitem.getType().equals(Material.TNT)){
tnt=tnt+chestitem.getAmount();
chest.getInventory().remove(chestitem);
chest.getInventory().addItem(new ItemStack(Material.STONE));
}
}
tnt is initialized with 0 before for
code block pls
depends on amount of version specific code
you're concurrently modifying
the actual plugins commands work but just whe i put the custom item in the furnace it doesnt
and the custom item doesnt grow
sounds like an easy tweak
can you help me?
yeah I mean do you have the code?
I have the jar file
Hi i want to make an jumppad but it does only this. code: https://paste.md-5.net/jofabehaco.cs
dont use outdated versions
me?
yes
i literally use 1.12.2?
you heard of 1.16.5?
lmao what
1.12.2 is outdated AF
well yea but
they didnt ask for an update they asked for help
then what 1.8 is
1.12.2 quite stable tho ngl
just apply velocity to their direction
1.8 is ancient
still popular
still outdated
automod stroke
1.12.2 on top
popularity doesn't mean it should be supported
^
i did but it just boots me to like 1-3 block forwards
also, add y velocity
i did here
Vector vector = player.getLocation().getDirection().setY(8).multiply(2);
player.setVelocity(vector);
wow I'm offended /s
only set is there no adding
1.8 is 7.9% of servers. 1.12 is 6.2% of servers. Not really high numbers to support
well okay but i asked for help not for telling me that 1.12.2 is outdated
fixed it, thanks
will never give help to people on fossils
pavlyi tbf the api hasnt had any significant changes altho the api isnt as rich
if someone asks you for support on a app you made ages ago you wouldnt help them, you would tell them to update
using 1.12.2 is like using windows 7 in 2021
but its stabler!1!11
omg
pavlyi what is the issue
lol, I use win7 😍
like
cursed
what doesnt work in code
when i step on the gold pressure plate it just boosts me a 1-3 blocks forward but not up or forward more
did you try adding instead of setting y
how do u currently handle the velocity?
I also said this
have you tried it
i have only an add(vector) method available
but i just wanna add the y
as i said, primary school maths
create a vector with x and z to be 0
and y to be whatever you want
okay it works ty
can someone make this plugin 1.16 compatible
ok so I assume that this plugin is UltraSuperCompatibleAnticheat b84928
so I shall make it k0mp@t1b3
you have to let us know what plugin lmao
@timid rose please tell us
ur gonna hv to send it here
Hi. Im just have 1 question. Why my plugin is on red?
public class RybakNPCListener implements Listener {
@EventHandler
public void onClick(PlayerInteractAtEntityEvent e){
Player p = e.getPlayer();
Location loc = e.getRightClicked().getLocation();
if(e.getRightClicked().getType()== EntityType.VILLAGER) {
if (loc.getY() == 64) {
e.getPlayer().sendMessage("Witaj. Jestem rybakiem");
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
}
}, 20L * 5);
}
}
}
}
on red?
Error
also thats some pathetic formatting
what kind of error
```java
use this formatting
```
:25:75
java: cannot find symbol
symbol: variable plugin
location: class me.NeVwer.EdycjaCzilCraft.RybakNPCListener
you have a pic on dm
Your plugin is red because its not a defined field
how do i do it?
you didnt define plugin
you need to pass an instance of your main class to this event class to use as thr plugin field.
so in main i what write?
You learn about dependency injection
Oh good news Oracle lost to Google that the Java API can be copied as "fair use".
because we don't support outdated versions
lmao
?
search oracle v. google
oracle was a dick and sued google bcuz they use java for android
Finally the courts recognised that an API is just a set of ideas not a copyright-able set of code.
if the supreme court ruled in favour of oracle android OS would've essentially been illegal
and that's pretty bad
indeed
It means you can use an API without being in breach of copyright.
You are only affected by the implementation
mhm
Its really good news actually. It means Bukkit is not copyright-able. CB is but not Bukkit
package standard.plugin.skills;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class AdrenalineSkill implements Listener {
@EventHandler
public void onProvoque(EntityDamageByEntityEvent e){
if (!(e.getEntity().hasPermission("bskills.adrenaline"))) return;
if (!(((Player) e.getEntity()).getHealth() <= 10)) return;
((Player) e.getDamager()).setNoDamageTicks(0);
}
}
``` Why is this not working?
you need to register the event
you mean in main class? Already did
and you don't need the triple parenthises either
in the first if statement
and second
you need to check if the entity is a player before casting
alright
ok. I think i repaired that but the Runnable doestn work
Listener:
public class RybakNPCListener implements Listener {
private Main plugin;
@EventHandler
public void onClick(PlayerInteractAtEntityEvent e){
this.plugin = plugin;
Player p = e.getPlayer();
Location loc = e.getRightClicked().getLocation();
if(e.getRightClicked().getType()== EntityType.VILLAGER) {
if (loc.getY() == 64) {
e.getPlayer().sendMessage("Witaj. Jestem rybakiem");
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
Bukkit.broadcastMessage("1");
Bukkit.broadcastMessage("2");
}
}, 20L * 5);
}
}
}
Main:
public class Main extends JavaPlugin {
public Main plugin;
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new RybakNPCListener(), this);
getServer().getPluginManager().registerEvents(new SideBarListener(), this);
}
}
Can someone help?
wheres the constructor in the Listener class
https://gist.github.com/Conclure/a01d187ab9127149a919daec6547757f just gonna link this
public class AdrenalineSkill implements Listener {
@EventHandler
public void onProvoque(EntityDamageByEntityEvent e){
Entity entity = e.getEntity();
if(!(entity instanceof Player)) return;
Player player = (Player) entity;
if (!player.hasPermission("bskills.adrenaline")) return;
if (!(player.getHealth() <= 10)) return;
Entity damager = e.getDamager();
if(!(damager instanceof Player)) return;
Player playerDamager = (Player) damager;
playerDamager.setNoDamageTicks(0);
}
}
there
This line if (!(((Player) e.getEntity()).getHealth() <= 10)) return; Is terrible. If NOT health less than or equal to 10, so really thats if (health > 10) return;
@hardy valley
thanks
that too
Im thinking about maybe trying to replicate some of the hypixel skyblock architecture. Aka, do some of the shit but not all of the shit because im not hundreds of developers getting paid for full time work
Open source, of course
and?
Got my plugin fully working with MySQL, now planning to make it SQLite compatible to since they do not differ than much would I copy paste the whole class or reuse the same class that MySQL is working with ?
Create an abstract SQL class, then extend and override
I read about their slime format for storing things. Made me question if i can have multiple people in one physical spigot server and they just cant see traces of each others existence unless they are in the same world
That works to I guess 🙂 ty
i'd like to replace farmland with dirt when a piston moves it, however the events ignore all block changes that happened within it and moves whatever existed there before - is there any way i can accomplish that?
One person per server no worky for 30k players
so its probably compacted
and the worlds are loaded with namings based on player name/uuid most likely
hello, i was wondering if the "player.setCooldown" method could be used with an ItemStack and not with a Material
That would be super useful
there are 12 devs
still paid full time, and 12 people = less overwhelming and stress of being confused cuz brainstorming
is it 12 on skyblock or 12 total?
altho at this point skyblock is basically all they work on but
Scoreboard scoreboard = player.getScoreboard();
Objective object = scoreboard.getObjective("mh-health");
if (show) {
if (object==null) {
object = scoreboard.registerNewObjective("mh-health","dummy", "§8(§f" + health + "§8) §6❤");
}
object.setDisplaySlot(DisplaySlot.BELOW_NAME);
object.setDisplayName("§8(§f" + health + "§8) §6❤");
}
``` Hey guys I got this piece of code that shows the player's health below their name, but it displays with a `0` in front (probably the score int). Is there a way to hide this (I know there is).
Seconds in long xd?
rip
12 on skyblock
just means you are in a git project
and I think like 4 in bedwars and 4 in skywars
nope, why not set their score to the health?
makes sense ig
how would you guys feel about an openskyblock project dedicated to remaking hypixel skyblock in open source
as in, the plugins, architecture, and premade spigot layouts/containers
we could do it in kotlin 😄
We could we could, i still would prefer java due to the amount of people who know it
more contributions
isn't hypixel skyblock basically an mmorpg at this point
yeah it was kinda like a joke rku
mostly story driven
yeah lmbishop
Kotlin is Skript on steroids 😂
🥲
yeah it is, also no story in it, falls short there
oh xd
if you're serious at actually recreating it then you're gonna have to come up with your own plot or events or whatever you call it
that means you staged it and it's new
CC seems a bit generic dont you think?
yeah i know that is what i was planning
call is ChatColor or YourPluginChatColor
ew
so, why not ChatColorX where X is what the purpose is
ColorUtil maybe or smtng
yeah that works too
for plots i was planning on having a server that would house a certain number of people, these servers are generic, plot worlds are stored in a similar format as slime. Upon user going to their home their plot world is saved and put on S3 or something, fetched when user is joining back to their world
that is how hypixel do it, they have 10 a server
Yeah thats what i was thinking too
I was speculating thats how they do it
The issue is what if someone joins their home and leaves really fast and joins back
S3 is in the process of writing but its fetched before it can by another server
Ratelimits can work so ill go with that because its way more simple than caching worlds
At that point everything is stateful and i might aswell have it all be kubernetes(many proxies are needed to support large player counts, plugin messaging and bungeecord state does not matter)
i keep getting this error from buildtools whenever i try to run it: https://paste.md-5.net/dakekiwiku.css
i am running it through git for windows
tried that
or see if the folder is read only
Use your regular cmd
tried that too
this too
bump
Or powershell, the git bash is broken at best
even when it uses portablegit, it still happens
no, because a cooldown is per an item type and not a specific item
before i installed git i was running it thru cmd prompt and was still giving the error
Then just spin up WSL I guess ¯_(ツ)_/¯
WSL?
delete everything and run BT in CMD prompt
not a vm though
are you actually the user whose desktop that belongs to?
oh, and instead is there a way to show durability bar for items that usually don't have it? So I can kinda recreate that
what do you mean by everything
I would assume that without messing with nms, no
but try doing it with a regular item just the same you woulc do with a sword
delete your BT folder. Uninstall Git. Download a new BT and run it in a cmd prompt.
ok
Nope. Unless you have a resourcepack that uses a modelid to change the look of another itemstack with durability. But then its also that tool type.
is it possible that github desktop is screwing up the process?
why are you using github desktop?
Does anyone actually use that?
electron crap make cpu die lmao
GH desktop should have nothing to do with the process, either run it on a different machine (or WSL) or nuke it and try again
ye thought of that too xD
Thanks though.
last time I used GH desktop I nearly called it malware because of how terrible it was
oh ok, ty anyway
Git bash ftw
the only acceptable git client is sourcetree, and thats because of its nice features to split up commits easily for company environments
This is a pure permission problem. Run your powershell/cmd as administrator and run build tools with it (In a clean folder)
And make sure this folder is not opened by another program. So better create a new folder with the jar
running a system with an actual bash shell ftw
i only use source tree for company/work environments (i will die if i make mistake lmao)
otherwise i say fuck off and use git cli
also im using amazon corretto, would that mess anything up?
no i use that one too for dev
- Why?
- No
oracle is evil
so is google but they know your SSN
eh idk
I would got for HotSpot (openjdk)
my dad uses a bunch of amazon stuff for his work so he recommended i use corretto
did all of this, and it still broke
It could also be a problem with the temp file never getting created
some file not exist error somewhere
show us exactly how you are running BT
C:\Users<redacted>\Desktop\Build Tools>java -jar BuildTools.jar
hey how do i check if i can add item to player inventory's
you mean if players inventory is full?
yes
I'm going to assume you are in that directory and not typing the path
yeah
public boolean isInventoryFull(Player p)
{
return p.getInventory.firstEmpty() == -1;
}
i am just running java -jar BuildTools.jar
ty
is it possible that my firewall is screwing this up?
is your command prompt run as administrator?
yeah
But this does not cover if a stack within one of the slots could still fit the ItemStack in question.
@quaint mantle
Yk my recommendation if this really isnt working well. Pull a jar artifact from the CI system that is the latest for buildtools
okay so what should i do?
what is the CI system?
try moving the folder off your desktop, so C:\buildtools
System auto builds when source code updates
ok
I think you need to iterate over all slots and manually keep track of the amount you can insert into that inventory. Let me cook up a method.
okay
that did it!
thanks guys, sorry for the trouble
I think this might work:
public boolean canFit(final Inventory inventory, final ItemStack itemStack) {
int itemsLeft = itemStack.getAmount();
final int maxStackSize = itemStack.getMaxStackSize();
for (final ItemStack slotItem : inventory) {
if (slotItem == null) {
return true;
} else if (slotItem.isSimilar(itemStack)) {
itemsLeft -= maxStackSize - slotItem.getAmount();
if (itemsLeft <= 0) {
return true;
}
}
}
return false;
}
Not sure if you need to check for air... Probably also check for air in the first if statement
okay
ty
@EventHandler
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player p = (Player)event.getPlayer();
if(!p.hasPermission("tntwars.bucket")) {
p.sendMessage("test");
return;
}
if(event.getBucket() == Material.WATER_BUCKET) {
p.setItemInHand(new ItemStack(Material.WATER_BUCKET, 1));
}
}``` why this wont work breh 😦 i feel like i forgot something xD
how do i tp a player back to spawn if he has reached certain coordinates?
Define "wont work"
package me.configz1.spawnleave;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public final class SpawnLeave extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
public void OnLeave()
@Override
public void onDisable() {
// Plugin shutdown logic
}
}
what do i put in the public void onLeave()?
Doesn't give the player a full bucket ¯_(ツ)_/¯ if it got empty
whats the difference between running a task asynchronously and synchronously
async doesnt run on server thread if we're talking bukkit scheduler, it runs on a separate thread meaning you can do stuff concurrently
so less lag?
depends
You need to check either periodically or in the move event.
Then depending how many areas you want to have you need to use either a BoundingBox, Fixed coordinate bounds, or the distance to fixed point in the world.
well you could download a file without making the entire application freeze
Set it one tick later
ig
or similar stuff that may take a while to perform
hmm ok got it
i wana make a plugin so if the player leaves lets say 500 blocks from spawn the plugin will tpa the player back to 0 0
There are some things you can do async like checking a bunch of block materials or spawning particles.
The thumb rule is: If it doesnt alter the game state you can try it async.
huh?
Then just use a Scheduler or the PlayerMoveEvent (latter is simpler) and check if the distanceSqared to the world spawn is bigger than 500 * 500
ok
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
i dont rly need this but ok
public ItemStack getPlayerHead(String player) {
Material type =Material.PLAYER_HEAD;
ItemStack head = new ItemStack(type);
SkullMeta meta = (SkullMeta)head.getItemMeta();
meta.setOwner(player);
meta.setDisplayName(player);
head.setItemMeta(meta);
return head;
}
I am using this to get player heads, but it causes a lot of lag, how do I fix that
wrap it with a future and then add a callback that posts a task on the server thread or something
I assume SkullMeta#setOwner specifically causes the lag
yh I think so
Cache the resulting ItemStack and clone it. Normally the PlayerProfile that results from this
method should be cached but for some reason cloning the ItemStack and reusing one instance
solved a lot of problems in the past for me...
@quaint mantle float distnace = 500; Location spawnLocation = new Location(Bukkit.getWorld("world"), 0,50,0); @EventHandler public void playerMoveEvent(PlayerMoveEvent playerMoveEvent) { if(playerMoveEvent.getPlayer().getLocation().distance(spawn_location) > distnace) { playerMoveEvent.getPlayer().teleport(spawn_location); } }
Make PlayerMoveEvent#getPlayer into a variable? and also java naming conventions 👀
And use distance squared if you dont want to fry your cpu with 15 users online
java conventions says nothing about disallowing allman style tho
This is actually not a java convention
who the hell wants to have a software developer that uses that, when the rest of the company uses the normal
I mean yeah when working in teams you should follow 1 style ofc
but that doesn't imply you should avoid allman style in java
thats what they call it?
mhm
disgusting
¯_(ツ)_/¯
tysm
Wow, this better portals plugin looks really cool. I wonder how they did it.
oh lmao
lol
Not trying to be rude to Jacek but you should maybe consider this instead
private static final int MAX_DISTANCE_SQ = 500 * 500;
@EventHandler
public void onMove(final PlayerMoveEvent event) {
final Location worldSpawn = event.getPlayer().getWorld().getSpawnLocation();
final Location targetLocation = event.getTo();
if (targetLocation == null) {
return;
}
if (worldSpawn.distanceSquared(event.getTo()) > MAX_DISTANCE_SQ) {
event.setTo(worldSpawn);
}
}
yes, this is much better approach
why not just do 500^2
cleaner and simpler
Because that would xor 500 and 2 in binary...
hUH