#help-development
1 messages Β· Page 1487 of 1
to the question
is there a limit of how many keys a hashmap can have?
cuz thats 2.1B keys
if I addItem() to a full inventory, will it drop on the ground?
is there a built-in way to handle that
you want to drop it?
yes
spawn the item in the location of the player
I need to know if its full or not
where item = itemstack that could not be added
if inv.get next free slot
smth like that
Inventory.firstEmpty()
hm that wont work for stacking items
try
Inventory.firstEmpty()
catch exception
spawn item
wut
if I have 1 wood in every slot and want to add 1 wood, it will not find an empty slot for it to go
even tho it should stack with the other woods
there is first(ItemStack) though maybe thats correct
any solutions?
actually no docs say its an exact match hm
first()
Returns the first slot in the inventory containing an ItemStack with the given stack.
firstEmpty()
Returns the first empty Slot.
ig you could use that
yea neither of them will work for me unfortunately
what are you trying to do
I will have to iterate it manually and do my own stackable test
I want to add an item to a storage block or drop on the ground if it doesnt fit
I think it does?
like a chest etc
addItem returns a HashMap<Integer, ItemStack> containing the items that could not be added
it doesn't
Does it not
loop through the values and World#dropItem them
I thought it does
what does the integer represent?
oh addItem takes many items so ig its just the index
Index I think
mhm
Or id
no more IDs π
i don't really see a point in that tbh
IDs still exist lol
they don't
yea you get the reference so index is kinda redundant
well not numeric IDs
IDs only exist for world saving etc
namespaced keys
But I looked into material class and it referred blocks and items with IDs
that's a bukkit thing
vanilla does not use them anymore
they are non-existent
are you depending on the spigot api or the bukkit api?
depend on spigot api
?
are you using maven/gradle or just stuffing the jars into ij?
yeah i strongly suggest you learn how to use maven or gradle, manage dependencies, build your applications/libraries, shade (bundle) libraries, publish to repos, and automate a billion other things (you don't necessarily have to do all of these, but the primary use you'll give them is manage dependencies such as spigot-api and other libraries)
ig this will suffice since a lot of people find maven easier to learn before gradle https://www.spigotmc.org/wiki/creating-a-plugin-with-maven-using-intellij-idea/
Try maven see if it works then
If maven works which it probs will then the way u are adding Ur spigot API jar must be wrong
I also encourage you to read the official maven docs, the whole "Getting Started" and "Introduction" are a must https://maven.apache.org/guides/index.html
i cant figure out why this doesn't work, what i want to happen is for an item that is unbreakable to not be able to be moved, but the events aren't even called at all (the prints dont work).
@EventHandler
public void onMoveItem(InventoryMoveItemEvent event) {
if (event.getItem().getItemMeta().isUnbreakable()) event.setCancelled(true);
System.out.println("1");
}
@EventHandler
public void onPickupItem(InventoryPickupItemEvent event) {
if (event.getItem().getItemStack().getItemMeta().isUnbreakable()) event.setCancelled(true);
System.out.println("2");
}
@EventHandler
public void onDragItem(InventoryDragEvent event) {
if (event.getCursor().getItemMeta().isUnbreakable()) event.setCancelled(true);
System.out.println("3");
}
it's going to work with maven or gradle
Maven is easier
the bungee chat api is a transitive dep of spigot api
a proper build tool will resolve it for you
And also u can get the latest jar of 1.16.3
Without having to use buildtools or anything
Or getting it online by urself
Bro please
Use maven
could someone help me w/ this?
Oh wait misread
Idk
hmmmmm, dang
did.. you register the listener?
yeah
i mean the sole fact that "the events aren't even called at all" tells me the listener is not being registered either
i mean other events in the same class do work
wait
does it work for the player inventory?
or just for like chest inventories?
should work for the player inv too
hmmmmmmmmm
do you also have an InventoryClickEvent listener..?
oh is it not?
no
i just want to detect when an item is changed from its slot
i mean none of them are being called
there are half a million events regarding inventories
add a handler for InventoryClickEvent, then test it
hmmmmmm
this doesnt work either:
@EventHandler
public void onInventoryInteract(InventoryInteractEvent event) {
System.out.println("1");
}
keep in mind there are two items involved in that event, cursor and current
because InventoryInteractEvent is in and of itself not an event that is called
wdym
sub-classes of it are
oh so its like Entity to LivingEntity
e.g. InventoryClickEvent extends InventoryInteractEvent, you can listen to InventoryClickEvent, you can't listen to InventoryInteractEvent
ok
you can only listen to events that have a HandlerList
and sub-classes of them
InventoryClickEvent has a HandlerList, InventoryInteractEvent does not
is there some api to handle hoppers and their data like item transfering, the amount of items, name of inv etc
Don't think so
why does event.getsource.getcontents return the itemstack with amount - 1? in inv move item event, single items are null and itemstacks are the amount - 1
Could probably be cleaned up but this is what i use @high prawn It'll fix your issue
oop, forgot to remove the ```'s
Is it in src/main/resources/
It's possible they're just not including it in the maven build process
which the above does π
Wait u include Ur files??
I don't in the pom
It works fine
Not explicitly, i mean like you're not using a plugin or something that takes it into account π
unless things are different π€
π€·ββοΈ
I think that tutorial thinks u know basic maven
^
It probs is for beginners but u probs need to know where to put Ur files in maven
Np π
Lol
It should work
Cuz anything from the chat stuff work for ne
Does anybody know what exactly happens when I add an item to an inventory? Because I try to get the item at the index I just added it and its not equal != at the item I just added
I would try comparing ItemStacks another way, like ItemStack#isSimilar(ItemStack)
I need the exact item ;p
declaration: package: org.bukkit.inventory, class: ItemStack
This method is the same as equals, but does not consider stack size (amount).
I'd just like to know what happens underground, so I'd have a better idea of what to do next
I mean, I need to be the exact item
==
use .equals()
item stacks are cloned left right and center when adding and getting them from inventories
EXACT
then use .equals if you don't care about stack size
.equals is exact..?
what are you on about
you will never get the EXACT item reference
because of that
I see
just use .equals if you don't care about the item stack size, it will only return true if the item is the same as the one you're comparing against
this tho ^
I'm just limit testing the items to see if there's a way to implement a sort of metadata to them
I don't want to store primitives or those stuff
I'm looking further
Like, attaching Consumers, Suppliers, Functions or Executors
Those kind of functional stuff
mate this isn't haskell
And I wouldn't like to use serializable functions ;p
I know, I'm limit testing
I'm pretty near actually
what do consumers and executors have to do with itemstack equality..?
you don't want to use serializable things?
The fact that won't be applied to another item with the same qualities
π¦ what did they ever do to you
if you want to identify an "EXACT" itemstack, you tag it with PDC
then check for the tag
if it's there, it's THE item
For example, I'd be able to abstract the Item metadata with IdentityMaps
Like a UUID for each item?
Might work
I know they are
you just did though
add the UUID to the PDC as a String, then check if it's there, get it etc
Or make a custom pdc type for UUIDs that saves the most and least significant bits
I assume thatβs a bit smaller
I use NBT Api ;p
yeah ig an array of the two longs will be better
toPlainText
public ChestGui createGui() {
ChestGui gui = new ChestGui(3, "Navigator");
gui.setOnGlobalClick(event -> event.setCancelled(true));
OutlinePane background = new OutlinePane(0, 0, 9, 3, Priority.LOWEST);
background.addItem(new GuiItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)));
background.setRepeat(true);
gui.addPane(background);
OutlinePane navigationPane = new OutlinePane(3, 1, 3, 1);
ItemStack shop = new ItemStack(Material.CHEST);
ItemMeta shopMeta = shop.getItemMeta();
shopMeta.setDisplayName("Shop");
shop.setItemMeta(shopMeta);
navigationPane.addItem(new GuiItem(shop, event -> {
// navigate to the shop
}));
ItemStack beacon = new ItemStack(Material.BEACON);
ItemMeta beaconMeta = beacon.getItemMeta();
beaconMeta.setDisplayName("Spawn");
beacon.setItemMeta(beaconMeta);
navigationPane.addItem(new GuiItem(beacon, event -> {
// navigate to spawn
}));
ItemStack bed = new ItemStack(Material.RED_BED);
ItemMeta bedMeta = bed.getItemMeta();
bedMeta.setDisplayName("Home");
bed.setItemMeta(bedMeta);
navigationPane.addItem(new GuiItem(bed, event -> {
}));
gui.addPane(navigationPane);
return gui;
}
I am using inventory framework. Should i be running this every time someone executes the admin gui command? or is there a way to create it, and then give it to a person later
It just creates a gui
createGui().show(plr);
im running this everytime they run the gui command
I mean you can create it once in a field and then call show as needed
Would that be better, or not that big of a deal?
better sure
Field definitely, you're not calling all of that code each time iirc
how do i start development on plugin are there any good tutorial videos you would recommend?
codedred
he does a lot of shit things
like bad practices
but hes the best tutorials i have found
Just ask questions here, and people will make fun of you for making mistakes. But hey, thats how you learn
I'd do a series myself, rn isn't the best time though qwq
@mint frigate
Howdy all and welcome to my all-new series for Plugin Development! New videos every Monday. Join my discord for help and more :)
Download Eclipse: https://www.eclipse.org/downloads/packages/release/2019-03/r/eclipse-ide-java-developers
Download Java Jre: https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
Down...
a LOT of bad practices, but its as basic as your gonna get
a LOT of bad practices
yyep, that's what I've heard as well lol
never seen any of their vids tho
thnx
looking actually π
videos are meh
they tend to take a shit ton of effort and outdate pretty quickly
i fucking hate reading
aaaaaaand that's an issue
meh
doesnt mean i dont do it
i just hate doing it
im reading a big fat java book rn
i hate it
Depends really, NMS? 100%
basics? Probably not unless there's massive changes
yea the videos i watched were from like 4 years ago lol
dude, i am still pretty new to spigot development
but i would love to help someone who doesnt know anything
lol
most of the time when i go onto forums, or here. Its questions i would ask, not beginner stuff
oh no, you guys are typing for a long time
sad reality is that, way more often than not, "i want to learn spigot" means "i know jack about java", because if you do understand how to make programs in java (not necessarily proficient, but you are sure you know your stuff) then "learning spigot" is not really that hard other than for a few odd ends here and there
sad reality is that, way more often than not, "i want to learn spigot" means "i know jack about java"
this was me
but yea
Looking at the first 3 episodes, there's not really anything "bad" per se, however there could be some improvements
e.g. in Ep3 It would be better done this way
if(!isNum(args[0])){
player.sendMessage(ChatColor.RED + "Usage: /launch <number-value>");
return true;
}
player.sendMessage(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Zooooom!");
player.setVelocity(player.getLocation().getDirection().multiply(Integer.parseInt(args[0])).setY(2));
I'm all in for learning Spigot as you learn Java, but learning spigot without knowing how to Java is a horrible idea
The way it's done isn't bad but it could still be improved
yea i knew nothing, didnt know what an API was, didnt know what an IDE was. Didnt know litterally anything about java lol
But i bought a java book, and asked dumb questions here
and boom im smart now
I started on spigot w/ little to no knowledge on Java (coming from C++, somewhat similar, very different nonetheless, but I did have previous knowledge about OOP in general) and my arrogant, self-confident ass made the worst code to ever exist :^)
lol, i think we all did (am currently for me)
I'm sure my code could be improved massively as well tbh π
can i send you one of my classes, and you guys just ridicule me for whatever is bad
?paste
Don't need the else statement
i thought so, (pretty sure i got that from codedred)
if (!(sender instanceof Player)) {
sender.sendMessage("Only Players can access this command!");
return true;
} else {
This one
oh
That's not needed
why tf did i use to name my command handler "CommanderKeen" π
lol
Formatting the code would of been nice too π
-<
Can't really see anything else wrong with the code, and fuck gui's
lol
by design a gui, i mean make it look nice
im using an easy gui creator
basically
Inventory Framework
yo any idea why this isn't working? I'm getting a Failed to deserialize object error https://hatebin.com/ebnhfgbwcl
full error?
woah
the bytes look like such so its not like an empty array being passed in https://hatebin.com/cuqipdiudp
https://imgur.com/kWrBYQk this one
cant paste images sorry
result.add(CastingUtils.confidentCast(bukkitStream.readObject())); //read serialisable (size times)
Was about to say, could of just sent the line as text π
is there a reason not to use color.TranslateAlternateColorCodes
yea but then the rest of the context is gone
Break up the line and see what is null. Is it the object?
yea its readObject()
the only thing null in here is w/e Bukkit is trying to read though, deep inside readObject
but that should just be whatever was written by bukkit in serialiseToBytes
Do all the objects you are saving correctly implement ConfigurationSerializable, and they are registered?
all the elements I pass to the serialisation function just do this:
@Override
public Map<String, Object> serialize() {
return stack.serialize();
}
is this the problem?
oh I had no clue we had to register them lol
Yep, have to register the classes.
GWA
ChatColor.translateAltern...*
is there a good way of registering them without having to do it in a manager class or something
I mean, the world has slowly been moving away from the legacy strings but if you wanna just use strings translateAlternateColorCodes is fine
components pog
Alright
without having to do it in a manager class or something
huh?
declaration: package: org.bukkit.configuration.serialization, interface: ConfigurationSerializable
Top tells you how to correctly implement
kyoris' or md_5's?
sex
Kyori π
+1
ye I mean registerClass still needs to be called somewhere, and ideally each class would register itself but idk if there's a smart way to make that happen
hex pog
B
idk how to use it in mc tho
with magic
if all your classes are in one package you could simply grab all members of teh package and register them
alright i need opinions
private static int SERVER_VERSION = -1;
public static int getVersion() {
if (SERVER_VERSION != -1) {
return SERVER_VERSION;
}
SERVER_VERSION = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]
.replace("1_", "").replaceAll("_R\d", "").replaceAll("v", ""));
return SERVER_VERSION;
}
public static String colorize(String string) {
if (getVersion() >= 16) {
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
for (Matcher matcher = pattern.matcher(string); matcher.find(); matcher = pattern.matcher(string)) {
String color = string.substring(matcher.start(), matcher.end());
string = string.replace(color, net.md_5.bungee.api.ChatColor.of(color) + "");
}
string = ChatColor.translateAlternateColorCodes('&', string);
return string;
}
return ChatColor.translateAlternateColorCodes('&', string);
}
yeeeeeeeee
hm that feels kinda hacky, maybe I should use a different serialiser
well you can just
public class SomeClass implements ConfigurationSerializable {
static {
ConfigurationSerialization.registerClass(SomeClass.class);
}
// ...
}
always weary of using static but if it doesnt break stuff then sure π
is all static code executed before main runs?
or the first time the class gets referenced
this, yes
wrap the url in <> π so <https://imgur.com/a/UZchlfy>
and it won't attach the embed
\π³
\π³
right
im dumb
\π³
anyway https://imgur.com/a/UZchlfy
does look good?
im gonna make the NBT ITEMS look obfuscated
with the .magic
its just not working rn
i think i put it out of order
is this like an in-game gui builder?
is it loot crates
so you dont have to use the config
no
good lol
ig it's good lol
alright
im not changing it
eyyyy
made it work
ill probably make that not bold
ayy got recipes working in my multiblocks, thanks for the help π
Should I sleep
You can sleep when you are dead
UK then
Ye
which one is easier to set up bungeecord or velocity?
?8ball should I sleep
Yes
Waterful
I think they all setup the same tho?
aight
Um btw little tip if Ur having more than 2k players u probs should have multiple bungees and hook them up to together
To balance the load
I tested 1 waterful bungee and used 2k fake players and the bungee crashed
XD
It had 10gb ram to
Well my friend tested
And it was his bungee lol
it only crashed at 2k?
Ye
I mean normal bungeecoord does worse
Is it just 1 proxy
Or multiple
Lol
Lol
I mean the users where like fake players and all but also they where joining pretty fast probs that's why it crashed
ig that could be a cause
It was like atleast 1 player per like 2 ticks
alright that makes sense in that case
but
does bungee have ticks?
or just are you using that to measure
Ticks is a time in mc lol
alright ur just using that as a measurment
Every like 0.1 seconds I think a new fake player was like joining
Cuz 1 MC tick in seconds is 0.05 seconds
1 tick = 1/20th of a second
Ye
yeah ik n stuff
Online it says 0.05
(n*(1/20)) < calculates ticks in seconds n = ticks
I think that's how u do it
Lol
Assuming it is running at 20tps
Eh
I mean
Yeah I guess but technically it converts ticks to seconds
It isn't meant to accurately give it in seconds depending on tps
servers ideally should be at 20tps, this equation assumes the ideal
Will this work (ticks*(1/20)+(20-tps)))? To get ticks to seconds by tps
Probs not
XD
why 12.2 spigot playerDeathEvent doesnt have getKiller?
event.getEntity().getKiller()? Or
event.getPlayer().getKiller()?
??
That's how you get the people who killed the player
what does getPlayer() return?
Yeah I think in newer version they added .getKiller to the event I think but in older version u have to do this
I cant understand why player instance has getKiller() sry
It does
Cuz the player stores who kills it
That's why they have a getKiller
Actually its livingentity that has it but player extends livingentity so it inherets getKiller
oh
It returns a player XD
My phone is lagging
Oof it sent my message 3 times
XD
thx
When will version 1.17 come out for spigot is it the same day as vanilla?
?eta
There is no ETA. Having an ETA leads to unrealistic deadlines, false hope, and a bad product. It will be ready when it's ready.
?1.17
There is no ETA. Having an ETA leads to unrealistic deadlines, false hope, and a bad product. It will be ready when it's ready.
Probs not maybe like 24-48 hours after release of 1.17 but idk I'm just a user
?1.17
There is no ETA. Having an ETA leads to unrealistic deadlines, false hope, and a bad product. It will be ready when it's ready.
π
Hey! I would like to know if there is a certain item somewhere in the player's inventory. I know that this can be done somehow with inventory.contents, but I don't know how exactly I could apply this. Can anyone help me with this by chance
so i don't need a For loop? i just need to enter this line?
how would the line have to look exactly then? I would write the following: player.getInventory().getContents().contains
and where would I have to specify the item that is being searched for?
i believe that contains(Material.OAK_LOG); returns true or false
if it exists or not
how do you mean that?
so I would like to query if a player has 4 iron bars in inventory but don't know how to do that
u have to do java if (player.getInventory().getContents().contains(itemstack)) { ur code }
when I do this I get the error for contains:
cannot resolve method 'contains' in 'Itemstack'
I have done that. I have written in there Material.IRON_BARS
what a disaster this is
idk
i like coding
what happened lmao
just reading this channel
lol what specifically i just got here
no it still gives the same error from
this guy that somehow doesn't seem to understand the inventory contains bit
idk
i never really messed with checking inventory contents
i dont do inventory stuff
lmao people are new let em learn
aint calling it a "disaster" gonna help
ok but thanks anyway
if(e.getPlayer().getInventory().contains(Material.DIRT)){
dude has dirt
}```
@burnt current
ok i will try
oh I just see, I already saved a player as a variable: Player player = (Player) event.getWhoClicked();
I pass the variable event at the beginning of the method as InventoryClickEvent.
Β―_(γ)_/Β―
ok now it seems to work. I thought you needed getContents for that but apparently you don't need that after all.
and then how could I still check if the player has at least 4 iron bars in the inventory in that case?
Question:
Can I use TextComponent in Minecraft 1.8? I have the problem that the function "player.spigot().sendMessage(myTextComponent)" does not seem to exist in Minecraft 1.8.
At this point googling might save you time
ok and what would be smart to google in this case?
spigot check if player has x amount of y
'spigot inventory contains at least item' second result gives the exact method for me
Ok thanks for your help
as does first
yeah I don't see why you wouldn't look it up before asking here
π
Just to be sure:
If I understood you correctly, the spigot API should be included in my jar. Wouldn't this mean that the plugin will be very large in terms of memory? So from a few kbs to several MB? Or have I misunderstood something there?
no I mean check your IDE is referring to spigot-api
spigot-api as your jar is for the IDE
you don't compile it with the jar, the plugin uses the server's jar at runtime
the method you want existed as far back as 1.7
wtf are u using a server jar for a plugin u have to use the spigot-api jar
lol
oh man ```default ClassName() {
}``` isnt a allowed ;-;
default is for interfaces
ik
:?
?:
what would a default class be then
π
i do
I restored IntelliJ idea's settings to its default, but then all my recent projects tab were wiped out, i tried opening them and it ended up like this
nvm i cant send pics here
Verify 
or don't, just won't be able to self the pics
help!
i restored intellij's idea's settings to defaulted options!! but then all my recent projects were wiped out!!!!! i tried opening them in my plugisn folder and it ends up like this !!!
it is saying no symbol for kitselector etc.e tc. !!
but when i crete spigot plugin using inecraft devleopment plugon it works fine
hello!, can whitelist msg have multi lines?
you would probably have to remake the whitelist command if you wanted that
as far as i know
oof
i mean not remake it
but make a seperate command
wait no
i guess you could use the onCommand event
then send messages w/ that
is ther a finishd plugin?
idk
idk but you can use Holographic Extension
ok ty
That formst will cause errors if someone posts a %
And also follow naming conventions for vars please
Image about it with a link to that thread
is there a way to set pathfinder goals in spigot? or is it only NMS
thanks
Heyo - Seem like if I hit one of my hotbar keys like 1 to put items into an inventory such as atest, the InventoryMoveItemEvent doesn't get fired
InventoryClickEvent
Yeah, there I also do ```java
if (e.getClickedInventory() != null && e.getClickedInventory().getType() == InventoryType.PLAYER) {
e.setCancelled(true);
return;
}
Could someone help me with potions. The potion that this gives just doesn't have levitation:
public static ItemStack leviPot = new ItemStack(Material.POTION, 1);
public static void init() {
leviPot = setLeviPot(leviPot);
}
public static ItemStack setLeviPot(ItemStack i) {
PotionMeta m = (PotionMeta) i.getItemMeta();
m.addCustomEffect(new PotionEffect(PotionEffectType.LEVITATION, 200, 4), true);
return i;
}
oh wait
shoot
forgot to set item meta
srry
π₯΄
Is this solved?
Also, does anyone know how to immediately summon a firework explosion
i wanted to know if there was a way to amplify slime block bounce each time
is it possible even with spigot?
org.bukkit.scoreboard.Scoreboard score = p.getScoreboard();
Objective health = score.getObjective("showhealth") == null ? score.registerNewObjective("showhealth", "health") : score.getObjective("showhealth");
if (health.getDisplaySlot() != DisplaySlot.BELOW_NAME) health.setDisplaySlot(DisplaySlot.BELOW_NAME);
health.setDisplayName(replaceChatColors("&cβ€"));
p.setScoreboard(score);
is there a solution to this also applying the health effect to NPC's (of those with metadata 'NPC' if that helps)?
it's not meant to, it's only supposed to apply it to players\
Have you tried adding the NPC's to a different scoreboard?
If that doesn;t do it then it likely can;t be done as NPCs are just fake players
its possible tho the tab plugin does it
they're citizens npcs
so i'm not sure if i can control that
hypixel and almost every other server pulls it off
so i just feel dumb
for still having this issue
is it open sourced
bc i don't wanna use another plugin
lol
Can anyone help me with this?
It uses nms to change the tab list etc
If I cancel the task of a scheduler does it immediately stop or finish everything till it is at the bottom again and stops there then?
Hi there! Metadata won't clear. What I should do to fix it
p.removeMetadata("camouflageCD", plugin);
p.sendMessage("===========");
p.sendMessage(p.getMetadata("camouflageCD").get(0).asBoolean() + "");
p.sendMessage(p.getMetadata("camouflageCD") + "");
p.sendMessage(!Utils.hasMetadata(p, "camouflageCD")+ "");
p.sendMessage(Utils.hasMetadata(p, "camouflageCD")+ "");
Anybody know how can i disable going left and right?
hey kid I heard you like APIs so I made an API for your API's API https://hatebin.com/zbqdrwmkog
PlayerMoveEvent in your disposition
I still don't know if those are 100% accurate
these things are documented in a weird way
we broke up with my friend and we will transfer the plugins we bought to a different account can anyone help me about this please
no
friendship ended with friend, now other friend is my new friend
what does Utils.hasMetadata do in the first place
public static boolean hasMetadata(Entity entity, String metadata) {
return !entity.getMetadata(metadata).toString().equals("[]");
}
@quasi snow
why.....
$5 says there is an entity.hasMetadata already
because. I know about p.hasMetadata()
k so?
why don't you use that instead
removeMetadata doesn't works
not in Utils.hasMetadata() problem
why are you relying on the super unreliable toString implementation that can not even do what you expect
why don't you just, y'know, use Entity#hasMetadata
as you are supposed to
using the API? we don't do that around these parts
open your eyes
then why don't you use it
as you are supposed to
removeMetadata doesn't works. Problem isn't in Utils.hasMetadata. I'll be use p.hasMetadata in future.
why do you insist that it doesn't work when getMetadata returns false
how are you so certain
plugins have been using this metadata API for literally ages, I really doubt it's broken
if (p.hasMetadata("camouflageCD")) returns true
p.removeMetadata("camouflageCD", plugin);
if (p.hasMetadata("camouflageCD")) {
p.sendMessage(String.valueOf(p.getMetadata("camouflageCD")));
return;
}
is there a method to figure out if the player is riding a horse?
I can't find it
i have some problem in sethome and it say only admin can sethome is there any good plugin that i can use?
permissions, #help-server
well idk what you're doing but this works fine for me https://paste.lucko.me/PIqgRUh79x
what do you plan on doing exactly?
en pee see when
very strange
can you share the rest of the code?
implements Listener, not extends Event lol
extends Event is for when you make an event of your own
oh xd
you shouldnt need to cast the class to Listener if it's done correctly
How do you guys debug stuff? I find that adding a new print to the plugin then recompiling, etc is a bit annoying, is there like a debugger for spigot or smthn?
that's extends
oh lmao
not what i said to do :)
System.out.println()
p.sendMessage()
Bukkit.getLogger().info()
Bukkit.shutdown()
you dont have to debug if you dont make any faults π
thats some 10000iq thinking there
or just ignore them π
you need to pass the plugin instance though, the metadata value takes the plugin instance and removeMetadata also takes a plugin instance (these highlighted here)
empty exception handlers and you r good to go
That would be noticing them, don't even do that.
ah, I didn't finish it, but I'll try again
p.removeMetadata("camouflageCD", getInstance()); doesn't work too
i get that, but recompiling and moving the plugin n stuff is much more painful than some debuggers for other things
what do you mean "store custom stats"? can't you do it in a List or a Map or something?
well you can attach a jvm debugger to the running java instance if you really want to have a deep look into things (field/variable values, current stack frame, etc), but keep in mind you'd need to crank up the watchdog time or whatever in spigot.yml so it doesn't kill the server if you're paused on a breakpoint hhhhhhhh
idk how old these are but
https://www.spigotmc.org/wiki/intellij-debug-your-plugin/
https://www.spigotmc.org/wiki/eclipse-debug-your-plugin/
what kind of stats, why do you need a player for this
I add debug messages that print to the console. Just gotta remember to remove them later.
There's been a few times where what I'm working on is pure java so I created a console application and dropped in just the relevant code so I was able to debug it in real time
the Bukkit API isn't really meant to be extended with the exception of commands and events
thanks!
public class CustomPlayer {
private Player player;
public CustomPlayer(Player player){
this.player = player;
}
public Player getPlayer(){
return player;
}
}
._.
good ol' composition
storing the player π€’
Gotta better solution?
UUID
I mean storing the player is fine just make sure you weak refrence it
True, the getPlayer would then have to be changed to a Bukkit method then.
I'm assuming @quaint mantle here is gonna use said field as well, don't wanna be calling getPlayer all the time
Hey we are using Packets to remove players from the tablist, we implemented a fix which adds the player back for a duration of 30 ticks when sending the named_entity_spawn packet to the player, it works fine BUT most of the times the players are steves or alex's is there a way to fix that?
how can I stop a parrot from randomly flying? I tried to override its pathgoal but without success.
same problem
disabling ai π€
No, I still need to code a custom pathfinder.
I just need to stop the parrot from randomly flying, removing the AI will freeze it.
how do i change entity speed?
If I cancel the task of a scheduler does it immediately stop or finish everything till it is at the bottom again and stops there then?
i need help here
it will run until it hits a return statement (or "hits the bottom" if it doesn't explicitly have one)
cancelling a task tells the scheduler to not run it again, it doesn't exit the function
okay thank you and a other question: is it normal that my PlayerInteractEvent gets called 2 times everytime?
change the base value of the GENERIC_MOVEMENT_SPEED attribute, I'm sure this will help https://www.spigotmc.org/threads/help-with-attributes.461710/
on right click?
yes
no one? π¦
if (event.getHand().equals(EquipmentSlot.HAND)) {
But I did this already
how can I prevent it from being called 2 times?
well uh... what's the rest of the code?
what have you tried
people, sharing code helps us help you π
There is a lot I know but I wrote I comment what gets called twice
why not putting two times HashMap?
ping me then pls thank you
because TASKS could be any kind of Map implementation, HashMap, TreeMap, EnumMap, etc; how it actually works is implementation detail, and if, during runtime you want to change the type of map (or maybe you let another plugin provide one), you can just pick any kind of map, not a specific implementation one; this is Liskov Substitution Principle
https://stackify.com/solid-design-liskov-substitution-principle/
sometimes
oh
well yes, the event itself will fire twice, but in your case you might want to add the getHand check at the very beginning of the event handler, like if (event.getHand() != EquipmentSlot.HAND) return;
(also, for enum constants (such as EquipmentSlot) use ==/!= (just like you do with the Material))
oh okay thank you alot
.ETA
?eta
There is no ETA. Having an ETA leads to unrealistic deadlines, false hope, and a bad product. It will be ready when it's ready.
if (player.getBrain.contains("anything")){
player.graduate;
}
shouldn't line 2 end with a semicolon
yea my bad
im tired
I'm unsuprised
How do i change it? i tried entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(3); its working for player but not for entity
entity prob is casted to a Player
are you sure you have the right entity selected? or maybe it is in the wrong form
I had to do LivingEntity
thanks its working
Neato
How can i change nbt tag to spawn horse with saddle
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
π₯
apparently you might need it to be set tamed first
and how do i do that? πΆ
horse.setTamed(true);
thanks
The javadocs will tell you all of this
or you can just look it up
There is already a forum that did that exact thing-> on spawn equip saddle on horse
Thatβs what the javadocs are for
huh
You look things up
yes
On the javadocs
does anyone know how to change the render distance for just the nether? could i make a plugin to do that or would i have to run the nether on a seperate bungeecord server
I would use something like view distance tweaks
Itβs a nice plugin to have in general
or use paper
i think spigot.yml lets you change the view distance on a per-world basis as well
ok so i made an api which works but im looking at it and want to make a full rewrite of it
before i would log everything so when the player logged off i could still check things like armor and health
now im just going to check the nbt
does the nbt update all the time though?
does anyone know the code for clearing the java console that works for all oses?
like would i need to check if the player is online and only check the nbt in order to get a live stat
Hey guys, I'm new to async programming and have run into a dilema, maybe you can help me:
-
On chunk load, I Asynchronously load information pertaining some blocks into a memory map.
-
I also have a block break event listener, that gets & uses information from that memory map.
-
How can i make sure the asynchronous task for the chunk is done before getting/using that information inside the block break listener?
Should i keep a list of unfinished chunks, add to that on chunk load, and remove with a callback when the info loading is done?
instead of holding a Map<Key, Data> as your "memory map"
hold a Map<Key, CompletableFuture<Data>>
Hello! I am currently writing on a minecraft plugin that connects a discord bot to the server.
I am trying to add a json file for easy configs but it gets overwritten on every reload/restart.
My onEnable calls this:
config = new Config(new File("plugins/ntstreakyDiscord/ranks.json"));
and this is the Config class:
when the chunk loads, you create a new completable future, and put it in the map
you then fire the logic that will get the actual data, that is, complete the completable future, on a different thread
when you need to access this data, first get the future
map.get(key)
then, on the future, call future.get()
if the future is complete, the data is returned immediately
public class Config {
private File file;
private JSONObject json;
private JSONParser parser = new JSONParser();
private HashMap<String, Object> defaults = new HashMap<String, Object>();
public Config(File file) {
this.file = file;
reload();
}
@SuppressWarnings("unchecked")
public void reload() {
try {
if (!file.exists()) {
PrintWriter pw = new PrintWriter(file, "UTF-8");
pw.print("{");
pw.print("}");
pw.flush();
pw.close();
}
json = (JSONObject) parser.parse(new InputStreamReader(new FileInputStream(file), "UTF-8"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
if the future is not yet complete, the data will be returned when the future is completed
@SuppressWarnings("unchecked")
public boolean save() {
try {
JSONObject toSave = new JSONObject();
for (String s : defaults.keySet()) {
Object o = defaults.get(s);
if (o instanceof String) {
toSave.put(s, getString(s));
} else if (o instanceof Double) {
toSave.put(s, getDouble(s));
} else if (o instanceof Integer) {
toSave.put(s, getInteger(s));
} else if (o instanceof JSONObject) {
toSave.put(s, getObject(s));
} else if (o instanceof JSONArray) {
toSave.put(s, getArray(s));
}
}
TreeMap<String, Object> treeMap = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
treeMap.putAll(toSave);
Gson g = new GsonBuilder().setPrettyPrinting().create();
String prettyJsonString = g.toJson(treeMap);
FileWriter fw = new FileWriter(file);
fw.write(prettyJsonString);
fw.flush();
fw.close();
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
public void addRankRole(String rolename, String roleid, String permission){
JSONObject obj = new JSONObject();
obj.put("Role_ID",roleid);
obj.put("Permission",permission);
defaults.put(rolename,obj);
save();
getRanks();
}
public String getRawData(String key) {
return json.containsKey(key) ? json.get(key).toString()
: (defaults.containsKey(key) ? defaults.get(key).toString() : key);
}
public String getString(String key) {
return ChatColor.translateAlternateColorCodes('&', getRawData(key));
}
Use the saveResource method
public boolean getBoolean(String key) {
return Boolean.valueOf(getRawData(key));
}
public double getDouble(String key) {
try {
return Double.parseDouble(getRawData(key));
} catch (Exception ex) {
}
return -1;
}
public double getInteger(String key) {
try {
return Integer.parseInt(getRawData(key));
} catch (Exception ex) {
}
return -1;
}
public JSONObject getObject(String key) {
return json.containsKey(key) ? (JSONObject) json.get(key)
: (defaults.containsKey(key) ? (JSONObject) defaults.get(key) : new JSONObject());
}
public JSONArray getArray(String key) {
return json.containsKey(key) ? (JSONArray) json.get(key)
: (defaults.containsKey(key) ? (JSONArray) defaults.get(key) : new JSONArray());
}
public Object[] getRanks(){
return json.keySet().toArray();
}
}
But is that json support?
Awesome, i think i got it @wraith rapids
which means that the main thread will be blocking on this method until the data is ready
Yep
I read that I would need to do it in another way
Yeah, but that pretty much can't be prevented
which is undesirable, but there's not really any way around it
if you need the data you need the data
Just include it in the jar
right
Okay thanks, I will try after I ate
Thanks a lot that really helped
Okay thanks
Umm where do I call the method?
https://hastebin.com/zoyotokofe.typescript can you tell me what to change to make it compatible?
How to remove players from online players?
Kick the player?
Nope, vanish
Player::hidePlayer
oh lol thats way simpler
might be paper only, dunno
Hey guys, I know this is the SpigotMC server, but since they're so similar to Spigot plugins, would it be okay to ask for help on a BungeeCord plugin? If not, where should I ask?
Maybe entity.setVisible(false)?
Okay, thanks
bungee is developed by the same people pretty much
Main class
see the channel description
Ah didn't see that
okay then
Here's my main class, it does print that onEnable ran when I start my BungeeCord server, but when I kick myself, it prints nothing. Is there something I'm doing wrong?
package net.GlitchedBlox.GlitchedBloxBungeeCore;
import java.util.concurrent.TimeUnit;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
public class Main extends Plugin {
private Main plugin;
@Override
public void onEnable() {
this.plugin = this;
System.out.println("onEnable ran!");
}
@EventHandler
public void onKick(final ServerKickEvent event) {
System.out.println("Player kicked!");
final ProxiedPlayer p = event.getPlayer();
if (event.getPlayer().getServer() != null) {
System.out.println("Player in server!");
if (!event.getPlayer().getServer().getInfo().getName().equalsIgnoreCase("hub")) {
System.out.println("Player not in hub!");
event.setCancelled(true);
plugin.getProxy().getScheduler().schedule(plugin, new Runnable() {
@Override
public void run() {
System.out.println("Player moving code called!");
p.connect(plugin.getProxy().getServerInfo("hub"));
p.sendMessage(new TextComponent(ChatColor.AQUA + "Oh no! You've been kicked from " + ChatColor.GOLD + event.getKickedFrom() + ChatColor.AQUA + " for " + ChatColor.DARK_RED + event.getKickReasonComponent() + ChatColor.AQUA + "!"));
}
}, 1l, TimeUnit.MICROSECONDS);
}
}
}
}
i don't know how the bungee event bus works, but on bukkit you'd have to have your class implement Listener, and register it with the plugin manager
hmm let me check if adding "implements Listener" fixes it
totally forgot about that
Nope
doesn't do anything.
Still doesn't say "Player kicked!"
google "event listener bungeecord tutorial"
dope
ty
Make sure you actually register the event. You might have created a listener class, but if you don't let spigot know that it has to use it, nothing is gonna happen
how could i manage hoppers? for example set the amount of items moving unsing the move item event or set the destination to another location or hopper
some API
or premade methods
Check if spigot has an event for it of some kind. Usually googling spigot event javadocs or something like that will yield you the results you want if you explore them
theres an event for that
its called itemMovementEvent
There you go, use that one π
You probably have to get the target container, cancel the event
yes, i already tried but it doesnt really thave that many things to use
and then change the inventory of that container
theres no such thing as setDestination or a way to set the amount of items moving to X in that location
Probably not
so the only way would be to cancel the event
take the item moving
take the item stack in the hopper
remove it
and add it to another location
but theres a bunch of problems with that logic
i already tried and its not ment to do that
so for example doing that i takes the amount - 1
i assume its becausue theres already 1 moving
so if you only have 1 it returns null
unless theres another one of those
so i was wondering how do people do plugins using this
InventoryMoveItemEvent::setItem
The one stop marketplace for all the Minecraft plugins you will ever need.
like this one
What should I take as path?
using "plugins/ntstreakyDiscord/ranks.json" doesnt work
The embedded resource 'plugins/ntstreakyDiscord/ranks.json' cannot be found in plugins\ntstreakyDiscord-1.0-shaded.jar
setItem would change the item moving from 1 inv to another
you should use the path it is at
if the file in your jar is at /mystuff/myfile.txt, then use mystuff/myfile.txt
Uhh but the file is not inside my jar
isnt it inside resourcess or smt?
No I want to create a json file and then be able to edit it. But after every server reload it gets overwritten with an empty one.
You have to include it it jar - itβs the source file path not output
either include it in the jar and extract it, or write to disc programmatically
I've never done this before. So like this?
getProxy().getPluginManager().registerListener(this, new Events());
assuming my Listener is in my main class
this, this
Actually it would be
getProxy().getPluginManager().registerListener(this, this);
right?
if you are running this in the main class and your event handlers are on the main class, then this, this
oh you said what I was thinking lol
one this is your plugin instance the other one the event listener
You should really separate your plugin in classes though
specially if you are new to programming
otherwise you won't understand what you are doing
and debugging and code changes will be a nightmare
Well it didnt change anything for me.. yes I wrote it to disk programmatically but after reload it is getting overwritten like before
well, if don't overwrite it if it's already there
https://hastebin.com/zoyotokofe.typescript But I dont let it overwrite anywhere
Why is my git appearing as "Buildtools"? How to revert this?
(sorry, I don't understand much about git) (and if that's offtopic pls tell me)
Yeah that happens you will have to login again
How do i 'get' the main thread in order to call an event
BukkitRunnable
Oke
It works! Thank you!
And to this note, I'm not new to plugin development or java, I just have never made a listener. I only didn't separate it because I literally have 35 lines of code, just putting a player in the lobby when they are kicked from another server with a few other cases. I have my main plugins on my Spigot servers super separated, each command even has it's own class.
don't use a bukkit runnable for that
use the bukkit scheduler
less overhead, more readable, doesn't shit up your project with anonymous local classes
yeye, thats what i am doing ^^
I'd like to get the bungee API kick reason, but
event.getKickReason()
is depreciated, and
event.getKickReasonComponent()
doesn't have a method to get the kick reason. How should I get it?
I can't find any other funtions
one returns a string
the other returns a component
a component is just a fancy string with formatting and shit
Yes, but I don't know how to get the string from the component.
toString or use the legacy/plaintext serializer
would I just be able to use .toString()
got why do I keep typing the same thing people say right after them
it'll probably do something like TextComponent[blah blah]
yeah
you should use BaseComponent#toPlainText to get the contents
okay
Yep, this works! Thank you!
Fefo helpful 
Fefo
sadge
help plzzzzzzzzzzz
i have a loc meneger i have multi loc's
and some of the loc's world are null
how to make it not null
code
error
Okay I fixed my Json Bug I think
Oh yeah Emily**
Now I have another Problem...
Config conf = Main.getInstance().config;
conf.reload();
String[] ranks = objectToStringArray(conf.getRanks());
System.out.println("hi");
ResultSet rs = sendStatement("SELECT * FROM DiscordTable");
System.out.println(ranks.length);
for (int i = 0; i < ranks.length; i++) {
System.out.println(i);
JSONObject ob = conf.getObject(ranks[i]);
System.out.println(ranks[i]);
try {
System.out.println(ob.get("Permission").toString()+"\n"+rs.getString(1));
if(Bukkit.getServer().getPlayer(rs.getString(1)).hasPermission(ob.get("Permission").toString()));
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
This Code should throw 14 times println if the ranks.length is 4 right?
[20:24:29 INFO]: hi [20:24:29 INFO]: 4 [20:24:29 INFO]: 0 [20:24:29 INFO]: Discord.RSS [20:24:29 INFO]: rss e0a683b3-10f7-4190-b48a-2cb4cb6b0631
But it only executes the for loop once...
i need helpeeeeeeppppppppppppppppp
Don't spam please, people will help you even if you don't spam
I'm trying to help you
ok
why doesn't it extend or implement anything?
what
it's ok
what does this do?
return Utils.color(Main.getConfiguration().getString("messages.no-permission"));
gets the color from messages.no-permission in the config file
Location event = LocationManeger.getLocation("event");
player.teleport(event);```
this is how i get loc
It doesnβt get the color but it probably just turns & into Β§
Why not? Isn't that what Utils.color does?
You have a typo in "Maneger" (should be Manager)
The configuration file
His class is called LocationManeger
It returns a string not a color
ow yea a see
Yes and it should be LocationManager π
But that's not where the error comes from
Yes I know
huh must have looked at the wrong Reference, thought it returned an actual Color
myeah
help?
What was the issue bud?
.
I can't figure out without all of your classes, I don't even know what code the error is coming from
Your call Bukkit#getWorld returns null precisely due to no world with the given name being present
that's a weird path tho...
lobby-name-world: TrestiaMap
event-name-world: TrestiaMap
you should be able to simple config.set(path, location) and config.getLocation(path)
the path key does not include the colon (:)
but this tbh ^