Created
January 23, 2016 06:17
-
-
Save Zyraun/ec86c2fddd1c68b62830 to your computer and use it in GitHub Desktop.
Create automated applications for your Minecraft server!
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
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
<orderEntry type="library" name="spigot3" level="project" /> | |
</component> | |
</module> |
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
## | |
## Thank you for using ApplyMc by Zyraun | |
## Last Update: 01/18/2016 (Mon) | |
## | |
application: | |
enabled: true | |
permissions: | |
apply: 'applymc.apply' | |
notifications: 'applymc.notify' | |
check: 'applymc.check' | |
open: 'applymc.open' | |
close: 'applymc.close' | |
reload: 'applymc.reload' | |
create-sign: 'applymc.sign.create' | |
use-sign: 'applymc.sign.use' | |
reapply: 'applymc.reapply' | |
messages: | |
questions: '&b[ApplyMc] &3%question%' | |
no-permissions: '&cYou are not allowed to do this.' | |
applications-closed: '&4[ApplyMc] &cApplications are currently closed.' | |
application-end: '&4[ApplyMc] &cThank you for your application. It will be reviewed by staff shortly.' | |
application-accept: '&2[ApplyMc] &aYour application has been accepted!' | |
application-deny: '&4[ApplyMc] &cYour application has been denied.' | |
already-applied: '&4[ApplyMc] &cYou have already applied. It will be reviewed shortly.' | |
reapply-deny: '&4[ApplyMc] &cAlready applied. You may reapply in %cooldown% seconds.' | |
reapply-allow: '&2[ApplyMc] &aYou may now reapply. /apply' | |
notification: '&4[ApplyMc] &c%notification%' | |
sign: | |
line1: '&9[ApplyMc]' | |
line2: '&8Click to Apply' | |
line3: '' | |
line4: '&cThank you!' | |
settings: | |
reapply: | |
enabled: true | |
cooldown: 300 | |
accept-commands: | |
- 'msg %player% &3[ApplyMc] &bYou were accepted as staff!' | |
deny-commands: | |
- 'msg %player% &4[ApplyMc] &cSorry, but your application was denied.' | |
questions: | |
- 'What are you applying for?' | |
- 'Why should we accept you?' |
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
package me.zyraun.bukkit.applications.commands; | |
import me.zyraun.bukkit.applications.Main; | |
import me.zyraun.bukkit.applications.util.MessageUtil; | |
import me.zyraun.bukkit.applications.util.PermissionUtil; | |
import me.zyraun.bukkit.applications.util.application.ApplicationManager; | |
import me.zyraun.bukkit.applications.util.application.task.ReapplyTask; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
public class ApplyCommand implements CommandExecutor { | |
public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) { | |
if (!cmd.getName().equalsIgnoreCase("apply")) return false; | |
if (Main.applicationsOpen()) { | |
if (s.hasPermission(PermissionUtil.getApply())) { | |
if (s instanceof Player) { | |
if (Main.getInstance().getConfig().getBoolean("application.settings.reapply.enabled")) { | |
// CAN reapply | |
if (ReapplyTask.getInCooldown().containsKey(((Player) s).getUniqueId())) { | |
s.sendMessage(MessageUtil.getReapplyDeny((Player) s)); | |
} else { | |
ApplicationManager.start((Player) s); | |
} | |
} else { | |
// NO reapply | |
if (ApplicationManager.getApplication((Player) s).getAnswers().size() == 0) { | |
ApplicationManager.start((Player) s); | |
} else { | |
s.sendMessage(MessageUtil.getAlreadyApplied()); | |
} | |
} | |
} else { | |
s.sendMessage("§cSilly Console, why would you apply? Haha!"); | |
} | |
} else { | |
s.sendMessage(MessageUtil.getPermissionsMessage()); | |
} | |
} else { | |
s.sendMessage(MessageUtil.getClosedMessage()); | |
} | |
return false; | |
} | |
} |
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
package me.zyraun.bukkit.applications.commands; | |
import me.zyraun.bukkit.applications.Main; | |
import me.zyraun.bukkit.applications.commands.command.CommandManager; | |
import me.zyraun.bukkit.applications.util.MessageUtil; | |
import me.zyraun.bukkit.applications.util.PermissionUtil; | |
import me.zyraun.bukkit.applications.util.QuestionUtil; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import me.zyraun.bukkit.applications.util.application.ApplicationManager; | |
import me.zyraun.bukkit.applications.util.application.events.ApplicationAcceptEvent; | |
import me.zyraun.bukkit.applications.util.application.events.ApplicationDenyEvent; | |
import me.zyraun.bukkit.applications.util.book.BookUtil; | |
import me.zyraun.bukkit.applications.util.common.ItemStackBuilder; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Material; | |
import org.bukkit.OfflinePlayer; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.inventory.Inventory; | |
import org.bukkit.inventory.ItemStack; | |
public class ApplymcCommand implements CommandExecutor { | |
public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) { | |
if (!cmd.getName().equalsIgnoreCase("applymc")) return false; | |
if (args.length == 0) { | |
/** BASE COMMAND */ | |
s.sendMessage("§6" + MessageUtil.getDivider()); | |
s.sendMessage(" §9ApplyMc §7created by §bZyraun"); | |
s.sendMessage(""); | |
s.sendMessage(" §b/apply §7Create an application"); | |
for (me.zyraun.bukkit.applications.commands.command.Command cmds : CommandManager.getCommands()) { | |
s.sendMessage(" §b/applymc " + cmds.getLabel() + " §7" + cmds.getDescription()); | |
} | |
s.sendMessage("§6" + MessageUtil.getDivider()); | |
} else if (args.length == 1) { | |
String arg = args[0]; | |
if (arg.equalsIgnoreCase("reload")) { | |
/** RELOAD COMMAND */ | |
if (!s.hasPermission(PermissionUtil.getReload())) { s.sendMessage(MessageUtil.getPermissionsMessage()); return false; } | |
s.sendMessage("§6" + MessageUtil.getDivider()); | |
s.sendMessage(" §3[ApplyMc] §bApplyMc plugin reload in progress..."); | |
Main.getInstance().getServer().getPluginManager().getPlugin("ApplyMc").reloadConfig(); | |
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() { | |
@Override | |
public void run() { | |
s.sendMessage(" §2[ApplyMc] §aFile configuration reload completed!"); | |
s.sendMessage("§6" + MessageUtil.getDivider()); | |
} | |
}, 10); | |
} | |
if (arg.equalsIgnoreCase("view")) { | |
/** VIEW COMMAND */ | |
if (!s.hasPermission(PermissionUtil.getCheck())) { s.sendMessage(MessageUtil.getPermissionsMessage()); return false; } | |
if (!(s instanceof Player)) { s.sendMessage("§cOnly players may do this."); return false; } | |
int amountApps = 0; | |
for (Application a : ApplicationManager.getApplications()) { | |
if (!a.wasReviewed()) | |
amountApps++; | |
} | |
Inventory inv = Bukkit.createInventory(null, 54, "ApplyMc Applications (" + amountApps + ")"); | |
for (Application a : ApplicationManager.getApplications()) { | |
if (!a.isApplying()) { | |
if (!(a.getAnswers().size() < QuestionUtil.getQuestions().size())) { | |
if (!a.wasReviewed()) | |
inv.addItem(BookUtil.write(a.getPlayer())); | |
} | |
} | |
} | |
inv.addItem(new ItemStackBuilder(Material.SIGN).withName("§aApplyMc Help").withLore(new String[]{ | |
"§7Help Topic: §bHow to Review", | |
"", "§7Move the application book into your", | |
"§7inventory. After reviewing the application", | |
"§7type §a/applymc accept §7or §c/applymc deny", | |
"§7with the book in hand to submit response.", "", "§8ApplyMc Help Sign" | |
}).build()); | |
((Player) s).openInventory(inv); | |
} | |
if (arg.equalsIgnoreCase("close")) { | |
/** CLOSE COMMAND */ | |
if (!s.hasPermission(PermissionUtil.getClose())) { s.sendMessage(MessageUtil.getPermissionsMessage()); return false; } | |
if (Main.applicationsOpen()) { | |
Main.getInstance().getConfig().set("application.enabled", false); | |
s.sendMessage("§bApplications have been closed.\n §9/applymc open §bto open them again."); | |
} else s.sendMessage("§cApplications are already closed."); | |
} | |
if (arg.equalsIgnoreCase("open")) { | |
/** OPEN COMMAND */ | |
if (!s.hasPermission(PermissionUtil.getOpen())) { s.sendMessage(MessageUtil.getPermissionsMessage()); return false; } | |
if (!Main.applicationsOpen()) { | |
Main.getInstance().getConfig().set("application.enabled", true); | |
s.sendMessage("§bApplications have been opened.\n §9/applymc close §bto close them."); | |
} else s.sendMessage("§cApplications are already open."); | |
} | |
if (arg.equalsIgnoreCase("accept")) { | |
/** ACCEPT COMMAND */ | |
if (!(s instanceof Player)) { s.sendMessage("§cOnly players may do this."); return false; } | |
Player p = (Player) s; | |
if (!p.getItemInHand().getType().equals(Material.WRITTEN_BOOK)) { p.sendMessage("§cHold an application book in your hand while you do this"); return false; } | |
ItemStack item = p.getItemInHand(); | |
if (!item.getItemMeta().getDisplayName().contains("Application")) { p.sendMessage("§cHold an application book in your hand while you do this"); return false; } | |
String name = item.getItemMeta().getDisplayName().replace("'s Application", "").replace("§b", ""); | |
if (!Bukkit.getOfflinePlayer(name).isOnline()) { | |
p.sendMessage(" §cThat player is not online. §cSomething could break!\n §cCancelling accept process. This may be changed later."); | |
} else { | |
Player ap = Bukkit.getPlayer(name); | |
Application a = ApplicationManager.getApplication(ap); | |
ApplicationAcceptEvent event = new ApplicationAcceptEvent(a); | |
Bukkit.getPluginManager().callEvent(event); | |
if (event.isCancelled()) return false; | |
a.review(); | |
p.sendMessage("§aYou have accepted §b" + ap.getName() + "§a's application"); | |
} | |
} | |
if (arg.equalsIgnoreCase("deny")) { | |
/** DENY COMMAND */ | |
if (!(s instanceof Player)) { s.sendMessage("§cOnly players may do this."); return false; } | |
Player p = (Player) s; | |
if (!p.getItemInHand().getType().equals(Material.WRITTEN_BOOK)) { p.sendMessage("§cHold an application book in your hand while you do this"); return false; } | |
ItemStack item = p.getItemInHand(); | |
if (!item.getItemMeta().getDisplayName().contains("Application")) { p.sendMessage("§cHold an application book in your hand while you do this"); return false; } | |
String name = item.getItemMeta().getDisplayName().replace("'s Application", "").replace("§b", ""); | |
if (!Bukkit.getOfflinePlayer(name).isOnline()) { | |
p.sendMessage(" §cThat player is not online. §cSomething could break!\n §cCancelling deny process. This may be changed later."); | |
} else { | |
Player ap = Bukkit.getPlayer(name); | |
Application a = ApplicationManager.getApplication(ap); | |
ApplicationDenyEvent event = new ApplicationDenyEvent(a); | |
Bukkit.getPluginManager().callEvent(event); | |
if (event.isCancelled()) return false; | |
a.review(); | |
p.sendMessage("§aYou have denied §b" + ap.getName() + "§a's application"); | |
} | |
} | |
} else if (args.length == 2) { | |
String arg = args[0]; | |
String param = args[1]; | |
if (arg.equalsIgnoreCase("view")) { | |
if (!(s instanceof Player)) { s.sendMessage("§cOnly players may do this."); return false; } | |
Player p = (Player) s; | |
if (!p.hasPermission(PermissionUtil.getCheck())) { s.sendMessage(MessageUtil.getPermissionsMessage()); return false; } | |
if (!Bukkit.getOfflinePlayer(param).hasPlayedBefore()) { s.sendMessage("§cThat player has never joined before."); return false; } | |
if (ApplicationManager.getApplication(param) == null) { s.sendMessage("§cThat player's application could not be found."); return false; } | |
if (ApplicationManager.getApplication(param).isApplying() == true) { s.sendMessage("§cThat player is still applying Try again later."); return false; } | |
if (ApplicationManager.getApplication(param).getAnswers().size() < QuestionUtil.getQuestions().size()) { s.sendMessage("§cThat application could not be found."); return false; } | |
p.getInventory().addItem(BookUtil.write(param)); | |
} | |
} | |
return false; | |
} | |
} |
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
package me.zyraun.bukkit.applications.commands.command; | |
public class Command { | |
private String cmdLabel; | |
private String cmdDesc; | |
public Command(String label, String description) { | |
CommandManager.addCommand(this); | |
cmdLabel = label; | |
cmdDesc = description; | |
} | |
public String getLabel() { return cmdLabel; } | |
public String getDescription() { return cmdDesc; } | |
} |
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
package me.zyraun.bukkit.applications.commands.command; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class CommandManager { | |
private static List<Command> commands = new ArrayList<>(); | |
public static List<Command> getCommands() { return commands; } | |
public static void addCommand(Command command) { | |
if (commands.contains(command)) return; | |
commands.add(command); | |
} | |
public static void removeCommand(Command command) { | |
if (!commands.contains(command)) return; | |
commands.remove(command); | |
} | |
public static void registerCommands() { | |
Command accept = new Command("accept", "Accept the application in your hand."); | |
Command deny = new Command("deny", "Deny the application in your hand;"); | |
Command view = new Command("view §3[player]", "View a specific player's application"); | |
Command toggles = new Command("§3[open/close]", "Start/Stop accepting applications"); | |
Command reload = new Command("reload", "Reload the ApplyMc configuration file."); | |
} | |
} |
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
package me.zyraun.bukkit.applications; | |
import me.zyraun.bukkit.applications.commands.ApplyCommand; | |
import me.zyraun.bukkit.applications.commands.ApplymcCommand; | |
import me.zyraun.bukkit.applications.commands.command.CommandManager; | |
import me.zyraun.bukkit.applications.util.MessageUtil; | |
import me.zyraun.bukkit.applications.util.PermissionUtil; | |
import me.zyraun.bukkit.applications.util.QuestionUtil; | |
import me.zyraun.bukkit.applications.util.application.ApplicationHandler; | |
import me.zyraun.bukkit.applications.util.application.task.ReapplyTask; | |
import me.zyraun.bukkit.applications.util.category.CategoryManager; | |
import me.zyraun.bukkit.applications.util.category.menu.CategoryMenu; | |
import me.zyraun.bukkit.applications.util.freezechat.FrozenChatHandler; | |
import me.zyraun.bukkit.applications.util.signs.SignHandler; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.Plugin; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class Main extends JavaPlugin { | |
private static Plugin main; | |
public static Plugin getInstance() { return main; } | |
@Override | |
public void onEnable() { | |
main = this; | |
getCommand("applymc").setExecutor(new ApplymcCommand()); | |
getCommand("apply").setExecutor(new ApplyCommand()); | |
getServer().getPluginManager().registerEvents(new FrozenChatHandler(), this); | |
getServer().getPluginManager().registerEvents(new ApplicationHandler(), this); | |
getServer().getPluginManager().registerEvents(new SignHandler(), this); | |
getConfig().options().copyDefaults(true); | |
saveConfig(); | |
//CategoryManager.loadCategories(); COMING SOON | |
QuestionUtil.loadQuestions(); | |
CommandManager.registerCommands(); | |
} | |
@Override | |
public void onDisable() { | |
for (Player p : Bukkit.getOnlinePlayers()) { | |
if (ReapplyTask.getInCooldown().containsKey(p.getUniqueId())) | |
ReapplyTask.endCooldown(p); | |
} | |
} | |
public static boolean applicationsOpen() { return Main.getInstance().getConfig().getBoolean("application.enabled"); } | |
} |
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
package me.zyraun.bukkit.applications.util.application; | |
import me.zyraun.bukkit.applications.util.MessageUtil; | |
import me.zyraun.bukkit.applications.util.QuestionUtil; | |
import me.zyraun.bukkit.applications.util.application.events.ApplicationAnswerEvent; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Application { | |
private Player appPlayer; | |
private boolean applying; | |
private boolean reviewed = false; | |
private List<String> answers = new ArrayList<>(); | |
public Application(Player player) { | |
ApplicationManager.addApplication(this); | |
appPlayer = player; | |
applying = false; | |
} | |
public Player getPlayer() { return appPlayer; } | |
public boolean isApplying() { return applying; } | |
public List<String> getAnswers() { return answers; } | |
public boolean wasReviewed() { return reviewed; } | |
public int getCurrentIndex() { return getAnswers().size(); } | |
public String getCurrentQuestion() { return QuestionUtil.getQuestion(getCurrentIndex()); } | |
public String getNextQuestion() { return QuestionUtil.getQuestion(getCurrentIndex() + 1); } | |
public void review() { reviewed = true; } | |
public void giveAnswer(String message) { | |
ApplicationAnswerEvent event = new ApplicationAnswerEvent(getPlayer(), this, message); | |
Bukkit.getServer().getPluginManager().callEvent(event); | |
if (event.isCancelled()) return; | |
List<String> answerList = new ArrayList<>(); | |
for (String s : getAnswers()) { | |
answerList.add(s); | |
} | |
answerList.add(message); | |
answers = answerList; | |
} | |
public void sendNextQuestion() { | |
if (getCurrentIndex() + 1 <= QuestionUtil.getQuestions().size()) { | |
getPlayer().sendMessage(MessageUtil.getQuestionMessage(getCurrentIndex())); | |
} else { | |
ApplicationManager.stop(getPlayer()); | |
} | |
} | |
public void start() { | |
applying = true; | |
ApplicationManager.start(getPlayer()); | |
} | |
public void stop() { | |
applying = false; | |
ApplicationManager.stop(getPlayer()); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.application; | |
import me.zyraun.bukkit.applications.Main; | |
import me.zyraun.bukkit.applications.util.MessageUtil; | |
import me.zyraun.bukkit.applications.util.PermissionUtil; | |
import me.zyraun.bukkit.applications.util.application.events.*; | |
import me.zyraun.bukkit.applications.util.application.task.ReapplyTask; | |
import me.zyraun.bukkit.applications.util.book.BookUtil; | |
import me.zyraun.bukkit.applications.util.common.JsonBuilder; | |
import me.zyraun.bukkit.applications.util.freezechat.FrozenChatManager; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Material; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.inventory.InventoryClickEvent; | |
import org.bukkit.event.player.AsyncPlayerChatEvent; | |
import org.bukkit.inventory.Inventory; | |
import org.bukkit.inventory.ItemStack; | |
public class ApplicationHandler implements Listener { | |
@EventHandler | |
public void onAppAnswer(ApplicationAnswerEvent e) { | |
Player p = e.getPlayer(); | |
Application a = e.getApplication(); | |
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() { | |
@Override | |
public void run() { | |
a.sendNextQuestion(); | |
} | |
}, 20); | |
} | |
@EventHandler | |
public void onAppStart(ApplicationStartEvent e) { | |
Player p = e.getPlayer(); | |
Application a = e.getApplication(); | |
if (FrozenChatManager.chatIsFrozen(p)) return; | |
FrozenChatManager.getFrozenChat(p).freezeChat(); | |
p.sendMessage(""); | |
p.sendMessage(MessageUtil.getQuestionMessage(0)); | |
} | |
@EventHandler | |
public void onAppEnd(ApplicationEndEvent e) { | |
Player p = e.getPlayer(); | |
Application a = e.getApplication(); | |
if (!FrozenChatManager.chatIsFrozen(p)) return; | |
FrozenChatManager.getFrozenChat(p).thawChat(); | |
p.sendMessage(MessageUtil.getEndMessage()); | |
p.getInventory().addItem(BookUtil.write(p)); | |
JsonBuilder json = new JsonBuilder(MessageUtil.getNotificationMessage(p.getName() + " has submitted a new application")); | |
json.withHoverEvent(JsonBuilder.HoverAction.SHOW_TEXT, "§bClick to view " + a.getPlayer().getName() + "'s application"); | |
json.withClickEvent(JsonBuilder.ClickAction.RUN_COMMAND, "/applymc view " + a.getPlayer().getName()); | |
for (Player ap : Bukkit.getOnlinePlayers()) { | |
if (ap.hasPermission(PermissionUtil.getNotify())) | |
json.sendJson(ap); | |
} | |
ReapplyTask.startCooldown(p); | |
} | |
@EventHandler | |
public void onAppAccept(ApplicationAcceptEvent e) { | |
e.getApplication().review(); | |
e.getApplication().getPlayer().sendMessage(MessageUtil.getAcceptMessage()); | |
for (String s : Main.getInstance().getConfig().getStringList("application.settings.accept-commands")) { | |
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s.replace("%player%", e.getApplication().getPlayer().getName())); | |
} | |
} | |
@EventHandler | |
public void onAppDeny(ApplicationDenyEvent e) { | |
e.getApplication().review(); | |
e.getApplication().getPlayer().sendMessage(MessageUtil.getDenyMessage()); | |
for (String s : Main.getInstance().getConfig().getStringList("application.settings.deny-commands")) { | |
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s.replace("%player%", e.getApplication().getPlayer().getName())); | |
} | |
} | |
@EventHandler | |
public void onInventoryEdit(InventoryClickEvent e) { | |
Player p = (Player) e.getWhoClicked(); | |
Inventory inv = e.getInventory(); | |
ItemStack item = e.getCurrentItem(); | |
if (!inv.getTitle().contains("Applications")) return; | |
if (item.getType().equals(Material.SIGN)) { | |
e.setCancelled(true); | |
} else if (item.getType().equals(Material.WRITTEN_BOOK)) { | |
e.setCancelled(true); | |
p.getInventory().addItem(item); | |
} else { | |
e.setCancelled(true); | |
} | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.application; | |
import me.zyraun.bukkit.applications.util.application.events.ApplicationEndEvent; | |
import me.zyraun.bukkit.applications.util.application.events.ApplicationStartEvent; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class ApplicationManager { | |
private static List<Application> applications = new ArrayList<>(); | |
public static List<Application> getApplications() { return applications; } | |
public static Application getApplication(Player player) { | |
for (Application app : getApplications()) { | |
if (app.getPlayer().getUniqueId() == player.getUniqueId()) return app; | |
} return new Application(player); | |
} | |
public static Application getApplication(String name) { | |
for (Application app : getApplications()) { | |
if (app.getPlayer().getName().equalsIgnoreCase(name)) return app; | |
} | |
if (Bukkit.getOfflinePlayer(name).isOnline()) return new Application(Bukkit.getPlayer(name)); | |
return null; | |
} | |
public static void addApplication(Application application) { | |
if (getApplications().contains(application)) return; | |
applications.add(application); | |
} | |
public static void removeApplication(Application application) { | |
if (!getApplications().contains(application)) return; | |
applications.remove(application); | |
} | |
public static void start(Player player) { | |
ApplicationStartEvent event = new ApplicationStartEvent(player, getApplication(player)); | |
Bukkit.getServer().getPluginManager().callEvent(event); | |
if (event.isCancelled()) return; | |
} | |
public static void stop(Player player) { | |
ApplicationEndEvent event = new ApplicationEndEvent(player, getApplication(player)); | |
Bukkit.getServer().getPluginManager().callEvent(event); | |
if (event.isCancelled()) return; | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.application.events; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.HandlerList; | |
public class ApplicationAcceptEvent extends Event { | |
private static final HandlerList handlers = new HandlerList(); | |
private Application eventApplication; | |
private Player eventPlayer; | |
private boolean cancelled = false; | |
public ApplicationAcceptEvent(Application application) { | |
eventApplication = application; | |
} | |
public ApplicationAcceptEvent(Player player, Application application) { | |
eventApplication = application; | |
eventPlayer = player; | |
} | |
public HandlerList getHandlers() { | |
return handlers; | |
} | |
public static HandlerList getHandlerList() { | |
return handlers; | |
} | |
public Application getApplication() { | |
return eventApplication; | |
} | |
public Player getPlayer() { return eventPlayer; } | |
public boolean isCancelled() { return cancelled; } | |
public void setCancelled(boolean value) { cancelled = true; } | |
} |
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
package me.zyraun.bukkit.applications.util.application.events; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.HandlerList; | |
public class ApplicationAnswerEvent extends Event { | |
private static final HandlerList handlers = new HandlerList(); | |
private Application eventApplication; | |
private Player eventPlayer; | |
private String eventAnswer; | |
private boolean cancelled = false; | |
public ApplicationAnswerEvent(Player player, Application application, String answer) { | |
eventApplication = application; | |
eventPlayer = player; | |
eventAnswer = answer; | |
} | |
public HandlerList getHandlers() { | |
return handlers; | |
} | |
public static HandlerList getHandlerList() { | |
return handlers; | |
} | |
public Application getApplication() { | |
return eventApplication; | |
} | |
public Player getPlayer() { return eventPlayer; } | |
public String getAnswer() { return eventAnswer; } | |
public boolean isCancelled() { return cancelled; } | |
public void setCancelled(boolean value) { cancelled = true; } | |
} |
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
package me.zyraun.bukkit.applications.util.application.events; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.HandlerList; | |
public class ApplicationDenyEvent extends Event { | |
private static final HandlerList handlers = new HandlerList(); | |
private Application eventApplication; | |
private Player eventPlayer; | |
private boolean cancelled = false; | |
public ApplicationDenyEvent(Application application) { | |
eventApplication = application; | |
} | |
public ApplicationDenyEvent(Player player, Application application) { | |
eventApplication = application; | |
eventPlayer = player; | |
} | |
public HandlerList getHandlers() { | |
return handlers; | |
} | |
public static HandlerList getHandlerList() { | |
return handlers; | |
} | |
public Application getApplication() { | |
return eventApplication; | |
} | |
public Player getPlayer() { return eventPlayer; } | |
public boolean isCancelled() { return cancelled; } | |
public void setCancelled(boolean value) { cancelled = true; } | |
} |
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
package me.zyraun.bukkit.applications.util.application.events; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.HandlerList; | |
public class ApplicationEndEvent extends Event { | |
private static final HandlerList handlers = new HandlerList(); | |
private Application eventApplication; | |
private Player eventPlayer; | |
private boolean cancelled = false; | |
public ApplicationEndEvent(Player player, Application application) { | |
eventApplication = application; | |
eventPlayer = player; | |
} | |
public HandlerList getHandlers() { | |
return handlers; | |
} | |
public static HandlerList getHandlerList() { | |
return handlers; | |
} | |
public Application getApplication() { | |
return eventApplication; | |
} | |
public Player getPlayer() { return eventPlayer; } | |
public boolean isCancelled() { return cancelled; } | |
public void setCancelled(boolean value) { cancelled = true; } | |
} |
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
package me.zyraun.bukkit.applications.util.application.events; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.HandlerList; | |
public class ApplicationStartEvent extends Event { | |
private static final HandlerList handlers = new HandlerList(); | |
private Application eventApplication; | |
private Player eventPlayer; | |
private boolean cancelled = false; | |
public ApplicationStartEvent(Player player, Application application) { | |
eventApplication = application; | |
eventPlayer = player; | |
} | |
public HandlerList getHandlers() { | |
return handlers; | |
} | |
public static HandlerList getHandlerList() { | |
return handlers; | |
} | |
public Application getApplication() { | |
return eventApplication; | |
} | |
public Player getPlayer() { return eventPlayer; } | |
public boolean isCancelled() { return cancelled; } | |
public void setCancelled(boolean value) { cancelled = true; } | |
} |
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
package me.zyraun.bukkit.applications.util.application.task; | |
import me.zyraun.bukkit.applications.Main; | |
import me.zyraun.bukkit.applications.util.MessageUtil; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import java.util.*; | |
public class ReapplyTask { | |
private static Map<UUID, Integer> inCooldown = new HashMap<>(); | |
public static Map<UUID, Integer> getInCooldown() { return inCooldown; } | |
public static void endCooldown(Player player) { | |
UUID uuid = player.getUniqueId(); | |
if (getInCooldown().containsKey(uuid)) { | |
inCooldown.remove(uuid); | |
player.sendMessage(MessageUtil.getReapplyAllow()); | |
} else return; | |
} | |
public static void startCooldown(Player player) { | |
UUID uuid = player.getUniqueId(); | |
if (getInCooldown().containsKey(uuid)) return; | |
int configCount = Main.getInstance().getConfig().getInt("application.settings.reapply.cooldown"); | |
inCooldown.put(uuid, configCount); | |
int count = configCount; | |
Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable() { | |
@Override | |
public void run() { | |
if (!getInCooldown().containsKey(uuid)) { | |
endCooldown(player); | |
return; | |
} | |
if (getInCooldown().get(uuid) == 0) { | |
endCooldown(player); | |
return; | |
} | |
inCooldown.replace(uuid, getInCooldown().get(uuid) - 1); | |
} | |
}, 20, 20); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.book; | |
import me.zyraun.bukkit.applications.util.QuestionUtil; | |
import me.zyraun.bukkit.applications.util.application.ApplicationManager; | |
import me.zyraun.bukkit.applications.util.common.ItemStackBuilder; | |
import org.bukkit.Material; | |
import org.bukkit.entity.Player; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.BookMeta; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import java.util.Date; | |
import java.util.List; | |
public class BookUtil { | |
private static Date now = new Date(); | |
private static SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); | |
public static ItemStack getBook(Player player) { | |
return new ItemStackBuilder(Material.WRITTEN_BOOK) | |
.withName("§b" + player.getName() + "'s Application") | |
.withLore(new String[] { | |
"§7Date Created: §a" + format.format(now), | |
"", "§7This is an §bapplication §7submitted", | |
"§7by §b" + player.getName() + "§7.", "", | |
"§cThis application has been automatically", | |
"§csubmitted to staff." | |
}).build(); | |
} | |
public static ItemStack write(Player player) { | |
ItemStack item = getBook(player); | |
BookMeta meta = (BookMeta) item.getItemMeta(); | |
meta.setAuthor("ApplyMc"); | |
List<String> finals = new ArrayList<>(); | |
finals.add("§8••••••••••••••••••••••••••••••\n\n §6§lApplyMc\n\n§8Application by: §2" + player.getName() + "\n§8Submitted on: §2" + format.format(now) + "\n\n§8••••••••••••••••••••••••••••••\n§7Click the next page to view Q&As"); | |
for (int i = 0; i <= QuestionUtil.getQuestions().size() - 1; i++) { | |
String builder = ""; | |
builder = "§3[" + (i + 1) + "] §9" + QuestionUtil.getQuestion(i) + "\n\n§8" + ApplicationManager.getApplication(player).getAnswers().get(i) + "\n"; | |
finals.add(builder); | |
} | |
meta.setPages(finals); | |
item.setItemMeta(meta); | |
return item; | |
} | |
public static ItemStack getBook(String name) { | |
return new ItemStackBuilder(Material.WRITTEN_BOOK) | |
.withName("§b" + name + "'s Application") | |
.withLore(new String[] { | |
"§7Date Created: §a" + format.format(now), | |
"", "§7This is an §bapplication §7submitted", | |
"§7by §b" + name + "§7.", "", | |
"§cThis application has been automatically", | |
"§csubmitted to staff." | |
}).build(); | |
} | |
public static ItemStack write(String name) { | |
ItemStack item = getBook(name); | |
BookMeta meta = (BookMeta) item.getItemMeta(); | |
meta.setAuthor("ApplyMc"); | |
List<String> finals = new ArrayList<>(); | |
finals.add("§8••••••••••••••••••••••••••••••\n\n §6§lApplyMc\n\n§8Application by: §2" + name + "\n§8Submitted on: §2" + format.format(now) + "\n\n§8••••••••••••••••••••••••••••••\n§7Click the next page to view Q&As"); | |
for (int i = 0; i <= QuestionUtil.getQuestions().size() - 1; i++) { | |
String builder = ""; | |
builder = "§3[" + (i + 1) + "] §9" + QuestionUtil.getQuestion(i) + "\n\n§8" + ApplicationManager.getApplication(name).getAnswers().get(i) + "\n"; | |
finals.add(builder); | |
} | |
meta.setPages(finals); | |
item.setItemMeta(meta); | |
return item; | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.category; | |
import me.zyraun.bukkit.applications.Main; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import me.zyraun.bukkit.applications.util.common.ItemStackBuilder; | |
import org.bukkit.Material; | |
import org.bukkit.inventory.ItemStack; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Category { | |
private String categoryName; | |
private int guiItem; | |
private List<String> acceptCommands; | |
private List<String> denyCommands; | |
private List<Application> applications = new ArrayList<Application>(); | |
public Category(String name) { | |
categoryName = name; | |
load(); | |
} | |
public String getName() { return categoryName; } | |
public int getItemID() { return guiItem; } | |
public ItemStack getGUIItem() { return new ItemStackBuilder(Material.getMaterial(guiItem)).withName("§6Category: §7" + getName()).build(); } | |
public List<String> getAcceptCommands() { return acceptCommands; } | |
public List<String> getDenyCommands() { return denyCommands; } | |
public List<Application> getApplications() { return applications; } | |
public boolean isDefault() { return Main.getInstance().getConfig().getBoolean("application.categories.category." + getName() + ".default"); } | |
public void setItemID(int id) { guiItem = id; } | |
public void setAcceptCommands(List<String> commands) { acceptCommands = commands; } | |
public void setDenyCommands(List<String> commands) { denyCommands = commands; } | |
public void addAcceptCommand(String command) { acceptCommands.add(command); } | |
public void addApplication(Application application) { applications.add(application); } | |
public void load() { | |
guiItem = Main.getInstance().getConfig().getInt("application.categories.category." + getName() + ".gui-item"); | |
acceptCommands = Main.getInstance().getConfig().getStringList("application.categories.category." + getName() + ".accept-commands"); | |
denyCommands = Main.getInstance().getConfig().getStringList("application.categories.category." + getName() + ".deny-commands"); | |
} | |
public void save() { | |
Main.getInstance().getConfig().set("application.categories.category." + getName() + ".gui-item", getItemID()); | |
Main.getInstance().getConfig().set("application.categories.category." + getName() + ".accept-commands", getAcceptCommands()); | |
Main.getInstance().getConfig().set("application.categories.category." + getName() + ".deny-commands", getDenyCommands()); | |
Main.getInstance().saveConfig(); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.category; | |
import me.zyraun.bukkit.applications.Main; | |
public class CategoryData { | |
public static boolean isEnabled() { | |
return Main.getInstance().getConfig().getBoolean("application.categories.enabled"); | |
} | |
public static boolean useGUI() { | |
return Main.getInstance().getConfig().getBoolean("application.categories.use-gui"); | |
} | |
public static boolean useChat() { | |
return Main.getInstance().getConfig().getBoolean("application.categories.use-chat"); | |
} | |
public static boolean useToggle() { | |
return useGUI() == true && useGUI() == true; | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.category; | |
import me.zyraun.bukkit.applications.Main; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Set; | |
public class CategoryManager { | |
private static List<Category> categoryList = new ArrayList<Category>(); | |
public static List<Category> getCategories() { return categoryList; } | |
public static Category getDefaultCategory() { | |
for (Category c : getCategories()) { | |
if (c.isDefault()) return c; | |
} return getCategories().get(0); | |
} | |
public static void loadCategories() { | |
categoryList.clear(); | |
Set<String> categories = Main.getInstance().getConfig().getConfigurationSection("application.categories.category").getKeys(false); | |
for (String category : categories) | |
categoryList.add(new Category(category)); | |
} | |
public static void saveCategories() { | |
for (Category c : getCategories()) | |
c.save(); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.common; | |
import org.bukkit.Color; | |
import org.bukkit.Material; | |
import org.bukkit.enchantments.Enchantment; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.ItemMeta; | |
import org.bukkit.inventory.meta.LeatherArmorMeta; | |
import org.bukkit.material.MaterialData; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class ItemStackBuilder { | |
private final ItemStack ITEM_STACK; | |
public ItemStackBuilder(Material mat) { | |
ITEM_STACK = new ItemStack(mat); | |
} | |
public ItemStackBuilder(ItemStack item) { | |
ITEM_STACK = item; | |
} | |
public ItemStackBuilder withAmount(int amount) { | |
ITEM_STACK.setAmount(amount); | |
return this; | |
} | |
public ItemStackBuilder withName(String name) { | |
final ItemMeta meta = ITEM_STACK.getItemMeta(); | |
meta.setDisplayName(name); | |
ITEM_STACK.setItemMeta(meta); | |
return this; | |
} | |
public ItemStackBuilder withLore(String name) { | |
final ItemMeta meta = ITEM_STACK.getItemMeta(); | |
List<String> lore = meta.getLore(); | |
if (lore == null) { | |
lore = new ArrayList<>(); | |
} | |
lore.add(name); | |
meta.setLore(lore); | |
ITEM_STACK.setItemMeta(meta); | |
return this; | |
} | |
public ItemStackBuilder withLore(String[] name) { | |
final ItemMeta meta = ITEM_STACK.getItemMeta(); | |
List<String> lore = meta.getLore(); | |
if (lore == null) { | |
lore = new ArrayList<>(); | |
} | |
for (String s : name) | |
lore.add(s); | |
meta.setLore(lore); | |
ITEM_STACK.setItemMeta(meta); | |
return this; | |
} | |
public ItemStackBuilder withDurability(int durability) { | |
ITEM_STACK.setDurability((short) durability); | |
return this; | |
} | |
@SuppressWarnings("deprecation") | |
public ItemStackBuilder withData(int data) { | |
ITEM_STACK.setData(new MaterialData(ITEM_STACK.getType(), (byte) data)); | |
return this; | |
} | |
public ItemStackBuilder withEnchantment(Enchantment enchantment, final int level) { | |
ITEM_STACK.addUnsafeEnchantment(enchantment, level); | |
return this; | |
} | |
public ItemStackBuilder withEnchantment(Enchantment enchantment) { | |
ITEM_STACK.addUnsafeEnchantment(enchantment, 1); | |
return this; | |
} | |
public ItemStackBuilder withType(Material material) { | |
ITEM_STACK.setType(material); | |
return this; | |
} | |
public ItemStackBuilder clearLore() { | |
final ItemMeta meta = ITEM_STACK.getItemMeta(); | |
meta.setLore(new ArrayList<String>()); | |
ITEM_STACK.setItemMeta(meta); | |
return this; | |
} | |
public ItemStackBuilder clearEnchantments() { | |
for (Enchantment enchantment : ITEM_STACK.getEnchantments().keySet()) { | |
ITEM_STACK.removeEnchantment(enchantment); | |
} | |
return this; | |
} | |
public ItemStackBuilder withColor(Color color) { | |
Material type = ITEM_STACK.getType(); | |
if (type == Material.LEATHER_BOOTS || type == Material.LEATHER_CHESTPLATE || type == Material.LEATHER_HELMET | |
|| type == Material.LEATHER_LEGGINGS) { | |
LeatherArmorMeta meta = (LeatherArmorMeta) ITEM_STACK.getItemMeta(); | |
meta.setColor(color); | |
ITEM_STACK.setItemMeta(meta); | |
return this; | |
} else { | |
throw new IllegalArgumentException("withColor is only applicable for leather armor!"); | |
} | |
} | |
public ItemStack build() { | |
return ITEM_STACK; | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.common; | |
import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; | |
import net.minecraft.server.v1_8_R3.PacketPlayOutChat; | |
import org.bukkit.Bukkit; | |
import org.bukkit.ChatColor; | |
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; | |
import org.bukkit.entity.Player; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.regex.Pattern; | |
public class JsonBuilder { | |
public enum ClickAction { | |
RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL | |
} | |
public enum HoverAction { | |
SHOW_TEXT | |
} | |
private List<String> extras = new ArrayList<String>(); | |
public JsonBuilder(String... text) { | |
for (String extra : text) | |
parse(extra); | |
} | |
public JsonBuilder parse(String text) { | |
String regex = "[&�]{1}([a-fA-Fl-oL-O0-9]){1}"; | |
text = text.replaceAll(regex, "�$1"); | |
if (!Pattern.compile(regex).matcher(text).find()) { | |
withText(text); | |
return this; | |
} | |
String[] words = text.split(regex); | |
int index = words[0].length(); | |
for (String word : words) { | |
try { | |
if (index != words[0].length()) | |
withText(word).withColor("�" + text.charAt(index - 1)); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
index += word.length() + 2; | |
} | |
return this; | |
} | |
public JsonBuilder withText(String text) { | |
extras.add("{text:\"" + text + "\"}"); | |
return this; | |
} | |
public JsonBuilder withColor(ChatColor color) { | |
String c = color.name().toLowerCase(); | |
addSegment(color.isColor() ? "color:" + c : c + ":true"); | |
return this; | |
} | |
public JsonBuilder withColor(String color) { | |
while (color.length() != 1) | |
color = color.substring(1).trim(); | |
withColor(ChatColor.getByChar(color)); | |
return this; | |
} | |
public JsonBuilder withClickEvent(ClickAction action, String value) { | |
addSegment("clickEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); | |
return this; | |
} | |
public JsonBuilder withHoverEvent(HoverAction action, String value) { | |
addSegment("hoverEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); | |
return this; | |
} | |
private void addSegment(String segment) { | |
String lastText = extras.get(extras.size() - 1); | |
lastText = lastText.substring(0, lastText.length() - 1) + "," + segment + "}"; | |
extras.remove(extras.size() - 1); | |
extras.add(lastText); | |
} | |
public String toString() { | |
if (extras.size() <= 1) | |
return extras.size() == 0 ? "{text:\"\"}" : extras.get(0); | |
String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",extra:["; | |
extras.remove(0); | |
; | |
for (String extra : extras) | |
text = text + extra + ","; | |
text = text.substring(0, text.length() - 1) + "]}"; | |
return text; | |
} | |
public void sendJson(Player p) { | |
((CraftPlayer) p).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(ChatSerializer.a(toString()))); | |
} | |
public void sendAllJson() { | |
for (Player p : Bukkit.getOnlinePlayers()) | |
sendJson(p); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.freezechat.events; | |
import me.zyraun.bukkit.applications.util.freezechat.FrozenChat; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.HandlerList; | |
public class ChatFreezeEvent extends Event { | |
private static final HandlerList handlers = new HandlerList(); | |
private FrozenChat eventChat; | |
private Player eventPlayer; | |
private String defaultMessage = "§7Your chat has been frozen"; | |
private boolean cancelled = false; | |
public ChatFreezeEvent(Player player, FrozenChat frozenChat) { | |
eventChat = frozenChat; | |
eventPlayer = player; | |
} | |
public HandlerList getHandlers() { | |
return handlers; | |
} | |
public static HandlerList getHandlerList() { | |
return handlers; | |
} | |
public FrozenChat getFrozenChat() { | |
return eventChat; | |
} | |
public Player getPlayer() { return eventPlayer; } | |
public String getDefaultMessage() { return defaultMessage; } | |
public void setDefaultMessage(String message) { defaultMessage = message; } | |
public boolean isCancelled() { return cancelled; } | |
public void setCancelled(boolean value) { cancelled = true; } | |
} |
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
package me.zyraun.bukkit.applications.util.freezechat.events; | |
import me.zyraun.bukkit.applications.util.freezechat.FrozenChat; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.Event; | |
import org.bukkit.event.HandlerList; | |
public class ChatThawEvent extends Event { | |
private static final HandlerList handlers = new HandlerList(); | |
private FrozenChat eventChat; | |
private Player eventPlayer; | |
private String defaultMessage = "§7Your chat has been unfrozen"; | |
private boolean cancelled = false; | |
public ChatThawEvent(Player player, FrozenChat frozenChat) { | |
eventChat = frozenChat; | |
eventPlayer = player; | |
} | |
public HandlerList getHandlers() { | |
return handlers; | |
} | |
public static HandlerList getHandlerList() { | |
return handlers; | |
} | |
public FrozenChat getFrozenChat() { | |
return eventChat; | |
} | |
public Player getPlayer() { return eventPlayer; } | |
public String getDefaultMessage() { return defaultMessage; } | |
public void setDefaultMessage(String message) { defaultMessage = message; } | |
public boolean isCancelled() { return cancelled; } | |
public void setCancelled(boolean value) { cancelled = true; } | |
} |
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
package me.zyraun.bukkit.applications.util.freezechat; | |
import me.zyraun.bukkit.applications.util.freezechat.events.ChatFreezeEvent; | |
import me.zyraun.bukkit.applications.util.freezechat.events.ChatThawEvent; | |
import org.bukkit.Bukkit; | |
import org.bukkit.entity.Player; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class FrozenChat { | |
private Player fcPlayer; | |
private boolean frozen; | |
private String[] missedMessages; | |
public FrozenChat(Player player) { | |
FrozenChatManager.addFrozenChat(this); | |
fcPlayer = player; | |
frozen = false; | |
} | |
public Player getPlayer() { return fcPlayer; } | |
public boolean isFrozen() { return frozen; } | |
public String[] getMissedMessages() { return missedMessages; } | |
public void addMissedMessage(String message) { | |
List<String> messages = new ArrayList<>(); | |
for (String s : getMissedMessages()) { | |
messages.add(s); | |
} | |
messages.add(message); | |
missedMessages = (String[]) messages.toArray(); | |
} | |
public void freezeChat() { | |
ChatFreezeEvent event = new ChatFreezeEvent(getPlayer(), this); | |
Bukkit.getPluginManager().callEvent(event); | |
if (event.isCancelled()) return; | |
frozen = true; | |
} | |
public void thawChat() { | |
ChatThawEvent event = new ChatThawEvent(getPlayer(), this); | |
Bukkit.getPluginManager().callEvent(event); | |
if (event.isCancelled()) return; | |
frozen = false; | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.freezechat; | |
import me.zyraun.bukkit.applications.util.application.Application; | |
import me.zyraun.bukkit.applications.util.application.ApplicationManager; | |
import me.zyraun.bukkit.applications.util.freezechat.events.ChatFreezeEvent; | |
import me.zyraun.bukkit.applications.util.freezechat.events.ChatThawEvent; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.player.AsyncPlayerChatEvent; | |
public class FrozenChatHandler implements Listener { | |
@EventHandler | |
public void onChat(AsyncPlayerChatEvent e) { | |
if (!FrozenChatManager.chatIsFrozen(e.getPlayer())) return; | |
Application a = ApplicationManager.getApplication(e.getPlayer()); | |
e.setCancelled(true); | |
e.getPlayer().sendMessage(" §a" + e.getMessage()); | |
a.giveAnswer(e.getMessage()); | |
} | |
@EventHandler | |
public void onFreeze(ChatFreezeEvent e) { | |
Player p = e.getPlayer(); | |
p.sendMessage(e.getDefaultMessage()); | |
} | |
@EventHandler | |
public void onThaw(ChatThawEvent e) { | |
Player p = e.getPlayer(); | |
p.sendMessage(e.getDefaultMessage()); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.freezechat; | |
import org.bukkit.entity.Player; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class FrozenChatManager { | |
private static List<FrozenChat> frozenChats = new ArrayList<FrozenChat>(); | |
public static List<FrozenChat> getFrozenChats() { return frozenChats; } | |
public static FrozenChat getFrozenChat(Player player) { | |
for (FrozenChat fc : getFrozenChats()) { | |
if (fc.getPlayer().getUniqueId() == player.getUniqueId()) return fc; | |
} return new FrozenChat(player); | |
} | |
public static boolean chatIsFrozen(Player player) { | |
return getFrozenChat(player).isFrozen(); | |
} | |
public static void addFrozenChat(FrozenChat frozenChat) { | |
if (frozenChats.contains(frozenChat)) return; | |
frozenChats.add(frozenChat); | |
} | |
public static void removeFrozenChat(FrozenChat frozenChat) { | |
if (!frozenChats.contains(frozenChat)) return; | |
frozenChats.remove(frozenChat); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util; | |
import me.zyraun.bukkit.applications.Main; | |
import me.zyraun.bukkit.applications.util.application.task.ReapplyTask; | |
import org.bukkit.entity.Player; | |
public class MessageUtil { | |
public static String getQuestionMessage(int index) { | |
String question = QuestionUtil.getQuestions().get(index); | |
return Main.getInstance().getConfig().getString("application.messages.questions").replace("&", "§").replace("%question%", question); | |
} | |
public static String getPermissionsMessage() { | |
return Main.getInstance().getConfig().getString("application.messages.no-permissions").replace("&", "§"); | |
} | |
public static String getClosedMessage() { | |
return Main.getInstance().getConfig().getString("application.messages.applications-closed").replace("&", "§"); | |
} | |
public static String getEndMessage() { | |
return Main.getInstance().getConfig().getString("application.messages.application-end").replace("&", "§"); | |
} | |
public static String getNotificationMessage(String message) { | |
return Main.getInstance().getConfig().getString("application.messages.notification").replace("&", "§").replace("%notification%", message); | |
} | |
public static String getAlreadyApplied() { | |
return Main.getInstance().getConfig().getString("application.messages.already-applied").replace("&", "§"); | |
} | |
public static String getAcceptMessage() { | |
return Main.getInstance().getConfig().getString("application.messages.application-accept").replace("&", "§"); | |
} | |
public static String getDenyMessage() { | |
return Main.getInstance().getConfig().getString("application.messages.application-deny").replace("&", "§"); | |
} | |
public static String getReapplyDeny(Player player) { | |
if (ReapplyTask.getInCooldown().containsKey(player.getUniqueId())) | |
return Main.getInstance().getConfig().getString("application.messages.reapply-deny").replace("&", "§").replace("%cooldown%", ReapplyTask.getInCooldown().get(player.getUniqueId()) + ""); | |
else return ""; | |
} | |
public static String getReapplyAllow() { | |
return Main.getInstance().getConfig().getString("application.messages.reapply-allow").replace("&", "§"); | |
} | |
public static String getDivider() { | |
return "-----------------------------------------------------"; | |
} | |
} |
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
package me.zyraun.bukkit.applications.util; | |
import me.zyraun.bukkit.applications.Main; | |
public class PermissionUtil { | |
public static String getApply() { | |
return Main.getInstance().getConfig().getString("application.permissions.apply"); | |
} | |
public static String getNotify() { | |
return Main.getInstance().getConfig().getString("application.permissions.notifications"); | |
} | |
public static String getCheck() { | |
return Main.getInstance().getConfig().getString("application.permissions.check"); | |
} | |
public static String getOpen() { | |
return Main.getInstance().getConfig().getString("application.permissions.open"); | |
} | |
public static String getClose() { | |
return Main.getInstance().getConfig().getString("application.permissions.close"); | |
} | |
public static String getReload() { | |
return Main.getInstance().getConfig().getString("application.permissions.reload"); | |
} | |
public static String getSignCreate() { | |
return Main.getInstance().getConfig().getString("application.permissions.create-sign"); | |
} | |
public static String getSignUse() { | |
return Main.getInstance().getConfig().getString("application.permissions.use-sign"); | |
} | |
public static String getReapply() { | |
return Main.getInstance().getConfig().getString("application.permissions.reapply"); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util; | |
import me.zyraun.bukkit.applications.Main; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class QuestionUtil { | |
private static List<String> questions = new ArrayList<String>(); | |
public static List<String> getQuestions() { return questions; } | |
public static String getQuestion(int index) { | |
return getQuestions().get(index); | |
} | |
public static void loadQuestions() { | |
questions.clear(); | |
for (Object o : Main.getInstance().getConfig().getList("application.questions")) { | |
if (!(o instanceof String)) return; | |
questions.add((String) o); | |
} | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.signs; | |
import me.zyraun.bukkit.applications.Main; | |
public class SignConfig { | |
public static String getLine(int index) { | |
if (index > 4 || index < 0) return ""; | |
return Main.getInstance().getConfig().getString("application.sign.line" + index); | |
} | |
} |
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
package me.zyraun.bukkit.applications.util.signs; | |
import me.zyraun.bukkit.applications.Main; | |
import me.zyraun.bukkit.applications.util.MessageUtil; | |
import me.zyraun.bukkit.applications.util.PermissionUtil; | |
import me.zyraun.bukkit.applications.util.application.ApplicationManager; | |
import org.bukkit.Material; | |
import org.bukkit.block.Block; | |
import org.bukkit.block.Sign; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.block.Action; | |
import org.bukkit.event.block.SignChangeEvent; | |
import org.bukkit.event.player.PlayerInteractEvent; | |
public class SignHandler implements Listener { | |
@EventHandler | |
public void onSignChange(SignChangeEvent e) { | |
if (!e.getPlayer().hasPermission(PermissionUtil.getSignCreate())) return; | |
if (!e.getLine(0).equalsIgnoreCase("[applymc]")) return; | |
e.setLine(0, SignConfig.getLine(1).replace("&", "§")); | |
e.setLine(1, SignConfig.getLine(2).replace("&", "§")); | |
e.setLine(2, SignConfig.getLine(3).replace("&", "§")); | |
e.setLine(3, SignConfig.getLine(4).replace("&", "§")); | |
e.getPlayer().sendMessage("§2[ApplyMc] §aCreated ApplyMc application sign"); | |
} | |
@EventHandler | |
public void onPlayerInteract(PlayerInteractEvent e) { | |
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { | |
Block b = e.getClickedBlock(); | |
if ((b.getType() == Material.SIGN_POST) || (b.getType() == Material.WALL_SIGN)) { | |
Sign s = (Sign)b.getState(); | |
Player p = e.getPlayer(); | |
if (s.getLine(0).equalsIgnoreCase(SignConfig.getLine(1))) { | |
if (p.hasPermission(PermissionUtil.getSignUse())) { | |
if (Main.applicationsOpen()) { | |
if (ApplicationManager.getApplication(e.getPlayer()).getAnswers().size() == 0) { | |
ApplicationManager.start(e.getPlayer()); | |
} else { | |
e.getPlayer().sendMessage(MessageUtil.getAlreadyApplied()); | |
} | |
} else { | |
e.getPlayer().sendMessage(MessageUtil.getClosedMessage()); | |
} | |
} else e.getPlayer().sendMessage(MessageUtil.getPermissionsMessage()); | |
} | |
} | |
} | |
} | |
} |
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
Manifest-Version: 1.0 | |
Main-Class: ApplyMc | |
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
name: ApplyMc | |
version: 1.5.8 | |
description: Easy application forms for Minecraft servers. | |
authors: [Zyraun, Crace] | |
main: me.zyraun.bukkit.applications.Main | |
commands: | |
applymc: | |
description: Base command for ApplyMc. | |
apply: | |
description: Start the application process. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment