linus 9 年之前
父节点
当前提交
63c06e4bca

+ 16 - 0
TimeIsMoney/.classpath

@@ -1,3 +1,4 @@
+<<<<<<< HEAD
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src"/>
@@ -11,3 +12,18 @@
 	<classpathentry kind="lib" path="/home/linus/api/Vault 1.8.1.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
+=======
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="lib" path="C:/Users/Bukkit/spigot1.8.3.jar"/>
+	<classpathentry kind="lib" path="C:/Users/Bukkit/Vault 1.8.1.jar"/>
+	<classpathentry kind="lib" path="C:/Users/Bukkit/spigot-api-1.8.4-R0.1-SNAPSHOT-latest.jar"/>
+	<classpathentry kind="lib" path="C:/Users/Bukkit/spigot-1.8-R0.1-SNAPSHOT-b1658.jar"/>
+	<classpathentry kind="lib" path="C:/Users/Linus/Desktop/Bukkit-1.8/spigot.jar"/>
+	<classpathentry kind="lib" path="C:/Users/Linus/Desktop/Dev-Server/Avendria/Server/hub/plugins/Essentials.jar"/>
+	<classpathentry kind="lib" path="C:/Users/Bukkit/spigot_server1.9.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
+>>>>>>> branch 'master' of https://github.com/mastercake10/TimeIsMoney.git

+ 31 - 0
TimeIsMoney/src/config.yml

@@ -2,6 +2,7 @@ give_money_every_second: 600
 afk_payout: false
 #You can add more payouts by copy and paste them. Don't forget to change the numbers!
 store-money-in-bank: false
+<<<<<<< HEAD
 #Set choose-payout-by-chance to true in order to choose the payouts by chances. Replace the "permission" to "chance", e.g. chance: 20. 
 choose-payout-by-chance: false
 payouts:
@@ -36,3 +37,33 @@ atm_deposit: "&cDeposit"
 atm_balance: "&cBank balance:"
 auto-update: true
 configuration-version: 12
+=======
+payouts:
+  1:
+    payout_amount: 50
+    max_payout_per_day: 1000
+    permission:
+  2:
+    payout_amount: 100
+    max_payout_per_day: 10000
+    commands:
+      - /give %player% diamond 1
+    permission: tim.vip
+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!"
+display-messages-in-chat: true
+display-messages-in-actionbar: true
+display-messages-in-actionbar-time: 10
+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_title: "&cATM"
+atm_withdraw: "&cWithdraw"
+atm_deposit: "&cDeposit"
+atm_balance: "&cBank balance:"
+configuration-version: 10
+>>>>>>> branch 'master' of https://github.com/mastercake10/TimeIsMoney.git

+ 331 - 0
TimeIsMoney/src/de/Linus122/TimeIsMoney/Main.java

@@ -8,6 +8,7 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.PrintWriter;
+<<<<<<< HEAD
 import java.net.URL;
 import java.sql.Timestamp;
 import java.util.ArrayList;
@@ -375,6 +376,336 @@ public class Main extends JavaPlugin{
 				Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
 					public void run(){
 						utils.sendActionBarMessage(p, msg.replace('&', '§'));
+=======
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.RegisteredServiceProvider;
+import org.bukkit.plugin.java.JavaPlugin;
+
+
+import modules.atm.ATM;
+import net.milkbowl.vault.economy.Economy;
+import webapi.VersionChecker;
+
+public class Main extends JavaPlugin{
+	
+	List<Payout> payouts = new ArrayList<Payout>();
+	HashMap<String, Double> payedMoney = new HashMap<String, Double>();
+	
+	HashMap<Player, Integer> onlineSeconds = new HashMap<Player, Integer>();
+	
+	HashMap<Player, Location> lastLocation = new HashMap<Player, Location>();
+	
+	public static Economy economy = null;
+	public static Utils utils = null;
+	String message;
+	
+	ConsoleCommandSender clogger = this.getServer().getConsoleSender();
+	
+	public static int version = 10;
+	
+	int currentDay = 0;
+	
+	public static YamlConfiguration finalconfig;
+	
+	boolean use18Features = true;
+	
+	@SuppressWarnings({ "deprecation", "unchecked" })
+	@Override
+	public void onEnable(){
+		
+		this.getCommand("timeismoney").setExecutor(new Cmd(this));
+		
+		currentDay = (new Date()).getDay();
+		
+		File config = new File("plugins/TimeIsMoney/config.yml");
+		if(config.exists()){
+			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") < 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));
+				}
+			}
+			this.saveDefaultConfig();
+			for(String key : cfg.getConfigurationSection("").getKeys(true)){
+				if(!this.getConfig().contains(key)){
+					this.getConfig().set(key, cfg.get(key));
+				}
+			}
+		}else{
+			this.saveDefaultConfig();
+		}
+		
+		new ATM(this);
+		
+		finalconfig = YamlConfiguration.loadConfiguration(config);
+		final int seconds = getConfig().getInt("give_money_every_second");
+		Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
+			public void run(){
+				for(Player p : Bukkit.getOnlinePlayers()){
+					if(onlineSeconds.containsKey(p)){
+						
+						onlineSeconds.put(p, onlineSeconds.get(p) + 1);
+					}else{
+						onlineSeconds.put(p, 1);
+					}
+					if(onlineSeconds.get(p) > seconds){
+						pay(p);
+						onlineSeconds.remove(p);
+					}
+				}
+			}
+		}, 20L, 20L);
+		Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
+			public void run(){
+				if(currentDay != new Date().getDay()){ //Next day, clear payouts!
+					log("Cleared all payouts");
+					payedMoney.clear();
+					currentDay = new Date().getDay();
+				}
+			}
+		}, 20L * 60, 20L * 60);
+		setupEconomy();
+		
+		message = finalconfig.getString("message");
+		message = message.replace('&', '§');
+
+		try{
+		    FileInputStream fis = new FileInputStream(new File("plugins/TimeIsMoney/payed_today.data"));
+		    ObjectInputStream ois = new ObjectInputStream(fis);
+		    payedMoney = (HashMap<String, Double>) ((HashMap<String, Double>) ois.readObject()).clone();
+
+		    ois.close();	
+		}catch(Exception e){
+			
+		}
+		
+		loadPayouts();
+		
+		if(this.version < VersionChecker.getVersion()){
+			clogger.sendMessage("[TimeIsMoney] §cYou are using an old version, please update at");
+			clogger.sendMessage("§chttps://www.spigotmc.org/resources/time-is-money.12409/");
+		}
+		
+		 String packageName = this.getServer().getClass().getPackage().getName();
+        // Get full package string of CraftServer.
+        // org.bukkit.craftbukkit.version
+        String Bukkitversion = packageName.substring(packageName.lastIndexOf('.') + 1);
+        // Get the last element of the package
+        try {
+            final Class<?> clazz = Class.forName(Bukkitversion + ".NBTUtils");
+            // Check if we have a NMSHandler class at that location.
+            if (Utils.class.isAssignableFrom(clazz)) { // Make sure it actually implements NMS
+                utils = (Utils) clazz.getConstructor().newInstance(); // Set our handler
+     
+            }
+            
+        } catch (final Exception e) {
+            this.getLogger().severe("Actionbars are not supported on your spigot version, sorry.");
+            use18Features = false;
+            return;
+        }
+	    Bukkit.getScheduler().scheduleAsyncDelayedTask(this,  new Runnable(){
+	    	public void run(){
+	    		VersionChecker.register();
+	    	}
+	    }, 1L);
+		if(Bukkit.getPluginManager().isPluginEnabled("Essentials")){
+			this.getLogger().severe("Essentials found. Hook in it -> Will use Essentials's AFK feature if afk is enabled.");
+		}
+		
+	}
+	@Override
+	public void onDisable(){
+	    FileOutputStream fos;
+	    try {
+	    	fos = new FileOutputStream(new File("plugins/TimeIsMoney/payed_today.data"));
+	        ObjectOutputStream oos = new ObjectOutputStream(fos);
+	        oos.writeObject(payedMoney);
+	        oos.close();
+	    }catch(Exception e){
+	    	
+	    }
+	}
+	public void reload(){
+		File config = new File("plugins/TimeIsMoney/config.yml");
+		finalconfig = YamlConfiguration.loadConfiguration(config);
+		
+		loadPayouts();
+	}
+	public void loadPayouts(){
+		try{
+			payouts.clear();
+			for(String key : finalconfig.getConfigurationSection("payouts").getKeys(false)){
+				Payout payout = new Payout();
+				payout.max_payout_per_day = finalconfig.getDouble("payouts." + key + ".max_payout_per_day");
+				payout.payout_amount = finalconfig.getDouble("payouts." + key + ".payout_amount");
+				if(finalconfig.getString("payouts." + key + ".permission") != null){
+					payout.permission = finalconfig.getString("payouts." + key + ".permission");	
+				}
+				if(finalconfig.getString("payouts." + key + ".commands") != null){
+					payout.commands = finalconfig.getStringList("payouts." + key + ".commands");
+				}
+				payouts.add(payout);
+			}
+			clogger.sendMessage("[TimeIsMoney] §aLoaded " + finalconfig.getConfigurationSection("payouts").getKeys(false).size() + " Payouts!");
+		}catch(Exception e){
+			clogger.sendMessage("[TimeIsMoney] §aFailed to load Payouts! (May made a mistake in config.yml?)");
+		}
+	}
+    boolean setupEconomy()
+    {
+        RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
+        if (economyProvider != null) {
+            economy = economyProvider.getProvider();
+        }
+
+        return (economy != null);
+    }
+    public Payout getPayOutForPlayer(Player p){
+    	Payout finalpayout = null;
+		for(Payout payout: payouts){
+			if(payout.permission == "") finalpayout = payout;
+			if(p.hasPermission(payout.permission)){
+				finalpayout = payout;
+			}
+		}
+    	return finalpayout;
+    }
+	@SuppressWarnings("deprecation")
+	public void pay(Player p){
+		//REACHED MAX PAYOUT CHECK
+		double payed = 0;
+		if(payedMoney.containsKey(p.getName())){
+			payed = payedMoney.get(p.getName());
+		}
+		Payout payout = getPayOutForPlayer(p);
+		if(payout == null) return;
+		if(payed >= payout.max_payout_per_day){ //Reached max payout
+			if(finalconfig.getBoolean("display-messages-in-chat")){
+				p.sendMessage(finalconfig.getString("message_payoutlimit_reached").replace('&', '§'));
+			}
+			if(finalconfig.getBoolean("display-messages-in-actionbar") && use18Features){
+				sendActionbar(p, finalconfig.getString("message_payoutlimit_reached_actionbar").replace('&', '§'));
+			}
+			return;
+		}
+		
+		//AFK CHECK
+		if(!finalconfig.getBoolean("afk_payout")){
+			//ESENTIALS_AFK_FEATURE
+			if(Bukkit.getServer().getPluginManager().isPluginEnabled("Essentials")){
+				com.earth2me.essentials.Essentials essentials = (com.earth2me.essentials.Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
+			    if(essentials.getUser(p).isAfk()){
+			    	//AFK
+					if(finalconfig.getBoolean("display-messages-in-chat")){
+						p.sendMessage(finalconfig.getString("message_afk").replace('&', '§'));	
+					}
+					if(finalconfig.getBoolean("display-messages-in-actionbar") && use18Features){
+						sendActionbar(p, finalconfig.getString("message_afk_actionbar").replace('&', '§'));
+					}
+					return;
+			    }
+			}else
+			//PLUGIN_AFK_FEATURE
+			if(lastLocation.containsKey(p)){ //AntiAFK
+				if(lastLocation.get(p).getX() == p.getLocation().getX() && lastLocation.get(p).getY() == p.getLocation().getY() && lastLocation.get(p).getZ() == p.getLocation().getZ() || lastLocation.get(p).getYaw() == p.getLocation().getYaw()){
+					//AFK
+					if(finalconfig.getBoolean("display-messages-in-chat")){
+						p.sendMessage(finalconfig.getString("message_afk").replace('&', '§'));	
+					}
+					if(finalconfig.getBoolean("display-messages-in-actionbar") && use18Features){
+						sendActionbar(p, finalconfig.getString("message_afk_actionbar").replace('&', '§'));
+					}
+					return;
+				}
+			}	
+		}
+		
+		//DEPOSIT
+		if(finalconfig.getBoolean("store-money-in-bank")){
+			String bank = p.getName() + "_TimBANK";
+			if(!Main.economy.hasAccount(bank)){
+				Main.economy.createPlayerAccount(bank);
+			}
+			Main.economy.depositPlayer(bank, payout.payout_amount);
+		}else{
+			double 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));
+			
+		}
+		if(finalconfig.getBoolean("display-messages-in-chat")){
+			p.sendMessage(message.replace("%money%", economy.format(payout.payout_amount)));	
+		}
+		if(finalconfig.getBoolean("display-messages-in-actionbar") && use18Features){
+			sendActionbar(p, message.replace("%money%", economy.format(payout.payout_amount)));
+		}
+		for(String cmd : payout.commands){
+			this.getServer().dispatchCommand(this.getServer().getConsoleSender(), cmd.replace("/", "").replaceAll("%player%", p.getName()));
+		}
+		
+		//ADD PAYED MONEY
+		if(payedMoney.containsKey(p.getName())){
+			payedMoney.put(p.getName(), payedMoney.get(p.getName()) + payout.payout_amount);
+		}else{
+			payedMoney.put(p.getName(), payout.payout_amount);
+		}
+		
+		lastLocation.put(p, p.getLocation());
+	
+	}
+	@SuppressWarnings("deprecation")
+	public void log(String msg){
+		Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
+
+		File file = new File("plugins/TimeIsMoney/log.txt");
+			try {
+				if(!file.exists()){
+					file.createNewFile();
+				}
+				FileReader pr = new FileReader(file);
+				int number = 0;
+				StringBuffer text = new StringBuffer();
+				while((number = pr.read()) != -1){
+					
+					text.append((char) number);
+				}
+				text.append(currentTimestamp.toGMTString() + ":" + msg + "\n");
+				PrintWriter pw = new PrintWriter(file);
+				pw.print(text);
+				
+				pw.close();
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+	}
+	public void sendActionbar(final Player p, final String msg){
+		int times = finalconfig.getInt("display-messages-in-actionbar-time");
+		if(times == 1){
+			utils.sendActionBarMessage(p, msg);
+		}else if(times > 1){
+			utils.sendActionBarMessage(p, msg);
+			times--;
+			for(int i = 0; i < times; i++){
+				Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
+					public void run(){
+						utils.sendActionBarMessage(p, msg);
+>>>>>>> branch 'master' of https://github.com/mastercake10/TimeIsMoney.git
 					}
 				}, 20L * i);
 			}

+ 3 - 0
TimeIsMoney/src/de/Linus122/TimeIsMoney/Payout.java

@@ -7,6 +7,9 @@ public class Payout {
 	double payout_amount = 0;
 	double max_payout_per_day = 0;
 	String permission = "";
+<<<<<<< HEAD
 	int chance = 0;
+=======
+>>>>>>> branch 'master' of https://github.com/mastercake10/TimeIsMoney.git
 	List<String> commands = new ArrayList<String>();
 }

+ 45 - 0
TimeIsMoney/src/modules/atm/ATM.java

@@ -59,6 +59,7 @@ public class ATM implements Listener {
 	@SuppressWarnings("deprecation")
 	@EventHandler
 	public void onClick(InventoryClickEvent e){
+<<<<<<< HEAD
 		
 		try{
 			if(e == null) return;
@@ -107,6 +108,50 @@ public class ATM implements Listener {
 			}
 		}catch(Exception e2){
 			
+=======
+		if(e.getClickedInventory() == null) return;
+		if(e.getClickedInventory().getTitle() == null) return;
+		if(e.getClickedInventory().getTitle().equals(Main.finalconfig.getString("atm_title").replace('&', '§'))){
+			e.setCancelled(true);
+			String bank = e.getWhoClicked().getName() + "_TimBANK";
+			if(e.getCurrentItem() != null){
+				if(e.getCurrentItem().getItemMeta().getDisplayName().split(" ")[0].equals(Main.finalconfig.getString("atm_withdraw").replace('&', '§'))){
+
+					double amount = Double.parseDouble(e.getCurrentItem().getItemMeta().getLore().get(0));
+					
+					if(!Main.economy.hasAccount(bank)){
+						Main.economy.createPlayerAccount(bank);
+					}
+					if(Main.economy.has(bank, amount)){
+						Main.economy.withdrawPlayer(bank, amount);
+						Main.economy.depositPlayer((Player) e.getWhoClicked(), amount);
+						e.getWhoClicked().sendMessage(Main.finalconfig.getString("atm_withdraw").replace('&', '§') + " " + Main.economy.format(amount));
+					}else{
+						e.getWhoClicked().sendMessage(Main.finalconfig.getString("message_atm_nomoneyinbank").replace('&', '§'));
+					}
+				}else
+				if(e.getCurrentItem().getItemMeta().getDisplayName().split(" ")[0].equals(Main.finalconfig.getString("atm_deposit").replace('&', '§'))){
+					
+					double amount = Double.parseDouble(e.getCurrentItem().getItemMeta().getLore().get(0));
+					
+					if(Main.economy.has((Player) e.getWhoClicked(), amount)){
+						if(!Main.economy.hasAccount(bank)){
+							Main.economy.createPlayerAccount(bank);
+						}
+						Main.economy.depositPlayer(bank, amount);
+						Main.economy.withdrawPlayer((Player) e.getWhoClicked(), amount);
+						e.getWhoClicked().sendMessage(Main.finalconfig.getString("atm_deposit").replace('&', '§') + " " + Main.economy.format(amount));
+					}else{
+						e.getWhoClicked().sendMessage(Main.finalconfig.getString("message_atm_nomoney").replace('&', '§'));
+					}
+				}
+				ItemStack is = new ItemStack(Material.GOLD_NUGGET, 1);
+				ItemMeta im = is.getItemMeta();
+				im.setDisplayName("§cBank balance: " + getBankbalance(e.getWhoClicked().getName() + "_TimBANK"));
+				is.setItemMeta(im);
+				e.getInventory().setItem(4, is);
+			}
+>>>>>>> branch 'master' of https://github.com/mastercake10/TimeIsMoney.git
 		}
 	}
 	public double getBankbalance(String name){

+ 37 - 0
TimeIsMoney/src/webapi/VersionChecker.java

@@ -1,6 +1,7 @@
 package webapi;
 
 import java.io.BufferedReader;
+<<<<<<< HEAD
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -80,4 +81,40 @@ public class VersionChecker {
 	  }
 		return content;
     }
+=======
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import de.Linus122.TimeIsMoney.Main;
+
+public class VersionChecker {
+	public static int getVersion(){
+        URL oracle;
+		try {
+			oracle = new URL("http://176.57.142.247/api/version.html");
+	        BufferedReader in = new BufferedReader(
+	        new InputStreamReader(oracle.openStream()));
+	
+	        String inputLine;
+	        while ((inputLine = in.readLine()) != null)
+	            return Integer.parseInt(inputLine);
+	        in.close();
+		} catch (Exception e) {
+			return 9999;
+		}
+		return 9999;
+	}
+	public static void register(){
+		URL url;
+		try {
+			url = new URL("http://176.57.142.247/api/post.php?info=" + "v-" + Main.version + "-");
+			url.openConnection().getInputStream();
+		} catch (Exception e) {
+
+		}
+	}
+	public static void unregister(){
+		
+	}
+>>>>>>> branch 'master' of https://github.com/mastercake10/TimeIsMoney.git
 }