#help-development

1 messages Ā· Page 2106 of 1

supple elk
#

the api would contain this

glossy venture
#

yeah

#

but how would you make it an enum

supple elk
#

then whomever was implementing could then create an enum?

restive tangle
#

Either way should work

supple elk
#

wait

restive tangle
#

In an API? Probably not

supple elk
#

I think it's a good idea to try and build my foundation as an API

restive tangle
#

For sure

supple elk
#

keeps it modular

ivory sleet
#

Feels like enum here would be way too inflexible, especially since you work with some sort of game type hierarchy

glossy venture
#

yeah but idk how you would implement an enum

#

here

#

because GameType is abstract

supple elk
#

mhm

ivory sleet
#

if its an interface

supple elk
#

I'll do the registery thing

#

though on this

#

if I say registered "skywars", SkywarsFactory

#

then I got the GameType by id

#

I'd then have to cast it back to SkywarsFactory wouldn't I?

glossy venture
#

yeah but its useful to have the id stored in the game type too

glossy venture
supple elk
#

oh?

glossy venture
#
@SupressWarnings("unchecked")
public <T extends GameType> getType(String id) {
  return (T) typesById.get(id);
}
supple elk
#

where does the T come from?

ivory sleet
#

Feels like you want a type token as well then

glossy venture
#

the compiler decides it

#
SkywarsGameType skywars = manager.getType("skywars");
#

now T is SkywarsGameType

ivory sleet
#

^ altho it becomes a little bit hard to keep track of the casts that way as you don't have anything that confirms it

restive tangle
#

That's pretty cool

glossy venture
#

you need to add T after iut

ivory sleet
#

returns T as well

glossy venture
#

you havent specified the return type yet

supple elk
#

ah

#

wait

#

show?

glossy venture
#

you can also do

<T extends GameType<?>> T getType(String id, Class<T> tClass)
``` for explicit type specification
supple elk
#

oh right

#

oh my god that is so cool

#

I never knew you could do that

glossy venture
#

then getType("skywars", SkywarsGameType.class) will return SkywarsGameType

supple elk
#

yeah

#

duddee

#

that is sick

sacred mountain
#

YESSS just spent 2 hours coding a plugin and it worked first time

ivory sleet
#

noice

sacred mountain
#

actually now i can revise for more important tings

noble lantern
#

the cursed class

sacred mountain
#

whats cursed about it

#

not extending javaplugin?

noble lantern
#

indeed, not sure how i like it tbh

restive tangle
#

BurchAPI

#

Alhamdurillah

sacred mountain
#

my death messages plugin works

torn shuttle
#

it's as fun as it is a pain in the ass to remember the syntax for

#

oh

#

that was about the generics thing

glossy venture
#

why

#

you mean at GameManager

#

its not my design

#

the game type class is meant to be extended

#

oh yeah forgot abstract

ivory sleet
#

why tho

sacred prairie
#

Is there any way to detect if a falling block with the tag "beacon" droped as item?

glossy venture
#

i honestly wouldnt care it makes more sense than a random registry

#

having a GameManager with running games and game types makes more sense to me than some random Registry<GameType<?>>

#

and then a List<Game>

#

yeah it depends per person

ivory sleet
#

Id actually disagree to some extent there

torn shuttle
#

only the sith deal in absolutes

ivory sleet
#

lol

torn shuttle
#

sometimes you need a manager

#

most times you should avoid it

glossy venture
#

well for things like services its useful

#

some kind of ServiceManager

ivory sleet
#

I mean the best part about managers is the fact that they are very abstract

#

so it can serve as high abstraction layer point

#

where it delegates to registries, observers etc

torn shuttle
#

tastes like my MatchInstance class

ivory sleet
#

so like

#

you want the projectile to go thru blocks?

#

like ghosting them?

lean gull
#

anyone?

ivory sleet
#

oh idk

#

not without looking at nms

lean gull
#

i wanna set the ObjectID of the _id of a document in mongodb to a player UUID, idk how to elaborate

#

i was told it's a little too much for my small knowledge

#

i barely know what i'm doing

supple elk
#

😰

#

šŸ‘€

sage patio
#

For disabling hitbox of an armor stand, setMarker() should be true or false?

willow mortar
lean gull
#

you just said a lot of things that i do not understand

willow mortar
#

Haha sorry :P

#

There are definitely tutorials somewhere that'll help, lemme find one

willow mortar
granite owl
#

can using pdc on a player cause the playerfile to get corrupted?

ivory sleet
#

it shouldn't

#

idk if its safe to use off the server thread

granite owl
#

i had the following: i stored an extra inventory in the player file using pdc

#

and then i killed myself to test it

#

went to title screen instead of respawn

#

and when i went back in

#

i was in an infinite loading terrain loop

#

when i deleted my playerfile i was able to login again

#

however since then i wasnt able to replicate the issue

#
public static void onPlayerJoin(main plugin, Player p)
    {
        File invDir = new File(Utils.getOwnDir + "inv");
        
        if (invDir.exists())
        {
            if (new File(invDir.getPath() + '/' + p.getUniqueId().toString() + ".bin").exists())
            {
                @SuppressWarnings("unchecked")
                HashMap<String, ItemStack[]> invs = (HashMap<String, ItemStack[]>) NonReflectables.deserializeBukkitObjectFromFile(invDir.getPath() + '/' + p.getUniqueId().toString() + ".bin");
                
                p.getInventory().setContents(invs.get("inv_main"));
                p.getEnderChest().setContents(invs.get("inv_chest"));
                if (invs.containsKey("inv_admin")) p.getPersistentDataContainer().set(new NamespacedKey(plugin, "inv_admin"), PersistentDataType.BYTE_ARRAY, NonReflectables.serializeBukkitObjectToByteArray(invs.get("inv_admin")));
            }
        }
    }
    
    public static void onPlayerQuit(main plugin, Player p)
    {
        File invDir = new File(Utils.getOwnDir + "inv");
        if (!invDir.exists()) invDir.mkdir();
        
        HashMap<String, ItemStack[]> invs = new HashMap<String, ItemStack[]>();
        invs.put("inv_main", p.getInventory().getContents());
        invs.put("inv_chest", p.getEnderChest().getContents());
        if (p.getPersistentDataContainer().has(new NamespacedKey(plugin, "inv_admin"), PersistentDataType.BYTE_ARRAY)) invs.put("inv_admin", (ItemStack[]) NonReflectables.deserializeBukkitObjectFromByteArray(p.getPersistentDataContainer().get(new NamespacedKey(plugin, "inv_admin"), PersistentDataType.BYTE_ARRAY)));
        
        NonReflectables.serializeBukkitObjectToFile(invs, invDir.getPath() + '/' + p.getUniqueId().toString() + ".bin");
    }
#

mhm

#

just some basic pdc

#

using byte arrays

#

to store the invs

#

everything works fine

#

is there a vanilla bug regarding dying/+going to title screen?

gritty basin
#

Is there any way to get structures to spawn in custom worlds?
we have a earth server and want it to have villages, ruined portals etc

solid cargo
#

i wanna recreate the buildmart plugin from mcc with my friend. idk what to start with tho. teams?

sacred mountain
#

What does the doesbounce do to a projectile

eternal oxide
#

it tells you in the javadoc

steel swan
#

guys i have a problem.
so i m using this :

public void playersList(String UUID){
        try {
             BufferedWriter writer = new BufferedWriter(new FileWriter("playerlist.txt"));
                
            writer.write("\n" + UUID);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

to write in a file.
The problem is, if there is already smth in the file, it will delete it andjust write what i tell it to

#

i want it to add what i tell him to

eternal oxide
#

new FileWriter("playerlist.txt", true)

steel swan
#

BufferedWriter writer = new BufferedWriter(new FileWriter("playerlist.txt", true));

#

like this?

tardy delta
#

try with resources is a thing šŸ˜‚

scarlet sun
#

Hello, I use intellij and i need a lil bit help. Is this the right place?

noble lantern
#

Whats up?

scarlet sun
#

Is it possible to do item event (compass), where you right click and it opens a gui, and it shows online people heads who have specific /team from minecraft, and when you select that player, the compass tracks the player? I already have an item made.

vocal mirage
#

Hello!
I use getProxy().getPlayer(UUID.fromString(s)) method to get a ProxiedPlayer from my UUID that I stored in a database.
The plugin throws me even though my server is in online mode & string S isn't null.

Can you help?

Thanks

sage patio
#

hologram is an Armorstand

#

but does not take affect

lost matrix
sage patio
lost matrix
vocal mirage
sage patio
#

so what should i do ?

vocal mirage
#

so object is null

lost matrix
vocal mirage
#

But I don't know why

lost matrix
scarlet sun
#

Is it even possible?

lost matrix
# scarlet sun Is it even possible?

Sure. Just open an Inventory, loop over all online players, filter out the ones with a specific team, listen to the InventoryClickEvent and set the compass target.

vocal mirage
#

15:12:08 [GRAVE] java.lang.NullPointerException 15:12:08 [GRAVE] at fr.pr11dev.getsupport.bungeecord.getsupportBungee.onEnable(getsupportBungee.java:82) 15:12:08 [GRAVE] at net.md_5.bungee.api.plugin.PluginManager.enablePlugins(PluginManager.java:265) 15:12:08 [GRAVE] at net.md_5.bungee.BungeeCord.start(BungeeCord.java:287) 15:12:08 [GRAVE] at net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:67) 15:12:08 [GRAVE] at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15) 15:12:08 [INFOS] Enabled plugin getsupport version 0.1.2 by pr11dev

sage patio
lost matrix
lost matrix
vocal mirage
vocal mirage
lost matrix
grave kite
#

Hi, does someone know ServerTickStartEvent alternative for 1.12.2?

lost matrix
lost matrix
grave kite
grave kite
lost matrix
small lynx
#

it is possible to save two different economies with vault? i want it to be able to save xp and coins for my KP-PVP plugin

vocal mirage
worldly ingot
#

Run a task that runs every tick

#

Not to mention, that's a Paper-exclusive event

lost matrix
# worldly ingot and why does it have to be an event when the scheduler exists?

Because the order of runnables are not determined. Ive used it to track the exact timestamp when a tick starts so that i know how many milliseconds my runnables are allowed to take.
For example if my runnable starts 32.5 ms after the tick started and they are only allowed to take 40 ms max then i know i can run them at least 2.5 more ms.

small lynx
#

it is possible to save two different economies with vault? i want it to be able to save xp and coins for my KP-PVP plugin

grave kite
lost matrix
worldly ingot
#

Right, yeah, you don't need the start of a tick for that

#

That's more or less what I was getting at. The use-case for calculating the start of a tick are far and few between

#

Only reasonable one I can think of is Spark's profiler

small lynx
grave kite
# lost matrix Then use a runnable

if I have a lot of listener classes with ServerTickStartEvent and ServerTickEndEvent, should I just make a runnable in the constructor? But I'm not quite sure how I distinguish tick start from tick end

grave kite
small lynx
lost matrix
#

Just run the cleanup of the previous tick on the start of the next one.

small lynx
#

and coins for purchase kits in shop

small lynx
vocal mirage
glossy venture
#

well yeah then use java 11

vocal mirage
worldly ingot
#

Certainly not required and few plugins did actually compile against 11 then

#

But if you can run 11, go for it

lost matrix
# grave kite ok, thanks

Something like this:

public class SomeTaskRunnable implements Runnable {

  @Override
  public void run() {
    Collection<? extends Player> players = Bukkit.getOnlinePlayers();
    players.forEach(this::cleanUp);
    players.forEach(this::execute);
  }

  private void execute(Player player) {

  }

  private void cleanUp(Player player) {

  }

}
grave kite
worldly ingot
small lynx
small lynx
#

i use playerpoints. but i dont want to force people to install it

sage patio
rough drift
#

Can you register a command on a specific server using BungeeCord?

#

or do I have to make a separate plugin

scarlet sun
#
import com.ignelis.tracker.items.ItemManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class events implements Listener {

    @EventHandler
    public static void onRightClick(PlayerInteractEvent event) {
        if (event.getItem().getItemMeta().equals(ItemManager.kompasas.getItemMeta())) {
            Inventory inv = Bukkit.createInventory(null, 6 * 9);
            inv.addItem(new ItemStack(Material.APPLE, 64));
            HumanEntity player = event.getPlayer();
            player.openInventory(inv);

        }
    }
}
#

i think im doing something really wrong

crisp steeple
scarlet sun
#

I found a documentation from 2014

rough drift
scarlet sun
rough drift
#

the thing is I am already doing everything, is there a way to HIDE a command on serverA but not serverB

small lynx
lost matrix
crisp steeple
rough drift
scarlet sun
#
            Inventory inv = Bukkit.createInventory(null, 6 * 9, "GUI" );
#

is this good?

lost matrix
scarlet sun
#

so when i right click compass, it should open?

crisp steeple
#

1.8 plugin making is pain

rough drift
#

TabCompleteResponseEvent is a thing, how can I check which command? (Bungeecord)

scarlet sun
#
package com.ignelis.tracker.events;

import com.ignelis.tracker.items.ItemManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class events implements Listener {

    @EventHandler
    public static void onRightClick(PlayerInteractEvent event) {
        if (event.getItem().getItemMeta().equals(ItemManager.kompasas.getItemMeta())) {
            Inventory inv = Bukkit.createInventory(null, 6 * 9, "GUI" );
            inv.addItem(new ItemStack(Material.APPLE, 64));
            HumanEntity player = event.getPlayer();
            player.openInventory(inv);

        }
    }
}
lost matrix
# scarlet sun so when i right click compass, it should open?
public class CompassItem {

  private static final NamespacedKey COMPASS_KEY = NamespacedKey.fromString("someplugin:custom-compass");

  public static ItemStack create() {
    ItemStack compass = new ItemStack(Material.COMPASS);
    ItemMeta meta = compass.getItemMeta();
    PersistentDataContainer container = meta.getPersistentDataContainer();
    container.set(COMPASS_KEY, PersistentDataType.BYTE, (byte) 0);
    compass.setItemMeta(meta);
    return compass;
  }

  public static boolean is(ItemStack itemStack) {
    if (itemStack == null || itemStack.getType() != Material.COMPASS) {
      return false;
    }
    return itemStack.getItemMeta().getPersistentDataContainer().has(COMPASS_KEY, PersistentDataType.BYTE);
  }

}
public class CompassEvents implements Listener {

  @EventHandler
  public void onClick(PlayerInteractEvent event) {
    if (CompassItem.is(event.getItem())) {
      openCompassInventory(event.getPlayer());
    }
  }

  private void openCompassInventory(Player player) {

  }

}

And giving a player the compass item is as easy as:

    player.getInventory().addItem(CompassItem.create());

šŸ„„ spoonfeed

#

You should take a look at this:

#

?pdc

lost matrix
#

TabCompleteResponseEvent might also work

rough drift
#

That's really it

crisp steeple
rough drift
#

I don't believe you can stack two items that have value in their containers

lost matrix
crisp steeple
#

ah i see

#

so it does come down to nbt in the end

#

just simpler

#

neat

hexed hatch
#

If the value they hold is the same, they can stack, right?

lost matrix
#

Its also one way to make an ItemStack unstackable: Just give them a PDC entry with a random UUID as value.

small lynx
lost matrix
lost matrix
#

?pdc

small lynx
#

it only works for 1.14?

lost matrix
#

Yes. 1.14+ But everything else is ancient anyways.

rough drift
#

1.16.5 is ancient

#

older than my grandma

lost matrix
#

I mean 1.16.5 community is still decently big. Bigger than 1.8 and 1.12

rough drift
#

ofc

#

but like

#

still ancient

jagged thicket
lost matrix
jagged thicket
#

u mean 1.18??

#

still no

lost matrix
#

1.12 1.16 1.17 1.18 are (on their own) all bigger than 1.8

jagged thicket
#

Howw

#

the pvp cliker bois

#

they are too big

lost matrix
#

Because 1.8 is a bubble where everybody thinks they are the biggest community while in fact they are vanishingly small.

rough drift
#

fair but like, they are only alive because of hyp

hexed hatch
#

I don’t even know if Hypixel can be considered 1.8

rough drift
#

eh

#

it is

hexed hatch
#

They’ve probably built their own server from the ground up

small lynx
quaint mantle
#

1.8 is increasingly getting smaller, only amplified from pvp montage and strictly hypixel YouTubers

rough drift
#

probs use some spigot fork

lost matrix
rough drift
#

One of the hyp admins was coding on a stream and it looked like spigot

small lynx
jagged thicket
#

is there a way to see vanish insta msgs on pc

rough drift
small lynx
#

Treasury is compatible with vault plugins? Like EssentialsX

dusty sphinx
#

how does Container#getContents work? Does it return empty item stacks for empty slots

quaint mantle
#

Never heard of Treasury before, it actually looks really cool

lost matrix
dusty sphinx
#

Ok. Will changes to the array be reflected or do I need to setContents

dull whale
#

how can I paste a schematic?

hexed hatch
lost matrix
dull whale
#

of course

lost matrix
dull whale
#

I've been looking for the best way but web's full of deprecate methods n stuff I wanna know the current best method

lost matrix
# dusty sphinx ?

What are you trying to do? You can do an index iteration and Inventory implements Iterable<ItemStack>.
You can do a lot without the getContents() overhead.

dusty sphinx
#

I'm trying to filter out items with illegal enchantments, so I think I will just turn the result of getContents into a stream and then flatten it back down to an array and put it back into the container with setContents

#

Are ItemStacks mutable?

lost matrix
dusty sphinx
#

Are ItemStreams mutable?

#

*ItemStacks

ivory sleet
#

yep

lost matrix
#

Yes. The underlying truth is a bit more complicated but they are mutable.

scarlet sun
#
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;

public class komanda implements CommandExecutor{
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player){
            Player player = (Player) sender;

            Inventory gui = Bukkit.createInventory(player, 9, ChatColor.RED + "Žmogžudžių gaudytojas");
            player.openInventory(gui);
        }

        return true;

    }
}

I made this as a command, how can I make it as a right click event?

rough drift
ivory sleet
#

not always

#

thats the "complication"

ivory sleet
#

because most of the times, the implementation copies your ItemStack instance to an identical CraftItemStack instance

rough drift
scarlet sun
lost matrix
dusty sphinx
#

is the map returned by item.getEnchantments mutable

severe oracle
#

hi, for some reason when i try to add a component to JFrame outside the main function, it doesent get added.

rough drift
#

show your code

#

because otherwise, I ain't a fuckin magician

lost matrix
dusty sphinx
#

I want to modify enchantments. Not remove them

lost matrix
#

In which way? Reduce their level?

dusty sphinx
#

yes

severe oracle
dusty sphinx
#

After I modify the ItemStack do I need to set it back into the Inventory or does it just update automatically

lost matrix
# dusty sphinx yes

getEnchantmentLevel(Enchantment ench) (returns 0 if not present)
addEnchantment(Enchantment ench, int level) <- replaces the level

But you can also try using the map. Tell me if it worked in that case.

ivory sleet
#

well you get an immutable copy

rough drift
#

addUnsafeEnchantment

#

ftw

dusty sphinx
ivory sleet
#

nah

rough drift
#

n o

ivory sleet
#

but getEnchantments and ItemMeta::getEnchants will return immutable copies

rough drift
#

oh yeah

#

forgot maps can be imumtable

ivory sleet
#

you need to set it back

dusty sphinx
#

ok

rough drift
#

sometimes

ivory sleet
#

pretty much always

solid cargo
#

i wanna remake the buildmart minigame from mcc with my friend. what should i start with? I have already imported WG and WE api

scarlet sun
#
    @EventHandler
    public static void onRightClick(PlayerInteractEvent event) {
        if (event.getItem().getItemMeta().equals(ItemManager.kompasas.getItemMeta())) {
            Player player = event.getPlayer();
            Inventory gui = Bukkit.createInventory(player, 9, ChatColor.RED + "Žmogžudžių gaudytojas");
            player.openInventory(gui);

        }
    }
}

Should this work? Sorry for being dumb, as i said im only a week into a programming

short raptor
#

How can I set an item's durability? The whole damageable interface thing is very confusing to me and I can't find any examples online

ivory sleet
undone axleBOT
solid cargo
short raptor
ivory sleet
#

and check if it instanceof Damageable

#

if so, cast it to Damageable and set the durability

steel swan
#

so i have this code : ```java
public boolean containsPlayer(String name){
try {
BufferedReader reader = new BufferedReader(new FileReader("playerlist.txt"));
String line;
List<String> listToWrite = Collections.emptyList();
while((line = reader.readLine()) != null) {
listToWrite.add(line);
}
reader.close();
if (listToWrite.contains(name)){
return true;
}else{
return false;
}

    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}
and
```java
@EventHandler
    public void onPlayerJoin(PlayerJoinEvent event){
        Player player = event.getPlayer();
        System.out.printf("0");

        if (!containsPlayer(player.getDisplayName())){
            playersList(player.getDisplayName());
            playersData(player.getDisplayName(), "CITOYEN", 0);
            setjobs(player, Job.CITOYEN);
            setmoneyInt(player, 0);
        }
}
``` but when i run it, i get an error : 
```[14:44:59] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to LunaRpDev v1.0-SNAPSHOT
org.bukkit.event.EventException: null```
https://paste.md-5.net/lenoqusiqu.bash
solid cargo
#

@scarlet sun are you lithuanian?

scarlet sun
#
    @EventHandler
    public static void onRightClick(PlayerInteractEvent event) {
        if (event.getItem().getItemMeta().equals(ItemManager.kompasas.getItemMeta())) {
            Player player = event.getPlayer();
            Inventory gui = Bukkit.createInventory(player, 9, ChatColor.RED + "Žmogžudžių gaudytojas");
            player.openInventory(gui);

        }
    }
}

