[EventManager]Help with event block while typing commands

Discussion in 'Plugin Development' started by Brugz, Jul 8, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Brugz

    What i want to do then if player types /event its will tp him like its should do and its does but i want it also save the items he had, the location he was on and tp him too the event with cleared inventory.
    and i also wanna do then if the played typed event and its will teleport him and disable all the commands except for /eventquit which return him back too where he was and give him back his items.
    so here is my script currectly:

    BTW I learn better by seeing examples.
    Code:Java
    1.  
    2. package me.eventwarping;
    3.  
    4.  
    5. import java.util.HashMap;
    6. import java.util.Map;
    7. import java.util.logging.Logger;
    8.  
    9.  
    10.  
    11. import org.bukkit.Bukkit;
    12. import org.bukkit.ChatColor;
    13. import org.bukkit.Location;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandSender;
    16. import org.bukkit.entity.Player;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class EventManager extends JavaPlugin {
    20.  
    21. public static EventManager plugin;
    22. public Logger logger;
    23.  
    24. public final static Map<String, Location> events = new HashMap<String, Location>();
    25. public String lastEvent = null;
    26.  
    27. public void onEnable() {
    28. plugin = this;
    29. logger = getLogger();
    30. }
    31.  
    32. public void onDisble() {
    33. }
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd,
    36. String commandLabel, String args[]) {
    37. Player player = (Player) sender;
    38. if (commandLabel.equalsIgnoreCase("startevent")) {
    39. if (player.isOp()) {
    40. if (args.length == 0) {
    41. player.sendMessage(ChatColor.RED
    42. + "Usge /startevent <eventname>");
    43. } else {
    44. Location location = player.getLocation();
    45. events.put(args[0], location);
    46. lastEvent = args[0];
    47. player.sendMessage(ChatColor.GREEN + "Event " + args[0]
    48. + " has started!");
    49. Bukkit.broadcastMessage(ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.GREEN + args[0]
    50. + " event has started, to join type /event!");
    51. }
    52. }
    53. } else if (commandLabel.equalsIgnoreCase("event")) {
    54. if (args.length == 0) {
    55. if (lastEvent == null) {
    56. player.sendMessage(ChatColor.RED
    57. + "No event started yet");
    58. return true;
    59. }
    60. player.teleport(events.get(lastEvent));
    61. } else {
    62. if (!events.containsKey(args[0])) {
    63. player.sendMessage(ChatColor.RED
    64. + "There's no event with this name");
    65. return true;
    66. }
    67. player.teleport(events.get(args[0]));
    68. }
    69. player.sendMessage(
    70. ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.GREEN + "You have joined the event. Good Luck!");
    71.  
    72. }else if(commandLabel.equalsIgnoreCase("finishevent")) {
    73. if (player.isOp()) {
    74. if(args.length == 0){
    75. player.sendMessage(ChatColor.RED + "Usge /finishevent <eventname> <player name>.");
    76. } else {
    77. events.remove(args[0]);
    78. Bukkit.broadcastMessage(ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.GREEN + args[0] + " Event has finished the winner is: " + args[1]);
    79. }
    80. }
    81. }else if(commandLabel.equalsIgnoreCase("closeevent")){
    82. if(player.isOp()) {
    83. events.remove(args[0]);
    84. player.sendMessage(ChatColor.GREEN + "The event warp has been closed!");
    85. }
    86. }else if(commandLabel.equalsIgnoreCase("eventmessage")){
    87. if(player.isOp()){
    88. if(args.length == 0){
    89. player.sendMessage(ChatColor.RED + "Usge /eventmessage <message>");
    90. if(args.length == 1){
    91. Bukkit.broadcastMessage(ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.YELLOW + args[0]);
    92. if(args.length == 2){
    93. Bukkit.broadcastMessage(ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.YELLOW + args[0] + " " + args[1]);
    94. if(args.length == 3){
    95. Bukkit.broadcastMessage(ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.YELLOW + args[0] + " " + args[2]);
    96. if(args.length == 4){
    97. Bukkit.broadcastMessage(ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.YELLOW + args[0] + " " + args[3]);
    98. if(args.length == 5){
    99. Bukkit.broadcastMessage(ChatColor.GREEN + "[" + ChatColor.YELLOW + "EventManager" + ChatColor.GREEN + "]" + ChatColor.YELLOW + args[0] + " " + args[4]);
    100. }
    101. return false;
    102. }
    103. }
    104. }
    105. }
    106. }
    107. }
    108. return false;
    109. }
    110. return false;
    111. }
    112. }
     
  2. Offline

    sayaad

    Sorry for the lack of code because im not feeling like to code an entire class with just a basic text editor but here is an algorithm (also excuse m bad spelling, im speed typein this) :

    Note : May be a bit to complex.

    It seems that it will be easier to create an ArrayList<String> that holds three variables in one string in one line of the arraylist. You do this by converting the variables to strings (Location;Event Name;PlayerName) adding a seperator between them (in this case, ";").

    Note : You convert Location to string by splitting the location into World,X, Y, Z, Yaw ad Pitch , convert those booleans/floats to strings then add them into one string seperating them with a seperator (in this case ",").

    Adding variables to the arraylist :

    Use the above method to make a string that in in this format :

    World,X,Y,Z,Yaw,Pitch;EventName;PlayersName

    Then add that string to the arraylist with arraylist.add(string);

    Getting Variables from the arraylist :
    Here comes the hard part...

    Create a for loop that loops through all the variables in the arraylist :

    Code:java
    1. for (int i = 0; i < ArrayList.size(); i++){
    2. String unformattedData = ArrayList.get(i);
    3. }


    in that loop we are now going to split it into your variables

    Code:java
    1. for (int i = 0; i < ArrayList.size(); i++){
    2. String unformattedData = ArrayList.get(i);
    3.  
    4. String[] Data = unformattedData.split(";");
    5.  
    6. String locationString = Data[0];
    7. String PlayersName = Data[1];
    8. String EventName = Data[2];
    9.  
    10. //Now lets get the location variable as a location
    11.  
    12. String[] LocaionData = locationString.split(",");
    13.  
    14. double x = Double.parseDouble(LocationData[1]);
    15. double y = Double.parseDouble(LocationData[2]);
    16. double z = Double.parseDouble(LocationData[3]);
    17. Float Yaw = Float.parseFloat(LocationData[4]);
    18. Float Pitch = Float.parseFloat(LocationData[5]);
    19. World w = this.getServer().getWorld(LocationData[0]);
    20.  
    21. Location loc = new Location(w, x, y, z, Yaw, Pitch);
    22.  
    23. /*so here are your variable names :
    24. location = loc
    25. PlayersName = the player's name
    26. EventName = the event's name
    27. */
    28.  
    29. //remember, these variables changes for every line in the arraylist so add you'r mass amounts of if loops to check if the player name matches, if the event name matches etc...
    30.  
    31. }
     
Thread Status:
Not open for further replies.

Share This Page