Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.20 KB | None | 0 0
  1. package Commands;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.util.HashMap;
  7.  
  8. import me.nicocrafting.main.Main;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.Location;
  12. import org.bukkit.World;
  13. import org.bukkit.configuration.InvalidConfigurationException;
  14. import org.bukkit.configuration.file.FileConfiguration;
  15. import org.bukkit.configuration.file.YamlConfiguration;
  16. import org.bukkit.entity.Player;
  17.  
  18. public class Funktionen {
  19.  
  20.     public static void sendMenu(Player p){
  21.        
  22.         p.sendMessage(Main.pluginName+"/game join [Arena]    Joine der Arena");
  23.         p.sendMessage(Main.pluginName+"/game leave           Verlasse die Arena");
  24.        
  25.     }
  26.    
  27.     public static void sendAdminMenu(Player p){
  28.         p.sendMessage("§6-------------- §a[Admin Commands] §6---------------");
  29.         p.sendMessage(Main.pluginName+"/game join [Arena]    Joine der Arena");
  30.         p.sendMessage(Main.pluginName+"/game leave           Verlasse die Arena");
  31.         p.sendMessage(Main.pluginName+"/game create [Arena]   Erstelle eine Arena");
  32.         p.sendMessage(Main.pluginName+"/game delete [Arena]   Lösche eine Arena");
  33.     }
  34.    
  35.     public static void createArena(Player p, String ArenaName) throws IOException{
  36.         File arena = new File("plugins//Game//Arenas//"+ArenaName+".yml");
  37.         if(arena.exists()){
  38.             p.sendMessage("§6Diese Arena existiert schon");
  39.         }else{
  40.             FileConfiguration cfg = YamlConfiguration.loadConfiguration(arena);
  41.            
  42.             Location loc = p.getLocation();
  43.             cfg.set("MaxPlayers", 4);
  44.             cfg.set("PosX", loc.getX());
  45.             cfg.set("PosY", loc.getY());
  46.             cfg.set("PosZ", loc.getZ());
  47.             cfg.set("Yaw", loc.getYaw());
  48.             cfg.set("Pitch", loc.getPitch());
  49.             cfg.set("World", p.getWorld().getName());
  50.             cfg.save(arena);
  51.            
  52.             p.sendMessage("§6Arena "+ ArenaName + " erstellt");
  53.         }
  54.     }
  55.    
  56.     public static void createArenaWarp(Player p, String ArenaName) throws IOException{
  57.         File arena = new File("plugins//Game//Arenas//"+ArenaName+".yml");
  58.         if(arena.exists()){
  59.             p.sendMessage("§6Der ArenaWarp existiert schon");
  60.         }else{
  61.             FileConfiguration cfg = YamlConfiguration.loadConfiguration(arena);
  62.            
  63.             Location loc = p.getLocation();
  64.             cfg.set("ArenaPosX", loc.getX());
  65.             cfg.set("ArenaPosY", loc.getY());
  66.             cfg.set("ArenaPosZ", loc.getZ());
  67.             cfg.set("ArenaYaw", loc.getYaw());
  68.             cfg.set("ArenaPitch", loc.getPitch());
  69.             cfg.set("ArenaWorld", p.getWorld().getName());
  70.             cfg.save(arena);
  71.            
  72.             p.sendMessage("§6Du hast den Arena Warp für die Arena "+ ArenaName + " erstellt");
  73.         }
  74.     }
  75.    
  76.    
  77.    
  78.    
  79.        
  80.         public static void delArena(Player p, String ArenaName){
  81.             File arena = new File("plugins//Game//Arenas//"+ArenaName+".yml");
  82.             if(arena.exists()){
  83.                 arena.delete();
  84.                 p.sendMessage("§6Arena erfolgreich gelöscht");
  85.         }else{
  86.             p.sendMessage("§6Arena existiert nicht");
  87.         }
  88.     }
  89.  
  90.     public static void joinArena(Player p, String ArenaName) throws FileNotFoundException, IOException, InvalidConfigurationException{
  91.         File arena = new File("plugins//Game//Arenas//"+ArenaName+".yml");
  92.         if(!arena.exists()){
  93.             p.sendMessage("§6Diese Arena existiert nicht!");
  94.         }else{
  95.             if(!Main.inGamePlayers.containsKey(p.getName())){
  96.             Main.inGamePlayers.put(p.getName(), ArenaName);
  97.            
  98.             FileConfiguration cfg = YamlConfiguration.loadConfiguration(arena);
  99.             cfg.load(arena);
  100.             Location loc = p.getLocation();
  101.             double x = (double) cfg.get("PosX", loc.getX());
  102.             double y = (double) cfg.get("PosY", loc.getY());
  103.             double z = (double) cfg.get("PosZ", loc.getZ());
  104.             double yaw = (double) cfg.get("Yaw", loc.getYaw());
  105.             double pitch = (double) cfg.get("Pitch", loc.getPitch());
  106.             String worldName = cfg.getString("World");
  107.            
  108.             World world = Bukkit.getWorld(worldName);
  109.             loc.setWorld(world);
  110.             loc.setX(x);
  111.             loc.setY(y);
  112.             loc.setZ(z);
  113.             loc.setYaw((float) yaw);
  114.             loc.setPitch((float) pitch);
  115.             p.teleport(loc);
  116.            
  117.            
  118.             p.sendMessage("§6Du bist der Arena "+ ArenaName + " beigetreten!");
  119.            
  120.            
  121.             }else{
  122.                 p.sendMessage("§6Du bist schon in einer Arena!");
  123.             }
  124.        
  125.         }
  126.    
  127.     }
  128.    
  129.     public static void leaveArena(Player p){
  130.        
  131.         if(Main.inGamePlayers.containsKey(p.getName())){
  132.             Main.inGamePlayers.remove(p.getName());
  133.             Location l = p.getWorld().getSpawnLocation();
  134.             p.teleport(l);
  135.             p.sendMessage("§6Du hast die Arena verlassen");
  136.         }else{
  137.             p.sendMessage("§6Du in keiner Arena");
  138.         }
  139.        
  140.        
  141.     }
  142.    
  143.     public static void sendMessage(HashMap<String, String> hplayer, String ArenaName, String message){
  144.         Player[] players = Bukkit.getOnlinePlayers();
  145.         for(int i = 0; i < players.length; i++){
  146.             Player z = players[i];
  147.             if(hplayer.containsKey(z.getName())){
  148.                 if(hplayer.get(z.getName()).equals(ArenaName)){
  149.                     z.sendMessage(Main.pluginName+message);
  150.                 }
  151.             }
  152.         }
  153.     }  
  154.     public static void startGame(HashMap<String, String> hplayer, String ArenaName) throws FileNotFoundException, IOException, InvalidConfigurationException{
  155.         Funktionen.sendMessage(hplayer, ArenaName, "§6Das Spiel wurde von einem Admin gestartet!");
  156.         Funktionen.teleport(hplayer, ArenaName);
  157.     }
  158.     public static void teleport(HashMap<String, String> hplayer, String ArenaName) throws FileNotFoundException, IOException, InvalidConfigurationException{
  159.         Player[] players = Bukkit.getOnlinePlayers();
  160.         for(int i = 0; i < players.length; i++){
  161.             Player a = players[i];
  162.             if(hplayer.containsKey(a.getName())){
  163.                 if(hplayer.get(a.getName()).equals(ArenaName)){
  164.                     File arena = new File("plugins//Game//Arenas//"+ArenaName+".yml");
  165.                     FileConfiguration cfg = YamlConfiguration.loadConfiguration(arena);
  166.                     cfg.load(arena);
  167.                     Location loc = a.getLocation();
  168.                     double x = (double) cfg.get("PosX", loc.getX());
  169.                     double y = (double) cfg.get("PosY", loc.getY());
  170.                     double z = (double) cfg.get("PosZ", loc.getZ());
  171.                     double yaw = (double) cfg.get("Yaw", loc.getYaw());
  172.                     double pitch = (double) cfg.get("Pitch", loc.getPitch());
  173.                     String worldName = cfg.getString("World");
  174.                    
  175.                     World world = Bukkit.getWorld(worldName);
  176.                     loc.setWorld(world);
  177.                     loc.setX(x);
  178.                     loc.setY(y);
  179.                     loc.setZ(z);
  180.                     loc.setYaw((float) yaw);
  181.                     loc.setPitch((float) pitch);
  182.                     a.teleport(loc);
  183.                    
  184.                    
  185.                 }
  186.             }
  187.         }
  188.        
  189.     }
  190.    
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement