#help-development
1 messages · Page 1770 of 1
any reason why its giving me jdk11?
idk prolly no binaries on that site for 17 or smthing
hey @worldly ingot the regex you gave me doesnt seem to be allowing anything
oops wrong one
else if (!PATTERN_ALPHANUMERIC.matcher(chatAnswer.get(player)).matches()) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3&lGUILDS &8> &7Guild names can only contain letters and numbers."));
}```
trying to check if a guild name only contains alphanumeral chars
so a-z and 0-9
capitals work too
unless regex isnt case sensitive
^[A-Za-z0-9]+$
jeez idek how that makes sense to you lmao
its simple you just gotta learn the syntax
ah
^ = start of text
[ = match any of...
A-Z = ABC..Z
a-z = abc..z
0-9 = 0123..9
] = end match
- = 1 or more
$ = end of text
I just throw stuff into regexr and fiddle around until it works for my use cases
well, that is, after I search for it online
how do I get tool used in PlayerInteractEvent
for example get pickaxe when mining a block
getItem()
Returns the item in hand represented by this event
its giving me Incompatible types. Found: 'org.bukkit.inventory.ItemStack', required: 'org.bukkit.block.Block'
show code
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.event.player.PlayerInteractEvent;
public class PlayerInteract implements Listener{
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event){
Block block = event.getClickedBlock();
Block tool = event.getItem();
if(block.getType() == Material.BEDROCK){
block.setType(Material.AIR);
ItemStack bedrock = new ItemStack(Material.BEDROCK,1);
block.getWorld().dropItemNaturally(block.getLocation(), bedrock);
}
}
}```
Block tool = event.getItem();
ItemStack tool = event.getItem()
what do you think the problem might be
😂
this is my first java/plugin project
its fine just change it to ItemStack
I did
so it should work now
yes
cool
I've got some more coding to do though
well we are here if you need help
where do I go to get info on the different function/events
the javadocs are the gods
imaginedev
Is it possible to have something similar to CompletableFuture in python?
lol
lol ye
1 sec
I know there’s like async await but is that all? :0
im not sure but most of the time you'd just create it yourself
i dont see a problem with that
python has a lot of modules but the point isnt really to create a jdk-like prebuilt module
use the threading module
Oo
what would this be called in https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/ItemMeta.html
declaration: package: org.bukkit.inventory.meta, interface: ItemMeta
which method
from threading import Thread
Thread(target=some_fun).start()
# or for Thread subclasses
class A(Thread):
def __init__(self) -> None:
Thread.__init__(self)
def run(self) -> None:
pass
A().start()
That’s very pog,, what does target do btw?
mhm
yuh
Oo sure will, is there a python discord btw??? Invite me x)
Hmm python possibly?
Maybe 👀
Ah, nvm then I’ll go ahead and join myself then lol
what method is canDestroy under hasItemMeta in Itemstack
Question, so I am creating an class called Inventories. This class has the task of returning several inventories, depending on the one you want. When you get a certain one, the items in it are set by calling method that would generate them. Every time it generates the items an item to create them are called. For example a displayPane would be java private ItemStack getPane() { ItemStack item = new ItemStack(Material.YELLOW_STAINED_GLASS_PANE); ItemMeta meta = item.getItemMeta(); assert meta != null; meta.setDisplayName(" "); item.setItemMeta(meta); return item; }
Do you think something better would be to initialize these items since they won't change when an instance of the inventories class is created? Create a non static initializer maybe that would save this to avoid creating them again every time this class is accessed?
correct
public static final ItemStack i =
then create an itembuilder class
First of all, assert won’t do anything if you don’t have a specific jvm flag enabled, secondly what do you mean by non static initializer? It probably doesn’t matter here, however you probably want to just cache the ItemStack in whatever way, although the creation of ItemStack is quite superficial in terms of memory and speed, it’s more over how it gets processed and converted to nms.
ok so for some reason if you set the damage in an entitydamageevent to 0 and set the health of the victim to 0 and the victim is a player, it dies twice
sending the death msg twice and calling a playerdeathevent twice
howdy kill
hello
That does sound like a bug
Maybe worth reporting
it's 3 am and my brain is frying because of this stuff
uh- i am on uh- 1.8
is that a known issue
from 1.8
Although it’s basically you that triggers an event which proceeds to make another event recur
Idk if it still is an issue, if you’re on 1.8 that is
Very possible it has been patched and dealt with then
oh actually i guess it kind of makes sense but still should be a bug
well the way i was handling damage was a bit sketch anyways so i should change it
I know assert will not do anything but it highlights it and tbh I hate it because it looks ugly on the code so I just put it in 😭. And I mean just for example
public class ToolsInventory() {
private itemStack goBack;
{
goBack = getGoBackItem(); etc...
}
}
Just initialize it when the class is created
basically i'm customizing damage calculation based on armor and weapons and so i need to set the final damage somehow
could someone help me with spawning a fishing hook in nms
Maybe have a map
but since you can't do that i'm setting damage to 0 and then damaging the victim
fishing hooks are pain
ik
In that way, it will be dynamically supported in case you wanna cache items during runtime or smtng jpdaniel
but ive concluded i absolutely have to have one
wdym
public class PlayerInteract implements Listener{
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event){
Block block = event.getClickedBlock();
ItemStack tool = event.getItem();
if(block.getType() == Material.BEDROCK & tool.hasItemMeta(CanDestroy:["minecraft:bedrock"])){
block.setType(Material.AIR);
ItemStack bedrock = new ItemStack(Material.BEDROCK,1);
block.getWorld().dropItemNaturally(block.getLocation(), bedrock);
}
}
}
```whats the correct use of hasItemMeta to accomplish what I'm trying to do here
The set of fields you define in your class is limited to whatever they’re sings they’re known at compile time to a certain extent
Having a map would make your cached items changeable at runtime more flexibly
As you could easily put and remove new items into the cache
well yes but it is a GUI
And the cache is usually something like a HashMap
what do you need it for?
so the ones I would initialize would be only the bottom items
Like the GUI options
so those I want to initialize at first but the items on top would be the ones that change
For example
Just because it’s a gui doesn’t mean you can’t make it into a more useful cache
grapple hook thingy in a minigame
Only the bottom ones will never change
Yeah
people will be riding pigs, so i need them to be able to cast fishing lines with carrots on sticks instead of rods
can't you send a playoutentityspawn or whatever the name is
Then go with a Map of a fixed size of 9 ?
it will allow you to swap items if you want to
Etc
yeah but it just breaks
Anyways you do you, guess this isn’t enterprise after all
yep
Wait so create a map? To store those bottom items?
I mean just do the way you intended to
Honestly that is where I wanna head so would be great to learn every little thing I can haha
I wanna go the most efficient way
i'm not sure if you can make it throw a fishing hook as a player casted it from a rod
is there a way i can change what item a player is holding client side?
yeah send a player equipment packet
not sure if it works for the player itself tho
ah so maybe i can instead just have them hold a fishing rod and make it look like a carrot on a stick
and ill just have to deal with manually operating the moving pig stuff
did you try to use the EntityFishingHook constructor
I was thinking of doing it how you said and I think it would be a better option, Thank you!
i even tried making the fishinghook parse as a projectile
Well, to be perfectly clear, if you want to make it enterprisy, usually we separate business requirements (aka the logic) and stuff like gui, storage etc.
Anyways I don’t have a good knowledge regarding your plugin precisely however what I’d do is to encapsulate, in this case, an ItemStack[] (array) with the size nine which maybe represents the nine items at the bottom. Then you have your inventory instance. Whenever you update the array, you’d then go on to update the items inventory as well. Of course this requires you to be disciplined, but yeah, that’d be one way.
Another way would be to completely have the logic of the gui in one class. So essentially you might want to have an ItemStack[] with the size of 56 if that was your inventory size. Then have the class with some useful functions to turn the pages, change items, or whatever you wish to do. Then make sure whatever is done with the functions gets reflected onto the actual gui. Which might be done through another class.
Anybody know off the top of their head how much gravity affects an entities motion every tick?
man wrote an essay
i actually got an error this time
¯_(ツ)_/¯
Yeah that was very useful thank you.
could anyone help with this plz
does anyone know any good plugins that whenever i place diamond blocks, it makes it so i can stack it and it supports ASkyblock. i dont want my players placing Diamond Blocks everywhere and I want it so they can stack em all while still gaining island value with ASkyblock per diamond block and stuff placed.
does anyone know the placeholder for displaying player hearts
public class PlayerInteract implements Listener{
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event){
Block block = event.getClickedBlock();
ItemStack tool = event.getItem();
//System.out.println(tool.getItemMeta());
if(block != null & tool != null & tool.getItemMeta() != null){
if(block.getType() == Material.BEDROCK ){
if(tool.getItemMeta() = "internal=H4sIAAAAAAAA/+NiYOBk4HJOzHNJLS4pyq/kYGBgYGQQzM3MS00uSkwrsUpKTSnKT85mAACgSyEVKQAAAA==}"){
block.setType(Material.AIR);
ItemStack bedrock = new ItemStack(Material.BEDROCK,1);
block.getWorld().dropItemNaturally(block.getLocation(), bedrock);
}
}
}
}
}
Incompatible types. Found: 'java.lang.String', required: 'org.bukkit.inventory.meta.ItemMeta'
[18:28:53] [Server thread/INFO]: UNSPECIFIC_META:{meta-type=UNSPECIFIC, internal=H4sIAAAAAAAA/+NiYOBk4HJOzHNJLS4pyq/kYGBgYGQQzM3MS00uSkwrsUpKTSnKT85mAACgSyEVKQAAAA==}
is there anyway I can make it so a armorstand cant trigger a pressure plate, I have the armor stand as a object
alright, I will give it a shot
that is not how you would compare itemMetas
whats the correct way to do it then ?
does anyone know any good plugins that whenever i place diamond blocks, it makes it so i can stack it and it supports ASkyblock. i dont want my players placing Diamond Blocks everywhere and I want it so they can stack em all while still gaining island value with ASkyblock per diamond block and stuff placed.
well, first you create a ItemMeta object, give it the values you are looking for, and do a if (itemMeta1 == itemMeta2) {code goes here}
what would that look like
no no no no no no no no no no no no no
what
literally everything about that is wrong
depends on your item meta, but something like this: ```java
// the item meta you want to find
ItemMeta creative_meta = creative.getItemMeta();
creative_meta.setDisplayName(ChatColor.GREEN + "Creative Mode");
ArrayList<String> creative_lore = new ArrayList<>();
creative_lore.add(ChatColor.LIGHT_PURPLE + "Become Invincible >:)");
creative_meta.setLore(creative_lore);
then compare them
```java
if (tool.getItemMeta == creativeMeta) {
//code goes here
}
why?
- You don't need to create a new ItemMeta object to compare properties
depends on accuracy
- You don't use item equality for objects, it will always return false unless they are the exact same object
shouldnt they be tho?
- The property being compared is not the entire ItemMeta, and if any properties deviate then the comparison will fail even if you use .equals
No
I'm only looking for if object has or not
If you create a new object it will not be the exact same object as any other object
Because I mean exact same object as in the same instance
in any of the situations I have used that it works for me
and I do use the same instance
I guess I didnt realise what he was looking for
so how do I do this
since I obviously dont know how to do this, I dont think I can help. You might be able to search on google comparing item lores tho, maybe someone else had the same issue
What properties are you trying to compare
theirs not a lot of documentation out their about how metadata works
CanBreak
Alright let's take a look
the goal is to make the plugin let players mine bedrock with any tool that has the meta property of can break bedrock
I don't think there's a property for that in ItemMeta
Alright, you don't need to actually set the property for that
You could add it in the lore and/or store that property in PDC
lets use lore then
Great, that should be simple enough
If you want an item to have that property, you can just add a line of lore like &cBreaks bedrock or something
Then you can just check if the lore contains that line
redempt im gonna make a better redlex than you
its gonna be like a template
What does that mean
idk
public class PlayerInteract implements Listener{
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event){
Block block = event.getClickedBlock();
ItemStack tool = event.getItem();
//System.out.println(tool.getItemMeta());
// the item meta you want to find
if(block != null & tool != null & tool.getItemMeta() != null){
if(block.getType() == Material.BEDROCK ){
if(tool.getItemMeta().getLore() = "Lore"){
block.setType(Material.AIR);
ItemStack bedrock = new ItemStack(Material.BEDROCK,1);
block.getWorld().dropItemNaturally(block.getLocation(), bedrock);
}
}
}
}
}
```why is it never this simple
Incompatible types. Found: 'java.lang.String', required: 'java.util.List<java.lang.String>'
its just gonna be better and easier
You can't use == on a list
That would be checking if the entire list is equal to another string
wrong error
You can use contains
How so
With RedLex you just write the bnf file, then use that to instantiate the parser and call tokenize
And bam, you've got your tokens
Yes because it's the method that checks if an element is in a list
You have to understand the logical difference between checking if something is equal to a list and checking if the list contains an element
Could make a bot reply learnjava to every post in here and it'll be 80% right
learnjava
can always learn more 🙂
what does this mean ? Could not pass event PlayerInteractEvent to BedrockMiner v1.0-SNAPSHOT
org.bukkit.event.EventException: null
Send the full error
It says what's wrong
but I have ```
if(block != null & tool != null & tool.getItemMeta() != null & tool.getItemMeta().getLore() != null){
You're using 1 &, which checks every condition. Tool is null, but then it's going to tool.getItemMeta(), but tool is null
So... use && instead.
You should pretty much always be using &&
plugin works as intended
Hey can one of the Staff please DM me I want to raise an issue.
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
public class BreakBlock implements Listener {
@EventHandler
public void onPlayerBreakBlock(BlockBreakEvent event) {
Block blockBroken = event.getBlock();
if (blockBroken.getType() == Material.WHITE_GLAZED_TERRACOTTA) {
event.setCancelled(true);
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
String command = "givetoken %player% 1";
Bukkit.dispatchCommand(console, command);
}
}
}
Does anyone know how to make it so the command is not shown in the consoole?
Don't use commands
Use an api
wtf is he even doing...?
Eh
Sometimes you really do need to use commands because a plugin doesn't have a good api
Or because that's how you're supposed to interact with it
You should really be careful when using it in events that are fired that often though
does anyone know any good plugins that whenever i place diamond blocks, it makes it so i can stack it and it supports ASkyblock. i dont want my players placing Diamond Blocks everywhere and I want it so they can stack em all while still gaining island value with ASkyblock per diamond block and stuff placed.
does anyone know any good plugins that whenever i place diamond blocks, it makes it so i can stack it and it supports ASkyblock. i dont want my players placing Diamond Blocks everywhere and I want it so they can stack em all while still gaining island value with ASkyblock per diamond block and stuff placed.
sir this is #help-development
it is a channel for developers seeking help with code
;-;
#help-server is the better channel to ask this
WildStacker?
idk, why would you use ASkyblock
How I make it stack other blocks that isn’t spawner
how can I save updates to config without removing comments and qoutes?
just search the config 🤦♂️
also, put these questions in #help-server
why does the player move circularly?
Player target = plugin.CuffLinker.get(p);
Location loc;
Vector vet;
Vector finalLoc;
Vector vel;
loc = new Location(e.getPlayer().getWorld(), e.getTo().getBlockX(), e.getTo().getBlockY(), e.getTo().getBlockZ());
vet = target.getLocation().toVector();
finalLoc = loc.toVector();
vel = finalLoc.subtract(vet);
target.setVelocity(vel.normalize()); ```
i would like the target player to follow the player that you get from e.getPlayer
hello i have a question about async queries
it cannot be accessed
if i call the method async, will the query be async ?
wtf are you doing...?
the b = true is for test
oh ok
hmmm
i might need to access the
boolean
so i can return it
Hey,
I'm wondering what exactly the provides keyword in plugin.yml does?
what?
are you asking about pom.xml
No, about the plugin.yml
I know there's a keyword named provides, but could not find any infos about it
private static boolean isTableEmpty() {
String query = "SELECT `name` FROM `presents` LIMIT 1";
try {
PreparedStatement ps = TrexPresents.INSTANCE.getSql().getConnection().prepareStatement(query);
ResultSet set = ps.executeQuery();
return !set.next();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
how to make this async
what is it
how to use it
you have to handle the response async too, which is where completablefuture is used
otherwise you lose the whole point of running sql async
what is a completablefuture
the link above explains that
i dont get it
completable future also links to future which gives more details. You probably skipped that info
can you give an example ?
google can
How could I make an inventory not draggable, only the virtual inventory, but if the player clicks on their inventory, they can drag
i'll give you an example with a way you can do it with an interface without completeable future
Cancel the inventory drag event
Yeah but
I can't send images
djghısjfhds
thanks
verify
CompletableFuture.runAsync(() -> {
// thanks
});
thanks
i found it myself
@quaint mantle
isTableEmpty(new Callback<Boolean>() {
@Override
public void execute(Boolean response) {
//do stuff here
}
});
}
private void isTableEmpty(Callback<Boolean> callback) {
String query = "SELECT `name` FROM `presents` LIMIT 1";
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
PreparedStatement ps = TrexPresents.INSTANCE.getSql().getConnection().prepareStatement(query);
ResultSet set = ps.executeQuery();
callback.execute(!set.next());
return;
} catch (SQLException e) {
e.printStackTrace();
}
callback.execute(null);
});
}
public interface Callback<R> {
public void execute(R response);
}```
hmm
tf
i dont get it
nevermind about it
it is the same thing
You can't do it like this. You actually have to wait for result.
How can I detect if a new item has been put in an inventory
(lambdas)
By player? Click n drag events
Is there a specific way or best practice to make a plugin have a exposed api for other plugins to use (I just need to expose a tiny api)
Can use the service API or don't and let people access it from grabbing the plugin directly
Could also use a static api class that people can grab certain things from
?paste
Ok, I'll use a static api class then, since bungee doesn't have the Service Manager
break down your project into 2 modules: api and plugin. In api module, you make interfaces to interact with your plugin, in plugin module - implement them
You can use static method as entry point of api or manually getting plugin from PluginManager aswell
But all I get is this error.
ElementsMain:26 is Bukkit.getPluginManager().registerEvents(new MergingTable(this), this);
Don't listen to the BlockEvent directly
1.17 or what?
oh that
oh i forgot about that lol
huh?
1.16.5
blockevent just a class contains everything for event about blocks
you need to listen to the block you want
whaa
the blockevent itself isnt intended to be an event i think
what block are you trying to listen to?
A crafting table
Huh??
i dont see any blockevent listen + the name in the error is ElementsMain not MergingTable
^^^^
Send the class
i did...
Are you sure that code is the same as the one youre running
Yes..?
this is the source code of the latest commit for 1.16.5 for the blockevent
Because the error would suggest that youre listening to the BlockEvent rather than one of the clases that extends it
This isn't a spigot bug
and other events extends this class
im not saying it is a spigot bug...
Hmm, I am using Paper, would that change anything? (Since it's a fork of Spigot...)
nothing.
if i remember it correctly
Alright then?
yeah nothing
Whats the problem?
.
You're not using Paper
Umm- ```xml
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
It's literally Paper??
The server is running Purpur not Paper
you must find the BlockEvent word in every class that implements listeners and try to replace it with other thing?
Yeah, but the plugin is paper
:heh:
Doesn't matter what api you're coding against
but still i dont think there are any differences
So the problem is with Purpur?
Oh ok
Probably not. I'd recompile your plugin and do a full server restart
I think BlockEvent is suppossed to be an event, because BlockPlace and Destory events extend BlockEvent
nah
And since BlockEvent extend Event
public abstract class BlockEvent extends Event
but if you dont believe me then that is the spigot statsh
extends Event
abstract
yes. but it didnt have a handler
^
Then how is it my fault?
so the blockevent itself isnt intended to be a real event
Dude
your fault for not trying to find other event...
🍭
That's fine
You... go click on the link hello?
this is the blockevent file
it doesnt have a handler
RPGAccount could you just chill a bit. I can handle this
Could you recompile the plugin and do a full restart?
Am in the middle of doing that
Okay :)
bukkit required every event to have a handler
the blockevent doesnt have handler = dev didnt intend it as a normal event
the reason for that is it is just a template for other block-related events, as it is an abstract.
Okay, starting the server
I know that Bukkit required every event to have a handler, and that it's a template.
Yeah, the same result.
hmmmm looks sus
what
as the class you provided dont have the block event listen
check other class then
I suggest you read this
it really is an abstract
im not laughing because im right, im laughing because of your reaction lol
Ah yes, my reaction was bad wasn't it? Thanking everyone for their help was a bad thing. It was idiotic of me to do this anyways! Thank you for the comment!
wtf...?
Just ignore him
^^^^^
i meant both of you
lmfao
God, please stop.
meh idk i dont think that is true
Why am I here
I thought discord had a minimum age of 13
lmfao
apparently not
hmmmmmmmmmmmm
Can we change the topic? This is not the chatting or acting like a kid channel.
? Not funny
hehe
Does Bukkit.getOfflinePlayers() also include online players? As the doc says Gets every player that has ever played on this server.
ok thanks
so ive made a bot (nms) and im able to make it move but im also able to move it through blocks. if i want to make it have collision, do i have to do that myself
Depends on how you made the bot
its an artificial player so i have to send packets for it do anything
Yeah sounds like you need your own collision then
Or try to find where vanilla calculates it and see if you can use it somehow
is there another way i could have made the bot to not need to implement my own collision
Simply don't use packets and register it like a normal player would be
Or you could have a bunch of JS bots with Mineflayer
Depends on what you're trying to do
Personally I'd just use the Citizens plugin api
Since they handle all of it for you
alright ill look into them
i hope this also works in java
well youcan left shift so i don't see why not
Integer.toHexString?
^
aaaaaaaaaaaah...
So Color#getRGB returns ARGB my sanity has been lost after troubleshooting that
@chrome beacon i tried to look at some stuff but i still can figure out how da hell to shade it
special colorblind glasses
You are shading it. That's the problem
ahh thats probably the dev idea plugin thats doing that
Add scope provided on to the gson dependency
is it safe to access stale player's object world object?
why do you have a stale Player object?
How do I expose an API ?
if some dumb argument has been passed
The world shoudl be valid even if the player is stale, as its just a reference and world references do not change
It would be safest to get a fresh player though
but what about get location method
it seems it gets the coords from NMS entity object reference
but i don't know if it does something with it before disconnecting
ah
i wouldnt bet on it
i'll just make a if statement
hey, i've noticed that when you set the damage to 0 in an EntityDamageEvent and set the health of the victim to 0, the player dies twice, sending 2 death msgs in chat and also calling EntityDeathEvent twice
this doesn't happen for other entities tho
sounds like a bug
are you canceling the damage event?
if not, you are setting the players health to zero, the player dies. The event continues and applies zero damage and makes teh player die again
oh that makes sense
i'm not canceling the event
so i should cancel the event if the health of the player will reach 0
if you are managing teh death yourself, yes
test with getFinalDamage() to account for armor
@EventHandler
public void onEntityDamage(EntityDamageEvent e){
e.setDamage(0);
if(e.getEntity() instanceof LivingEntity){
Bukkit.broadcastMessage("");
LivingEntity entity = (LivingEntity) e.getEntity();
double calcDamage;
if(e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) e).getDamager() instanceof LivingEntity) {
EntityDamageByEntityEvent e1 = (EntityDamageByEntityEvent) e;
calcDamage = pvpManager.calculateDamage((LivingEntity) e1.getDamager(), entity);
} else {
calcDamage = pvpManager.calculateDamage(null, entity);
}
Bukkit.broadcastMessage("calculated damage:" + calcDamage);
//if(entity.getHealth() - calcDamage <= 0.0){
//}
entity.setHealth(Math.min(Math.max(entity.getHealth() - calcDamage, 0), entity.getMaxHealth()));
}
}
this is my code btw
a bit messy but i'm doing some testing
i don't, i'm on 1.8
else i'd use java 16 and the if with instance checks would not be painful to read
basically what this code aims to do is create a custom damage system calculated by pvpManager#calculateDamage()
if i'm using an import for a plugin that isnt on the server but i dont use the import, will i get a classnotfound exception or not?
or are imports pre-checked or something
sadly you can't check the final damage so this is the only way to change damage blocking normal damage modifiers(strength, armor, and so on)
no afaik
No the error would be when used
oki thanks
you should specify in your plugin.yml what plugin dependencies you have
why would you have an import you don;t use? unless you are static importing
else if the classes are not present at runtime, you will get an exception
i'm checking if that plugin is present before using its code
thats fine
then you won't have issues unless you do wrong checks
looks clean
i usually have different classes for each service provider and i have a boolean method that says if it is present or not
ah i do it in my main class
if i do something like this, will that throw an exception?
maybe go that plugin's support server?
yes
ah lets check for vault then
which is why in my code I use ```java
public static Class<?> getClazz() {
try {
return GroupManager.class;
} catch (NoClassDefFoundError ex) {
// Ignore the error as it simply means the plug-in is not on the server.
}
return null;
}```
the only way you can avoid that is by getting teh plugin by name
yesh
ok so i have a small issue
i have damaged a player by the max double value
and now it's in kind of a softlock state
exceptions should be avoided if you can, but these days they are not as inefficient as they used to be.
a possible exception when testing for a plugin is nothing to worry about
🌝
so long as you test for it and catch it
that will thrown an exception if LP isn't present.
i check with ispluginEnabled
k
oh i've just noticed this breaks /kill
is there any other way to do what i'm tryna do
Yeah /kill just deals a lot of damage
Check and allow the void damage type?
oh is it void damage?
well that works but still this method's kinda sketcy
yea that worked
for some reason i cant set things to a config file
i'm trying this
private final FileConfiguration homesFile = plugin.getConfigManager.getHomes();
homesFile.set("homes." + executor.getUniqueId() + "." + name, null);
plugin.getConfigManager().saveConfig(ConfigManager.FileType.HOMES);
and here is my configmanager class ?paste
?paste
I am developing a parkour plugin, and I want when a player steps on a pressure plate, it keeps track of their time, until they touch the next pressure plate, I know how to do this, but I dont know what to do when multiple people are doing the parkour at once. how would I handle this?
store them in a map or something
arraylist
yeah I need time as well
I think I will do a Map<Player, ParkourInstanceThingy> playersInParkour then in the thing I am instancing per player will have a stopwatch, checkpoint variable, and all that logic
i didnt read the topic but why dont you store a set of uuids in your parkour instance
Just a list of custom class objects?
i miss structs 🥺
F
still didnt find it
So In theory
This should block the usage of the 49th slot of a gui
it does not...
The drag event is rather limited tho
The Inventory click event would most likely need to be checked too
I JUST SWITCHED FROM THE CLICK EVENT-
Two different events xx
is there a reason why you have to go through the slots with a for loop?
i have no idea i have lost control of my life
check both and youre on the safe side XD
what
click event and drag event, then nothing can go wrong can it
OH LOL IM...
@chrome beacon btw you were offline so i didnt want to bother you
No worries ping me if you need me
Quick question relating to entering the plugin API version.
My 100% sure my plugin works on prior versions of minecraft. Even tho i'm building it targeting the latest 1.17.1. Which version should I enter inside the plugin.yml?
the lowest API you want to run on
I heard its like 1.13 right?
1.13 is lowest api-version
Yeah, i have that right now
if you want 1.13, build against 1.13 too
maybe if you want to support 1.8+ then remove the api-version i think?
if you remove it it'll just go "brrt brrt plugin using legacy support!"
So I got it right. Thanks for the response 👍
I will just test it on a 1.13 before actually re-building it
is there anything built in the Material enum to get the default display name of a Material? (ex. from IRON_SWORD to Iron Sword)
or do i have to make it myself
no method
why i cant restore hashmap ?
public void saveLife(){
for (Object key : Setup.life.keySet()) {
getConfig().set("Life."+key, Setup.life.get(key));
}
saveConfig();
}
public void restoreLife(){
for (String key : getConfig().getConfigurationSection("Life").getKeys(false)) {
Setup.life.put(key, (Integer) getConfig().get("Life."+key));
}
}
@misty current This should answer your question (Untested):
String itemName = new ItemStack(Material.DIAMOND_HELMET).getItemMeta().getDisplayName();
getdisplayname returns null if the item doesn't have a custom name iirc
I guess you could Bukkit.getItemFactory().getItemMeta(material).getDisplayName(); So long as you check the material is a valid item.
I was about to post the same code @eternal oxide ahaha
thanks i'll give it a try
with checking if it is valid do you mean checking if it is not null?
Yeah, store the item meta inside variable and null check it
Just to be safe
Because the getItemMeta method is nullable
oh yea the methods where i use it already check if the item is not null/air
Thats always good 💪
uh it returns null
It will be null unless you change the display name
Is it correct to save the Arraylist
` public void saveBackpack(){
getConfig().set("Backpack.", me.ag4.blox.backpack.Setup.blocks);
saveConfig();
}
public void restoreBackpack(){
me.ag4.blox.backpack.Setup.blocks.add((Location) getConfig().getConfigurationSection("Backpack"));
}`
Now the way vanilla handles item names is with translatable text components. If possible this is what you should use
that code is 💀
nms?
What mc version?
1.8
Yeah... no
how should i get it?
🤷♂️ I always use modern versions where things are easy
Does it work with 1.8?
idk if it does, but it isnt my issue if it doesnt lol
welp i don't blame you
i think it does cause it supports legacy serialization stuff
meh at this point i'd rather take the raw material name, replace _ with " " and capitalize it
Yeah you can do that
any built in method to make Title Text or do i google one?
can anyone help me with a scoreboard that score updates everytime a certain block is destroyed?
alright
Yes
return toStrictProperCase(material.toString().replaceAll("_", " ").toLowerCase(Locale.ENGLISH)); works fine
Uh the spigot api has built in sidebar api
ez
yeah but it's painful to use
unless you want to do per players
especially as you said per player
im not doing per player
Well, it's pretty painful to do 1.8
🙂
lol
agreed
lol
wanted to see how bad it was and i feel like the server i'm making fits better in 1.8
that gonna look weird for non-english clients
how do i get a plugin to create a config
does FileConfiguration#set("section", object) works if the section key doesnt exist?
yes
in some way my config doesnt let me write something down
where are you going to use those? If on title, actionbar chat and booms only just use adventure
i save it and nothing is saved
item names to add the level to the name
@tardy delta Are you saving data inside the config file?
yes
I personally would not recommend that
its just an yml data file
Leave the config file for the configuration only
I personally would recommending a json data file for saving data
this
its just for saving some small stuff no need for json
why final?
can anyone help me? my plugin's having a hard time finding my main class
Make sure you entered the correct path to your main class inside the plugin.yml
main: com.yourname.myproject.Main
If this doesnt work. Show me your Main class code
because its in a command class and it s not modified
i save the file so i dunno whats the problem
still doesnt work, here's the code
package com.servers.AllOfTheThings;
public class Main extends JavaPlugin {
private static Main instance;
public static Main getInstance() {
return instance;
}
public DataManager data;
@Override
public void onEnable() {
initialize();
listeners();
commands();
CustomEnchants.register();
this.data = new DataManager(this);
World world = (World) Bukkit.getServer().getWorld("world");
Location serverLocation = new Location((org.bukkit.World) world,
238.5,
115,
2173.5);
//new Stats(this);
Bukkit.broadcastMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "Hello World! :D");
}
public void onDisable() {
Bukkit.broadcastMessage(ChatColor.RED + "Reloading the server, a lag spike will occur!");
getServer().getConsoleSender().sendMessage(ChatColor.RED + "(!) | AllOfTheThings | Disabled | (!)");
}
}
(got rid of some voids due to char limit)
Does it throw errors inside the console?
yeah, file here for being too long
you talking to me?
@latent pilot Your missing the @Override annotation on the "onDisable"method
Maybe that causes the error
**What's the best way to efficiently read/write date to a local file upon onDisable? **
Up to this point I've only used SQL to store data for my server. However I'm interested in writing/reading local data. onDisable I want some data to get instantly written to a file so the data doesn't get lost, and read it when the server reboots to take the correct measures.
that didnt fix it. here's my plugin.yml
main: com.servers.AllOfTheThings.Main
name: AllOfTheThings
version: 2.0
description: All moderation and extra items for the server.
api-version: 1.16
?main
do i need to save my fileconfiguration when creating a new file with file.createNewFile() or something?
I personally recommend using json for storing data
it seems like the file is there, because values are read directly from the file but when the server restarts, the things are gone
And when working with big data, make reading and writing async by using the Bukkit scheduler API
im using intellij, would that be a problem? i can send you the artifact output layout if needed
I'm using intelliji aswell
and i never had that issue before
It looks very weird to me
Since i'm not seeing any issues with your files
my plugin is reading data from an empty file and it works :////
do you need to see the artifact output?
Use the Spigot Configuration API. This may help https://www.spigotmc.org/threads/yaml-configuration-tutorial.444987/
SpigotMC - High Performance Minecraft
A tutorial on how to do this async exists here:
https://www.spigotmc.org/threads/async-yaml-file-configuration-tutorial.474385/
Introduction
In this...
for some reason when i delete my plugins directory and i stop the server, the files come back, with the exact values as before
which wouldnt make sense as those are gathered during onenable
maybe you save things up ondisable?
i'm executing a method that gets the fileconfiguration (when the server files were not removed) from a field and sets some things in it
i guess that objects stays in memory with the original values or something
is there any significant benefit of using CompleteableFuture over bukkit schedulers/runnables?
the bukkit schedualer literally like calls a completablefuture with a bukkit executor
yeah it's cached, so the value are still there
and why isnt it possible to set things in it then?
hmm ok
and also plus a lot of other devs do it anyways cause it has better functionality
unless you are working with ticks, you shouldn't have to use the bukkit schedualer
I've always used async delayed schedulers when calling database stuff but if that's better I will switch
Yeah
Also the completablefuture can return a piece of data
the bukkit sched cannot do that
another reason why to use it instead
why to null??
yeah that was my other reason for asking, because I think I actually have a use for that now
cause the guide writer small brain
and dont know java
lol
lol
hmm i guess reloading or something breaks my whole config files
as they are cached
and dont belong to the original files anymore or something
When a player enters a specific command, it adds some coordinates to a mongodb database, and then when a player goes to those cords it triggers something, put in the mongodb it is adding 3 to the z coordinate, and I cant find why. Here is the code: https://paste.helpch.at/gulomomupu.cs
as a quick fix I might be able to just add 3 to the value it is comparing it to
hmm it seems the map from the fileconfiguration is cached
and when i reload my plugin, the fileconfig isnt
so if i removed my files before reloading
it is still writing in the file in memory
and when i shutdown the server the original file comes back in some magical way
It be like that
If I build my plugin with Maven, the classes that I've excluded start now with hidden.classname, but I want them completely removed from the jar
I use <relocations> from the shade plugin
When saving a player to a Player variable, does that variable become null once the player has logged off?
Would this be best to be executed async?
No
No variable becomes null just like that
I assume you'd get a nullpointer when using it though
However, the player instance itself might lose certain data
Add a Dependency
That might be if you invoke a method on that instance which does something that yields an NPE
yeah that's what I meant. Guess i'll just stick with Player#isOnline() to make sure
Not sure if that works once a player instance has become invalid
😵💫
Null checking Server::getPlayer is probably more solid here
anyone know?
why don't you simply use a bukkitrunnable
But yeah I guess this is probably a thing you'd execute async
im not going to use a bukkitrunnable for every player on join 🤦♂️
that would just lag the server
Literally wouldn’t lol
Yeah I mean I assume your TaskUtil is going to do the exact same thing anyway
I mean BunkitRunnable::runTaskAsynchronously still submits the task to its cached thread pool thus it would be executed asynchronously the same way BukkitScheduler::runTaskAsynchronously does it.
oh ok
does chunk.load() run asynchronously or not?
I don't think it does but with some of the results I am getting, I am starting to think otherwise.
I think it does on paper?
Chunk#load will load on the main thread
paper has some async alternatives
but chunk.load will live on your thread
k thx
Question. If i create a copy of a map, will it still share the same memory location of the keys and values or it changes?
// If i modify test later on, the values on someOtherMap will change too>?
Map<String, String> test = new HashMap<>(someOtherMap);
because of I modify test a entry set or something, will it also modify someOtherMap?
im wondering if anyone can help me on making a player specific variable for a scoreboard, and then displaying the top 5 people with the highest of that variable
depends on way you clone it, see https://www.baeldung.com/java-copy-hashmap. The way you showed WILL NOT clone values and keys, so they will point to the same value. If you want them to not point to the same value use external libraries or write your own implementation (i.e. Apache commons lang: SerializationUtils.clone(originalMap), though every element in map you want to be deep copied must implement Serializable).
Thought so, So I would have to clone the map correct? Damn, thank you.
no problem
this will probably be helpful: https://www.spigotmc.org/threads/how-to-hide-player-only-from-tab-list.309766/. though it uses NMS. if you dont want to deal with it you may go with external library.
No
Yes
No
like, Whats point of doing this async? You have billions of npcs? You load npcs from database?
@EventHandler
public void gui(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (event.getView().getTitle().equals("Start A Game")) {
event.setCancelled(true);
if (event.getClick().isLeftClick()) {
if (event.getSlot() == 12) player.sendMessage("public game");
else if (event.getSlot() == 14) player.sendMessage("private game");
}
}
}``` so the first time opening this gui, the slots send the messages twice, and every time i reopen the gui, the amount of messages +1
can someone explain how i use bungee
Hello, I wanted to know if there was a way to run the code inside a scheduled task on a command. For example if I run /endtasks it will end the scheduled tasks but still run the code inside of that task
Right now I am using Bukkit.getScheduler().cancelTask(task); but that doesn't actually run the code inside the task
Yes I know it shouldn't
you extract the logic inside of the task, put that in a method, then run it AFTER you cancel the task
I don't know exactly what task I am running though, I guess I could track this though
you are referring to the task in some way
if you want a systematic approach to this you can also create your own task system with your own cancellation system in it
we're not here to do your homework for you, there's plenty of resources out there that will show you how to compile code step-by-step
dm me
that's piracy what you're offering to do
I'm sure the mods will love it
I'm just trying to understand what he is going for lmao
I'm not offering to do anything
Hi, I'm making Arena Game and I don't want to spend my money by buying 30 server for each arena, so I want help with making Per World Kill Counter.
If you can help, TSYM!
If you can't TSYM for reading ❤️
@quaint mantle do discord helpers have moderation powers in here? I forget
Done. That felt good.
ill use that for now
I don't really understand what he even wanted lmao
Wow someone actually got banned for leaks or asking for leaks. Thats a first.
he wanted someone to compile illegally obtained source code from a premium plugin because he was too cheap to buy it and still had access to the source
well, compile and I assume send it to him as well
was a ban worthy?
If he was trying to pirate illegal content I would say probably, yes
well i mean it is against the rules
All leakers or people asking for leaks should be banned.
I'd say yes, hopping on the developer side of chat support to ask people to take money away from the devs takes quite the set of balls
ok yeah there banned
oof
imagine if I showed up on amazon support and started asking them to give me a fake credit card
You can say "shitty spigot knockoff hosted by a dumbass"
btw they changed the name to " infinite leaks "
idk why
They change back and fourth
bonkspigot
i used to be a moderator there, i thought its a normal website, I didn't know what "Leak" meant lol
go to jail
I still have my mod rank oof
I paid the dumbass owner to whitelist my plugin and one of his admins sent me a screen shot of him saying they were allowed to leak it still lol
that has a name, I was going to say blackmail but it's more like extortion or smth right
They're dumb, they removed "Staff" Rank but didn't remove "Moderator"
child murderer
imagine being so beta that you start leaking people's products
:)
I actually was just helping
no leak xd
beta male
the true beta move is donating to a leak website
The drama group songoda actually paid for hosting for leaksites at one point in time and they doxed the current owner of "black knockoff spigot"
oh god is songoda still going
I don't get what the issue is, it has never done that to me...
🤷 Only brought it up cause its part of the current convo
CREATE TABLE IN NOT EXISTS "PLAYERS" (
"ID" INTEGER UNIQUE,
"NAME" TEXT NOT NULL,
"UUID" BLOB NOT NULL,
"IP" BLOB NOT NULL,
"SKIN" INTEGER NOT NULL,
PRIMARY KEY("ID" AUTOINCREMENT)
);""";``` can someone check that? SQL error or missing database (near "IN": syntax error)
how tf is songoda even an llc
This is MaxiCity.java class: https://paste.md-5.net/opupijiyig.cpp
The only new thing I added is this:
registerListener(new Cancelled());
And this is Cancelled.java class: https://paste.md-5.net/sihuhiyaxa.cs
if not exists
Not in
Also please make your column names lowercase and remove quotes
ty
god reddit is clueless
Anything can be an LLC it just costs money
I know, maybe it's cheaper elsewhere but here iirc it was something like 50k € to set up
CREATE TABLE IF NOT EXISTS PLAYERS (
ID INTEGER UNIQUE,
NAME TEXT NOT NULL,
UUID BLOB NOT NULL,
IP BLOB NOT NULL,
SKIN INTEGER NOT NULL,
PRIMARY KEY(ID AUTOINCREMENT)
);""";``` like this?
make them lowercase
ID -> id
NAME -> name
why
naming conventions. To not mess column name with actual sql syntax
you alse dont need text and blob
okay that makes sense
yep double checked I am pretty sure the portuguese equivalent of an llc costs 50k€ just to set up
for Name, use VARCHAR(16)
For uuid VARCHAR(36)
For ip VARCHAR(16)
could I get any help plz?
in sql lite it doesn't work i think
It should
?paste
solved
How can I untrack an entity with my plugin? (so its non-ticking)
I already tried to remove the AI and disabled collisions.
And i set activatedTick to Integer.MAX_VALUE
hey so why am i getting a nullpointerexception
Because playerList was never initialized
how would i do so?
assign a value to the variable
for example ArrayList<Player> playerList = new ArrayList<>();
i meant like where would i do so, outside the events?
Just where it is
@digital rainYou also got typos in your methods
that doesnt matter
optionally it would be actually beneficial to save the list
no
nonono
yes
use a list of uuids
never store players
Yea but I was still right so dont say no
ur not me mum
still List<UUID> playerList = new ArrayList<>();
ok ill do uuids! :)
?
wrong, ArrayList<UUID> playerList = new ArrayList<>(); because otherwise you lose access to special ArrayList methods ;)
they're all the same
nah
find me one major java project that has no bugs, I'm waiting
hi whats the problem?
its java, thats unfair
ArrayList actually doesn't specify any public methods over List
And even then, you're supposed to refer to the interface for conventional and OOP reasons.
thanks maow
e.g. if the implementation is ever changed, you only have to change the new expression as opposed to every single usage of the type in your code base.
my github
daily nugget of wisdom
how would i convert uuid to player afterwards
Bukkit.getPlayer(uuid)
Bukkit.getPlayerExact()
bro do you even have more than... 75 stars on your github projects
ensureCapacity and trimToSize sad noices
👍
Are you even supposed to use those...?
well, those are exposed in public and not deprecated, nothing in docs says you arent supposed to
well alright then
only 1 star, not even an influencer programmer
gaze upon my mighty 76 stars and despair
ensureCapacity is useful when you wanna avoid unecessary array recreation, if you wanna add multiple elements at once
bet yall aren't even getting sponsorships from gaming linters and rgb IDEs
Also when im here i might as well ask, whats the best way to save variables and stuff
print them physically, you never know when your computer might get set on fire
Anyway to explain why you don't store Player instances in collections like this:
It's incredibly memory inefficient as you are storing a reference to a large object, therefore stopping the GC from claiming it when it is no longer in use (which I imagine Player instances are no longer in-use when they are removed from worlds/servers or whatever, but I'd have to confirm that myself)
also player instances change when they log out and log back in which tends to be a way more pressing issue
Oh yeah that's also really bad.
one of these breaks the plugin functionality and the other one saves you a few bytes, maybe start with the more important one
UUIDs are harmless though, so you should pretty much always use that over storing Players.
do a infinite loop to run the gc
