Skip to content

Commit

Permalink
Update module items & inventory configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
teraprath authored May 11, 2023
1 parent bf4ab46 commit 4cfe131
Show file tree
Hide file tree
Showing 23 changed files with 1,071 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.spigotcloud</groupId>
<artifactId>lobby</artifactId>
<version>1.4.0-STABLE</version>
<version>1.4.2-STABLE</version>
<packaging>jar</packaging>

<name>Lobby</name>
Expand Down
110 changes: 110 additions & 0 deletions src/main/java/net/spigotcloud/lobby/Lobby.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package net.spigotcloud.lobby;

import net.spigotcloud.lobby.command.*;
import net.spigotcloud.lobby.listener.ItemListener;
import net.spigotcloud.lobby.listener.JoinQuitListener;
import net.spigotcloud.lobby.listener.ProtectListener;
import net.spigotcloud.lobby.manager.InventoryManager;
import net.spigotcloud.lobby.manager.LanguageManager;
import net.spigotcloud.lobby.manager.LocationManager;
import net.spigotcloud.lobby.module.ModuleLoader;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

public final class Lobby extends JavaPlugin {

private static Lobby instance;
private final BaseCommand command = new BaseCommand();
private final Set<Player> buildPlayers = new HashSet<>();

private ModuleLoader moduleLoader;
private LanguageManager languageManager;
private LocationManager locationManager;
private InventoryManager inventoryManager;

@Override
public void onEnable() {

instance = this;

this.moduleLoader = new ModuleLoader();

this.languageManager = new LanguageManager(new File(getDataFolder(), "language.yml"));
this.locationManager = new LocationManager(new File(getDataFolder(), "locations.yml"));
languageManager.reload();
locationManager.reload();

registerCommands();
registerEvents();


moduleLoader.reload();

this.inventoryManager = new InventoryManager(new File(getDataFolder(), "inventory.yml"));
inventoryManager.reload();

log();
}

@Override
public void onDisable() {
moduleLoader.disable();
}

private void registerCommands() {
getCommand("lobby").setExecutor(this.command);
command.registerSubCommand("help", new HelpCommand());
command.registerSubCommand("reload", new ReloadCommand());
command.registerSubCommand("modules", new ModulesCommand());
command.registerSubCommand("build", new BuildCommand());
command.registerSubCommand("setspawn", new SetSpawnCommand());
}

private void registerEvents() {
final PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new ItemListener(), this);
pm.registerEvents(new JoinQuitListener(), this);
pm.registerEvents(new ProtectListener(), this);
}


private void log() {
getLogger().info("Registered " + moduleLoader.getModules().size() + " modules.");
getLogger().info("Registered " + getBaseCommand().getSubCommands().size() + " commands.");
getLogger().info("Registered " + getInventoryManager().getItems().size() + " items.");
}

public BaseCommand getBaseCommand() {
return this.command;
}


public ModuleLoader getModuleLoader() {
return this.moduleLoader;
}

public Set<Player> getBuildPlayers() {
return this.buildPlayers;
}

public LanguageManager getLanguageManager() {
return languageManager;
}

public LocationManager getLocationManager() {
return locationManager;
}

public InventoryManager getInventoryManager() { return inventoryManager; }

public static Lobby getInstance() {
return instance;
}


}
12 changes: 12 additions & 0 deletions src/main/java/net/spigotcloud/lobby/api/LobbyAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.spigotcloud.lobby.api;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

public class LobbyAPI {

public static Plugin getPlugin() {
return Bukkit.getServer().getPluginManager().getPlugin("Lobby");
}

}
77 changes: 77 additions & 0 deletions src/main/java/net/spigotcloud/lobby/command/BaseCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package net.spigotcloud.lobby.command;

import net.spigotcloud.lobby.Lobby;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

import javax.annotation.Nonnull;
import java.util.*;

public class BaseCommand implements CommandExecutor, TabCompleter {

private final HashMap<String, SubCommand> subCommands;

public BaseCommand() {
this.subCommands = new HashMap<>();
}

public Map<String, SubCommand> getSubCommands() {
return this.subCommands;
}

public void registerSubCommand(@Nonnull String command, @Nonnull SubCommand subCommand) {
this.subCommands.put(command, subCommand);
}

public void unregister(@Nonnull String command) {
this.subCommands.remove(command);
}


@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (args.length > 0) {

if (subCommands.containsKey(args[0])) {
SubCommand subCommand = subCommands.get(args[0]);
if (sender.hasPermission(subCommand.getPermission())) {
subCommand.onCommand(sender, command, label, args);
} else {
sender.sendMessage(Lobby.getInstance().getLanguageManager().getNoPermission(subCommand.getPermission()));
}
} else {
sender.sendMessage(Lobby.getInstance().getLanguageManager().getWrongUsage("help"));
}

} else {
sender.sendMessage(Lobby.getInstance().getLanguageManager().getWrongUsage("help"));
}

return false;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {

ArrayList<String> list = new ArrayList<>();
String current = args[args.length - 1].toLowerCase();


if (args.length == 1) {
subCommands.forEach(((s, subCommand) -> {
list.add(s.toLowerCase());
}));
} else {
SubCommand subCommand = subCommands.get(args[0]);
if (subCommand != null) {
return subCommand.onTabComplete(sender, command, label, args);
}
}

list.removeIf(s -> !s.toLowerCase().startsWith(current));
return list;
}
}
44 changes: 44 additions & 0 deletions src/main/java/net/spigotcloud/lobby/command/BuildCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.spigotcloud.lobby.command;

import net.spigotcloud.lobby.Lobby;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

public class BuildCommand extends SubCommand {

public BuildCommand() {
super("build", "Toggle build mode");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (!(sender instanceof Player)) {
sender.sendMessage(Lobby.getInstance().getLanguageManager().getNoPlayerInstance());
return false;
}

final Player player = (Player) sender;

if (Lobby.getInstance().getBuildPlayers().contains(player)) {
Lobby.getInstance().getBuildPlayers().remove(player);
player.setGameMode(GameMode.SURVIVAL);
player.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("build_mode_on"));
} else {
Lobby.getInstance().getBuildPlayers().add(player);
player.setGameMode(GameMode.CREATIVE);
player.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("build_mode_off"));
}

return false;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return null;
}
}
31 changes: 31 additions & 0 deletions src/main/java/net/spigotcloud/lobby/command/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.spigotcloud.lobby.command;

import net.spigotcloud.lobby.Lobby;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginDescriptionFile;

import java.util.List;

public class HelpCommand extends SubCommand {

public HelpCommand() {
super("help", "Show this page");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
PluginDescriptionFile desc = Lobby.getInstance().getDescription();
sender.sendMessage("");
Lobby.getInstance().getBaseCommand().getSubCommands().forEach((cmd, subCommand) -> {
sender.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("help_list").replace("%command%", cmd).replace("%description%", subCommand.getDescription()).replace("%permission%", subCommand.getPermission()));
});
return false;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return null;
}

}
33 changes: 33 additions & 0 deletions src/main/java/net/spigotcloud/lobby/command/ModulesCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.spigotcloud.lobby.command;

import net.spigotcloud.lobby.Lobby;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginDescriptionFile;

import java.util.List;

public class ModulesCommand extends SubCommand {

public ModulesCommand() {
super("modules", "List all modules");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Lobby plugin = Lobby.getInstance();
sender.sendMessage("");
sender.sendMessage(plugin.getLanguageManager().getMessage("registered_modules").replace("%amount%", plugin.getModuleLoader().getModules().size() + ""));
plugin.getModuleLoader().getModules().forEach(module -> {
sender.sendMessage(plugin.getLanguageManager().getMessage("module_list").replace("%module%", module.getDescription().getName()).replace("%version%", module.getDescription().getVersion()).replace("%author%", module.getDescription().getAuthor()));
});
return false;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return null;
}

}

31 changes: 31 additions & 0 deletions src/main/java/net/spigotcloud/lobby/command/ReloadCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.spigotcloud.lobby.command;

import net.spigotcloud.lobby.Lobby;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import java.util.List;

public class ReloadCommand extends SubCommand {

public ReloadCommand() {
super("reload", "Reloads the plugin");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Lobby plugin = Lobby.getInstance();
plugin.getLocationManager().reload();
plugin.getLanguageManager().reload();
plugin.getModuleLoader().reload();
plugin.getInventoryManager().reload();
sender.sendMessage(Lobby.getInstance().getLanguageManager().getMessage("reload"));
return false;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return null;
}

}
41 changes: 41 additions & 0 deletions src/main/java/net/spigotcloud/lobby/command/SetSpawnCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.spigotcloud.lobby.command;

import net.spigotcloud.lobby.Lobby;
import net.spigotcloud.lobby.manager.LanguageManager;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

public class SetSpawnCommand extends SubCommand {

public SetSpawnCommand() {
super("setspawn", "Set spawn location");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

LanguageManager languageManager = Lobby.getInstance().getLanguageManager();

if (!(sender instanceof Player)) {
sender.sendMessage(languageManager.getNoPlayerInstance());
return false;
}

final Player player = (Player) sender;
final Location location = player.getLocation();
Lobby.getInstance().getLocationManager().setSpawn(location);
player.sendMessage(languageManager.getMessage("spawn_set"));

return false;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return null;
}

}
Loading

0 comments on commit 4cfe131

Please sign in to comment.