#help-development
1 messages ยท Page 1471 of 1
how can i fix it?
im using intellij and im building artifacts to my server/plugins folder
use this http://www.yamllint.com
Validate and Verify your YAML documents, optimized for Ruby on Rails
can we see your project structure?
yeah its valid
what's in the plugin jar?
in terms of classes?
just take a screenshot ._.
i cant post images here
Link your forums account
Your plugin.yml is placed inside of a package
where is it meant to be?
Root of the source folder preferably
If I have PlayerData object and store them in a Map and I modify the value inside the object, would the value on the Map changed aswell?
Yes, because the map stores the reference of the object not the copy
HashMap stores only object references. That is why, it is impossible to use primitive data types like double or int.
ah, basically I'm trying to store the last saved data and compare them on save.
If the value is different, then save the data.
unless you change the object itself
then it won't
every created object in java have a hashcode which used in Maps
if memory address doesn't match it means objects are not the same
== compares memory address of the primitive data type or object
String s1 = new String("HELLO");
String s2 = new String("HELLO");
System.out.println(s1 == s2);
for example this would output false
since two String object's memory addresses are different on heap
if you do
s1.equals(s2) then it would return true, because it doesn't check the memory address but the content of object itself
equals() method can be overriden by class if you want to create your custom equality method.
private final Map<UUID, PlayerData> map1 = new HashMap<>();
private final Map<UUID, PlayerData> map2 = new HashMap<>();
// On Join
PlayerData playerData = new PlayerData(uuid);
map1.put(uuid, playerData);
map2.put(uuid, playerData);
// On Move
map1.get(uuid).addCoins(1);
// Will the value will be the same?
broadcast(map1.get(uuid).getCoins());
broadcast(map2.get(uuid).getCoins());
something like this
yeah i'm about to test it
it should return properly for both
unless its on separate threads
since its undefined behaviour if the two threads access the same object, thread caches need to be synchronised, because we don't know when the value will be updated in the another thread
but in single thread enviroment this would work fine
i think it's pretty clear if the map only holds the reference not the copy
is there a way to lock minecraft doors?
How do I fix "your sending too many packets!" even after its been set to -1 in the .yml file
in the spigot.yml file
if someone has the answer to my question ^^
please reply or @obtuse anchor1550
set it to int limit
which is?
^^
2147483648
thanks
I saw no borders
30 seconds in, blue border around the island ;)
same on bedrock just different texture
Please help me, how create a minecraft launcher and connect the launcher with minecraft server?
how do I fix the bug of the player receiving a very weird amount when they take damage from poison, fall damage etc?
That looks like just a normal worldborder. You can resize it
the like reason why being on fire/poisoned can make your jump longer
there's one for each island
why does intelliJ tell me "Method invocation 'setExecutor' may produce 'NullPointerException'" for getCommand("mycommand").setExecutor(new myCommand());
tell intellij to ignore this warning
ok
Then its packets, as the client can only support one, they are sending a separate worldborder to each client.
hey! I'm trying to switch from static to constructors but I've done something wrong and I'm not quite sure what I did wrong. I get this error in my console: https://paste.md-5.net/sujufapopa.bash.
This is where I get it and set the lobby location in a command: https://paste.md-5.net/bugurizohe.cpp and this is the ArenaManager file: https://paste.md-5.net/recojalipe.java
MainCMD.java:51
Yeah I know. I'm just not sure what's wrong there?
hey ElgarL
as I don't see any errors there
what is line 51?
this.ArenaManager.setLobbyLocation(player, player.getLocation());
lemme try soemthing really quick
Is there a way to circumvent the wierd velocity that fall damage/poison/fall damage gives?
yeah line 51, It doesn't seem to work
Vanilla doesn't do this and the bug has been here ever since the beginning of time
ArenaManager is null
maybe bukkit messing up
well can we fix this?
also this.ArenaManager is a field so should be this.arenaManager
I know, but I don't see how I'm gonna fix that
oh
That doesn't seem to work as I'm somewhat sure it's supposed to be ArenaManager
Only a class would be called that. You set it as a field so it shoudl be arenaManager. But its null, you are never setting it
ait I changed it all now but I still get an error with this line arenaManager.setLobbyLocation(player, player.getLocation());
How do I fix "your sending too many packets!" even after its been set to -1 in the .yml file for viaversion
in the config.yml file
if someone has the answer to my question ^^
please reply or @obtuse anchor
i already tried making it -1
and the inf number it still did it
you have not set your field. The field is still null
Yeah I know, and I literally don't see how it's null
want me to send the classes and stuff?
wait... send your arena manager again? o.O
ArenaManager: https://paste.md-5.net/ukujivixuc.cpp
and the command?
is it possible to damage player without the velocity being
0
-0.0784000015258789
0
Just send yoru main class
It's a bukkit bug iirc?
here
Main onEnable: https://paste.md-5.net/apesecawok.java
ArenaManager: https://paste.md-5.net/ukujivixuc.cpp
MainCMD: https://paste.md-5.net/avejupuwub.cpp
error: https://paste.md-5.net/odowowideh.bash
this.getCommand("timv").setExecutor(new MainCMD(arenaManager)); ArenaConfig arenaConfig = new ArenaConfig(); this.arenaManager = new ArenaManager(arenaConfig, this);
Ordering
Hey choco
oh I had those two under the command :(
is there a solution to the unwanted velocity?
I don't know. I'm not sure I'd even consider it a bug because that's just vanilla functionality
How do I fix "your sending too many packets!" even after its been set to -1 in the .yml file for viaversion
in the config.yml file
if someone has the answer to my question ^^
please reply or @obtuse anchor
i already tried making it -1
and the inf number it still did it
I'm so blind i stg... thank you
Im pretty sure vanilla doesn't have it
how can i get the amount of blocks a player has mined?
the api says player.getStatistic(Statistic.MINE_BLOCK) but it says it requires an additional parameter do i really need to add all the blocks :/
umm, i don't need to do that.
player.getStatistic(Statistic.MINE_BLOCK); works fine
it gives an IllegalArgumentException and says it needs an additional paramater :/
console dont lies
yeah statistics aren't tracked globally, only per-block
same issue as with the deaths statistic
huh
ah true
you mean deaths are tracker per player?
nevermind
or maybe i can specify an array with the blocks that needs to be counted
use an enumset
sure
okay
or something like this
Material[] blocks_mined = {Material.STONE, Material.ANDESITE};
EnumSet<Material> materials = EnumSet.of(
Material.STONE,
Material.ANDESITE
);
If I add this --add-opens java.base/java.lang.reflect=ALL-UNNAMED, I have access to reflection, but how to automatically add this? So people don't have to start up their server with this line
and how do i get the amount of those blocks the player mined?
by looping the set
public void getTotalMinedBlocks(Player player){
int total = 0;
for(Material material : materialSet){
total += player.getStatistic(Statistic.MINE_BLOCK, material);
}
return total;
}
if you want to get all materials, just change materialSet to Material.values()
@maiden briar you don't
Ok ๐ฆ
Are you having issues accessing private/static fields?
Blocked by teh Security manager?
That could be possible
simple question, is your error thrown when you setAccessible?
hi there. How i can cancel moving item in offhand with F hotkey? InventoryMoveItemEvent, InventoryClickEvent and InventoryDragEvent don't helps
PlayerItemHeldEvent
- This does not work
- I need to switch between slots.
k, i'll try
Thx
Thank you so much!
Is there a good working ArmorEquipEvent? Using https://github.com/Arnuh/ArmorEquipEvent/tree/master/src/com/codingforcookies/armorequip, when e.setCancelled(true), the armor is duped.
how much ticks is one second in minecraft?
how do I prevent players from using the offhand
20
20
okay thx
declaration: package: org.bukkit.event.player, class: PlayerSwapHandItemsEvent
what about putting in the off hand in the inventory
paper api has it afaik.
check slit
what about without using paper?
using libs like that ig
how can i send a countig down 3, 2, 1 title?
repeating tasks
p.spigot().sendMessage(*your needs*) in BukkitRunnable
or scheduler
yes player.sendTitle("")
ah. yes
that's for actionbar
sry
not action bar, player.sendTitle
A combination of InventoryClickEvent with MOVE_TO_OTHER_INVENTORY and PLACE_ALL Action and the PlayerInteractEvent could work
In a BukkitRunnable that self cancels once done
hmmm
why i need in PlayerInteractEvent?
thx
If you right click with a armor piece in hand, you equip it
you will also equip armor if a dispenser fires at you
PlayerPickupItemEvent works too
That's deprecated
k
at least for me
i'm going to realize it
its entity now
as if deprecations meant anything
you can still use the ages-ago-deprecated sync chat event
Shift + Left Clicked
I thought MOVE_TO_OTHER_INVENTORY would solve that
woops
@quaint mantle if you were concerned about being optimized, you'd be using paper
but, it's not that heavy unless your server has armor items with super large itemmeta
and lots of players wearing armor
paper has several significant bugs for me with my assembly.
:)
sounds dubious, but i won't debate that here
You could test if it's a Shiftclick on armor
or you could use redlib which has an armor change event
i'll try
Is there a way to reload a world after unloading it using Bukkit.unloadWorld that is not restarting the server?
?paste
worldcreator or something, I don't remember
https://paste.md-5.net/nuhomeyixa.java can i use this code?
for what?
ik but except the permission?
use the bukkit scheduler instead of the bukkit runnable
use english variable names
if u want to loop this - use scheduler
other than that it's fine
okay
help I can't prevent players from placing items onto their off hand
if(event.getRawSlot() == 45 && event.getSlot() == 40)
{
event.setCancelled(true);
}
I did this but if they click at anything above like 4cps it goes in anyway
thx, I'll try
is there a good tutorial for the BukkitSheduler?
yes, the documentation and the wiki
also using bukkitrunnable instead of bukkit scheduler here is the least of your worries
at present your command will explode if used from console
call updateInventory or whatever
but you cant send the command from the console in my code
no i check if the sender is a Player
no you don't
you just cast to player
Player player = (Player) sender;
this explodes if sender is not a Player
and if it isn't it dies lol
you are not checking whether it's a Player before casting
oh yes okay
?paste
call player.updateinventory or something
ppl can still place item in off hand by spam clicking
how do I even get the player from InvetoryClickEvent
The closest is HumanEntity which doesn't allow updateinvetory
check and cast
Cast it
HumanEntity extends Player?
Player extends HumanEntity
if HumanEntity extended Player, you wouldn't need to cast
because HumanEntity is a Player
oh dats right
dats xD
k, PlayerChangedArmorEvent from RedLib haven't e.setCancelled() method. I'm going to make crutches.
Anyone know what is the safest way to use premium resource placeholder?
how can i clear built blocks from a player?
how i can delete item from player inventory in PlayerChangedArmorEvent? item.setType(Material.AIR); doesn't works
use events
k
pretty sure that's not an event
that's event from RedLib
I don't know how to use this to get the modifiers field of a Field (MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup()).findVarHandle(Field.class, "modifiers", int.class), when calling this I get the error
You got the Inventory and ItemStack object yes?
yup
Hello. I want to ask. How can i try/catch this error. Caused by: java.lang.AssertionError: TRAP. I look on internet for what it means and i find out that if item is removed from inventory when player just interacted with it. So i want to ask how i can try/catch it. I tried everything to try/catch but still.
then just Inv.remove(Item)
i'll try
it removes all of ItemStack item from Inventory Inv
But that item is in another class.
that's for multiple items and returns a HashMap
use remove
So I have 2 classes. 1st is for joining into arena and 2nd is for leaving it. So in 1st class is that ItemStack that leaves player from arena.
so you want to give player an ItemStack when then join the arena and remove it when they leave?
removeItem and remove:
https://imgur.com/VbjFyBv
When they interact with bed to leave it clears inventory their inventory and that error happends
why not Inventory.clear()
when i use that i got that error.
PlayerInventory playerinv = player.getInventory();
playerinv.clear();
well I'm guessing you want to delete the armor whenever they put on any? This way just Inventory.clear(SlotNumberForArmor)
And my friend tells me that it might me server problem.
i'll try
are u checking Player?
And use Inventory
it's not PlayerInventory playerinv
it's Inventory playerinv
uh it's up to me how i call it
No i want to get player inventory
it's not up to you
and clear that
yes but Player's inventory is still an Inventory
just try it man
can't hurt you
PlayerInventory just does stuff with their hands and armor
not useful for you
same error.
well at least we know it doesn't make a difference
did you do Inventory.clear when the player is in bed?
or just when they click the bed
what event did you use
"NoSuchFieldException"
nothing changes
No clue then
ah, i have an error
did you use the correct slot
also why would you need whatever that lib is anyway
just use the InventoryInteractEvent or whatever it's called
for to cancel armor equip
it isn't helps
cancel and delete is different
bruh. I need to drop it from this slot. I'm using deleting(clearing) item and dropNaturally
Thanks for help. My friend helped me and it worked.
why drop
i just need to stop event.
and not just put it back
IT IS NOT CLEARED
VarHandle MODIFIERS = MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup()).findVarHandle(Field.class, "modifiers", int.class); the problem is at this line, no clue how to solve
Are you calling this inside the AccessController?
how can i add 1.8 support to a 1.12 plugin?
If I force this argument to the compiler --add-opens java.base/java.lang.reflect=ALL-UNNAMED I don't get any errors
wrap in an Access controller and see if it still fails
How to wrap in it?
Oh this one, let's try
hi elgarl save me
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
// code here
return resultl;
}
}```
that is only going to stop very specific actions
Your raw is different to your slot, so its only if you have an inventory open
AccessController.doPrivileged(new PrivilegedAction()
{
public Object run()
{
try
{
return MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup()).findVarHandle(Field.class, "modifiers", int.class);
}
catch(NoSuchFieldException | IllegalAccessException e)
{
e.printStackTrace();
return null;
}
}
});```
How can I set the field then? Or do I need to do it inside the run()? `private static VarHandle MODIFIERS;`
have you debuged that?
try it and see?
Ok
it seems like it's just the server didn't respond fast enough and the client is just like screw it Im placing it in there or smth
I have confirmed 45 is 40
Does it ever prevent the placement?
it does until the player spam clicks
try calling an inventory update after teh cancel
tried it
so delay the update 1 tick
how do I do that
java.lang.IllegalAccessException: module java.base does not open java.lang.reflect to unnamed module @aeb947a
private static VarHandle MODIFIERS;
static
{
AccessController.doPrivileged(new PrivilegedAction<VarHandle>()
{
public VarHandle run()
{
try
{
MODIFIERS = MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup()).findVarHandle(Field.class, "modifiers", int.class); //HERE
return MODIFIERS;
}
catch(NoSuchFieldException | IllegalAccessException e)
{
e.printStackTrace();
return null;
}
}
});
}
What r u trying to do?
Changing Final modifier from field in Java 16
He's trying to access a "modifiers" field but its being blocked by the SecurityManager
Cant you use unsafe for that or no?
This should work, but it seems its not for him https://stackoverflow.com/questions/41265266/how-to-solve-inaccessibleobjectexception-unable-to-make-member-accessible-m/41265267#41265267
@eternal oxide then what
make p final
final Player p = (Player) event.getWhoClicked();
final Player p = (Player) event.getWhoClicked();
new BukkitRunnable() {
@Override
public void run() {
p.updateInventory();
}
};
and after the } on the BukkitRunnable. type .runTaskLater
https://stackoverflow.com/questions/41265266/how-to-solve-inaccessibleobjectexception-unable-to-make-member-accessible-m/41265267#41265267 I tried this also with the modifiers field itself, but then I get NoSuchFieldException
auto complete to see the method
yes
@maiden briar try this https://www.baeldung.com/java-unsafe
so I need to do the dependency injection thing again
Ok
I need to cast main to plugin?
no
it asks for a plugin so
the instance of yoru plugin
wait wat
your instance extends JavaPlugin which extends Plugin
so Main
not just Main, but an instance of Main
the instance of your Main, via DI
oh....
for some reason my main was un-capitilised
which made me reference the wrong main
yes, it shoudl be
a Class is Capitolised, a field is camelCase
there we go
if(event.getWhoClicked() instanceof Player)
{
final Player p = (Player) event.getWhoClicked();
new BukkitRunnable() {
@Override
public void run() {
p.updateInventory();
}
}.runTaskLater(main, 1);
}
It doesn't say how to set FINAL fields
final int Number = 1;
I donโt think it matters whether the field is final or not
Ok
He's talkking about reflective field access ๐
If itโs an instance variable it definitely doesnโt matter for unsafe
oh
True constants (static final) wonโt get affected
@eternal oxide This is fine yeah?
yes
And static final fields?
it still blocks most but spam clicking gets passed?
no
di dyou even canel it?
doesn't even try
@EventHandler
public void OnClickOffhand(InventoryClickEvent event)
{
if(event.getRawSlot() == 45 && event.getSlot() == 40)
{
event.setCancelled(true);
if(event.getWhoClicked() instanceof Player)
{
final Player p = (Player) event.getWhoClicked();
new BukkitRunnable() {
@Override
public void run() {
p.updateInventory();
}
}.runTaskLater(main, 1);
}
}
}
You are supposed to cancel it still, but then in yoru runnable update the inventory 1 tick later
you will likely need to also cancel in teh inventory drag event
- It doesn't attempt to stop it if Im not placing in a full stack
so scrap all the runnable
- spam click is still fine
- I can shift click things that defaults to the offhand slot into it
it there a better way man
java.lang.IllegalArgumentException
[15:25:38 WARN]: at java.base/jdk.internal.misc.Unsafe.objectFieldOffset0(Native Method)
[15:25:38 WARN]: at java.base/jdk.internal.misc.Unsafe.objectFieldOffset(Unsafe.java:1066)
[15:25:38 WARN]: at jdk.unsupported/sun.misc.Unsafe.objectFieldOffset(Unsafe.java:650)
[15:25:38 WARN]: at me.tvhee.tvheeapi.api.reflection.Reflection.setStaticField(Reflection.java:282)
[15:25:38 WARN]: at me.tvhee.tvheeapi.api.reflection.Reflection.setStaticField(Reflection.java:270)
[15:25:38 WARN]: at me.tvhee.tvheeapi.spigot.core.BukkitPluginLoader.onLoad(BukkitPluginLoader.java:34)
[15:25:38 WARN]: at org.bukkit.craftbukkit.v1_16_R3.CraftServer.loadPlugins(CraftServer.java:394)
[15:25:38 WARN]: at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:251)
[15:25:38 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1065)
[15:25:38 WARN]: at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:289)
[15:25:38 WARN]: at java.base/java.lang.Thread.run(Thread.java:831)```
Keeps going over, had to force stop the server
`unsafe.putObject(null, unsafe.objectFieldOffset(reflectedField), object);` static
`unsafe.putObject(this.object, unsafe.objectFieldOffset(reflectedField), object);` normal
You will need to cancel both click event and the drag event.
The click event is the one that happens dropping an item in. The drag is if you are spam clicking in the box and you accidentally move the mouse as you click
no
just remember a Class should have a specific task. So if you want to prevent that specific slot being used, you put all the events for that in one class.
yeah ik
You can have teh same events in other classes for other objectives.
the class is named BanOffhand
I know but it just feels "Unclean"
I feel like it's not done cleanly
Clean/tidy comes with experience
:/
is it possible to change hikari logger prefix
because this one is one big ugly one
[me.mraxetv.beasttokens.sqllib.hikari.HikariDataSource]
problem is it is static final
https://gyazo.com/b75de3af67f3b535d8c890b01b047e46
this is what I was using
before to change it
https://gyazo.com/13bbfa65645122c420e3fc68dbbbc1d4
but not working in Java 12+
so I am stuck
๐
Add a handler
any example of what do u mean
hey I'm having a problem building my plugin
Error: Failed to execute goal on project APTurrets: Could not resolve dependencies for project snowleapord.github.com:APTurrets:jar:2.5.a: Failed to collect dependencies at org.spigotmc:spigot-api:jar:1.14.4-R0.1-SNAPSHOT -> net.md-5:bungeecord-chat:jar:1.13-SNAPSHOT: Failed to read artifact descriptor for net.md-5:bungeecord-chat:jar:1.13-SNAPSHOT: Could not find artifact net.md-5:bungeecord-parent:pom:1.13-20190406.085510-73 in spigot-repo (https://hub.spigotmc.org/nexus/content/repositories/snapshots/) -> [Help 1]
anyone know what is up with that?
logger.setUseParentHandlers(false);
handler = new LoggerHandler();
logger.addHandler(handler);```<https://github.com/ElgarL/GroupManager/blob/master/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java>
Am I able to change my already existing plugin to a premium plugin?
no
Look at the subinterfaces https://hub.spigotmc.org/javadocs/spigot/org/bukkit/persistence/PersistentDataHolder.html
well there is a server that has a plugin who's able to lock doors
so i was wondering how to do it then
you track doors in some form of DB
or on the chunk PDC
validate the data on chunk load
Is there a way to have more colors in one line of lore?
add more colors
or just use ChatColor#translateAlternateColorCodes
I haven't done spigot for months and I've been doing too much pure java, how do you print to console (I'm pretty sure you're not meant to System.out.println(String msg))
well, you can, but using the logger is better
declaration: package: org.bukkit, class: Bukkit
you can use the logger to print messages
oh yeah, getLogger().info(); thanks
DB?
database
well how do i validata the data on chunk load? ๐
You read the data you have stored there, and check it corresponds to actual doors in the chunk
no
Its exactly as you are currently doing in teh TileEntity PDC, but you store a map of that data against location keys in the chunk PDC
hmmm
turns out I just had to put + between different colors for the lore
so a hashmap?
with some data and a location
I'm wondering how to add this on my existing piece of code
so i have this now
Player p = event.getPlayer();
Location l = p.getLocation();
Chunk c = l.getChunk();
don;t use teh players location for the chunk, use teh block location
ok
player could be stood in a different chunk
like this
Chunk c = block.getLocation().getChunk();
PersistentDataContainer chunkContainer = c.getPersistentDataContainer();
is there a known way to freeze a player at a position, but he can still look around (change his yaw and pitch)
cancel move event if x.y or z change
i made something like that
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (MagmaBuildNetwork.getFrozenPlayerList().contains(event.getPlayer().getUniqueId())) {
if (event.getTo().getBlockX() != event.getFrom().getBlockX() || event.getTo().getBlockY() != event.getFrom().getBlockY() || event.getTo().getBlockZ() != event.getFrom().getBlockZ()) {
event.setCancelled(true);
}
}
where MagmaBuildNetwork.getFrozenPlayerList() returns a set of players uuids who are 'frozen'
but ElgarL how can i add that piece you said to the code I already have?
https://paste.md-5.net/avelemimaz.cs
you change how you are creating your keys
but if the block is a tileState it converts to tilestate but how can i check if it's a door, fencegate etc?
class Openable I assume
yes
well something that i found myself ๐คฃ
javadocs are excellent when you learn to use them ๐
uhu
is it a good idea to use CraftPersistentDataContainer to create an new instance PersistantDataContainer ?
You should never create a new instance.
y ?
something like this?
if (!(blockState instanceof TileState) || (!(blockState instanceof Lockable) || (!(blockState instanceof Openable)))) return;
if (blockState instanceof Openable) {
TileState tileState = (TileState) blockState;
PersistentDataContainer container = tileState.getPersistentDataContainer();
}
Why would you ever want to create a new one? and why are you using Craft items?
I'm probably doing it wrong
if you move all your data to the chunk you can replace all your tests
wdy mean?
cuz I can't find a way to make this work
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/persistence/PersistentDataType.html#TAG_CONTAINER_ARRAY
once it gets past this java if (!(blockState instanceof TileState) || (!(blockState instanceof Lockable) || (!(blockState instanceof Openable)))) return;You know its lockable for you.
It doesn;t matter what the block is beyond that
but what about moving that data to the chunk?
just create your key plugin, blockX + "|" + blockY + "|" + blockZ
store your UUID under that key on the chunk PDC
any block you want to check if its locked you generate a key like that and see if the PDC has an entry
blockX + "|" + blockY + "|" + blockZ
which one lags more?
getting data from mysql without async
or setting data in mysql without async?
i want to know because i have few things
both lag to hell and could crash out your server
The lag comes from the delay between the 2 servers
which one more?
it will alwasy vary
It doesnt matter
oke
String s = block.getX() + "|" + block.getY() + "|" + block.getZ();
NamespacedKey chunkOwnerKey = new NamespacedKey(MagmaBuildNetwork.getPlugin(), s);
i just wanted to know which one actually makes more
The time between will vary so much there is no "which is worse"
oke
The SQL part is quick usually, it's the request having to travel between servers which is the lag
If there are millions of records it might be slow though
i just had this question in my mind, because at 1 point i forgot to use async but it didn't lag a lot
so i got the data and it didn't lag
and i had another code does the same but lags
If you are working with a database on your pc you wont notice it unless SQL hangs somewhere
or it hits the HD
if you use java 16 with native unix sockets and the mysql server is on the same host, you won't have much of a delay depending on hardware and resources.
@eternal oxide how do i use that key in this case?
you use that to store the UUID that is locking the block in the chunk PDC
but you were talking about locations, what was that then?
some one know how to remove hologram?
destroy the armor stand
hiii, if anyone is available to give me a hand with crafting recipes, i'd appreciate it <3 https://www.spigotmc.org/threads/custom-crafting-recipes.508493/ made that post because im stuck xD
pretty sure I gave you that command a few days ago
teh armorstand is an entity, use .destroy()
so the key stores the x, y, z and an uuid?
no, just the x,y,z
dont really understand sorry
you already store the UUID under a key, this is just changing the key to use the blocks location
as you are storing the uuid on teh chunk and not teh blocks TileEntity, you have to use a key that represents the block
how to make an server chat message again i forgot
no
like uhh it like speaks in the chat kinda. im probably explaining it weird
well but how can i check if the player has access to that (for example door)?
you built a key for a block
you build the key again and check if it exists in the PDC
You have to manually transfer the lore and enchants
mmm
inventory slot
confusion D:
get the ItemStack in the slot
oki, lemme figure out how to do that
im hella new to bukkit so my head is just imploding
There are two events, prepareCraftItemEvent and a craft event
so if the key with the location exists in the pdc?
thank you good sir
Then somethgin is locked at that location
you get the entry and check the UUID
how can i get the uuid of it isnt stored :/
Its exactly as you are doing now, but not on the block so you have to use the location
You store it as I said earler
You seem to be not understanding what a key is and what the value is
okay, and using that event https://lukemango.com/9tKum.png - how do I select a slot to get the itemstack?
yes i do but its confusing how you explain it
in teh Matrix
Probably. one sec I'll throw some code
something like this?
String s = block.getX() + "|" + block.getY() + "|" + block.getZ();
NamespacedKey chunkOwnerKey = new NamespacedKey(MagmaBuildNetwork.getPlugin(), s);
AND
container.set(chunkOwnerKey, PersistentDataType.STRING, p.getUniqueId().toString());```
how can i add 1.8 support to a 1.12.2 plugin?
yes
but i'm stucked how to implement it in the code i already have
?paste
do you have a handle to teh armorstand?
oof
I also have the normal lock inside the code to evaluate tilestate entities
you don;t need tilestates nor data on the block if you store on the chunk. But you do need to clean up your data on chunk load or unload
how?
Thats not quite so easy as you have locations stored in teh keys. Sec and I'll show you.
is declaring an owner for a specific, entire chunk not what he wants?
i didn't read any of the conversation
nah, he's storign lock data on specific blocks
you'll want a singular key then with a Set<Block> or Map<Block, UUID> value
He's concat x,y,z in teh key
yeah, don't do that
its fine for his first attempt
i suppose
Not tested it, but that should remove any locks in the PDC that do not have a corresponding block that you want to lock.
ie, someone breaks a locked chest or door, when that chunk unloads that lock data gets removed.
or the server runs (for some reason) without your plugin loaded for a while.
iirc there have been some arcane issues with accessing blocks in the chunk unload event
but my memory about that is very foggy and I think it had more to do with neighbors than just directly accessing the chunk
also what are we doing? why are we storing this in the chunk?
he wanted to lock things other than things that had TielEntities
yep
dealing with TE's might be redundant then
I'd just do ```java
private boolean canLock(BlockState state) {
return (state instanceof TileState || state instanceof Lockable || state instanceof Openable);
}```
since you'll be using some sort of a transient in-memory blockkey -> data map anyway
is openable even related to state? isn't that data
and yes, I told him to not bother with anything on the TileEntities
um, I'll check
i vaguely remember it being blockdata rather than blockstate
myeah just grab data and instanceof
return (state instanceof TileState || state instanceof Lockable || state.getBlockData() instanceof Openable);
Just BlockState instance Lockable would achieve that, no?
It encompasses all of these
doors aren't Lockable
Yeah by design
The Lockable interface represents objects that have the Lock NBT tag in vanilla ;p
but yeah I suppose the tilestate check could be removed as we don't really care about things being tiles anymore
not that anything could be Lockable without being a Tile but iirc the api doesn't reflect that
My basic example https://paste.md-5.net/osideheduz.java
what are the semantics of the chunk unload event again?
semantics?
i remember someone having issues with cyclic/recursive chunk loads caused by getting the contents of a chunk during the chunk unload event
No clue, I've never used it, but it seemed the most sensible place to put the cleanup code
might've been caused by them calling World::getChunk rather than ChunkUnloadEvent::getChunk
possibly
i remember there was some noob trap there that makes shit explode
does it make sense that an entity is valid but not in a loaded chunk?
For a short time, yes
define short time
till cleanup after it moved into an unloaded chunk
wdym cleanup
I'm guessing Entities get cleaned up seperate to chunks unloading
the new chunk system is a headache
i'm pretty sure the entities get invalidated and serialized with the chunk when it unloads
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player hurt = (Player) event.getEntity();
Player dealer = (Player) event.getDamager();
if (hurt instanceof Player) {
if (dealer.getInventory().getItemInMainHand().hasItemMeta() && dealer.getInventory().getItemInMainHand().getItemMeta().getLore().contains(ChatColor.GREEN + "- Blinding")) {
hurt.removePotionEffect(PotionEffectType.BLINDNESS);
hurt.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 2, false, true));
//when player is not wearing a helmet this line here always sends an error
if (hurt.getInventory().getHelmet().hasItemMeta() && hurt.getInventory().getHelmet().getItemMeta().getLore().contains(ChatColor.GREEN + "- True Sight")) {
hurt.removePotionEffect(PotionEffectType.BLINDNESS);
}
}
}
}
}
}``` I am always getting any error sent to console when the player is not wearing any helmets why is that? can someone please help
but when a chunk actually unloads is different from when the api considers it to unload
because under the hood there are like different load levels and shit
and the api doesn't reflect that
?paste the error
it's all just ugh
CounterEffects.java:27 Something is null there
no
If he has no helmet you can't call .getItemMeta() on it
do you know a way i can fix that please?
test if he has a helmet first
?jd The javadocs are your friend. Always test anything that can be null.
package index
so i am checking if the player is wearing a helmet first before running the code?
yes
or air ๐
right, yeah, mystery solved
it was caused by load levels
apparently the api doesn't consider chunks with a load level below entity activation as loaded
however entities in such chunks are still valid
I stopped getting the error from when the player didn't have a helmet now I get an error for checking if their wearing a helmet
how are you checking?
return;```
you can;t getType
getType will never be null
getHelmet may be null
if getHelmet is null, then the value you're calling getType on has nothing to be called on
which throws a nullpointerexception
alright I will try removing the get type
you should try learning java
He's close
no really, look up a tutorial somewhere, you'll have a much easier time
A lot of people have trouble understanding null
a lot of people should gb2 the tutorials
I am learning java but not the best at it yet tbh
null is an odd concept it doesn't really exist in most languages.
good luck!
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player hurt = (Player) event.getEntity();
Player dealer = (Player) event.getDamager();
if (hurt instanceof Player) {
if (hurt.getInventory().getHelmet() != null && hurt.getInventory().getHelmet().getType() != Material.AIR) {
return;
} else {
if (hurt.getInventory().getHelmet() != null && hurt.getInventory().getHelmet().getType() != Material.DIAMOND_HELMET && hurt.getInventory().getHelmet().hasItemMeta() && hurt.getInventory().getHelmet().getItemMeta().getLore().contains(ChatColor.GREEN + "- True Sight")) {
hurt.removePotionEffect(PotionEffectType.BLINDNESS);
}
}
}
}
}
}
I stopped getting the error but however when the player is wearing that helmet they still get blindness
thank you it is hard but fun
What error
Dont worry,
Can you show the line 27
CounterEffects class
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player hurt = (Player) event.getEntity();
Player dealer = (Player) event.getDamager();
if (hurt instanceof Player) {
if (dealer.getInventory().getItemInMainHand().hasItemMeta() && dealer.getInventory().getItemInMainHand().getItemMeta().getLore().contains(ChatColor.GREEN + "- Blinding")) {
hurt.removePotionEffect(PotionEffectType.BLINDNESS);
hurt.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 2, false, true));
//when player is not wearing a helmet this line here always sends an error
if (hurt.getInventory().getHelmet().hasItemMeta() && hurt.getInventory().getHelmet().getItemMeta().getLore().contains(ChatColor.GREEN + "- True Sight")) {
hurt.removePotionEffect(PotionEffectType.BLINDNESS);
}
}
}
}
}
}```
the error was from this code but then i changed it to the one u just saw
um could you provide the line 27
btw why are you casting (hurt instanceof Player)
hurt is an entity right
yes
ah nvm
Do a null check maybe
this code right here i think i did it and this code also gives no errors but why is the player still getting blindness
How to save and set someones inventory?
I know this example is very simple, but wouldn't it be like this?
Doesn't work
Doesnโt it?
As far as I knew it did
oh here im again
What is the problem ? What do you want to do exactly
I think when you do : Inventory inv = player.getInventory() the method will return the class not a copy of the inventory so when you clean the player inventory, inv will also become empty, so when you will set inv to a player inventory nothing will be put because inv is empty
saving the player's inventory
this doesn't do what you expect it to do
Yes
what you are doing here is not copying the player inventory, nor are you copying its contents
I think you have to save the content
what you are doing is copying the reference
you then call clear() on the original reference, which tells the object that it refers to to clear its contents
your copied reference, however, also points at this same object
Better explained than me haha
so using the copied reference 'inv' to access the contents gives the same results as with the original player.getInventory() reference; empty
is .isItem false for stuff like "potatoes" and "carrots"
yes
depends
ok ty
carrots block or potatoes block
ageable
never remember which one is the item and which is the block
potato is item
yes im trying to filter out all items that arent actually items from material#values
potatoes is block
Material.values().stream()
.filter(Material::isItem)
.collect(Collectors.toSet());```
sssttreeeeammms
A random bukkit post from 2016 explained it quite well
it works! Basically using ItemStack[]
yes, retrieving the ItemStack[] returns a clone
as does almost any other itemstack related operation in bukkit
thanks man
:D
can i put several checks in the .filter?
.filter again
ok ty!
just don't do it all of the time
the material enum is enermous and streams aren't super fast to begin with
filter(Material::isItem) is the same as filter(m -> m.isItem())
which is the same as filter(new Predicate() {@Override public boolean test(Material m) { return m.isItem();}})
yes but a lambda is nicer for the eyes
a lambda is also cheaper than an anonymous local class
is Arrays.stream(Material.values()) and Material.values().stream() the same?
so to store the lock on the chunks pdc what do i have to do?
did you not look at my last paste?
im testing it
you should read it and understand it instead of testing it
He will have to, It doesn;t do everything he wants
bet you're on a version < 1.14 lmao
No idea, you haven't posted anything
blockState.getBlockData()
Cause what? You've been rambling about something but posted nothing.
ow it just does nothing
do i need to set an api version?
Fatal error trying to convert MagmaBuildNetwork v1.0:io/github/FourteenBrush/MagmaBuildNetwork/PluginCommandExecutor.class
org.bukkit.plugin.AuthorNagException: No legacy enum constant for ANDESITE. Did you forget to define a modern (1.13+) api-version in your plugin.yml?
are you building for a specific version?
nope
Do you intend this to run on any version or only x+
this stupid thing
EnumSet<Material> materials = EnumSet.of(
Material.STONE,
Material.ANDESITE,
Material.COBBLESTONE,
Material.DIORITE,
Material.GRANITE
);
public int getTotalMinedBlocks(Player p){
int total = 0;
for (Material m : materials) {
total += p.getStatistic(Statistic.MINE_BLOCK, m);
}
return total;
}
set an api version in your plugin.yml
ke
how do i get the block the projectile hit in a projhitevent?
lock thing is going like brr again
how does ChatColor#getByChar work?
See if you can figure it out https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/ProjectileHitEvent.html
1.8.8
Shoo
think it gives early return
not a method
@eternal oxide bro I am so sorry for pinging you, i just wanted to let you know that I fixed the code i had == & != mixed up, thank you for your help
Hello, I am having issues with this line of code:
if (ChatColor.translateAlternateColorCodes('&', e.getClickedInventory().getTitle()).equals(ChatColor.GREEN + "Main Menu")) {
It just doesn't work. And it also says .gettitle is deprecated, what's the replacement then?
What I am trying to do is cancel inventoryclickevent on a custom gui. Thanks!
getView
How Would I implement that?
event.getView()
if (ChatColor.translateAlternateColorCodes('&', e.getView.getTitle()).equals(ChatColor.GREEN + "Main Menu")) {
like that?
Yup. It works
Thanks!
please dont find your GODDAMN CUSTOM INVENTORY BY ITS NAME AAAA
How do you reccomend me to find it?
store something in the backend
what if someone renames a chest to that and places it down and opens it?
it'll have the same name.
With color codes? Nah, plus the clicked items is also custom
Thanks though! I'll take it
it's very possible if the server has a plugin for renaming items with colors; mine does.
strongly recommend finding it via something not accessible by the user
Allright, thanks
not doing anything
oh what
[20:38:10] [Server thread/INFO]: FourteenBrush issued server command: /lock set
[20:38:12] [Server thread/INFO]: No Lock exists for this block!
Store teh view when they open the GUI. you can then simply compare the instance
if if not exists set one ._.
can do that too.
but not via the name
its maybe some strange code but i think it can work
i'm only wondering how to get the data of the uuid ingame
something with /data prob
I just tested this code. It works without fault. It places a lock if there is none, and keeps them between server starts https://paste.md-5.net/vojuqopocu.java
and it cant get removed the lock when the chunk unloads for example?
no
dont you need to update the state?
no, nothing is stored on the block, its on the chunk PDC
hmm
night
people, lol
uhh
lizard people
tf
neh
I'm getting a list of all the materials with Material.values(), then adding it to another list if if (c != null && c != Material.BARRIER && c != Material.BEDROCK) {, basically any non survival obtainable block. I'm using 1.8.8, and I'm pretty sure there's some other invalid items, for example Item entity 16163 has no item?!
Is there a clean way of getting all the survival obtainable items (as a Material[])?
Material 1.8.8 docs: https://helpch.at/docs/1.8/org/bukkit/Material.html
kek
yup
yeah, but then there are quite a few items that have no value, but aren't null
spawneggs
Air has a value
Are the item id's in order?
No material in the array will be null
hmm not sure
is there, and this is a longshot, a way to call like getBlocks or something on a chunk
to get all solid blocks
Nested loops
Ahh ok
but no method
for (int y = 0; y <= 255; y++) {
for (int x = 0; x <= 15; x++) {
for (int z = 0; z <= 15; z++) {
world.getBlockAt(x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16)).setType(Material.AIR, false);
}
}
}
like this? ^^
i bet you do
i bet you do
what is the way to destroy block + tile entities and stuff
Bukkit.shutdown()
set to Air and it will remove any TileEntity
if you set to any other type the TE may not be removed, or be the wrong type
Okay
@EventHandler
public void onChunkLoad(ChunkLoadEvent event){
if (!event.isNewChunk()) return;
Chunk chunk = event.getChunk();
World world = chunk.getWorld();
if (chunk.getZ() == 0) return;
if (chunk.getZ() == -1 || chunk.getZ() == 1) return;
for (int y = 0; y <= 255; y++) {
for (int x = 0; x <= 15; x++) {
for (int z = 0; z <= 15; z++) {
world.getBlockAt(x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16)).setType(Material.AIR, false);
}
}
}
for (Entity entity : chunk.getEntities()) {
entity.remove();
}
}
This code is causing some real issues
[20:13:29] [Server thread/WARN]: Tried to load a DUMMY block entity @ BlockPosition{x=-683, y=45, z=79} but found not block entity block Block{minecraft:air} at location
[20:13:29] [Server thread/WARN]: Tried to load a block entity for block Block{minecraft:air} but failed at location BlockPosition{x=-683, y=45, z=79}
Ig it is because they would be filled once the chunk is generated... anyone know how to stop this?
it's telling you that you're a dummy
im gonna laugh
do it
BWAHAHAHAHAHHAHAHHA
getState() setType then update(true)
it has to be forced to wipe the old TE
block.getState().setType(Material.AIR);
block.getState().update(true);
Like this? Im not sure what you mean by update
yes
ok, ill give it a shot
so store the state?
state = block.getState();
state.setType(Material.AIR);
state.update(true, false);```
added a false if you want no physics
um, what the heck are you doing to get that?
how would i loop all the bungeecord servers in a for loop?
probs like getServers() or something
Oh, you are doing this in teh ChunkLoadEvent?
yuhuh
IDE threw an error for that
oh my
yeah
Yeah good luck with that. I'd run it a tick after it loads
changing it during load is going to be problematic
as during that event its not yet loaded and you makign changes will try to reload it
Can i just supress the warnings? ๐
is there a better way to do this
List<String> allBlockStrings = new ArrayList<>();
for (Material block : allBlocks) {
allBlockStrings.add(block.toString());
}