#help-development
1 messages · Page 1358 of 1
a resource folder is in yoru project but is not transfered to yoru jar
an common library?
those are either in the libs folder at the root of your server or you are using the wrong terminology
Lastly, if its a common library, why are you decompiling anything?
ahh, now i see
but it returned 3 different jar filles
1 original
1 shaded
and 1 "normal"
i think im going to do my database with local filles
i think its better
The library has a database wrapper that both spigot and bungee use
There schema.sql is in the resource folder, it gets copied to the jar(proven by decompiling the jar)
!decompiling. Its just a zipped jar.
however. all contents of the jar can be accessed using getResource() which is the correct way to access it
getResource() returns an InputStream
yes, unfortunately I need to get this with both bukkit and spigot in an agnostic library
its a library used by other plugins
It is a library in maven used by two plugins, bungee and spigot, i need to get the resource from the inside the jar
platform agnostic is terminology
for does not rely on a singular API
structure
need to get schema.sql
so you have a file in your jar you want to access from both spigot and from Bungee
Not what I am talking about, the myriadcommon is a dependency of a plugin in both spigot, and bungee
Stop trying to use flashy words, and explain in basic english what you are trying to achieve
These are basic words that tell you what I am trying to do. This MyriadCommon module in maven(official terminology) is a dependency of two separate plugins, a spigot plugin and a bungeecord plugin. Usually in java you can embed a resource in the resources folder and fetch it with this getClass().getResource("schema.sql"). This seems that it does not work and returns null when used in bungee/spigot plugin. Unzipping the jar shows me that the schema.sql is still there
I cannot do this because its not inherently bukkit or bungee plugin. It is a library used by both, and I need to get the resource from both
Also that terminology is almost official everywhere in the software development world
you have to use the correct ClassLoader to access the resources. It has the be the ClassLoader that loaded the plugin jar itself
is the library being loaded via your plugin or by Spigot/Bungee?
The library isnt really being loaded by them as a plugin but it is being accessed from the plugins
I don't recognise it as anythign shaded by Spigot/Bungee, so I'll assume its yoru plugin shaded
in the form of
database = new Database(config.getString("mysql.url"), config.getString("mysql.username"), config.getString("mysql.password"));
database is in the common library
Yeah its shaded
Well i didnt specify it being shaded but its a maven project with modules so it is shaded in the end result i think(plus it runs normally lmao, so yes shaded)
try using plugin.class.getClassLoader().getResource(arg0)
as that will guarantee you are usign teh ClassLoader that loaded your plugin, no matter if it was spigot or bungee
plugin is?
your plugin main class instance
Ah so since i initialize the database in myriadcommon ill just make the classloader an arg
How do I make it add a specific amount of the item ep?
ItemStack.setCount
Also don’t forget setItemMera
would be nice to see the whole code though, you could just do new ItemStack(Material, Integer)
well the number depends per if statement
so i think i'll just set the item cound in the if statement
but there's the code
Forgot about setting it in the constructor, probably a better idea
well they plan on changing the item's amount multiple times ig? 
can I see the code for checkForItem
yea
just curious
why not just have it return a boolean instead of a string?
idk
wait what
I like strings i guess
yeah just have it return a boolean, so you could do something like:
if(findItem.checkForItem(player1, Material.WHITE_BED)){
}```
Yeah that is some wack code
also you should read up on some naming conventions
ik is supposed to be lowerThenUpper
I tried to do set count but it said set amount, is this the same
what happen
How do i remove a certain amount of a certain material from a players inventory
k
Hey how do i disable something like "You logged from another location." but on BungeeCord
Good morning
Does anyone know about a good job Plugin for economy-based Server?
Any better ways to use TabCompleter?
public final List<String> onTabComplete(CommandSender s, Command cmd, String alias, String[] args) {
if (s.hasPermission("roomicommands.others.ci")) {
return null;
} else {
return Collections.emptyList();
}
}```
EssentialsX and Vault maybe?
Yee, i am using Essentials and Vault but i am searching for a Plugin which Allows to sell Items for money or getting money for farming items
ShopGUIPlus
Or EssentialsX's Sign Shop [BUY] [Sell]
Disabled by Default in config
enabledSigns:
#- color
#- balance
#- buy
#- sell
#- trade
#- free
#- disposal
#- warp
#- kit
#- mail
#- enchant
#- gamemode
#- heal
#- info
#- spawnmob
#- repair
#- time
#- weather```
You can enable it in plugins/EssentialsX/config.yml
I need help. how to get all bossbars in server with foreach? (I tried many things that i can, but I coludn't do)
well its rather straight forward
you cant do commands async
you have to move to main thread before dispatching
If i make a delayed task it do the work?
just make a normal task runnable
Ok ty very much!
.runTask
thanks but for each(Iterator<KeyedBossBar>) Not work
ty
How can I make my own challenges gui? (Like this picture) (This is possible. I'm sure.)
In 1.16 its possible
Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.
thanks but I saw it on 1.12.2 server
1.12.2 ~ 1.16.5 server
but based on 1.12.2
I dont know if its possible or not but im sure you can do it in 1.16
ok thanks, but I couldn't found result on google
of course, I already googled before question
I recommend using MiniMessage https://docs.adventure.kyori.net/minimessage.html and its placeholders https://docs.adventure.kyori.net/minimessage.html#placeholder
Thanks for the advice i will check them
Please decipher
config is not formatted well
hey how do i get if the server is full by using ServerInfo or convert ServerInfo to Server? bungeecord
fix your file
hey can anyone help me with adding placeholders to my scoreboard
i cant find any tutorials that show a scoreboard one
hook into papi
i put it in the external jar things
PlaceholderAPI.setPlaceholders(player, x); thats the code you need to use papi placeholders
yes and make x be the string you want to change
okay
How can I open chest silently? Without any animations? Currently I'm opening chest normally but with animation and if chest is doubled then only 1 part is opening.
Code: java @EventHandler public void onPlayerInteract(PlayerInteractEvent event){ Player p = event.getPlayer(); Block block = event.getClickedBlock(); if(block != null && event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (CHESTS.contains(block.getType())) { if(vanished.contains(p)) { event.setCancelled(true); Inventory inv = ((Chest) block.getState()).getBlockInventory(); p.openInventory(inv); } } } }
well first of all you are getting the block inventory so you are only getting one chest because of that
i dont think it worked
so instead of using getBlockInventory use just getInventory
Score score7 = obj.getScore(PlaceholderAPI.setPlaceholders(player, "%statistic_kill_entity:Zombie%")); score7.setScore(7);
is underlined in yellow
and probably the best way is using packets to not see the animation @odd bronze
Add @SuppressWarnings to createBoard or to deprecation or smth
I tried both and it still didnt show up
Description Resource Path Location Type The method getScore(OfflinePlayer) from the type Objective is deprecated Main.java /rennsb/src/me/renndrew/scoreboard line 54 Java Problem
line 54: Score score7 = obj.getScore(PlaceholderAPI.setPlaceholders(player, "%statistic_kill_entity:Zombie%"));
hi, how could I set as join message an arraylist from the config file?
I tried to do a for loop but it only sends one line
if you mean the setJoinMessage() then that only takes 1 string not an array
yeah, it takes basically a String
what is your arraylist?
are you trying to create multiple lines?
just join them with '\n'
but what if my config has:
JoinMessage:
- "Hello %player%!"
- "Welcome to my Server"
- "Hope you don't leave :D"
you can't set the message multiple times you need to do \n ^
yeah use String.join
String.join?
I remove the for loop?
correct
what's your code
@EventHandler
public void onJoin(PlayerJoinEvent e) {
fl = new FileListener(main);
FileConfiguration msgFile = fl.getMessages();
Player player = e.getPlayer();
if(!(Bukkit.getOfflinePlayer(player.getUniqueId()).hasPlayedBefore())) {
List<String> firstJoinMessage = msgFile.getStringList("Events.FirstJoin");
for (String asd : firstJoinMessage) {
String msgJoin = String.join("-", asd);
e.setJoinMessage(msgJoin);
}
}else {
e.setJoinMessage("Not first time");
}
}
oh ok
the for loop
put the set message method under the forloop
hmm
e.setJoinMessage(String,join("\n", msgFile.getStringList("Events.FirstJoin"))
surely?
nope
no?
The method join(CharSequence, CharSequence...) in the type String is not applicable for the arguments (char, List<String>)
I try toString()?
nothing
XD
The method join(CharSequence, CharSequence...) in the type String is not applicable for the arguments (char, List<String>)
wait
not that error
The method join(CharSequence, CharSequence...) in the type String is not applicable for the arguments (char, Object[])
that one
where can i check the logs file of my minecraft server
i mean the file that stores the console
the recent console logs
in the logs folder
Your , was a .
Your . Was a ,
wat
omg i see the , now XD
bruh
I know why it doesn't work
the setJoinMessage can't get multiple lines I think
but the player.sendMessage can
you're concatenating them down into one line
@EventHandler
public void onLoginEvent(final PlayerJoinEvent event) {
event.setJoinMessage("§f------------\n\n§e[§a+§e]§f Someone Joined\n\n§f------------");
}
Look at what the others suggested
yeah but using a list that is in a config file
I'm trying it XD
yeah it works thx xd
buy I have a little bug
- "&m "
- "&aWelcome &e%player% &ato &cMyServer"
- "&bLet's welcome &e%player%&b!"
- "&m "
that's my list
the last line appears with &b color
ChatColor.translateAlternateColorCodes
I tried to do &r and &f but still in blue
I know how to translate the colors XD
look
is that not expected
I can't send img :c
hey , why when i export a plugin with maven the dependency is in the plugin (ex. bungeecord)
set scope to provided
<dependency>
<groupId>whatever</groupId>
...
<scope>provided</scope>```
i do have it like that
is there any way i could hide the senders name of a message in chat through the AsyncPlayerChatEvent
ah i see why
lose the shade plugin config
wait so how do i export maven?
and where do i write the mvn?
lose the build plugins section then yes, its fine
okay
how can I do that? I know that ProtocolLib can help but idk where to start
gg just fixed the bug 😄
Do you just want to view the content and maybe update the chest on closing or do you want to live edit the chest.
live edit
I've found some article on the internet and changed my code a little bit.
Code: https://paste.gg/p/anonymous/7a167a3adc9e4f55ac15d37ca3dd79dc
I havent check it yet
There is a way where you use a proxy inventory and mirror all click and drag events to the original inventory (and vise versa).
Thats the non packet way
🤔
There might be a way using nms...
Do you want to keep version compatability?
I'm currently at 1.16.4 and Im doing everything on it
so I think yes
so what do you think? @lost matrix
ItemStack sword = new ItemStack(Material.GOLD_SWORD);
ItemMeta im = sword.getItemMeta();
im.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&lGod Sword"));
im.setLore(Collections.singletonList(ChatColor.translateAlternateColorCodes('&', "&7Only to be used by gods!")));
im.spigot().setUnbreakable(true);
sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 100);
sword.setItemMeta(im);```
why is the sword unenchanted?
does anyone know why entitytarget event is not working correctly with hoglins & zoglins?
Im cancelling the target event for them
they dont attack me first anymore
but if i punch them, they still attack me
which it shouldnt do
@EventHandler
public void onWrongTarget(EntityTargetLivingEntityEvent e) {
if (main.getConfig().getBoolean("hostile-mobs-attack") == false) {
if (e.getEntity() instanceof Zoglin) {
if (e.getTarget() instanceof LivingEntity) {
e.setCancelled(true);
}
}
}
}
But e.setcancelled works with all the other mobs
theys never attack me
the issue only occurs with zoglins and hoglins
but ill try it
How do I get the location for every gold block. The green wool has the coordinate -52 76 -66. And the way to the gold block is with a vector to (5, -1, 3).
question, how can i clear a specific nbt tag in a tile entity?
ive tried this but it completely resets the furnace
Ok, so i have a PacketPlayOutMapChunk packet which is then put into a PacketContainer. I currently then modify the packet like this:
(wrappedPacket is the PacketContainer)
if (fillWithAir) {
wrappedPacket.getByteArrays().modify(0, bytes -> {
Arrays.fill(bytes, (byte) 0);
return bytes;
});
}
In order to essentially 'void' the chunk as it just overwrites all blocks with air. However, instead i would like to have it like this:
Where the ‘south’ row of blocks are all left behind. However, I am not too familiar with the byte arrays and would appreciate some pointers! 😄
@opal juniper https://wiki.vg/Chunk_Format#Data_structure
Why do you need an alternative to morphia?
Morphia causes alot of errors for me
I have tried to fix them for like a week
I've just given up
at this point
how can i rotate this?
Morphia is the most popular odm for a reason. If it throws errors then you are probably misusing the library.
Using any mapper has to flow into your design process when you start writing your application. You cant just
throw any mapper in at some point and expect it to work.
How much experience do you have with using the plain mongodb driver for persisting objects?
Not much
Jackson + mongodb is the sexiest thing to exist
Then scrap the idea of using ODMs or ORMs. Its an extra abstraction level for people who have
experience with the underlying database architecture so they dont need to write the boilerplate code
they have written several times already.
How much experience do you have with serializing Objects into Json? Like with Gson or Jackson.
mongodb on its own is a bit of a pain
Not much either
Then also scrap the idea of using document databases. Step one:
Serialize your objects to .json files and deserialize them back from .json files.
You can use Gson (which is build into Spigot) or Jackson for that.
After that you can use that code + your gained knowledge to easily get into document based databases like mongoDB.
@lost matrix Alr, but one question. When I use mongodb it spams Opened connection [connectionId{localValue:2, serverValue:21499}] to database and then creates 50 objects with the same ObjectId
Is mongodb the first database you are trying to learn?
So you are skipping
- Simple (de-)serialisation
- Persisting objects to arbitrary Strings like yaml
- Database architecture
- Connections and connection handling
- Connection pooling
- Simple Json (de-)serialisation
- Document based vs Relational based comparison
- Manual mapping from json to bson
- Automatic mapping with mapper tools like ORMs and ODMs
- Auto persisting with morphia < -- You are here. Most of the steps above are a hard dependency for understanding mophia. (Like connection handling)
You skipped a lot of important steps in learning morphia. No idea who told you to jump right into that but its a bad idea because you will be confused for months.
Step one is saving your objects into plain .json files. Thats where you should start. Gson is pretty easy to understand and there are some great tutorials on that.
@weary geyser
maybe use a rotation matrix
Spigot vectors already do the heavy lifting for you. They have rotation methods for all axes.
oh lol since when what the hell
Lol ye
Whats the best way to set a spawn location for a player?
?jd
package index
How do you mean? is it on RespawnEvent?
On join
teleporting the player on join doesnt seem right to me
No, that seems ok
Set a one tick delay
Good Idea, so it doesnt kick the player, like previously
What? Lol
Before PlayerJoinEvent? Are you referring to Async/PlayerLoginEvent
Dont know, but I had issues with it recently
Adding a delay happens after the event
Yes
👍 thought you got confused in regards of that
@quaint mantle be careful, teleporting players on join might cause visibility issues
I know
you should use playeronspawnevent
THANK YOUUUU
PlayerSpawnLocationEvent*
That was exactly what I was looking for , thx
Probably some NMS hackery
Never knew that, thanks Ferskfisk
most likely
hm
Hey, how can I round a double to 2 decimal places? I have looked a lot on the internet but somehow nothing worked out.... I have a BlockBreakEvent and every time the player takes down a sand, then 0.45 is added. 🥲
there are many ways to do this, which a simple google search will yield
Two ways. Some cast and division trickery or using DecimalFormat
There are definitely more than 2 ways
DecimalFormat df = new DecimalFormat("#.##");
df.format(number);```
thats how I do it at least
that was what i was trying 2 do
thats an M
I never noticed how weird the font is
thats an M
lmao
what is the best way for saving player stats?
Caching and know updates by plugin messaging
CompletableFutures for IPlayers and caching some for placeholders```
#help-server pls thx
then what? xd
Having boss bars for that stuff is neat
yeah @young knoll
then I name is Player
who, me?
yes
no
oh what do you use then
or what do you mean by oshi?
one sec let me pull it up
I need like a MMOItems plugin in 1.16.5 (sorry for english lul)
The one just truncates the double the other one formats it with the given options.
public static double truncateDecimalPlaces(final double value, final int decimals) {
double scale = Math.pow(10, decimals);
return (int) (value * scale) / scale;
}
public static String format(final double value, final int decimals) {
String formatString = "#." + "#".repeat(decimals);
return new DecimalFormat(formatString).format(value);
}
That looks pretty sweet
im using com.sun.management.OperatingSystemMXBean
yeah

and also
This intendation
what about the indentation lol
if(players>0) entTitle += "Player " + players + " ";
if(items>0) entTitle += "Item " + items + " ";
if(minecarts>0) entTitle += "Cart " + minecarts+ " ";
if(peaceful>0) entTitle += "Peace " + peaceful+ " ";
if(hostile>0) entTitle += "Hostile " + hostile+ (others==0?"":" ");
if(others>0) entTitle += "+" + others;
🥲
And stacked blocks...
what is this?
(:
O.o
@lost matrix , @solemn shoal thanks! now it worked : )
i swear that code is autoformatted
yeah i dont see the issue
it reduces the length of the bossbar lol
!_!
guys can somebody help me?
im trying to teleport to another world
but it wont work
yeah what about the onenable
Show some code pls
ok
@EventHandler
public void onRightClick(PlayerInteractEvent event){
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(event.getItem() != null){
if (event.getItem().getItemMeta().equals(ItemManager.Survival.getItemMeta())){
Player player = event.getPlayer();
player.teleport(new Location(Bukkit.getWorld("LoTooS2"), 260, 68, 270, 0, 0));
}
}
}
}
Do you want to teleport to the other worlds spawn location?
player.teleport(Bukkit.getWorld("LoTooS2").getSpawnLocation());
i only put it in the root server dir
Is the world loaded?
wdym?
Is the world your main world or did you manually load the world by using the WorldCreator class?
Because Spigot doesnt just randomly try to load every folder thats in your directory.
Wherever you need it.
Then load the world so you can teleport to it.
how?
WorldCreator worldcreator = new WorldCreator("name");
worldcreator.environment(Environment.NORMAL);
Bukkit.createWorld(worldcreator);```
yes that code could be shorter but it works
what if i want to use a world i downloaded?
Np
public World loadWorld(final String worldName) {
final File worldFolder = new File(Bukkit.getWorldContainer() + File.separator + worldName);
if (!worldFolder.exists()) {
return null;
}
return WorldCreator.name(worldName).createWorld();
}
This doesnt check for the world type so it only works for default worlds.
does anyone here have experience with NMS? if so, i have a CraftServer instance, how can i force a tick
or set a tickrate that isnt 20
Guys, this code: orangeglassmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE);
Don't make my cool orange glass glowing, help?
Hello, I don't know a thing about nms. And I want to support multiple versions of my plugin. Do you have any tutorials for anyone who hasn't done nms at all?
CraftServer is craftbukkit and not NMS
The tick rate is a static final constant. You could change it but this would instantly break absolutely everything.
Yea but my glowing cool orange glass? 😭
did you actually enchant it?
^
It isn't enchanted
Wow
Look 😄
yeah.. you need to actually enchant it with something for it to glow
the item flag simply hides the fact that it is enchanted in the lore
well my main objective is to run more random ticks
and if possible, more ticks in general
I have never used an enchant / itemflag before, thanks
gamerule randomTickSpeed?
I mean you can set the randomTickSpeed from code
basically what im trying to achieve is speeding up the game whilst players sleep
So set the tick speed higher for a bit when they sleep
I've a problem, i need an enchant for a glass_pane
Just add any enchant
Force the enchantment?
hw
I looked a bit into the MinecraftServer class and this is worth a try:
public void forceTickNow() throws ReflectiveOperationException {
final MinecraftServer server = MinecraftServer.getServer();
final Field forceTicks = MinecraftServer.class.getDeclaredField("forceTicks");
forceTicks.setAccessible(true);
forceTicks.setBoolean(server, true);
final Field nextTick = MinecraftServer.class.getDeclaredField("nextTick");
nextTick.setAccessible(true);
nextTick.setLong(server, SystemUtils.getMonotonicMillis());
}
Thanks Mr.Eclipse
Mr.Eclipse, unSafeEnch doesn't work, my super cool orange glass isn't glowing
package index
yo thats neat
I think the problem is here:
orangeglass.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, 1);
orangeglassmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE);
On the flag
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html#addUnsafeEnchantment(org.bukkit.enchantments.Enchantment,int) yes, yes it does
declaration: package: org.bukkit.inventory, class: ItemStack
Also, did you even set the itemmeta?
And you should also no change the enchantment via non-itemmeta ways in between obtaining the itemmeta and setting it on an itemstack, as otherwise it will get overridden
ItemStack orangeglass = new ItemStack(Material.ORANGE_STAINED_GLASS_PANE);
ItemMeta orangeglassmeta = orangeglass.getItemMeta();
orangeglass.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, 1);
orangeglassmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE);
orangeglassmeta.setDisplayName(ChatColor.GRAY + "");
orangeglass.setItemMeta(orangeglassmeta);
see, this is you issue
I'm going to try, thanks Mr.Eclipse
probably since you are already manipulating item meta
ItemStack orangeglass = new ItemStack(Material.ORANGE_STAINED_GLASS_PANE);
ItemMeta orangeglassmeta = orangeglass.getItemMeta();
orangeglass.addUnsafeEnchantment(Enchantment.VANISHING_CURSE, 1);
orangeglass.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_UNBREAKABLE);
orangeglassmeta.setDisplayName(ChatColor.GRAY + "");
orangeglass.setItemMeta(orangeglassmeta);
This doesn't work..
WOW did you even read my comment?
You are still using the itemstack methods
kekkekekekekkkk
Issue is there is no force enchantment method for itemmeta
There is a ignore levelcap parameter though, but I do not know if it is doing what it should
So better be safe than sorry
I'm confused, help Mr.eClipse
Stop being an idiot ffs
And you should also no change the enchantment via non-itemmeta ways in between obtaining the itemmeta and setting it on an itemstack, as otherwise it will get overridden
Shut mr automod
You shouldn’t do it at all if you are already editing the meta
^
So do I have to turn both of them into itemmeta and not put them out of it?
xy cvdfhmkljrzäfs vjvxcdizk
Ight, discord is bad for my mental health, if anyone needs me, I'll be at IRC
No pls geol help me
Hello again
doesnt seem to work?
is there an easy way to have different inventories in each world?
for example when im in a hub i will have a different inv than when im in survival world
Try to make a hash map with the world id and an inventory
a what?
nvm im dumb, didnt start my timer
Im currently in a deep dive on the search of the class that extends MinecraftServer.
My first hint was DedicatedMinecraftServer.class but i cant find it. I might need to follow the breadcrumbs through the manifest file and the whole bootstrapping to find out what
single method invokes the actual tick.
but how do i do that for each player?
Hashmap in a hashmap
HashMap<UUID, HashMap<Integer, Inventory> data = new HashMap<UUID, HashMap<Integer, Inventory>();
note to self: dont invoke 5 ticks at once
I think this should work
But its possible that there is a lot simpler solution
As i told you: You will break absolutely everything. Minecraft is hard wired on this 20 TPS constant.
no i was trying to run infinite ticks lol
rip
also minecraft catches up when it has a lag spike
sometimes peaking up to hundreds of tps
yatopia is fork hell
i've heard stories
enjoy when your world gets eaten for breakfast
it's literally just a compilation of everyone else's patches
well yes
Btw this is the actual method that gets called by the minecraft scheduler.
public void forceTickNow() throws ReflectiveOperationException {
final MinecraftServer server = MinecraftServer.getServer();
final Method tickMethod = MinecraftServer.class.getDeclaredMethod("b", BooleanSupplier.class);
tickMethod.setAccessible(true);
final BooleanSupplier someBool = () -> true;
tickMethod.invoke(server, someBool);
}
isnt b already public?
Its protected i think
what's the "good" way to get the main instance of a plugin
instead of using singletons
I want to make my main instance accesable
Nope. None of those tick the server.
Either static singleton or dependency injection (for example passing the instance in the constructor of your manager classes)
Heyo!
Just wondering how I can add stuff to my config.yml from another class that isn't my main.
if (configFile == null) {
configFile=new File(Main.instance.getDataFolder(), "config.yml");
}
configuration=YamlConfiguration.loadConfiguration(configFile);
I use this
im a bit stuck on this. i want to list all online players on index but i dont have a clue on how i can do this
oh yes I am definitely using DI for internal plugin classes, I meant making my class accessable by other plugins
I don't really want to use a singleton
imma try your code now
I guess it doesn't matter too much
You normally dont expose your main class to other plugins.
If you want to write an API for other plugins to hook into then you should create an API class that can provide other
devs with the needed methods and/or instances (besides your JavaPlugin instance)
hey smile, your code doesnt seem to work either
nvm
it isnt reflected in the server TPS tho
obvsly...
is there a decent way to make a particle trail just using the player's direction?
I'm trying to learn all the test driven development-type stuff
and good oop and all that
Btw this is hilarious:
@Override
public void onEnable() {
Bukkit.getScheduler().runTaskTimer(this, () -> {
try {
SpigotCore.forceTickNow();
} catch (final ReflectiveOperationException e) {
e.printStackTrace();
}
}, 1, 1);
Bukkit.getPluginManager().registerEvents(this, this);
}
public static void forceTickNow() throws ReflectiveOperationException {
final MinecraftServer server = MinecraftServer.getServer();
final Method tickMethod = MinecraftServer.class.getDeclaredMethod("b", BooleanSupplier.class);
tickMethod.setAccessible(true);
final BooleanSupplier someBool = () -> true;
tickMethod.invoke(server, someBool);
}
Everything just runs twice as fast/often.
But the client gets out of sync very often.
i mean im surprised the server only reports 20tps regardless of running faster, considering if its catching up due to lag, it works fine
Do you mean a particle trail as they walk, or a trail from them to some location?
trail for a place
Just because you invoke the tick method more often doesnt magically re-write thousands of lines of code that expect the TPS to be 20.
This piece of code will never be helpful and will always break everything. No exception.
i mean if the server had a lag spike, and it catches up, it does go above 20
@minor garnet yes it fairly easy but you need to explain your end goal better so we don;t waste time on things you don't need
I feel like there's a better way to do this then searching the class for the method every single time
maybe you should consider caching the method in a static variable or something
You would obvsly cache the Method instance. But this is just a little toy thingy.
ah ok makes sense
I just need to do a particle trail when you right-click in the direction from which you aimed
lol im so big brain
I was adding something to my config.yml and I was wondering why it wasn't showing up
@minor garnet ok thats easy.
then I realized I forgot to save lol 😂
Ive send you my code ive written yesterday where i played around with bullets. There is some method that creates a particle trail somewhere in there.
https://gist.github.com/Flo0/bbc2ee41e4decf33a83fa0b9d65fb853
that ?
Yes. Now that i look at it its not so pretty and doesnt explain itself really well...
@minor garnet When you click you just need to get the players location. then loop however may times you want to place a particle java Location loc = player.getLocation(); Vector direction = loc.getDirection(); Location particle; for(int x... particle = loc.clone().add(direction.clone().multiply(x)); loc.getWorld().spawn...
@lost matrix time to call that code from a timer lol
Stay on the main Thread
Fork the server and re-write the code so the server can handle the arbitrary tick delay.
what, just fork spigot?
Yes. This way you dont need to tinker with reflections or injections
Generics pognt:
I currently have OxideDAO<T> defined. I have a map of it that looks like this: Map<String, OxideDAO<?>>. It is defined in another class. I am trying to use this to get a DAO from the map: OxideDAO<Ban> testDAO = (OxideDAO<Ban>) databaseHandler.getDaos().get("ban"); However, there's all kinds of generics issues with that. IntelliJ wants me to generify the class, but when I try to, it does nothing. I'd also prefer a way that doesn't require me to cast. The class Ban doesn't extend anything; it's a morphia (mongo) object.
What should I do?
Side note: getDaos is generated by lombok and I cba to rename it yet
You have to pass the class of your generic type and then cast. The type is erased at runtime and there is no way around that. (Unless you make the DAO type aware)
what is the maximum speed of a projectile for it not to be going in random relations on the player's client?
random relations?
I get what you mean by passing the class but how would I do that?
Also, what do you mean by this?
(Unless you make the DAO type aware)
I'm fairly unlearned when it comes to generics, although I understand the basics.
Example:
private final Map<String, DAO<?>> daoMap = new HashMap<>();
public <T> DAO<T> getDao(String daoName, Class<T> daoClass) {
return (DAO<T>) daoMap.get(daoName);
}
ah, I see.
random directions, bad translator
velocity is a Vector so there should never be a random direction
Wait, but daoClass is never used?
Oh nvm I get it
Yes. Its just to generify the method.
poggers OxideDAO<Ban> testDAO = databaseHandler.getDAO("ban", Ban.class);
poggers is my thing right now
it works
how do I check the first collision with a block from the player's direction? in a max of 8 blocks
I want to teleport the player to the location that is 8 blocks in the direction they are looking at, but stop them if there is a block in between
Location destination = p.getLocation().add(p.getLocation().getDirection().multiply(8));
p.teleport(destination);
that's the code I have right now (no checks for collisions)
Ray trace for blocks or use a BlockIterator
how do I use raytracing?
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/World.html#rayTraceBlocks(org.bukkit.Location,org.bukkit.util.Vector,double) Will be null if no blocks are found
but I need to get the collision location as well
if there is a collision, you get a RayTraceResult
public Vector traceOrMax(final Location start, final Vector direction, final double length) {
final RayTraceResult result = start.getWorld().rayTraceBlocks(start, direction, length);
if (result == null) {
return direction.multiply(length);
}
final Block hitBlock = result.getHitBlock();
if (hitBlock == null) {
return direction.multiply(length);
}
final Vector hitPosition = result.getHitPosition();
return hitPosition.subtract(start.toVector());
}
This will return the max length vector or the vector at which the first Block
was hit if present.
ok thanks
question, how can i unload a plugin through code?
say i want to disable & unload a plugin called SleepFix
You can try:
Bukkit.getPluginManager()#disablePlugin(JavaPlugin);
Spigot only has one method.
wait my IDE says world doesn't have the method rayTraceBlocks()
This means you are probably on an ancient spigot version.
can I use newer spigot/bukkit api methods for a legacy server?
like 1.16 api for 1.8 server
lol
no right?
update to 1.16 and use a plugin to provide 1.8 combat
No. The 1.8 server just misses a ton of new API features. Its old and unsupported for a reason.
Do you know an easy-method for create an "Animate GUI"?
Inventory with a scheduler. Its a bit hard to get this right.
i read this is "anime tea'd goo why"
A normal Repeating Scheduler? SyncRepeatingTask?
Yes. I would create a single scheduled runnable that contains some collection of tickable inventories of which each is a state machine that can be progressed by ticking it.
Then upon opening the inventory i would add it (or better its wrapper) to the runnable and remove it again when the player closes the inventory.
yes it is
its my plugin test server so it doesnt matter
anyways
dunno how i didnt notice
I think there is an easier method because UltraPermissions is too light too
but 1.16 servers are laggier
and btw if i compile for newer versions
would I have to add api-version?
1.8 is over 5 years old and no longer supported
Do you need to support literally hundreds of concurrent users?
No? -> Not a concern for you.
I know but it's still better optimized than 1.13+
no but I want to use it on a 1.8 server
then write it for 1.8
as 7smile7 said, unless you have hundreds of concurrent users you'll never notice.
youre already going for low spec hardware to begin with
I ran 1.15 on a rpi 4 with 4gigs. No problems for <10 users if properly configured.
HOWWW
i have a 4gb rpi
and run a 1.16 smp in paper with preloaded chunks and the server goes to 8tps with 3 players
:c
wait this should be in #help-server
You probably installed a bunch of trash plugins.
And didnt configure the server for the load.
??
i only use plugins to load chunks, tp through worlds and my custom coded ones
none of them should really lag the server that much
i also turned down the chunk distance to like 8
Run timings v2 (to track down bottlenecks)
Also use a high Java version and the G1GC
@civic apex use Spark and run it for a bit to get some info about your server and what’s happening
you’ll get much more in-depth info about the root of the issue than regular timings
nah 8 is fine
is there a way i can display mob health bars without overriding their names?
can some1 help me
bb and bp should final or something like this idk but where i must change this
@solemn shoal You could probably use packets. That way, the server will not have to rename mobs, but the clients will think the mobs are named
hm its not like i can do a scoreboard belowName kinda thing?
when you define them
e.g. final Player bp;
does spigot fork craftbukkit?
Spigot builds CraftBukkit
how can I import CraftWorld?
more precisely BuildTools builds Spigot and includes CraftBukkit.
well yes
using Maven?
if you are importing a spigot jar then CraftWorld is in there
as I said above.
but is it from nms or bukkit/spigot?
and how do I import it then?
Spigot jar has them all
because (CraftWorld) world gives me an error
show what you are trying to do
CraftWolrd cw = (CraftWorld) e.getPlayer().getLocation().getWorld();
I hope thats a typo
it was
then that code is correct
are you tryign to get the NMS world object?
hm, how can i fix a "NoClassDefFound" error?
:c
my class exists yet the server throws a tantrum over it
No class found = using a lib thats not on yrou server at runtime
its another class in my plugin
[20:33:32 ERROR]: Could not pass event BlockRedstoneEvent to EssentialTools v1.0
[20:33:32 ERROR]: Suspected Plugins:
[20:33:32 ERROR]: EssentialTools{enabled,ver=1.0,path=plugins\EssentialTools.jar}
[20:33:32 ERROR]: Exception details below:
java.lang.NoClassDefFoundError: net/thearcanebrony/essentialtools/mechanics/RedstoneEventTracking
at net.thearcanebrony.essentialtools.events.ETBlockRedstoneEvent.RedstoneEvent(ETBlockRedstoneEvent.java:14) ~[?:?]```
that is using 1.8 and craftworld for raytraceblocks
ETBlockRedstoneEvent.java:14
package net.thearcanebrony.essentialtools.events;
import net.thearcanebrony.essentialtools.RuntimeStore;
import net.thearcanebrony.essentialtools.mechanics.RedstoneEventTracking;
import net.thearcanebrony.essentialtools.wrappers.ETEventHandler;
import org.bukkit.Chunk;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockRedstoneEvent;
public class ETBlockRedstoneEvent extends ETEventHandler {
@EventHandler
public void RedstoneEvent(BlockRedstoneEvent e) {
Chunk a = e.getBlock().getLocation().getChunk();
RuntimeStore.RedstoneEvents.get(RedstoneEventTracking.CurrentTick).add(new Integer[]{a.getX(), a.getZ()});
}
}```
line 14 is RuntimeStore... (2 lines from end)
That error you posted looks odd. Suspected plugins?
suspected plugins..
only one listed is mine
(all the code is in the same plugin)
its definately there in the jar..
https://gitlab.com/thearcanebrony/essentialtools
compiled jar:
throw your RedstoneEventTracking.java in here
one sec gotta figure out whats eating my cpu
just drag/drop it will auto format
wait my org.bukkit.craftbukkit only has Main as a class
Can you make a parent module depend on a child module? (Maven)
drag/drop what?
nm I see you posted source
anyone knows why? CraftWorld isn't a class for some reason
did you import bukkit
i imported spigot
you need bukkit
both imported?
craftbukkit right?
im compiling against a yatopia jar but youre on 1.8 so i cant help you there
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>version</version>
</dependency>```
im not using maven
Bump
ugh
mod
ant? i dont actually know
Use a framework
just use import
wouldn't that parent module under another parent module just be a child module?
That's way better
oh shit
meant child module
typo
Yes I think
How would you do it?
Well it's a bit confusing
<dependency>
<groupId>me.zoibox.core</groupId>
<artifactId>LucentAPI</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>``` Because that didn't work
what was the error?
Yk a fix?
its impossible to know without some context or smthing
What do you want
could you show me your full pom
Yeah i'm not sure hm
People have to stop doing this if they want to use craftbukkit and or nms.
The proper way is using the normal spigot group id and spigot artifact instead of spigot-api
i compile against a paperclip cached jar
Did you manually install that into your maven repo?
Ah...
i started in eclipse
bump
This support is for Spigot only. Replace your jar with Spigot and try. If it doesn't work come back for help
never learned how to set up maven etc
That doesnt make sense. Why would a parent depend on a child...
Idk but I need to
If you "need to" then your design is flawed. I dont even know how this is supposed to work in the first place.
I was thinking of something different. Like we could have a completely separate project with a parent which its dependencies having one of the childs of another project as a dependency
regardless @eternal oxide found any reason why my class wouldnt be found?
idk anything outside of ant lol
i'd be using gradle but idk how to set it up
regardless, it works fine for my usage
If you never depend on external libraries then this is fine.
i had a dependency ages ago
i just included its compiled files in my jar
also i currently have a dependency on Vault (softdepend)
(no im not compiling against 1.15)
just cba to rename that module
And then you see some proper java libraries you would like to use and have to tinker with maven commands to get an actual jar you can include.
And if one of the transitive dependencies changes you have no way of automatically detecting and updating that. ^^ But you will eventually encounter those problems.
i mean, aside vault and a server jar i have no dependencies
wait let me try cleaning my build dir lol
or is that not a thing you can do in intellij?
that fixed it..
What does EntityDamageEvent.DamageCause.CUSTOM does and how could I use it?
its just an explanation of how an entity was damaged for devs
iirc it's only used when specified manually by a plugin
Its only applied for damage that is normally not dealt in vanilla.
Does it let me display custom death causes?
no
How could I override death messages only on some ocassions?
EntityDeathEvent#setDeathMessage(String)
Listen for the EntityDeathEvent and set the messages based on conditions.
Ok, thanks!
ok thats wierd I just got a Github notification for somethign from 2014 https://github.com/AigleDev/backport/commit/ca27a33e84f9332a045de70d91d3f48061946f12
404
lul
silly links
it was just a fix for offline uuids for pseudo players being duplicated in CraftBukkit
but it was from 2014
oh lol
how do I get an array of blocks that go on a straight line between 2 positions, or one position and a vector?
loop getRelative for X distance
How to make a delay in event? Like PlayerMoveEvent player moves send message 2 seconds send message. For not spamming.
Using a BlockIterator if you want it for an arbitrary vector
Create a Map<UUID, Long> where you keep track of the last time you have sent a message to a specific player (System.currentTimeMillis())
Then you can check if the last message is older than 2 seconds.
Thanks
Something like this should work:
public List<Block> getBlocksInBetween(final Location from, final Location to) {
Preconditions.checkArgument(from.getWorld() != null && from.getWorld().equals(to.getWorld()));
final World world = from.getWorld();
final Vector start = from.toVector();
final Vector direction = to.toVector().subtract(from.toVector());
final int distance = (int) Math.floor(direction.length());
final double yOffset = 0;
final BlockIterator blockIterator = new BlockIterator(world, start, direction, yOffset, distance);
final ArrayList<Block> blockList = new ArrayList<>();
blockIterator.forEachRemaining(blockList::add);
return blockList;
}
any idea why this doesnt work? ```
class simplecmd: CommandExecutor {
override fun onCommand(
sender: CommandSender?,
command: Command?,
label: String?,
args: Array<out String>?,
): Boolean {
val player: OfflinePlayer? = null
val worldname: String = player?.getUniqueId().toString()
if(Bukkit.getWorld(worldname) != null) {
Bukkit.createWorld(WorldCreator(worldname).type(WorldType.valueOf("DEFAULT")))
return true
} else {
return true
}
}
}```
it doesn't gives any error or smth
that isn't java right?
What exactly doesnt work?
Did you register this class as an executor for a command?
Did you specify the command in your plugin.yml?
Kotlin, but mostly similar to java
oh ok
it doesn't create the world
thought that was only used for android dev mb
Did you check if the method actually gets called?
Add some std outs in there and see what condition block is actually called.
Btw this can be scrapped to just return true at the end:
return true
} else {
return true
}
Hey someone have an idea how to cancel a block place in radius 3 arond block of sandstone
@civic apex java is used for android dev too
Around every block of sandstone or just one specific block that happens to be sandstone.
every
Kotlin can be used everywhere where Java can be used
Could be expensive... The only thing i could think of is iterating over every nearby block.
i dont like kotlin's syntax, but to each their own
also afaik kotlin and java compile to the same bytecode regardless
So
public boolean isNearMaterial(final Block block, final int checkRadius, Material material) {
for (int x = -checkRadius; x < checkRadius; x++) {
for (int y = -checkRadius; y < checkRadius; y++) {
for (int z = -checkRadius; z < checkRadius; z++) {
if (block.getRelative(x, y, z).getType() == material) {
return true;
}
}
}
}
return false;
}
I have some things in mind that could be done for optimizing this but they are really labour intensive.
Guys, i've a problem, I need to make a region of the GUI clickable and i need to transfer item in it, but I can't move items from my main inventory, help?
I tried with a switch of all single slot
Check the clicked slots and dont cancel if the clicked slot is one that should be clickable.
I tried all, i'm trying this for now:
https://pastebin.com/jKK2vu1e
Atrocious.
If you want to determine if a slot is clickable then you can just use a Set<Integer> and add all non clickable slots in there. Then you simply call contains on that Set to check if the event should be cancelled or not.
Already tried everything as I said.
I can't move from my main inv
I was using if, switch + default and so more..
Yes. Dont create fields but just have methods that take a Location and create an Entity at that location
public LivingEntity spawnSpecialMob(Location location) {
Check if the clicked inventory is of type PlayerInventory and dont cancel the event in that case.
The basic bukkit inv is a Chest right?
You should add this to some manager class.
Yes
Perfect
At the point you write the method you have no idea what Location you will get later on.
You just write the method and dont call it in your constructor. You call it every time when a mob should be spawned later on.
You know how to make a safezone around a location ?
I tried, this doesn't work https://pastebin.com/7qNwAcDa, i can't move from my main
Sure. If you want to do it from scratch: BoundingBox
Otherwise: WorldGuard
Sry but im not reading that. Its just too messy. Arent there a ton of tutorials on creating proper GUIs?
What do you mean by that? Do you mean what you should put there as method parameter? As method body? As return value or type?
Man, are you kidding me? It's just a
if title = title && Inventory = Chest
Switch Slot 3, 13, 22 cancel false
Default cancel true
The problem is only this: "I can't move from my main inventory"
declaration: package: org.bukkit, interface: World
Check if the clicked inventory is of type PlayerInventory and dont cancel it in that case.
No sense, i'm already checking if the inventory Is a Chest before the event cancelled
You are checking for the primary inventory involved in this event and not the clicked one.
Im stupid, thanks and Sorry ahahah
i would like to get a radius around player and delete all sandstone blocks
int raduis = 2;
Block middle = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
for (int x = raduis; x >= -raduis; x--) {
for (int y = raduis; y >= -raduis; y--) {
for (int z = raduis; z >= -raduis; z--) {
if (middle.getRelative(x, y, z).getType() == Material.SANDSTONE) {
}
}
}
}```
i don't know if it's good ?
Sure... but who iterates loops like that?
idu
Then you need to stop with Spigot and give yourself some days to learn the very basics of Java.
You spawn the mob inside the method body, modify it then return it.
You can get the World instance from the Location variable.
Spawning the mob gives you an instance of Entity (Wither, Zombie, Skeleton or whatever)
Just return that
int radius = 5;
final Block block = event.getBlock(); //placed block
for (int x = -(radius); x <= radius; x ++)
{
for (int y = -(radius); y <= radius; y ++)
{
for (int z = -(radius); z <= radius; z ++)
{
if (block.getRelative(x,y,z).getType() == Material.OBSIDIAN)
{
block.getBlock().setType(Material.AIR);
}
}
}
}
it will work ?
Sure. This would remove all obsidian blocks in a 5 block radius.
Its a variable...
Not even close...
Im not trying to be a d**k but you need to learn at least the very basics of the programming language before jumping into writing plugins for another application that was written in that language.
And you did clearly not take the time to do that...
This is an example of how you would use a static spawn method from your MobManager class
to spawn some mob each time a certain Material is broken:
@EventHandler
public void onBreak(BlockBreakEvent event) {
// Get the block from the event
Block block = event.getBlock();
// Check if the block is of type OBSIDIAN
// If its not then we do nothing (We just return)
if (block.getType() != Material.OBSIDIAN) {
return;
}
// Get the location of the broken block
Location blockLocation = block.getLocation();
// Spawn a mob at that location by using the MobManager
MobManager.spawnObsidianZombie(blockLocation);
}
But i strongly advice against using the static keyword until you understood it completely.
99% of Java can and should be done without using statics.
@lost matrix just out of interest how long have you been doing Java
I dont know... i think i started programming in summer of 2019
Oh wow, so not that long
Or winter 2018? Thats more probable. So 2 - 2.5 years i suppose
Dang ur good
Thanks 😄 i just got a passion for programming. Ive actually started because of Minecraft.
It's very satisfying 👍
Btw did you figure out how to create the border chunks by now?
How may I send action bar messages in 1.8.8?
Using packets i think.
Yeah, I found a tutorial on sending action bar messages but no hope at all
PacketPlayOutChat. But 1.8 is ancient. So go and search in forum posts from half a decade ago.
No... I was talking to the guys in paper earlier but didn’t get anywhere. They said it would be REALLY difficult, lemme try find the message
yeah I know, I did but nothing I find on the forums works
public void sendActionText(Player player, String message) {
PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(message), (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
This breaks compatability with all versions but it should work.
Where did you find that one?