#help-development
1 messages · Page 1478 of 1
EnumSet
Use == when comparing enums
Also make sure item is the Material and not the ItemStack
(or change the item variable)
isn't there a tag for pickaxes ?
That might throw a nullpointer just a heads up
Probs paper
sad
and?
I usually see null items rather than air
Yeah they are null 99% of the time
Spigot is somewhat inconsistent with null and air
You can
Checking for both is probably best
Not holding an item
xd
Yeah it is
Spigot really is inconsistent
Yeah
or use an EnumSet like Conclure said
getItemMeta can be null
Check if it a has item meta before calling
Yes
Hey I'm confused on what I should put as the JsonSerializationContext for TextComponentSerializer
anyone know how to add the proper javadoc documentation (comments) from the spigot api (or any api) to intellij assuming you're using gradle and not maven?
it used to work most of the time with maven but with gradle I'm guessing there's some specific setup step that is required
I mean, the error message is rather clear. Movement is processed on the main thread of the server.
Incoming packets are not
so you are moving an entity around on a different thread which is somewhat fine until it crosses a chunk board, in which case the old chunk lets loose of the entity and the new chunk tracks it.
doing so on a non-main thread causes this error
Hey, I am looking for a SignGUI for 1.16.4/5 that works without issues and is a standalone class, does anybody have one?
how can I get the target block of a player?
hey guys trying to create a list of entities but getting an error on Arrays. List<EntityType> list = Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE);
Anyone know why?
- Arrays cannot be
resolved
- List cannot be resolved
to a type```
youre just passing in a set of entity types not an array
you need to declare the array
?
idk what buoo is on, your code is perfectly fine for creating a list of entity types
just missing some imports I am guessing
it does yea
ah mb
can I use an array instead of an array list for this?
I'm a little confused but I think that may be simpler
nah your code is fine, like lynx said it looks like imports
oh thanks missed this
i imported import java.util.ArrayList; but still nothing
Done! Ty still learning ><
- Line breakpoint:Listeners [line: 30] - creatureDmg
(EntityDamageByEntityEvent)
- The method asList(EntityType, EntityType) is undefined for the type
Array```
String name = event.getEntityType().name();
double damageTaken = event.getDamage();
Location loc = event.getEntity().getLocation();
List<EntityType> list = Array.asList(EntityType.CREEPER, EntityType.ZOMBIE);
yeah Arrays, not Array
RIP done
i changed it to import java.util.Arrays; too
that seemed to fix everything
now for the BEST part
if we can get this to work ill be friggin happy
spawning random mobs lol
yeah, could be created outside of the method
yeah this is one of the things I need to work on
ty for bringing it up
not a gigantic memory hog so its pretty negligible
would it be a public method outside the method? and into the class
no it'll be a private variable*
just a variable would be enough
how can I get the target block of the player
private List<EntityType> list = Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE, EntityType.CHICKEN);
can be final also
Depends on how many time the method is actually fired tbh, if there are severals players attacking at the same time, that could end up in a little memory bloat
final, also immutable if you really want
Yeah List.of might be more suitable
that's what i was worried about
yo guys i wan a crate bedwar plagin but i dont kno what is arrylist
by the way wut is car
an arrayList is a collection of objects
char i tink
am jokin lol
stop recycling old jokes, what are you, a stand-up comedian?
better than what you call a "stand-up comedian" 😏
that was lame
So this is what I'm using to spawn the random entity loc.getWorld().spawnEntity(loc, mobList.get(random.nextInt(mobList.size())));
😔
That's good
I'm getting the error The method spawnEntity(Location, EntityType) in the type World is not applicable for the arguments (Location, Object)
not understanding because i'm providing it a location and an entity type
Mmmh
why is it being cast to obejct?
mobList is a collection or EntityType right
not Object
isn't your list named "list"
private List<EntityType> mobList = Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE, EntityType.CHICKEN);
(from what you've sent before)
i changed it to mobList
Mmmh why is that on private ?
huh
Are you doing it outside the method ?
because I don't want anyone outside of this class to access this?
yeah
private List<EntityType> mobList = Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE, EntityType.CHICKEN);
@EventHandler
public void creatureDmg(EntityDamageByEntityEvent event, List mobList) {```
You shouldn't initialise a non static var outside a method
you should init it on the constructor
damn taking me back
i haven't done that in a long time haha
ok time to google constructor
Just do, public Listeners() { mobList = Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE, EntityType.CHICKEN); }
and so your private would be
private List<EntityType> mobList;
it can be, yeah.
I wouldn't do static since you're not going to use it without an actual instance of this listeners class
its called in moveEvent, none for specifically jumping htough
so i would have to keep it uninitialized and then create it under my Main class
i thought there was a constructor method that we could use within classes to do this
i haven't done this in a long time sorry guys
You have to register your listeners anyway
and create an instance of the listener in the onEnable method
I am
instance = this;
getServer().getPluginManager().registerEvents(new Listeners(), this);
}```
but I don't understand the one liner too much
not sure why i have to pass the main instance over
use getFrom and compare to current location, if getFrom.y > loc.y its a jump
that's what confused me
private static Main instance;
public static Main getInstance() { return instance; }
@Override
public void onEnable() {
instance = this;
getServer().getPluginManager().registerEvents(new Listeners(), this);
}```
I thought it was needed to work
Well I never told you to pass the actual instance x)
:I
no you didn't just thought it was necessary
ill comment it out and see if it works
try and avoid using static instance stuff like that
I mean I would argue not to do it if you wanna write loosely couple code and keep your code object oriented
Since it's a Singleton, doing it in a static way it's not bad, it's the purpose of the singleton so he can do it by injection or by static, here is the same tbh
I'm going to have to start from scratch pretty much with this lol
You could also use event.getTo()
location wouldn't be updated byh then
wym "by injection of by static"
is it registered
that was 'or' missclick ^^'
oh right I mean I couldn't care less if anyone decides to use a static singleton I'm pointing out this:
I mean I would argue not to do it if you wanna write loosely couple code and keep your code object oriented
@last temple by the way, why did you define player in the first place
oh cool then
@opal sluice how does this look:
- in main initialize the listeners class and assign a variable
Listeners x = getServer().getPluginManager().registerEvents(new Listeners());
- inside Listeners class create a constructor to intialize the private mobList.
mobList = tmpMobs;
return mobList;
}```
3. back in main send the list over to setMobs constructor
```x.setMobs(Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE, EntityType.CHICKEN));```
Nope totally wrong sorry ^^'
I'm not sure, but I think #registerEvent is a void method
So, you'll not be able to save an instance of that, and there are no reason to do it tbh
but i thought you guys told me to get rid of this
Then, yeah, you forgot the plugin instance to pass
doing "this" has nothing to do with the instance you saved in the static var
Then, you said "I create a constructor"
Those are not constructors, but methods
You don't need methods to do it
do it in the constructor
The constructor is a method called the same as the actual class file
and not having any return type
Ig it does until you reach the ground
// For you it would be like that
private List<EntityType> mobsList;
public Listeners(List<EntityType> mobsList)
{
this.mobsList = mobsList
}
oh I was being half blind, figured out the doc issue
🤡
Hi, is there a way to check if the blocks are connected to the ground?
My idea is to make it so that when a structure is completely "floating" in the air, it collapses. (Turn into falling blocks)
ty! i was almost there but used Arrays instead of list entity type like you did
getting this error though on this.moblist mobsList cannot be resolved or is not a field
hows ur class looking
don't forget the
private List<EntityType> mobList; //Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE, EntityType.CHICKEN);
public Listeners (List<EntityType> mobsList) {
this.mobsList = mobsList;
}
```
yeah
Also, I did not pointed it out earlier, but you shouldn't handle multiple events in one class
what do you mean register?
you mean split them out into individual methods?
sorry I meant handle**
So you would have EntityDamageByEntityEvent in one class
i wanted to make this work and then tidy up the code that's my approach to coding. it's ugly
right on!
I'm still getting The method spawnEntity(Location, EntityType) in the type World is not applicable for the arguments (Location, Object)
loc.getWorld().spawnEntity(loc, mobList.get(random.nextInt(mobList.size())));```
Well, cast the object
what does that mean
loc.getWorld().spawnEntity(loc, (EntityType) mobList.get(random.nextInt(mobList.size())));
Normally you wouldn't but idk why the list doesn't seem to pass the type when you get an item by index in your case
oh ok
last question i have and it might be a logic one is..
every time a mob takes damage, i want it to retain the health. can i place a variable in a constructor that holds and refreshes the value of the mob(s) health being hit until it reaches 0?
what's currently happening is when a mob takes damage, I'm teleporting it outside the map to be killed and spawning a new mob in its place
i'd like for the new mob and future mobs to retain the health value and eventually die
Can't you just kill the mob then respawn one
instead of getting him outside the map
I don't want the players to see the mobs die in front of them. i was teleporting them out of view and killing them
?jd
LOL
I don't see that
well anyway does anyone have some ideas
i live on the docs but thanks?
what..
He means he uses the docs
thanks 🙂
so there doesn't seem to be a remove only damage or set health
I can see it right there 😭
unless you using some outdated ass version
wtf
¯_(ツ)_/¯
this is my bookmarkhttps://hub.spigotmc.org/javadocs/spigot/index.html
looks like the same thing
and i just searched for entity ctrl+f for remove and nothing
RIP me
yeah.. there is a search function
ctr+f only looks at the currently loaded webpage
methods arent in the main page
lmao
smh
the javadocs are more than one webpage xD
hello how can i create plugin?
research
lmao deserved
so many tutorials out there already
so?
why do you ask us xd
then?
- figure out what you want to make. 2. ask a specific question once you're already coding
- Use google
ok
thanks
so I just ran the new version of the code but nothing is spawning when an entity is taking damage now
loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
console says ShapeShift v0.1 attempted to register an invalid EventHandler method signature "public void com.cowagames.Listeners.creatureDmg(org.bukkit.event.entity.EntityDamageByEntityEvent,java.util.List)" in class com.cowagames.Listeners
why is there a list argument to your event listener
blocks do not carry over information whether or not they were generated or placed
yeah blocks don't save this
my bad that was old code and i forgot to remove it getServer().getPluginManager().registerEvents(new Listeners(), this);
but it's saying the constructor is undefined now
ok i get it
the list object is to pass it a list of entities
getServer().getPluginManager().registerEvents(new Listeners(Arrays.asList(EntityType.CREEPER, EntityType.ZOMBIE, EntityType.CHICKEN)), this);
this.mobsList = mobsList;
}
```
that's how it's getting intialized
then we pass it over to the damageby event public void creatureDmg(EntityDamageByEntityEvent event, List mobsList) {
to spawn a new entity
How can I fill the chest I opened with random items?
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getClickedBlock().getType() == Material.CHEST) {
Player pl = (Player) e.getPlayer();
//xxxx
pl.sendMessage("true");
}
}
my question is why is it an invalid eventhandler hmm
Chest chest = (Chest) e.getClickedBlock().getState();
chest.getInventory().clear();
chest.getInventory().addItems...```
thankyou
This is all wrong
How can I put items in an array?
You can't pass argument to events :/
List a = new Arraylist
a.add("e")
Why are you even trying to pass the actual mobsList
java tutorials online would be helpful
When you can just get it from the same class
It's a class variable
no need to pass it
You can't invent methods. Always check the Javadocs https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/PluginManager.html#registerEvents(org.bukkit.event.Listener,org.bukkit.plugin.Plugin)
because if i told it's saying the constructor is uninitialized
i got confused
It's this code wrong
ty
not the constructor part
You can pass anything in the constructor
The problem here
is that you're trying to add a parameter
to an event method
and you can't do that
ok fixed, that was an oversight sorry
the morphing works great now! and the remove element is beast
the only problem i have now is the HP
can i keep track of their HP somehow from the original mob?
What you can do
is
remove the entity
get the total damage
spawn the new entity
apply the total damage to new entity
that's what I was doing before
but would that be fair? what if we're fighting a cow then a dragon spawns
his health would be insane
how do I init a List?
what type of List
string
you cant initialize/instantiate a List
List<T> myList = new ArrayList<>();
List is an interface
thanks
you can only use an ArrayList, and subclasses of List
ok let's say we go with this
i tried to use set health at the end of loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size()))) but it doesn't seem available
so this?
ArrayList<String> Lore = new ArrayList<String>();
would i have to make an entity variable out of this line then set it?
No
List<String> lore = new ArrayList<>();
#spawnEntity return the entity spawned
so you can do
Entity spawnedMob = loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
you didnt import the class
<String> get underlined with
Type 'java.awt.List' does not have type parameters
wrong import
java.util.list
Entity spawnedMob = loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
setHealth doesn't seem to be available for that
spawnedMob variable
lmck
Mobs spawn at max health
Heya - Is there a way to send a message when a player logs onto the server w/ bungee? From what I can tell the client doesn't receive messages if I send them directly on PostLoginEvent
yeah we're trying to set their health
to what?
Entity takes damage, we store the damage done to that entity and apply it to the new entity spawned
double maxHealth = zombie.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
zombie.setHealth(maxHealth-damageTaken);```
I've done it this way before
but now that we're randomizing the entity spawned I can't
Entity spawnedMob = loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
i'm guessing it's because of the spawn vs spawnEntity difference?
cast it to Damageable
hmm
+1
not sure what you mean
if the Entity is instanceof Damageable, cast it and then you'll have setHealth
how would i cast it?
Java
Damageable spawnedMob = (Damageable) loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
Can i use Maven to add 1.8 support to a 1.12.2 plugin?
Actually, I think you're right
It sends before the player actually joins
It should be LivingEntity
and not damageable
So
LivingEntity spawnedMob = (LivingEntity) loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
Either, LivingEntity inherits Damageable, but Damageable; is the interface that controls its health
There is two
hmmm so would it be a damageable or living
Yup, I saw the item one, that's why ^^
Can be both, that's pretty much the same if you only want to modify the health
Can i use Maven to add 1.8 support to a 1.12.2 plugin?
i need to recreate on 1.8?
well Damageable's getMaxHealth is depreciated and I can't use attributes on it for whatever reason
You need to downgrade the plugin to 1.8
or what i need to do
The method getAttribute(Attribute) is undefined for the type Damageable
If you want to do other things, use LivingEntity
Cause attributes are on EntityTypes
how can i downgrade?
Recode the parts that doesn't work on 1.8 with the 1.8 API
oh ok
jesus this is confusing so do i need to recast it as an entitytype?
Lol, no, you don't need it. As @eternal oxide said, the entity spawns already with max health
Just LivingEntity as you want attribultes and setHealth
So just remove the total damage from the actual health
spawnedMob.setHealth(damageTaken - spawnedMob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
yeah but how would i get the actual health
isn't that max health
oh nvm
derp
get health
spawnedMob.damage(totalDamage);
cuz it's spawning with max
yup
however, calling damage will trigger a damage event
ok so now how do we carry this over to the next mob? cuz the next one will spawn and only get the dmage that was caused to the previous one
Oh lol that would make a damage machine 😂
String name = event.getEntityType().name();
double damageTaken = event.getDamage();
Location loc = event.getEntity().getLocation();
//kill previous entity
event.getEntity().remove();
Random random = new Random();
Damageable spawnedMob = (Damageable) loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
spawnedMob.setHealth(damageTaken - spawnedMob.getHealth());
```
Well, then use LivingEntity to get the max health and set the health to not trigger a damage event
What exactly are you trying to do as killing one perfectly good Entity to spawn another seems... odd
sure
i want mobs to change every time i hit them
but i want their health to eventually drop to 0 lol
as in, it changes to a different type?
correct, a totally diff. entity
ok, that makes more sense
so if it's a chicken it can become a zombie 🙂
I'm just not sure how to retain the hp and keep track of that now
that's the last hurdle
Instead of casting it to Damageable, cast to LivingEntity
LivingEntity has the arributes so you can read them,. It also implements Damageable
Hi
What AWD (antiworlddownloader) do you recommend?
i probabbly do better by restarting to code because i found some problems
hmm but would it matter if it's a whole new entity each time?
you would need to get the Max health of the entity you are killing. Set that max health on the entity you are spawning, then copy over its actual health
If you are not using nms it might be fine
oh!!!
it's a bedwars plugin, probabbly can be a little problem the code, i have to watch better
Does it use nms
If you use this spawn event you can set all its attributes before you spawn it https://hub.spigotmc.org/javadocs/spigot/org/bukkit/World.html#spawn(org.bukkit.Location,java.lang.Class,org.bukkit.util.Consumer)
for now i am not using
Oh then Nothing much to worry about
unless if it shows errors
Is there anyone that does development work?
fancy ok, first how would i get the health of the entity that was damaged? i can't seem to access that using event.getEntity().getHealth()
are errors internal the team system
why not?
i'll recode from 8th june
Check its a LivingEntity and cast
public class MapManager {
public List<Map> maps = new ArrayList<>();
public MapManager MapManager() {
return this;
}
public List<Map> Maps(){
return maps;
}
public void addALine(Map e){
Maps().add(e);
}
public boolean isInGame(Player player){
Map m = Maps().get(1);
for ( int j = 0 ; j <= m.getPlayers().size() ; j++ ){
Player p = m.getPlayers().get(j);
if ( p == player){
return true ;
}
}
return false ;
}
public void setMap(Map m){
if ( Maps().size() == 0 ){
addALine(m);
} else {
if ( Maps().size() == 1 ){
maps.clear();
addALine(m);
}
}
}```
i used setMap(new Map ... in a Class
it sayed added to arayy list
but i use list commad it sayed me 0 is size of array
and it not added
can help me pls ?
that code looks mega confusing to me
like a boolean to see if it's alive and if true get the health? event.getEntityType().isAlive()
/list command??
yes
can u show the command method
yes wait
btw /list is already a spigot command
it's hard to code a bedwars plugin, mine project is mor bigger, multilang, arenareset and other 12 features
@eternal oxide I'm using EntityDamageByEntityEvent which is inherited from an entity it seems but entity doesn't have the get health method
if ( e.getMessage().toLowerCase().equals("/ffaadmin list") ){
e.getPlayer().sendMessage(" " +mm.maps.size()) ;
}```
i test it in a onCommand
but are like this
No, if (!entity instanceof LivingEntity) return;
Im confused on why the constructor is returning something
Are you using CommandPreProcessEvent ?
Well, I guess you are since you're doing e.getMessage()
Entity entity = event.getEntity();
if (!(entity instanceof LivingEntity)) return;
LivingEntity mob = (LivingEntity) entity;```
ik . but i add /ffaadmin list command on a onCommand() class
and make a new legit command
you just need to register ffadmin
and then you check for the args of the command
i registed
Even in the plugin.yml ?
You set the executor to the right class ?
i added a object too maps Array on MapManager , and i use this for return size of this array . but it returned me 0
but i added a object
The operator ! is undefined for the argument type(s) Entity
Ok, so why are you using the CommandPreProcessEvent then ?
i think my object not added for i use onCommand . i use it for test
Sorry, but I don't understand ^^', could you send some code ? If the command is not registered properly it's obvious that it will not work
yes i can
do you want my full source code of my plugin ? i can send it
Only the main class and the command
k
first issue i've been encountering as soon as I change it to th spawn method from spawnEntity is that i receive an error stating The method spawn(Location, Class<T>) in the type World is not applicable for the arguments (Location, EntityType)
see dm
Zombie.class
but then wouldn't we be only able to spawn zombies?
and not random entities
you use whatever class you want to spawn
You also want to be using this spawn method not the one you are https://hub.spigotmc.org/javadocs/spigot/org/bukkit/World.html#spawn(org.bukkit.Location,java.lang.Class,org.bukkit.util.Consumer)
it has a Consumer
so from LivingEntity spawnedMob = (LivingEntity) loc.getWorld().spawnEntity(loc, (EntityType) mobsList.get(random.nextInt(mobsList.size())));
to
LivingEntity spawnedMob = (LivingEntity) loc.getWorld().spawn(loc, (newMob) newMob;```
something similar to that?
Sorry, maybe I'll be a bit rude, but shouldn't you learn a bit more java before trying to make a plugin ? We're making the plugin at your place at this point ^^'
LivingEntity spawnedMob = (LivingEntity) loc.getWorld().spawn(loc, (newMob.getEntityClass() newMob));```
Thanks for the help
I like learning through examples. I should due my job and google/troubleshoot more
Was leaning too much on you guys since we're at the home stretch
but I came here with almost no knowledge and I've learned a lot so ty
I knew Java really well at one point but haven't touched it in years so I'm getting back into it
so no not rude and i can partially agree. You guys are helping a ton and that goes unsaid
double max = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
double current = entity.getHealth();
loc.getWorld().spawn(loc, newMob, e -> {
e.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(max);
e.setHealth(current);
});```
dude this blew my mind
this is what I had prior to you sending that
Thats how to set the max and current health before its spawned/
LivingEntity spawnedMob = (LivingEntity) loc.getWorld().spawn(loc, newMob.getEntityClass());
spawnedMob.setHealth(damageTaken-spawnedMob.getHealth());
```
yeah i was really curious about that when you said it
Yours would work, but for a short moment the mob would spawn with its default health.
right on
so the e-> {}
what is e?
just tell me the name and ill google the rest
e is the mob that is about to be spawned
its a Consumer method. Basically it runs that code before teh mob spawns.
right on
btw getting errors on e.getattribute - The method getAttribute(Attribute) is undefined for the type capture#1-of ? extends Entity
loc.getWorld().spawn(loc, newMob.getEntityClass(), (LivingEntity) e ->
like that?
The target type of this expression must be a functional interface
((LivingEntity)e).getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(max);
((LivingEntity)e).setHealth(current);```
((LivingEntity)e).getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth-damageTaken);
that's the same logic in one line right?
i'm setting the max health the prior's max health - their damage taken
no
you are reducing their max health
their max health has to be identical, its their currrent health you set lower
((LivingEntity)e).setHealth(maxHealth - damageTaken);```
im a little confused
so get attribute max health set base value is getting their max health and setting it to the original mob we hit
is this in a damage event where you need to apply more damage?
then we aply the damage to set health right?
yeah this is within the entitydamagebyentityevent
yes
yep, so its damage to his health, not his max health
so thinking logically one more time, will mobs eventually die like this?
not with your current code
oh
you have to use the entities gethealth - damage
Entity entity = event.getEntity();
if (!(entity instanceof LivingEntity)) return;
LivingEntity mob = (LivingEntity) entity;
double maxHealth = mob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
double damageTaken = event.getDamage();
Location loc = event.getEntity().getLocation();
//kill previous entity
event.getEntity().remove();
Random random = new Random();
EntityType newMob = mobsList.get(random.nextInt(mobsList.size()));
//LivingEntity spawnedMob = (LivingEntity) loc.getWorld().spawn(loc, newMob.getEntityClass());
loc.getWorld().spawn(loc, newMob.getEntityClass(), e -> {
((LivingEntity)e).getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
((LivingEntity)e).setHealth(maxHealth - damageTaken);
});```
thought we already had that above with the maxHealth variable? We're getting the original mobs health
and applying it to the new one below
sorry im a little confused
use getFinalDamage over getDamage
else its not takign into account buffs and armor
and you need to get teh mobs health as well
which mobs? we do under maxHealth?
double maxHealth = mob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();```
LivingEntity entity = event.getEntity();
Location loc = entity.getLocation();
double max = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
double current = entity.getHealth();
double damage = event.getFinalDamage();
Entity mob = loc.getWorld().spawn(loc, newMob, e -> {
((LivingEntity)e).getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(max);
((LivingEntity)e).setHealth(current - damage);
});```
I think that setting the new mob to the max health of the previous mob isn't that great, I would rather calculate a coefficient of max health between the two and then multiply the damages by the coefficient to match the new max health of the new mob
Is there a way to detect a right click in the void without item in the hand with the packets? It would seem that this is not possible with the PlayerInteractEvent
You have to set teh max health else you gradually reduce its max value as he changes mob. Eventually you end up with a chickens max health
Yup, that's why you could also change the health value with the coefficient and all would be sync
why is current needed? shouldn't we be subtracting max - damage? otherwise we'd be dealing double the damage to the new mob?
no need to be super complex. You just start with the max health of the mob you first hit
no
You are removing the old mob and applying the damage to the new
isn't current health the health of the mob after its been dmged?
when teh event fires no damage has been applied
oooooooooo
you should never be subtracting from Max. Always from current.
If you subtract from Max, you are always applying a single set of damage to full health mob
thanks
going in to take this for a ride!
fingers crossed
worked! the only quick error i found was that if an entity hit me it became me and then the whole world froze lol
lol
going to need to put an exception in there somewhere
dude this thing is amazing
ty so much for all the help
and that goes to all of you
you guys pretty much have the plugin but if you want the final version just let me know and i can host it somewhere 🙂
You'll have to early return if not instanceof Mob
same as you did for LivingEntity
ok trying that now
Hey.
You may also want to setTarget in the Consumer so the new spawned mob fights back
Hello everyone ! I'm trying to deal with packets with bungeecord and i've got this error when i send the packet to the player :
java.lang.IllegalArgumentException: Cannot get ID for packet class com.nolydia.bungee.api.protocol.packets.PacketPlayOutOpenWindow in phase GAME with direction TO_CLIENT
https://pastebin.com/y888zxE8 <- I want my timer to add 1 second every second when i do /timer start. When i do /timer stop i want to set it to 0 and then stop adding. Why does it not work?
Because there is no timer
How can i make one
That will kill the server lmao
I want to add 1 to time every second and display it over the hotbar
Make a runnable running every 20 ticks
how?
that increment if a bool is on true
BukkitRunnable#runTaskTimer
A bit outdated but works
So a BukkitRunnable?
y
they were fighting back automatically but I'll do more testing. The only thing I'd like to do is find the item that the original mob drops and have the one killed drop the same one? if that's possible. so if it's a chicken and ends up dying as a zombie it'll be good for it to drop a breast
is it possible to obtain a list of items that's dropped by mob using entity's itemstack and assigning it to the new mob?
Not easily as you'd have to set a PDC on every mob you spawned to say what it originally was, then use the following Builder to generate the loot yourself https://hub.spigotmc.org/javadocs/spigot/org/bukkit/loot/LootContext.Builder.html#lootedEntity(org.bukkit.entity.Entity)
or, you could just check if its going to die, remove it, spawn teh original type and kill it
you'd still have to do the PDC bit though
hmmm
well after killing about 100 mobs
only the donkey dropped some leather
nobody else dropped anything
in which case, you need to change your code a little
getting food is going to be a b***
lol
i just find it weird that nobody is dropping anything
you need to set health, set a flag so you don;t process the next damage event, then .damage the entity for the correct amount.
its because you are using setHealth and not damage
oh
I went from this:
((LivingEntity)e).setHealth(currentHealth - damageTaken);```
to
((LivingEntity)e).setHealth(currentHealth);
((LivingEntity)e).damage(damageTaken);```
you need to ```
if (ignoreEvent) {
set ignoreEvent false
return
}
Check if getHealth - damage <= 0
set a boolean ignoreEvent true
then return instead of spawning.```
do you have any idea where it could come from?
what is ignoreEvent?
you need to set a boolean to prevent your code running for the next damage event
ignoreEvent would be a field
actually scrap all that
before you do the spawning, check if current - damage <= 0 return
don;t kill the current mob, so before you remove the mob and spawn the new
by returning you are simply allowing the event to run and kill the mob.
Hello!
Does someone now how I could get the Player, a other Player is looking at?
You don't need to look at the other Player exactly tho and he should not be to far away...
Thank you!
ok let me see if I understand. Before we spawn a new mob we want to check if the current health - damage is less than or equal to 0 (aka the mob will die). If so, we just return and kill the existing mob instead of removing it
yep
so wouldn't it be
if current - damage !=0 then proceed with the rest of the code else just don't do anythign and the mob will die?
Whatever the mob is that gets the killing blow you let die
no if (current - damage) <= 0 return;
kk
works flawlessly now
got a ton of chicken and food now haha
I dont understand what to put in raySize...
Location, would be the players eye location, getDirection for the vector, distance is in blocks, and predicate on Player
if you use raySize the javadoc tells you exactly what it does.
raySize - entity bounding boxes will be uniformly expanded (or shrinked) by this value before doing collision checks
okay thank you
so a bigger value = you can be looking further away from the player and still detect it
oh okay thank you
i have this file that retrieves a weapon from a hashmap
but when i try to get a scoped rifle it keeps returning null
even though the display name matches the key
and what do I put in the Last one the Predicate<Entity> if I want it to be a Player?
(entity) -> entity.getType() == EntityType.Player
something like that should be fine
Color codes (if any) are going to mess with that match
cannot resolve the method getType
its probably not that exactly
i know, but i compensated for it by adding the color character before it
if theres no gettype or whatever then just instanceof check it, but thats more intensive
ill try without color codes tho
declaration: package: org.bukkit.entity, interface: Entity
there literally is a getType
and its in all versions
yeah I know but its red haha
why is inv null there? i already built the inv by running the command
public void onEnable() {
instance = this;
// Plugin startup logic
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "starting");
Objects.requireNonNull(getCommand("open")).setExecutor(new Command());
getServer().getPluginManager().registerEvents(new InvClick(), this);
}```
Main
public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, String[] args) {
Player player = (Player) sender;
new InvClick().open(player);
return true;
}```
command
RayTraceResult rayTraceResult = new RayTraceResult(player.getLocation(), player.getLocation().getDirection(), 30, (entity) -> entity.getType() == EntityType.Player);
You are creating a New InvClick and your inv is not static
I did it like this is that wrong?
wdym creating a new inv click
do you ever call build()?
yea in the code i sent
and in your onCommand you create a new InvClick
use the listener you register not create a whole new instance just to access the Inv
Nowhere in the code you showed do you call build() before you try to access inv
should be ok?
ah ok, SS is too small for me to read
yeah but the getType and Player is read
you dont create raytraceresults, you use the method
RaytraceResult is returned by the method, you dont create it
so no "new"
player.getWorld().rayTraceEntities(your parameters here)
does signs line count start from 1?
no, 0
Hey huge shout out to @eternal oxide who helped me with my first plug-in. Thank you so much!! 🙂
np
Can’t wait to play the game with it haha
Its going to confuse people for sure
I want to send Particles only to Players that have set there visibility in a way that they see the Players from whom the Particles originate from. To do that I have a List that contains all the hidden Players.
if (!hideList.contains(player)) {
loopPlayer.spawnParticle(Particle.HEART, player.getLocation(), 2, offsetX, offsetY, offsetZ);
}
Thats the code i use
It doesn't work. Any idea why?
I know for sure that the List is working as it should
public void update(int index, String text) {
scoreboard.getObjective(DisplaySlot.SIDEBAR).getScore(text).setScore(index);
}
is this how I should update a scoreboard line
is there a good way to pause a method few seconds?
wait()
no imports needed?
it says you cant cause it's static method
Get an Instance of you plugin and put the wait method onto that
Do not use wait()
oh
Do not use sleep(), unless its in a separate Thread.
If you wait or Sleep the main thread you lock up the server
i'm not sure what thread is or means 😭
so if i use those, a whole server waits for it?
If you need to run some code later use teh Bukkit Scheduler
i'm trying
lots of scheduler methods have a 'task' parameter, is any examples of how to write it?
new BukkitTask() { @Override public void run() {}} ?
yep
thx
if you .runTaskLater at the end you can schedule it to run
delay is in ticks, 20 ticks to a second
no
none
aha
they're the same thing
bukkit is a static wrapper of Server
using the Server one would be 1 ns faster i guess
if i want to put a plugin parameter, is it right that using my main(extends JavaPlugin)'s constructor?
huh
sry for my english i cant see huh is yes or no
No, your main has no constructor
you pass an instance of your main this to any class that needs it.
so new YourListenerClass(this);
it's in command's onCommand(...) method
?jd
package index
[ERROR] Could not pass event PlayerMoveEvent
@EventHandler
public void onMove(PlayerMoveEvent e) {
User user = Rusty.USERS.get(e.getPlayer().getUniqueId());
Distance distance = new Distance(e);
CheckResult speed = SpeedCheck.runCheck(distance, user);
if (speed.failed()) {
e.setTo(e.getFrom());
Rusty.log(speed, user);
}
}
hey guys, anyone know how to make an enchantment stay on a block even after it is placed?
@EventHandler
public void onWeatherChange(WeatherChangeEvent e) {
e.setCancelled(false);
}```
Can this stop the rain?
e.setCancelled(e.toWeatherState()); ?
you have to add a few functions first to make it stop raining
i want to make it always sunny
can anyone help?
@gleaming venture blocks can't have enchantments, but you can add some metadata to it and retrieve it later
@austere cove that might be exactly what I need! how can I go about doing that?
if (p.getInventory().getItemInMainHand().getType() == Material.FLINT){
if (target.getType() == Material.DIAMOND_ORE) {
target.setType(Material.STONE);
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
p.getWorld().dropItem(p.getLocation(), new ItemStack(Material.DIAMOND, 1));
}
}
```i dont know whats wrong with this and i dont get any errors
p represents the player
Certain Block types have a PersistentDataHolder.
would a chest be one of those blocks?
yes
yea I forgot not all blocks support it
chests do
TileState#getPersistentDataContainer()
.
you need to send a lil more of your code sir
i just have the diamond condition with more ores
everything is the same exxcept the materials
@EventHandler
public void onWeatherChange(WeatherChangeEvent e) {
World w = e.getWorld();
if (e.toWeatherState()) {
e.setCancelled(true);
w.setThundering(false);
w.setStorm(false);
w.setWeatherDuration(0);
}
}```
Is this good?
what event are you using, what isn't working exactly and did you (properly) register your listener
all the other code are working except this
send the whole code
yea if the other ones work and this one doesn't, it would be useful to show more code
its too long
?paste
btw just the method
ye checkin
Block target = e.getTargetBlock(p, 5);
OOf
lmao
i checked the code
you do
if (target.getType() == Material.STONE) {
if (target.getType() == Material.DIAMOND_ORE) {
}
}
there isnt e.getTargetBlock wtf
so it's actually unreachable code
my bad
also PlayerInteractEvent#getClickedBlock() is a thing
i didnt do that...
you do
i am not doing target.getType(), i am doing p.getInventory().getItemInMainHand().getType()
?services @topaz shale
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
could someone join my server and help me with a few things?
uh
Ah, ok
how could i make it so if i place a sign itemstack it will just set the lines?
like i tried this way https://paste.md-5.net/fidozudawo.cs
but i can't seem to make it work
set the lines in a runnable after the event is finished
how could i do that?
with a delayed task
use the BukkitScheduler
bukkit documentation: Scheduler Delayed Task
well at this point i decided to use the signchangevent, tho i also can't get this to work https://paste.md-5.net/ilodoxanop.cs
do the delayed task didint work?
i don't want to do that, also that would be not working completely? since it just gives time for the player to exit out of the sign GUI for the server to actually edit its data
as i understood
hm idk signs and editing signs is in my todo list
lamo
with commands.yml is there a way to set permissions for these custom commands
https://paste.md-5.net/araqediwos.java my code doesn't seem to be doing anything, what i'm trying to do is teleport everybody in the command senders world to them
what did i do wrong
Well well well what do we have here
if(p.getWorld().getName().equals("" + pWorld)); is never going to match. You are comparign a name to a world
o
register Command
huh?
No need to register the command as its in his main class
register the command?
It's in the main class. It's already registered
setExecutor i think
the command is already in the main class. It does not need to be registered
^
I see
lmao
how would i check the world name
i only want players in the senders world
line 26 you should be using cmd not label. I think its cmd.getNane()
#getName() ?
Just compare the world object
Does anyone know how to make custom weapons? Like not weapons that are changed from the ace or shovel. Like weapons / tools that are brand new.
@eternal oxide cmd.getName and label are the same thing
if p.getWorld().equals(pWorld)
No they are not. Label is the command precicely as entered and can be the alias
cmd is always the command thats in the plugin.yml
I always thought it was the other way around, for the longest time
U can just do that on onCommand method
Description Resource Path Location Type Command is a raw type. References to generic type Command<S> should be parameterized Main.java /tpworld/src/me/renndrew/tpworld line 24 Java Problem
You should also remove the suppression on raw types and instead fix any issue it shows
if (sender.hasPermission("e.perm")) {}
yeah
You have the wrong Command imported import org.bukkit.command.Command;
o
lmao
Thats minecraft stuff. Not Spigot
yea
?paste teh code you have now
if(p.getWorld().equals(pWorld));
p.teleport(pLocation);
p.sendMessage("§a§lSMPcraft » §aYou've been teleported to: " + player.getName());
}\
line 33 change the ; to a {
nice if statement
and add a close after the sendMessage line
if(p.getWorld().equals(pWorld));{
p.teleport(pLocation);
p.sendMessage("§a§lSMPcraft » §aYou've been teleported to: " + player.getName());
}```
or you could change it to if (!p.getWorld().equals(pWorld)) continue;
lol, you have the ; too 😛
ok i changed it and it didnt work
show how you changed it
if(p.getWorld().equals(pWorld)) {
p.teleport(pLocation);
p.sendMessage("§a§lSMPcraft » §aYou've been teleported to: " + player.getName());
}
}```
I meant his if statement was broken not saying the if statement looks cool
xD
that looks fine
It should not, you sure you compiled and uploaded the new jar?
oh there we go
weird
for(Player p : Bukkit.getOnlinePlayers()) {
if(!p.getWorld().equals(pWorld)) continue;
p.teleport(pLocation);
p.sendMessage("§a§lSMPcraft » §aYou've been teleported to: " + player.getName());
}```
Use this
looks better 😎
the one ya sent is okay but this is cooler
i forgot to reload 🤦♂️
lol
Reload 
lmfao
i always mess up on the simple bits
such as imports
or the most recent example: reloading 🤦♂️
player.sendMessage("2");
Location spawnLoc = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY() + 5 , player.getLocation().getZ());
RayTraceResult rayTraceResult = player.getWorld().rayTraceEntities(player.getLocation(), player.getLocation().getDirection(), 30, (entity) -> entity.getType() == EntityType.ZOMBIE);
spawnLoc.getBlock().setType(Material.GRAVEL);
FallingBlock fallingBlock = (FallingBlock) spawnLoc.getBlock();
player.sendMessage("3");
I get the first "2" but not the "3" something is wrong in between I cant find it tho
Errors?