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