#help-development
1 messages · Page 1347 of 1
try that
ok i will
i recommend
if (!item.getType().equals(Material.WRITTEN_BOOK)) {
player.sendMessage(ChatColor.RED + "You have to hold your data book to start the game!");
return true;
}
BookMeta meta = (BookMeta) item.getItemMeta();
String testPage = meta.getPage(0);
player.sendMessage(testPage);
else is redundant
And
😳 👉 👈
if (!item.getType().equals(Material.WRITTEN_BOOK)) {
player.sendMessage(ChatColor.RED + "You have to hold your data book to start the game!");
return true;
}
BookMeta meta = (BookMeta) item.getItemMeta();
[there was nothing here]
String testPage = meta.getPage(0);
player.sendMessage(testPage);
if (meta.getPageCount() <= 0) {
player.sendMessage(ChatColor.RED + "Book is empty!");
return true;
}
String testPage = meta.getPage(0);
this is my favorite part
I got it working
does it start at 1?
How can I make setFireTicks infinite? what value?
useless check
because sometimes 0 is one
because even if it's empty it still has the 1st page
because someone wanted to confuse ppl
yea i know but somethimes in programming the first index is 0
yea
broke something?
;_;
well that's a minecraft thing
Gotta throw an exception with a 'This is literally impossible how'
you checked if it was the 0th page then opened the 0th page
I have one of those mike
if I ever see it, I'll know something went severely wrong
BookMeta should be burned at the stake
y2k21 or something
sorry for giving wrong code
huh I wonder where my impossible check is
I write some funny stuff sometimes
aw I think I got rid of it
hm?
I want to make it so that when a person puts an axe in a smithing table, and a blaze powder in a smithing table, it makes the result an axe that has all the enchants of the axe that the player put in the smithing table, but also with fire aspect x. how do i do this?
If there is a PrepareItemSmith event or similar you can use that to copy the input item and add fire aspect
And then just register a simple smithing recipe so the event is triggered
oh ok, ill try that
If there isn’t an event for that you will have to use the inventory click event to determine when they put the two items in and manually set the output
There is one
baka 😳
Welcome to cancer:
public net.md_5.bungee.api.ChatColor getColour(String clan) {
java.awt.Color colour = new java.awt.Color(DyeColor.valueOf(clanData.getString("clan." + clan + ".colour")).getColor().asRGB());
return net.md_5.bungee.api.ChatColor.of(colour);
}
...
format = getColour(clan) + clan + ChatColor.DARK_GRAY + format;
DyeColor.getColor() returns a org.bukkit.Color
Is it possible to import all the things you need to make a plugin without actually making the plugin jar file like importing org.bukkit.plugin.java.JavaPlugin ?
I am asking because it will save me alot of time
?? you wanna make a plugin without making the plugin jar file?
Yes. Like you pretty much need to import the jar file including like the module
unless I am mistaken.
@limber dust
i am so confused on what you mean
I want to make a plugin without putting it in a jar file
I am sort of new to this and i think it would be faster. I am not making it public.
wait, so code the plugin, but not compile it and run it on a server?
no
not possible what so ever
if thats what you mean
So you cant do import org.bukkit.plugin.java.JavaPlugin outside of a plugin jar file
Plugins are regular class files
So I can make a plugin without making it public?
The JVM loads the code from .jar and recompiles it to program 0 1
Do you want a private plugin for your server?
Yes
If so just don’t release the jar to anyone
Ok thanks
then just don't send the jar to anyone or post to spigot
any software recommendations to make it?
I still don't quite understand what was going on here xD
i didn't understand the first part either
Coming from using primarily eclipse, i woudl recommend use IntelliJ
eclipse is pretty outdated and intelliJ offers a bit more
don't let choco hear ya
im immune to dogman
yes, the dogs own the human
Why doesn't the RIGHT_CLICK_AIR Action fire when a user isn't holding anything? is there a way to get around this
because they arent interacting
they have to hold something
darn
it works for LEFT_CLICK_AIR tho
and is there a way to get around this? another event fired?
can we get some context
what do you need it for exactly
might be some work arounds
I'm doing this little affect where when they right click it throws a projectile
Using this currently ```java
if(event.getAction() == Action.LEFT_CLICK_AIR) {
Player sender = event.getPlayer();
if(arrowPowerManager.getActive(sender.getUniqueId())) {
sender.launchProjectile(Arrow.class, sender.getLocation().getDirection().multiply(2)).setFireTicks(Integer.MAX_VALUE);
}
}
that works, but you will need packets for empty right hand click
Any good docs/reading for this?
Iirc it fires as cancelled by default
But that may have changed due to mojang changes
it makes sense that an empty right click wouldn't be sent to the server
so are there good docs for packets
i dont know if protocollib actually has the packet
ItemStack itemstack = this.player.inventory.getItemInHand(); boolean flag = worldserver.weirdIsOpCache = worldserver.dimension != 0 || this.minecraftServer.serverConfigurationManager.isOp(this.player.name); // CraftBukkit if (packet15place.face == 255) { if (itemstack == null) { // <----- return; } // CraftBukkit start int itemstackAmount = itemstack.count; PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack); if (event.useItemInHand() != Event.Result.DENY) { this.player.itemInWorldManager.useItem(this.player, this.player.world, itemstack); }
old bukkit forums craftbukkit code
horribly formatted
If it doesn’t trigger the event it probably doesn’t even send a packet
But you can try
MY EYES but thanks
I'll live with left click
another question: what's the best velocity vector for a completely straight path?
Like a fireball path, it doesn't fall
kinda unnecessary
wdym
oh you mean completely straight
You can set no gravity on any entity
Player#launchProjectile(Fireball.class);
I want to apply this affect to an arrow
how would I even apply that
Call the method
I can't affect the entity with Player.launchProjectile
Sure you can
It returns the projectile
badbrain
i should probably try things before asking you guys because I end up answering it myself sometimes
Arrow arrow = (Arrow) player.launchProjectile(Arrow.class);
arrow.setGravity(0);
no you cant
Sounds like a way for people to make code even harder to read
(Arrow) is redundant
isn't that the fun part
is it?
It returns a generic
anyone wanan see a super ugly method that needs refactoring
so it isnt redundant
You don’t even need it as an arrow since the method is from entity
if you wanted arrow class methods
its returns Arrow
Indeed
it returns the class you put in
i get it
ugly
🥵
😳
finna make me act up
😳
horny police
Can I get uh
A few more pixels
millennial memes
no
gif game too strong
gifs are a very millennial thing
walk it like i talk it ima big steppah
you like this?
this does bring a smile to my face
HAHAHA funny
ok now show the rest of him 😐 do it 😩
is it possible to Class#cast(x) with type erasure without needing a reference to Class<T>
Ernest Khalimov
if(field.getAnnotation(Serializer.class) != null) {
VariableSerializer<T> serializer = ((VariableSerializer<T>)field.getAnnotation(Serializer.class).value().getDeclaredConstructor().newInstance());
value = (T) serializer.serialize((T) field.get(data));
}```
I have this abomination
that i needa fix
(the inscription means nothing)
How do you make a event that detects when a player moves and get the players new position?
PlayerMoveEvent
PlayerMoveEvent
PlayerMoveEvent
getPlayer().getLocation()
Can you send me the docs for player please
@EventHandler
public void onMove(PlayerMoveEvent event) {
Location to = event.getTo();
}
Location to = event.getTo(); Is the position of the player?
this is a more safer method
https://pastebin.com/pygQbVP0 i got an error, and idk how to fix
@EventHandler(priority = EventPriority.HIGHEST)
public void onMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
player.teleport(new Location(player.getWorld(), 0, 50, 0));
Location to = event.getTo();
Location yourLocation = player.getLocation();
}
these locations will be different (I think)
send a screenshot with line numbering
ok
It is confusing Location inLocation to = event.getTo(); for a module that I need to import
What varible type is it?
Like is it an int
if (!meta.hasLore()) {
//meta no has lore
}
yeah but the thing is
line 59 is on a whole other event
and that event is EntityDamageByEntityEvent
and also why would that kind of an event cause a problem with the smithing table event?
see if there will be a bug in the code now
ok
Hey, are you available?
whos you
Full code: ```
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@EventHandler
public void onMove(PlayerMoveEvent event) {
Location to = event.getTo();
}
}
``` The system thinks location in Location to = event.getTo(); is a module I did not import yet
What type of varible is it
Like why am I getting that error
um
just import it then
Its not a module inside bukkit
what IDE you are using
eclipes
import org.bukkit.Location;
replenishing this by hand is tragic
'to' inside Location to = event.getTo(); is invalid
yellow notifications are information about unnecessary code or bad practice. (you haven't used this variable yet, if you use it this notification will disappear)
yellow notifications are not errors, but warnings that something can be done better, but not required
Hopefully, the last question for the day. Location is not a varible so I cant log the players location
@topaz atlas
Learn to program in java. (Basics of Object Oriented Programming)
OOPs 
English is not my mother tongue but I think this course may be good
https://www.guru99.com/java-oops-concept.html
Learn concept of Object Oriented Programming(OOP) in java with example. Know about Abstraction, Encapsulation, Inheritance, Polymorphism in this tutorial.
@topaz atlas
language?
ye
you've never heard someone say that before? lmao
wow
Name of automatic module 'craftbukkit' is unstable, it is derived from the module's file name.
Am I using the wrong jar
are you using maven?
What are you doing with modules?
I am using craftbukkit-1.16.5.jar
Code: ```package me.SpiderUnderUrBed.chunkRenderSys;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@EventHandler
public void onMove(PlayerMoveEvent event) {
@SuppressWarnings("unused")
Location to = event.getTo();
System.out.println(to);
}
}
hey guys, this may be a stupid absolutely moronic question, but i'm reading the whitelist.json file in my server, what is the proper name of the player object? Just player?
md_5?
Player
thanks!
md5 is deprecated
or you could use OfflinePlayer depending on your usecase
how did you import it
I click add external jars then added it
is it a warn or an error
warn
I guess it does not matter then
I get errors for thismain: me.SpiderUnderUrBed.chunkRenderSys.Main name: customChunkRenderSys version: '1.0' author: SpiderUnderUrBed
Missing property "api".
on launch?
Yep
try and add
api-version: 1.16
your ide shouldnt give you errors on your plugin.yml though
Ok. Im new to eclipes where is the compile button?
Jar file or runnable jar file
jar file
Hey, I'm trying to read data from my first config file, but struggling to understand how. Here's an example of my config.yml Mode: STRING I want to be able to identify what String is next to Mode: I tried final boolean methodString = plugin.getConfig().getBoolean("Mode.STRING", true); which doesn't seem correct.
Mode:
STRING: true
I get this error:```[05:52:24] [Server thread/ERROR]: Could not load 'plugins/chunkRenderSys.jar' in folder 'plugins'
2021-03-29T05:52:24.882962+00:00 app[worker.1]:
2021-03-29T05:52:24.884933+00:00 app[worker.1]: org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: me/SpiderUnderUrBed/chunkRenderSys/Main has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions up to 52.0
2021-03-29T05:52:24.884935+00:00 app[worker.1]: at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:137) ~[server.jar:2991-Bukkit-f3f3094]
2021-03-29T05:52:24.884935+00:00 app[worker.1]: at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:393) ~[server.jar:2991-Bukkit-f3f3094]
2021-03-29T05:52:24.884935+00:00 app[worker.1]: at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:301) ~[server.jar:2991-Bukkit-f3f3094]
2021-03-29T05:52:24.884936+00:00 app[worker.1]: at org.bukkit.craftbukkit.v1_16_R3.CraftServer.loadPlugins(CraftServer.java:381) ~[server.jar:2991-Bukkit-f3f3094]
2021-03-29T05:52:24.884936+00:00 app[worker.1]: at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:179) ~[server.jar:2991-Bukkit-f3f3094]
2021-03-29T05:52:24.884937+00:00 app[worker.1]: at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:787) ~[server.jar:2991-Bukkit-f3f3094]
Thanks
your JDK is old
your JVM* (I think)
59 is Java 15
so I need java 10?
is there any effective difference between
(T) obj vs clazz.cast(obj)
This is my config.yml Mode: STRING: true CHARS: false INTS: false and this is one of my variables, which keeps causing the plugin to fail to start. What am I doing wrong? private boolean methodString = plugin.getConfig().getBoolean("Mode.STRING", true);
is there an error log?
❤️
Sorry I assumed my variable had something obvious wrong with it, which is why I didn't include error
can we see line 15 of the Commands file
de.joeakeem.spigotmc.plugin.template.commands.Commands.<init>(Commands.java:15) ~[?:?]
it's a NPE, so something is null
This actually is line 15 private boolean methodString = plugin.getConfig().getBoolean("Mode.STRING", true);
ah
so that's outside of a constructor
plugin probs null
^
or method lol
plugin is null 
plugin == null (reply to Monzter -. -)
so plugin is null cause it's being called before the constructor
because it's outside of it
Ohh ok, thanks
I cant find a download for JavaSE-8
And I need that for my plugin
eclipes does not have JavaSE-8 by default
or maybe its my computor
is there a way to get if the player is crouching
if (player.isSneaking())
Player#isSneaking
thanks
Event fired when player switches their mainhand to a different inventory slot?
nvmd
when does MapRenderer.render triggers?
Can i have accurate details about its trigger time.
And yeah, i know it is "when a map renders", but the question is "what are the conditions for it to render, what is the time interval between each render if the conditions are met, for how long does it keep rendering"
System.out.println(to); Does not log the string to the console
why is there no deathcause.,...
Here is the rest of the code
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@EventHandler
public void onMove(PlayerMoveEvent event) {
@SuppressWarnings("unused")
Location to = event.getTo();
System.out.println(to);
}
}```
I need to log the players position
please help.
Hello!
how can i get the name of an npc?
Define "log"
Do you only want it to appear in console?
(And remove the @SuppressWarnings("unused") annotation!)
java.lang.ClassCastException: Could not cast 0 to int
So besides @SuppressWarnings("unused") what else do i have to do?
Just create a new String which contains the worldname x, y and z
You can get all that from the location object
That class is extending JavaPlugin, you need to implements Listener to use EventHandler.
Show some code pls
well it's a misleading error first of all lol
public static <T> T cast(Object obj, Class<T> clazz) {
if (clazz.isAssignableFrom(obj.getClass()))
return clazz.cast(obj);
if (clazz.equals(UUID.class)) {
return clazz.cast(UUID.fromString((String) obj));
} else if (clazz.isArray()) {
if (obj instanceof Collection) {
Collection<?> col = (Collection<?>) obj;
return clazz.cast(col.toArray(new Object[0]));
}
}
throw new ClassCastException("Could not cast " + obj + " to " + clazz);
}
I have a manual casting method
How do I import it like what is the path
import <path>
https://www.spigotmc.org/wiki/spigot-plugin-development/
Take a look at this
any ideas smile?
looks like you are casting an incompatible wrapper class to a primitive.
One example for this being:
Long a = new Long(10);
int b = (int) a;
This wont compile
Take your time and learn java. There is nothing you can just do "quickly" without at least learning the very basics.
With citizens or your own npc implementation?
I understand some parts. I need to know the path to import the module
Becuse I need the event listiner
What IDE are you using? finding import path wouldn't be an issue at all.
eclipes
i.e. to obtain the name of an npc without the need of its api
Get the entity then get its name
This
@lost matrix fixed it by adding
else if (clazz.isPrimitive() && obj instanceof Number) {
Number n = (Number) obj;
return (T) n;
}
with entityType.getName();
@summer scroll Whats the path to import the event listiner?
Nvm i think a just found it
@lost matrix
getName should return its name no?
Not quite how casting works. This would still be a problem when casting a Long to an int.
But it will at least give you a better exception.
ya
Show the code pls
I'm running into another one now
java.lang.ClassCastException: Cannot cast java.lang.Integer to int
What’s up 😮
The ceiling
LOL apparently this works
Number n = (Number) obj;
if (clazz.equals(int.class))
return (T) ((Integer) n.intValue());
First thing i would do is change ClassCastException("Could not cast " + obj + " to " + clazz); to ClassCastException("Could not cast " + obj.getClass() + " to " + clazz);
did that ty
MSWS what r u trying todo
im going insane
dont worry i am too
return clazz.cast((Integer) n.intValue());
return (T) ((Integer) n.intValue());
what is the diff between those two lines
clazz is int
I don't have it right now, I just came to ask what method it was.
You cannot use the primitive classes and invoke #cast afaik
@hasty lynx Entity#getName
Since it uses generics so it would auto box wouldn’t it
@candid galleon ok not its entityType.getName();
if you have an entityType just use Enum#toString
Either case both would autobox
i'm not familiar with Class#cast so idk
only one of those lines works @ivory sleet
which is just bizarre to me
Still haven’t told me what you wanna do
public static <T> T cast(Object obj, Class<T> clazz) {
if (clazz.isAssignableFrom(obj.getClass()))
return clazz.cast(obj);
if (clazz.equals(UUID.class)) {
return clazz.cast(UUID.fromString((String) obj));
} else if (clazz.isArray()) {
if (obj instanceof Collection) {
Collection<?> col = (Collection<?>) obj;
return clazz.cast(col.toArray(new Object[0]));
}
} else if (clazz.isPrimitive() && obj instanceof Number) {
Number n = (Number) obj;
if (clazz.equals(int.class))
// return clazz.cast((Integer) n.intValue());
return (T) ((Integer) n.intValue());
}
throw new ClassCastException("Could not cast " + obj.getClass() + " to " + clazz);
}
I'm trying to have a "simple" method to cast a object to another
a serialized object*
int to Integer
Integer#valueOf(int)
Integer to int
Number#intValue()
Well primitives are a bit special
yes exactly
hence all the extra if statements and headaches
effectively...
what the code is doing is casting an Integer to an int
but it somehow works by getting the int value, casting it to an Integer, then casting it back to an int
Well you’re not really casting it but rather auto boxing and unboxing it
yeah that
i can't return the primitive itself because of the generic restriction
so I guess it somehow technically works?
Hmm yeah
Number n = (Number) obj;
if (clazz.equals(int.class))
return (T) n;
that also works
less casting lol
Uh well I guess
!Primitives.isWrapperType() is also a thing
Maybe not what you want but the Primitives class can be handy fyi (:
This is what i came up with
private static final Map<Class<?>, Class<? extends Number>> PRIMITIVE_WRAPPER = new HashMap<>() {{
this.put(int.class, Integer.class);
this.put(long.class, Long.class);
... and so on
}};
private static Optional<Class<? extends Number>> getWrapperOf(Class<?> primitiveClass) {
return Optional.ofNullable(PRIMITIVE_WRAPPER.get(primitiveClass));
}
private static <T extends Number> T wrapPrimitive(Object obj) throws ReflectiveOperationException {
Class<?> primitiveClass = obj.getClass();
Optional<Class<? extends Number>> wrapperOptional = getWrapperOf(primitiveClass);
if (wrapperOptional.isEmpty()) {
throw new RuntimeException("Not implemented: " + primitiveClass);
}
Class<? extends Number> wrapperClass = wrapperOptional.get();
Constructor<? extends Number> constructor = wrapperClass.getConstructor(primitiveClass);
return (T) constructor.newInstance(obj);
}
yeah that's better than a bunch of elseifs i spose
what's the diff between that and Class#isPrimitive
oh i see
You dont get incompatible casts
that returns true for Integer, isPrimitive is for int
god you gotta love generics
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
if anyone wants to critique that class hmu
(i'm also completely open to astonishment and "wow that's super cool") 😉
Serialisation depth of one...
Also: Single char variables. Please name them more meaningful.
like for (Field f : getFields(obj.getClass())) { ?
Yeah
For serialisation you would normally use some sort of registry for complex type resolver.
Example: you cant serialise a class that contains another complex object.
ah gotcha
i'd use recursion for that right?
im not actually gonna but theoretically
how can i use placeholderapi in an animated tablist that runs (kinda) on onEnable?
10:31:14 [SEVERE] java.sql.SQLException: Operation not allowed after ResultSet closed
Why do I get this error?
private static EMCServer getDataBaseServer()
{
ResultSet rs = MySqlConnection.executeQuery("SELECT * FROM Server");
if(rs == null)
return null;
Map<String, EMCServer> servers = new HashMap<>();
try
{
while(rs.next())
servers.put(rs.getString(1), JSONConverter.convertServer(rs.getString(2)));
if(servers.size() == 1)
return servers.get("server");
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
return null;
}
because the Operation isn't allowed after you close it
But I am doing exactly what they want: Mapping the results and then look if it contains the correct one
no idea, you might be closing a connection somewhere
I am closing the connection only in onDisable
This is (a part of) the MySqlConnection class
public static ResultSet executeQuery(String SQL)
{
if(statement == null)
{
try
{
throw new Exception("First call the connect method!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
try
{
return statement.executeQuery(SQL);
}
catch(SQLException ex)
{
ex.printStackTrace();
return null;
}
}```
you can also check if connection is closed then reopen
at the start of the method
Ok I can try
if(!isConnected()){
connect();
}
//code
``` basic example
Ok thanks
That's unfortunately not the solution I keep getting the error
The solution: Use PreparedStatement, not Statement
Why this error? I had never problems with MOTDS
10:49:30 [WARNING] Event ProxyPingEvent(connection=[/31.201.249.78:56725] <-> InitialHandler, response=ServerPing(version=ServerPing.Protocol(name=BungeeCord 1.8.x-1.16.x, protocol=754), players=ServerPing.Players(max=5, online=0, sample=null), description= Welkom bij EindjeMinecraft!
7 bij 7 km van Eindhoven in Minecraft!, modinfo=ServerPing.ModInfo(type=FML, modList=[]))) took 328ms to process!
Oh now it dissapeared
what's the different between 'MinecraftServer#TPS' and 'MinecraftServer#getServer()#.recentTPS[0]'
MinecraftServer#TPS is just a constant. Its just 20.
always 20?
Holy... what is this:
if(statement == null)
{
try
{
throw new Exception("First call the connect method!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
MinecraftServer.getServer().recentTps[0]
I know I have created an custom class
MinecraftServer.getServer().recentTps[0] is pretty much the same as MinecraftServer#recentTps
But MinecraftServer#TPS is just a constant
if(statement == null) {
throw new IllegalStateException("No connection established");
}
Yes. Its a field in MinecraftServer.class
getServer is just an instance
Oh i misread that. Thought you were referring to another method.
You need to periodically check the placeholder and re-send the tablist
Hello, how do I make it, that on a certain command it creates a player(from an argument) in config for it to store a number?
Use the FileConfiguration API and just add a new section with the UUID or Name as key and a number as value.
So /command argument(playername)
it takes the argument and creates it in the config like this
playername: 1
Do we understand each other?
it always adds 1 on each command in the config
Yes, you can do that.
I know, but I dont know how XD
What part that you don't know?
dont know how to make it like that, I created a class for the command, but I dont know how to CREATE the playername in the config and then add 1 as a number next to it.
So you're already know how to create the command?
Yea, I am just not good with configs yet
Ah okay, are you planning to use the default config? which is the config.yml
yes
Okay you can just get the FileConfiguration with getConfig() method from the MainClass instance.
already have that
getConfig().options().copyDefaults();
saveDefaultConfig();
currently im not in the main class
Pass the config to the command class.
the same way?
You can use method FileConfiguration#set() to set a value in the config.
Use dependency injection.
Ooooh, but I first need it to create the player in the
ookk....
Where can I implement it?
Use that method on the Command.
Example
onCommand(){
//code
}
So, for example, your config will look like this I guess.
data:
player1: 1
player2: 2
yes
And then on command.
onCommand(){
Player player = Bukkit.getPlayer(args[0]);
config.set("path", value);
saveConfig();
}
OOOOOOOOH
But first, check If the path is null or not, If the path isn't null, get the value and then increment it.
My dumb-ass was putting player.setConfig() uh nevermind
Huh?
if(config.getInt("path") == null){
config.set("path", 1);
} else {
config.set("path", config.getInt("path") + 1);
}
You want to increase it every command right?
Keep in mind, you need to save the config everytime you set it, otherwise the config won't change.
Ok
This only works in main clas
same goes for the first one
Pass your main class instance then, so you can save the config on other class.
Constructor?
Yes, something like that.
private final MainClass plugin;
public OtherClass(MainClass plugin){
this.plugin = plugin;
}
Yea I forgot to create plugin and getting confused, thx
and I need to do that for every class that uses config?
You use that If you need to do something that requires MainClass to work I guess.
Like, you can't save the config without passing the main class.
yea because saveDefaultConfig()
Use saveConfig();, you just called that on onEnable I think.
Whats the difference between these two?
public void saveConfig() {
try {
this.getConfig().save(this.configFile);
} catch (IOException var2) {
this.logger.log(Level.SEVERE, "Could not save config to " + this.configFile, var2);
}
}
public void saveDefaultConfig() {
if (!this.configFile.exists()) {
this.saveResource("config.yml", false);
}
}
So defaultConfig cant be changed
save default should only be done on the server start or whenever you wanna create it, not used for saving
I see
However, whats with the OtherClass?
it's the "create file" method
you change that to you commands class name
he just used OtherClass as a example
Yea I did that but it seems weird
it's a constructor
it's so you can pass a instance of your main class into your commands class
to use plugin methods like saveConfig
Ok then
eg my commands constructor
public lpsCommand(LevelPoints lps, String command){
lps.getCommand(command).setExecutor(this);
lps.getCommand(command).setTabCompleter(new lpsTabComplete());
}
``` i use it for setting the executer and tabcompleter
in your case you need it for main class instance
I still have a long way I see
wtf
why does config still get unidentified?
in the OtherClass?
Show your code maybe?
this is mapsdone class
package astreansbuildsystem.astreansbuildsystem.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class mapsdone implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player p = Bukkit.getPlayer(args[0]);
if(p.hasPermission("astreans.mapsdone")){
config
}
return true;
}
}
this is the main class
package astreansbuildsystem.astreansbuildsystem;
import astreansbuildsystem.astreansbuildsystem.commands.menu;
import org.bukkit.plugin.java.JavaPlugin;
public final class AstreansBuildSystem extends JavaPlugin {
private final AstreansBuildSystem plugin;
public mapsdone(AstreansBuildSystem plugin){
this.plugin = plugin;
}
@Override
public void onEnable() {
// Plugin startup logic
getCommand("menu").setExecutor(new menu());
getConfig().options().copyDefaults();
saveConfig();
}
}
You need to do the dependency injection on your command class.
And next time use this.
Whats that?
k
private final AstreansBuildSystem plugin;
public mapsdone(AstreansBuildSystem plugin){
this.plugin = plugin;
}
``` this one.
Yes, its inside the main class, do I need to do something like this in mapsdone?
well you said no changes visible so what are you referring to?
config not getting detected
And now you can get it by plugin.getConfig().
ooooh
Jesus I look stupid, thanks guys
Oh yeah, because plugin refers to the mainclass
Yup, now you can use all method in the main class basically.
what is path considered? data: ?
no :
if your entry in your yml is "data:" your path is "data"
if its yaml data: info: - test - testThen your path would be "data.info"
Ok, ty
You might want to do "data." + player.getName() for the path.
and if the playername isnt there will it automatically create it?
no, if its not there it will return null
If you use config.set() yes, it will create the path.
but config.set() doesnt work
you have to check if it exists first
yeah, i showed you above.
if you make a change to the config you have to save it.
I have problems with messaging: Bungee does not receive messages
BungeeListener: https://paste.md-5.net/lofedafuxe.java, Spigot message sender: https://paste.md-5.net/anokocejew.java
Registering (The listeners are registered in the classes above):
Spigot:
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "emc:channel");
Bungee:
ProxyServer.getInstance().registerChannel("emc:channel");
show code
if i used packetevents by retrooper how would i get when a player moves?
actually gtg sleep now :(
Okay so, I have a "resources/config.yml" (same path as bungee.yml) and I would like to paste it to my BungeeCord configuration file. How would I do this?
How to create this in reflection?
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer)```
My point here is how to get this enum by reflection
@naive knoll You can grab all the enums using <class>.getEnumConstants()
ok but what can i get ADD_PLAYER enum?
You can get all declared sub classes via reflection. Then you call the enum constant getter from that.
Siemka @naive knoll
witam
but how can I do it?
@naive knoll w fg jest trochę refleksji może coś byś tam znalazł i się powzorował
i nawet ta sama klasa
dobry pomysł ogółem
hah
XD
say if I wanted to get the number of zombies killed by a player on a command, if I try and use:
int zombieKills = player.getStatistic(Statistic.MOB_KILLS, EntityType.ZOMBIE);
the MOB_KILLS enum can't specify an entity type, is there any other way to do this... or am I just going to have to make a database for this and update values on a mob kill?
em
Example:
@SneakyThrows
@Override
public void onEnable() {
System.out.println(this.getEnumFrom("net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo$EnumPlayerInfoAction", "ADD_PLAYER"));
}
public Object getEnumFrom(final String className, final String enumName) throws ClassNotFoundException {
final Class<?> enumClass = Class.forName(className);
final Object[] values = enumClass.getEnumConstants();
for (final Object object : values) {
if (object.toString().equals(enumName)) {
return object;
}
}
return null;
}
um
int zombieKills = player.getStatistic(Statistic.KILL_ENTITY, EntityType.ZOMBIE); check this
ohhh
if it doesn't work then there is probably no such data
because it is saved
so in this case you will have to log the number of killed zombies yourself
you can clearly see that the entity kills are logged
its just accessing it
one second I am compiling and deploying to a test server
generally getStatistic a lot of bugs :/
probably just better to save this all to a database then and have it updated upon a mob killed
and it means I know how to work with it then 😉
yes
thanks
its an incorrect number saved hahaha
nope it works fine, I just obviously reset the statistics on the server
¯_(ツ)_/¯
thanks @sick ravine
how to get material by name i mean creating new material by string STONE
Material.valueOf(String)
Thats a thing for all enums
thx
https://gyazo.com/c9ef359f6b57053593a4383d6f4550de
how can i make this effect in the inv slot?...
guys i have a problem..., i dont know why the funtion is not working anybody can help me?
@EventHandler
public void onSpawn(CreatureSpawnEvent e) {
LivingEntity entity = e.getEntity();
if (!MobUtil.isStackable(entity))
return;
if (e.getEntityType().equals(EntityType.PIG_ZOMBIE)) {
if (entity.getCustomName() == "Gegner") {
Bukkit.broadcastMessage("1§e-----§7§l" + entity.getCustomName());
return;
} else {
MobUtil.tryToStack(entity);
Bukkit.broadcastMessage("2§e-----§7§l" + entity.getCustomName());
}
return;
}
MobUtil.tryToStack(entity);
}
no error is coming
if (entity.getCustomName() == "Gegner") { <-- i Fink this is not working :/
.equals
i try now if (e.getEntityType() == EntityType.PIG_ZOMBIE) {
That should work
No not working
but yes to the entitytype...
if i ask the entitycostumname i gotn null back :/
?jd
package index
Means it has no custom name
What conclue said
yeah i give them..
What that means is that it is running the else clause most likely
Has it occurred that it may be running when other entities are spawning
Other than the one that you have spawned
@empty oyster
are you in the overworld?
sure
ok, so that rules that out
hmm, what about it you cast the entity to a PigZombie
im not sure at this point
No, I only spawn one
then the other one..
can i check how spawn (region) the piglen?
who*
if (e.getEntityType().equals(EntityType.PIG_ZOMBIE)) {
PigZombie piglin = (PigZombie) entity;
if (piglin.getCustomName() == "Gegner") {
//etc etc ....
}
}
.equals for strings
now i will try
ok
I finally got formatting right for my start message
https://paste.lucyy.me/qozayejixu
Lucy's Pretty Pastebin
ughhh, you are one of those developers...
one line needs fixing but it looks good so far
what'd i do man
i kinda hate it when my console gets spammed with huge graphics as plugins load
ok, thats fine then, just i got one which was like a whole monitor once
dude wtf a whole monitor???
@opal juniper no notworking
yeah, it was terrible
Sounds ew
@EventHandler
public void onSpawn(CreatureSpawnEvent e) {
LivingEntity entity = e.getEntity();
if (!MobUtil.isStackable(entity))
return;
if (e.getEntityType() == EntityType.PIG_ZOMBIE) {
PigZombie piglin = (PigZombie) entity;
if (piglin.getCustomName() == "Gegner") {
Bukkit.broadcastMessage("1§e-----§7§l" + entity.getCustomName());
return;
} else {
MobUtil.tryToStack(entity);
Bukkit.broadcastMessage("2§e-----§7§l" + entity.getCustomName());
}
}
MobUtil.tryToStack(entity);
Bukkit.broadcastMessage("3§e-----§7§l" + entity.getCustomName());
}
it was because the version was one behind, so it freaked out
I only do custom shit on my plugins B) If I'm making one for somebody i'll just put "Enabled"
or somethin
can you make these java code blocks in future
yea, makes sense
I mean there is a default message
How ? =D, with || or ** ?
no, so you would do:
```java
yeah but I can put a little note in there for the person I'm making it for
ahh okey.
Why lol
thx i updated..
use .equals() instead of ==
so:
if (piglin.getCustomName().equals("Gegner")) {
and, what gets broadcasted
😄
at de.daniellainand.listener.MobStackEvents.onSpawn(MobStackEvents.java:36) ~[?:?]
------------------------------------------------------
36=: if (piglin.getCustomName().equals("Gegner")) {
npe as it has no custom name
yeah, probs a null error
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
there is something wrong with how you set the custom name
i come in 2min, i go smoke a ziggrat...
smh
Guys does anyone know why the spigot placeholder %%__USER__%% remains the same also after downloading the plugin?
coding in a nutshell
tell me if this is relatable or not
Me: learns new language.
Gets bored cause I can't code in that language
Also Me: returns to old comfy language
lol
im back
🚬
we get it, you smoke
way to go
how old are you ? 😮
69
420
bruh
wait, misclick
I wish to be as wise as you ancient
😎
can i have your method for spawning the mob
sure
You need to actually parse and replace it. PlaceholderAPI doesnt automatically check every String in the JVM heap...
public static void spawnEnemy(Player p) {
Location l = CommandTank.loc;
l.setY(CommandTank.loc.getY() + 0.5);
PigZombie pigz = CommandTank.loc.getWorld().spawn(CommandTank.loc, PigZombie.class);
pigz.setAngry(true);
pigz.setCustomName("Gegner");
pigz.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, Integer.MAX_VALUE, 2)); // (PotionEffectType.INCREASE_DAMAGE);
pigz.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); // pigz.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
pigz.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 10)); // pigz.hasPotionEffect(PotionEffectType.INVISIBILITY);
pigz.setTarget(p);
ItemStack is = new ItemStack(Material.DIAMOND_AXE);
is.addUnsafeEnchantment(Enchantment.DURABILITY, 3);
is.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 8);
pigz.getEquipment().setItemInHand(is);
}
what?
And your problem is?
he is trying to detect the custom name
i mean this placeholders https://www.spigotmc.org/wiki/premium-resource-placeholders-identifiers/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
however it is not working
the wiki says "Will get transformed and the various variables will be changed to the appropriate values."
@EventHandler
public void onSpawn(CreatureSpawnEvent e) {
LivingEntity entity = e.getEntity();
if (!MobUtil.isStackable(entity))
return;
if (e.getEntityType() == EntityType.PIG_ZOMBIE) {
PigZombie piglin = (PigZombie) entity;
if (piglin.getCustomName() == "Gegner") {
Bukkit.broadcastMessage("1§e-----§7§l" + entity.getCustomName());
return;
} else {
MobUtil.tryToStack(entity);
Bukkit.broadcastMessage("2§e-----§7§l" + entity.getCustomName());
}
}
MobUtil.tryToStack(entity);
Bukkit.broadcastMessage("3§e-----§7§l" + entity.getCustomName());
}
@lost matrix
Oh i see. Pls show what you have tried so far.
The problem here is that the String is compared with ==
Which is always false.
yeah, i told him but i thought he said he changed it...
@EventHandler
public void onSpawn(CreatureSpawnEvent e) {
LivingEntity entity = e.getEntity();
if (!MobUtil.isStackable(entity))
return;
if (e.getEntityType() == EntityType.PIG_ZOMBIE) {
PigZombie piglin = (PigZombie) entity;
if (piglin.getCustomName().equals("Gegner")) {
Bukkit.broadcastMessage("1§e-----§7§l" + entity.getCustomName());
return;
} else {
MobUtil.tryToStack(entity);
Bukkit.broadcastMessage("2§e-----§7§l" + entity.getCustomName());
}
}
MobUtil.tryToStack(entity);
Bukkit.broadcastMessage("3§e-----§7§l" + entity.getCustomName());
}
At the time the event is fired, the custom name is not set.
PigZombie pigz = CommandTank.loc.getWorld().spawn(CommandTank.loc, PigZombie.class); // <- Event is fired right here
// Everything that follows is called after the event
pigz.setAngry(true);
ohh,yea
This is the fix @empty oyster
final PigZombie pigz = CommandTank.loc.getWorld().spawn(CommandTank.loc, PigZombie.class, preSpawnZombie -> {
preSpawnZombie.setCustomName("Gegner");
});
Are you on 1.8?
sure
🥶
arghhhhh
Then you are on your own. That version is half a decade old.
lol
just set a delay in the event handler
imagine not playing 1.8 tho
?
playing 1.8 is ok
but for pvp 1.8 is the besst......
hosting a server on 1.8 is not
yeah if you like that more you can just use plugins on 1.16
there are plugins that support 1.16 servers and then support the 1.8 clients
If you are an adhd kid who just cares for hammering on your left mouse button as fast as possible then problably.
you got me
yo, calm down lmao
performance issues say hello
you gotta figure out how to scale vertically :/
xDD
thats like saying windows 10 is impossible to scale vertically compared to windows xp
where did I say it's impossible?
not impossible but you get what i mean
@lost matrix hmmm maybe, but for potion pvp it is...
I'm saying it's an important task that needs to be done, while it wasn't that big of a deal in 1.8.
And that can be a really complex issue.
But for 90% of the server that care about performance it is not an issue.
Only a hand full of servers have to support hundreds of concurrent users
you get performance issues below 100 players as well on 1.16
The average server has way below 20 players on peak.
Hmm a server I was deving on reached over 100 with no problems using 1.16 paper
Why do people always pull out the "performance" card. It is much faster than you think.
in fact, 1.17 comes with many huge optimizations
so you should look forward to updating
do we know for certain that other changes won't degrade performance? no
to higher versions
And if everyone would stop using old versions the we could focus on improving the newer ones without worrying for compatability issues with older ones.
I guess it makes sense to wait before deciding whether vertical scaling is needed or not
this. Spigot devs have to deal with stupid kids trying to support legacy
if legacy was gone, imagine all the changes to the api
1.8 fanbase💩
whoever supports old versions is their own fault, I don't see why that should impact new versions
I wonder why my plugin is so expensive
people arent going to stop playing 1.8 because plugin devs want them to
i dont think they give af
7smile ich gebe dir ja recht nur das PotionPvP ist einfach das das noch sehr viele PotionSpieler haben wollen..
Exactly. So you guys shouldn't get help either
with development
cause we have moved on from that years ago
fair enough
What does that mean exactly? Potions can be stacked in 1.16 too.
I mean if the api is similar then why not pulse
Nooo this is not the reason, this is to much OP and the shield
it's really not for people who ask about "custom mobs" which are apparantly the common thing being asked in spigot these days
like ai
and nbt tags
pdc
Ye
Does someone know why my plugin is on the top of my timings report?
Its ok. I can see how some people prefer the 1.8 pvp.
its the InteractEvent but it doesn't have much checks
Show the timings
And then the code
It's MCFCore
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if (event.getClickedBlock() != null) {
if (event.getClickedBlock().getState() instanceof Container) {
Container container = (Container) event.getClickedBlock().getState();
StringBuilder inventoryString = new StringBuilder();
for (ItemStack item : container.getInventory().getContents()) {
if (isLargeItem(item) || isCrashItem(item)) {
item.setItemMeta(null);
}
inventoryString.append(itemToString(item));
}
if (inventoryString.length() >= 150000) {
event.setCancelled(true);
container.getInventory().clear();
}
}
}
if (isCrashItem(event.getItem()) || isDangerousEgg(event.getItem())) {
event.getItem().setItemMeta(null);
event.setCancelled(true);
}
if (event.getItem() != null) {
if (event.getItem().getType() == Material.TRIDENT) {
if (event.getItem().getEnchantmentLevel(Enchantment.RIPTIDE) > 10) {
event.getItem().addUnsafeEnchantment(Enchantment.RIPTIDE, 10);
}
}
}
}```
That's the InteractEvent
yes?
anything other than spigot is not supported here
Lol I mean what’s the issue serverfilter
do people even run bare spigot anymore?
Ye
but anyways worldedit is causing the issue
ye
a lot of people run spigot
Nice
paper has a bit more than spigot
I didn't think it was still used that much lol
Hello, I know how to set a game mode for a specific player. player.setGameMode(GameMode.ADVENTURE);But does anyone know how I could change the servers game mode instead of just changing a specific players game mode?
package index
?jd
Bukkit.setDefaultGameMode(GameMode.CREATIVE);
I think you can set the default gamemode on the server.properties
Thanks for the help
declaration: package: org.bukkit, interface: Server
https://server.properties is an actual domain lol
LMAO
lol
well, i think i know who hosts it...
Sadge
also is this correct
for (Map.Entry<Enchantment, Integer> ench : item.getEnchantments().entrySet()) {
Should be fine
Help, I am teleporting the player to the same location in two different occasions, one time is when he joins and another time is when he dies, but when he dies it teleports him a few blocks above, I debugged and saw it DOES teleport to the same X,Y,Z but it still teleports to different Y for some reason.
method?
player.teleport
the whole thing
You need to teleport on the respawn event
I did event.setRespawnLocation
Or simply set the spawn location in that event
and I also teleported in another place
to the same place
And in the messages I sent, it's the same location, but for some reason it teleports a few blocks above.
But when the player joins, it doesn't teleport a few blocks above
Yea, it teleports to above surface
So its just a safe teleportation.
Some kind of that, but it should be that, I am not trying to teleport the player inside a block or something...
If you say so
If I keep programming and learning everyday, how much time would it approximately take me, to master java?
If you are a prodigy i would say at least 3 years and then another 3 or 4 for JavaEE
you shouldn't know everything (and i mean everything) in the library thats unhealthy lol
by that point you should move to other languages
Being able to program any plugin I want
Oh that might take 3 months or smtng
wat 3 years xD
I know people who can
Like if you fully put in effort
that just takes time
like if you had a huge ass plugin you wanted to make or something hard
prolly will take you a couple months
But you will never stop learning. When i started writing code for a company during my studies, i thought i was fairly knowledged.
But boy was i wrong. There is so much more to programming than just knowing the language features (of which i also learned a lot more there)
I started working on a plugin, however my goals are beyong my understanding, I still cant use configs properly or know how to use worlds and autonatically create stuff etc.
For how long did you write Java by now?
it sounds like a lot now but i probs did take that long wit programming in general befor i could touch plugins xD
bout 1.5ish years java
but liek 15+ c++
15 or also 1.5
15
my mom for some god damn reason says C++ is similar to java and im like wot
I tried java 6 months ago, didnt understand shit, so I learned html css and a little js and linux and hacking, now im doing spigot for like 10 days
it kinda is lol i just jumped into java treating it like c++ and figuring out the differences as i went along xD
Yeah. No. Kind of. But actually no.
yeah exactly lol
C# tho
C# conventions 🥲
💩
c# same syntax fam