#helping keylesstravis

1 messages · Page 1 of 1 (latest)

strange imp
#

Ok this is too hard to track I'm making a new thread

exotic tendon
#

yeah good idea

small cape
#

Ok

exotic tendon
#

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

small cape
strange imp
#

That is what you should be using

exotic tendon
#

yeah

small cape
#

Huh

strange imp
#

Sorry it's just this.getCommand not getServer.getCommand

exotic tendon
#

they are

strange imp
#

I'm on phone so I can't test anything

exotic tendon
#

look at the paste they sent

small cape
#

It works so right?

exotic tendon
#

it should

#

make Egg lowercase

small cape
#

Maybe my plugin.yml

strange imp
#

Can you make the paste an actual link?

exotic tendon
#

otherwise it probably wont work

strange imp
#

Just post it by itself

exotic tendon
strange imp
#

He put now:link so I can't click it

exotic tendon
#

oh

small cape
#

version: 1.0 name: cheese main: com.travis.testing_or_server.Main author: e commands: egg: usage: /egg description: e Is my plugin.yml

exotic tendon
#

@small cape make the Egg in your Main.java into lowercase egg

#

its case-sensitive

#

wont work otherwise

small cape
#

ok

exotic tendon
#

also remove the Bukkit.getPluginManager().registerEvents(new TestCommand(), this);

#

wont work

#

unneccisary unless u have other events in there

#

but im assuming you dont

exotic tendon
#

wait send TestCommand rq

small cape
#

k

#

eclipse takes forever to launch

exotic tendon
#

why did u close it

small cape
#

?paster

#

?paste

exotic tendon
#

oh it doesnt wokr here

small cape
exotic tendon
#

nvm keep that line

#

but i strongly recommend seperating the event handler and the command

small cape
#

author: cheese

exotic tendon
#

very strongly

small cape
exotic tendon
#

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

strange imp
#

Make it in your main and get an instance in your other classes

#

That's the easiest way to make global vars

strange imp
exotic tendon
#

yeah

#

but it is the easiest way

small cape
#

Its giving me an error

safe lynx
#

?learnjava

#

Nice

#

thats not valid java

exotic tendon
#

bro

small cape
#

ok

strange imp
#

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

small cape
strange imp
#

You can make a method in main called getInstance and return a private instance of your main class

safe lynx
#

or just use dependency injection

exotic tendon
#

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`
*/
strange imp
#

Make a private MianClassName instance, set the instance to this onEnable and then call the getInstance method

safe lynx
#

private final

strange imp
#

Yeah

exotic tendon
#

._.

#

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

exotic tendon
#

apart from security

strange imp
#

It's mainly for security but in general it's just a bad practice and teaches programmers the wrong way

exotic tendon
#

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; }
}
exotic tendon
#

but it can be helpful

small cape
#

uhh nothing is getting put into console

exotic tendon
#

wdym

#

what isnt

small cape
strange imp
#

The onEnable sysout isn't being shown?

small cape
#

No heres the console for ex

strange imp
#

Then the plugin is not enabled

#

Do /pl

#

Is the plugin in the list and is it green?

small cape
#

Not there

exotic tendon
#

i gtg

small cape
#

gb

exotic tendon
strange imp
#

Ok give me the latest log

exotic tendon
#

or class is throwing runtime error

#

anyways cya

strange imp
#

There is an error somewhere

small cape
strange imp
small cape
exotic tendon
#

ty

strange imp
#

I need the whole log

#

Go to your server folder/logs and send me latest

small cape
#

Uh oh

#

Ok

#

...

#

Paste web almost crashed

strange imp
#

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

small cape
#

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

strange imp
#

Don't use underscores for the packagae name

#

It should be just lowercase letters/numbers

#

Is the plugin enabling now?

small cape
#

After a bit of reading typing and testing I kept getting this error in the console

strange imp
#

Send the command class and the main class

#

Your plugin instance is null

small cape
#

Should I use null check?

strange imp
#

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

small cape
small cape
#

I think I need a setter as well, or is that another word for a getter?

#

Geez I need to work on my java

strange imp
#

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

small cape
#

this.plugin.CantThrow().add(player); is the thing causing an error

small cape
#

I think the problem is something with this private ArrayList<Player> cantThrow = new ArrayList<>(); // make arraylist public ArrayList<Player> CantThrow() { return cantThrow; } // getter

strange imp
#

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

strange imp
#

If you want resources to learn Java do ?learnjava in the help channel

small cape
#

What happened

#

Paste bin link disappeared

#

Also does anyone know how to give a player something random

#

Like e.getPlayer().random().location()

strange imp
#

Make a list of the things you want to randomly select from and choose a random index in the list

strange imp
#

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

strange imp
#

no a List

#

ArrayList

small cape
#

How to I do that though?

#

Wait

#

I'll watch the vid first on java arrayLists

small cape
small cape
strange imp
#

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