#help-development
1 messages ยท Page 2261 of 1
Performance
?!?!
Obviously use hasItemMeta when you dont access the meta
Also you're talking microseconds of performance
it doesnt matter
ItemMeta#clone is a pretty expensive call
๐
We are talking in dozens of ฮผs
ItemStack#equals can be discarded anyways
Huh
Im redoing a plugin i madea while back basically from scratch
I need to generate a spawner with certain parameters as PDC values
Should i make a static class that has methods to generate that?
Also i have a bunch of namespaced keys. I have no idea what to name the class or package to put them in
Most items are CraftItemStacks, which has a different impl for that
How can i make an npc teleport randomly to any player? (in a volume defined by me, that volume would be the map i have)
npc.teleport(randomPlayer.getLocation())
?scheduling
Ok, since everyone is ignoring my previous messages. New question
I have a "DataManager" class that has methods that saves the dataconfig and all the file work. Then i have a "Data" class that is mapped into a file as the config (gotten with getConfig()). Should i use plugin.getDataManager().getConfig() or should i save object holding the config in my plugin class to do plugin.getConfig()
Maybe im overcomplicationg this
It's more logical to keep the Data getter inside the DataManager class. Cause it can cause some issues if you do not use a singleton object
Otherwise change your whole structure
Thank you
thats what i did
@lost matrix
public class Data {
private final Map<UUID, String> playerListMap = new HashMap<>();
/**
* This method is used to get a clone of a players items from the config
* @param playerUUID The target players UUID.
* @return Returns clone of players items.
*/
public List<ItemStack> getPlayerItems(UUID playerUUID) {
if (!playerListMap.containsKey(playerUUID)) {
putPlayerItems(playerUUID, new ArrayList<>());
}
return List.of(SerializationUtils.deserialize(playerListMap.get(playerUUID)).clone());
}
/**
* This method simply puts the players items into the hashmap saved into the config
* @param playerUUID The target player.
* @param items The target playuers items.
*/
public void putPlayerItems(UUID playerUUID, List<ItemStack> items) {
playerListMap.put(playerUUID, SerializationUtils.serialize(items.toArray(new ItemStack[0])));
}
}
I have spent an hour on this ๐ but its the most beutiful looking code i have ever written
heyho, i have a question. how do i catch out the nullpointerexeption when im asking for a location for a String what didnt got one at the moment?
public List < Location > getFdoorLoc(String frak) {
List < Location > savedLocs = new ArrayList < Location > ();
for (String locationID: data.getConfigurationSection(frak).getKeys(false)) {
savedLocs.add(new Location(Bukkit.getWorld(data.getString(frak + "." + locationID + ".world")), data.getDouble(frak + "." + locationID + ".x"), data.getDouble(frak + "." + locationID + ".y"), data.getDouble(frak + "." + locationID + ".z")));
}
return savedLocs;
}
that spacing
lol
i wanna request locations for stringst who didnt got one
and it throws nullpointerexeption
return List.of(SerializationUtils.deserialize(playerListMap.getOrDefault(playerUUID, new ArrayList<>())).clone());```
my english is bad
Thats fair
seems very conflated though
whats getOrDefault do?
german schools dont teach good enough for it
i thought it was like a southern american thing
but anyways im trying to get a location for a String like mex what didnt got any location at the moment
and i know its returning null
so i wanna catch it so i dont get a nullpointer
gets the object from the map or if null inserts and returns the default
nah german school system is pretty bad
Makes teh code above it redundant
got it
oh wait
shit
you just pointed out a big whoopsie on my part
thank you for showing me that, but in this case that wont work
Cause its not a array its a serialized array stored in a string
yep
So i should check
If it doesnt have the key
And then make a new array and return that
yes
If false
you can still use getOrDefault
wait
you might be right
i might be stupid hold up
Yea no getOrDefault wouldnt work here
i dont think
public List<ItemStack> getPlayerItems(UUID playerUUID) {
if (!playerListMap.containsKey(playerUUID)) {
return new ArrayList<>();
}
return List.of(SerializationUtils.deserialize(playerListMap.get(playerUUID)).clone());
}
that would be what would work
And since im cloning the existing value
It doesnt matter that the new value is a new array
Cause i will have to use putPlayerItems() anyway
Unless you have a way of optimizing that
@eternal oxide Thoughts on saving namespacedkeys in my main class like this?
public class BetterSpawners extends JavaPlugin {
public final NamespacedKey ENTITY_TYPE_KEY = new NamespacedKey(this, "bs.entityType");
public final NamespacedKey MULTIPLIER_KEY = new NamespacedKey(this, "bs.multiplier");
public final NamespacedKey MINED_KEY = new NamespacedKey(this, "bs.wasMined");
public final NamespacedKey OWNER_KEY = new NamespacedKey(this, "bs.ownerName");
public final NamespacedKey XP_KEY = new NamespacedKey(this, "bs.xpAmount");
public final NamespacedKey LAST_GEN_KEY = new NamespacedKey(this, "bs.lastGen");
You literally push an empty array if there is no entry for the player
Cant think of a better place lmao.
yed
Am i stupid?
so just do the same, push an empty array with getOrDefault instead of pushign an empty one first
Maybe im not understanding how getordefault works
ye
if there is no entry you don;t add one, you just return an empty List
Yed
then you are correct
thats a first
Mine would bloat teh data with empty arrays using getOrDefault
thoughts?
BetterSpawners.KEYS.ENTITY_TYPE_KEY
you can pass a plugin reference to a static class
How?
Y the BetterSpawners before KEYS?
Assuming KEYS is a class?
What would be the specific event to make an npc teleport? and these, (the npcs) are entities and not players I guess, right?
?paste
?
Step 1: Realize you can cancel events
Step 2: Find PlayerQuitEvent
Step 3: 
hes helping me out and hes writing beeg code
and hes using a paste to be nice
Oh ok
is that how static is supposed to be used?
yes
Oh ok
constants
thank you so much for that
Should KEYS be final?
no
You'd not be able to assign it if it was
public static Keys KEYS;
public BetterSpawners(){
KEYS = new Keys(this);
}
public class Keys {
private static BetterSpawners plugin;
public Keys(BetterSpawners plugin) {
Keys.plugin = plugin;
}
public static final NamespacedKey ENTITY_TYPE_KEY = new NamespacedKey(plugin, "bs.entityType");
public static final NamespacedKey MULTIPLIER_KEY = new NamespacedKey(plugin, "bs.multiplier");
public static final NamespacedKey MINED_KEY = new NamespacedKey(plugin, "bs.wasMined");
public static final NamespacedKey OWNER_KEY = new NamespacedKey(plugin, "bs.ownerName");
public static final NamespacedKey XP_KEY = new NamespacedKey(plugin, "bs.xpAmount");
public static final NamespacedKey LAST_GEN_KEY = new NamespacedKey(plugin, "bs.lastGen");
}`
yep
awesome
i cant test anything yet cause nothing works yet ๐
im redoing a big plugin
Its looking great
@eternal oxide
hold up
plugin.KEYS.ENTITY_TYPE_KEY
or
Keys.ENTITY_TYPE_KEY
plugin
doesnt that defeat the purpose of making it static?
yes, you could remove all the statics in keys
got it
so they are protected
Should i remove it from private static BetterSpawners plugin;
no need to static access within Keys
Happens to me all day
Any way to add a player twice to the player list? Or add a fake player to it?
actually yes
idk how
but citizens has a bug
where npcs will show up there
so im sure you could recreate that
Creating an NPC <#help-development message>
So
I have a system
With "dynamic permissions"
gui:
groups:
#Use default group if user does not have any betterspawners.group.(group)
default-group:
spawner-amount: 3
cansilk: false
# Groups to be used in permissions, so betterspawners.group.(group)
custom-groups:
vip:
spawner-amount: 5
cansilk: true
admin:
spawner-amount: 10
cansilk: true
So i was told to create some way to track these groups on startup. And then keep track of them from that rather than from checking the config every time
They might have been referring to generally any config value.
Not sure, anyway how would i go about that?
@eternal oxide
Create a "groups" class holding those values?
create a properties class to hold the data for each group
then read and store each in a HashMap
is that essentially what i said lmao
y a hashmap?
yep
What would the value be?
as I assume you are allowing editing of the config to create custom groups
a manager
yes
i will do that
Is this a spigot only thing? No imports found on paper
You have to import not only the spigot api but also the server to reach NMS
This should work correct?
configSection.getInt(i + ".spawner-amount")
configSection = plugin.getConfig().getConfigurationSection("gui.groups.custom-groups");
have you tried it?
custom-groups:
vip:
spawner-amount: 5
cansilk: true
admin:
spawner-amount: 10
cansilk: true
I cant yet
But i dont know how configurationsection works
Not sure if i need the i + there
what is i?
my bad
for (String i : configSection.getKeys(false)) {
for (String i : configSection.getKeys(false)) {
try{
new Group(configSection.getString(i), configSection.getInt(i + ".spawner-amount"), configSection.getBoolean(i + ".cansilk"));
}catch(Exception e){
System.out.println("Error getting group " + i + ".\n" + e);
}
}
And catching that exception wont break the loop right?
@eternal oxide For the hashmap should i use it through a getter or through custom methods such as getGroup(String)
catching a generic exception is not really that good, I suggest you test this properly and make your assumptions when an exception pops up
If it were me I'd get teh Map from the config and deserialize it
private void getGroups(){
for (String i : configSection.getKeys(false)) {
try{
groupMap.put(i, new Group(configSection.getString(i), configSection.getInt(i + ".spawner-amount"), configSection.getBoolean(i + ".cansilk")));
}catch(Exception e){
System.out.println("Error getting group " + i + ".\n" + e);
}
}
}
public void resetGroups(){
groupMap = new HashMap<>();
getGroups();
}
In resetGroups is that how to clear a hashmap?
If im printing the exception does it matter?
you can serialize a map in a config and deserialize it on retrieval
I dont see how thats relevant?
thats for this
Yea so @eternal oxide i dont see how thats relevant
Surely it should be new Group(i, ...)
groupMap.put(i, new Group(configSection.getString(i), configSection.getInt(i + ".spawner-amount"), configSection.getBoolean(i + ".cansilk")));
I assume is the name?
yeas
then what is configSection.getString(i)?
groupMap.put(i, Group.deserialize(i, configSection.get(i).getValues(true));Probably
well that seems a lot easier than what im doing
do that for each group
But that sleep deprivity is starting to kick in
private Group getPlayerGroup(Player plr){
String group = "default-group";
for (String i : groupMap.keySet()) {
if (plr.hasPermission("betterspawners.group." + i)) {
group = i;
break;
}
}
return groupMap.get(group);
}
public boolean canPlayerSilk(Player plr){
return getPlayerGroup(plr).getCanSilk();
}
public int getSpawnerAmount(Player plr){
return getPlayerGroup(plr).getSpawnerAmount();
}
this is what im doing
private void getGroups(){
for (String i : configSection.getKeys(false)) {
try{
groupMap.put(i, new Group(i, configSection.getInt(i + ".spawner-amount"), configSection.getBoolean(i + ".cansilk")));
}catch(Exception e){
System.out.println("Error getting group " + i + ".\n" + e);
}
}
//Add the default section to the map.
ConfigurationSection defaultGroupSection = plugin.getConfig().getConfigurationSection("gui.groups.default-group");
groupMap.put("default-group", new Group("default-group", defaultGroupSection.getInt("spawner-amount"), defaultGroupSection.getBoolean("cansilk")));
}
Im gonna review it in the morning
Caujse im super tired rn
Your permission check is probaly going to mess up for Ops
actually, it may not as these are undefined permission nodes
is there a way to create a flat world?
WorldCreator("MyWorld").type(WorldType.FLAT).createWorld();
you may have to add a generatorSetting string
Entity's hitbox size is defined only in the entity type or can it be changed per entity? (server side hitbox)
how do i make a plugin
guys, sorry for the stupid question: how to make the event activate on command?
"the event"?
guys in InventoryPickupItemEvent
how can i get the hopper or hopper minecart that picks the thing up
and its location
getInventory().getType() == InventoyType.HOPPER
to get teh hopper itself get Inventory and getHolder()
is my guess
is there an api documentatin for all the events and stuff
?jd-s
gracias
I want if a player writes a certain command, then a certain event is activated
how do i make the plugin type in chat
This
?eventapi
Bukkit#broadcastMessage
Is one way
Bukkit.broadcastMessage("Hello World!");
True
When I was in the hospital my home PC got me to 2 weeks
havent shut down my pc for 4 days or smth
how to add variable to string
By learning java first
?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.
By packaging it
I want a waffle toaster
Depends on the project
You really should learn these things before starting with Spigot
I started learning Gradle a bit back
I think I know everything I'm going to need
But there's so much you can do with it
You are now on a watch-list
Things take too long to package with maven.
i really should\
It's great you want to make a plugin but we need to rewind to learning java first. Some resources are above but lots of free content everywhere
No it's not good
Skript is fine if you're building something for yourself on a small scale. You want real control you need to use java.
k
Taking the training wheels off so to speak
Depends on if you shaded anything important
One is your code only it starts with original-
The other one contains other code that you included in it from your dependencies
Ok so i made PlayerInteractionEvent to check if player right-clicks playerhead, how to check if the playerhead has custom data from for example https://minecraft-heads.com/
On Minecraft-Heads.com you can find more than 30.000 custom heads, which can be used to decorate your world! The collection is seperated into two databases: the first contains custom heads, which never change their texture, using the Give-Codes from Minecraft 1.8+, the second one includes player heads which can be used in all Minecraft versions.
Isn't there a meta for heads SkullMeta or w/e
1.18.1 sadly
Oh well NMS it is then I believe
no reason to be on 1.18.1
^
if i want to rebuild project for 1.18.2 api, i need to just change pom.xml?
#992483541126496266 is also very sus
I never knew that was there
kekw
why isint my plugin working
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Bukkit.broadcastMessage("Welcome!" + event.getPlayer() + "Hope you enjoy your stay!");
Player player = event.getPlayer();
player.giveExp(100000);
}
anythuing wronmg with taht
you registered it?
register?
in your onEnable: getServer().getPluginManager().registerEvents(new ListenerClass(), this)
Definitely some things wrong with that. But run it and find out cause you'll see.
declaration: package: org.bukkit.plugin, interface: PluginManager
mye use the event::setJoinmessage instead
and other stuff..
They'll figure it out when it runs
@Override
public void onEnable() {
// Plugin startup logic
getLogger().info("Yo bro, my awesome plugin is working!");
getServer().getPluginManager().registerEvents(new ListnerClass(), this);
}
like this?
tias is also here lmfao
Yuppers
cannot find symbol
what symbol
getServer().getPluginManager().registerEvents(new onPlayerJoin(), this);
is this wrong
yes
you are (I assume) trying to register a method in your Main class so registerEvents(this, this);
Ah the joys of learning
the java channel in the coding den is even worse
people not following conventions at all
I left that place it was too toxic and I realized that learning through discord suxs
depends on what you're learning
I'm 99% sure that unless you're learning about power tripping moderators or how little social interaction effects peoples ability to communicate properly there are better learning sources lol
Isn't SkullMeta for item.getMeta? How to check for the skull already placed and clicked as event.getClickedBlock
I'm confused
?jd-s
Skull block tysm
how could i store info inside blocks previous to 1.16?
change the Broadcast "event.getPlayer()" to "event.getPlayer().getName()"
Hey @chrome beacon, sorry for ping, but i wanted to let you know that i fixed my issue
googling a bit more i found out that i needed to use \\ instead of \
How do I know how many slots should be filled?
Is this just broken for 1.18.2? I'm using the correct dependency and the correct API version but nothing happened on the events?
Sorry for butting in
(rowto - rowfrom) * (colonto - colonfrom)?
forgot to register the listener?
7smile why are you so fast..
๐๐ป
๐คท
Not working
well idk why you should use such a method too
who not just taking a start and end index as params
I'm doing a paginated menu
At the end I have to check if all slots are filled
I gave you all the code you needed yesterday. You should be checking the number of items sent before you start filling a UI
Its no good shoving everything into a UI and finding you don;t have room
Sorry to but in but what api-version do you use for a 1.18.2 plugin in the plugin.yml?
1.18.2 doesn't work
1.18
I insert all the items first and want to create the next page at the end, if there is not enough space
Thats not going to work... one sec
No, you're right, though.
?paste
A simple paginated UI. Look how it does it, it creates new pages as it needs https://paste.md-5.net/dibijezuye.java
fully working, just add it as a listener to see how it works
I'm trying to store a list of objects in a json file. Saving works fine with serializing and gson.
But i can't get reading to work. Are there any examples on how to do that, or other ways to do that?
what objects?
Usually you just use the same gson instance and read the objects again.
SomeObj obj = gson.fromJson(jsonString, SomeObj.class);
And thats it. But as ElgarL pointed out: Depending on your object or its composition you need custom serializer.
your methods are static?
Okay, thanks
afaik you need them not make non static in order for this to work
he didnt register it
ye but kinda weird
can I use a filereader instead of the jsonstring and can i get like a hashmap instead of a class?
Show us what you are storing pls
also does spigot include any form of json library?
Yes. Gson.-
And yes you can also use a Reader (like a FileReader)
As you are not willing to provide any more information: Here is the general approach.
Saving a map:
// Your data map
Map<UUID, PlayerData> dataMap = ...;
// Creating a json string from that map
String jsonString = gson.toJson(dataMap);
// <- Save the string in a File
Loading a map:
// Reading the string from a file
String jsonString = ...;
// Creating a type token because the class we want to serialize is generic
Type typeToken = new TypeToken<Map<UUID, PlayerData>>() {}.getType();
// Deserialize the json string
Map<UUID, PlayerData> dataMap = gson.fromJson(jsonString, typeToken);
lets go its finished
lets clean up those method names a little
150 lines mwoa
lets see how essentials does it
Hello,
if i have 3 coordinates :
-178 62 193
345 3 -1
0 134 -1033
how could I do to check which coordinates of these 3 is the most near to a player
weak they only have 50 lines
Calculate the distance squared to each location and check which one is the closest
why is there even a squared method?
Because calculating the distance between two points (or rather the length of a vector) uses
the square root function, which is pretty expensive.
|a| = โx^2 + y^2
And squaring this us just
|a| = x * x + y * y
Which is way cheaper to calculate
PlayerDropItemEvent
When I cancel the Event and try
Player#getInventory#remove(Event#getItem)
it just cancels event
and doesn't do anything else..
any clue why?
ItemStack i = e.getItemDrop().getItemStack();
e.setCancelled(true);
p.getInventory().remove(i);
Try it one tick later
using bukkit runnable or is there some other way to wait a tick
scheduler.runTask
public Location closest(Location target, List<Location> points) {
double smallestDistance = Double.MAX_VALUE;
Location closestLocation = null;
for(Location point : points) {
double distance = target.distanceSquared(point);
if(distance < smallestDistance) {
smallestDistance = distance;
closestLocation = point;
}
}
return closestLocation;
}
๐ฅ
No square root
Spigot already got you covered. You just call
locA.distance(locB)
Or better
locA.distanceSquared(locB)
Hello someone knows how to use maven ?
yes lol
oh well all right, thats much easier, thank you!
Ask your question
So some time ago I purchased source code for a Discord bot and the guy built for me the source code and it used to look like this and everything was good
https://media.discordapp.net/attachments/994579878336811079/994580155601264680/unknown.png
but now my bot have new token and when I try to install it with maven it looks different:
when I install the source code (target/) :
https://media.discordapp.net/attachments/994579878336811079/994580296462774312/unknown.png
and when i try run the HoloInvites.jar it aint working
How can I teleport entity relatively to other entity'r direction? I mean when other entity e.g will turn then teleported entity changes self position
You are gonna need to provide more info than that lol
yep worked
thx
also kinda strange
like how? which info i can more provide?
pom
but I meant why there is different structure when i install and he install
thats whole screen
Wdym?
As U can see when he installed for me I dont think he used maven:
https://media.discordapp.net/attachments/994579878336811079/994580155601264680/unknown.png
and when I install it looks different
https://media.discordapp.net/attachments/994579878336811079/994580296462774312/unknown.png
I dont really know Java
He probably used a different build tool or the built in one
The difference is just the structure ?
I need your full pom, not just a screenshot of some of the dependencies
Use this:
?paste
I think you chose the Jar without dependencies
I think the error is caused by the dependencies being missing and not shaded.
Just to check, what is the size of the original JAR compared to the one you made?
Because also in your pom I donโt see any shading configuration setup
alright
yeah I also think its dependencies
when I try to mvn verify
how do i fix that ?
when I try to download in maven menu it just dont download
Search online for maven shading guide and implement it
}else if (command.getName().equalsIgnoreCase("healther")) {
if (sender instanceof Player) {
Player p = (Player) sender;
if (args.length == 0) {
p.sendMessage(ChatColor.translateAlternateColorCodes(&, getConfig().getString("heal-success")));
p.setHealth(p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
}else if(args.length == 1){
Player target = Bukkit.getServer().getPlayer(args[0]).getName();
}
```
Errors:
Help?
p.sendmessage from args.length==0 is line 54
first up, youve got a floating &
floating?
alright i have this now
if your args.length == 0 is line 54, your line 57 is the else if?
57 is Player target = bukkit and more on in that line
Ah yes
get rid of the .getName()
youre casting a string to a player, then back to a string, then back to a player
Thanks
alright thx sorry for deleting
last thing, how can i check if target is an online player on the server?
would if(target.isOnline()){} work?
If the player from Bukkit.getPlayer is null, they are offline
What error?
An internal error occurred while attempting to perform this command
Thatโs not enough information
works if I target an online player though
Go into console
alright wait
is there a way to make mobs pick up any item
ye
i think with offline player theres a function to check 1) if they're online, and 2) if theyve ever joined
so i could do if(target.isOnline) to avoid the errors?
alright thank you
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/OfflinePlayer.html#isOnline()
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/OfflinePlayer.html#hasPlayedBefore()
declaration: package: org.bukkit, interface: OfflinePlayer
๐ thx
i enable both mob#canpickupitems and item#canmobspickupitem and it still doesnt work is there no way
how are you going about allowing all mobs to pick up items? like are you changing it on mob spawn, using custom mobs, etc?
Where can I download the Spigot API 1.19 for my plugin development?
Maven is the quickest, and easiest way. if not, refer to the build tools; https://www.spigotmc.org/wiki/buildtools/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I spawn a mob and enable its canpickupitems
and I enable items' canmobspickup on itemspawnevent&itemmergeevent
I assume you want certain mobs to be able to pick up everything?
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event){
Item item = event.getEntity();
if(!item.canMobPickup()){
item.setCanMobPickup(true);
item.setOp(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onItemMerge(ItemMergeEvent event){
Item item = event.getEntity();
if(!item.canMobPickup()){
item.setCanMobPickup(true);
item.setOp(true);
}
}
Trying to install the latest version but I get this error. I dont understand, Java 8 is the most recent right?
java 8 is quite old. Java 17 is the latest LTS version.
I think I needed it for javaFX
hey can you tell me if making mobs able to pick up any item directly posibble
java 8?
EntityPickupItemEvent
No idea what that sentence is supposed to mean...
I think he means, wheres his code going wrong
imagine a sheep picking up a sword and killing u ๐ฟ
why is there no 1.19?
"bukkit"
lol
dis spigot
alright so i should change to spigot?
if u want help ye
alr thx
spigot-api
thx it works now
waitt
ye its weird
of course Bukkit supports 1.19
yea but i couldnt change to 1.16 and above with bukkit
ah depending on bukkit. yep thats wrong
Thatโs just IntelliJ tab complete
I believe it fetches from what you already have downloaded
well if i did 1.19 it showed an error
Not sure then
bukkit is not publicly available. You need to run buildtools for that version so its being installed in your local maven repo
im not a fan of buildtools tbh
who is
paperclip
ssshhh
Since 1.17 you should use a different approach for craftbukkit/nms
?bootstrap
Bootstrap Jar
The main spigot-1.18.jar is now a bootstrap jar which contains all libraries. You cannot directly depend on this jar. You should depend on Spigot/Spigot-API/target/spigot-api-1.18-R0.1-SNAPSHOT-shaded.jar, or the entire contents of the bundler directory from your server, or use a dependency manager such as Maven or Gradle to handle this automatically.
Please read the release notes for further information: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/#post-4305163
s.setLine(1, player.getInventory().getItemInMainHand().getType().name());
So Im trying to make a shop plugin. Therefor I need to save the item that I want to sell. But when I use .getType().name() and Amethyst Shard it returns AIR.
What am I doing wrong?
Are you sure the player is holding you're item in it's mainhand?
Yes
so how can i directly fill the blocks between x2000 any z2000
What's your api version in plugin.yml?
Hi, I've been learning minecraft plugins and am now looking at custom mobs using NMS, and have been looking at videos but a bit confused as they are able to do this.setPosition(loc.getX(), loc.getY(), loc.getZ()) where as I am unable to use .setPosition() and instead I am forced to use this.a(loc.getX(), loc.getY(), loc.getZ()) . been looking for the past hour and haven't found the answer, think it has something to do with buildtools and installing spigot as --remapped but have done this and not sure how to update my current project with it.
Im using
oh no, there copying hypixel!!
Yeah but in plugin.yml, you should have a line api-version
I dont have that๐
What should I add?
But that is just documentation right?
Is it possible to change armorstand's pitch (that blue line when hitbox enabled :D)
probably need to change the mobs pathfinder (that's just the idea that comes to my mind). don't know how to do that as I am trying to learn that myself atm
Still need help on this ๐
Hey so making an addon system here. I'm using lamp. and uh im getting this Could not load 'plugins\cloud-1.0-SNAPSHOT.jar' in folder 'plugins' org.bukkit.plugin.InvalidPluginException: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register revxrsal.commands.bukkit.brigadier.Commodore$ServerReloadListener@b55dfd3 while not enabled heres the github https://github.com/JadeStudioss/Cloud
i dont have a life to send the classes
dont do direct initialisation
Yeah but your plugin would work fine without that line in your plugin.yml
oh
You can;t register anythign without a valid Plugin instance
^^ plugin isnt enabled yet
and as Fourteen said, the plugin must be enabled to do it too
Tell me if it works with that line
me starting runnables in the constructor ๐๐
it worked!
But why does it work tho? Thanks anyways! ๐
It's because since Material things changed a lot since I don't remember which version, you have to specify which material stuff you're using
instead of Bukkit.getLogger, use getLogger while still in ya main class
oh yeah duh
so the command isnt working, um no error. heres my command ```java
package org.cloud.addon.commands;
import revxrsal.commands.annotation.Command;
import revxrsal.commands.annotation.Default;
public class TestCommand {
@Command("echo")
public String echo(@Default("") String message) {
return message;
}
}
this is also in the addon jar so idk if that would cause it
package org.cloud.addon;
import org.cloud.addon.commands.TestCommand;
import org.eternitystudios.plugins.cloud.Cloud;
public class Addon {
Cloud instance;
public Addon(Cloud instance) {
this.instance = instance;
}
public void addonMain() {
instance.registerCommand(new TestCommand(), "test");
}
}
``` heres the main class for the addon
and the registerCommand method should work
i think you should actually do smth in ya command instead of just returning a string
it sends the string i think. also im just testing if it works
add some sysout to test if it works
Is it possible to change armorstand's pitch (that blue line when hitbox enabled)?
okay how do i list strings from a file ingame? like when theres something in the file written that the command ill do put it out whats written in the file
?configs
See this wiki page on how to use custom configuration files: https://www.spigotmc.org/wiki/config-files/
uhh
just print the content to the player
like player.sendMessage(config.getString("boo"))
assuming its a yaml file
sysout? that would not do anything
print if the code gets triggered
i guess it gets triggered but your command doesnt do anything
Hello I'm trying to make a custom join/leave messages plugin so i have this problem i have a config file and i make it so it'll get the string from the config as the welcome msg so i have the dependency placeholder api too but the %player% which is in the config won't load
you need to interact with the papi code
iirc theres smth like PlaceHolderApi.fillInPlaceHolders or smth
yeah but what if its empty?
May i know where should I do that?
and im not working with the config, im working with files like yml
the config is already in use by other thing
how are you saving it
hm?
like this way: ```java
public static void setreportmessage(String name, String message, String Bugtype) {
File file = new File("plugins/RegiPlug", "reportmessage.yml");
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
cfg.set(name + ".repmessage", message);
cfg.set(name + ".bugtype", Bugtype);
try {
cfg.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
so the stuff is saved smth like
name:
message: 'smth'
bugtype: 'smthelse'
othername:
Kinda like that but you may want to store the FileConfiguration so you don't load it everytime you want to access it.
^^
might be, othername is not in use
and what do you want to print everything?
i want to print when theres something in that file that he print it out in chat for me
and there can be more than one entry
for (String str : config.getKeys(false)) {
String message = config.getString(str + ".message");
String bugtype = config.getString(str + ".bugtype");
sender.sendMessage(str + " got reported for " + bugtype + ", message: " + message);
}```
basically
config.getKeys(false) will iterate over the root keys (all the names in your case)
OHHH
Hey so I am using MongoDB and I am kinda confused on how to organize my stuff. So does it work like where I have a database per server then a collection per plugin?
you should be saving the users uuid instead of their name, as their name can change but uuid not
its just for identification, so i dont have to search all the time for their names
okay okay really thank u
Can anyone help me with this?
uhm not the one I'm looking for but anyway thank you.
what are you looking for then
Hi, I've been learning minecraft plugins and am now looking at custom mobs using NMS, and have been looking at videos but a bit confused as they are able to do
this.setPosition(loc.getX(), loc.getY(), loc.getZ())
where as I am unable to use .setPosition() and instead I am forced to use
this.a(loc.getX(), loc.getY(), loc.getZ())
been looking for the past hour and haven't found the answer, think it has something to do with buildtools and installing spigot as --remapped but have done this and not sure how to update my current project with it.
where should I like input the thing u said that placeholderapi.fillinplaceholders to let the config print out the placeholder
what isnt clear about this
Uhm like i don't have the %player_name% has joined the server in the main class i have it in the config file. so i have to make it to print out from config
..
placeholderapi โค๏ธ
Use config#getString("path-to-var")
I have tried this but doesn't seem to work.
may i know where?
where what?
when I try to copy the pom.xml file it doesn't work
2nd param
where to input the things u said "config#getString("path-to-var")" sorry I'm just a starting stage developer so i have many doubts.
always fun when i discover bugs in the code ive been working on for three days smh
Thats the place_holder correct?
uhh which?
then replace %player_name% with " + config.getString("path-to-var") + "
replace %Player% with %player_name%
ok
500 lines of code with bugs in lets go
nearly the 2000 lines of C code with one comment on top of the file: //this code contains bugs
๐ฅฒ
pain
Why IS IT SO PAINFUL TO DESIGN FULLY FUNCTIONAL API
what api
im designing ui api
which fully implements NMS containers
that problem isnt that they don't work
problem is that It so hard to maintain bukkit api support by using NMS
since every instance of NMS menu or container is hardcoded to packet handling
@mortal harewhats your code?
Again ๐ Pull requests are an option
You're welcome to make patch files if necessary and improve our API
Want to expose something for your library and it makes sense to be a native Bukkit method? You can add one today! Just call 1-800-44 ehm- sign the CLA and open a PR!
why are there events in ur command smh
Is there a bungee.yml documentation?
cuz those events need access to the command methods
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("healther")) {
if (sender instanceof Player) {
Player p = (Player) sender;
if(p.hasPermission("healther.*")){
if (args.length == 0) {
p.sendMessage(ChatColor.RED + "List of commands:");
p.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.RED + "/healther reload");
p.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.RED + "/healther help");
p.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.RED + "/healther");
} else if (args[0].equalsIgnoreCase("reload")) {
reloadConfig();
p.sendMessage(ChatColor.GREEN + "Reloaded the config");
} else if (args[0].equalsIgnoreCase("help")) {
p.sendMessage(ChatColor.RED + "List of commands:");
p.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.RED + "/healther reload");
p.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.RED + "/healther help");
p.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.RED + "/healther");
} else {
p.sendMessage(ChatColor.RED + "Please enter a valid command, view the list of them using /healther help");
}
}
}else if (command.getName().equalsIgnoreCase("heal")) {
if (sender instanceof Player) {
Player p = (Player) sender;
if (args.length == 0) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("heal-success")));
p.setHealth(p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
p.setSaturation(20);
}else if(args.length == 1){
Player target = Bukkit.getServer().getPlayer(args[0]);
if(target.isOnline()){
target.setHealth(target.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue());
target.setSaturation(20);
p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("heal-other-success").replace("%target%", target.getDisplayName())));
target.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("heal-ttt").replace("%player%", p.getDisplayName())));
}else{
p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("heal-error")));
}
}
}
}
}
return true;
}``` no errors, but the command:
else if(command.getName().equalsIgnoreCase("heal")) doesnt respond anything in game
Have you registered it?
cant tell if its discord formatting but i think its in the healther check
true
yeah
heal:
description: Heals a player
aliases: heal
your if statements are probably nested wrong idk
btw I removed the aliases
Did you set the executor as well?
getCommand(String).setExecutor(Command)
oh
hello guys how can i avoid the crashing when setting to many blocks
I dont think i have that, where do I put that?
onEnable
what do I replace String and Command with? I mean the commands always worked without it
String is the name of the command (needs to be the same as in plugin.yml) and command is an instance of CommandExecutor (so your class that implements it ig)
handling all commands in one method is so ugly
yeah
This btw
well youre doing it so idk
what is the event for an npc to teleport?
would this work?
declaration: package: org.bukkit.event.entity, class: EntityTeleportEvent
there is a red line, so no
how do I make an instance of the executor though? (sry im new to plugin dev)
take a look at the expected arguments, it takes an instance of your class that implements CommandExecutor so smth like new MyCommandThing()
public class MyCommandThing implements CommandExecutor {
I have that
oh i got it working, thanks guys!
?paste
Hi i have problem.
I create config filees but if you edit messages in config and restart server new config settings dont load.
Code: https://paste.md-5.net/eweqagecuf.java
are you restarting or reloading?
Restart server
i dont know exactly, but you have config.set there which from my understanding could set the settings to "Has joined" when the server is enabled
oh
You don;t need any of that cofig stuff in yoru onenable. Just put saveDefaultConfig();
this is what i use for config
getConfig().options().copyDefaults();
saveDefaultConfig();```
it works good
getConfig().options().copyDefaults(); is pointless. It does nothing
copyDefaults is a boolean return value.
i go try
include a config.yml in your plugin jar and all you need in onEnable() is saveDefaultConfig()
how can i make the plugin work for multiple versions? or is it too hard to just explain here?
Don't use NMS/Craft imports and it will work for multiple versions
And where should I write things in the config?
write things?
hm? basically to make a config you can create a config.yml almost anywhere (i recommend in resources cause its kind of an resource) and open it, write things in it
generally your plugin would not write things to the config, unless you are toggling default options.
okey
Can a Bungeecord network have 1 spigot server on online mode and other on offline mode?
plugin be like lol Fuck u
[turns on pvp without asking]
no, validation through bungee is the correct method
anyone?
replace less at once
but i need it suddenly
then redesign what you are doing
wdym
you can not replace too many at once, so you need to find another way of doing things.
What are you trying to achieve?
how can people do that in uhc servers
what is uhc?
No idea what you are talking about
dont you know uhc logic?
I have no idea what uhc is
i mean every 10 minutes the border is getting shorter. I mean first 10 min its 2000x2000 after 10 minutes its being 1000x1000
after 10 minutes you need to teleport people to 1000x1000 so you need to make a new border 1000x1000
are you talking about the MC border? or some physical border?
its good idea let me try
i dont know how to use it
and vanilla border is not physical thing not let place blocks front of the border
How can I cancel this task? I've tried to here https://imgur.com/a/agdMkbJ
just cancel()
why not just using the lambda way
external counter. using lambda would require final
or the Consumer<BukkitTask> so you could just do runTaskSmth(plugin, task -> { task.cancel(); })
AtomicInteger integer = new AtomicInteger();
BukkitTask task = return Bukkit.getServer().getScheduler().runTaskTimer(Main.oPlugin, new Runnable() {
public void run() {
if (countDownTimer <= 0) {
Bukkit.getServer().getScheduler().cancelTask(integer.get());
Logger.logMessage("cancelled: " + performShutDownTimerFunction().isCancelled());
Logger.writeDebugLog("Removing shutdown task timer: ");
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "forcestop");
} else if (countDownTimer == 10 || countDownTimer <= 5) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "broadcast Restarting the server in " + countDownTimer + " seconds!");
}
--countDownTimer;
}
}, 0L, 20L);
integer.set(task.getId());
return task;
int[] with one value is my preferred way
int[] num = new int[] {someNumber};
AtomicInteger num = new AtomicInteger(someNumber);
var obj = {
int num = someNumber;
}
If it's sync anyways
all of those are valid
{}?
ye wait
What is obj supposed to be
lemme make it correct
For real?
Where jep
Oh it's a Java 10 thing
yes
It's just the anonymous class definition
ye
But it lets the variable have an anonymous type
Which honestly doesn't seem that useful
i get most part but i couldnt do it
the class, however the objects within don't have to be
Yeah but you couldn't meaningfully return such an object
None of its values would be accessible
So what's the point
but they are
What return type could you use that would allow that
lemme show you what I mean
a is of type int
it's just that the type is gotten at initialization
so you don't type really long names
like
Thatโs inferred types at compilation
FactoryFactoryBuilderFactoryFactoryBuilder
I know how type inferencing works
you can just use var
I'm talking about anonymous types
You cannot return an anonymous object without losing the type data
that's why you don't return it
it's used as a workaround for like final stuff
so you can have mutable vars passed into lambda without needing to make like finalMyVarName
cries in still writes java 8
https://www.spigotmc.org/threads/setvelocity-follow-function-curve-sin-cos.556837/#post-4412088
Any1 can help me with this?
I have done something like that before
Calculate the curve ahead of time and keep it as a list of locations or something
Then set the velocity every tick
also just found this rn:
https://www.spigotmc.org/threads/moving-armorstand-on-sine-curve.490428/
https://www.spigotmc.org/threads/parabolic-curves.241381/
also this for someone needing same thing as I do
ok i removed the dependency reduced pom from my project and now the maven tab is gone :/
gj
x^2 is parabola.
use graph calc to calculate your curve
and just utilise the math function
by placing blocks or particles
?paste
Modeling a 2d function in 3d space if it's not axis aligned might be annoying
Actually no it wouldn't be
You'd just do sqrt(xOffset^2 + zOffset^2) to get your input variable
oh FileConfiguration::getString returning whatever it finds
i made a section there by default and now its returning MemorySection::toString
Hi, i have problem with configs.
Create config files is work but events dont send messages
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.
Hey, am having a stupid issue
Trying to send fake blocks using packets on 1.18.1, the packets debug fine but the blocks simply don't appear.
Relevant code: https://paste.md-5.net/oxetovegod.cs
I might've encoded the shorts wrong โ ๏ธ
anyone have experiences about heavy threads?
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
Wym by heavy threads?
filling somewhere with big amount of blocks
@lost matrix has a tutorial on that
?workdistro
ngl I made like 30$ off of that tutorial
lul
i just have some problem with my server
You cant. Unless the would have a property for that.
They simply have a predefined lifetime and then vanish.
Why do you need that?
This has to be done repeatedly anyways
getLocation() returns the Location at the players feet
I'm using the runnable but its not decreasing the time of working thread
are u splitting up the workload
?configs
See this wiki page on how to use custom configuration files: https://www.spigotmc.org/wiki/config-files/
i just triggered the runnable
did u ping me and then delete it or did discord bug and ping me anyway
i accidentally
For server issue use the apropiate channel!
wtf?
Am i doing something wrong? xdd how to import authlib
did you add the correct repo ?
Don't you have to run BT for authlib?
Yes
also, 1.5.21? what old ass version is that?
Lol
iirc current 1.19.1 stuff is on 3.9.47
I mean, concerning there is a maven repo, I'd suggest using that ๐ค
unless you need server internals anyway
think thats from like 1.8 looool
woops meant to turn off ping
pings are fine. keeps me awake ๐
Why do you tag me?
A dumb question how i can get server status without ping it every time?
Becaue if you are using bungeecord its really annoying to see a ping message every time
What story
What
Why did you say me to text the correct channel??
I was already using the correct one
Didnt you er asking about a server issue?
Or maybe i confuse with another guy
โ๏ธ
if an entity is hit by a player (directly, crosshair target) with a fully charged sword, is the damage source still ENTITY_ATTACK or is it ENTITY_SWEEP_ATTACK
not in an env to test it myself rn
Could you finish your annotated file system? Im interested on see it
its not very polished tbh, just enough that it does what i need it to do
i wanna see too @buoyant viper
i literally just made this lib because im tired of boilerplate config shit
Oh really thanks
?jd-s ProtocolInjector
hh ill make a repo later then
Sorry for being annoying but if open source a file system would someone be interested on pulling a request to add the ConfigurationSection thing
Why on big server Skull Textures dissapear?
On localhost they worked well
Skull headBlock = (Skull) event.getClickedBlock().getState();
ItemStack item = playerHead.getCustomHead(headUrl, headName, headDisplayName);
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
// check if the headblock (placed skull) is item (custom head)
}
Can someone tell me how to check for this i'm confused theres material.skull and block.skull
Rate limiting. Make sure to not request too much data from mojang
Material is for an ItemStack. Skull (BlockState) is for checking a placed skull
im getting prob 4 skins?
Do i have to store placed skull blocks and then check for it or how?
Or just check skull block skullowningplayer
@EventHandler
private void onRightClick(PlayerInteractEvent event) {
if (event.getPlayer().isSneaking()) return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getHand() == null || !event.getHand().equals(EquipmentSlot.HAND)) return;
var clickedBlock = event.getClickedBlock();
if (clickedBlock == null) return;
if (!(clickedBlock.getState() instanceof Skull skullState)) return;
if (skullState.getOwningPlayer() == null) return;
var ownerName = skullState.getOwningPlayer().getName();
if (ownerName == null) return;
event.getPlayer().sendMessage(String.format(ChatHelper.format("&eThis head belongs to &c%s"), ownerName));
event.setCancelled(true);
}``` heres code i have for skull block
dont know if its useful for u
whats your skullState variable?
if ur also dealing with a placed skull its the block's (Skull)state
okay
ur equivalent variable is headBlock
yeah
oh are u trying to make sure its a player head and not like a skeleton or otherwise
