Linus 8 yıl önce
ebeveyn
işleme
ba491050f6

+ 2 - 0
TimeIsMoney2/src/config.yml

@@ -3,6 +3,8 @@ configuration-version: 12
 auto-update: true
 debug-log: false
 
+# You can define if the player gets a payout whether player is afk or not.
+# the permission tim.afkbypass would avoid this for certain user or groups.
 afk_payout: false
 display-messages-in-chat: true
 display-messages-in-actionbar: true

+ 0 - 113
TimeIsMoney2/src/config.yml~

@@ -1,113 +0,0 @@
-<<<<<<< HEAD
-configuration-version: 12
-
-auto-update: true
-debug-log: false
-
-afk_payout: false
-display-messages-in-chat: true
-display-messages-in-actionbar: true
-display-messages-in-actionbar-time: 10
-give_money_every_second: 600
-store-money-in-bank: false
-# Payouts will be delivered by "chance" instead "permission".
-choose-payout-by-chance: false
-
-# You can add as many payouts you want. You only can choose between "permission"
-# and "change", not both.
-payouts:
-  1:
-    payout_amount: 50
-    max_payout_per_day: 1000
-    # chance: 10
-    permission:
-  2:
-    payout_amount: 100
-    max_payout_per_day: 10000
-    commands:
-      - /give %player% diamond 1
-    # chance: 90
-    # You can use any permission name you want. e.g. myserver.donor
-    permission: tim.vip
-
-# Translations
-message: "&aYou earned &c%money% &afor 10 minutes online time!"
-message_payoutlimit_reached: "&cYou have reached the payout limit today. You earned 0$"
-message_afk: "&cYou havn't earned money because you were afk!"
-message_actionbar: "&aYou earned &c%money% &afor 10 minutes online time!"
-message_payoutlimit_reached_actionbar: "&cYou have reached the payout limit today. You got 0$"
-message_afk_actionbar: "&cYou havn't earned money because you were afk!"
-message_atm_noperms: "&cYou don't have the permission to use ATM's!"
-message_atm_nomoneyinbank: "&cYou don't have enough money in bank!"
-message_atm_nomoney: "&cYou don't have enough money!"
-# ATM -> Place down a sign with [atm] on the first line to use it!
-atm_title: "&cATM"
-atm_withdraw: "&cWithdraw"
-atm_deposit: "&cDeposit"
-atm_balance: "&cBank balance:"
-# You can seperate the ATM balances for different worlds by group them.
-group-atms: false
-# Example groups for seperating all worlds:
-#atm_groups:
-#  group1:
-#  - world
-#  group2:
-#  - world_nether
-#  group3:
-#   - world_the_end
-# Example groups for seperating skyblock worlds and survival worlds:
-#atm_groups:
-#  group1:
-#  - ASkyblock_world
-#  - Askyblock_spawn
-#  group2:
-#  - survival_world
-#  - farm_world
-=======
-configuration-version: 12
-
-auto-update: true
-debug-log: false
-
-afk_payout: false
-display-messages-in-chat: true
-display-messages-in-actionbar: true
-display-messages-in-actionbar-time: 10
-give_money_every_second: 600
-store-money-in-bank: false
-# Payouts will be delivered by "chance" instead "permission".
-choose-payout-by-chance: false
-
-# You can add as many payouts you want. You only can choose between "permission"
-# and "change", not both.
-payouts:
-  1:
-    payout_amount: 50
-    max_payout_per_day: 1000
-    # chance: 10
-    permission:
-  2:
-    payout_amount: 100
-    max_payout_per_day: 10000
-    commands:
-      - /give %player% diamond 1
-    # chance: 90
-    # You can use any permission name you want. e.g. myserver.donor
-    permission: tim.vip
-
-# Translations
-message: "&aYou earned &c%money% &afor 10 minutes online time!"
-message_payoutlimit_reached: "&cYou have reached the payout limit today. You earned 0$"
-message_afk: "&cYou havn't earned money because you were afk!"
-message_actionbar: "&aYou earned &c%money% &afor 10 minutes online time!"
-message_payoutlimit_reached_actionbar: "&cYou have reached the payout limit today. You got 0$"
-message_afk_actionbar: "&cYou havn't earned money because you were afk!"
-message_atm_noperms: "&cYou don't have the permission to use ATM's!"
-message_atm_nomoneyinbank: "&cYou don't have enough money in bank!"
-message_atm_nomoney: "&cYou don't have enough money!"
-# ATM -> Place down a sign with [atm] on the first line to use it!
-atm_title: "&cATM"
-atm_withdraw: "&cWithdraw"
-atm_deposit: "&cDeposit"
-atm_balance: "&cBank balance:"
->>>>>>> refs/remotes/origin/master

+ 153 - 25
TimeIsMoney2/src/de/Linus122/TimeIsMoney/Main.java

@@ -8,21 +8,31 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.PrintWriter;
+import java.lang.reflect.Field;
 import java.net.URL;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 
 import org.bukkit.Bukkit;
 import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
 import org.bukkit.command.ConsoleCommandSender;
