Skip to content

Commit fd3002d

Browse files
committed
Update variable names and cleanup README
1 parent 6bc1381 commit fd3002d

File tree

1 file changed

+33
-58
lines changed

1 file changed

+33
-58
lines changed

README.md

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -71,80 +71,55 @@ import net.milkbowl.vault.chat.Chat;
7171
import net.milkbowl.vault.economy.Economy;
7272
import net.milkbowl.vault.economy.EconomyResponse;
7373
import net.milkbowl.vault.permission.Permission;
74-
7574
import org.bukkit.command.Command;
7675
import org.bukkit.command.CommandSender;
7776
import org.bukkit.entity.Player;
78-
import org.bukkit.plugin.RegisteredServiceProvider;
7977
import org.bukkit.plugin.java.JavaPlugin;
8078

8179
public class ExamplePlugin extends JavaPlugin {
82-
83-
private static Economy econ = null;
84-
private static Permission perms = null;
80+
private static Economy economy = null;
81+
private static Permission permission = null;
8582
private static Chat chat = null;
86-
87-
@Override
88-
public void onDisable() {
89-
getLogger().info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
90-
}
91-
83+
9284
@Override
93-
public void onEnable() {
94-
if (!setupEconomy() ) {
85+
public void onLoad() {
86+
if (getServer().getPluginManager().getPlugin("Vault") == null) {
9587
getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
9688
getServer().getPluginManager().disablePlugin(this);
97-
return;
98-
}
99-
setupPermissions();
100-
setupChat();
101-
}
102-
103-
private boolean setupEconomy() {
104-
if (getServer().getPluginManager().getPlugin("Vault") == null) {
105-
return false;
106-
}
107-
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
108-
if (rsp == null) {
109-
return false;
11089
}
111-
econ = rsp.getProvider();
112-
return econ != null;
11390
}
114-
115-
private boolean setupChat() {
116-
RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
117-
chat = rsp.getProvider();
118-
return chat != null;
91+
92+
@Override
93+
public void onEnable() {
94+
economy = getServer().getServicesManager().load(Economy.class);
95+
permission = getServer().getServicesManager().load(Permission.class);
96+
chat = getServer().getServicesManager().load(Chat.class);
11997
}
120-
121-
private boolean setupPermissions() {
122-
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
123-
perms = rsp.getProvider();
124-
return perms != null;
98+
99+
@Override
100+
public void onDisable() {
101+
getLogger().info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
125102
}
126-
103+
127104
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
128-
if(!(sender instanceof Player)) {
105+
if (!(sender instanceof Player player)) {
129106
getLogger().info("Only players are supported for this Example Plugin, but you should not do this!!!");
130107
return true;
131108
}
132-
133-
Player player = (Player) sender;
134-
135-
if(command.getLabel().equals("test-economy")) {
136-
// Lets give the player 1.05 currency (note that SOME economic plugins require rounding!)
137-
sender.sendMessage(String.format("You have %s", econ.format(econ.getBalance(player.getName()))));
138-
EconomyResponse r = econ.depositPlayer(player, 1.05);
139-
if(r.transactionSuccess()) {
140-
sender.sendMessage(String.format("You were given %s and now have %s", econ.format(r.amount), econ.format(r.balance)));
109+
110+
if (command.getLabel().equals("test-economy")) {
111+
// Let's give the player 1.05 currency (note that SOME economic plugins require rounding!)
112+
sender.sendMessage(String.format("You have %s", economy.format(economy.getBalance(player.getName()))));
113+
EconomyResponse r = economy.depositPlayer(player, 1.05);
114+
if (r.transactionSuccess()) {
115+
sender.sendMessage(String.format("You were given %s and now have %s", economy.format(r.amount), economy.format(r.balance)));
141116
} else {
142-
sender.sendMessage(String.format("An error occured: %s", r.errorMessage));
117+
sender.sendMessage(String.format("An error occurred: %s", r.errorMessage));
143118
}
144119
return true;
145-
} else if(command.getLabel().equals("test-permission")) {
146-
// Lets test if user has the node "example.plugin.awesome" to determine if they are awesome or just suck
147-
if(perms.has(player, "example.plugin.awesome")) {
120+
} else if (command.getLabel().equals("test-permission")) {
121+
// Let's test if the user has the node "example.plugin.awesome" to determine if they are awesome or just suck
122+
if (permission.has(player, "example.plugin.awesome")) {
148123
sender.sendMessage("You are awesome!");
149124
} else {
150125
sender.sendMessage("You suck!");
@@ -154,15 +129,15 @@ public class ExamplePlugin extends JavaPlugin {
154129
return false;
155130
}
156131
}
157-
132+
158133
public static Economy getEconomy() {
159-
return econ;
134+
return economy;
160135
}
161-
136+
162137
public static Permission getPermissions() {
163-
return perms;
138+
return permission;
164139
}
165-
140+
166141
public static Chat getChat() {
167142
return chat;
168143
}

0 commit comments

Comments
 (0)