Anyways, this is not working

#

What am I doing wrong

short raptor
ivory sleet
#

yes you do

#

set the item meta back after the setDamage call

steel swan
#

?paste

undone axleBOT
short raptor
#

I don't think I am doing the right

ivory sleet
#

nope

#

definitely not

solid cargo
#

@ivory sleet so you gotta remake the schematic given on the left square on the square to the right

#

and so plugin checks if ur done it, if yes, give points, else, do nothing and wait

ivory sleet
#

var stack = ...;
if (stack.getItemMeta() instanceof Damageable damageable) {
damageable.setDamage(4);
stack.setItemMeta((ItemMeta)damageable);
}
or sth

short raptor
#

whaaaaaaaaaaaaaaaaaa

#

Okay I will try that ig

lavish hemlock
#

Only works on newer versions of Java :)

lost matrix
short raptor
lost matrix
#

Even with a few hundred if people log in a bit more often.

solid cargo
lavish hemlock
short raptor
lavish hemlock
#

Besides, you should really only code in either Java 8 or Java 16 since those are the two versions Minecraft uses :p

steel swan
#

so anyone knows about the error?

lost matrix
# steel swan the server isnt big

Then dont write/read to/from a file that often. When the server starts -> Load every entry in a Set<UUID>
and only use this Set during runtime. Then when the server stops you simply write the whole Set to a File again.