+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.Plugin;
+import org.bukkit.plugin.PluginManager;
 import org.bukkit.plugin.RegisteredServiceProvider;
+import org.bukkit.plugin.SimplePluginManager;
 import org.bukkit.plugin.java.JavaPlugin;
 
 import modules.atm.ATM;
@@ -45,7 +55,7 @@ public class Main extends JavaPlugin{
 	ConsoleCommandSender clogger = this.getServer().getConsoleSender();
 	
 	public static int cfg_version = 12;
-	public static int pl_version = 1930;
+	public static int pl_version = 1937;
 
 	int currentDay = 0;
 	
@@ -110,7 +120,7 @@ public class Main extends JavaPlugin{
 					currentDay = new Date().getDay();
 				}
 			}
-		}, 20L * 60, 20L * 60);
+		}, 20L * 60, 20L * 60 * 15);
 		setupEconomy();
 		
 		message = finalconfig.getString("message");
@@ -127,30 +137,36 @@ public class Main extends JavaPlugin{
 		}
 		
 		loadPayouts();
-		try{
-			VersionChecker.init();
-			if(Main.pl_version < VersionChecker.getVersion()){
-				if(this.getConfig().getBoolean("auto-update")){
-					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();
-					String url = VersionChecker.getNewVersionFileUrl();
-					Bukkit.getUpdateFolderFile().mkdir();
-					File file = new File(Bukkit.getUpdateFolderFile().getPath() + "/" + loc.getFile().split("/")[loc.getFile().split("/").length - 1]);
-					
-					VersionChecker.download(url,file);
-					clogger.sendMessage("[TimeIsMoney] §aSuccess! Downloaded v" + VersionChecker.getVersion());
-					Bukkit.reload();
-					return;
-				}else{
-					clogger.sendMessage("[TimeIsMoney] §cYou are using an old version, please update at");
-					clogger.sendMessage("§chttps://www.spigotmc.org/resources/time-is-money.12409/");
+		if(this.getConfig().getBoolean("auto-update")){
+
+			Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
+				public void run(){
+					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();
+						Bukkit.getUpdateFolderFile().mkdir();
+						File file = new File(Bukkit.getUpdateFolderFile().getPath() + "/" + loc.getFile().split("/")[loc.getFile().split("/").length - 1]);
+						
+						try {
+							VersionChecker.download(file);
+						} catch (IOException e) {
+							// TODO Auto-generated catch block
+							e.printStackTrace();
+						}
+						clogger.sendMessage("[TimeIsMoney] §aSuccess! Downloaded v" + VersionChecker.getVersion());
+						try {
+							reloadPlugin("TimeIsMoney");
+						} catch (Exception e) {
+							// TODO Auto-generated catch block
+							e.printStackTrace();
+						}
+					}
 				}
-			}
-		}catch(Exception e){
-			
+			},0L, 20L * 60 * 20);
 		}
 		
+		
 		 String packageName = this.getServer().getClass().getPackage().getName();
         // Get full package string of CraftServer.
         // org.bukkit.craftbukkit.version
