Skip to content

Commit 4cfe131

Browse files
authored
Update module items & inventory configuration
1 parent bf4ab46 commit 4cfe131

23 files changed

+1071
-1
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.spigotcloud</groupId>
88
<artifactId>lobby</artifactId>
9-
<version>1.4.0-STABLE</version>
9+
<version>1.4.2-STABLE</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Lobby</name>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package net.spigotcloud.lobby;
2+
3+
import net.spigotcloud.lobby.command.*;
4+
import net.spigotcloud.lobby.listener.ItemListener;
5+
import net.spigotcloud.lobby.listener.JoinQuitListener;
6+
import net.spigotcloud.lobby.listener.ProtectListener;
7+
import net.spigotcloud.lobby.manager.InventoryManager;
8+
import net.spigotcloud.lobby.manager.LanguageManager;
9+
import net.spigotcloud.lobby.manager.LocationManager;
10+
import net.spigotcloud.lobby.module.ModuleLoader;
11+
import org.bukkit.entity.Player;
12+
import org.bukkit.plugin.PluginManager;
13+
import org.bukkit.plugin.java.JavaPlugin;
14+
15+
import java.io.File;
16+
import java.util.HashSet;
17+
import java.util.Set;
18+
19+
public final class Lobby extends JavaPlugin {
20+
21+
private static Lobby instance;
22+
private final BaseCommand command = new BaseCommand();
23+
private final Set<Player> buildPlayers = new HashSet<>();
24+
25+
private ModuleLoader moduleLoader;
26+
private LanguageManager languageManager;
27+
private LocationManager locationManager;
28+
private InventoryManager inventoryManager;
29+
30+
@Override
31+
public void onEnable() {
32+
33+
instance = this;
34+
35+
this.moduleLoader = new ModuleLoader();
36+
37+
this.languageManager = new LanguageManager(new File(getDataFolder(), "language.yml"));
38+
this.locationManager = new LocationManager(new File(getDataFolder(), "locations.yml"));
39+
languageManager.reload();
40+
locationManager.reload();
41+
42+
registerCommands();
43+
registerEvents();
44+
45+
46+
moduleLoader.reload();
47+
48+
this.inventoryManager = new InventoryManager(new File(getDataFolder(), "inventory.yml"));
49+
inventoryManager.reload();
50+
51+
log();
52+
}
53+
54+
@Override
55+
public void onDisable() {
56+
moduleLoader.disable();
57+
}
58+
59+
private void registerCommands() {
60+
getCommand("lobby").setExecutor(this.command);
61+
command.registerSubCommand("help", new HelpCommand());
62+
command.registerSubCommand("reload", new ReloadCommand());
63+
command.registerSubCommand("modules", new ModulesCommand());
64+
command.registerSubCommand("build", new BuildCommand());
65+
command.registerSubCommand("setspawn", new SetSpawnCommand());
66+
}
67+
68+
private void registerEvents() {
69+
final PluginManager pm = getServer().getPluginManager();
70+
pm.registerEvents(new ItemListener(), this);
71+
pm.registerEvents(new JoinQuitListener(), this);
72+
pm.registerEvents(new ProtectListener(), this);
73+
}
74+
75+
76+
private void log() {
77+
getLogger().info("Registered " + moduleLoader.getModules().size() + " modules.");
78+
getLogger().info("Registered " + getBaseCommand().getSubCommands().size() + " commands.");
79+
getLogger().info("Registered " + getInventoryManager().getItems().size() + " items.");
80+
}
81+
82+
public BaseCommand getBaseCommand() {
83+
return this.command;
84+
}
85+
86+
87+
public ModuleLoader getModuleLoader() {
88+
return this.moduleLoader;
89+
}
90+
91+
public Set<Player> getBuildPlayers() {
92+
return this.buildPlayers;
93+
}
94+
95+
public LanguageManager getLanguageManager() {
96+
return languageManager;
97+
}
98+
99+
public LocationManager getLocationManager() {
100+
return locationManager;
101+
}
102+
103+
public InventoryManager getInventoryManager() { return inventoryManager; }
104+
105+
public static Lobby getInstance() {
106+
return instance;
107+
}
108+
109+
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.spigotcloud.lobby.api;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.plugin.Plugin;
5+
6+
public class LobbyAPI {
7+
8+
public static Plugin getPlugin() {
9+
return Bukkit.getServer().getPluginManager().getPlugin("Lobby");
10+
}
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package net.spigotcloud.lobby.command;
2+
3+
import net.spigotcloud.lobby.Lobby;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandExecutor;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.command.TabCompleter;
8+
9+
import javax.annotation.Nonnull;
10+
import java.util.*;
11+
12+
public class BaseCommand implements CommandExecutor, TabCompleter {
13+
14+
private final HashMap<String, SubCommand> subCommands;
15+
16+
public BaseCommand() {
17+
this.subCommands = new HashMap<>();
18+
}
19+
20+
public Map<String, SubCommand> getSubCommands() {
21+
return this.subCommands;
22+
}
23+
24+
public void registerSubCommand(@Nonnull String command, @Nonnull SubCommand subCommand) {
25+
this.subCommands.put(command, subCommand);
26+
}
27+
28+
public void unregister(@Nonnull String command) {
29+
this.subCommands.remove(command);
30+
}
31+
32+
33+
@Override
34+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
35+
36+
if (args.length > 0) {
37+
38+
if (subCommands.containsKey(args[0])) {
39+
SubCommand subCommand = subCommands.get(args[0]);
40+
if (sender.hasPermission(subCommand.getPermission())) {
41+
subCommand.onCommand(sender, command, label, args);
42+
} else {
43+
sender.sendMessage(Lobby.getInstance().getLanguageManager().getNoPermission(subCommand.getPermission()));
44+
}
45+
} else {
46+
sender.sendMessage(Lobby.getInstance().getLanguageManager().getWrongUsage("help"));
47+
}
48+
49+
} else {
50+
sender.sendMessage(Lobby.getInstance().getLanguageManager().getWrongUsage("help"));
51+
}
52+
53+
return false;
54+
}
55+
56+
@Override
57+
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
58+
59+
ArrayList<String> list = new ArrayList<>();
60+
String current = args[args.length - 1].toLowerCase();
61+
62+
63+
if (args.length == 1) {
64+
subCommands.forEach(((s, subCommand) -> {
65+
list.add(s.toLowerCase());
66+
}));
67+
} else {
68+
SubCommand subCommand = subCommands.get(args[0]);
69+
if (subCommand != null) {
70+
return subCommand.onTabComplete(sender, command, label, args);
71+
}
72+
}
73+
74+
list.removeIf(s -> !s.toLowerCase().startsWith(current));
75+
return list;
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package net.spigotcloud.lobby.command;
2+
3+
import net.spigotcloud.lobby.Lobby;
4+
import org.bukkit.GameMode;
5+
import org.bukkit.command.Command;
6+
import org.bukkit.command.CommandSender;
7+
import org.bukkit.entity.Player;
8+
9+
import java.util.List;
10+
11+
public class BuildCommand extends SubCommand {
12+
13+
public BuildCommand() {
14+
super("build", "Toggle build mode");
15+
}
16+
17+
@Override
18+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
19+
20+
if (!(sender instanceof Player)) {
21+
sender.sendMessage(Lobby.getInstance().getLanguageManager().getNoPlayerInstance());
22+
return false;
23+
}
24+
25+
final Player player = (Player) sender;
26+
27+
if (Lobby.getInstance().getBuildPlayers().contains(player)) {
28+
Lobby.getInstance().getBuildPlayers().remove(player);
29+
player.setGameMode(GameMode.SURVIVAL);
30+
player.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("build_mode_on"));
31+
} else {
32+
Lobby.getInstance().getBuildPlayers().add(player);
33+
player.setGameMode(GameMode.CREATIVE);
34+
player.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("build_mode_off"));
35+
}
36+
37+
return false;
38+
}
39+
40+
@Override
41+
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
42+
return null;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.spigotcloud.lobby.command;
2+
3+
import net.spigotcloud.lobby.Lobby;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.plugin.PluginDescriptionFile;
7+
8+
import java.util.List;
9+
10+
public class HelpCommand extends SubCommand {
11+
12+
public HelpCommand() {
13+
super("help", "Show this page");
14+
}
15+
16+
@Override
17+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
18+
PluginDescriptionFile desc = Lobby.getInstance().getDescription();
19+
sender.sendMessage("");
20+
Lobby.getInstance().getBaseCommand().getSubCommands().forEach((cmd, subCommand) -> {
21+
sender.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("help_list").replace("%command%", cmd).replace("%description%", subCommand.getDescription()).replace("%permission%", subCommand.getPermission()));
22+
});
23+
return false;
24+
}
25+
26+
@Override
27+
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
28+
return null;
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.spigotcloud.lobby.command;
2+
3+
import net.spigotcloud.lobby.Lobby;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.plugin.PluginDescriptionFile;
7+
8+
import java.util.List;
9+
10+
public class ModulesCommand extends SubCommand {
11+
12+
public ModulesCommand() {
13+
super("modules", "List all modules");
14+
}
15+
16+
@Override
17+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
18+
Lobby plugin = Lobby.getInstance();
19+
sender.sendMessage("");
20+
sender.sendMessage(plugin.getLanguageManager().getMessage("registered_modules").replace("%amount%", plugin.getModuleLoader().getModules().size() + ""));
21+
plugin.getModuleLoader().getModules().forEach(module -> {
22+
sender.sendMessage(plugin.getLanguageManager().getMessage("module_list").replace("%module%", module.getDescription().getName()).replace("%version%", module.getDescription().getVersion()).replace("%author%", module.getDescription().getAuthor()));
23+
});
24+
return false;
25+
}
26+
27+
@Override
28+
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
29+
return null;
30+
}
31+
32+
}
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.spigotcloud.lobby.command;
2+
3+
import net.spigotcloud.lobby.Lobby;
4+
import org.bukkit.command.Command;
5+
import org.bukkit.command.CommandSender;
6+
7+
import java.util.List;
8+
9+
public class ReloadCommand extends SubCommand {
10+
11+
public ReloadCommand() {
12+
super("reload", "Reloads the plugin");
13+
}
14+
15+
@Override
16+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
17+
Lobby plugin = Lobby.getInstance();
18+
plugin.getLocationManager().reload();
19+
plugin.getLanguageManager().reload();
20+
plugin.getModuleLoader().reload();
21+
plugin.getInventoryManager().reload();
22+
sender.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("reload"));
23+
return false;
24+
}
25+
26+
@Override
27+
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
28+
return null;
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package net.spigotcloud.lobby.command;
2+
3+
import net.spigotcloud.lobby.Lobby;
4+
import net.spigotcloud.lobby.manager.LanguageManager;
5+
import org.bukkit.Location;
6+
import org.bukkit.command.Command;
7+
import org.bukkit.command.CommandSender;
8+
import org.bukkit.entity.Player;
9+
10+
import java.util.List;
11+
12+
public class SetSpawnCommand extends SubCommand {
13+
14+
public SetSpawnCommand() {
15+
super("setspawn", "Set spawn location");
16+
}
17+
18+
@Override
19+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
20+
21+
LanguageManager languageManager = Lobby.getInstance().getLanguageManager();
22+
23+
if (!(sender instanceof Player)) {
24+
sender.sendMessage(languageManager.getNoPlayerInstance());
25+
return false;
26+
}
27+
28+
final Player player = (Player) sender;
29+
final Location location = player.getLocation();
30+
Lobby.getInstance().getLocationManager().setSpawn(location);
31+
player.sendMessage(languageManager.getMessage("spawn_set"));
32+
33+
return false;
34+
}
35+
36+
@Override
37+
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
38+
return null;
39+
}
40+
41+
}

0 commit comments

Comments
 (0)