steel swan
solid cargo
#

reminder i have we and wg api already installed

lost matrix
vocal mirage
lost matrix
knotty gale
#

how would I make a message send every time someone shoots a bow using EntityShootBowEvent

lost matrix
knotty gale
#

but like how would I get the players name my b

maiden thicket
#

Entity by EntityShootBowEvent#getEntity

#

Name by Entity#getName

vocal mirage
#

So how can I store a "player identity" in a DB?

lost matrix
#

^ Like this. You can check if the shooter is a Player by using instanceof

vocal mirage
lost matrix
steel swan
#
public boolean containsPlayer(String name){
        try {
            BufferedReader reader = new BufferedReader(new FileReader("playerlist.txt"));
            String line;
            String[] listArray = {};
            List<String> listToGet = Arrays.asList(listArray);
            while((line = reader.readLine()) != null) {
                listToGet.add(line);
            }
            reader.close();
            if (listToGet.contains(name)){
                return true;
            }else{
                return false;
            }

        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
vocal mirage
# lost matrix Use their UUID as primary key

it's what I do. But when the servers restarts, it "rebuilds" the data that was saved when it stopped. And I need to get the ProxiedPlayer object, so what can I do? And the player isn't online when it does that

lost matrix
steel swan
#

and so what should i do?

lost matrix
#

Please. Just create a new instance of an ArrayList like its taught in java 101

lost matrix
steel swan
lavish hemlock
#

Wouldn't it be super fucking slow to re-read the player list per method call...?

lavish hemlock
#

You're just trolling

steel swan
#

no bro

#

i m just making what he told me to

lavish hemlock
#

He did not tell you to use the copy constructor of the list

lavish hemlock
#

He told you to make a new list

#

Learn how the fuck to make a list because it's one of the most common things in Java

steel swan
lavish hemlock
#

Nah okay you're trolling

steel swan
#

BRO

#

if i m doing smth wrong just explain to me

#

i dont quite get what you want me to do

lost matrix
# steel swan BRO

Im also getting troll vibes to be honest. The list is completely useless to begin with.

lavish hemlock
steel swan
#

oh nvm i think i get it

knotty gale
lavish hemlock
#

Violates LSP, explicit righthand type parameter, empty Arrays.asList as the parameter of a collection's copy constructor.

severe oracle
#

hi, for some reason when i try to add components to a JFrame outside the main method it wont be added to the frame.

maiden thicket
steel swan
#

i get it

#

so sry

knotty gale
#

so I would do

        Entity Shooter = EntityShootBowEvent#getEntity;
steel swan
#

i created an array but not a list

lavish hemlock
#

Okay listen lemme point the shit out for you

steel swan
lavish hemlock
# steel swan like that ArrayList<String> listToGet = new ArrayList<String>(Arrays.asList());
  1. You should declare your variable as List<String> listToGet instead of ArrayList<String> listToGet because of conventions that are semi-complicated to explain.
  2. You do not need to declare the String in new ArrayList<String> because of the "diamond operator," you can refactor this to just new ArrayList<>.
  3. It is pointless to create an empty Arrays.asList within the "copy constructor" of an ArrayList, the copy constructor copies the contents of another list into the list you're creating. You should remove this parameter to create a new empty ArrayList.
#

So

#

In other words

short raptor
#

Now this is setting the item durability to 0 šŸ¤”

lavish hemlock
#

List<String> listToGet = new ArrayList<>();

#

That's all you need to do.

#

Uhh

#

Well the style comes from javadocs

#

Javadoc conventions state that you should declare parentheses if it is actually important

#

e.g. if you're differentiating between two overloads

warm saddle
#

how would i get the itemstack that is in a specific slot in an inventory from an inventoryclickevent?

gritty basin
#

What are some cool money making plugins?

knotty gale
#

what is a way to make a Listener that listens for if a bow was shot

lost matrix
knotty gale
#

yeah but it wont work

lost matrix
knotty gale
#
public class ArrowShot implements Listener{
    @EventHandler
    public void EntityShootBowEvent(org.bukkit.event.entity.EntityShootBowEvent event2) {
        if(event2.getEntity() instanceof Player) {
            Bukkit.broadcastMessage(event2.getEntity().getName() + " threw the ball");
        }
    }
}
#

this wont work for some reason

lost matrix
#

Did you register the listener? Also import your packages instead of using them like this.

knotty gale
#

lemme check if i did it right though

#

ok how do I register a listener that is not the Main class?

#

because I do not need @Override right?

tardy delta
gritty basin
knotty gale
#

i beleive Essentials comes with a money thing

tardy delta
gritty basin
#

and thats just a currency holding thing

lost matrix
gritty basin
lost matrix
knotty gale
ivory sleet
tardy delta
#

or plugin, listener idk

warm saddle
#

how would i set the time for a ban using target.getServer().getBanList(BanList.Type.NAME).addBan method, i know you need to do target.getServer().getBanList(BanList.Type.NAME).addBan(player, banReason, <time>, mod) how would i make the time 14 days, would i just put 14d otrrr

lost matrix
tardy delta
#

so look at the methods in that class

scarlet sun
#

how can i filter out the ones with a specific team online players?

craggy cosmosBOT
#

:dynoError: The AFK module is disabled in this server.

sterile token
scarlet sun
echo basalt
#

Just use epoch seconds for that

warm saddle
#

it has to be a Date object

sterile token
#

ms can be directed converted into date object?

#

So then its posible to get the hours, seconds, etc from the date?

warm saddle
#

would this be an issue because this is 14 days in milliseconds: 1.21e+9

#

yeah it wants it to be a Long not a Date

#

yep that works, thank you :)

flat olive
ivory sleet
sacred mountain
#

lmao what

steel swan
#

hey , i have this code to check if smth from a file is smth
:

if(containsPlayer(player.getDisplayName())){
            int index  = getIndexOfPlayer(player.getDisplayName());
            String text = readerFile("file.txt", index + 1);
            System.out.println(text);
            if (text == "CITOYEN"){
                System.out.printf("is");
                setjobs(player , Job.CITOYEN);
            }
            if (text == "STAFF"){
                System.out.printf("is");
                setjobs(player , Job.STAFF);
            }
            if (text == "VISITEUR"){
                System.out.printf("is");
                setjobs(player , Job.VISITEUR);
            }
            setmoneyInt(player , 0);
        }

The output in the console is CITOYEN, but the condition if (text == "CITOYEN"){ doesnt work

#

anyone knows why?

#

the output :

flat olive
#

yes

ebon arrow
flat olive
#

use text.equals()

#

use equals() method

steel swan
tardy delta
#

i used opera gx a while ago 😳

#

its just slow

steel swan
kind hatch
lost matrix
steel swan
#

okey

#

imma try that

tardy delta
#

get ninja'd

flat olive
#

bing on top 😭

#

šŸ’€

tardy delta
#

smh bing

#

you didnt mention duckduckgo

sterile token
#

20L = 1 second?

kind hatch
#

There are 20 ticks in a second yes.

flat olive
#

apparently firefox is top 1 but i havent used it since the stone ages

tardy delta
#

im usin firefox rn

flat olive
#

šŸ’©

tardy delta
#

chromium was behaving weird šŸ’€

lost matrix
# steel swan okey

Btw this is a very, very bad approach to whatever you are doing. And its also way more complicated than it needs to be.
Constantly reading and writing from/to files on the main thread is just super bad.

lost matrix
sterile token
flat olive
#

yes indeed it takes so much space up

#

now time to code again

lost matrix
sterile token
#

sources?

lost matrix
tardy delta
#

<type>javadoc<type> is it that?

#

ah

sterile token
#

šŸ¤”

kind hatch
#

The first one is the delay, second one is the interval in which it will repeat.
Also, I thought that #runTaskLater() only had one parameter which was the delay. Are you sure you didn't mean #runTaskTimer()?

tardy delta
#

wondering the same thing

sterile token
#

Yes lmao im stressed to be using apis that doesnt contain good methods, arguments

tardy delta
#

so you there is your explaination :)

sterile token
#

Oh nice getting an NPE when comparing item displayname with config displayname. Amazing hahahaa

#

šŸ˜‚

kind hatch
#

No worries. You just have to remember that both the delay and the interval period for the bukkit scheduler are in ticks instead of milliseconds. So 20 ticks is 1 second.

sterile token
#

Because long can be anything hour, seconds, etc

kind hatch
#

No, they are just ticks. You would have to do the math if you wanted it to be something like seconds or minutes.

sterile token
#

That what i hate from the apis that are not good coumented

kind hatch
#

Yes, it takes a long as the parameter, but it's interpreted as game ticks.

sterile token
#

But its okay its not a paid api

#

If im paying for the api of course i will argue

#

But thanks Shadow and sorry for fucking you

scarlet sun
#

I can't find any of the working docs where how i should get all online players and add their skulls to gui

#

is there a way to do it?

lost matrix
sterile token
tardy delta
kind hatch
#

That's one of the things that annoys me about item comparisons.
The method #hasDisplayName() can thrown an NPE instead of just returning false.

lost matrix
sterile token
kind hatch
#

If it's on the player interact event, then the item could be null in certain cases. Or the wrong one.

lost matrix
sterile token
#

I dont have another way to compare my items

scarlet sun
#

sorry for ping btw

sterile token
#

Or atleast i dont kno

void shale
#
@EventHandler
public void onBlockExplode(final BlockExplodeEvent event) {
    event.blockList().forEach(x -> {
        ...
    }
}

Would this be a good way to deal with blocks that are being destroyed by tnt or creeper?
I tried it but i think it did not fire up :/

sterile token
kind hatch
void shale
lost matrix
# scarlet sun in eventhandler?

No the class this method is in doesnt matter. You should decouple your concerns. Your first is: "How to convert a Player to a Skull ItemStack"
and this method tries to solve this task.

flat olive
#

does anyone know how to get all of the permissions of what a user has in a string format

String playerPermissions = Bukkit.getServer().getPluginManager().getPermissions();

getEffectivePermissions() only returned it in an object and someone told me to loop with getPermissions, however, I have no clue how to start

kind hatch
scarlet sun
lost matrix
sterile token
void shale
#

I can share screen if that would help to show

sterile token
flat olive
kind hatch
void shale
lost matrix
scarlet sun
void shale
#

wait would it print to console if i use regular System.out.println?

tardy delta
kind hatch
lost matrix
sterile token
kind hatch
lost matrix
flat olive
scarlet sun
#
public class .... implements ....

something like this?
@lost matrix

sterile token
scarlet sun
#

ah, im sorry

lost matrix
#

@scarlet sun ?learnjava

#

?learnjava

undone axleBOT
sterile token
kind hatch
sterile token
#

Because im looping over each item and creating a memory object for each item

kind hatch
#

Ok, so you need to pay close attention to how you format your string.

You will want to loop through the config section Items using #getConfigurationSection("Items").getKeys(false) It will return the names of every sub item in the list. So in your case it would just return test.

If you had more, it would be part of the list.

You can use that to then build your string.

If you wanted to get the display name: "Items." + sectionName + ".Display"
If you wanted to get the slot: "Items." + sectionName + ".Slot"

scarlet sun
#

oh nvm

#

nvm

#

sorry

lost matrix
scarlet sun
#

oh, okay

#

I get it now

sterile token
#

In other words (Shadow):

section.getKeys(false).forEach((name) -> {
  getPlugin().getLogger().info("Item " + name + " (Display: " + section.getString("Display") + ")" + " loaded");
  Item item = new Item(name, getPlugin().getConfig().getString("Items." + name + ".Display"));
  item.setSlot(getPlugin().getConfig().getInt("Items." + name + ".Slot"));
  item.setCommand(getPlugin().getConfig().getString("Items." + name + ".Command"));
  ItemBuilder material = new ItemBuilder().of(Material.valueOf(getPlugin().getConfig().getString("Items." + name + ".Material")));
  material.name(getPlugin().getConfig().getString("Items." + name + ".Display"));
  material.lore(getPlugin().getConfig().getStringList("Items." + name + ".Lore"));
  item.setItem(material.build());
});
kind hatch
#

Your items would be created properly, but your console output wouldn't be what you expect.

tardy delta
#

my eyes

void shale
#

I am confused even if do this and exploded tnt nothing is being send to players:

@EventHandler
public void onBlockExplode(final BlockExplodeEvent event) {
        App.plugin.getServer().getOnlinePlayers().forEach(y -> y.sendMessage("Lasagna!"));
}
lost matrix
kind hatch
#

What class is that method in?

tardy delta
#

main class 😟

void shale
# kind hatch What class is that method in?

In my Events class which implements Listener and on main class I have:

public void onEnable() {
        App.plugin = this;
        App.config = App.plugin.getConfig();
        this.getServer().getPluginManager().registerEvents(new Events(),this);
    }
lost matrix
kind hatch
#

Well, that looks right to me. How are you trying to trigger the event? TNT, Creeper?

void shale
#

TNT

tardy delta
#

why having a config field

lost matrix
void shale
#

whole main class:

package lt.lucy.lucyutils;

import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

public final class App extends JavaPlugin {
    public static FileConfiguration config;
    public static App plugin;

    public void onEnable() {
        App.plugin = this;
        App.config = App.plugin.getConfig();
        this.getServer().getPluginManager().registerEvents(new Events(),this);
    }

    public void onDisable() {}
}
tardy delta
#

do a sysout before the player looping

lost matrix
flat olive
kind hatch
#

Wouldn't the BlockExplodeEvent also apply to Respawn Anchors if it goes by that logic?

lost matrix
#

*For the respawn anchor it also fires now i suppose

flat olive
#

oh and permissions is a string field not a array

lost matrix
kind hatch
small lynx
void shale
flat olive
dry aspen
#

Hello guys, do you guys have any idea of how i could, possibly modify a line of a file?
Here is an exemple.
For instance, guys, if i have a file where the first line is x and the second one is y.
i want it so that, i can modify the second line by saying that it is the second line that i want to modify and , for instance , replace the y with a z

flat olive
tardy delta
void shale
#

actually one other thing i wanted to ask for now, how do i change block type's blast resistance?

small lynx
kind hatch
lost matrix
flat olive
#

it only outputs my permissions as if it were an object surrounded with a string 🤣

tardy delta
lost matrix
small lynx
kind hatch
tardy delta
lost matrix
sterile token
small lynx
#

how i change subsbriber to a EconomySubscriber(PlayerAccount)

kind hatch
small lynx
tardy delta
#

you should be able to see the method signature from in your ide

#

well.. eclipse...

lost matrix
small lynx
lost matrix
#

If not you then you need to cast it

small lynx
#

it is a method from a public plugin

#

called Treasury

scarlet sun
#

I can't, I don't understand what should I do but I really do wan't to learn java, but I don't know from where to start :/

lost matrix
undone axleBOT
lost matrix
#

Those are some helpful links.

scarlet sun
#

Yes, but how to find things I need

small lynx
lost matrix
crimson terrace
#

https://www.youtube.com/c/CodingwithJohn this guy has also helped me a lot in understanding basic things. maybe its easier to start with videos @scarlet sun

lost matrix
tardy delta
#

mye do what 7smile7 said

scarlet sun
# lost matrix Nope. The whole lambda.
    public ItemStack createPlayerHeadItem(Player player) {
        return .addTexture(new ItemStack(Material.LEGACY_SKULL_ITEM, 1);
    }

Is this even the right thing? Probably not

lost matrix
lost matrix
scarlet sun
#

So that line = everything's wrong

knotty gale
#

Hey! does anyone know how to make a random chance that something happens off of a listenr. So like if someone is hit there is a 1% chance that a messege appears when they are hit

knotty gale
#

ok

crimson terrace
#

you can compare that to another number in order to see wether it should do what you want or not

tardy delta
#

and make the random a field

void shale
#

how to show title/subtitle to player?
player.showTitle(Title.title("Tesxt", "test")); it expects components

tardy delta
#

Random random = ThreadLocalRandom.current()

lost matrix
tardy delta
#

get ninjad

crimson terrace
tardy delta
#

vanilla java lol

lost matrix
lost matrix
crimson terrace
#

damn, never seen that, thanks šŸ™‚

tardy delta
crimson terrace
#

what are the downsides to making a new Random()?

knotty gale
#

can you gimme a example of how to use that?

warm saddle
#

Does anyone have any ideas what the issue is with this: java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.ItemStack.getType()" because the return value of "org.bukkit.event.inventory.InventoryClickEvent.getCurrentItem()" is null here is the code for the event listener that is causing it: ```java
package dev.jamieisgeek.bangui.events;

import dev.jamieisgeek.bangui.utils.BanMenuUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

public class PunishMenuListener implements Listener {

@EventHandler
public void onMenuClick(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();

    if(e.getView().getTitle().equalsIgnoreCase(ChatColor.RED + "Pick a punishment")) {
        if(e.getCurrentItem().getType() == Material.BOOK) {
            String reason = e.getCurrentItem().getItemMeta().getDisplayName();

            String player = p.getInventory().getItem(50).getItemMeta().getDisplayName();
            Player whoToBan = p.getServer().getPlayerExact(player);

            BanMenuUtils.openConfirmMenu(p, whoToBan, reason);
            e.setCancelled(true);
        } else {
            return;
        }
    } else {
        return;
    }
}

}

undone axleBOT
lost matrix
warm saddle
#

well i am clicking on an item, so why is it null?

lost matrix
# knotty gale I am kinda confused
  public static boolean roll(double chance) {
    return ThreadLocalRandom.current().nextDouble() < chance;
  }

Call this method with a value between 0.0 and 1.0 where 1.0 is 100.0%

lost matrix
tardy delta
#

else return isnt really a good practice writin that

warm saddle
#

so it shouldn't be null

crimson terrace
warm saddle
#

IT SHOULDN'T BE NULL I AM CLICKING AN ITEM

#

bruh

crimson terrace
#

it doesnt really matter what it should be if it isnt that

tardy delta
#

just add a null check, it can be null and you dont want exceptions

carmine mica
#

you aren't clicking anywhere else on the screen? not even to make the mc window your active window?

lost matrix
carmine mica
#

that counts as a click too

knotty gale
lost matrix
knotty gale
#

sorry I am new but where is that šŸ˜“

lost matrix
undone axleBOT
crimson terrace
#

you have to call the method and give it that parameter

lost matrix
#

33.33% chance to say hi:

    if (roll(0.3333)) {
      System.out.println("Hi");
    }
small lynx
#

someone knows what i need to cast to solve that

crimson terrace
tardy delta
#

where are your brackets >_<

crimson terrace
#

brackets arent in the budget

tardy delta
#

grr

lost matrix
small lynx
#

i think i fixed

lost matrix
small lynx
#

i just cast it to BigDecimal

#

instead of PlayerAccount

tardy delta
#

my eyes cant handle that theme

crimson terrace
lost matrix
tardy delta
crimson terrace
#

thats fair

lost matrix
#

I never leave any brackets out. Ever. Helps me detect code smell much better and if i where to add more later i wouldnt have to first add the brackets in.

tardy delta
#
if (yes) {
  return;
}``` doesnt look good for the brain
crimson terrace
#

issa doin me a brain hurt

warm saddle
#

no

tardy delta
#

i saw people codin like

if (no) {
  return;
}
if (no2) {
  return;
}
if (no3) {
  return;
}```
crimson terrace
kind hatch
warm saddle
#

works for the other menus im using

#

just

#

and im using the same code with a different item

#

soo

tardy delta
#

and why bedrock

kind hatch
#

What's your event code look like?

tardy delta
#

hurts my brain

warm saddle
crimson terrace
warm saddle
tardy delta
#

people usin eclipse smh

restive tangle
#

Eclipse?!?!

#

Alhamdurillah

tardy delta
#

wha

crimson terrace
#

no idea

warm saddle
tardy delta
#

do you still have an exception or not

lost matrix
warm saddle
crimson terrace
#

Why would you even come here if you wont listen to peoples advise

tardy delta
#

lmao add a null check to prevent errors

lost matrix
restive tangle
#

Lmao, what help a null pointer would be.

tardy delta
#

?

restive tangle
#

Clearly, a null pointer here is just useless!!

crimson terrace
#

gson.toJson() and gson.fromJson will use the @ SerializedName by default without any other code, right?

crimson terrace
crimson terrace
#

nice

patent horizon
#

if i add to the nbt of an entity, will that data stay there until the entity has died

tardy delta
#

pdc?

void shale
#

Is it alright to read other plugin config file or there is better way to read essentials spawn location?

kind hatch
#

Nothing's stopping you, it's just recommended that you use APIs instead if they are available.

warm saddle
#

nope like i suspected adding a null check did fuck all

tardy delta
#

?

eternal oxide
#

Then you did it wrong

crimson terrace
kind hatch
void shale
#

hmm thats right it probably has some api, I just need to figure houw to to check if essentials exist so I can integrate with it

warm saddle
crimson terrace
#

your code changed, we need to see how you changed the code in order to properly help with it

tardy delta
#

i mean.. by code...

flat olive
#

is 32kb for a database good enough to hold 10,000+ players in it?

#

player data related

#

uuid, name, permissions

tardy delta
#

no

flat olive
#

how much space would I need then

tardy delta
#

lol what question is that

flat olive
#

im dead serious I mean you need a big database to hold player data

#

gotta be prepared

crimson terrace
#

see it like this, if you wanted to have 10000 players in a 32kb database you would have 3.2 bytes for each player. I dont think thats enough

kind hatch
#

Potentially Infinite? It all depends on how the data is stored.

#

How it's converted and accessed via memory.

eternal oxide
# warm saddle .

I'm going to guess your NPE happens when you go to drop an item in to a slot

flat olive
#

Hm I guess so

kind hatch
#

A uuid might be stored as a string, or a binary blob, or maybe it could be encoded. Resulting in different sizes of data.

flat olive
#

yeah

kind hatch
#

Names will likely be strings, so they will be relatively large.

#

Same with permission nodes.

#

You'd probably want at minimum 10GB of storage for a large database.

flat olive
#

Yeah I wonder how much those cores cost

#

im gonna check

kind hatch
#

I mean, I did the math a while ago for YAML storage and holy shit can it grow to absurd numbers quickly.

#

I'm talking about Gigabyte range in storage and ram usage.

flat olive
#

Yeah I think its best to have some code to delete some rows of users who haven't played in months, unless they donated or have special perms

kind hatch
#

Databases will obviously be smaller in size, but you could be working with a gigabyte of data if the database is large enough.

crimson terrace
flat olive
kind hatch
#

But, that's really due to how YAML stores its data.

#

It's all one big string.

crimson terrace
#

5kb for one player is a lot damn

#

one byte per char, was it?

flat olive
#

dude what the heck

#

mongdb pays by the hour

kind hatch
#

Yea, the base player file is ~1KB and I wanted to keep track of unique stats. So I needed to log several interactions with the player. Resulting in an ever growing file.

flat olive
#

jesus

crimson terrace
mortal hare
#

5MB for 1000 player data

#

its nothing in today's world

kind hatch
#

Maybe so, but that shouldn't be an excuse to ignore the benefits of smaller file sizes.

crimson terrace
#

5MB is 5MB and could be used in other places if youre able to make the files smaller

kind hatch
#

It's a real challenge to make small programs. Just take a look at the really old school programs/games that had to be made with less than 5KB of storage.

scarlet sun
#
    @EventHandler
    public void onRightClick(PlayerInteractEvent e) {
        Player p = (Player) e.getPlayer();
        ArrayList<Player> list = (ArrayList<Player>) p.getServer().getOnlinePlayers();
        Inventory oplayers = Bukkit.createInventory(p, 9, ChatColor.RED + "Žmogžudžių gaudytojas");
        for (int i = 0; i < list.size(); i++) {
            ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
            ItemMeta meta = playerHead.getItemMeta();
            meta.setDisplayName(list.get(i).getDisplayName());
            ArrayList<String> lore = new ArrayList<>();
            lore.add(ChatColor.GOLD + "Gyvybės:" + ChatColor.RED + list.get(i).getHealth());
            meta.setLore(lore);
            playerHead.setItemMeta(meta);
            oplayers.addItem(playerHead);
            p.openInventory(oplayers);
        }
    }
}

what's wrong here?

scarlet sun
#

GUI isn't opening

#
[21:09:18 ERROR]: Could not pass event PlayerInteractEvent to Tracker v1.0
java.lang.ClassCastException: class java.util.Collections$UnmodifiableRandomAccessList cannot be cast to class java.util.ArrayList (java.util.Collections$UnmodifiableRandomAccessList and java.util.ArrayList are in module java.base of loader 'bootstrap')
#

I get this error in console

crimson terrace
#

this is the error

#

cant cast the getOnlinePlayers to an ArrayList I believe

#

instead you should make a new ArrayList<>(p.getServer().getOnlinePlayers())

kind hatch
#

That's because #getOnlinePlayers() returns a Collection.

#

You need to make a new arraylist instead of casting.

tardy delta
#

which is immutable

sick ermine
#

In minigame addons such as bedwars, skywars, can a map be in only one game?

kind hatch
#

Probably. They likely use copies of a map and remove them once the game is over.

#

If you only had one map, then you could only have one game running at a time.

scarlet sun
kind hatch
#

You could do that, or you could use what Shreb suggested.

scarlet sun
#

I tried, but idk what to change else to make it work, because then how it will find list name

#

oh nvm

#

something like this?

#

Ik it's wrong but what do i need to fix

quaint mantle
# scarlet sun
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
lost matrix
# scarlet sun Ik it's wrong but what do i need to fix

If you sit down and properly learn 2h of java each day for the next 2 weeks then you will have a much greater progress
than dabbling with random java code in Spigot. You wont be able to write a plugin on your own in 3 Months if you keep doing this.

echo basalt
lost matrix
quaint mantle
#

? extends Player

#

eat my balls

lost matrix
#

Yeah

#

XD

quaint mantle
#

same thing

#

just fancier

lost matrix
#

No not the same thing

flat olive
#

extend pp

lost matrix
#

Yours wont compile

quaint mantle
#

more explicit for no reason

kind hatch
#

Got a bit of a design question. As of right now I have an interface called PlayerDataManager. It's currently responsible for handling everything related to the player. Data, preferences, etc.

My question is should I split the interface up into multiple different interfaces? Something like, PlayerDataManager, PlayerPreferencesManager, etc.
As of right now, it's a bit annoying having to update implementations with the new methods even though they don't really apply to them. However, it's real simple to work with as everything is consistent in the one class.

supple elk
#

How can I check this cast?

lost matrix
supple elk
#

I see

restive tangle
#

Fancy colors

#

What's the theme?

lost matrix
supple elk
supple elk
#

can I not do a try catch?

lost matrix
lost matrix
flat olive
#

wow I don't have to pay for mongodb storage if im only keeping track of this data because this data is just a few bytes and I have about 282 bytes on free cluster

supple elk
#

wait so what happens if it the cast isn't safe?

flat olive
#

(500 megabytes) / (300 bytes) =1,666,666 users/w/userdata

lost matrix
eager knoll
#

ItemBuilder b = new ItemBuilder(item).setName(name).setLore(description + ChatColor.GOLD + "\nCost: " + ChatColor.GRAY + "$" + price);
The "setLore" class only gets the first element of what I gave it (description) to output, any way I can fix this?

supple elk
lost matrix
supple elk
#

_>

#

that's stupid

restive tangle
#

Java solos

lost matrix
tardy delta
quaint mantle
#

thanks

tardy delta
#

x)

restive tangle
#

What extends Player?

quaint mantle
#

i guess

kind hatch
restive tangle
#

Alhamdurillah

tardy delta
#

CraftPlayer ye

ornate mantle
#

can i item.setAmount(65)

#

because its bigger than a stack

quaint mantle
#

if the max stack size allows it

ornate mantle
#

what

quaint mantle
#

idk how this works

ornate mantle
#

alr lets say the max stack size is default

quaint mantle
#

but it exists šŸ¤·šŸæā€ā™‚ļø

ornate mantle
#

and i set an item amount to 65 and give it to a player

#

will the player get a stack and one item

quaint mantle
#

no

#

probably just throws an exception

ornate mantle
#

well that sucks

kind hatch
#

No. I think the method has a safeguard that puts it to the max size. Either that or it throws an exception.

ornate mantle
#

the docs dont mention an exception

quaint mantle
#

weird

#

?stash

undone axleBOT
ornate mantle
#

oh

#

"in this stack"

#

probably throws an error

quaint mantle
#

no

#

it doesnt on stash

#

try it and see

#

maybe an internal error instead

ornate mantle
#

wjat

#

what am i meant to do with the stash

quaint mantle
#

i was looking at the code

#
    /**
     * Sets the amount of items in this stack
     *
     * @param amount New amount of items in this stack
     */
    public void setAmount(int amount) {
        this.amount = amount;
    }
#

try it

ornate mantle
#

imma just make a loop and fill all the required spaces

quaint mantle
#

its probably an internal error

ornate mantle
#

If you pass in ItemStacks which exceed the maximum stack size for the Material, first they will be added to partial stacks where Material.getMaxStackSize() is not exceeded, up to Material.getMaxStackSize(). When there are no partial stacks left stacks will be split on Inventory.getMaxStackSize() allowing you to exceed the maximum stack size for that material.

#

alright

lost matrix
# supple elk what do you mean by this?

Example for a registry using the class as key for internal type safety.
First some product class:

  public abstract class Game {

  }

Then a factory class for this product:

  public abstract class GameFactory<T extends Game> {
    public abstract Class<T> getGameClass();
    public abstract Game createGame();
  }

Now we want to have a registry for centralised access to those factories:

public class GameRegistry {

  private static final Map<Class<? extends Game>, GameFactory<? extends Game>> gameFactoryMap = new HashMap<>();

  @SuppressWarnings("unchecked")
  public static <T extends Game> GameFactory<T> getFactoryForGame(Class<T> gameClass) {
    return (GameFactory<T>) gameFactoryMap.get(gameClass);
  }

  public static <T extends Game> void registerGameFactory(GameFactory<T> gameFactory) {
    gameFactoryMap.put(gameFactory.getGameClass(), gameFactory);
  }

}

You can see here that i suppressed the warnings for unchecked casts because the only way to add elements to the internal
map is my calling the registerGameFactory method which assures type safety. This is called strong encapsulation. All the casts happen internally
and you assure type safety by that.
Example for registering factories:

  public static void registerGames() {
    GameRegistry.registerGameFactory(new SkyWarsFactory());
    GameRegistry.registerGameFactory(new OneBlockFactory());
  }

And here you can see the type safe usage with everyone outside this class not having to do any unsafe casts:

  public static void createSomeGames() {
    SkyWars skyWars = GameRegistry.getFactoryForGame(SkyWars.class).createGame();
    OneBlock oneBlock = GameRegistry.getFactoryForGame(OneBlock.class).createGame();
  }
supple elk
#

kk

#

so I'd done all that expect I was using an id as the key not the class

#

so there could theoretically be duplicates

#

or they pass in a string which isn't registered

#

but yeah by using the class itself there will never be an error

lost matrix
#

The problem with your approach is that the String doesnt provide any type context...

spring current
#

I tried to make it so that blocking your sword Will make you take 0 damage instead of 0.5 but it didnt work. Can someone help me?

lost matrix
spring current
supple elk
#

well, it would to the user

lost matrix
supple elk
#

cause if I had a game called skywars the id would be "skywars" or similar

spring current
#

1.8.8

supple elk
lost matrix
# spring current 1.8.8

Well... this is half a decade old. Anyways: Listen to the EntityDamageEvent and check if the defender is of type Player, then cast, then check if the player is blocking.
If so -> set the damage to 0.

kind hatch
#

7smile7: Are you using 1.8?
Fawwazpow3145: No
7smile7: Then what are you using?
Fawwazpow3145: 1.8

#

lmao

spring current
supple elk
spring current
#

Oh

#

Yea i'm just really stupid

supple elk
#

lol dw

lost matrix
# spring current Oh

Should be something in the lines of

  @EventHandler
  public void onDamage(EntityDamageEvent event) {
    if (event.getEntity() instanceof Player player && player.isBlocking()) {
      event.setDamage(0);
    }
  }
feral socket
#

java 16 in 1.8, yeah right

lost matrix
spring current
#

I just learn coding 2 days ago lol

spring current
feral socket
#

what exactly did you try?

spring current
feral socket
#

no, not you

supple elk
#

cause this is eerily similar lol

#

which is probably a good sign

knotty gale
#

I am rying to detect if a arrow hits a block

#

and I am wondering how to check if it hits a certain block

supple elk
#

also @lost matrix can I register with the GameFactory class instead?

supple elk
#

though I'm guessing not considering this..?

knotty gale
lost matrix
# supple elk

This looks weird. Why is GameType not an enum? Does it need to be dynamic?

supple elk
#

GameType is equivalent to GameFactory

feral socket
lost matrix
# supple elk GameType is equivalent to GameFactory

gameType.getClass() is not what you want here.

  public static abstract class GameFactory<T extends Game> {
    public abstract Class<T> getGameClass(); // <- This is the extra method that returns the Class<T>
    public abstract Game createGame();
  }
supple elk
#

why not?

knotty gale
#

like how do I check WHICH block is hit