@@ -252,6 +268,8 @@ public class Main extends JavaPlugin{
     }
 	@SuppressWarnings("deprecation")
 	public void pay(Player p){
+		if(p == null) return;
+		
 		//REACHED MAX PAYOUT CHECK
 		double payed = 0;
 		if(payedMoney.containsKey(p.getName())){
@@ -272,7 +290,7 @@ public class Main extends JavaPlugin{
 		}
 		
 		//AFK CHECK
-		if(!finalconfig.getBoolean("afk_payout")){
+		if(!finalconfig.getBoolean("afk_payout") && !p.hasPermission("tim.afkbypass")){
 			//ESENTIALS_AFK_FEATURE
 			if(Bukkit.getServer().getPluginManager().isPluginEnabled("Essentials")){
 				com.earth2me.essentials.Essentials essentials = (com.earth2me.essentials.Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
@@ -310,7 +328,11 @@ public class Main extends JavaPlugin{
 			}
 			Main.economy.depositPlayer(bank, payout.payout_amount);
 		}else{
-			double before = economy.getBalance(p);
+			double before = 0;
+			if(economy.hasAccount(p)){
+				before = economy.getBalance(p);
+			}
+		
 			economy.depositPlayer(p, payout.payout_amount);
 			log(p.getName() + ": Deposited: " + payout.payout_amount + " Balance-before: " + before + " Balance-now: " + economy.getBalance(p));
 			
@@ -385,4 +407,110 @@ public class Main extends JavaPlugin{
 			}
 		}
 	}
+	private boolean unloadPlugin(String pluginName)
+		    throws Exception
+		  {
+		    PluginManager manager = getServer().getPluginManager();
+		    SimplePluginManager spmanager = (SimplePluginManager)manager;
+		    if (spmanager != null)
+		    {
+		      Field pluginsField = spmanager.getClass().getDeclaredField("plugins");
+		      pluginsField.setAccessible(true);
+		      List<Plugin> plugins = (List)pluginsField.get(spmanager);
+		      
+		      Field lookupNamesField = spmanager.getClass().getDeclaredField("lookupNames");
+		      lookupNamesField.setAccessible(true);
+		      Map<String, Plugin> lookupNames = (Map)lookupNamesField.get(spmanager);
+		      
+		      Field commandMapField = spmanager.getClass().getDeclaredField("commandMap");
+		      commandMapField.setAccessible(true);
+		      SimpleCommandMap commandMap = (SimpleCommandMap)commandMapField.get(spmanager);
+		      
+		      Field knownCommandsField = null;
+		      Map<String, Command> knownCommands = null;
+		      if (commandMap != null)
+		      {
+		        knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
+		        knownCommandsField.setAccessible(true);
+		        knownCommands = (Map)knownCommandsField.get(commandMap);
+		      }
+		      Plugin plugin;
+		      Iterator<Map.Entry<String, Command>> it;
+		      for (Plugin plugin1 : manager.getPlugins()) {
+		        if (plugin1.getDescription().getName().equalsIgnoreCase(pluginName))
+		        {
+		          manager.disablePlugin(plugin1);
+		          if ((plugins != null) && (plugins.contains(plugin1))) {
+		            plugins.remove(plugin1);
+		          }
+		          if ((lookupNames != null) && (lookupNames.containsKey(pluginName))) {
+		            lookupNames.remove(pluginName);
+		          }
+		          if (commandMap != null) {
+		            for (it = knownCommands.entrySet().iterator(); it.hasNext();)
+		            {
+		              Map.Entry<String, Command> entry = (Map.Entry)it.next();
+		              if ((entry.getValue() instanceof PluginCommand))
+		              {
+		                PluginCommand command = (PluginCommand)entry.getValue();
+		                if (command.getPlugin() == plugin1)
+		                {
+		                  command.unregister(commandMap);
+		                  it.remove();
+		                }
+		              }
+		            }
+		          }
+		        }
+		      }
+		    }
+		    else
+		    {
+
+		      return true;
+		    }
+
+
+		    return true;
+		  }
+		  
+		  private boolean loadPlugin(String pluginName)
+		  {
+		    try
+		    {
+		      PluginManager manager = getServer().getPluginManager();
+		      Plugin plugin = manager.loadPlugin(new File("plugins", pluginName + ".jar"));
+		      if (plugin == null)
+		      {
+		        return false;
+		      }
+		      plugin.onLoad();
+		      manager.enablePlugin(plugin);
+		    }
+		    catch (Exception e)
+		    {
+
+		      return false;
+		    }
+
+		    return true;
+		  }
+		  
+		  private boolean reloadPlugin(String pluginName)
+		    throws Exception
+		  {
+		    boolean unload = unloadPlugin(pluginName);
+		    boolean load = loadPlugin(pluginName);
+
+		    if ((unload) && (load))
+		    {
+
+		    }
+		    else
+		    {
+
+		      return false;
+		    }
+		    return true;
+		  }
 }

+ 0 - 13
TimeIsMoney2/src/plugin.yml~

@@ -1,13 +0,0 @@
-name: TimeIsMoney
-depends: [Vault]
-soft-depends: [Essentials]
-author: Linus122
-main: de.Linus122.TimeIsMoney.Main
-version: 1928
-description: Gives money for online time
-commands:
-   timeismoney:
-      description: Reloads the Config
-      aliases: tim
-      usage: /<command>
-      permission: tim.reload

+ 19 - 24
TimeIsMoney2/src/webapi/VersionChecker.java

@@ -8,39 +8,34 @@ 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 = "https://www.spigotmc.org/resources/time-is-money.12409/";
-	public static String content = "";
+	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(){
-		int version2 = 10;
-		try{
-	        String s = content.split("<div class=\"section\" id=\"versionInfo\">")[1].split("</div>")[0];
-	        String version = s.split("<h3>Version ")[1].split("</h3>")[0].replace(".", "");
-	        version2 = Integer.valueOf(version);
-		}catch(Exception e){
+
+		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");
+
+			return Integer.parseInt(get_content(con));
 			
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
 		}
-        return version2;
-	}
-	public static String getNewVersionFileUrl(){
-		String s = content.split("<label class=\"downloadButton \">")[1].split("</label>")[0];
-		String link = s.split("<a href=\"")[1].split("\" class=\"inner\">")[0];
-		String link2 = "https://www.spigotmc.org/" + link;
-		return link2;
-	}
-	
-	public static void init() throws MalformedURLException, IOException {
-		HttpsURLConnection con = (HttpsURLConnection) new URL(url).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");
-		content = get_content(con);
+		return 0;
+
 	}
-	public static void download(String url2, File location) throws IOException{
-		HttpsURLConnection con = (HttpsURLConnection) new URL(url2).openConnection();
+	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);
@@ -56,7 +51,7 @@ public class VersionChecker {
 		fos.flush();
 		fos.close();
 	}
-    public static String get_content(HttpsURLConnection con){
+    public static String get_content(URLConnection con){
 		String content = "";
 		if(con!=null){