Advertisement
Guest User

a

a guest
Apr 18th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. package me.pineabe.modernmc;
  2.  
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Random;
  8.  
  9. import net.milkbowl.vault.economy.Economy;
  10. //import net.milkbowl.vault.economy.EconomyResponse;
  11.  
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.ChatColor;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandExecutor;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.plugin.Plugin;
  19.  
  20. public class Commands implements CommandExecutor {
  21. public final Plugin plugin;
  22. public static Economy econ = null;
  23. public final HashMap<Player, Integer> hm = new HashMap<Player, Integer>();
  24. public final HashMap<String, Integer> map = new HashMap<String, Integer>();
  25.  
  26. public Commands(Plugin plugin){
  27. this.plugin = plugin;
  28. }
  29. @Override
  30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
  31. Player p = (Player) sender;
  32. //EconomyResponse r = econ.withdrawPlayer(p.getName(), plugin.getConfig().getInt("TicketFare"));
  33. int wn = new Random().nextInt(plugin.getConfig().getInt("TicketsForSale"));
  34. int jackpot = plugin.getConfig().getInt("Jackpot");
  35. int fare = plugin.getConfig().getInt("TicketFare");
  36. if(commandLabel.equalsIgnoreCase("lotto")){
  37. if(args.length == 0) {
  38.  
  39. if(p.hasPermission("lotto.admin")){
  40.  
  41. p.sendMessage(ChatColor.GREEN + "------(MCLotto Help)------");
  42. p.sendMessage(ChatColor.DARK_GREEN + "/lotto buyticket (1 - " + plugin.getConfig().getInt("TicketsForSale") + ") " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Purchase a lotto ticket");
  43. p.sendMessage(ChatColor.DARK_GREEN + "/lotto jackpot " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Shows the current jackpot and ticketfare");
  44. p.sendMessage(ChatColor.DARK_GREEN + "/lotto start " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Selects a random number and allows tickets to be bought");
  45. p.sendMessage(ChatColor.DARK_GREEN + "/lotto stop " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Stop ticket sales and disallow the winner");
  46. p.sendMessage(ChatColor.DARK_GREEN + "/lotto setjackpot " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Set the jackpot using in-game commands");
  47. p.sendMessage(ChatColor.DARK_GREEN + "/lotto setfare " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Set the ticket fare with in-game commands");
  48. p.sendMessage(ChatColor.DARK_GREEN + "/lotto setmaxtickets " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Set the max ticket number with in-game commands");
  49. }
  50.  
  51. else if(p.hasPermission("lotto.user")){
  52. p.sendMessage(ChatColor.GREEN + "------(MCLotto Help)------");
  53. p.sendMessage(ChatColor.DARK_GREEN + "/lotto buyticket (1 - " + plugin.getConfig().getInt("TicketsForSale") + ") " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Purchase a lotto ticket");
  54. p.sendMessage(ChatColor.DARK_GREEN + "/lotto jackpot " + ChatColor.WHITE + "|" + ChatColor.AQUA + " Shows the current jackpot and ticketfare");
  55. }
  56. }
  57. else if(args.length == 1 ){
  58. if(args[0].equalsIgnoreCase("buyticket")){
  59. p.sendMessage(ChatColor.RED + "Syntax Error: Please define a ticket value");
  60. }
  61.  
  62. else if(args[0].equalsIgnoreCase("stop")){
  63. if(map.containsKey("le")){
  64. if(p.hasPermission("lotto.admin")){
  65. map.remove("le");
  66. Bukkit.broadcastMessage(ChatColor.GOLD + "The lotto has been" + ChatColor.RED + " stopped");
  67. }
  68. }
  69. else{
  70. p.sendMessage(ChatColor.RED + "The lotto has not started yet!");
  71. }
  72. }
  73.  
  74. else if(args[0].equalsIgnoreCase("jackpot")){
  75. if(p.hasPermission("lotto.user") || p.hasPermission("lotto.admin")){
  76. if(!map.containsKey("le")){
  77. p.sendMessage(ChatColor.RED + "The lotto has not started yet!");
  78. }
  79. else{
  80. p.sendMessage(ChatColor.YELLOW + "The jackpot is: " + jackpot + " " + econ.currencyNamePlural());
  81. p.sendMessage(ChatColor.YELLOW + "The ticket fare is: " + fare + " " + econ.currencyNamePlural());
  82. }
  83. }
  84. }
  85. if(args[0].equalsIgnoreCase("start")){
  86. if(p.hasPermission("lotto.admin")){
  87. if(!map.containsKey("le")){
  88. map.put("le", null);
  89. map.put("wn", wn);
  90. p.sendMessage(ChatColor.YELLOW + "You have now started a lotto with the winning number as " + wn);
  91. Bukkit.broadcastMessage(ChatColor.GOLD + "A lotto has now commenced! (/lotto)");
  92. }
  93. else{
  94. p.sendMessage(ChatColor.RED + "The Lotto has already started");
  95. }
  96. }
  97. }
  98. }
  99. else if(args.length == 2){
  100. if(args[0].equalsIgnoreCase("buyticket")){
  101.  
  102. if(p.hasPermission("lotto.user") || p.hasPermission("lotto.admin")){
  103. if(!map.containsKey("le")){
  104. p.sendMessage(ChatColor.RED +"The lotto has not started yet!");
  105. }
  106. else if(hm.containsKey(p)){
  107. p.sendMessage(ChatColor.RED + "Error: You have already purchased a ticket");
  108. }
  109. //else if(r.transactionSuccess()) {
  110. else {
  111. List<Player> onlinePlayers = Arrays.asList(Bukkit.getServer().getOnlinePlayers());
  112. Iterator<Player> iterator = onlinePlayers.iterator();
  113. while(iterator.hasNext()){
  114. Player onlinePlayer = iterator.next();
  115. if(args[1].equals(hm.get(onlinePlayer))){
  116. p.sendMessage(ChatColor.RED + onlinePlayer.getName() + " is in ownership of this ticket");
  117. }
  118. }
  119. if(!(Integer.parseInt(args[1]) == (map.get("wn")))){
  120. Bukkit.broadcastMessage(ChatColor.GREEN + p.getName() + " has purchased lotto ticket #" + args[1]);
  121. hm.put(p, Integer.parseInt(args[1]));
  122. }
  123. else{
  124. econ.depositPlayer(p.getName(), jackpot);
  125. map.remove("le");
  126. Bukkit.broadcastMessage(ChatColor.GREEN + p.getDisplayName() + " has won the lotto with the jackpot of " + jackpot + " " + econ.currencyNamePlural() );
  127. }
  128. }
  129. //}
  130. //else {
  131. //p.sendMessage(String.format(ChatColor.RED + "An error occured: %s", r.errorMessage));
  132. //}
  133.  
  134.  
  135.  
  136. }
  137. }
  138. else if(args[0].equalsIgnoreCase("setjackpot")){
  139. if(p.hasPermission("lotto.set")){
  140. p.sendMessage(ChatColor.YELLOW + "Jackpot set to " + args[1]);
  141. plugin.getConfig().set("Jackpot", Integer.parseInt(args[1]));
  142. plugin.saveConfig();
  143. }
  144. }
  145. else if(args[0].equalsIgnoreCase("setfare")){
  146. if(p.hasPermission("lotto.set")){
  147. p.sendMessage(ChatColor.YELLOW + "Ticket fare set to " + args[1]);
  148. plugin.getConfig().set("TicketFare", Integer.parseInt(args[1]));
  149. plugin.saveConfig();
  150. }
  151. }
  152. else if(args[0].equalsIgnoreCase("setmaxtickets")){
  153. if(p.hasPermission("lotto.set")){
  154. p.sendMessage(ChatColor.YELLOW + "Max ticket number set to " + args[1]);
  155. plugin.getConfig().set("TicketsForSale", Integer.parseInt(args[1]));
  156. plugin.saveConfig();
  157. }
  158. }
  159. }
  160. else if(args.length >= 3) {
  161. p.sendMessage(ChatColor.RED + "Syntax Error: Unrecognized argument " + args[2]);
  162. }
  163. }
  164. return false;
  165. }
  166.  
  167.  
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement