Add command to clear arrows, fix healing effects.
This commit is contained in:
parent
26368e2b9a
commit
b3c5a1fcc9
@ -18,17 +18,20 @@ public class ChairEffects {
|
||||
|
||||
public ChairEffects(Chairs plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void startHealing() {
|
||||
effectsTask();
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
public void cancelHealing() {
|
||||
plugin.getServer().getScheduler().cancelTask(taskID);
|
||||
taskID = 0;
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
this.cancel();
|
||||
this.effectsTask();
|
||||
public void restartHealing() {
|
||||
cancelHealing();
|
||||
startHealing();
|
||||
}
|
||||
|
||||
private void effectsTask() {
|
||||
|
@ -71,11 +71,15 @@ public class Chairs extends JavaPlugin {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
chairEffects = new ChairEffects(this);
|
||||
ignoreList = new ChairsIgnoreList(this);
|
||||
ignoreList.load();
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
loadConfig();
|
||||
if (sitEffectsEnabled) {
|
||||
chairEffects.startHealing();
|
||||
}
|
||||
psitdata = new PlayerSitData(this);
|
||||
getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this);
|
||||
getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this);
|
||||
@ -93,20 +97,12 @@ public class Chairs extends JavaPlugin {
|
||||
if (ignoreList != null) {
|
||||
ignoreList.save();
|
||||
}
|
||||
if (chairEffects != null) {
|
||||
chairEffects.cancel();
|
||||
}
|
||||
chairEffects.cancelHealing();
|
||||
chairEffects = null;
|
||||
log = null;
|
||||
vehiclearrowclass = null;
|
||||
psitdata = null;
|
||||
}
|
||||
|
||||
public void restartEffectsTask() {
|
||||
if (chairEffects != null) {
|
||||
chairEffects.restart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadConfig() {
|
||||
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"));
|
||||
|
||||
sitEffectsEnabled = config.getBoolean("sit-effects.enabled", false);
|
||||
sitEffectInterval = config.getInt("sit-effects.interval",20);
|
||||
sitEffectsEnabled = config.getBoolean("sit-effects.healing.enabled", false);
|
||||
sitEffectInterval = config.getInt("sit-effects.healing.interval",20);
|
||||
sitMaxHealth = config.getInt("sit-effects.healing.max-percent",100);
|
||||
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");
|
||||
sitDisabledCommands = new HashSet<String>(config.getStringList("sit-restrictions.commands.list"));
|
||||
|
@ -4,9 +4,17 @@
|
||||
*/
|
||||
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.CommandExecutor;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -30,9 +38,8 @@ public class ChairsCommand implements CommandExecutor {
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) {
|
||||
//plugin.reloadConfig();
|
||||
plugin.loadConfig();
|
||||
plugin.restartEffectsTask();
|
||||
plugin.chairEffects.restartHealing();
|
||||
if (!plugin.msgReloaded.isEmpty()) {
|
||||
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) {
|
||||
Player p = (Player) sender;
|
||||
if (args[0].equalsIgnoreCase("on")) {
|
||||
@ -68,8 +89,23 @@ public class ChairsCommand implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
//plugin.sendSit(p,Integer.parseInt(args[0]));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,17 @@ public class PlayerSitData {
|
||||
{
|
||||
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)
|
||||
{
|
||||
return sitblock.containsKey(block);
|
||||
|
@ -39,9 +39,9 @@ ignore-if-item-in-hand: false
|
||||
disabledWGRegions:
|
||||
- exampleregionname
|
||||
sit-effects:
|
||||
enabled: false
|
||||
interval: 20
|
||||
healing:
|
||||
enabled: false
|
||||
interval: 20
|
||||
amount: 1
|
||||
max-percent: 100
|
||||
sit-restrictions:
|
||||
|
Loading…
Reference in New Issue
Block a user