Guest User

Staff.java

a guest
Jan 7th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. package eu.trinitydev.staff.commands;
  2.  
  3. import eu.trinitydev.staff.Core;
  4. import net.md_5.bungee.api.ChatColor;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandExecutor;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10.  
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. /**
  15. * Created by Thiemo on 7-1-2016.
  16. * No part of this publication may be reproduced, distributed, or transmitted in any form or by any means.
  17. * Copyright © 2016 by Thiemo
  18. */
  19. public class Staff implements CommandExecutor {
  20.  
  21. private Core plugin;
  22.  
  23. public Staff(Core instance) {
  24. this.plugin = instance;
  25. }
  26.  
  27. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  28. if (!(sender instanceof Player)) {
  29. return false;
  30. }
  31.  
  32. Player p = (Player) sender;
  33. if (args.length == 0) {
  34. List<String> display = plugin.getConfig().getStringList("display");
  35. List<String> staff = plugin.getConfig().getStringList("staffs");
  36. List<String> on_staff = new ArrayList<String>();
  37. for(String d : display) {
  38. if(d.contains("%list") && d.contains("%status")) {
  39. for(String s : staff) {
  40. Player st = Bukkit.getPlayer(s);
  41. if(st != null) {
  42. on_staff.add(s);
  43. }
  44.  
  45. String on = isOnline(on_staff, s) ? plugin.getConfig().getString("status.online") : plugin.getConfig().getString("status.offline");
  46. p.sendMessage(ChatColor.translateAlternateColorCodes('&', d.replace("%list", s).replace("%status", on)));
  47. }
  48. } else {
  49. if(d.contains("%amount")) {
  50. d = d.replace("%amount", String.valueOf(on_staff.size()));
  51. }
  52. p.sendMessage(ChatColor.translateAlternateColorCodes('&', d));
  53. }
  54. }
  55. } else if (args.length == 1) {
  56. if(args[0].equalsIgnoreCase("reload")) {
  57. if(p.hasPermission("staff.reload")) {
  58. plugin.reloadConfig();
  59. p.sendMessage("\n" + ChatColor.YELLOW + "> Staffs Config.yml has been reloaded" + "\n ");
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65.  
  66. private boolean isOnline(List<String> l, String s) {
  67. if (l.contains(s)) {
  68. return true;
  69. }
  70.  
  71. return false;
  72. }
  73.  
  74. }
Add Comment
Please, Sign In to add comment