#helping keylesstravis
1 messages · Page 1 of 1 (latest)
yeah good idea
Ok
you can also use
JavaPlugin.getCommand(String)
``` straight from your onEnable
probably safer
because if other plugins are registering a command with the same name it will be weird
So the main class is now:https://paste.md-5.net/cubagihaqo.java
declaration: package: org.bukkit.plugin.java, class: JavaPlugin
That is what you should be using
yeah
Huh
Sorry it's just this.getCommand not getServer.getCommand
they are
I'm on phone so I can't test anything
look at the paste they sent
It works so right?
Maybe my plugin.yml
Can you make the paste an actual link?
otherwise it probably wont work
Just post it by itself
what
He put now:link so I can't click it
oh
version: 1.0 name: cheese main: com.travis.testing_or_server.Main author: e commands: egg: usage: /egg description: e Is my plugin.yml
@small cape make the Egg in your Main.java into lowercase egg
its case-sensitive
wont work otherwise
ok
also remove the Bukkit.getPluginManager().registerEvents(new TestCommand(), this);
wont work
unneccisary unless u have other events in there
but im assuming you dont
What about the eventHandler
wait send TestCommand rq
why did u close it
oh it doesnt wokr here
nvm keep that line
but i strongly recommend seperating the event handler and the command
author: cheese
very strongly
How do I keep the array list tho
make it public static ArrayList<Player> cantthrow = new ArrayList<>();
in the event handler class
and then just reference it using <EventHandlerClass>.cantthrow
or just cantthrow inside the class
Make it in your main and get an instance in your other classes
That's the easiest way to make global vars
You should not be using static for global vars
Its giving me an error
bro
ok
Easiest almost never means best
Using static for everything is a very bad programming practice and people should be taught the correct way the fist time, not the easiest way
Use a constructor?
First
You can make a method in main called getInstance and return a private instance of your main class
or just use dependency injection
Main
private ArrayList<Player> cantThrow = new ArrayList<>(); // make arraylist
public ArrayList<Player> getCantThrow() { return cantThrow; } // getter
@Override
public void onEnable() {
// ... //
}
TestCommand
Main plugin;
public TestCommand(Main plugin) {
this.plugin = plugin;
}
/*
change all `cantthrow` to `plugin.cantThrow`
*/
TestHandler
Main plugin;
public TestHandler(Main plugin) {
this.plugin = plugin;
}
/*
change all `cantthrow` to `plugin.cantThrow`
*/
Make a private MianClassName instance, set the instance to this onEnable and then call the getInstance method
private final
Yeah
._.
its for performance reasons
and final ensures security
as using a getter method will provide the same level
but ur right
normally you should use a private and a getter
aight i fixed it
also why is static for global variables bad
apart from security
It's mainly for security but in general it's just a bad practice and teaches programmers the wrong way
also i would use another layer of classes like this
public class MyPlugin {
public final MyPluginState state = new MyPluginState();
}
public class MyPluginState {
private int a = 100;
public int a() { return a; }
public void a(int v) { this.a = v; }
}
yeah
but it can be helpful
uhh nothing is getting put into console
The onEnable sysout isn't being shown?
Not there
i gtg
gb
maybe issue with plugin.yml
Ok give me the latest log
There is an error somewhere
Here it is
Bye
gb and gn
ty
Your main class is wrong in the yml
Check and make sure the package and class name correct
It should be entire package name.mainclassname
Like this? version: 1.0 name: cheese main: com.travis.testing_or_server1.Main author: e commands: egg: usage: /egg description: e
It worked but the bukkit schuldar stopped it in its tracks
Bukkit.getScheduler().runTaskLater(main, new Runnable() { public void run() { cantthrow.remove(player); } }, 100L); seems innocent to me tho
Don't use underscores for the packagae name
It should be just lowercase letters/numbers
Is the plugin enabling now?
Should I use null check?
The error is telling you that this.plugin is null in TestCommand line 41
I gtg I'll be back in a couple of hours
I can't find why it would be null
I think I need a setter as well, or is that another word for a getter?
Geez I need to work on my java
Ok well like you just said you should really learn Java before you make plugins but send me the code and I'll look at it
this.plugin.CantThrow().add(player); is the thing causing an error
I just dont know how MUCH java
I think the problem is something with this private ArrayList<Player> cantThrow = new ArrayList<>(); // make arraylist public ArrayList<Player> CantThrow() { return cantThrow; } // getter
The problem is in the error, it has nothing to do with cantThrow. The thing that is null is this.plugin
I can't really tell you what's happening without the code
Which is exactly why I said you should learn basic Java before making plugins
If you want resources to learn Java do ?learnjava in the help channel
I have been learning java from pluralsight.com but that's it
What happened
Paste bin link disappeared
Also does anyone know how to give a player something random
Like e.getPlayer().random().location()
Make a list of the things you want to randomly select from and choose a random index in the list
Your plugin variable is never set to anything... you just created a null AntiPickupItems
You need to put that var in main and set it to this onEnable
Then use a getter to get the instance in your command class
Enum?
How do I do this again? And should I be able to just do plugin.GetCantPickUp().add((Player) sender); on the command?
I tried doing it with normal Java but Math.random works for int and double, maybe others just not PotionEffectType
You can't just use math.random for a spigot class...
Spigot has nothing to do with the java api/tools
Like I said get a random number and a list of all of the objects you want to randomly select from and then use the number as an index in the list
In the case of PotionEffectType you can use PotionEffectType#values and select use the random number as an index in the array
Also don't use math.random, use ThreadLocalRandom
You really need to actually learn Java before making anything, these are very simple Java concepts and don't really have anything to do with spigot
Your never going to get anywhere by asking for help with everything you need to learn it yourself and gain experience if you ever want to be good at this