Browse Source

* added 1.11 support + fixed some messages

Linus 8 years ago
parent
commit
274ffc935f

+ 1 - 1
TimeIsMoney2/src/de/Linus122/TimeIsMoney/Cmd.java

@@ -14,7 +14,7 @@ public class Cmd implements CommandExecutor {
 	public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] arg3) {
 		if(cs.hasPermission("tim.reload")){
 			main.reload();
-			cs.sendMessage("§aTime is Money §cv" + main.pl_version + " §aReloaded!");
+			cs.sendMessage("§aTime is Money §cv" + main.PL_VERSION + " §areloaded!");
 			
 		}
 		return true;

+ 8 - 7
TimeIsMoney2/src/de/Linus122/TimeIsMoney/Main.java

@@ -29,6 +29,7 @@ import org.bukkit.command.PluginCommand;
 import org.bukkit.command.SimpleCommandMap;
 import org.bukkit.configuration.file.YamlConfiguration;
 import org.bukkit.entity.Player;
+import org.bukkit.plugin.InvalidDescriptionException;
 import org.bukkit.plugin.Plugin;
 import org.bukkit.plugin.PluginManager;
 import org.bukkit.plugin.RegisteredServiceProvider;
@@ -54,8 +55,8 @@ public class Main extends JavaPlugin{
 	
 	ConsoleCommandSender clogger = this.getServer().getConsoleSender();
 	
-	public static int cfg_version = 12;
-	public static int pl_version = 1938;
+	public static int CFG_VERSION = 12;
+	public static int PL_VERSION;
 
 	int currentDay = 0;
 	
@@ -66,7 +67,7 @@ public class Main extends JavaPlugin{
 	@SuppressWarnings({ "deprecation", "unchecked" })
 	@Override
 	public void onEnable(){
-		
+		PL_VERSION = Integer.parseInt(((Plugin)this).getDescription().getVersion());
 		this.getCommand("timeismoney").setExecutor(new Cmd(this));
 		
 		currentDay = (new Date()).getDay();
@@ -76,7 +77,7 @@ public class Main extends JavaPlugin{
 			YamlConfiguration cfg = YamlConfiguration.loadConfiguration(config);	
 			String old_config = "config_old " + cfg.getInt("configuration-version") + ".yml";
 			if(cfg.contains("configuration-version")){
-				if(cfg.getInt("configuration-version") < cfg_version){
+				if(cfg.getInt("configuration-version") < CFG_VERSION){
 					clogger.sendMessage("[TimeIsMoney] §cYOU ARE USING AN OLD CONFIG-VERSION. The plugin CANT work with this.");
 					clogger.sendMessage("[TimeIsMoney] §cI have created an new config for you. The old one is saved as config_old.yml.");
 					config.renameTo(new File("plugins/TimeIsMoney/" + old_config));
@@ -141,7 +142,7 @@ public class Main extends JavaPlugin{
 
 			Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
 				public void run(){
-					if(Main.pl_version < VersionChecker.getVersion()){
+					if(Main.PL_VERSION < VersionChecker.getVersion()){
 						clogger.sendMessage("[TimeIsMoney] §cYou are using an old version, I will update this plugin for you.");
 						//Update
 						URL loc = Bukkit.getPluginManager().getPlugin("TimeIsMoney").getClass().getProtectionDomain().getCodeSource().getLocation();
@@ -187,9 +188,9 @@ public class Main extends JavaPlugin{
         }
 
 		if(Bukkit.getPluginManager().isPluginEnabled("Essentials")){
-			this.getLogger().severe("Essentials found. Hook in it -> Will use Essentials's AFK feature if afk is enabled.");
+			clogger.sendMessage("Time is Money: Essentials found. Hook in it -> Will use Essentials's AFK feature if afk is enabled.");
 		}
-		clogger.sendMessage("§aTime is Money §2v" + pl_version + " started.");
+		clogger.sendMessage("§aTime is Money §2v" + PL_VERSION + " started.");
 	}
 	@Override
 	public void onDisable(){

+ 1 - 1
TimeIsMoney2/src/plugin.yml

@@ -3,7 +3,7 @@ depends: [Vault]
 soft-depends: [Essentials]
 author: Linus122
 main: de.Linus122.TimeIsMoney.Main
-version: 1928
+version: 1942
 description: Gives money for online time
 commands:
    timeismoney:

+ 17 - 0
TimeIsMoney2/src/v1_11_R1/NBTUtils.java

@@ -0,0 +1,17 @@
+package v1_11_R1;
+
+import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+
+import de.Linus122.TimeIsMoney.Utils;
+import net.minecraft.server.v1_11_R1.IChatBaseComponent;
+import net.minecraft.server.v1_11_R1.PacketPlayOutChat;
+
+public class NBTUtils implements Utils{
+  public void sendActionBarMessage(Player p, String message)
+  {
+	    IChatBaseComponent icbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + message.replace('&', '§') + "\"}");
+	    PacketPlayOutChat bar = new PacketPlayOutChat(icbc, (byte)2);
+	    ((CraftPlayer)p).getHandle().playerConnection.sendPacket(bar);
+  }
+}

+ 41 - 41
TimeIsMoney2/src/webapi/VersionChecker.java

@@ -1,76 +1,76 @@
 package webapi;
 
-import java.io.BufferedReader;
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 
-import javax.net.ssl.HttpsURLConnection;
-
 import de.Linus122.TimeIsMoney.Main;
 
-
 public class VersionChecker {
 	public static String url_check_version = "http://avendria.de/tim/checkversion.php?version=";
 	public static String url_download = "http://avendria.de/tim/download.php";
-	
-	public static int getVersion(){
+
+	public static int getVersion() {
 
 		try {
-			URLConnection con = new URL(url_check_version + Main.pl_version).openConnection();
-			con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
-			
+			URLConnection con = new URL(url_check_version + Main.PL_VERSION).openConnection();
+			con.setRequestProperty("User-Agent",
+					"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
+
 			return Integer.parseInt(get_content(con));
-			
+
 		} catch (IOException e) {
-			return 9999999;
+			return 0;
 		}
 
 	}
-	public static void download(File location) throws IOException{
-		URLConnection con =  new URL(url_download).openConnection();
-		con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
+
+	public static void download(File location) throws IOException {
+		URLConnection con = new URL(url_download).openConnection();
+		con.setRequestProperty("User-Agent",
+				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
 		InputStream in = con.getInputStream();
 		FileOutputStream fos = new FileOutputStream(location);
 		byte[] buf = new byte[512];
 		while (true) {
-		    int len = in.read(buf);
-		    if (len == -1) {
-		        break;
-		    }
-		    fos.write(buf, 0, len);
+			int len = in.read(buf);
+			if (len == -1) {
+				break;
+			}
+			fos.write(buf, 0, len);
 		}
 		in.close();
 		fos.flush();
 		fos.close();
 	}
-    public static String get_content(URLConnection con){
-		String content = "99999999";
-		if(con!=null){
+
+	public static String get_content(URLConnection con) {
+		String content = "";
+		if (con != null) {
+
+			try {
+
+				BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
+
+				String input;
+				while ((input = br.readLine()) != null) {
+					content += input;
+				}
+				br.close();
+
+			} catch (IOException e) {
 				
-		try {
-					
-		   BufferedReader br = 
-			new BufferedReader(
-				new InputStreamReader(con.getInputStream()));
-					
-		   String input;
-		   while ((input = br.readLine()) != null){
-		      content += input;
-		   }
-		   br.close();
-					
-		} catch (IOException e) {
-		   e.printStackTrace();
+			}
+
+		}
+		if(content.length() == 0){
+			return "0";
 		}
-	    
-			
-	  }
 		return content;
-    }
+	}
 }