-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
647 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package net.spigotcloud.lobby; | ||
|
||
import net.spigotcloud.lobby.api.LobbyAPI; | ||
import net.spigotcloud.lobby.command.BaseCommand; | ||
import net.spigotcloud.lobby.command.BuildCommand; | ||
import net.spigotcloud.lobby.command.ModulesCommand; | ||
import net.spigotcloud.lobby.command.ReloadCommand; | ||
import net.spigotcloud.lobby.listener.JoinQuitListener; | ||
import net.spigotcloud.lobby.listener.ProtectListener; | ||
import net.spigotcloud.lobby.module.ModuleLoader; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
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; | ||
|
||
@Override | ||
public void onEnable() { | ||
|
||
instance = this; | ||
|
||
this.moduleLoader = new ModuleLoader(); | ||
|
||
moduleLoader.reload(); | ||
moduleLoader.enable(); | ||
|
||
registerCommands(); | ||
registerEvents(); | ||
|
||
|
||
} | ||
|
||
private void registerCommands() { | ||
getCommand("lobby").setExecutor(this.command); | ||
command.registerSubCommand("reload", new ReloadCommand()); | ||
command.registerSubCommand("modules", new ModulesCommand()); | ||
command.registerSubCommand("build", new BuildCommand()); | ||
} | ||
|
||
private void registerEvents() { | ||
final PluginManager pm = getServer().getPluginManager(); | ||
pm.registerEvents(new JoinQuitListener(), this); | ||
pm.registerEvents(new ProtectListener(), this); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
moduleLoader.disable(); | ||
} | ||
|
||
public BaseCommand getBaseCommand() { | ||
return this.command; | ||
} | ||
|
||
|
||
public ModuleLoader getModuleLoader() { | ||
return this.moduleLoader; | ||
} | ||
|
||
public Set<Player> getBuildPlayers() { | ||
return this.buildPlayers; | ||
} | ||
|
||
public static Lobby getInstance() { | ||
return instance; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/net/spigotcloud/lobby/command/BaseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
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 org.bukkit.plugin.PluginDescriptionFile; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
// TODO: Custom messages | ||
|
||
public class BaseCommand implements CommandExecutor, TabCompleter { | ||
|
||
private final HashMap<String, SubCommand> subCommands; | ||
|
||
public BaseCommand() { | ||
this.subCommands = new HashMap<>(); | ||
} | ||
|
||
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("No permission."); | ||
} | ||
} else { | ||
sender.sendMessage("Sub-Command does not exists."); | ||
} | ||
|
||
} else { | ||
PluginDescriptionFile desc = Lobby.getInstance().getDescription(); | ||
sender.sendMessage(desc.getName() + " v" + desc.getVersion() + " by " + desc.getAuthors().get(0)); | ||
} | ||
|
||
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; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/net/spigotcloud/lobby/command/BuildCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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; | ||
|
||
// TODO: Custom messages | ||
|
||
public class BuildCommand extends SubCommand { | ||
|
||
public BuildCommand() { | ||
super("build"); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
|
||
if (!(sender instanceof Player)) { | ||
// TODO: Send message to console | ||
return false; | ||
} | ||
|
||
final Player player = (Player) sender; | ||
|
||
if (Lobby.getInstance().getBuildPlayers().contains(player)) { | ||
Lobby.getInstance().getBuildPlayers().remove(player); | ||
player.setGameMode(GameMode.SURVIVAL); | ||
player.sendMessage("Build Mode: off"); | ||
} else { | ||
Lobby.getInstance().getBuildPlayers().add(player); | ||
player.setGameMode(GameMode.CREATIVE); | ||
player.sendMessage("Build Mode: on"); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { | ||
return null; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/net/spigotcloud/lobby/command/ModulesCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.spigotcloud.lobby.command; | ||
|
||
// TODO: Custom messages | ||
|
||
import net.spigotcloud.lobby.Lobby; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.List; | ||
|
||
public class ModulesCommand extends SubCommand { | ||
|
||
public ModulesCommand() { | ||
super("modules"); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
sender.sendMessage(""); | ||
sender.sendMessage("§6§lLobby Modules"); | ||
Lobby.getInstance().getModuleLoader().getModules().forEach(module -> { | ||
sender.sendMessage("§8- §7" + module.getDescriptionFile().getName() + " v" + module.getDescriptionFile().getVersion() + " by " + module.getDescriptionFile().getAuthor()); | ||
}); | ||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { | ||
return null; | ||
} | ||
|
||
} | ||
|
30 changes: 30 additions & 0 deletions
30
src/main/java/net/spigotcloud/lobby/command/ReloadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.spigotcloud.lobby.command; | ||
|
||
import net.spigotcloud.lobby.Lobby; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.List; | ||
|
||
// TODO: Custom messages | ||
|
||
public class ReloadCommand extends SubCommand { | ||
|
||
public ReloadCommand() { | ||
super("reload"); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
sender.sendMessage("Reloading modules and files..."); | ||
Lobby.getInstance().getModuleLoader().reload(); | ||
sender.sendMessage("Lobby reload successfully."); | ||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { | ||
return null; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/net/spigotcloud/lobby/command/SubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.spigotcloud.lobby.command; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.List; | ||
|
||
public abstract class SubCommand { | ||
|
||
private final String permission; | ||
|
||
public SubCommand(String permission) { | ||
this.permission = permission; | ||
} | ||
|
||
public abstract boolean onCommand(CommandSender sender, Command command, String label, String[] args); | ||
public abstract List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args); | ||
|
||
public String getPermission() { | ||
return "lobby.command." + this.permission; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/net/spigotcloud/lobby/listener/JoinQuitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.spigotcloud.lobby.listener; | ||
|
||
// TODO: Custom join messages | ||
|
||
import net.spigotcloud.lobby.Lobby; | ||
import org.bukkit.GameMode; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
|
||
public class JoinQuitListener implements Listener { | ||
|
||
@EventHandler | ||
public void onPlayerJoin(PlayerJoinEvent e) { | ||
final Player player = e.getPlayer(); | ||
e.setJoinMessage(null); | ||
player.getInventory().clear(); | ||
player.setHealth(20); | ||
player.setFoodLevel(20); | ||
player.setExp(0); | ||
player.setTotalExperience(0); | ||
player.setLevel(0); | ||
player.setGameMode(GameMode.SURVIVAL); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerQuit(PlayerQuitEvent e) { | ||
final Player player = e.getPlayer(); | ||
e.setQuitMessage(null); | ||
Lobby.getInstance().getBuildPlayers().remove(player); | ||
} | ||
|
||
} |
Oops, something went wrong.