#help-development
1 messages · Page 1367 of 1
build against 8, run on 15 (mostly)
can someone show me an example of some gui system with many many custom items?
i need to create about 250 custom items
and making them 1 by 1 is going to be a nightmare
Hi, is there an event for when the open his own inventory ?
Cause the InventoryOpenEvent does only fire when it opens and other type of container than his own inv
Oh ok
not sure if I'm dim here but I'm trying to colourize a string and the method only accepts characters but it wont let me parse them in ``` public static String format(String s) {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
s = ChatColor.translateAlternateColorCodes("&", c);
}
return s;
}```
wow that was dim
Also you just translate the whole string, not each individually
You have it backwards, as the docs would tell you
if(args[0].equalsIgnoreCase("redeem")) {
Inventory inv = gui.getInv();
player.openInventory(inv);
}
this is run everytime someone rund a command with redeem as the argument
obviously
Will that inv variable be changed every time someone excecutes the command
if(event.getInventory().equals(gui.getInv())) {
i have this
and it just returns false every time
Yeah
I think you should compare InventoryViews or use InventoryHolders, the latter is discouraged due to side effects
If gui.getInv() just returns one instance then equals should be fine. But you need to use the same instance of your "gui" class
maybe a dumb question
how do i pass a instance of a class to another class
public HealthArmor health = new HealthArmor();
this
Probably dependency injection
Via the constructor for example
Ahh ok
constructors are still a bit confusing for me
but ill try to figure it out
private MainGui gui;
public Listeners(Main plugin) {
this.plugin = plugin;
gui = plugin.guiMain;
}
@lost matrix
gives me a null
exception
is guiMain set?
check to see if it's null
yes
how?
I think guiMain is null
onEnable if guiMain == null print smthgn>
The only thing that could throw a npe in those line is if plugin is null
ill do that
let me see the declaration of Listeners
public Listeners listener = new Listeners(this);
thank you
Im putting all the listeners into a class for organization?
typically they're in separate classes for better organization
what's false?
if(event.getInventory().equals(gui.getInv())) {
if(event.getInventory().equals(gui.getInv())) {
event.setCancelled(true);
public MainGui guiMain = new MainGui();
@Override
public void onEnable() {
this is in my main class
gui = plugin.guiMain;
this is where the coimmand is run
creating the GUI
gui = plugin.guiMain;
this is where the listener is
does this have to be in onenable?
Hello, someone knows what the deluxechat api is to put it as a dependency
as far as I know getTitle() was removed from inventories back in 1.13
I figured it out thank you
if(inventory.contains(fee)) {
Im doing this
fee is == to this
ItemStack fee = new ItemStack(Material.DIAMOND);
fee.setAmount(this.plugin.getConfig().getInt("ammountofsaphires"));
For some reason that no worky
it passes as false
oh crap
wait
ItemStack fee = new ItemStack(this.getItem());
no material diamond
leme test it
what is the inventory?
yea no it still passes as false
the inventory
Inventory inventory = plr.getInventory();
and you're checking if the inventory contains a specific itemstack?
this is how I normally compare inventories
https://paste.lucyy.me/gitogisoqa
Lucy's Pretty Pastebin
get the inventory contents instead
I tried
I cant figure that out
If i put the contents into a itemstack array
here i poisted about it a while ago
hmm i cant find it
But it just shows up as no methods
When I use inventories I check for specific item stacks, and it works fine... do you need to specifically check for 50 or will 1 be fine?
what are you trying to do?
specifically whatever they put in the config
When they click on the item in the inventory. it takes X amount of custom diamonds from their inventory and gives them the item
question, 50 in 1 stack or 50 in the entire inventory?
entire inventory
inventory.contains(fee)
wouldnt that work?
For just 1
fee.setAmount(this.plugin.getConfig().getInt("ammountofsaphires"));
sets the anmount to however many is in the config
you need to iterate through player inventory contents ig.
thats what i thought but how.
can you show more code?
Yea
you could check each slot in the inventory and then add it to an int and then check if it’s equal to the amount
Its just messy
Inventory inventory = plr.getInventory();
ItemStack[] invArray = inventory.getContents();
that invArray has nothing attatched
leme send screenshot
Paste your code
?paste
if you're just trying to get the items from their inventory, don't use getContents
use what?
getStorageContents is what you want
use for loop
getContents iirc returns everything, including their armor and offhand
are you using the correct Inventory import?
import org.bukkit.inventory.Inventory;
for(ItemStack item : inventory.getStorageContents()){
// check itemstack.
}
or remove them
List<ItemStack> would allow you to add and remove ItemStacks
though I have no idea what you're trying to do
basically you're trying to check if the player has a specific item on their inventory, right?
quick question, does the getName or wahtever the method is called in the playerexecute command return the command without the slash or with it?
yes i need to check if they have X amount of these
wich have a special NBT tag

so, loop every item on the players inventory
no no i mean NBT, i've never used it really
O
Ok
ItemStack[] items = inventory.getStorageContents();
int total = 0;
for (ItemStack i : items) {
if (i == yourItem) {total++;}
}
If (total == 50){
// do whatever
}
Could try something like this?
might be spelt wrong, csnt type on phone
Omg it’s not formatted
Whatever man, get over it
Oh I was just joking (:
Inventory#containsAtLeast to check if there is X amount of a specific item
Inventory#removeItem with a clone of your ItemStack that is set to the amount you want to remove to remove it
Tada, 2 lines
Hi, when I do spam click an inventory even if I cancelled the event, sometimes, the item can be placed :/
Is there a way to avoid that ?
^
I believe it’s only visual
sorry for "bumping" my message
Unfortunately not :/
Also creative mode behaves weirdly with inventories
slash is generally excluded
that's what I thought as well
I'm in survival cause I know it does break things the creative mode
It's not picking the item
It's placing it
if the slot is empty
sometimes
it just place it anyways
As far as I know if you are cancelling the event properly you won’t have an issue
(but you really have to spam)
I’ve never had one anyway
Heavily depends on what you do in the event, ya got some code to look over?
ive also never had an issue when cancelling click / place events
if(((clickedSlot == extraSlot1 || clickedSlot == extraSlot2) && !extraSlotTypeUtils.isRing(cursorItem) && (cursorItem != null && cursorItem.getType() != Material.AIR) /*&& extraSlotTypeUtils.isRing(currentItem)*/)
|| (clickedSlot == extraSlot3 && !extraSlotTypeUtils.isNecklace(cursorItem) && !extraSlotTypeUtils.isAccessory(cursorItem) && (cursorItem != null && cursorItem.getType() != Material.AIR) /*&& (extraSlotTypeUtils.isAccessory(currentItem) || extraSlotTypeUtils.isNecklace(currentItem))*/))
{
e.setCancelled(true);
return;
}
if you are having an issue, you can try calling Player#updateInventory after, see if that fixes anything for you
try calling Player#updateInventory after you cancel
Maybe your click results in an InventoryDragEvent, not a click one?
That could be it
Gonna try
anyone know of a way to detect how much durability a block would take a way from an ItemStack if it were used to mine that block?
I think there might be a way to do so
not sure if durability removal depends on block type
but i forget
only on unbreaking
it doesn't
so just removing 1 from the durability should suffice?
it always takes 1 damage, minus a % chance when it has dura
It does
ah
Using a tool on the wrong block does 2 damage
hmm
wait actually?
oh damn, there's a whole lotta exceptions with tool damage
Mhm
wait
since when did the registerevent params change
oh wait
nvm
i was using the wrong method xD
Does anyone knows how could I know if a region is within a chunk ?
if (someChunk.getBlock(rX, rY, rZ).getType() != Material.AIR)
I meant a WorldGuard region ^^
😔
public static boolean isRegionInChunk(Chunk chunk)
{
RegionManager regions = getRegionManager(BukkitAdapter.adapt(chunk.getWorld()));
final int maxX = chunk.getX() * 16;
final int minX = maxX + 15;
final int maxZ = chunk.getZ() * 16;
final int minZ = maxZ + 15;
final BlockVector3 max = BlockVector3.at(maxX, 256, maxZ);
final BlockVector3 min = BlockVector3.at(minX, 0, minZ);
ProtectedRegion chunkRegion = new ProtectedCuboidRegion("chunkRegion", min, max);
if(regions != null)
{
return !regions.getApplicableRegions(chunkRegion).getRegions().isEmpty();
}
return false;
}
Here you go if someone needs it ^^
EDIT: Thank you btw 😉 @quaint mantle
I was useful?!
havent felt that in a while
@jade perch 👀 https://github.com/SpigotMC/BungeeCord/commit/6a039de8db3a9dc78fe884e5d150db24df1933bb
Lets goooo
That with the spigot api annotations are going to be one of my favorites
for (Player p : Bukkit.getOnlinePlayers()) {
if (!args[0].equalsIgnoreCase(p.getDisplayName())) {
player.sendMessage(CC.RED + "That player is not online!");
return true;
}
}
}
works fine with one person but when 2 join it always says they are offline
That's cause your loop can only run at max one time
how do I change that
you need to not return inside of your for loop
aight
You could just Bukkit#getPlayer(String) and check if it's null
but don't use display names if you go that method
aight
Player player = Bukkit.getPlayer(args[0]);

you can use getPlayer with their name i'm pretty sure
idk if it's case sensitive or not
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
player.sendMessage(That player is not online!);
}
like this?
Player onlineTarget = Bukkit.getPlayer(args[0]);
if (onlineTarget == null) {
player.sendMessage(CC.RED + "That player is not online!");
return true;
}
yes
yeah, I'd return after sending the message
yeah I need to
java 9 the best
Optional.ofNullable(Bukkit.getPlayer(args[0]))
.ifPresentOrElse(
player -> {
//player stuff
},
() -> sender.sendMessage("FUCK")
);
can't wait till java 11 is mainstream
sender.sendMessage("FUCK")
10/10 error message
I mean if spigot were to adopt something like paper did it would be 100% in the near future
I'm excited bc I'm angry at Java 8
To be fair with them pushing java 11 most hosts will offer it now
So you can just make your plugin with java 11 anyway
I doubt 1.8.8 server operators will upgrade 
I'm trying to take a player's chat event and utilize it in a different method, how would I go about doing this?
Example:
Player clicks with item and is prompted to enter something in chat
It then takes the chat input and uses that to alter additional code
If anyone could guide me in the correct direction it would be much appreciated ❤️
add a metadatatag to them
Dang that API is from 1.1
lol
Back when they added unique planks to each wood
So add a metadatatag to the player and check if it's persistent in the chat event, then if it is we can use it that way?
yh
Or try that API
definitely go with the conversation api
To be honest I’ve never used it, but I’m sure it works
its 10x smoother to use
how do I make it so that worldedit pastes where im looking
but I only want nsew
not oother directions
currently ive got
if (player.getLocation().getYaw() > 90 && player.getLocation().getYaw() < -90) clipboard.rotate2D(90);
if (player.getLocation().getYaw() > 180 && player.getLocation().getYaw() < -180) clipboard.rotate2D(180);
I posted a method for you when you asked this question earlier
when I posted this question at 5am
no almost a day ago
huh?
private Location getTarget(Player player) {
RayTraceResult target = player.rayTraceBlocks(200);
if (target == null) return null; // no hit
return target.getHitBlock().getLocation().add(target.getHitBlockFace().getDirection());
}```
that will get you the empty Location the player is looking at
upto a range of 200
but im not using 1.16
ah 😦
why is my code not working?
what is it not doing?
not rotating it
have you tried debugging the yaw?
no but I dont see why it wouldn't work
This is why you debug, to see WHY its not working. sysout the yaw to make sure it lays in the ranges you expect
ok
I’ve tried nothing and I’m all out of ideas
like this?
if (player.getLocation().getYaw() > 90 && player.getLocation().getYaw() < -90) { clipboard.rotate2D(90); printConsole(String.valueOf(player.getLocation().getYaw())); }
You should probably do it outside of the if statements
I assume it’s tracked as a number from 0-360
Ok, now look at your if statement.
Rather than -180 to 180
Do you think both of those conditions can be true at the same time?
no
Oh yeah, didn’t even notice that
Yet you are making it test that both are true with &&
perhaps || instead of &&
yeah
thats what I was thinking
ok
it works now kind of
its just not pasting to the right place
but it does change depending on where I look
For that you will have to perform your own basic raytrace
using player.getEyeLocation() and player.getEyeLocation().getDirection()
?paste
Yea ik, but the other one is cooler
Just sjowing smthng i just found
f
cant I just do, clipboard.rotate2D(player.getEyeLocation.getDirection);
pseudo code would be java Location start = player.getEyeLocation(); Vector direction = start.getDirection.clone().normalize(); for (i = 1; i < 200; ) { Block block = player.getWorld().getBlockAt(start.add(direction.clone().multiply(i)); if (block.getType() != Material.AIR) //this is the first block collision so return the last location tested.
Ok, actuall question this time.
for(ItemStack item : inventory.getStorageContents()){
if(item != null)
if(NBTEditor.getBoolean(item, "isdiamond")) {
}
}
this loops through ever item in the inventory and checks for NBT. how do i just delete the items that have the NBT...
should be simple but i have no idea lol
item.remove doesnt exist...
you set it to AIR
thank you
It seems to do noithing...
No error
for(ItemStack item : inventory.getStorageContents()){
if(item != null)
if(NBTEditor.getBoolean(item, "isdiamond")) {
item.setType(Material.AIR);
}
}
Setting it to null has the same effect
howe
Inventory.remove(ItemStack)
I don’t think that he’s to that array are reflected in the article inventory unless you use setStorageContents
oh wait
i totally forgot
i need to remove exactly 50 of them
for(ItemStack item : inventory.getStorageContents()){
if(item != null)
if(NBTEditor.getBoolean(item, "isdiamond")) {
diamondAmount = diamondAmount + item.getAmount();
}
}
this counts all of the items they have
like the amount
in that case you can always modify your array and then use Inventory.setStorageContents to push your changes back
ok leme try it rq
You shoudl be able to set teh amount to remove
but what if i wanna remove say 200
just get teh stack you want, set teh amount on it and call remove
or more than the stack
Then Math
array to list, stream, filter 🤔
i wish there were more BlockFaces like NORTH_WEST for up/down
i wish there was something like UP_NORTH
you want a 3x3x3 cube of BlockFaces?
no, just up north/east/south/west
i just decided to take in a Set<Location> to store x/y/z which is probably not an ideal solution
and then use getRelative(face.getBlockX(), face.getBlockY(), face.getBlockZ())
public abstract class DirectionBlock implements Block {
public Block[] getDirectionBlocks() {
return {
getRelative(BlockFace.NORTH),
getRelative(BlockFace.EAST),
getRelative(BlockFace.SOUTH),
getRelative(BlockFace.WEST)
};
}
}
@gecko10000#7137 smth like this?
@sage swift
so you want a 3x3 thats on top of a block?
or just cardinal directions on top
odd to just want the ones on top
for a tree traversal
I have a plugin that spawns a boss right. Whenever someone dies next to it, and the chunks unload. It despawns
How do i fix this?
forceload it
? how?
prevents teh chunk being unloaded until you remove the ticket
teh
you just call it on the Chunk passing yoru plugin instance
why are you doing this elgar
yu'roe*
you mean teh typos? Age, arthritis and carpal tunnel
I looked it up, and couldnt find anything on it..
Could you elaborate?
do what he said
how young are you
wat..
I'm not yet 60
call what
you're in your 50s?
bruh
Yep
damn
CALL WHAT
veteran spigot member
the function
method*
I posted the javadoc link in chat
function*
method* this isnt lua
lol
I used to call them functions for a bit lol
my brain
everyone and their dog uses functions
interface Method extends Function {}
java wanted to be special
fr!
still a function
as it functions
it does not method
you can function a method but you can't method a function
big bron
🤯
Location bossSpawn = this.data.getConfig().getLocation("bossspawn");
bossSpawn.getWorld().addPluginChunkTicket(null, null, this);
am i using this wrong
or you just use the method from the actual chunk you want the ticket on
then it only has a plugin requirement
Location.getChunk()
Location bossSpawn = this.data.getConfig().getLocation("bossspawn");
bossSpawn.getChunk().addPluginChunkTicket(this);
}
yea
i did that
let me test
how the hell are you passing null to int
yea @eternal oxide that didnt work
I tested it while the chunk was unloaded
and still errored
an error message would be greatly appreciated
um, it can;t error
NPE
Its trying to kill an unloaded entity
it cant
also whenever it unloads the mob dissapears
Plugin plugin)
Adds a plugin ticket for this chunk, loading this chunk if it is not already loaded.
A plugin ticket will prevent a chunk from unloading until it is explicitly removed. A plugin instance may only have one ticket per chunk, but each chunk can have multiple plugin tickets. ```
Location bossSpawn = this.data.getConfig().getLocation("bossspawn");
bossSpawn.getChunk().addPluginChunkTicket(this);
this is in my onEnable
Yet that chunk is still unloaded when i leave the area
add the ticket 1 tick after the server is fully up and running
Bukkit.getScheduler.runTaskLater
thank you @eternal oxide
@eternal oxide
Bukkit.getServer().getScheduler().runTaskLater(this, new Runnable(){
@Override
public void run() {
Location bossSpawn = this.data.getConfig().getLocation("bossspawn");
bossSpawn.getChunk().addPluginChunkTicket(null);
}
},1);
i cant reference the Main class by doing this
while inside the runnable
How fix?
create a final field
?
elaboratre?
in your Main class private final Main INSTANCE; Then in your constructor public Main() { INSTANCE = this; }
you can then use INSTANCE
Should there be a constructor for the runnable?
no your main class constructor
oh ok
add one for Main
ok
yea so
after all that
spawner.getEntityByUniqueId((UUID) plugin.data.getConfig().get("bossid")).remove();
this is giving me an NPE
just like it was before
did you use INSTANCE when you added the ticket?
yea
Then your issue is not with the chunk being unloaded
ive been using /rl
it only happens when the chunk is unloaded
You shoudl be using UUID.fromString(plugin.data.getConfig().get("bossid"))
so long as bossid is a UUID string
their the same thing no?
I don't believe you can cast String to UUID
No. This is exactly what the ticket is for. I guess it doesn;t prevent entities despawning though
hmmm
@eternal oxide i just added a bunch of try and catch to just skip the error
Zombie babyZombie = loc.getWorld().spawn(loc, Zombie.class);
babyZombie.setBaby(true);
how do i make that happen like 2 times
do i just repeat it?
or is there a babyZombie.spawn()?
or right clicking in interact @somber hull
?
same effect can happen there
in newer versions right clicking is called twice
once for right clicking the main hand and once for the offhand
no lol
@lilac dagger now i havea bug lol
but its unrelated
how do i check if the player has clicked in the inventory GUI and not the players inventory
if (clickedInv == null || clickedInv instanceof PlayerInventory) return;
thank you
better yet
hey fr33styler
nice to meet you
this check is faster than instanceof
thanks, but of course. i know that. but I made custom recipe, This is strange, but the custom recipe I made is still impossible even though I have the ingredients.
I want to make custom recipe possible without ingredients.
the red slots are completely client-side, i would assume
the client only knows of the recipes themselves
ah thanks
https://paste.helpch.at/ojaxaxatuj.cs
am i doing math wrong?
is there an easier way to do it?
what are you trying to achieve? sort of hard to know without background info
you click
and it takes 50 items
instead it gives me like 4 stacks lol
@drowsy helm
i think i did math wrong?
if (newDiamondAmount >= this.plugin.getConfig().getInt("ammountofsaphires")) {
if(newDiamondAmount > this.plugin.getConfig().getInt("ammountofsaphires")) {```
whats up with that aswell
this.plugin.getConfig().getInt("ammountofsaphires") == 50
so you just want to remove 50 form the stack?
from the entire inventory
cause if they set it to more than a stack
in the config
I wan it to still work
but how do i take
?paste
You can;t use the containsAtLeast as you also need them to have the NBT tag
the only one that gives extar hearts is the helmet
true
Not sure that will check NBT
public ItemStack getItem() {
ItemStack diamond = new ItemStack(Material.DIAMOND);
diamond = NBTEditor.set(diamond, true, "isdiamond");
ItemMeta meta = diamond.getItemMeta();
meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Legendary Saphire");
List<String> lore = new ArrayList<String>();
lore.add("");
lore.add(ChatColor.BLUE + "" + ChatColor.ITALIC + "A legendary diamond, obtained");
lore.add(ChatColor.BLUE + "" + ChatColor.ITALIC + "by slaying the Gem Keeper");
lore.add("");
lore.add(ChatColor.AQUA + "" + ChatColor.ITALIC + "Use \"/boss redeem\" to redeem");
lore.add(ChatColor.AQUA + "" + ChatColor.ITALIC + "any peice of armor/tool for " + plugin.getConfig().getInt("ammountofsaphires") + " saphires");
meta.setLore(lore);
meta.addEnchant(Enchantment.DURABILITY, 69420, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
diamond.setItemMeta(meta);
return diamond;
}
@eternal oxide i have this
idk if that would help?
thats where i create the item
like i said you can iterate over contents and check if the item is the same
keep a current counter of items that match
then you can check if they are same
I already did that lol
similar for removing
if(NBTEditor.getBoolean(item, "isdiamond")) {
newDiamondAmount = newDiamondAmount + item.getAmount();
inventory.remove(item);
is newDiamondAmount the current?
Yea, it starts at 0
and goes up by however many is being deleted
for(ItemStack item : inventory.getStorageContents()){
if(item != null)
if(NBTEditor.getBoolean(item, "isdiamond")) {
if(NBTEditor.getBoolean(item, "isdiamond")) {
at this point
we know its the item we need
i just need to take exactly 50
this.plugin.getConfig().getInt("ammountofsaphires") == 50
You need to count all with that NBT tag before you start removing so you know they have enough
i do that already
for(ItemStack item : inventory.getStorageContents()){
if(item != null)
if(NBTEditor.getBoolean(item, "isdiamond")) {
diamondAmount = diamondAmount + item.getAmount();
}
}
ok
if(diamondAmount >= this.plugin.getConfig().getInt("ammountofsaphires")) {
int counter = 0;
int amountRequired = this.plugin.getConfig().getInt("ammountofsaphires"));
for(ItemStack item: inventory.getStorageContents()){
if(item == null) continue;
if(!NBTEditor.getBoolean(item, "isdiamond")) continue;
if(counter == amountRequired) return;
if(item.getAmount() >= amountRequired - counter){
item.setAmount(item.getAmount() - (amountRequired - counter))
return;
}else{
counter += item.getAmount();
item.setAmount(0);
}
}```
thats what i meant
Thats close, but you also need to check if you are over adn only reduce by the correct amount
in the setAmount
first if statement
ah ok
leme test that
shoudl that not be if (counter + item.getAmount()
oh actually you would have to account for counter in amount Required
yeah the first if statement should be item.getAmoint() >= amountRequired - counter
@drowsy helm why are you setting the amount to 0
is that the same as setting the type to null
just deleting it?
same deal
its getting set to 0 because it wont fulfill teh amountRequired so it's just taking all of that then looking for the next itemstack
@drowsy helm thank youfor the help!
all good
this
This is creating all the armor im using
idk why its not working properly
you should have an itembuilder
?
idk why but seeing extra red hearts just makes me weirded out on mc
lol
like for example if i want to make an item
i can do
new ItemBuilder(Material.DIAMOND_HELMET).name("test").enchants(...).Attributes(...).etc etc etc
instead of having a whole method for it
oh
well oh well
i did this
and idk why the attributes are not working?
They work on the helmet tho
is ther a maximum for it possibly?
try putting it as al ower value and see if it does anything
hmm probs has something to do with it being leather armour im thinking
since the helmet is just a skull
is it just me or is this wiki page in German? https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel-de/
because its the german version lol
cant seem to find an english version for it hto weird
hmm that doesnt work either...
unrelated but you can easily remove the @SuppressWarnings("static-access")
howe
yeah sleep is the best fix lol
im assuming it's your nbt.set() function
can just be NBTEditor.set
then you dont need to suppress
lmao
dude im so confused
i changed some stuff with the chestplate meta
and now it wont let me get it out of the gui
this makes no sense
depends how your inventory system works lol
weird thing is the first Google result has an english Preview but the page does not exist https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/
yeah thats the one i was looking at
i swear i was reading that wiki page like 4 months ago aswell
maybe take it up with forum staff
hello
this is going to sound very very dumb
public enum DirectionUtil {
SOUTH,
SOUTHWEST,
WEST,
NORTHWEST,
NORTH,
NORTHEAST,
EAST,
SOUTHEAST;
private static final DirectionUtil[] directions = {SOUTH, WEST, NORTH, EAST};
private static final DirectionUtil[] doubleDirection = {SOUTH, SOUTHWEST, WEST, NORTHWEST, NORTH, NORTHEAST, EAST, SOUTHEAST};
public DirectionUtil getDirection(Location location) {
return getDirection(location.getYaw());
}
public DirectionUtil getDoubleDirection(Location location) {
return getDoubleDirection(location.getYaw());
}
public DirectionUtil getDirection(float yaw) {
return directions[((int)(yaw+45F)%360)/90];
}
public DirectionUtil getDoubleDirection(float yaw) {
return doubleDirection[((int)(yaw+22.5F)%360)/45];
}
}
I have this enum and I want to get one of the methods, how do I get them?
DirectionUtil.SOUTH.getDirection(Location)?
ty
np
and, if you wanted them to be static, it would be DirectionUtil.getDirection(Location) :)
lmk if it works 👍
for example, if I wanted to get them facing north, how would I go about doing that
what would I put in the float field
Are you trying to turn a Direction into yaw, the other way around, or both?
im trying to get the direction they are looking and run code based on that
Get the player's location, get the yaw of their location, parse that through a method in the enum and make it return a direction.
public DirectionUtil getDirection(float yaw) {
return directions[((int)(yaw+45F)%360)/90];
}
how do I use this method? what do I put in the yaw field
thats what I dont understand
why it requires be to give a field
Shouldn't that be a static method? :\
So you are meant to input the yaw to return a direction
I do that
If it was a static method as I suggest, use DirectionUtil direction = DirectionUtil.getDirection(player.getLocation().getYaw());
ok ty
I don't think that enum is made very well
ikr\
like
getDirection should return the direction
not whatever it does
if (direction == NORTH)
like that?
How can I change a line with the Holographic Displays Plugin with the Api?
HologramAdapter ad = (HologramAdapter) HologramAdapter.activeHolograms.get(holo); ad.setLine(1,"§etest"); I've already tried this, but it doesn't work
But then how can I change the line?
This is my main class, I set up the yml configuration file and I can use it with this.getCustomConfig(), I'm familiar with constructors, though how can I use the config in my other classes? Doing new MyMainClass().getCustomConfig() doesn't seem to work. https://pastebin.com/S2mffCxQ
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
How can I run a task on onDisable? Currently I'm trying to save a data on async and it's giving me errors. Plugin attempted to register task while disabled
You are not meant to run async tasks onDisable, because the server is stopping.
So just run it? without a task.
Yes
if it is an enum yes
aight, thanks.
Restart > Reload
I agree, but any context? 😁
Running async task on disable usually means because there’s a reload and the user is trying not to lock the plugin disable
Huh, onDisable is called when the server stops too.
Ahh, yep.
Yes it is meant to.
You can use sdk-15 if you want. Just make sure you set the target version to java 8
Only bukkit should call onDisable
What are you using to compile
literally I just want to get a list of strings into flag value and read back that list as some sort off array from the region flags with WorldGuard API... I can find literally zero documentation because apparently my google-fu is not strong enough and I get irrelevant results that use the same words as what I'm looking for but aren't the same thing.
and I am in worldguard docs but can't find anything specific for this? o.O
//north
if (direction == NORTH) clipboard.rotate2D(0);
//east
if (direction == EAST) clipboard.rotate2D(90);
//south
if (direction == SOUTH) clipboard.rotate2D(180);
//west
if (direction == WEST) clipboard.rotate2D(270);
it aint working @abstract sleet
This talks about SetFlag<T> which is fine, but how do? I can't find anything useful here. I've created the flag but when I /rg flag blah value1,value2 it just says null in chat
https://worldguard.enginehub.org/en/latest/regions/flags/
I am making my own enum rn for it:)
tysm
I have not tested this and I have no idea if it works. Could you let me know? :)
https://paste.gg/p/anonymous/bc2f0d02b5e141948100e4c1bf16a006
and gfl with this, it shows a StateFlag but there is like zero documentation for any other type? https://worldguard.enginehub.org/en/latest/developer/regions/custom-flags/
aight
Click on the Raw button and make a new class in your project, just paste that code in without the package of course use your own package
If it works then I will include it into my lib
Not sure but check File > Project Structure > Project > Project Language Level
@abstract sleet how do I use it? if Direction.north or if player.getLocation.getYaw(direction.north)
ect
Usually the language level is set to your jdk’s level
I can't seem to find a good and clean nametag api, all of them messes with the scoreboard. Is it smart to have it built in with the scoreboard?
You can always just make it yourself
yeah but is it smart to have it in the scoreboard?
so it don't fuck up the scoreboard
It has to be in the scoreboard
ok
can u plz help me
I have a custom config file, it's in the same class as the onEnable() method, so when I try to create a new instance I get a "plugin is already enabled" error, how can I use my getCustomConfig method in other classes? I would usually just do this.getCustomConfig, though as I mentioned above creating an instance doesn't work java MainClass plugin = new MainClass();
public FileConfiguration getCustomConfig() {
return this.customConfig;
}
private void createCustomConfig() {
customConfigFile = new File(getDataFolder(), "config.yml");
if (!customConfigFile.exists()) {
customConfigFile.getParentFile().mkdirs();
saveResource("config.yml", false);
}
customConfig= new YamlConfiguration();
try {
customConfig.load(customConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
Using dependency injection.
// MainClass.java
public FileConfiguration getCustomConfig(){
return this.customConfig;
}
// OtherClass.java
private final MainClass plugin;
public OtherClass(MainClass plugin){
this.plugin = plugin;
}
public void someMethod(){
plugin.getCustomConfig().getString(...);
}
``` for example, so you want to pass your main class to the other class using constructors.
wdym
I would love to know when/how the word dependency injection became mainstream
@abstract sleet
you would use DirectionUtils.getDirection(location.getYaw())
that returns a direction
ty
you can compare it to another direction (I think that is what you were trying to do) or go Direction.toString() if you want the name of the direction
tbh, I don't really know xd.
back in my day dependency injection was a mystery thing guice/spring did and that was it
Thank you!
Even better If you pass the FileConfiguration instead your main class.
https://sourceb.in/MOv4h7f2dR - so it doesn't remove my fake voucher, whcih is the paper, but the rest of the code runs fine
so the issue is that if I have 1 paper it wont remove it, but if I have 2, it will remove all
if (item.getType() == Material.PAPER && item.getItemMeta().equals(createPaper().getItemMeta())) {
int amount = item.getAmount();
Material material = Material.PAPER;
ItemStack itemStack = new ItemStack(material, amount);
if (p.getInventory().containsAtLeast(itemStack, amount)) {
p.getInventory().removeItem(itemStack);```
I tried doing this, but it wouldn't work
So you're only passing the necessary thing.
nvm im just the dumbest human on earth
like this?
if (DirectionUtil.getDirection(loc.getYaw()) == Direction.NORTH)
If the getDirection() method returning Direction enums then yes.
it dont work
//north
if (DirectionUtil.getDirection(loc.getYaw()) == Direction.NORTH) clipboard.rotate2D(0);
//east
if (DirectionUtil.getDirection(loc.getYaw()) == Direction.EAST) clipboard.rotate2D(90);
//south
if (DirectionUtil.getDirection(loc.getYaw()) == Direction.SOUTH) clipboard.rotate2D(180);
//west
if (DirectionUtil.getDirection(loc.getYaw()) == Direction.WEST) clipboard.rotate2D(270);
Debug the DirectionUtil.getDirection(loc.getYaw()) maybe?
what doesn't work
are you sure your code is working properly?
you should probably use a switch statement as well
switch(DirectionUtil.getDirection(loc.getYaw()) {
case NORTH:
clipboard.rotate2D(0);
break;
case EAST:
//...etc
ok
but make sure you debug your own code to make sure it is working properly.
My other class is an event handler which I registered in the main class, though after using the dependency injection method my event class is null.
Chek if clipboard.rotate2D is working, check if the code is actually being executed, check if DirectionUtil.getDirection is returning the correct direction
switch(DirectionUtil.getDirection(loc.getYaw())) {
case NORTH:
clipboard.rotate2D(0);
printConsole("NORTH");
break;
case EAST:
clipboard.rotate2D(90);
printConsole("EAST");
break;
case SOUTH:
clipboard.rotate2D(180);
printConsole("SOUTH");
case WEST:
clipboard.rotate2D(270);
printConsole("WEST");
break;
}
how do I debug the method? It should be working tho cause its we
ofc apart from smth like a command
don't forget the break; before case WEST:
to debug the method, just add System.out.println("Debug 1") and increment the number each time you use it so that you can identify exactly which parts of the code are and aren't working.
You should also add text to the debug logs such as the Direction for example, makes it even easier to source issues.
e.g. System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + direction.toString() + ".");
What you got currently set up (printing the direction it receives in the switch block) should be enough.
ok thanks
ok
so
it works
apart from west
all the rest work
or they dont work
but it prints correct
case NORTH:
clipboard.rotate2D(0);
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case EAST:
clipboard.rotate2D(90);
printConsole("EAST");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case SOUTH:
clipboard.rotate2D(180);
printConsole("SOUTH");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case WEST:
clipboard.rotate2D(270);
printConsole("WEST");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
sure
aff nevermind, in my plugin I did the exact invert thing.
wdym
sorry x)
all good
I've got a pretty basic question, how can I place my plugin.yml in another folder (in /src), I'm getting a plugin.yml not found error. I've seen people have the file in other folders / packages on github
is there a way to identify when the player's tool name has changed ?
in an anvil, yes
without a anvil
theres no other vanilla way to change it so no
When it is changed or if it has been changed
Two different things
When it is changed -> anvil event
If it is changed -> ItemMeta#hasDisplayName
its bad translator, but
I have an item that is named and changed by another plugin, and I want to know if there is a way to identify when this happens
No
in the plugin there is no api for it
The other plugin would need to make an event
nothing is called when they rename it, so you cant listen for it
unless you have a runnable check every so often but that would be super inefficient
not even creating a runnable to check if the item in the hand has a name?
you can cache the name and see if it hs changed
you could check it when its equipped
but it wouldnt be efficient
If you want to identify an item persistently you might need to use PDC
use PlayerItemHeldEvent and check its meta
Are there any utils or example how to create a subcommand? Like I want to have each class for every command argument, for example the main command is money and the subcommands are deposit, pay, etc.
a switch statement on args[0] in your onCommand
If it prints correctly then it is not an issue with my code
Currently I have like 15 subcommands, and It's all in one class.
Using switch statement on args[0].
I feel like that's kinda messy.
yes.
are they all truly sub commands?
what do you mean by truly?
do they really need to be sub commands of that specific command?
oh, yes it needs to be the subcommands of that commands otherwise it's gonna be messy.
and might overriding other plugin command.
in that case make a sub command class and register it in your main command class
so each sub command gets its own class
I use ElgarL's method above in my plugin, it is working very well and the code is far cleaner than if all subcommands were combined into the same class.
I kinda need an example for that.
I'll link you my repo in a tick, in no way is this good code, but just an example that you can see
And if anyone has suggestions for it then please let me know
All in this subpackage
I don't want to use external lib.
In my mind, I will create a SubCommand abstract class.
Have you seen my code aglerr?
yes
public abstract class SubCommand {
public abstract String getName();
public abstract String getDescription();
public abstract String getSyntax();
public abstract void perform(CommandSender sender, String[] args);
}
and then, on command I check if the args[0] is equalsIgnoreCase to the subcommand name.
I am unsure if any of that is necessary, apart from perform
If it's matches, do perform.
I handle syntax etc just inside the subcommand itself
Okay, I think I understand now, thanks.
https://paste.md-5.net/kusogatepo.cs for the command.
is it possible to create a nametag for the player above their current nametag (sorta like blc prem and hypixel's status system) to display a string? is this through nms, spigot api (armor stands), or..?
it's kinda different from lokka, but yeah.
switch(DirectionUtil.getDirection(loc.getYaw())) {
case NORTH:
clipboard.rotate2D(0);
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case EAST:
clipboard.rotate2D(90);
printConsole("EAST");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case SOUTH:
clipboard.rotate2D(180);
printConsole("SOUTH");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case WEST:
clipboard.rotate2D(270);
printConsole("WEST");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
why is this not working?
it is always spawning north
that is full method
@abstract sleet
was Material.getMaterial.(MaterialId) changed in 1.16 bukkit
There are no more material IDs as in numbers e.g. 1 for stone
Use Material.valueOf(materialName) e.g. Material.valueOf("STONE")
Which location are you feeding the method?
Is this the location of the player?
Could you add printconsole(loc.getYaw()); to your debug and lmk what that says?
ok
Yes, that yaw is meant to be north, is it not?
oh shit, I fucked up. 😆
Might have meant to be pitch.
thats a different place
Yeah, my bad @crude charm
do I need to?
Use getPitch() instead of getYaw() for all of the direction stuff.
You should.
oh
You can combine multiple cases in a switch statement
ye
e.g.
case NORTH:
case NORTH_WEST:
code...
break;
case WEST:
code...
break;
case SOUTH:
case SOUTH_WEST:
code..
break;
etc
why dont u check for north east?
It has north east
north, north east, east, south east, south, south west, west, north west.
-180 to 180
hmm
ok
im a little lost
switch(DirectionUtil.getDirection(loc.getYaw())) {
should I set it to pitch?
I thought pitch was up and down
I got them mixed up, pitch is what we are looking for I think.
ok
OMG IT WORKS
kind of
just a little off sometimes
but apart from that its perfect
if I check for the others it will work
just a little lost what to check for
I could make the enum more accurate by adding NNW (north north west) etc.
Me either. I'd just prioritise north/south
ok
ItemStack[] allItems = pInv.getContents();
for (int k = 0; k < allItems.length; k++) {
}
getServer().broadcastMessage("" + k);
}
Any idea why k isn t recognized?
switch(DirectionUtil.getDirection(loc.getPitch())) {
case NORTH_WEST:
case NORTH_EAST:
case NORTH:
clipboard.rotate2D(0);
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case EAST:
clipboard.rotate2D(90);
printConsole("EAST");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case SOUTH_EAST:
case SOUTH_WEST:
case SOUTH:
clipboard.rotate2D(180);
printConsole("SOUTH");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
case WEST:
clipboard.rotate2D(270);
printConsole("WEST");
System.out.println("DirectionUtil translated yaw of " + loc.getYaw() + " to direction " + getDirection(player.getLocation().getYaw()).toString() + ".");
break;
like this?
nope, looks good to me
yep
k cannot be resolved to a variable
Syntax error on token "}", delete this token
In the cmd
there ya go
you have an extra } somewhere.
Ooh, I looked past it.
ItemStack[] allItems = pInv.getContents();
for (int k = 0; k < allItems.length; k++) {
getServer().broadcastMessage("" + k);
}
Removed line 3 @cosmic sleet
Above the line you broadcast k, you had an extra curly bracket (}).
You either need to remove the one on the for(... line, or the one underneath it.
thx
nw
i have a question
i am making rn a plugin to fetch every 10 seconds the entire inventory of all online players
https://gyazo.com/e13bce144778d8ab7a44529cf16875f3 this gif is really bad but I think its worse now
is it going to take a lot of server performance if i save each inv in a seperate txt file?
I don't think so, actually It's better to save it in a different files.