#help-development
1 messages · Page 1602 of 1
The things is I don’t like how long it actually takes to “receive” the item since it has to connect to db
Yes, so decide if your timers need to persist over a server start?
Anyways. Databases are usually needed if you have multiple server instances running and every instance needs the same data as the other servers.
By persist do you mean transfer over?
yes, so someone is waiting on a timer. do they still need to be waiting after the server restarts
be the same
Persisting means that it does not vanish when the server shuts down
ok it persists, so you need some form of database for it to persist
sql is slow
if timers are based on a single server the fastest would be flat file
well NBT-tags/PDC would be fastest. Next is flat file
also NBT tags means no database or file management for you
was trying to understand the nbt api thing
7smile7 explained it for ItemStacks. Its identical for Player objects
yes, Player is an Entity
NBTEntity nbtent = new NBTEntity(player);
//set
nbtent.setInteger("kitCooldown", time);
//get
if (nbtent.hasKey("kitCooldown")
return nbtent.getInteger("kitCooldown");
else
return 0;```
very simple
don't I want time as a long?
yes, was just an example
nvm
so essentially if I did nbtent.getLong("kitCooldown") it would return the time for kitCooldown
@lost matrix
F
You cant
Then how does it not have meta..
It has to have an ItemMeta
But it doesnt, im getting an error saying the meta is null
Show the whole code and stack trace pls
Ok
its a shit-show since i started this as my first project so a lot of it is unorganized, give me a minute
hmmm
hang on a sec
now its just not working since i added a check if its null, or air
Just show me the code section and ill give you some spots where you can add debug messages
ok, i added a log to the thing and this is what i got
ok
blocks:
- null
- ==: org.bukkit.inventory.ItemStack
v: 2730
type: AIR
amount: 0
- ==: org.bukkit.inventory.ItemStack
v: 2730
type: BIRCH_PLANKS
this was in my yaml file even though all i added was an itemstack
heres the code
?paste
type: AIR
he told you earlier AIR has no ItemMeta
i just said that idk why air is there
but it shouldnt matter since air wasnt there when i was talking earlier
line 12 will never be null, but the Item could be null
an ItemStack will always have a type
I would just prevent any null or AIR items from being added to the list. This will probably resolve all your problems.
huh, true
but an ItemStack can be null
i removed the .getType() == null
i already am
if (item == null)
return;
if (item.getType() == Material.AIR)
return;
line 33 if(i.getType() == Material.AIR) continue;
Yea, i added that so if it is air, ignore it
yep, just use == not .equals
oh
i was told by multiple people to use .equals
i had a ton of issues with == for comparing objects'
not to compare enums
Usually you would want to use .equals()
Just not for primitives and enums
objects you compare with .equals
Ok
There are some occasions where you would want to compare objects by == but they are quite rare
like comparing Inventory instances use ==
let me try it out rq
ok
so
it kind of works
but idk why its doing what its doing
gime a sec to explain
but you still can use .equals()
Not sure if this is basic or not but was never taught this. Is there a way to call a object in 2 different methods but the objects getting the same values that was added from another method?
Huh
I dont even remotely understand what that means...
I click with a block, and it gets the event.getCursor() then it runs these 2 lines
plugin.reloadGuis();
plugin.blocksGui.show(event.getWhoClicked());
this should reload the gui to allow it to have the new block, then show it to the player. but for some reason the block does not appear in the gui. But if i restart the serve or do /rl it does show up?? (plugin.reloadGuis is in the onEnable)
I think you can figure that out by just adding a bunch of debug messages and following the breadcrumbs
but the thing is
its the same...
its just the reloadGuis
i have no idea where i would put the messages
In reloadGuis() for example.
Did you call a Player#updateInventory()?
public void reloadGuis() {
webhookGui = guiClass.createWebhookGui();
commandsGui = guiClass.createCommandsGui();
punishGui = guiClass.createPunishGui();
adminGui = guiClass.createMainGui();
settingsGui = guiClass.createSettingsGui();
blocksGui = guiClass.createBlocksGui();
}
would i have to?, im removing the inventory, and showing it to them again
i never had to do this before and it worked fine
And it doesnt update?
Not if you are showign them a new Inventory
MyClass myClass;
public void myMethod(String name) {
myClass = new MyClass(name);
myClass.setName(name);
}
public String getName(String name) {
myClass = new MyClass(name);
return myClass.getString(name);
}``` something like this idk if that makes sense haha
no
I assumed you were just updating it
and if i close it
What happens if you close it and open it back again
and open it again
it still is missing
Thats why im confused
but if i reload the server
it shows up
the only thing affecting that
would be reloadGuis()
then you are not creating a new inventory
and that is in both spots
Then your methods use an old instance of your FileConfiguration
there is nothing wrong with this so far, but you are most definitely doing extra work
hmm
leme check on that
but wouldn't it not return the same value?
but when i take the item out it updates...
and when i add it it doesnt update
leme send the code for that
navigationPane.addItem(new GuiItem(item, event -> {
event.setCancelled(true);
if (event.isRightClick()) {
List<ItemStack> items = (List<ItemStack>) plugin.getConfig().getList("blocks");
items.remove(i);
plugin.getConfig().set("blocks", items);
plugin.saveConfig();
plugin.reloadGuis();
plugin.blocksGui.show(event.getWhoClicked());
}
removing an item
This makes no sense because every time one of the methods is called the "myClass" object would be a new instance all over again. Which makes it obsolete.
one return type is void, another is string, of course they wont return the same value?
background.addItem(new GuiItem(backGroundItem, event -> {
event.setCancelled(true);
ItemStack item = event.getCursor();
if (item == null)
return;
if (item.getType() == Material.AIR)
return;
List<ItemStack> items = (List<ItemStack>) plugin.getConfig().getList("blocks");
items.add(item);
plugin.getConfig().set("blocks", items);
plugin.saveConfig();
item.setAmount(0);
plugin.reloadGuis();
plugin.blocksGui.show(event.getWhoClicked());
}));
adding an item (this one doesnt work)
I should clone the item first shouldnt i
But how could you make it so it wouldn't make a new instance with it taking a field
just dun make the new instance then
I still dont quite understand what you want to achieve...
fk i misread
Is this what you want?
private MyClass myInstance = new MyClass();
public String getMyName() {
return myInstance.getName();
}
public void createRandomName() {
myInstance.setRandomName();
}
kinda but MyClass takes a field
yup it will, and you cant prevent that
Yes. Objects created inside a method are just thrown away as soon as the method is done.
the value has to be saved somewhere, and not in a method
This should never be a problem in an object oriented language
You can always pass one value from within a method to another by just calling it tho ^^
anyone know a tutorial on easy to understand custom config files for newbies?
if you're gonna say i need to learn java basics first, just don't
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
scroll down
oh ok thank you
Hello I am using token manager as my token currency, anyway to link these across bungee servers?
i'll try this, i might come back with some questions though
Uhm... doesnt it just have MYSQL support?
yes
So... problem solved?
can u send me the website for MySQL
I can't find it hehe
question: what's the difference between File variable type and FileConfiguration variable type?
for linux or windows?
you may want to look into java.io.File first
windows but I use a host
FileConfiguration is from spigot
and is specialized in helping you manage configuration files as the name suggests
A File represents a File on the hard drive. Its the basic java.io.File.
FileConfiguration is an in-memory representation of that file. So basically the data in the File was read and parsed into some sort of HashMap
What does that mean you use a host? On what machine do you want to install the mysql server? Linux or windows?
so File is the directory in the hard-drive and FileConfiguration is what's in it?
you dun have to know the latter
it is abstracted
Nope. File can be a directory or .txt file or even a .jar file.
FileConfiguration is just a glorified HashMap that contains the content of the File
alr i think i understand, thx
Do you know what a HashMap is?
how nice of you
well it is kind of basic
hashmap is a data structure that maps key to values using a hash function such that you can query its elements in O(1) time
what
You can think of it like a simple table with one column being the keys and one column being the values.
ohh right i remember now
And for each key you can store a specific value
To be fair, it seems like understanding maps is always a bit of a hustle for entry level devs
ok can i ask line by line on what this means
it is more algorithmic based, which prob most of them isn't interested in
on the custom config thingie article
You just have to understand how File works first
file is a directory or a file
is there a more accurate one?
and a file can be a directory
file as in java.io.File
No you cant
wat
the File can be either a directory or a normal file
it has methods for both
like listFiles
isDirectory
stuff like that
so it can be both a directory and a normal file
at the same time
You see with NBTEntity it requires a field when calling the object so that's why I was asking
so you can get a file from a directory but you can't get a directory of a file?
i've been programming in different languages for many years, and as frustrating as it is to try and explain something to someone who has little experience using the language, in my experience the best way to learn a new language is by using it.
no...
that isnt what i even said
I try to get in there and mess around
True. Just playing around with stuff helps so much understanding it.
Yes
I am saying the File class can be used to represent a directory or a normal single file.
if it is a directory, it has its own methods such as listFiles which list the files of the directory
you're saying or but also both
sigh
we are cursed with knowledge here
if you don't want to help, don't. you don't have to be rude about it
@lean gull I haven't been following this conversation at all really, but I can recommend a few great resources for you to help learn SOME of the basics
you really don't need more than an hour of work to learn the basics
the real basics
the codeacademy one takes like 22 hours i think
i thought codeacademy was paywalled
actually may need longer
there are quite a lot of basics
depends how dedicated you are
how consistent you are
and how quickly you can pick it up
imma just ask questions about this article, if you don't want to help then just don't and don't be rude about it please
I wouldn't recommend that someone start programming with Java
Python or even Lua is a good place to start for true beginners
I mean, I dunno python or how easy that is haha
imo of course
python, lua, and JS are all very similar
so you get a lot of usage out of learning one of them
With NBTEntity you need to do NBTEntity entity = new NBTEntity(Entity) but I wanna be able to use the object in multiple methods without making a new instance for each method.
Every python script ever:
import a_bunch_of_random_stuff as lib
lib.doTheThing()
so this sets the variable customConfigFile to a file/directory that can later be set to something
private File customConfigFile;```am i wrong?
this is a declaration
hence the "that can later be set to something"
Sure. This variable can hold a value later on
@lean gull my best advice to you: Find someone who knows Java well & is willing to give you their time to answer all your questions
im finding people like that here
you'll start picking stuff up, but if you don't want to go the traditional route that seems like the best idea
use a library for anything
ok and then this one declares without setting customConfig to what's inside the file
private FileConfiguration customConfig;```
inside what file?
well then
did i get that right
This is another variable you can store a value in later on
hence the "declares without setting"
Yes. Its declared but not initialized.
btw this thing has to be in the main file, right?
huh?
this method
what...
or methods
wut?
that's what i was told
method?
Nope. Nothing has to be anywhere. You can do whatever you want.
who the hell told u that
hahaha
tell us
dunt remember
we will beat them up
!
wtf Im doubting my years of experience
Maybe we were wrong all along. Maybe everything needs to be in a single class called "main"...
In all seriousness, this is a field by the way
yes i know
fields are outside of functions and inside classes, correct?
i mean methods
bump
Then just create a field containing the instance
On second thought... holding a hard reference to an Entity is not a good idea.
method is a method, nothing belongs there
what
it is a set of instructions on how to convert an input to output
Why do you want to use the same instance over again? For the nbt lib that makes no sense. You are meant to create a new instance of NBTEntity if you want to modify the nbt data of one.
confused confusing confusion
I’m making a method to set their cooldown time and one for getting their time
Sure. You can create a new NBTEntity in both methods. NBTEntity is just a wrapper class to allow access to the underlying Entity. The data withing the entity stays the same. Doesnt matter if 10 new instances wrapped it.
ok so anyway this just starts a method on startup, correct?
@Override
public void onEnable(){
createCustomConfig();
```
Yes. onEnable is called when the plugin is enabled. Then it calls createCustomConfig once.
when I do NBTEntity#setLong then in another method do NBTEntity#hasKey in a if statement it returns 0 even though it should be true
this lets you use the config from outside of the used class, correct?
public FileConfiguration getCustomConfig() {
return this.customConfig;
}```
Ah i see. NBTAPI only supports vanilla tags on entities
I think your problem is not knowing terminologies @lean gull
Well. You are on 1.8 anyways so good luck i guess...
But the entity im using is Player
Doesnt matter. Still an Entity and doesnt support custom tags.
this is a getter, yes
So then I have to use plain file then
How can I run a bit of code on a entity when it spawns?
Just when a mob spawns, do x to it
there is EntitySpawnEvent and CreatureSpawnEvent
Tried that
Does anyone know anything about this error?
https://media.discordapp.net/attachments/316208160232701955/869799525626282074/unknown.png
You're sending a String somewhere that's longer than the maximum (16)
I think that's what it is anyways
Doing anything with Scoreboards perhaps? I think it can happen there if you set a team prefix or something longer than 16 chars
Is there an event for a player setting their spawn? I know there is PlayerDeepSleep event but what I’m specifically trying to do is cancel the spawn set but still let night pass, plus a player doesn't need to sleep to set their spawn, it's just clicking the bed. One user directed me to use PlayerSpawnLocationEvent but that doesn't get fired on bed use.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getBlock() != null && e.getBlock().getType() == Material.BED) {
//
}
}
Bungee hard-limited usernames to 16 characters due to that being the protocol limit
So if you join with a (cracked username) with over 16 characters, it'll give you an exception
thanks, ill test around using that!
I don `t believe. On my Network, I never had this problem, until I updated my Bungee fork to 1.17 and ViaVersion.
Since then it started, but only in versions 1.8 - 1.12; any version 1.13+, does not throw this problem.
Also, I do not think that is what they comment, since the error occurs with practically any player, regardless of their name or prefix.
@wet jewel At what stage do they get it?
While logging in?
The settings packet is also hard limited at 16
It is random. But it happens, when the player enters or changes the server; for example when using / lobby or entering a mode / arena.
Though not always. You can change the server a thousand times and not happen or change the server 10 times and happen every time.
Yeah no idea then. The only two packets I can think of with a hard limit of 16 on a string is the LoginRequest (name), and the Settings packet
But both of those would only cause a problem when you're connecting to the server
So maybe a plugin issue
But both of those would only cause a problem when you're connecting to the server
Later, I was reading the possibility that it was the ScoreBoard; I tried taking it out and it persisted.
Besides that I use TAB and in that sense, it is friendly.
Now, I just updated ViaVersion from 4.0.1 (which is up to date); to beta version 4.0.2 and I think the incidents decreased; but they still exist.
I also tried updating LuckPerms (which in the past gave me some trouble adding support for new versions), and the problem has persisted.
@wet jewel You don't have a stacktrace inside of Bungeecord's logs?
That'd be helpful
@wet jewel Oh you know what
That's actually a client error most likely. So you're probably sending too large of a string
Like a scoreboard or teams variable is over 16 characters long
Or the PlayerList entry is over 16
Or worldType
forgive me but in the code of PlayerInteractEvent it seems as i can only either completely cancel it or let it pass? i still want players to sleep in a bed i just dont want the spawn to be set
@paper geyser You should look into Objects. That way you can just have one map.
Like:
public class YourObjectWhatever {
private int maxMama;
private int currentMana;
methods....
}
Makes java a hell of a lot less tedious
alright I'll look into it
How do you make the item not stand out? I wrote world#dropItem, but the item pops to the side. I've tried item#teleport, but it doesn't work.
droppedItem2.teleport(new Location(Bukkit.getWorld("world"), 51.5, 69, -54.5));``` (Not work)
hey im wondering how i can get all blocks between two points
obviously nothing huge
an area smaller than 50 blocks
i googeld a bit but the results i came with seemed to crash my server
what is the easiest way to get the nearest block that is not air from a location?what is the easiest way to get the nearest block that is not air from a location?
yes
?
yes is not a answer to this question or wdym
how can I spawn dropped item without world#dropItem?
How would i create a plugin that if i update one of the plugins in a list in the config, that it would see that and reload the server?
is it hard?
why do u want it without dropItem?
because the item pops to the sid
what?
item pops? sorry what?
hmm
item moves
I want item to stop moving
when it dropped
like when dropped it won't rotate?
Iterate outwards from a coordinate and stop the loop once currentBlock.isAir() is false. If your max range is high you might want to use chunk snapshots, but that's more work (in a similar case, I use a Map<ChunkCoordinate, ChunkSnapshot>, where chunk coordinate is a pair of ints x,y and the hash function hashes based on those variables. You can get a chunk coordinate from a block coordinate with a bitshift)
The item might have popped to the side because it was stuck in a block
and how can i Iterate outwards? with .add()?
Nah, probably not, depends how you define your distance
and how can i do it?
Well what's your definition for distance
Which block is closer to X:
A X B
C
A B or C?
AB obviously +
A or B
both
Which one should your program pick
it doesnt matter say A
You have to know in order to come up with the correct algorithm. More importantly for this case:
A B
C X
Is A equally close as B and C?
yes
If yes then it's easy, if not it's gonna be harder
No hehe
What about:
A B C
D E F
G H X
Is A equally close to X as C is?
Wait my bad wrong example
xD
yes it is
Okay then you can iterate outward in rings
Keep in mind this will favour corner blocks
Like A
i just want to throw a snowball and where the snowball hits it should create a "blob" of red blocks around it
Ah so it needs to choose multiple blocks
It wouldnt be round
with add or what?
Based on your definition of equally close
Does it matter if it colours blocks through walls
Like:
A B C X
C is air, X is snowball, A and B are solid
Should A be coloured too or only B
A and B
oh sry then no
a bit randomly like a blob
Randomly needs a definition
e.g. the further out from the impact point the smaller chance to be coloured
idk
yeah
This would give an effect like a spray can in MS Paint
yeah
How big will the blob be
it should be a paintball plugin
the most coloured blocks should be 10
But in what radius
radius of 6 or 7 blocks
Ok let's say 7
ye
Radius or diameter?
7 radius would be 14 diameter (or more likely 15 since you want it centered around the ball)
So maximum volume would be 15*15*15 = 3375 blocks, at most, to check
Which means you probably want to use chunk snapshots to reduce lag
ye
any idea how to periodically allow certain mobs to spawn near the player ?
can we go in a talk? general1?
Not in a place I can talk sorry
okay
??
nooo
Hey, I have a quick SQL Question;
I am trying to get every column in my Database using SELECT * FROM table_name WHERE user = 'user_name'
Checking the ResultSetMetaData, it returns every column.
Now going through the ResultSet with rs.next() in a while loop, only returns the first column though.
Any ideas ?
My table has 11 columns
can i copy a building and paste it through code?
true lol
Any idea how to periodically allow certain mobs to spawn near the player ?
so how do i do that
do you just want to copy the material?
and not its data
like texts on signs
items in containers
I mean Columns, here's the code:
public void onFinish(ResultSet resultSet) {
try {
ResultSetMetaData data = resultSet.getMetaData();
p.sendMessage(HexColor.UNIFORM_GREEN + "for Loop");
for (int i = 1; i <= data.getColumnCount(); i++){
p.sendMessage(HexColor.UNIFORM_BLUE + "Column found: " + HexColor.UNIFORM_MAGENTA + data.getColumnName(i));
}
p.sendMessage(HexColor.UNIFORM_GREEN + "while Loop");
while (resultSet.next()){
p.sendMessage(HexColor.UNIFORM_BLUE + "Data found: "
+ HexColor.UNIFORM_MAGENTA + resultSet.getObject(resultSet.getRow())
+ HexColor.UNIFORM_BLUE + " in Row: " + HexColor.UNIFORM_PURPLE + resultSet.getRow() + " (" + data.getColumnName(resultSet.getRow()) + ")");
}
resultSet.close();
resultSet.getStatement().close();
resultSet.getStatement().getConnection().close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}```
Output: https://i.imgur.com/WyoQUIQ.png
blocks and 1 door and a commandblock with pressure plate
Oh wow I just realized that it's Row and not Column, my brain did a massive game there LMAO
@near crypt So you need something like:
Triple nested for loop for delta x,y,z going from -7 to +7.
Using distance squared should be fine for controlling the random chance. So let's say dist = dx*dx + dy*dy + dz*dz.
Then your chance to colour that block is baseChance/(dist+1) (plus one to avoid dividing by zero).
Roll a random number and if it is greater than the chance, skip this block (using continue;).
Otherwise, you have to check if the block is air. The current block's position is the snowball's position plus dx, dy and dz. Use world.getBlockAt and then check if block.isAir(). If yes, skip the block. Otherwise keep going.
Then, you have to check if there is a block between the current block and the snowball or not. You can do a raycast from the block's position to the snowball and see if it hits something. If yes, skip the block.
Finally, you set the block to whatever the coloured block is supposed to be.
okay thx brother
Okay yeah I had a massive brainfart, I was going into the next row trying to read out the Column haha
Fixed it now, thank you very much!
yea haha
@hardy swan
nah i need something that can get copied with a trigger in my code
well basically i need to do it through code
then the simplest way is to have a list
Can someone please tell me
any idea how to periodically allow certain mobs to spawn near the player ?
iterate through all x, y, z between two blocks and add to the list
and that will be your clipboard
okay thanks
can I understand it as despawn all mobs that doesn't match a list?
when you say allow, do you mean to spawn them manually?
no basically
i want to make a plugin that continously spawns a certain mob X [ and not despawn the mobs that are not X ] to simulate an apocalypse of mob X
like for example i want a zombie apocalypse
they keep spawning near the player , periodically
BukkitScheduler#runTaskTimerAsynchronously(Plugin,Runnable,long,long)
where you runnable would be a callback to server thread
Bukkit.getScheduler.runTask(Plugin, Runnable)
In this runnable will you then spawn entities around the player
bro im sort of new , i was thinking of doing something basic like
p.getLocation().getX() + new Random().nextInt(32)+1;
of this sort
yes all these are in the second runnable Im talking about
okay
you want to spawn periodically right
yes , in intervals
yea then this
okay , will i find a guide online on what exactly entails this command
so i can learn
declaration: package: org.bukkit.scheduler, interface: BukkitScheduler
BukkitScheduler helps you solve it
avoid handling threads and sleep yourself unless specifically needed and you know exactly what is happening
I tried to spawn an armor stand with packets and set the armor stand invisible, but the armor stand is still visible, I'm using 1.16.5
ok thanks a lot.
@hardy swan so in long delay it should be 0 because the first run should be initiated instantly
and for long period , what is 1 tick = ?
like how many seconds or so.
0.05s
yes
ahah thanks again 😛
is there anyway to set my plugin version in plugin.yml to project's version?
nvm think i found the solution
Some curly brackets shit
?paste
Hi! Im making a command you can use as /attractie hub Hub
What it should do is output a message like [info] argument2 is opened click to warp
I have made it clickable and use the ClickEven.Action.RUN_COMMAND, "/warp" + args[1]))):
When using it gives me a internal error. Can someone look at my code and see what I did wrong?
ive been banging my head at this for an h or so
i use this code to get Leafs
Leaves leaves = (Leaves) block.getBlockData();
But by some magic sometimes (usualy on a block break event) it returns craftblock and it meses up the casting. Any ideas on how to turn CraftBlockData into BlockData, and also what is the use of CraftBlock?
what is the MATERIAL name for enchanted golden apple
because IntelliJ is suggesting me only GOLDEN_APPLE
which line is 36
Bukkit.broadcastMessage("§7[§dInfo§7] " + ChatColor.BLUE + "De " + ChatColor.DARK_GREEN + args[2] + ChatColor.BLUE + "Is geopend!" + ChatColor.DARK_AQUA + "[Klik hier om te warpen]");
What version?
1.12
MATERIAL.NOCH_APPLE
damage value of 1
do you mean args[1] instead of args[2]
No I meant the second argument in the command. /attractie argument1 argument2
/cmd args[0] args[1]
Thank you! I'll try it out
np haha
how can I set it?
because I have no idea, doing it for first time 😅
Sorry for being that guy but i realy need some ideas on it.
ItemStack.setDurability(1)
is this code in a block break event listener?
sorry, i mean I'm making PlayerItemConsumeEvent and I want to apply some effects on player when the enchanted golden apple is eaten
dont you have a getItem()
yep it breaks, it somehow gets CraftBlock witch then returns CraftBlockData witch cant be cast to Leaves
I have
private Map<ServerInfo, Boolean> pingServers()
{
Map<ServerInfo, Boolean> servers = new HashMap<>();
for(Map.Entry<String, ServerInfo> server : ProxyServer.getInstance().getServers().entrySet())
{
ServerInfo serverInfo = server.getValue();
serverInfo.ping((serverPing, throwable) ->
{
if(throwable != null)
servers.put(serverInfo, true);
else
servers.put(serverInfo, false);
});
}
return servers;
}
I am trying to reach servers in Bungee, but the problem is, if I return the servers map the CallBack won't be finished. This is to search a reachable gameserver or lobby
show code on how you get CraftBlock
then use that, test its material and its durability
code:
private void onAppleEat(PlayerItemConsumeEvent e) {
Player p = e.getPlayer();
if (e.getItem().equals(Material.GOLDEN_APPLE)) {
}
}
and I dont have something like getMaterial or getDurability, only getData and getMaxDurability
'getType()' in 'org.bukkit.inventory.ItemStack' cannot be applied to '(org.bukkit.Material)'
Spi.gt go brrrrt LeafDecay. GitHub Gist: instantly share code, notes, and snippets.
e.getItem().getType() == Material.GOLDEN_APPLE
my bad
much better
I have literaly posted everything that ever tuches that instance in case i somehow turned it to CraftBlock by accident
did you check if the block in the argument is org.bukkit.block.Block
it should be
hmmm
yep it is
if (e.getItem().getType() == Material.GOLDEN_APPLE && e.getItem().getDurability() == 1) will it work?
you might have to add (short) in front of 1
ok, thanks 😅
java might not recognise it as a short, i forgot
or you can use 1S
or you might not even need to add since getDurability's short can is subtype of int?
idk I'm just trolling
also how can I apply potion effect for X seconds and with X amplifier?
declaration: package: org.bukkit.potion, class: PotionEffect
thx
after that look at this:
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/LivingEntity.html#addPotionEffect(org.bukkit.potion.PotionEffect)
declaration: package: org.bukkit.entity, interface: LivingEntity
Guys , what's the sound that like ding ? In Spigot 1.8.8
one ding sound? or player level up sound?
No ding @hardy swan
The player level up is not good
As u open in other server an GUI , ding sound plays , how ?
@hardy swan
try player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1); and see if that's the sound you want
Just play with the sound for a bit untill you get it
Or you can make a small mod in fabric that writes sound input and then log into <server-of-choise> and yoink the valius
use the /playsound and have fun
How can I check if a bungee server is online?
or maybe try Sound.SUCCESSFUL_HIT
im so good at googling
Ok thx
yep you wont need any casts, symbols or manual conversions:
https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2
Also may i ask what was the indended use of CraftBlock
That isnt just breaking deadlines
I don't even know how your Block can be a CraftBlock
eh wait CraftBlock implements Block
but somehow doesn't implement getBlockData()?? what version are you in lol
Guys how to spawn particle in 1.8 using spigot
is bit shifting or dividing faster if you want to know how many powers of two are in a number and you dont care about the part after the column
IE integer divisions
Bec the spawnParticle function don't show , how to spawn
Probably bit shifting
How to spawn particles in spigot 1.8 ??? @ivory sleet
he just told you, with the use of nms
What's nms
good gui library?
nms is the standard minecraft code
net.minecraft.server package
without bukkit or spigot atop it
https://www.spigotmc.org/threads/spawning-particles-in-1-8-8.249505/ I will just redirect you to this.
which library is good for gui? any suggestions?
Thx @ivory sleet
Interfaces, mf-gui, inventoryframework, bkcommonlib, helper and canvas are just some of them.
public class RightClick implements Listener {
@EventHandler
public static void onInteract(PlayerInteractEvent e){
if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
e.getPlayer().sendMessage("Action.");
}
}
}```
That triggers twice. Why?
try filtering with right or left hand
i mean you can right click with left hand
How can I get EntityPotionEffectEvent cause by golden apple? Because when I do:
if (e.getCause().equals(Material.GOLDEN_APPLE)) {, Intellij says Condition 'e.getCause().equals(Material.GOLDEN_APPLE)' is always 'false'
or should I ignore this warn
because getCause() returns something completely else
figured out but thanks
having a ide is helpful at times lol
on another note what's the reach of a player? I want to make that interact thing work at the same range as block placement
5 for blocks
no
Main.java: https://paste.md-5.net/ajupesogeg.java
Commands.java: https://paste.md-5.net/obupimutut.java
SubCommand.java: https://paste.md-5.net/hoxuwipaxi.java
MysteryBoxCommand.java: https://paste.md-5.net/uwayuvawow.java
CaixaCommand.java: https://paste.md-5.net/qiwidiripu.java
Someone knows why Main dont enable Commands...
actually it is below 5
neither of the methods take anythine else than int so imma settle for 5
1.17
It implements get block data but it returns CraftBlockData for some godforsaken reason
cant you cast that? Sounds like one extends the other to me
Nitidez yeah you should have a separate Command instance per command.
java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData cannot be cast to class org.bukkit.block.data.type.Leaves (org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData and org.bukkit.block.data.type.Leaves are in unnamed module of loader 'app')
thats because youre casting to type
do ((BlockData) craftblockdata).equals(Material.<Leaves here>)
Is it possible to make Bukkit.broadcastMessage("§7[§dInfo§7] " + ChatColor.BLUE + "De " + ChatColor.DARK_GREEN + args[1] + ChatColor.BLUE + " Is geopend!" + ChatColor.DARK_AQUA + " [Klik hier om te warpen]"); a clickable like I did with this line:
TextComponent message = new TextComponent(ChatColor.GRAY + "[" + ChatColor.LIGHT_PURPLE + "Info" + ChatColor.GRAY + "]" + ChatColor.RED + " Oh nee! Je hebt te weinig woorden gebruikt om de broadcast functie te gebruiken! /attractie [warpnaam] [attractienaam]"); message.setColor(ChatColor.RED); message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp " + args[0])); player.spigot().sendMessage(message);
since the one is a textcomponent but the other is a bukkit.broadcastmessage
Bukkit.getServer().spigot().broadcast()
CraftBlockData does implement BlockData
nop, for example i spanwed it in x:1,y:2,z:1. and it dropped to x:2:y:2z:0
just a different subtype than Leaves
if (e.getCause().equals(EntityPotionEffectEvent.Cause.FOOD) && (e.getModifiedType().equals(PotionEffectType.DAMAGE_RESISTANCE))){ how can I specify the material of food?
yes, try adding 0.5 to x and z
yeah
I dropped it in void
But CaixaCommand is a subcommand, MysteryBoxCommand is a command that pick up the CaixaCommand subcommand
If im right I should replace that with player.spigot().sendMessage(message);
Or with Bukkit.broadcastMessage("")
A BlockData instance may not be a Leaves type however a Leaves instance will always be a BlockData type since Leaves extends BlockData
I want to know why Main dont enable Commands, if i put Commands.setupCommands().
And it dont sends any error to me.
Look at implementation, from what I know broadcastMessage is not the equivalent of looping through every player and sending the message.
No thing is you’re never registering Commands.
try {
SimpleCommandMap simpleCommandMap = (SimpleCommandMap) Bukkit.getServer().getClass().getDeclaredMethod("getCommandMap").invoke(Bukkit.getServer());
simpleCommandMap.register(this.getName(), "mysterybox", this);
} catch (ReflectiveOperationException ex) {
Main.getInstance().getLogger().log(Level.SEVERE, "Cannot register command: ", ex);
}
And it dont sends the "Cannot register" message in console.
Which is called nowhere because you’re never instantiating a subtype of Commands
Just because you put something a class constructor won’t make it automatically calling itself
uhh
This is basic java. A class constructor is invoked when you instantiate the class.
you need to do sth like this
plugin.getCommand("").setExecutor(new ...);
class A {
A() {
}
}
new A();
When the server meets the line new A(); then it will run the code inside the constructor which is the A() {...} part inside the class A
here is video
you sure it is not spawned in the block?
public class MysteryBoxCommand extends Commands {
private final List<SubCommand> commands = new ArrayList<>();
public MysteryBoxCommand() {
super("mb", "mysterybox");
Thanks, i kinda lost my mind whilst debugging this. Will try something now
at void?
yea
under y = 0?
nop
Bukkit.getWorld("world").dropItem(new Location(Bukkit.getWorld("world"), 33.5, 70, -54), new ItemStack(Material.STONE)); here is my code
I already told you
ok then is 33.5, 70, -54 the location of the block
new
Do you see any new MysteBoxCommand();
ummm what do you mean?
33.5, 70. -54's block type is air
At Commands.java - setupCommands()
public static void setupCommands() {
new MysteryBoxCommand();
}
At Main.java
Commands.setupCommands();
then where is this new MysteryBoxCommand stored?
nowhere
it isn't assigned to anything
thrown into garbage collection
kiss it goodbye
it doesnt work but thanks
Anyways nitidez I missed that but you should probably clean up your code a little bit.
it isnt about imports
I think he does register it in the Commands class
Anyways it’s hard to tell, inheritance relationships are the most coupled code designs you will ever encounter.
Why ;-;
unless you do sth weird in the constructor, you have to assigned your newly instantiated instance to a variable
or return it
Like making a variable to the MysteryBoxCommand class?
otherwise, this instance is lost if the reference to it is lost
you can
@heavy void I feel this is more of a basic OOP concept
You should add some print statements and see where it stops
Yep ive made it so it no longer throws exceptions but the mf only returns craftblock
by using basic oop (instanceof)
Even getting the block seperatly returns craftblock
👍
Im giving up, thanks you anyway, im so dumb for that.
you prob have to look at where you called this method
it is weird that you would encounter instances of craftblock
Doesn’t sound like a good way to tackle a problem
Did you add those print statements?
There might be so that your MysteryBoxCommand#perform is where it stops at
@EventHandler
public void playerJoin(PreLoginEvent e)
Can I cast the PendingConnection to ProxiedPlayer?
You can’t do that
because the event fired before the player is registered into the server
?paste
What is in line 14
in main?
yup
getCommand("startchallenge").setExecutor(new Setup());
did you add the startcommand in pluin yml
Send the plugin yml
name: MCBDamagedFood
version: ${project.version}
main: me.hex.mcbdamagedfood.MCBDamagedFood
api-version: 1.16
authors: [ 2Hex ]
description: Minecraft But, Food damages you.
commands:
startchallenge:
description: start MCBDAMAGEDFOOD Challenge
aliases: [sch, startch]
endchallenge:
description: end MCBDAMAGEDFOOD Challenge
aliases: [ech, endch]
?paste
i fixed it nvm
👍
Is it possible to get material of EntityPotionEffectEvent?
Potion Effects do not have a Material
tptg:
description: Teleportiert dich zu deiner Gilde, falls vorhanden.
usage: "Usage: /tptg"
permission: ccrp.default
permission-message: Du besitzt keine Berechtigungen, um diesen Befehl auszuführen!```
Me with OP: /tptg
Ouput: Usage: /tptg
Why the command is not working correctly by adding it to the plugin.yml?
?paste
Wait
Okay. Entwickler
Paste your command
/tptg
i mean class
public class TeleportToGuildCommand extends Command
{
public TeleportToGuildCommand(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases)
{
super(name, description, usageMessage, aliases);
}
@Override
public boolean execute(@NotNull CommandSender commandSender, @NotNull String label, @NotNull String[] args)
{
if(commandSender instanceof Player)
{
Player sender = (Player) commandSender;
if(RolePlayer.getOnlineRolePlayer(sender).isTeleportingToGuild())
{
sender.teleport(RolePlayer.getOnlineRolePlayer(sender).getGuild().getGuildLocation().add(0, 1, 0));
}
else
{
sender.sendMessage("§cDu musst einen Teleportationspunkt nutzen, um dich zu teleportieren!");
}
}
else
{
commandSender.sendMessage("§cNur Spieler können diesen Befehl ausführen!");
}
return true;
}
}
Sorry
?paste
The pasting of this is as good, as paste
return false
Always?
when you use return true it means it will print the usage that in plugin yml
I thought return false would do this.
No. Its the other way around
My thought
Returning false means the command failed
It shouldn't be unless there is an error
It cant. Maybe if an exception is thrown.
I try remove the part from plugin.yml
So im suspecting that you are not running the code you have shown us
Before I added it, it worked perfect
Now. The command works @lost matrix
I just removed commands: from plugin.yml
how does removing it from the plugin.yml make it work lmao
I don't know.
surely it isn't registered anymore
I registered it in the commandMap
Looks like you are using some sort of command framework.
Because you dont implement CommandExecutor
ohhhhh
-.-
you could have said
What is?
commandMap.register("help", new TeleportToGuildCommand("tptg", "Teleportiert dich zu deiner Gilde, falls vorhanden.", "/tptg <player>", new ArrayList<String>()));
Hacky way of registering commands
How should I do it?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I'm happy, when I learn to make things better.
Ähm. I have a little question.
If I want to run /guild create
How can i make that the player can complete the command with tab?
Hey, is it possible to store some data within a block?
I'm looking for something like the PersistentDataAPI but for blocks
Unfortunately I don't think so. Gotta store it manually. Only tile entities can store data like that.
isnt it that entities lose nbt data on restart and you can store nbt in blocks?
i mean
if you give any block chest nbt and put a hopper below it
that block acts as if its a chest
Entities keep their data
ah sorry meant meta data
I remember that there was a glitch where a spawner had chest nbt
Hmm so I would have to create something like a small database
it depends on what you want to achieve
I am working on a furniture system where you can specify a list of barriers to use to simulate "hitbox"
If you only need one barrier, this is really easy because I can check if there is an invisible itemframe behind with the right persistent data
but if your furniture is made of 10 barriers, I would need to save the orientation and the root location in every block
so that if one of these blocks is broken, I can find the other ones
you said invisible itemframe
it is behind one of these barriers right
for every "furniture"
yep right
so it's easy if your furniture is made with only one barrier, because you can easily find the item frame
but if this is a furniture with one item frame and 10 barrier blocks
then that's not easy
ah ok
I would need to store the location of the item frame in these 10 blocks
or something like that
Bungeecord I get Already connecting to this server, but I only call the connect method once
and if any is itemframe, it may tell you whether the block belongs to this furniture
Yeah but that's going to be complex
hmmm
yes as I said this is what I am already using
my problem is to find the itemframe when you break a block from a big furniture
currently it's easy because this can't be further than 1 block
There is a libs/api for that, check this out https://www.spigotmc.org/threads/custom-block-data-store-any-information-in-blocks-without-databases-or-files.512422/
So I do something like that:
for (Entity entity : block.getWorld().getNearbyEntities(block.getLocation(), 1, 1, 1))
if (entity instanceof ItemFrame frame
&& entity.getLocation().getBlockX() == block.getX()
&& entity.getLocation().getBlockY() == block.getY()
&& entity.getLocation().getBlockZ() == block.getZ()
&& entity.getPersistentDataContainer().has(FURNITURE_KEY, PersistentDataType.STRING)) {
if (entity.getPersistentDataContainer().has(SEAT_KEY, PersistentDataType.STRING)) {
Entity stand = Bukkit.getEntity(UUID.fromString(entity.getPersistentDataContainer()
.get(SEAT_KEY, PersistentDataType.STRING)));
for (Entity passenger : stand.getPassengers())
stand.removePassenger(passenger);
stand.remove();
}```
finding entity in a radius is not difficult
hmm I'll look into that
it depends
if your furniture is 50 blocks long, it might not be a good idea to check it everytime someone breaks a barrier block
I'll check it out @summer scroll
it looks awesome, thank you very much! ❤️
Forgot to return....
but how often does someone break a barrier block
everytime someone breaks a little furniture?
I don't know how getNearbyEntities is implemented, but it may not be slow
Is there a way to get an entity's projectile resistance or do I need to manually sum the enchantments
Manually sum the enchantments
okay, is there anything else I need to consider
Depends on what you are trying to achieve
I'm damaging an entity with my own projectile
Because potion effects also can reduce the damage a projectile does. Same goes for normal protection.
If you damage the entity with DamageType.PROJECTILE then the enchantment should also be applied automatically
I thought there was just a method for that. Let me investigate.
yeah I think forge had that but don't see it in spigot
Is your custom projectile an actual Entity of type Projectile or a virtual one?
getConfigurationSection(x+"-"+"-"+y+"-"+z)```
or
```java
getConfigurationSection(x+"."+"."+y+"."+z)```
when storing/accessing extra block data?
virtual projectile
can I instantiate an EntityDamageEvent?
Using a minus sign to separate numbers is a bad idea for obvious reasons...
it is .
Thats what i was thinking...
like should i make it in the style of
x:
y:
z: 'Seven'
#or
x_y_z: 'Seven'
Maybe just try firing an EntityDamageEvent and reduce the value of the targets health by the outcome. This way you also support other plugins.
I'd use a hashmap (with an x,y,z object as the key) and serialise/deserialise it. Storing it the way you are doing means it needs to search the config file linearly any time you want to access the data.
Does firing the event actually apply the damage?
Something like that:
public void damageWithProjectile(final LivingEntity target, final double damage) {
final EntityDamageEvent entityDamageEvent = new EntityDamageEvent(target, DamageCause.PROJECTILE, damage);
Bukkit.getPluginManager().callEvent(entityDamageEvent);
final double finalDamage = entityDamageEvent.getDamage();
target.setHealth(Math.max(0, target.getHealth() - finalDamage));
}
Uhm...
I dont think so?
But you should test that
yeah will do thanks
```this fine?
either way it has getFinalDamage() so I can get that and manually apply
i need a config_section by coordinates
nope, you need a data structure with x,y,z and a hash function that considers those 3 variables
String key = x + "_"+y+"_"+z ?
Are you trying to save custom data in blocks?
yes
I use this:
public static final class BlockPosition implements Serializable {
private static final long serialVersionUID = 100L;
public final int x;
public final short y;
public final int z;
public BlockPosition(Location location) {
this(location.getBlockX(), (short)location.getBlockY(), location.getBlockZ());
}
public BlockPosition(int x, int y, int z) {
this(x,(short)y,z);
}
public BlockPosition(int x, short y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public BlockPosition above() {
return new BlockPosition(x,(short)(y+1),z);
}
public BlockPosition below() {
return new BlockPosition(x,(short)(y-1),z);
}
public BlockPosition east() {
return new BlockPosition(x+1,y,z);
}
public BlockPosition west() {
return new BlockPosition(x-1,y,z);
}
public BlockPosition south() {
return new BlockPosition(x,y,z+1);
}
public BlockPosition north() {
return new BlockPosition(x,y,z-1);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlockPosition that = (BlockPosition) o;
return x == that.x && y == that.y && z == that.z;
}
@Override
public int hashCode() {
return Objects.hash(x, y, z);
}
@Override
public String toString() {
return "(" + x + "," + y + "," + z + ")";
}
}
there are some casts to short left-over from when I didn't have the second constructor so you can ignore those
how exactly would i use that in a hashmap? <Object, ConfigurationSection>
<BlockPosition, YourExtraData>
yea as said it changes hence configsection
depending on the block
Then check this post out:
https://www.spigotmc.org/threads/tracking-blocks-that-were-placed-by-players.500216/
Saving such data in the PersistentDataContainer of a chunks is def a possibility. This way you dont need to think about where and when to save the data.
if you want it completely custom per-block (like nbt is completely custom per item) then you can use a Map<String, ConfigurationSerializable> or Map<String, Serializable> as the value
that would be most similar to a config section
then you could do YourCustomDataType.data.put("arbitraryDataName", arbitraryDataValue);
well i plan on storing it as a configuration section, do i have to cast it to configurationserializable ?
anything you serialise with bukkit's serialisation has to be either config serialisable or normal serialisable
but why would i use serializable in the first place
i mean
i get configsections from the file
and use configsections in my code
but that will be slower than having:
class ConcreteCustomBlockData extends YourAbstractCustomDataType {
private String someVar1;
private UUID someVar2;
private int someVar3;
}
config sections seem to be designed for config stuff not for arbitrary data serialisation
hey ! I have a problem with a plugin in minecraft can someone help me or try to help me ?
also config sections are, I believe, configuration serialisable anyway
teams:
enabled: false
solo-item: "Oxey_Daisy"
solo-name: "&fSolo"
team-items:
- "BLUE_DYE"
- "RED_DYE"
team-names:
- "&1Blue"
- "&4Red"
teamlore: "&3Use this chest to choose a team!"
but i need my plugin to be cpu heavy instead of ram heavy
here is my problem
i ran a bingo plugin
and i cant enable team
when i change false and true
the plugin doesnt work on my server
how much data do you plan to store? Also, reading from config file puts the file into ram too I believe. If not, then it would stream from disk, which is slow and only really recommended if you have multi-GB files
@quaint mantle ah, this channel is just for help with your own plugins
oh and where can i redirect for my problem ?
the plugin should have a discussion section, faq or github issues page
Well that is completely player dependent... specific commands/actions are supposed to 'link' blocks, and i need to store the coordinates they're pointing to in that block
I also would rather not store that data in the chunk files as in the plugin linked so that there is no data leftovers after deleting the plugin and its files
do you split your saved files per chunk
no
then you will have big files on big worlds
I could but that would bring a whole other host of problems with it
