#help-development
1 messages · Page 1452 of 1
an event won't be both entity and block damage at the same time
yeah I just thought it would be a common problem
you can listen to them both
but fall damage isn't either?
probably not no
but I want to handle all damages
then listen to entity damage event
and spin the appropriate type of logic based on the actual event you get
hey
anyone? 😄 its spigot api
anyone know if entity.damage respects armour etc?
do you have a question
Didn't know this was a thing ;p
then I wouldn't be able to deal knockback
since it doesn't provide me with the attacker
you would
wait wat
and handle it appropriately
fuck
wrong button
you'd test whether it is a entity damage by block/entity event
and handle it appropriately
it respects
ty toto 🙂
np
but how do I calculate knowback
by getting the damager
EntityDamageEvent doesn't include the attacker right
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit take a look how they do it in the source
EntityDamageByEntityEvent is an EntityDamageEvent
EntityDamageEvent could be a EntityDamageByEntityEvent
I confuse
my bad I gave the wrong link
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit here you should be able to see vanilla implementations of mechanics if you search. Function/variable names will be confusing but you can figure them out from context
lol
eventually
anyways I gave the premise in how it works 😉
up to them to figure out how to apply it
what is he even trying to do
so, they want to apply their own damage but keep the knockback effect
so this involves cancelling the first damage event to apply custom damage
doesn't the damage event have like a setDamage or setFinalDamage method or something
it might, but I remember the event needing to be cancelled if you were going to change the damage values
in either case, they are worried about the knockback effect so I gave the snippet in how you would re-apply knockback yourself
declaration: package: org.bukkit.event.entity, class: EntityDamageByEntityEvent
it just super(damager) and it somehow does it
public Entity getDamager() {
return damager;
}
yes it returns the entity that damaged the other entity
private final Entity damager;
public EntityDamageByEntityEvent(@NotNull final Entity damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
super(damagee, cause, damage);
this.damager = damager;
}
it just supered it and somehow it works
I dont know how to do this for myself
what
that's the thing
idk, they are freaking out over a super call
No, just worrying about something that you don't need to worry about is all
how did it get the damager
this.damager = damager;
it got the damager in the constructor
it then assigned the damager to the field
now it has the damager
because you are only looking at the class, and not how it is actually implemented in the server, which is ok because you don't really need to worry about how it is specifically implemented. There is a reason I gave link to the API Javadocs. This way you don't get confused over implementation details.
I think I should just explain how my snippet works >>
so how do I do it in my listener
i think the issue here is that he doesn't understand the is-a relationship between the entitydamagebyentity and entitydamage events
ok there's a relationship, then?
yes, like i said
entitydamagebyentityevent is a entitydamageevent
Car is a Vehicle
no
you listen to entity damage event
and check whether it is a entitydamagebyentity event
and get the damager the same way as EntityDamageByEntityEvent right?
any Vehicle might be a Car
but not every Vehicle is a Car
the entitydamageevent (Vehicle) you get could be an entitydamagebyentity event (Car)
or it could be an entitydamagebyblockevent (Bicycle)
you want to check whether it is a Car and then treat it as a Car
instanceof
if (vehicle instanceof Car)
getcause?
no, instanceof
yes but like..
the event could be an instance of EntityDamageByEntityEvent
seems like you have this handled so I will leave you to it 😉
X instanceof car
event instanceof EntityDamageByEntityEvent
but how do I get X
X is the event
so if(event instanceof EntityDamageByEntityEvent)?
yes
if this returns true, the event is an EntityDamageByEntityEvent
and you can cast it to EntityDamageByEntityEvent
and then call the methods specific to EntityDamageByEntityEvent on it
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
event2.getDamager()
or
if (event instanceof EntityDamageByEntityEvent) {
((EntityDamageByEntityEvent) event).getDamager()
well yes
the implementation given to you was very trivial
it's calculated differently by the game
hmm
in order to reproduce it properly you'd have to figure out what the server does to calculate it
can I make it calculate using the original function or smth?
Is this jerk a vanilla mechanic (bug) or is it my implementation?
the jerk looks like you're setting its velocity to 0 for some reason
you'd need to either invoke or copy nms shit in order to reproduce vanilla behaviour
basically glhf
frick
ig you could just tweak the numbers until it looks more or less right
I need it to be the same .-.
try something easier as your first project
see if the jerk still happens if you remove the velocity packet
and by remove i mean comment out the code that sends it
i have commented out the call to the method that sends the cancel velocity packet tho, so i am kinda confused
sorry, forgot to send that^^^
then it's probably just vanilla being weird
what like the falling blocks + tnt
seems kind of annoying to set up
my only other guess is that cancelling the destroy packet somehow fucks with the velocity
wait...
what am I doing smhhh
I can just get the original damage to 0
then the KB would still apply
iirc that stops the damage sound and knockback
i know for certain it stops the sound
let's see
not sure about knockback
well
i guess
not exactly an ideal solution and will probably fuck with plugin compatibility somewhere down the road
but ig bukkit doesn't really leave much of a choice
screw it Im gonna bodge hard until it's a problem
Why does the EntityChangeBlockEvent get called when sand goes from block -> fallingBlock
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[Plugin] Plugin Is Enabled");
in the onEnable()
how about no
don't send messages to the console sender
use your plugin's logger for logging
getLogger().info("plugin enabled")
gets automatically prefixed with your plugin name
Yeah, but it is nicer cause it sends colours
and respects the end user's logger configuration for your logger
but can I color it
and does work with colors contrary to popular belief
idk tbh, thats a point. Can you distinguish between them?
now, there's something to keep in mind
idk about sound effect and it doesn't matter since I do my own damage after it anyway
using .damage on an entity fires a new entity damaged event
so make sure you don't process those
if(event.getEntity() instanceof Player)
if a player gets damaged, you catch that event
then you set the damage to 0
and then you damage the player, yes?
yes
that will fire a new event
@EventHandler
public void OnPlayerDamaged(EntityDamageEvent event)
{
if(event.getEntity() instanceof Player)
{
which then is caught by your listener again
it's the first condition
you set the damage to 0
and you damage the player
which fires a new event
and eventually either the server or the entity dies
well i'm not sure what you're doing but it should be doing that
since I have a variable that tracks health instead
on one hand you'd want the event to be fired, as that'd let other plugins customize the result
but on the other hand that could also cause incompatibility with plugins that make assumptions
inter-plugin compatibility when dealing with combat and damage is cancer and you never get it right
something always blows up somewhere
what is wrong?
if not Imma get custom plugs
errors on 37 and 38 lines
read the warning
what does it say
it'll tell you what's wrong
at net.zarpg.Main.scoreboards(Main.java:37) ~[?:?]
omg
what is the error
whats the full error
k, wait
or, actually
read what the warning says first
i have a strange tingling sensation that it might somehow be relevant
lmao
have you read the warning yet?
see that yellow underline on line 37?
place your mouse on it
yes
and then use your eyeballs to read
ok thanks
<
NullPointerException is thrown when you try to call a method or otherwise deference a variable or a field that has no value
a variable without a value is null
it points at no object
it is a null-pointer
yup
trying to interact with it throws a null-pointer exception
now read the warning
and apply this understanding to the error
getTeam is annotated as Nullable
it's return value could be null
therefore calling any methods on the returned value before checking whether it is null will blow up if it is null
check yourself before you shrek yourself
nullcheck nullable variables
'shrek yourself'? lol
very big amount of null
huhhh
some sort of desynchronization between clientside and serverside physics presumably
Guys hello i spawn Particle.REDSTONE, i want change color
and i have this code:
player.spawnParticle(builder.particle(), location.getX(), location.getY(), location.getZ(), 0, 0.001, 1, 1, 1);
how change color to 224, 224, 224 rgb?
This is quite a pain
i'm so dumb. I replaced getTeam to registerNewTeam. Thanks.
ideally you'd getTeam and if it's null, then registerNewTeam
not sure what registerNewTeam does when there is already an existing team
already complete
IntelliJ IDEA ❤️
❤️
Seeesh
Go to pm 😄
Nothing should just throw an Exception
but i'm most dumb and this isn't works
throw a throwable
It would be more specific, if it's not the developer is a dumbass that set it to throw it
Check messages, i write u in pm.
??
why does running a command echo that command back to me
you are probably returning false
bruh
I is dummy
ok so how do I send a message to the console/command block or whatever so I can tell them this command can only be run as a player
if(commandSender instanceof Player)
{
//thing
}else
{
//tell console
}
oh k
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if(commandSender instanceof Player)
{
Player p = (Player) commandSender;
int ping = p.getPing();
p.sendMessage("Your Ping is: " + Integer.toString(ping));
}else
{
commandSender.sendMessage("You can only use this command as player!");
}
return true;
}
How can I place the thing after the if statement automatically on the next line? Can't find the right setting in IntelliJ
if(condition) callMethod();
else if(condition)
callMethod2();
What I want:
if(condition)
callMethod();
else if(condition)
callMethod2();
why not just
if(conditionOne) callMethod();
if(conditionTwo) callMethod2();
or
if(conditionOne)
callMethod();
if(conditionTwo)
callMethod2();
Yes, but IntelliJ has no setting for that?
I really tried, but it can't get fixed
The last thing is what I want
what do you mean setting for that?
That they auto format it
Yes I know, but if I return back, they auto formatted it back
yeah the auto formatting is trash
i've disabled it because it keeps fucking up everything
Anyways it is good, but I can't get this fixed
what method converts strings to int and what errors does i catch if it can't be converted
Im trying to make a command with argument here
Integer.parseInt
Integer.parseInt()
and NumberFormatException
assuming strings is a String[] and the array has at least 2 elements yes
we don't know why you're getting red underlined
the red underlined says why it's red underlined
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
try(Integer.parseInt(strings[1]))
{
}
return false;
}
that's all I have
that's not how you do a try catch block
wait what
You are doing try-with-resources
you're confusing try catch with try with resources
resources should be autocloseable
int is not autocloseable
oh
Ah the setting was "Control statement in one line" to false
what do I do
you google "how to try catch java"
Guys hello i spawn Particle.REDSTONE, i want change color
and i have this code:
player.spawnParticle(builder.particle(), location.getX(), location.getY(), location.getZ(), 0, 0.001, 1, 1, 1);
how change color to 224, 224, 224 rgb?
so what's the correct why to parse a command with a number argument
bruh
int value = 0;
try {
value = Integer.parseInt(args[number (int)]);
}
catch (Exception exception) {
//no integer
}
try
{
int i = Integer.parseInt("0");
//number
}
catch(NumberFormatException e)
{
//no number
}
yep as I expected
🥄
spooon
PLS learn JAVA
I just forgot ok me sadge ;-;
Ok
don't use a shit outdated version if you don't want a shit outdated api
How i can fix this?
I created my own ChatComponent class, I want to do ChatComponentinstance + anotherChatComponentInstance
I want 1.12.2 without 1.16.5
Ok so it is pretty difficult? Then we'll need to create an append method
you'd have to prefix them with "" to kick in the string concatenation
and the resulting object would be a string
you'd then have to convert it back into a chatcomponent
Ok, I will create an append method
why not just use one of the half a dozen viable component libraries out there
Let me do it my own way 😄
how do I add a file to be included by git
player.spawnParticle(Particle.REDSTONE, location.getX(), location.getY(), location.getZ(), 0, 0.001, 1, 0, 1); i have this code
its only green
I can not, but i have this:
Team rage = Bukkit.getScoreboardManager().getNewScoreboard().registerNewTeam("rpg_rage");
player.spawnParticle(Particle.REDSTONE, location.getX(), location.getY(), location.getZ(), 0, 255, 0, 0, 1);
try this
i dont have my ide open but i think it is something like this
its red and dark red
I need to add if() to all command classes right
since or else it would run all commands?
i want only light blue
a command executor will only be called for the commands it has been set as the executor of
cmd.setExecutor(commandExecutor)
wait then why is it doing it
player.spawnParticle(Particle.REDSTONE, location.getX(), location.getY(), location.getZ(), 12, 168, 235, 0, 1); only my guess
confused unga bunga
by default all of your plugin's commands will have the main class instance set as their executor
I want to add player in team for custom glowing color
Ok, i think that there may be a new Velocity Packet Sent on that jerk in middair however idrk how to cancel only that one...
Something like this:
rage.addEntry(player.getName());
so I currently have this
}catch(Exception NumberFormatException)
{
commandSender.sendMessage("health has to be a number");
}
but it also throws this error when I dont give any argument
how do I differentiate
bcz you dont check for argument length
oh right
btw this }catch(Exception NumberFormatException) should be }catch(NumberFormatException exception)
exception checks for every error and numberformatexception checks for only when you put string into int
oh so like the order
Thanks for spoonfeed, but i have all of this in my code already without last line. I won't set scoreboard for player, team must simply creates
hi guys i am trying to save data into my config
i should have something like this:
count:
playeruuid: uuid
location: serialised location
tho I've reached what i wanted it does duplicate things. like it does repeat the same things twice but with a different counter.
I set the velocity of an boat for Y to 1f but my boat does nothing... why
Vector playerVelocity = ent1.getLocation().getDirection();
velo.setX(playerVelocity.getX() / 100.0 );
Float veloY = getPlayerSlot(ent1);
System.out.println("Velo gets "+veloY);
velo.setY(1f);
e.setVelocity(velo);
nvm
okey
hi spigot! I made a skinChanger but it doesn't work :(```public static void changeSkin(Player player, String skinPlayer) {
GameProfile profile = ((CraftPlayer) player).getHandle().getProfile();
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
connection.sendPacket(new PacketPlayOutPlayerInfo(
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer) player).getHandle()));
profile.getProperties().removeAll("textures");
profile.getProperties().put("textures", getSkin(skinPlayer));
Bukkit.broadcastMessage(getSkin(skinPlayer).toString());
connection.sendPacket(new PacketPlayOutPlayerInfo(
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, ((CraftPlayer) player).getHandle()));
}```
private static Property getSkin(String skinPlayer) {
try {
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + skinPlayer);
InputStreamReader reader = new InputStreamReader(url.openStream());
String uuid = new JsonParser().parse(reader).getAsJsonObject().get("id").getAsString();
URL url2 = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid
+ "?unsigned=false");
InputStreamReader reader2 = new InputStreamReader(url2.openStream());
JsonObject property = new JsonParser().parse(reader2).getAsJsonObject().get("properties")
.getAsJsonArray().get(0).getAsJsonObject();
String texture = property.get("value").getAsString();
String signature = property.get("signature").getAsString();
Bukkit.broadcastMessage(texture);
return new Property(texture, signature);
} catch (IOException exception) {
exception.printStackTrace();
return null;
}
}
``` and no erros when I run it.
:(
I have this method which produces a strange issue
public void start() {
arena.setOccupied(true);
int pos = 0;
for (UUID uuid : players) {
IPlayer iPlayer = core.getPlayerManager().getPlayer(uuid);
iPlayer.setMatch(this);
Player p = playerReference.get(uuid);
if (!p.isOnline()) {
arena.setOccupied(false);
return;
}
alivePlayers.add(uuid);
p.getInventory().setArmorContents(null);
p.getInventory().forEach(itemStack -> p.getInventory().remove(itemStack));
p.getInventory().addItem(new ItemStack(Material.DIAMOND_AXE, 1));
p.setFoodLevel(20);
p.setHealth(20);
p.getActivePotionEffects().forEach(potionEffect -> p.removePotionEffect(potionEffect.getType()));
p.teleport(arena.getSpawns().get(pos));
p.setAllowFlight(false);
p.setFlying(false);
pos++;
if (pos == arena.getSpawns().size()) {
pos = 0;
}
}
startCooldown();
}```
But for some players the an item that was previously in their inventory is actually still there when they click the slot
As seen at the end of this clip
This only happens on one of the accs
How do I get player from the command
p.getInventory().clear()?
no I mean like
Issue still exists with clear
Bukkit.getPlayer(args[0]);
k thax
has anyone got a solution to this?
wait this might have fixed it
What's the best way to get and also cancel the raw-est player chat input possible? I'm having issues with plugins such as DeluxeChat or CMI either providing me with some reformatted message or not letting me cancel properly with PlayerChatEvent.
So ``` p.getInventory().clear();
p.getInventory().forEach(itemStack -> p.getInventory().remove(itemStack));
highest and lowest all cause issues
especially with DiscordSRV
nothing gets cancelled lol
1.16
dont think that has anything to do with the issue
if player has health boost(more than 20 health), how do I set their health to that
player.setAbsorptionAmount(hearts);
PlayerChatEvent iirc is more of a monitor event right now consider AsyncPlayerChatEvent is a thing
that's gold hearts right
yea
isnt the playerchatevent fired before asyncplayerchatevent or am i missing something here
it is
the others you can just set by modifying max health
^
Does somebody know how many pixels the itemname from any item (in the meta) max may have?
the extra red heards
Can I set someone's mode to spectator but have the client assume it's survival? so they can't interact with shit but can't fly through blocks and have that vague menu spectator has
no
Then another question would be why do you use a deprecated event Demeng? The scheduler would be the way if you wanna do stuff on the main thread with APCE.
movement is partially client side so if the client thinks theyre in survival they wont go through walls
currently asking myself that lol
fixing up an old plugin, ig i changed it because schedulers weren't on my mind or something 🤔
Oh oof
provides openjdk8 with hotspot jvm
I'll just use my own spectator mode then, would cancelling interaction and pickupevents be sufficient?
Why wont the boat (entity e) not start to fly?
Vector playerVelocity = ent1.getLocation().getDirection();
velo.setX(playerVelocity.getX() / 100.0 );
Float veloY = getPlayerSlot(ent1);
System.out.println("Velo gets "+veloY);
velo.setY(1f);
e.setVelocity(velo);
There are most likely a lot more
Can you get all of the entities effected by an explosion, not just the blocks?
anyone?
Its just, i need to get all the falling blocks affected by an explosion
But then i remembered that they don't even trigger the EntityDamageByEntityEvent
hmm, thats a point
thanks
does the getNearbyEntities() base it off a radius from the entity?
Or do i do it like this:
List<Entity> entities = event.getEntity().getNearbyEntities(5.2,5.2,5.2);
I was about to pop a hemorrhoid over this, turns out I just fucked shit up myself. I was trying to figure out why my players weren't being hidden but I had this method at the end of my match finish method ```java
for (UUID uuid : dead) {
Player dead = playerReference.get(uuid);
for (UUID alivePlayer : alivePlayers) {
Player alive = playerReference.get(alivePlayer);
alive.showPlayer(dead);
}
}
public void setField(String field, Object object)
{
try
{
Field reflectedField = this.object.getClass().getDeclaredField(field);
reflectedField.setAccessible(true);
reflectedField.set(this.object, object);
}
catch(NoSuchFieldException | IllegalAccessException e)
{
e.printStackTrace();
}
}
public Reflection getFromField(String field)
{
try
{
Field reflectedField = this.object.getClass().getDeclaredField(field);
reflectedField.setAccessible(true);
return new Reflection(reflectedField.get(this.object));
}
catch(NoSuchFieldException | SecurityException | IllegalAccessException e)
{
e.printStackTrace();
return null;
}
}
getFromField works, but setField gives java.lang.NoSuchFieldException
it depends?
I mean you dont need to, but depending on what your coding you can
I'm just trying to send a message every 30 seconds.
alright cool.
Guys, quick question. I would like to know how to write a patch for a java application. I looked how spigot patch nms package, i think they use something like a diff tool but idk the name...
spigot uses git to create patches
I would like to apply a patch to a maven dependency. Is there some plugin that allows me to do that?
to one of the servers maven dependencies ?
or to your program
maven dependencies are distributed as jars afaik
a 3th party dependency
you'll have a hard time patching these
What does it means 'afaik'?
as far as I know
Ok, thanks.
Guys how create circle particles behind of player?
gives me an error, I have to make sure that when he enters for the first time he opens that inventory. If it is in the list it opens the inventory
that is?
I understand this but I don't know the pk ahahaha
pk?
How can I split any message at the & character and get the second character behind it? ("message&a&bm&c"), I want then String[]{"&a", "&b", "&c"}
regex is probably the way to go
Ok
so what should I do? I do not understand
well the menu youre trying to open is null
show the join.regole class
ok
Because I want to test messages on not working color codes like &z is nothing
if (player.isOnGround) {
``` is deprecated, is there anything else I should be using?
I don't think so. Deprecated because the client gets to set it
there was some effort on #5515 on paper, but I don't think that ever made it anywhere near upstream
cant you add an velocity to an boat with an player inside? I set an velocity but boat ignores it
playerDeathEvent I guess
PlayerDeathEvent
lol
thanks
how do I call the first join of the player? putting hasPlayedBefore() opens it to me in every join
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getName());
if (offlinePlayer.hasPlayedBefore())
{
Bukkit.broadcastMessage(player.getName() + " plays for the first time!");
}
how can i get how many blocks a player mined with the Statistic class?
Statistic.MINE_BLOCK ?
adopt openjdk has java 16
1.16.4 doesnt support 16
i used 16
but with 1.16.4 ?
yes
like what prevents you from just 1.1.6.5 it and run java 16
anyways what is JVM
so?
you wanna usually go with hotspot
which is the one you would find in an oracle java distribution
openj9 is a JVM developed by IBM/Eclipse Foundation and focuses more on low resource usage
yes try
ok
i download JDK or JRE
jdk
^^
no, I go in and open it to subsequent joins as well
how to uninstall java 16
I need that only the first join adds the player to the list and opens the inventory
depends very very much on operation system
and installation method of java 16
like, I really don't know
can I write to you in private?
oh then add ! in the offlineplayer
yeah sure
I sent you the request, I cannot write to you otherwise
I use windows 10
then even more questions as to how you installed java 16
idk
Yea then gl xD
i will search on google
👍
Hi guys so I'm trying to delete a world (with its folders and files inside) it works but the region folder is not deleted. I asked to some people and even to a multiverse core's devs and told me that it was happening because there were some player data in that world, the problem is that actually before deleting the whole world, I teleport all players in that world to a different one. So can someone help me with this please?
Hi. I use the Clans-API and i get the error java.lang.ClassNotFoundException: Clans.ClanConfiguration if i deploy my jar on the server. Have anyone any idea?
spanish user 😎
also use GetUniqueId instead of getName
removes the deprication error 🙂
I uninstalled.
I actually made a delay por the teleportation for all players, another for when I unload the world, and a last one for when I delete the world
I will try, thanks!
@eternal night thanks it help a lot
just as a heads up, 1.16.4 does not receive any bugfixes or updates. so if you can upgrade to 1.16.5 that might be a good idea at some point.
concerning how minor the changes are, I don't see much of a reason to keep 1.16.4
yeah and that
@quaint mantle Isn't Matcher also an option?
Like check if the colors are in the pattern
Ok....
How do I "individualise" an inventory?
I am trying to make a system where you place a furnace, and if you left click you bring an upgrade menu up and if you click the diamond it gets upgrade, but I'm not sure how to link the furnace to the inventory since the inventory will be the exact same for every furnace
It might be a stupid question but idrk how to do it haha
I wanted to check the codes, and throw exceptions
Oh sorry then
Yes, I want every color as that, and then can I check if valid
So you want to have a different inventory for each furnace?
Not necessarily, so basically how do I make it so when they click the diamond in the inventoryclickevent it finds the furnace which that links to
since you cant link the inventory to the furnace as theyre all the same
so when you leftclick it brings up an furnace gui?
Yeah
I have it so that happens
but inside the inventoryclickevent
how do I find the furnace from the inventory
Wait, when you left click what? The diamond?
and what is that diamond?
whats a pdc?
Ah okay
xd
how will the pdc enable me to link this generic diamond clicked to the furnace?
but explain what's that diamond?
u could store the id of the furnace
the thing you click to upgrade the furnace
and where's that?
in the inventory that you pull up when you left click the furnace
ooh
@EventHandler
public void onLeftClickBlock(PlayerInteractEvent e) {
if (Objects.requireNonNull(e.getClickedBlock()).getType() == Material.FURNACE) {
if (instance.getFurnace(e.getClickedBlock()) != null) {
FurnaceObject furnace = instance.getFurnace(e.getClickedBlock());
FurnaceGUI.openUpgradeGUI(e.getPlayer(), furnace);
}
}
}```
just make an eventHandler that checks if you left click a furnace and then bring up a gui
o
I already did that
my issue is that
I'm inside my inventoryclickevent
i register that they clicked a diamond
now how do i link this inventory to the specific furnace
anyone?
That when u left click it opens a custom inv?
and ther's a diamond tp upgrade
Ok, so do the furnaces get stored?
ok
but then how do I get the specific furnace when I click the diamond in an inventory which is the same for every furnace
Well, i mean if you store the loc of the furnace then you could just compare the loc and increment level by one
maybe store the player's UUID inside a hashlist when they upgraded their furnace?and every time you rightclick a furnace it checks if that player's uuid is inside it
yes -> it shows up custom inv gui i assume
no -> just normal furnace
how do I link the UUID to the inv?
wait
no
idk i would do it that way
I'd use a hashmap, but objects work better 🙂
but I'm figuring out how to access the pdc of a container that've been placed down
make an object for every furnace
thats what I've done
public class FurnaceObject {
@Getter
Block b;
@Setter
@Getter
int level;
@Getter
private static FurnaceObject instance;
public FurnaceObject(Block b, int level) {
instance = this;
this.b = b;
this.level = level;
FizzyFurnaces.instance.addFurnace(this);
}
}```
you can do @getter instead of write a getter? 😮
if you use lombok
:/
?
prob not possible
What does that do?
@Getter
class POJO {
Object o1;
Object o2;
}
effectively same as
class POJO {
@Getter
Object o1;
@Getter
Object o2;
}
this is fine right?
return new ItemStack(Material.AIR);
it will return a new itemstack generated in the return with material AIR
yurp
can i get the state of a block (.getState()) that've been placed down (event.getClickedBlock() inside eventHandler) ?
yes
Ok the solution @quaint mantle :
Pattern colorCodesPattern = Pattern.compile("(?<!\\\\)(" + code + "[a-zA-Z0-9])");
Pattern validColorPattern = Pattern.compile("(?<!\\\\)(" + code + "[a-fA-F0-9])");
And match them
okay then it would be possible to get the pdc of a block that is already placed down
u can use case insensitive flag instead of having to type both a-zA-Z
also I believe \d can be instead of 0-9
does anyone have an exmaple of some class that adds default commented lines?
commented lines?
like
are we talking configs?
/command
#this command does that```
yea
config.yml file
i saw a few examples online but they are quite rare
I believe the spigot config api doesnt allow you to put commented headers on nodes
needless to say their version of snakeyaml isnt capable of it iirc
one solution i found for this is creating a doc.text and copy paste the stuff and document it there, but i want a better solution
I mean one way would be to use something else instead of the spigot config api like a 3rd party lib
I believe Configurate has a way of dealing with commenting nodes
im trying to hook into vault but it seems that when i do the economy's registeredserviceprovider is null, even though i have vault installed hooked into essentials economy and have vault in my plugin.yml's depends
public static boolean setupEconomy() {
if (Main.getPlugin().getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}
RegisteredServiceProvider<Economy> rsp = Main.getPlugin().getServer().getServicesManager().getRegistration(Economy.class);
// rsp is null
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return true;
}
do you depend on vault?
yes
i tried adding essentials to the depends as well which also didnt change anything, and judging from the server console essentials does load before my plugin and after vault
also checked if i was using the right import of economy and checked if essentials is properly hooking into vault and stuff
In principle it should work then
where do u call setupEconomy
in my main's onenable
idk probably some weird pebkac issue
im not even sure if its a plugin issue but i wouldnt know what on the server could cause the plugin to break
i had another plugin that uses similar hooking like that which worked previously and stopped working as well for the same reason
know code quality aint the best with the whole public static enabled shit but this is just a tiny private plugin i had to make
idc
as long as its readable
yeah this feels like a strange issue
did u check if Main.getPlugin().getServer().getPluginManager().getPlugin("Vault") returns null or if
rsp is null
what version of essentials
which is?
i literally just downloaded it lol, 2.18.2
Is Vault in softdepend or depend?
ye could likewise be that
depend
dont think older versions will fix it either because updates arent released that frequently for vault or essentials
the newest versions just made it compatible for 1.13.x and stuff
EssentialsX does get fequent updates
^
And you better not be using the original one
I also would go grab the latest dev build of EssentialsX
i mean there hasnt been an update since nov 2020
cap
an official one anyway
oh yeah not a release
Dev builds get released ever other day or so
will do the dev builds tho
How can I prevent players from picking up EXP
do u use spigot?
cancel PlayerExpChangeEvent
does that also stop the orbs from dissapearing
i dont thhink so
What version of vault are you on? also make sure you don't reload in anyway
That's not Vault
so xp orbs have targets?
try this Athlaeos in onEnable
Bukkit.getScheduler().runTask(JavaPlugin.getProvidingPlugin(this.getClass()), () -> {
Collection<Class<?>> a = Bukkit.getServicesManager().getKnownServices();
for (Class<?> b : a) {
Collection<RegisteredServiceProvider<?>> c = Bukkit.getServicesManager().getRegistrations(b);
for (RegisteredServiceProvider<?> d : c) {
System.out.printf(
"Service from %d class %d instance %d\n",
d.getPlugin().getName(),
d.getService(),
d.getProvider());
}
}
});```
Guys how link to pitch particles i have this code:
for (int ig = 0; ig <= 5; ig++) {
float radius = 1.5f;
double x = Math.sin(YinYangAngle);
double z = Math.cos(YinYangAngle);
YinYangAngle -= 0.1;
player.spawnParticle(Particle.REDSTONE, location.getX() + x, location.getY() + z + 1, location.getZ(), 0, 0, 1, 0);
}
he work only one side, example:
player.spawnParticle(Particle.REDSTONE, location.getX() + x, location.getY() + z + 1, location.getZ(), 0, 0, 1, 0); // for x
player.spawnParticle(Particle.REDSTONE, location.getX(), location.getY() + z + 1, location.getZ() + x, 0, 0, 1, 0); // for z
how link to player?
I have a class called PlayerDataManager and all it does is it holds a map of player data, and has methods that deal with stuff in this map.
If I know that I will only have 1 instance of this class, is it suitable to make the stuff inside of it (The map and methods) static? Why or why not? I'm asking for a friend. I normally would not make stuff static but he brought up this argument.
hey there so im trying to run functions over servers with this code but at line 50 i get this error in my console java.lang.ClassCastException: java.util.Collections$UnmodifiableRandomAccessList cannot be cast to org.bukkit.entity.Player
my class: https://pastebin.com/08j6M5WB
you're trying to cast all online players to a single player
no not really, i suspect it to be a server/other plugin issue though although i really wouldnt know why
if i do
public Inventory build(){
Inventory inv = new CreateLocationsGUI().buildLocations(pageId,"Select the location to add the loot in");
return inv;
}
public void sum(){
pageId++;
}```
and run build it will open inv pageID 1
but if i then run sum
and run build again, it wil open the pageID 2 right?
another plugin i had there, fancyitems, used to work just fine and now it just doesnt
yeah its odd
would this run for every player or just the sender?
I mean after all it seems like vault and essentials work like they should
according to the prints
What is he trying to do?
trying to hook into vault but the registered service provider for economy is returning null
get essentials Economy implementation through servicesmanager
Idk never had any problem from any essential version
How can I create a server by code in Java / Spigot and add it to a BungeeCord server?
Without bungee restart
private boolean setupEconomy() { RegisteredServiceProvider<Economy> economyProvider = pl.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); if (economyProvider != null) { economy = economyProvider.getProvider(); hasEco=true; } return (economy != null); }
Worked everytime for me
im stupid
how can i let my scoreboard show placeholderapi campatible values?
u need the placeholder api in your plugin
oh
which import for economy are you using @onyx shale
Love the video or need more help...or maybe both?
💬Join us on Discord: http://discord.gg/invite/fw5cKM3
Thank you for tuning in to this episode of TheSourceCode! ❤️
If you enjoyed this video make sure to show your support by liking , commenting your thoughts, and sharing for all your friends to see and learn!
All code is available on Github:
...
rather you have 2 diff ones it seems
net.milkbowl.vault.economy.Economy
Only 1
The snippet had the namespace and was lazy to ever remove it
Guys i have this code how link animation to pitch?
I view static lines rotation
i want
now:
what does ..createInventory(null,..) mean? what does null represent?
what is this spigot download error?
Resetting Spigot-Server to CraftBukkit...
error: No such remote: 'upstream'
HEAD is now at c744c872 CraftBukkit $ Sat May 22 22:56:24 ICT 2021
Applying patches to Spigot-Server...
fatal: Resolve operation not in progress, we are not resuming.
InventoryHolder
how can I keep snowman from dying in the desert
cancel EntityDamageEvent
throw fire resistance into a snow man
but which damagecause is it
We need your full log and move to #help-server
idk you can test it
Yeah was about to say
wait it is doing something again
what about when a snowman leaves a snow trail, what event would have that
oh yep that's it.
I was looking at the wrong event
hey there is there any way to generate a world without any lag. so using my code once two players join a server it starts generating a world, thing is that then the server becomes very laggy and unstable while the world is generating and some times the players get kicked out. that's why i thought it would maybe be easier if i would have a server which the players wait in while on the other server the world is generating and then the players would get teleported once the world is finished generating.
is there any way to make this any smoother?
im making a manhunt plugin, so 3 vanilla worlds
that could maybe work but how would i then go about doing that if a player wants to play it again. do i just reload the server?
yea no im thinking more that everytime a game of manhunt finishes it reloads the server and then it deletes the old world and generates a new one
yea but if the player get kicked out to the lobby server and then the server reloads?
but yea that does sound kinda stupid
how would i go about unloading a world then?
How can a plugin be affected by changing from jdk 8 to JDK 16?
alright, but then when a world of manhunt finishes how would i go about creating a new world?
since that would cause lag
help :c
and then i never have to reload it?
awesome
amazing ill look more into loading and unloading worlds!
Adding to this, consider using a Java's FileVisitor to delete the world files and directories.
thanks i've been trying to solve this now for weeks!
If i include the config.yml in the jar what is the best way to load it into the plugin dir
why is this error?
package me.yourname.projectname;
public class Main ~~JavaPlugin~~ {
}
Javaplugin is error
ingore ~~
public void setField(String field, Object object)
{
try
{
System.out.println(getObjectClass());
for(Field field1 : getObjectClass().getDeclaredFields())
{
System.out.println(field1.getType());
System.out.println(field1.getName());
}
Field reflectedField = getObjectClass().getDeclaredField(field);
reflectedField.setAccessible(true);
reflectedField.set(this.object, object);
}
catch(NoSuchFieldException | IllegalAccessException e)
{
e.printStackTrace();
}
}
This won't work if I try to get a field from the extended class, how to fix? (Like if I for example extend JavaPlugin and want to get the field "description" (JUST AN EXAMPLE!!!)
You need to add the keyword extends, right before JavaPlugin
package me.yourname.projectname;
public class Main extends JavaPlugin {
}
still
you have no imports
i downloaded buildtools
No wrong, get it from Maven
Follow this step-by-step guide: https://www.spigotmc.org/wiki/setting-up-the-development-environment/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
how
stop yelling
Actually, you've already done the IDE part I reckon. Follow this: https://www.spigotmc.org/wiki/creating-a-plugin-with-maven-using-intellij-idea/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
but seriously, people don't like it when you do dumb stuff
but i am new
I also started without learning java, failed, and failed, made stupid mistakes. Then I looked forward and in a month I mastered Java. That was the end of stupid mistakes!
*Month of 2
Consider doing one of the many free Java courses, like mooc.fi/en
I did an paid course, but whatever, you have to learn Java
Any 2 month course that leaves me thinking I've mastered the topic can't be a good one.
Nah it was a good one
I know Java better than before
And rest of the tings I search on the web
who understand particles help...
It's a good course
Went through it already knowing Java to familiarize myself with the theory
works really well
Mastering java in 2 months lol
ok
hey there how would i go about checking for something while the server is starting?
checking for what
like running a function like right after the plugin is loaded
Im a bit confused by what you mean...
What does the function do
it check if a world is there if it's not there it starts generating the world
you can either just add code to the onEnable
or write a method that gets called onEnable
oh yea right lol
but if you are doing world stuff, your plugin should probably load preworld
tvhee i remember when you used to ask here before knowing java
im glad you learned now
me? lol yea i have learned alot. im right now remastering my manhunt plugin!
oh thought so
lmao
yeah, if you are doing world shit probably put this:
load: STARTUP
in ur plugin.yml
cause this makes the plugin load b4 the world
Pretty sure you can't load a new world in your plugin before the server has finished starting, so be careful with that.
wdym? I assume not
are you using netbeans
It’s some what ambiguous actually
o
I assume that the method takes in Object...
The issue is that int[] could also be seen as a single value of Object or an array of Objects
Then it is interesting to why the IDE thinks that it is varargs
If newInstance(255) does not compile, then it is a bug
Cast it to object to explicate it
Hm
Would new Object[]{new int[]{255}} stop the complaints?
ew
uhm, I think we are getting in the realms of accidentally creating things that may compile, but not run
what are the arguments that the constructor takes (i. e. the actual constructor)?
If having it on multiple lines does not bother you, you might want to try
Object o = new int[] {255};
c.newInstance(o);
hey there so i have just generated a couple of worlds but for some reason if i try for example to go to from world1 to world1_nether with a nether portal it dosen't work same thing with the end portal how would i go about fixing this?
But idk, eclipse takes in
Constructor<?> c = this.getClass().getConstructor(getClass());
c.newInstance(new int[] {255});
nicely, so it might be an IntelliJ issue after all
haha intellij
🥲
Does Spigot wait "onDisable" in plugins?
Pog
what
Yes
The server will not shutdown till all the calls are done
"no, it'll shut down before it lets plugins finish doing what they need"
varargs can be evil at times
Woth exceptions i guess..
As I remember, it was 15 or 30 seconds max?
After that, Spigot forces the plugin to finish its tasks
There is indeed some form of timeout
You will receive like "the plugin failed to..."
ProccesBuilders exist if you need to do really long calculations
Oo
I was sure that it waits but why the people in Spigot forum keep saying "no, you have 1 tick to finish your task"
maybe it has changed
I'm not sure...
1 tick lol
Some plugins do heavy stuff on disable i doubt 1 tick is a limit
So you just said Spigot won't wait onDisable?
So don't use the Bukkit Scheduler on disable
Oh, you mean scheduler
Oh the disable tick can be pretty long then
alright
https://paste.md-5.net/oboraziyey.cs
did i do some really dumb mistake here? it works just fine in other plugins i have
lol didnt see that
let me change it
still when i click outside the gui
it reurns the eror r
yea but thats what i have
like
so just
if (event.getCurrentItem() == null || clickedItem.getType() == Material.AIR) return;
is there a way of making a sound audible from further away than normal?
and if you click an empty slot?
thats air
but if you click outside the gui then its null
oh you are right, thank you
ah its only for my custom-sent sounds so it should be easier
imagine using a decompiler :/
so ig I'd have to send out a sound to each player with the distance clamped to some max value
generally speaking, always check for both null and air
^ thats what i do
will save you quite a bit of headache with bukkit's inconsistent usage of null and air in return values
Im getting a weird issue when working with arraylists
the ArrayList says that the value is in it but then doesnt recognize it
if (bypassChatList.contains(main.targetName)) {
inv.removeItem(chatBypass);
inv.setItem(13, removeChatBypass);
player.updateInventory();
System.out.println("test");
} else if (!(bypassChatList.contains(main.targetName))) {
inv.removeItem(removeChatBypass);
inv.setItem(13, chatBypass);
System.out.println("test1");
player.updateInventory();
}
what is that supposed to mean
yea thats confusing
so here
thats my code yea
it never prints test
it only ever prints test1
but
my arraylist contains the targetName
that second if condition is redundant
if bypassChatList.contains(main.targetName) returns false, !bypassChatList.contains(main.targetName) will by definition return true
why would it return false though
oh
yea ik that
but I was just messing around to see if i could get it to work
idk
print out the target name and print out the list to stout
what type is the list
array
what type or arraylist
string
add the target name to the list and then print the list
i am already doing that
add it before checking contains
@EventHandler
public void test(PlayerToggleSneakEvent event) {
Entity e = event.getPlayer().getWorld().spawnEntity(event.getPlayer().getLocation(), EntityType.BEE);
velocityPacket(e.getEntityId(), 0, 10, 0);
}
public void velocityPacket(int id, double x, double y, double z) {
final PacketContainer veloctiyPacket = new PacketContainer(Server.ENTITY_VELOCITY);
veloctiyPacket.getIntegers()
.write(0, id)
.write(1, (int) (x * 8000.0D))
.write(2, (int) (y * 8000.0D))
.write(3, (int) (z * 8000.0D));
veloctiyPacket.setMeta("CUSTOM", 1);
Bukkit.getOnlinePlayers().forEach(player -> {
try {
this.protocolManager.sendServerPacket(player, veloctiyPacket);
} catch (final InvocationTargetException e) {
e.printStackTrace();
}
});
}
why no worky
get the hashcode of the string in the list and compare it to the hashcode of target name
and by compare i mean print them both and look at them
theyre the same
now try calling Objects.equals on them and see what it returns
how do I do that lol
how do i fix that when i typ a command, all the available options come onto the screen? like this:
a solution is commodore
Objects.equals(bypassChatList.get(0), main.targetName)
you must override onTabComplete
remove the line where you add the name to the list before checking
okay
java.lang.IndexOutOfBoundsException
but for some reason my cmd isnt working
in what way?
your list is empty
yea
remove the thing I told you to add earlier
i did
then why is the list empty now
cause i removed it