#help-development
1 messages Β· Page 2204 of 1
iirc no
shit
its with constants
shti
shit
from stackoverflow
hopefully they implemented that by now
well if you do sth like
static final int SIXTEEN = 16;
static final int EIGHT = 16 / 2;
then obviously it uses 8 directly.
If you do stuff like this however
static final int SIXTEEN = 16;
static int half(int num) { return num / 2; }
static final int EIGHT = half(SIXTEEN);
then it definitely can't optimize it to bitshifts because it wouldn't work for negative "num"s
but there are signed and unsigned bitshifts
i think signed works for both negative and positive
hm no idea. but I wouldn't worry about it anyway. I mean how often are you ging to divide something? it's probably totally irrelevant for the overall performance in 99.999% of cases
well its every time for a chunk access
block access
then it's totally unnecessary to worry about it at all imho
what
how
Hello can anyone help me I have a server of spigot but after i updated the server to 1.19 it always shows (incomplete sets of tags received from the server) but my friends can join but I cant
it might happen a load per tick
No one replies over there
bitshift works on negative numbers
but in the wrong channel (this one) noone will reply as well
π
normally your CPU will use bit shifting anyway if possible
I have just tried it a few hundred times for one million divions and one million bitshifts and it's basically the same time for bitshifting or division
ok
sometimes bitshifting is a bit faster, sometimes division is a bit faster
np
anyone?
It's cuz of the new chat thing
If I install a custom resource pack with custom fonts, I can for example use this command /tellraw ANFFGaming {"text":"\uE000"} to show the fonts in the chat. How can I do the same with the plugin???
you can check tellraw's source code
and recreate it in your plugin
`
`
is there way to get string in string like f-string in python
python example:
avar = "some content"
print(f"> {avar}")
output:
> some content
thanks ash
thx i'll check it out
Player player = null;
ComponentBuilder builder = new ComponentBuilder();
TextComponent component = new TextComponent("My text");
component.setFont("fontname");
builder.append(component);
player.spigot().sendMessage(builder.create());
Ty, I ll go to try it now
hi, how do I make it so my plugin loads after every world has been loaded?
Doesnt apply PostWorld?
Doesn't work nope
yeah I tried that, doesn't work..
how do i check if a player is inside lava? similar to player.isInWater()
the problem with checking the block at player position is that the player can stand mostly on one block but still touch the lava to the side
yeah I already tested it, it's actually always POSTWORLD when you don't specify anything
If I declare a variable, will it be deleted after the execution of the last line of code of a class, or until the server restarts?
well if you censor the most important part, noone can help
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
you should learn about "variable scope" and the difference between instance, class and local variables
Actually, I know the concept, I don't know if in Spigot, will be the same, in theory if the var. isn't stored in the a persistent data place, you loose that after the restart.
Java's Garbage Collector managers what vars stay around and which ones are cleaned up
You don't have to worry about manually managing that
When the plugin disables you lose all vars the same as any other program. If you close the program its nolonger going to be holding onto any memory. So again like any other java program if the plugin is disabled ofcourse the variables will be gone. If you want stuff to stick around use a database or if its small identifiers use PersistentDataContainers
i think only need the warden turn...
I heard that the warden is a pain to modify
let's hope it's not ender dragon levels of pain
not sure.. i mean i dont usually work with BehaviorController and this things...
yeah im try to make a method to force the attack for my PR for methods in Warden
I feel like mojang will make all new mobs just use BehaviorController instead of pathfindergoals
might just be a new dev tasked with all of this tbh
Hi guys, I want to make a team system in which players on the same team can see each other with a glowing effect, but I don't want the other teams to see this effect. After some research it seems that I need to use packets but I do not handle them very well actually, anyone got a hint/a piece of code/a link to help me out ? mc version : 1.18.2
glowing is done via entity metadata
or the glowing potion effect but that's kinda meh
you can use GlowAPI if you really need to
Yeah but GlowAPI relies on PacketListenerAPI and it's not updated for 1.18 yet :(
Just a white glowing ?
yep
Well a solution with all the colors would be better if someone else know a way to do it
anyone know what plugin could possibly be adding $100 to everyone's account every 100 seconds because it's so annoying and we can't figure it out?
TimeIsMoney?
thats the thing I don't have that installed lol so idk what it could possibly be
or anything that runs commands on a timer
What was FriendlyByteBuf called in 1.16.5?
oh that would do the trick
why are you using Object
it accepts both NMS and bukkit entities and I can't bother making the same method twice
or couldn't, at the time
generics cry in the corner
yessir
xd
oh thats sad
i dont even know what those are π
ok i'll try that later and I'll let you know ^^
TL;DR - it would suck to make an individual method for each data type
fr
How can i use colored arguments in a command with bridadier?
https://i.imgur.com/O7cTEtw.png
event.getEntity().getWorld().createExplosion(event.getEntity().getLocation(), 6f, false, false, event.getEntity());
6f is power and power is explosion strenght?
yes
it handles block damage and entity damage
6f is wither explosion iirc
tnt is a 4
An explosion is a physical event, generally destructive, that can be caused by several different circumstances. It can destroy nearby blocks, propel and damage nearby players, entities, and their armor, and cause one or more fires under correct circumstances. Explosions produce a "shockwave" particle effect.
Multiple close explosions may propel ...
welp ig I'm an idiot then
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerBedLeaveEvent.html use this as argument
declaration: package: org.bukkit.event.player, class: PlayerBedLeaveEvent
public void functionName(PlayerBedLeaveEvent event) {}
oh thanks
working with minecraft client is defenetly harder than with server
yes
Huh, why Statistic.PLAY_ONE_MINUTE returns ticks???
because someone in the development team forgot to take their brain with them that day
what is that even supposed to return
playtime
^
yeah but
EXACTLY π€·
yea idk
fun tidbit, it used to be called play_one_tick, not play_one_minute
but it returns playtime in ticks
all those statistics have those shitty names
FLY_ONE_CM instead of FLY_CM or FLY_CENTIMETERS
yea its very weird
like noone would store the amount of TWO minutes played
I don't mind the shitty name, At least put the ****ing right messure
I want to make a logger plugin for all events. is there any easy way or I have to right all events?
you want to listen to all events?
Yes
well the only way to do that is to do some reflection magic
https://www.spigotmc.org/threads/listening-to-all-events-listing-all-events.337466/ heres some information about that
Alright. thanks
logging ALL events? oh boy you're gonna have a bad time
because you completed "play one minute" for x times. So it kinda would make sense. But not in ticks
BlockPhysicsEvent, RedstoneEvent, ...
umm, I just found it
YES, I remember how big of a pain forge was
I don't use forge
BlockPhysicsEvent
I have optifine
That's even worse
so bassiclly decompiled minecraft client
Im thinking of disabling some of the particle affects done by the warden when sonic booming, however i've never dived this deep into the spigot api so any suggestions on where to start? I've heard it may be something to do with packets
I know I have asked the question the 100th time but I think I have to ask again ,How to remove a goal from an entity
How can I send to different clickable messages in one chat line???
you can use bungee chat api
so what do you wanna know?
Sammu I'm not at my computer rn but is there a way to get the goals?
I told you to use a ComponentBuilder
?
I cant you new goals and edit it
this.targetSelector.addGoal(3, new NearestAttackableTargetGoal(this, Pig.class, true));
I saw a method to get list but it was 5 years old and not working
U need tognet the goals by reflection or if there is a method
U can't remove a "new" goal since you're creating a goal that the enitity doesn't have
can i block the player from executing any commands?
what's togent?
It worked, I forgot to add sth
Get the goal that you want to remove from the entity then remove it
To get *
HidePlayer
ohk
thats was the main reason why i asked
i was getting confused on how can i get it
Look in the entity class and see if there's a method that returns the goals
Or if there's a feild with the goals
Or whatever targetselector is
there are many methos but i suspect addBehaviourGoals
This is to register the initial goals im pretty sure
here all the goals are added
yah
i cant find any reutrn
can i block the player from executing any commands?
i think i need to check more properly
See where the goals are stored from adding
Playercommandpreprocessevent
thanks
there is a register goal but i dont think it gonna work
See how goals are registered and u can figure how to unregister
What is targetselector?
Yes i know but look deeper than that
See what that method does and the methods inside that method as well
Playing around with nms requires alot of digging around since it's undocumented
this.goalSelector.removeGoal(this.breakDoorGoal);
don't give the player the permission, remove the command from the command map, or cancel the CommandPreprocessEvent
U don't even need to look thru a list of goals then
Thats what i am saying form the starting
.
I didn't know it was a custom entity
wdym?
Overriding abstract method of abstract class
you can use lambdas for functional interfaces
public interface MyInterface {
void apply();
MyInterface SOME_IMPLEMENTATION = () -> System.out.println("Nothing");
}
It has only one
okay than you have to annotate it with FunctionalInterface
one sec let me check my update checker, it uses sth similar
I already found a mthod to do it but it gives out an internal error
Trying to use the java.util.logging.Formatter as lambda
ah no it must be an interface @tardy delta
Ah sad
Can't help then
I'll be able to when I'm home tonight
ok
can i have multiple commands in the same class
ok well then how can i access a hashmap from one command class in another
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
what was i doing lol
can someone help me in my thread?
else try {} π’
that it is doing those things when the class gets initialized
static means its constant through instances of the class
so same time when static variables are instialized
yeah as others said it's run when the class gets initialized. you can do it to run code related to your static fields like this
public class WhatEver {
private static final Set<Material> ALL_SHOVELS = new HashSet<>();
static {
Arrays.stream(Material.values())
.filter(mat -> mat.name().endsWith("_SHOVEL"))
.forEach(ALL_SHOVELS::add);
}
}
static { } is a constructor but for static stuff only runs once
Have a class just to handle the hashmap
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
And have a getter for an instace of that class in your main class
And use dependency injection to pass your plugin to the command classes
Itβs a record
no, records are final
smh
why do you need an abstract record?
Yea
can anyone help me with a design choice? I'm making a plugin and I am making wrapper classes for different types of items (enchantable items, ability items, consumables, etc.) and i want each one of them to have a static method to check if the itemstack you provide is that type of item (example, if the item has a certain nbt tag it will be a consumable). Any suggestions for a design i could use?
What have you got so far?
i think i messed up the di ```java
private final HashMap<UUID, Boolean> frozenDict;
public UnfreezeCommand(HashMap<UUID, Boolean> frozenDict) {
this.frozenDict = frozenDict;
}```
i have an abstract class with a basic validator (checks if the item is not null or air) and i was making a registry class with all the wrapper classes in a list
something i thought of is making the constructor throw exceptions if the item argument is invalid and making a method in the registry class that tries to construct with reflections the class and catches exceptions to tell if the item is valid or not
oh ok
And then inbthe brackets of ()
Put the map variable
So u give the map to your command
Don't change anything you had already
ok
Why does the method have to be static, won't you have one instace of the item class for each item?
Sounds good kill05
Just makenit abstract
Remember the direct values of your registries can always be facades providing access to your factories, observers and what not
what do you mean?
Ugh, do you know any design patterns? π
^
i should've googled it, right :p
umm Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
array indexes start at 0
oh yeh
your array has only one element so only array[0] exists
my brain is not functioning lol
I used this without even knowing it had a name
Same lol
yeah it's probably the most vague of all design patterns lol
Yes kill05 the most generic design pattern in Java in principle but itβs good to have formal names for all of these patterns, makes it easier to talk about design on a higher level
one could say "it's an object that combines other objects and how they work together" lol
Can I pass a global variable from one plugin to another?
U can
yup i agree
i often find naming classes problematic
How?
is Player#setWalkSpeed thread safe?
i missed one of the args[1] >:(
because i don't know how to express what does the class do
also, is Inventory#getItem thread safe?
No
Bukkit stuff aren't thread safe
quick question, does the player persistent data container survive restarts?
Yes
thanks
why do you need to access an inventory from another thread
There is no reason to multi-thread inventory access
it's not an expensive operation
The rule generally is bukkit stuff isn't going to be thread-safe\
I want to pass Hashmap. Any ideas how?
dependency injection
Pass it as a parameter in a consturctor or method
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Thnaks
?paste
what is vanilla walkspeed
anyways back to what i was saying, this is the abstract wrapper class https://paste.md-5.net/beromunuhu.java
1
thanks
and the child classes will implement the isValid method
if the isValid method returns false for an item, the constructor will throw an exception
Read access more or less so
But frequent read writes will not be thread safe by any means
kill05 why does it need to throw an exception?
i'm trying to figure out how to make a player look at an entity (trying to make a diologue thing) and i am having trouble with vectors. here is my code https://paste.md-5.net/kekuyovoco.cs
and i think the main problem is the error on line 6
idk how to get the .subtract to work
woah, 1 is way too fast
try 0.1 then
it might be 10% of what i said
1 might be 10 to essentials
its .2
so if i ever try to wrap the wrong item i will know before i start getting exceptions later on
interesting
well according to google its .2
and also so i don't write illegal data to an item's nbt
because let's say i try to wrap a consumable as an enchanted item by mistake and i don't notice
and then i try to enchant the item, the consumable will have illegal data on it
iirc yep that's the value
Hmm okay I would null return or use Optional upon invalid conversion
I am trying to use Fast Async World Edit API in my code, but when I try to install it through maven and write some code, upon compilation it says it cannot access some classes?
cannot access com.sk89q.worldedit.bukkit.BukkitAdapter
How would you start a raid wave through spigot?
should i use DateTimeFormatter or is there a newer class?
I'm directly using the constructors to create the wrappers, but if I made a factory class i could do that
Yes almost always use factory methods or classes
Itβs a so easy yet powerful way to decouple creation and instantiation
can I make the factory into a singleton or is that bad design?
i'm pretty sure i would start getting annoyed by having to dependency inject my factory instance everywhere
Why wpuld you need the factory everywhere?
static/singleton is usually fine for a factory
because i would need the wrappers very often
Ah ok
anything i do related to items/entities will be done trough the wrappers
tryna experiment different designs to see what i am comfortable with
is there somewhere online with some sorta javadocs for Mojang mappings
so I can actually find classes and methods for stuff yaknow
and also I assume that if I want to use Mojang mappings I will have to use that maven plugin that has been included in the dev section of update logs since 1.17
Or paperweight
Does anyone know a sound that sounds like turning a page or some sort of short "clicky" sound?
(Gradle)
I mean isnt there book and quills/ lectern sounds for pages
i guess there is a better way lol
UI_BUTTON_CLICK is a pretty nice one
Book turn page sound
how do i retrieve an actual entitytype from the registry (my custom entity) to use in it's constructor for an item spawn
ITEM_BOOK_PAGE_TURN
Registry.ENTITY_TYPE.get(keyThing) returns capture but i need the entitytype itself and i'm not smart enough for that
@iron glade ^^
Hi yβall, is there anyway to modify a particle packet to make the particle stay visible longer? From what I read itβs hard coded but I just want to make sure
i'm pretty sure the client handles the duration of particles
That sucks, thank you though! :)
you could just try making another particle
public NewMob(Location location) {
super(((CraftWorld) location.getWorld()).getHandle());
List targetB = (List)getPrivateField("b", NearestAttackableTargetGoal.class, targetSelector);
targetB.clear();
this.setPos(location.getX(), location.getY(), location.getZ());
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, Player.class, false));
this.targetSelector.addGoal(3, new NearestAttackableTargetGoal(this, Pig.class, true));
this.goalSelector.addGoal(2, new AvoidEntityGoal<Creeper>(this, Creeper.class, 1.0f, 1.0, 1.0));
this.goalSelector.addGoal(2, new PanicGoal(this, 1.0d));
}
public static Object getPrivateField(String fieldName, Class clazz, Object object) {
Field field;
Object o = null;
try {
field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
o = field.get(object);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
return o;
}
return o;
}
This code is suppose to get the list of the goals of my custom entity and clear it but instead it gives internal error
returning o in any case /shrug
?
Are you sure the field name is correct
the internal error being?
?paste
yes
How do i parse urls in java? I need to parse mongo and redis url
It's final
what final?
U can't set it cuz it's final
so that means there is no hope now?
I feel like you're going about this the wrong way
You can set a field to no longer be final
Minion, do you know how i can parse url like does mongo or redis?
What?
Yeah let say i have the url: "mongodb://username:password@host:port/route"
I donβt understand what you mean by βparseβ it?
I mean Mongo and redis allows you to connect via a URI directly afaik
You donβt need to parse it and extract the credentials yourself
Im needing to find a way of reading let say the hot, port, etc
I know i just want to design my own url that why
hi i have a question i wanna make soemthing when you shoot an arrw the console sends a message tot that player with the cordinates of that arrow
This would be helpful https://docs.oracle.com/javase/7/docs/api/java/net/URI.html
Oh thanks, im using that but i cannot find the method for parsing the password
//dont actually use
int separator = input.indexOf("://");
String dbProvider = input.subString(separator);
int colon = input.indexOf(":");
String username = input.subString(separator, colon);
int at = input.indexOf(...)
Allright
does all of it for you
Thi should be for parsing password and username rigt?
Thanks to the too of you
listen to ProjectileHitEvent, get the shooter of the arrow, then send a message
mfalex, is open source your http client?
can you maybe send a ittle bit of a beginning code becouse im not new but wanna learn more about java
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
thx
Imagin so:
URI bla = URI.create("custom://username:password@host:port");
String[] auth = bla.getUserInfo().split(":");
String user = auth[0];
String pass = auth[1];
do you ever listen to what i say
like not even being mean
i dont even think you need the username:password
well
i think authority takes that in
so you dont have to worry about that
no need to split anything
kms
"user:pass@localhost:6379" that what return getAuthority()
weird
How do I change network ID of an entity ideally without ProtocolLib? I just want to make my custom entity a different entity to clients but I can't find anything on this specific topic
the "authority" is the full string
Nor can I find anything in NMS itself about it
without the path
Probably just bad at looking but if someone can point me at where to look in NMS to learn I'd appreciate it
URI uri = URI.create("custom://username:password@jeff-media.com:25565/location");
System.out.println("Authority: " + uri.getAuthority());
System.out.println("Path: " + uri.getPath());
System.out.println("Host: " + uri.getHost());
System.out.println("Port: " + uri.getPort());
System.out.println("UserInfo: " + uri.getUserInfo());
this prints out this:
Authority: username:password@jeff-media.com:25565
Path: /location
Fragment: null
Host: jeff-media.com
Port: 25565
UserInfo: username:password
Allright
you'd have to listen to outgoing packets. why do you want to change the ID in the first place?
mfalex, also client can display non minecraft entity?
because i'm stupid is probably the main reason
i was able to register my entity so I thought hey, why not just pass that to superconstructor
means it saves, reloads, loads, etc. all perfectly fine without janky workarounds like changing the ID on save
i know the normal way to do things is pass a different entitytype to superconstructor (matching the class it extends) so it shows like that to clients
but i didn't like the janky workarounds purely subjectively so i thought i'd make things harder for myself
π
idk probably you'll get an error message like "unknown entity type" on the client
just shows as a pig
oh or that
yup
it's weird that pig is the default entity lol
Hey guys! Was just wondering if anyone could help me with this...
So I'm using the InventoryClickEvent alongside a InventoryType.ANVIL Inventory Menu.
The inventory is opening all fine, but I'm basically struggling with getting the Display Name of the item in the 3rd Slot, e.g. the final slot. However when trying to print out the DisplayName value it is returning the original name of the item in that slot. Also to clarify, I am setting a NameTag to both Slot 0 and Slot 2 with the name "Rename Me" and when printing out the value even after changing it in the Anvil GUI it is returning "Rename Me".
if (i.getView().getTitle().equalsIgnoreCase("Alliance Creation")) {
if (i.getSlotType() == InventoryType.SlotType.RESULT) {
Bukkit.broadcastMessage(i.getCurrentItem().getItemMeta().getDisplayName());
i.setCancelled(true);
player.closeInventory();
gui.add(player);
}else{
i.setCancelled(true);
}
}
``` here's the code alongside a few screenshots
im assuming for specifically a minecart from the packet list i'm reading - i need to modify Entity Spawn and Passenger packets but everything else should be fine?
I have no idea, as said I never really did any custom entities
I don't really understand the problem you're having
pls try again to explain
- what you want to do
- what happens instead
So as you can see in the screenshot. I basically want to get the DisplayName of the item after I click the 3rd slot, however, it is instead just returning the default name which is just "rename me"
I endup with this code, if someone want to do something similar in the future then you can use it
URI uri = URI.create("scheme://user:pass@localhost:6379/db-name");
System.out.println("Scheme: " + uri.getScheme());
System.out.println("Host: " + uri.getHost());
System.out.println("Port: " + uri.getPort());
System.out.println("Username: " + uri.getUserInfo().split(":")[0]);
System.out.println("Password: " + uri.getUserInfo().split(":")[1]);
System.out.println("Database: " + uri.getPath().split("/")[1]);
- I want to retrieve the DisplayName of the item in the 3rd Slot after changing it via the Anvil GUI.
- When retrieving the DisplayName of the item in the 3rd Slot it is receiving the DisplayName "Rename Me" rather than the Display Name "Rename Medasd" as seen in the Screenshot. So basically it appears the event isn't updating the item meta as I'm changing it simultaneously in the GUI
Hopefully that makes sense
yeah that makes sense. Hm can you send your current code? Because that should work fine from what I guess
the full code of your listener
ah ty sorry
Inventory inv = Bukkit.createInventory(null, InventoryType.ANVIL, "Alliance Creation");
ItemStack invitem = new ItemStack(Material.NAME_TAG);
ItemMeta meta = invitem.getItemMeta();
meta.setDisplayName("Rename Me");
invitem.setItemMeta(meta);
inv.setItem(0, invitem);
inv.setItem(2, invitem);
player.openInventory(inv);
``` here's the command to open the GUI
if (i.getView().getTitle().equalsIgnoreCase("Alliance Creation")) {
if (i.getSlotType() == InventoryType.SlotType.RESULT) {
Bukkit.broadcastMessage(i.getCurrentItem().getItemMeta().getDisplayName());
i.setCancelled(true);
player.closeInventory();
gui.add(player);
}else{
i.setCancelled(true);
}
}
Here's the InventoryClickEvent
Yeah lol π Usually I do 'E' instead of 'I' but because it's to-do with Inventory I did 'I' lol
not even e
no idea, from what I see it should be working fine. might have something to do with the fact that you set both slots to the same item. try to do
inv.setItem(2, invitem.clone());
Also, when asking for support always send full code
why having to clone the item again?
Unfortunately the same thing
okay let me try sth
Because if I only set it to the first slot, when clicking the 3rd Slot it returns the item as null
So something funky is happening π
hi there
I'm very new to this and i'm trying to understand how things work, and i encountered my first "issue"
I'm pretty sure it's a logical error
Integer XCoord = event.getBlock().getX();
if(XCoord < 50){
Player player = event.getPlayer();
player.sendMessage("X = " + XCoord);
The intent = if a block is places when the x coordinate is above 50 it sends a message specifically to the player which states the X coordinate
however it won't seem to work, no errors
Also dont use Integer, use int
makes a difference ?
Silly question, but have you registered the command/event
its an event
one moment
here
public void BlockPlaces(BlockPlaceEvent event){
int XCoord = event.getBlock().getX();
if(XCoord < 50){
Player player = event.getPlayer();
player.sendMessage("X = " + XCoord);
}
}
pretty much the full code
That wrong
except the class
You are missing the annotation @EventHandler
Do you have @EventHandler above that?
That the reason
I do that just by write @eventhandler ?
@EventHandler
thanks
Like that using capitalls
also if you don't mind me asking
whats the difference if I write Integer or Int
Honestly wrote it bc it was the thing that came up, not because I write integer
but nonetheless thanks :)
int*
int yes my bad
you need an AnvilInventory. Unfortunately you cannot cast a custom inventory to an AnvilInventory. I'll look through some CraftBukkit classes to see if I find something
Hmm interesting, thank you! All I basically wanted was the player to be able to name something via this GUI, as I'm pretty sure I've seen it in other plugins before. I really appreciate you for helping with this, let me know if you get it to work π
you can definitely do it with NMS but it's messy. I'm sure there must be another way
@prisma steeple https://www.spigotmc.org/wiki/using-the-event-api/
I found this, but couldn't figure out how to do it
Thanks :)
yeah that's simply using NMS
are you using maven?
does anybody know a good spigot tutorial for intelij for begginers
int is a primitive datatype and can only hold numbers
Integer is the corresponding class that can also hold null (not 0) values
That's also why you use it in maps and lists
and for generics
Yep I believe so. I managed to link into the API of AnvilGUI but couldn't figure out how to use it properly
do you have a pom.xml file?
Yep
If you need help with AnvilGUI hit me up
Oooh π
.
then you can add the the stuff mentioned in "Usage -> As a dependency" to your pom.xml, click the maven reload button, and then mess around with the AnvilGUI.Builder to build your custom anvil inv
eh- my code still seems to not be working
I should use the AnvilGUI.Builder in my Command Class right?
yeah
just like before, nothing happens
and then you can provide a BiFunction to the onComplete method
why is the @EventHandler so far away from the Event xD
@EventHandler
public void BlockPlaces(BlockPlaceEvent event){
int XCoord = event.getBlock().getX();
if(XCoord < 50){
Player player = event.getPlayer();
player.sendMessage("X = " + XCoord);
}
}
i have no idea, i will arrange it
Out what the issue?
did you register the event
the main issue is me not exactly knowing how it works if anything
However i don't see anything wrong with this code
Which code?
I feel not enough
package com.outletserver;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class ChunkLoad implements Listener {
@EventHandler
public void BlockPlaces(BlockPlaceEvent event){
int XCoord = event.getBlock().getX();
if(XCoord < 50){
Player player = event.getPlayer();
player.sendMessage("X = " + XCoord);
}
}
}
this code
this is not working
it should work
oh wait, it seems like the AnvilGUI doesn't even have a method to set the result item lol
I am at X27 placing a grass block
show your onEnable in your main class
yes
method names start with a lowercase letter smh
yeah that's unfortunate
that's the one thing that annoyed me like hell
I know
Jut copy-paste what he ent
then do it >-<
Its not my event
Oh... ermmm
Its him/her even t
his/her*
did you register the listener in your onEnable
Yes sir, soy espaΓ±ol that the problem
pas de probleme mon ami
Haha no problem
I think sth like this should work
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
ItemStack myNametag = new ItemStack(Material.NAME_TAG);
ItemMeta meta = myNametag.getItemMeta();
meta.setDisplayName("Rename me");
myNametag.setItemMeta(meta);
new AnvilGUI.Builder()
.itemLeft(myNametag)
.plugin(this)
.onComplete((player, name) -> {
Bukkit.broadcastMessage(name);
return AnvilGUI.Response.close();
}).open((Player) sender);
return true;
}
yes, i think i did it well
hold on
public void onEnable() {
System.out.println("hi!");
Bukkit.getPluginManager().registerEvents(new ChunkLoad(), this);
}
public void onDisable(){
System.out.println("Server off");
}
}
(although not needed for it to work)
yes
what does override do
is your plugin.yml setup properly?
nothing, besides throwing a compile time error if you misspelt onEnable or whatever method you wanna override
i mean, there isn't necessarily much supposed to be in there right?
main: com.outletserver.myfirstplugin
name: Plugin1
version: 1
this is what is in there
ahh okay
what's your main class called?
myfirstplugin
okay
that's a weird class name
which version are you coding against?
[20:55:55 INFO]: RocketManKian issued server command: /alliance create
[20:55:55 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'alliance' in plugin AllianceTag v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[purpur-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:172) ~[purpur-api-1.18.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_18_R2.CraftServer.dispatchCommand(CraftServer.java:906) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.server.network.ServerGamePacketListenerImpl.handleCommand(ServerGamePacketListenerImpl.java:2389) ~[?:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl.handleChat(ServerGamePacketListenerImpl.java:2200) ~[?:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl.handleChat(ServerGamePacketListenerImpl.java:2181) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundChatPacket.handle(ServerboundChatPacket.java:46) ~[?:?]
at net.minecraft.network.protocol.game.ServerboundChatPacket.a(ServerboundChatPacket.java:6) ~[?:?]
at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:51) ~[?:?]
at net.minecraft.server.TickTask.run(TickTask.java:18) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1426) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:188) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1403) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1396) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1374) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1256) ~[purpur-1.18.2.jar:git-Purpur-1628]
at net.minecraft.server.MinecraftServer.lambda$spin$1(MinecraftServer.java:320) ~[purpur-1.18.2.jar:git-Purpur-1628]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.NoClassDefFoundError: net/wesjd/anvilgui/AnvilGUI$Builder
at me.rocketmankianproductions.alliancetag.commands.AllianceTagCommand.onCommand(AllianceTagCommand.java:110) ~[AllianceTag.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[purpur-api-1.18.2-R0.1-SNAPSHOT.jar:?]
... 21 more
Caused by: java.lang.ClassNotFoundException: net.wesjd.anvilgui.AnvilGUI$Builder
at me.rocketmankianproductions.alliancetag.commands.AllianceTagCommand.onCommand(AllianceTagCommand.java:110) ~[AllianceTag.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[purpur-api-1.18.2-R0.1-SNAPSHOT.jar:?]
... 21 more
``` hmmm
wdym?
you did not shade the anvil gui. it's explained on the github page in the "as dependency" section
or you didnt use maven to build your plugin
API version.. like.. 1.18?
try just sending a message without any of the conditions just to make sure the listener is registered properly
alright
i will do that too
anything in the console when loading the plugin?
it literallytold me what you told me to do
"did not specify API version"
should've read the console
that's no problem
it would still work
that's just a warning to inform you that your plugin is the reason for legacy material support being enabled
Just tried to shade it, still didn't work unfortunately. I'm pretty sure I'm using maven to build it? How do I check just to make sure
m, makes sense
what do you do to compile the plugin?
so if i specify it won't need to enable it
anything else in the console @prisma steeple
uh
Build -> Build Artifacts -> Build
The
iirc it enables it if your plugin is < 1.13
Server permissions file permissions.yml is empty, ignoring it
yeah that means you're not using maven. On the upper right, click on maven -> double click on package
the most beautiful button
[22:00:04] [Server thread/WARN]: Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!
[22:00:08] [Server thread/WARN]: Legacy plugin Plugin1 v1 does not specify an api-version.
[22:00:08] [Server thread/INFO]: [Plugin1] Loading Plugin1 v1
[22:00:08] [Server thread/INFO]: Preparing level "world"
I love how everyone uses the weird minecraft development plugin and gets a pom but never use maven to actually compile anything
hmm, i did this
still doesn't send anything
java.lang.IllegalArgumentException: Unsupported class file major version 60
public class ChunkLoad implements Listener {
@EventHandler
public void BlockPlaces(BlockPlaceEvent event){
Bukkit.broadcastMessage("Test");
what version is your "maven-shade-plugin" set to?
it should be 3.3.0
It's 3.2.4
set it to 3.3.0
there you go
still nothing?
?paste your full console log
?paste
is the bot offline?
bruh
Bot no ):
It worked! Legend. Just one thing... is there a way to change where Maven saves the jar to?
ye
Yeah its definetly down
the plugin is activated
yep
Any plugin that you know that have a "plugin-jar" and then separate the "plugin-jar-api" for that plugin?
<configuration>
<outputfile>PathToSave</outputfile>
<configuration>
yeah sure
one sec
does anybody know a good starting tutorial for making a project in intelij
@tender shard could you have a quick look at my POM? i have the feeling something's wrong there
sure
why? π
<exclusions>
<exclusion>
<artifactId>FastAsyncWorldEdit-Bukkit</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
this is basically useless
it's scope provided anyway
that's copied from their site
triumph-gui doesn't have a scope set
idk why tbh
Hmmm... doesn't seem to be working. But it's not giving any errors or anything. It just keeps saving into my IdeaProjects folder
send your full pom
?paste
RIP bot
yeah you didnt read my blog post correctly
why is spigot SO eazy?
the configuration for the output must go inside the maven-jar-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<outputDirectory>C:\mctest\plugins</outputDirectory>
<finalName>MyAwesomePlugin</finalName>
</configuration>
</plugin>
searching in minecraft decompiled client code is hard as fu**
@tender pond
Hello there! Im kinda new in the spigot plugin development.
I have a problem with detecting a player right clicked another player with a specific item.
I know the two events PlayerInteractEvent, PlayerInteractEntityEvent but i dont know how to link them each other.
public void onPlayerSelect(PlayerInteractEvent event, PlayerInteractEntityEvent e) {
if (event.getAction().equals(Action.PHYSICAL) && event.getItem() != null && event.getItem().getItemMeta().equals(ItemManager.telegem.getItemMeta())) {...}
I tried this but I got an error
[22:06:13 ERROR]: [Hg-Core] Hg-Core vBeta-1.0.1 attempted to register an invalid EventHandler method signature "public void hu.hugaming.hgcore.events.teleportGem.onPlayerSelect(org.bukkit.event.player.PlayerInteractEvent,org.bukkit.event.player.PlayerInteractEntityEvent)" in class hu.hugaming.hgcore.events.teleportGem
I actually did this initially but it's red, and it doesn't go away
you cannot declare two events to listen to in one method
maven-jar-plugin(!!)
Even after Loading Maven Changes
I know...
now maven-compiler-plugin
just create your own method where you pass the required arguments to
Do I have to worry that I don't have a maven jar plugin in my pom?
?learn-spigot-api momment!
remove the 2nd
On listener, 1 method listen to 1 event
Ahh, I don't seem to have that in my Pom do I have to custom add it?
Nvm it says that on the Blog post
My bad
public void myMethod(ItemStack item) {
...
}
@EventHandler
public void onFirstEvent(SomeEvent event) { myMethod(event.getItemStack()); }
@EventHandler
public void onAnotherEvent(AnotherEvent event) { myMethod(event.getItemStack()); }
@cerulean charm
you just add it to your <plugins> section
You're a life saver thanks!!!
np
Worked thank you!
trying to use Scoreboard teams for Prefixes but im 100% doing something wrong idk what tho
Hey guys! Basically I got some soft-dependencies and from any reason my plugin is loaded before the actual dependencies
what theme are you using?
no, thats loadbefore
π
explanation of softdepend: A list of plugins that are required for your plugin to have full functionality.
Your plugin will load after any plugins listed here.
But I dont really know why it doesnt work
One sec
I dmed a guy something that works
that's weird
why does attempting to retrieve the color from PotionMeta from a valid
potionmeta result in a nullptr error
I knooow
@humble tulip dm me that lol
@undone axle
specified the exact name?
yes
that they specified in their plugin.yml
beep boot I am a bot: https://paste.md-5.net/
its being loaded before ModelEngine
Ty
PotionMeta meta = (PotionMeta) potion.getItemMeta();
this.red = meta.getColor().getRed();
this.green = meta.getColor().getGreen();
this.blue = meta.getColor().getBlue();
```from a valid Potion ItemStack, why does this result in a nullptr error in the console log?
which part
Does it have a color?
Plugins should check that hasColor() returns true before calling this method.
but potions always have colors dont they
declaration: package: org.bukkit.inventory.meta, interface: PotionMeta
apparently not
where do vanilla potions get their color from then?
okayive just used hasColor
apparently vanilla potions have no color?
why not lol
how can i do something async, and then when its done doing the task have all data in the class be synchronized immediately
imagine if i have a class
class Data {
boolean loadComplete;
int x, y, z;
void loadAsync() {
threadPool.execute(() -> {
// do some expensive loading task
// now i want to synchronize all the data
loadComplete ();
});
}
synchronized void loadComplete() {
loadComplete = true;
}
}
how do i cast an integer to a double? blind casting isn't working
(double)
yea i tried that
(double) urint
double d = (double) whatever
u need to use the constructor if ur using complex classes
set the fields in the loadcomplete method i guess
And what if i want to check them both? The player holding the item and right clicking onto the other player?
bruh but then the data is gone
i dont want to synchronize all accesses
what Β―_(γ)_/Β―
anyways if i wanted to get some annotation with #getAnnotation what retentionpolicy does it need to have?
CLASS i think
public void BlockPlaces(BlockPlaceEvent event) {
Player player = event.getPlayer();
if i have this
and 2 people place a block
what happens
nothin
two different events are fired
Ahh when you explain it like that it makes much more sense
that player variable refers to the player who played the block
is that even annotated with EventHandler?
and will be executed for each blockplace
Yes
It's also single threaded so 2 ppl can't place a block at once
no i mean it when that variable is taken up
Ohhh
and someone else places a block
That what makes the game really laggy
you can get the annotation from classes, methods and fields. The retentionpolicy has nothing to do with whether you can get it via reflection or not, or am I misunderstanding your question?
no i just started with this and im noob
if a class is annotated, you can use Class#getAnnotations(). If a field is annotated, you can use Field#getAnnotations(), etc
ye but whats the retentionpolicy then?
oh that's what you mean
"how long the annotations are to be retained" doesnt tell me much
erm tbh not sure. SOURCE is definitely not visible anymore, I think for CLASS it's kinda unspecified. It simply says "need not be retained by the VM" but not that it will definitely discarded
Hey guys can anyone help with this? I'm very confused... So I'm basically getting a string and sending it through this system, and just to confirm I'm posting the string to make sure it's 100% correct before this if statement.
So for some reason this is entering the if statement even when only using Letters and no numbers for some weird reason, and I have no clue why as I'm pretty sure the regex works
I think to access them with reflection you definitely need RUNTIME
Why using Bungeecord chat color?
lets find out
Honestly not sure, it just tab completed into that π I'll change now
is it possible to send the player turning red death animation when the player hasnt died?
Allright, because that can cause issue
how to get player XYZ levels
Yep still not working unfortunately
i think i need runtime ye
just use [a-zA-Z]
then it'll work
Does that block special characters too though? Cause I need to block special characters
it will only return true if the string consists of NOTHING besides normal a-z and A-Z
Hmm... still nothing π
"2asd".matches("[a-zA-Z]+") -> false
"âÀü".matches("[a-zA-Z]+") -> false
"asd".matches("[a-zA-Z]+") -> true
I just tested this
Would including it in the AnvilGUI.Builder thing affect it?
Cause I'm basically including it under the .onComplete() thing
Any simple code for genereting random codes with numbers and letters?
it might contain color codes. print out the string or run it through ChatColor.stripColors
cast the return type of the random next int to a char and concatenate them or smth
Yep I already am, it's coming out White
Will strip colors just to make sure though
bump
Still not working
Omg I've just realised what caused it... spaces π
π
Really thanks
How would one start a raid in the spigot api?
or write it yourself
private static final char[] CHARS = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
public static String getRandomString(int length) {
char[] chars = new char[length];
for(int i = 0; i < length; i++) {
chars[i] = getRandomChar();
}
return new String(chars);
}
private static char getRandomChar() {
return CHARS[ThreadLocalRandom.current().nextInt(CHARS.length)];
}
Oh ok
there doesn't seem to be a way
What yor issue?
what is that supposed to do btw?
what is a PacketType.Status.Server.OUT_SERVER_INFO ?
Allright, if doesnt work jut wait until somene help, open a thread on this channel or ask on ptclib discord
I cannot send their discord link
Ok
1 sec
why do you use protocollib for that
declaration: package: org.bukkit.event.server, class: ServerListPingEvent
RIP
it also exists in 1.12.2
you can
I know
that's from the 1.12.2 javadocs
ugh well this is from 1.19, I wonder why it exists if it's always just throwing an exception
very weird lol
all the Player.Spigot methods are throwing an unsupportedexception too arent they?
me too lol
nooo
Player.spigot() is for example to send basecomponent msgs
that method is overriden when is called in NMS
i remember when make the PR for support the hide player info for ping things...
huh why so complicated
not sure why...
sounds confuse but that is how works..
hey guys I've been struggling at finding a working answer on how to do tool durability
creating a class in a method brr
cast the ItemMeta to Damageable, set the damage, then set back the itemmeta
then hover over it and read it
it cannot resolve the method
which method?
setDamage
wrong import
you imported org.bukkit.entity.Damageable
but you have to import org.bukkit.inventory.meta.Damageable
is this done correctly?
ItemMeta tempPick = inHand.getItemMeta();
(Damageable) tempPick.setDamage(tempPick.getDamage() - 1);
inHand.setItemMeta(tempPick);```
no, that's not even valid syntax
Damageable meta = (org.bukkit.inventory.meta.Damageable) inHand.getItemMeta();
meta.setDamage(meta.getDamage() - 1);
inHand.setItemMeta(meta);
when casting do I have to put the whole import?
na
I imported it at the top
only make sure you got yhe right one
it's this one :)
maybe I'm doing something wrong
instead of taking damage it just repairs the item?
damage goes up not down. 0 = no damage
so should I add instead of subtract?
setting a negative damage wouldnt make much sense for me
idk if it works like that but ye
I want it to just be as if the pickaxe mined a block
but I have to cancel the event so it's not taking damage
ok it works
thank you guys
I just tested and it kind of works
it bypasses unbreaking enchants
then you have to do sth more complicated
how would I go about doing it?
otherwise you'd be ignoring vanilla and/or custom enchantments, etc bla bla
where is JeffLib.getRandom() defined?
it's just an instance of Random
just do ```java
private static final Random random = new Random();
np
:3
Or simple use gson
gson will not serialize a Location
Both require additional steps to serialize
So just use teh one thats already coded for you in Bukkit
yes
was able to figure out stuff from earlier :) custom entity using its own id that client sees as a minecart π
just feels a bit less janky than the workarounds to respawn a custom entity
no idea if it's more practical or can do anything the ones using another's ID/EntityType cant
if you correctly implemented CS and did as teh Javadoc says and register your Class.
In addition to implementing this interface, you must register the class with ConfigurationSerialization.registerClass(Class).
in your onEnable, or anywhere before you attempt to read from yrou config
nope
better in onLoad. otherwise you'll get problems when the config gets loaded, because that happens before onEnable IIRC?
that is the data you are going to build your object with
yep
no
public class Person implements ConfigurationSerializable {
private final String name;
private final int age;
public Person(final String name, final int age) {
this.name = name;
this.age = age;
}
@Override
public Map<String, Object> serialize() {
Map<String,Object> map = new HashMap<>();
map.put("name",name);
map.put("age",age);
return map;
}
public static Person deserialize(Map<String,Object> map) {
String name = (String) map.get("name");
int age = (int) map.get("age");
return new Person(name, age);
}
}
and in your onLoad:
ConfigurationSerialization.registerClass(Person.class);
Location is already serializable so you can use map.put("location", location.serialize())
you can also just put in the location directly
no need to call serialize
um, true, it will be retained as an object and serialized when needed
actually if you use serialize() yourself then it will be stored as map so you won't know what to deserialize it to again
because it will be missing the "==" field in the yaml or whereever it is stored
oh yeah
So quick question, does anyone here use sth like
(++i)++ as opposed to i+=2
