Advertisement
Guest User

Untitled

a guest
Mar 24th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.60 KB | None | 0 0
  1. package me.funzocker1.MtsSystem;
  2.  
  3.  
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11.  
  12. import net.minecraft.server.v1_5_R1.Position;
  13.  
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.Location;
  16. import org.bukkit.block.Block;
  17. import org.bukkit.block.Sign;
  18. import org.bukkit.configuration.file.FileConfiguration;
  19. import org.bukkit.configuration.file.YamlConfiguration;
  20. import org.bukkit.craftbukkit.v1_5_R1.block.CraftSign;
  21. import org.bukkit.event.Listener;
  22. import org.bukkit.plugin.java.JavaPlugin;
  23.  
  24. import SignChangeEvent.SignChangeEvent1;
  25.  
  26. public class MtsSystem extends JavaPlugin implements Listener {
  27.     private FileConfiguration ProsiebenLocationConfig = null;
  28.     private FileConfiguration ProsiebenTimeConfig = null;
  29.     private File ProsiebenTimeFile = null;
  30.     private File ProsiebenLocationConfigFile = null;
  31.       public String stringKey = "BLOCKSXX12345";
  32.     @Override
  33.     public void onEnable() {
  34.         System.out.println("Mts by Funzocker1 Enabled. ");
  35.         saveConfig();
  36.  
  37.  
  38.         getProSiebenTime().set("d", 1);
  39.        
  40.         new SignChangeEvent1(this);
  41.         reloadProsiebenLocation();
  42.        
  43.         getProsiebenLocation().options().header("##AUF KEINEN FALL ETWAS EINTRAGEN ODER ENTFERNEN");
  44.         saveProSiebenLocation();
  45.  
  46.         saveProSiebentimes();
  47.         saveProSiebentimes();
  48.         reloadProSiebenTime();
  49.         this.getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
  50.  
  51.             @Override
  52.             public void run() {
  53.                 Date d = new Date();
  54.                 SimpleDateFormat t = new SimpleDateFormat("dd/MM/yyyy/HH/mm");
  55.                 System.out.println(t.format(d));
  56.                 if(getProSiebenTime().contains(t.format(d) )== true) {
  57.                     System.out.println("Schiler werden upgedatet");
  58.                    
  59.                            
  60.                    
  61.                    
  62.                     String[] help = getProsiebenLocation().getString(stringKey).split(Position.SepPos);
  63.                     for (int i = 0; i < help.length; i++) {
  64.                         String[] p = help[i].split(Position.SepCo);
  65.                         double x = Double.parseDouble(p[0]);
  66.                         double y = Double.parseDouble(p[1]);
  67.                         double z = Double.parseDouble(p[2]);
  68.                         Position pos = new Position(x, y, z);
  69.                    
  70.                         Location loc = new Location(getServer().getWorld("world"), pos.x, pos.y, pos.z);
  71.                          
  72.                     Sign s = (Sign) loc.getBlock().getState();
  73.                         s.setLine(0, ChatColor.GOLD + "Pro7");
  74.                         s.setLine(1, getProSiebenTime().getString(t.format(d)));
  75.                         s.getLocation().setX(pos.x);
  76.                         s.getLocation().setY(pos.y);
  77.                         s.getLocation().setZ(pos.z);
  78.                        
  79.                     }
  80.                    
  81.                    
  82.                 }else  {
  83.                     System.out.println("hi");
  84.                 }
  85.                
  86.                
  87.             }
  88.            
  89.         }, 0, 1200);
  90.        
  91.     }
  92.     @Override
  93.     public void onDisable() {
  94.        
  95.     }
  96.  
  97.       public String getConfigForPath() {
  98.             return getProsiebenLocation().getString(this.stringKey);
  99.           }
  100.  
  101.           public void addNewConfig() {
  102.               getProsiebenLocation().addDefault(this.stringKey, "");
  103.               getProsiebenLocation().options().copyDefaults();
  104.             saveProSiebenLocation();
  105.           }
  106.  
  107.           public void saveValue(String s) {
  108.               getProsiebenLocation().set(this.stringKey, s);
  109.             saveProSiebenLocation();
  110.           }
  111.          
  112.          
  113.             public void saveProSiebenLocation() {
  114.                 if (ProsiebenLocationConfig == null || ProsiebenLocationConfigFile == null) {
  115.                 return;
  116.                 }
  117.                 try {
  118.                     ProsiebenLocationConfig.save(ProsiebenLocationConfigFile);
  119.                 } catch (IOException ex) {
  120.                     Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Konfiguration konnte nicht nach " + ProsiebenLocationConfigFile + " geschrieben werden.", ex);
  121.                 }
  122.             }
  123.             public FileConfiguration getProsiebenLocation() {
  124.                 if (ProsiebenLocationConfig == null) {
  125.                     reloadProsiebenLocation();
  126.                 }
  127.                 return ProsiebenLocationConfig;
  128.             }
  129.             public void reloadProsiebenLocation() {
  130.                 if (ProsiebenLocationConfigFile == null) {
  131.                 ProsiebenLocationConfigFile = new File(getDataFolder(), "ProsiebenLocation.yml");
  132.                 }
  133.                 ProsiebenLocationConfig = YamlConfiguration.loadConfiguration(ProsiebenLocationConfigFile);
  134.              
  135.                 // Look for defaults in the jar
  136.                 InputStream defConfigStream = this.getResource("ProsiebenLocation.yml");
  137.                 if (defConfigStream != null) {
  138.                     YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
  139.                     ProsiebenLocationConfig.setDefaults(defConfig);
  140.                 }
  141.             }
  142.            
  143.             //###########################################################################################################################
  144.             public void saveProSiebentimes() {
  145.                 if (ProsiebenTimeConfig == null || ProsiebenTimeFile == null) {
  146.                 return;
  147.                 }
  148.                 try {
  149.                     ProsiebenTimeConfig.save(ProsiebenTimeFile);
  150.                 } catch (IOException ex) {
  151.                     Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Konfiguration konnte nicht nach " + ProsiebenTimeFile + " geschrieben werden.", ex);
  152.                 }
  153.             }
  154.             public FileConfiguration getProSiebenTime() {
  155.                 if (ProsiebenTimeConfig == null) {
  156.                     reloadProSiebenTime();
  157.                 }
  158.                 return ProsiebenTimeConfig;
  159.             }
  160.             public void reloadProSiebenTime() {
  161.                 if (ProsiebenTimeFile == null) {
  162.                     ProsiebenTimeFile = new File(getDataFolder(), "ProsiebenTimeFile.yml");
  163.                 }
  164.                 ProsiebenTimeConfig = YamlConfiguration.loadConfiguration(ProsiebenTimeFile);
  165.              
  166.                 // Look for defaults in the jar
  167.                 InputStream defConfigStream = this.getResource("ProsiebenTimeFile.yml");
  168.                 if (defConfigStream != null) {
  169.                     YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
  170.                     ProsiebenTimeConfig.setDefaults(defConfig);
  171.                 }
  172.             }
  173.             class Position {
  174.  
  175.                 public static final  String SepPos = ":";
  176.                 public static final  String SepCo = "/";
  177.  
  178.                 public Position(double x, double y, double z) {
  179.                     this.x = x;
  180.                     this.y = y;
  181.                     this.z = z;
  182.                 }
  183.  
  184.                 private double x = 0;
  185.                 private double y = 0;
  186.                 private double z = 0;
  187.  
  188.                 public String getStringforCoordinates() {
  189.                     return String.valueOf(x) + SepCo + String.valueOf(y) + SepCo
  190.                             + String.valueOf(z);
  191.                 }
  192.  
  193.                 public boolean isInRadius(Position pos, double r) {
  194.                     return getDistance(pos) <= r;
  195.                 }
  196.  
  197.                 public double getDistance(Position pos) {
  198.                     double d = Math.sqrt(Math.pow((x - pos.x), 2)
  199.                             + Math.pow((y - pos.y), 2) + Math.pow((z - pos.z), 2));
  200.                     return d;
  201.                 }
  202.             }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement