Add items pickup while sitting
This commit is contained in:
		| @@ -5,6 +5,8 @@ | |||||||
| package com.cnaude.chairs; | package com.cnaude.chairs; | ||||||
|  |  | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
|  | import org.bukkit.entity.Entity; | ||||||
|  | import org.bukkit.entity.Item; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -13,20 +15,24 @@ import org.bukkit.entity.Player; | |||||||
|  */ |  */ | ||||||
| public class ChairEffects { | public class ChairEffects { | ||||||
|  |  | ||||||
|     Chairs plugin; |     private Chairs plugin; | ||||||
|     int taskID; |     private int healTaskID = -1; | ||||||
|  |     private int pickupTaskID = -1; | ||||||
|  |      | ||||||
|  |  | ||||||
|     public ChairEffects(Chairs plugin) { |     public ChairEffects(Chairs plugin) { | ||||||
|         this.plugin = plugin; |         this.plugin = plugin; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public void startHealing() { |     public void startHealing() { | ||||||
|         effectsTask(); |         healEffectsTask(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void cancelHealing() { |     public void cancelHealing() { | ||||||
|         plugin.getServer().getScheduler().cancelTask(taskID); |     	if (healTaskID != -1) { | ||||||
|         taskID = 0; |     		plugin.getServer().getScheduler().cancelTask(healTaskID); | ||||||
|  |     		healTaskID = -1; | ||||||
|  |     	} | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public void restartHealing() { |     public void restartHealing() { | ||||||
| @@ -34,8 +40,8 @@ public class ChairEffects { | |||||||
|         startHealing(); |         startHealing(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void effectsTask() { |     private void healEffectsTask() { | ||||||
|         taskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { |         healTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { | ||||||
|             @Override |             @Override | ||||||
|             public void run() { |             public void run() { | ||||||
|                 for (Player p : Bukkit.getOnlinePlayers()) { |                 for (Player p : Bukkit.getOnlinePlayers()) { | ||||||
| @@ -55,4 +61,39 @@ public class ChairEffects { | |||||||
|             } |             } | ||||||
|         }, plugin.sitHealInterval, plugin.sitHealInterval); |         }, plugin.sitHealInterval, plugin.sitHealInterval); | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     public void startPickup() { | ||||||
|  |     	pickupEffectsTask(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void cancelPickup() { | ||||||
|  |     	if (pickupTaskID != -1) | ||||||
|  |         plugin.getServer().getScheduler().cancelTask(pickupTaskID); | ||||||
|  |         pickupTaskID = -1; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     public void restartPickup() { | ||||||
|  |     	cancelPickup(); | ||||||
|  |     	startPickup(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private void pickupEffectsTask() { | ||||||
|  |     	pickupTaskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { | ||||||
|  |     		public void run() { | ||||||
|  |                 for (Player p : Bukkit.getOnlinePlayers()) { | ||||||
|  |                 	if (plugin.getPlayerSitData().isSitting(p)) { | ||||||
|  |                 		for (Entity entity : p.getNearbyEntities(1, 1, 1)) { | ||||||
|  |                 			if (entity instanceof Item) { | ||||||
|  |                                 if (p.getInventory().firstEmpty() != -1) { | ||||||
|  |                                 	p.getInventory().addItem(Item.class.cast(entity).getItemStack()); | ||||||
|  |                                 	entity.remove(); | ||||||
|  |                                 } | ||||||
|  |                 			} | ||||||
|  |                 		} | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |     		} | ||||||
|  |     	},0,1); | ||||||
|  |     } | ||||||
|  |      | ||||||
| } | } | ||||||
|   | |||||||
| @@ -32,6 +32,7 @@ public class Chairs extends JavaPlugin { | |||||||
|     public int sitMaxHealth; |     public int sitMaxHealth; | ||||||
|     public int sitHealthPerInterval; |     public int sitHealthPerInterval; | ||||||
|     public int sitHealInterval; |     public int sitHealInterval; | ||||||
|  |     public boolean sitPickupEnabled; | ||||||
|     public boolean sitDisableAllCommands = false; |     public boolean sitDisableAllCommands = false; | ||||||
|     public HashSet<String> sitDisabledCommands = new HashSet<String>(); |     public HashSet<String> sitDisabledCommands = new HashSet<String>(); | ||||||
|     private Logger log; |     private Logger log; | ||||||
| @@ -74,13 +75,16 @@ public class Chairs extends JavaPlugin { | |||||||
|         chairEffects = new ChairEffects(this); |         chairEffects = new ChairEffects(this); | ||||||
|         ignoreList = new ChairsIgnoreList(this); |         ignoreList = new ChairsIgnoreList(this); | ||||||
|         ignoreList.load(); |         ignoreList.load(); | ||||||
|  |         psitdata = new PlayerSitData(this); | ||||||
|         getConfig().options().copyDefaults(true); |         getConfig().options().copyDefaults(true); | ||||||
|         saveConfig(); |         saveConfig(); | ||||||
|         loadConfig(); |         loadConfig(); | ||||||
|         if (sitHealEnabled) { |         if (sitHealEnabled) { | ||||||
|         	chairEffects.startHealing(); |         	chairEffects.startHealing(); | ||||||
|         } |         } | ||||||
|         psitdata = new PlayerSitData(this); |         if (sitPickupEnabled) { | ||||||
|  |         	chairEffects.startPickup(); | ||||||
|  |         } | ||||||
|         getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this); |         getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this); | ||||||
|         getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this); |         getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this); | ||||||
|         getServer().getPluginManager().registerEvents(new CommandRestrict(this), this); |         getServer().getPluginManager().registerEvents(new CommandRestrict(this), this); | ||||||
| @@ -98,6 +102,7 @@ public class Chairs extends JavaPlugin { | |||||||
|             ignoreList.save(); |             ignoreList.save(); | ||||||
|         } |         } | ||||||
|         chairEffects.cancelHealing(); |         chairEffects.cancelHealing(); | ||||||
|  |         chairEffects.cancelPickup(); | ||||||
|         chairEffects = null; |         chairEffects = null; | ||||||
|         log = null; |         log = null; | ||||||
|         vehiclearrowclass = null; |         vehiclearrowclass = null; | ||||||
|   | |||||||
| @@ -44,6 +44,11 @@ public class ChairsCommand implements CommandExecutor { | |||||||
|                 } else { |                 } else { | ||||||
|                 	plugin.chairEffects.cancelHealing(); |                 	plugin.chairEffects.cancelHealing(); | ||||||
|                 } |                 } | ||||||
|  |                 if (plugin.sitPickupEnabled) { | ||||||
|  |                 	plugin.chairEffects.restartPickup(); | ||||||
|  |                 } else { | ||||||
|  |                 	plugin.chairEffects.cancelPickup(); | ||||||
|  |                 } | ||||||
|                 if (!plugin.msgReloaded.isEmpty()) { |                 if (!plugin.msgReloaded.isEmpty()) { | ||||||
|                     sender.sendMessage(plugin.msgReloaded); |                     sender.sendMessage(plugin.msgReloaded); | ||||||
|                 } |                 } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Shevchik
					Shevchik