Add command to clear arrows, fix healing effects.

This commit is contained in:
Shevchik 2014-01-02 17:42:06 +04:00
parent 26368e2b9a
commit b3c5a1fcc9
5 changed files with 67 additions and 28 deletions

View File

@ -18,17 +18,20 @@ public class ChairEffects {
public ChairEffects(Chairs plugin) { public ChairEffects(Chairs plugin) {
this.plugin = plugin; this.plugin = plugin;
}
public void startHealing() {
effectsTask(); effectsTask();
} }
public void cancel() { public void cancelHealing() {
plugin.getServer().getScheduler().cancelTask(taskID); plugin.getServer().getScheduler().cancelTask(taskID);
taskID = 0; taskID = 0;
} }
public void restart() { public void restartHealing() {
this.cancel(); cancelHealing();
this.effectsTask(); startHealing();
} }
private void effectsTask() { private void effectsTask() {

View File

@ -71,11 +71,15 @@ public class Chairs extends JavaPlugin {
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
} }
chairEffects = new ChairEffects(this);
ignoreList = new ChairsIgnoreList(this); ignoreList = new ChairsIgnoreList(this);
ignoreList.load(); ignoreList.load();
getConfig().options().copyDefaults(true); getConfig().options().copyDefaults(true);
saveConfig(); saveConfig();
loadConfig(); loadConfig();
if (sitEffectsEnabled) {
chairEffects.startHealing();
}
psitdata = new PlayerSitData(this); psitdata = new PlayerSitData(this);
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);
@ -93,20 +97,12 @@ public class Chairs extends JavaPlugin {
if (ignoreList != null) { if (ignoreList != null) {
ignoreList.save(); ignoreList.save();
} }
if (chairEffects != null) { chairEffects.cancelHealing();
chairEffects.cancel(); chairEffects = null;
}
log = null; log = null;
vehiclearrowclass = null; vehiclearrowclass = null;
psitdata = null; psitdata = null;
} }
public void restartEffectsTask() {
if (chairEffects != null) {
chairEffects.restart();
}
}
public void loadConfig() { public void loadConfig() {
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml")); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml"));
@ -119,17 +115,10 @@ public class Chairs extends JavaPlugin {
disabledRegions = new HashSet<String>(config.getStringList("disabledWGRegions")); disabledRegions = new HashSet<String>(config.getStringList("disabledWGRegions"));
sitEffectsEnabled = config.getBoolean("sit-effects.enabled", false); sitEffectsEnabled = config.getBoolean("sit-effects.healing.enabled", false);
sitEffectInterval = config.getInt("sit-effects.interval",20); sitEffectInterval = config.getInt("sit-effects.healing.interval",20);
sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100); sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100);
sitHealthPerInterval = config.getInt("sit-effects.healing.amount",1); sitHealthPerInterval = config.getInt("sit-effects.healing.amount",1);
if (sitEffectsEnabled) {
if (chairEffects != null) {
chairEffects.cancel();
}
logInfo("Enabling sitting effects.");
chairEffects = new ChairEffects(this);
}
sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all"); sitDisableAllCommands = config.getBoolean("sit-restrictions.commands.all");
sitDisabledCommands = new HashSet<String>(config.getStringList("sit-restrictions.commands.list")); sitDisabledCommands = new HashSet<String>(config.getStringList("sit-restrictions.commands.list"));

View File

@ -4,9 +4,17 @@
*/ */
package com.cnaude.chairs; package com.cnaude.chairs;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.RemoteConsoleCommandSender;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
@ -30,9 +38,8 @@ public class ChairsCommand implements CommandExecutor {
} }
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) { if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) {
//plugin.reloadConfig();
plugin.loadConfig(); plugin.loadConfig();
plugin.restartEffectsTask(); plugin.chairEffects.restartHealing();
if (!plugin.msgReloaded.isEmpty()) { if (!plugin.msgReloaded.isEmpty()) {
sender.sendMessage(plugin.msgReloaded); sender.sendMessage(plugin.msgReloaded);
} }
@ -42,6 +49,20 @@ public class ChairsCommand implements CommandExecutor {
} }
} }
} }
if (args[0].equalsIgnoreCase("removearrows")) {
if (sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender || (sender instanceof Player && sender.hasPermission("chairs.removearrows"))) {
if (args.length == 2) {
World world = Bukkit.getWorld(args[1]);
int removed = removeArrows(world);
sender.sendMessage("Removed "+removed+" unused arrows");
} else if (args.length == 1) {
for (World world : Bukkit.getWorlds()) {
int removed = removeArrows(world);
sender.sendMessage("Removed "+removed+" unused arrows");
}
}
}
}
if (sender instanceof Player) { if (sender instanceof Player) {
Player p = (Player) sender; Player p = (Player) sender;
if (args[0].equalsIgnoreCase("on")) { if (args[0].equalsIgnoreCase("on")) {
@ -68,8 +89,23 @@ public class ChairsCommand implements CommandExecutor {
} }
} }
} }
//plugin.sendSit(p,Integer.parseInt(args[0]));
} }
return true; return true;
} }
private int removeArrows(World world) {
Iterator<Entity> entityit = world.getEntities().iterator();
int removed = 0;
while (entityit.hasNext()) {
Entity entity = entityit.next();
if (entity instanceof Arrow) {
if (!plugin.getPlayerSitData().isAroowOccupied(entity)) {
entity.remove();
removed++;
}
}
}
return removed;
}
} }

View File

@ -29,6 +29,17 @@ public class PlayerSitData {
{ {
return sit.containsKey(player.getName()); return sit.containsKey(player.getName());
} }
protected boolean isAroowOccupied(Entity entity)
{
for (Entity usedentity : sit.values())
{
if (usedentity.getEntityId() == entity.getEntityId())
{
return true;
}
}
return false;
}
protected boolean isBlockOccupied(Block block) protected boolean isBlockOccupied(Block block)
{ {
return sitblock.containsKey(block); return sitblock.containsKey(block);

View File

@ -39,9 +39,9 @@ ignore-if-item-in-hand: false
disabledWGRegions: disabledWGRegions:
- exampleregionname - exampleregionname
sit-effects: sit-effects:
enabled: false
interval: 20
healing: healing:
enabled: false
interval: 20
amount: 1 amount: 1
max-percent: 100 max-percent: 100
sit-restrictions: sit-restrictions: