Added healing while sitting.
Updated for CB1.5.0-R0.1
This commit is contained in:
parent
268ec403c1
commit
db1912445e
@ -42,4 +42,10 @@ upside-down-check: true
|
||||
seat-occupied-check: true
|
||||
upper-step-check: true
|
||||
per-item-perms: true
|
||||
ops-override-perms: false
|
||||
ops-override-perms: false
|
||||
sit-effects:
|
||||
enabled: false
|
||||
interval: 20
|
||||
healing:
|
||||
amount: 1
|
||||
max-percent: 100
|
||||
|
57
src/net/spoothie/chairs/ChairEffects.java
Normal file
57
src/net/spoothie/chairs/ChairEffects.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.spoothie.chairs;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author cnaude
|
||||
*/
|
||||
public class ChairEffects {
|
||||
|
||||
Chairs plugin;
|
||||
int taskID;
|
||||
|
||||
public ChairEffects(Chairs plugin) {
|
||||
this.plugin = plugin;
|
||||
effectsTask();
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
plugin.getServer().getScheduler().cancelTask(taskID);
|
||||
taskID = 0;
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
this.cancel();
|
||||
this.effectsTask();
|
||||
}
|
||||
|
||||
private void effectsTask() {
|
||||
taskID = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
String pName = p.getName();
|
||||
if (plugin.sit.containsKey(pName)) {
|
||||
if (p.hasPermission("chairs.sit.health")) {
|
||||
double pHealthPcnt = (double) p.getHealth() / (double) p.getMaxHealth() * 100d;
|
||||
if ((pHealthPcnt < plugin.sitMaxHealth)
|
||||
&& (p.getHealth() < p.getMaxHealth())) {
|
||||
int newHealth = plugin.sitHealthPerInterval + p.getHealth();
|
||||
if (newHealth > p.getMaxHealth()) {
|
||||
newHealth = p.getMaxHealth();
|
||||
}
|
||||
p.setHealth(newHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, plugin.sitEffectInterval, plugin.sitEffectInterval);
|
||||
}
|
||||
}
|
@ -5,8 +5,8 @@
|
||||
package net.spoothie.chairs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.server.v1_4_R1.DataWatcher;
|
||||
import net.minecraft.server.v1_4_R1.WatchableObject;
|
||||
import net.minecraft.server.v1_5_R1.DataWatcher;
|
||||
import net.minecraft.server.v1_5_R1.WatchableObject;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -6,12 +6,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.v1_4_R1.Packet40EntityMetadata;
|
||||
import net.minecraft.server.v1_5_R1.Packet40EntityMetadata;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@ -20,12 +20,17 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Chairs extends JavaPlugin {
|
||||
private static Chairs instance = null;
|
||||
public static ChairEffects chairEffects;
|
||||
public List<ChairBlock> allowedBlocks = new ArrayList<ChairBlock>();
|
||||
public List<Material> validSigns = new ArrayList<Material>();
|
||||
public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
|
||||
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
|
||||
public boolean sitEffectsEnabled;
|
||||
public double sittingHeight, sittingHeightAdj, distance;
|
||||
public int maxChairWidth;
|
||||
public int sitMaxHealth;
|
||||
public int sitHealthPerInterval;
|
||||
public int sitEffectInterval;
|
||||
private File pluginFolder;
|
||||
private File configFile;
|
||||
public byte metadata;
|
||||
@ -50,11 +55,24 @@ public class Chairs extends JavaPlugin {
|
||||
loadConfig();
|
||||
getServer().getPluginManager().registerEvents(new EventListener(this, ignoreList), this);
|
||||
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
||||
if (sitEffectsEnabled) {
|
||||
logInfo("Enabling sitting effects.");
|
||||
chairEffects = new ChairEffects(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
ignoreList.save();
|
||||
if (chairEffects != null) {
|
||||
chairEffects.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public void restartEffectsTask() {
|
||||
if (chairEffects != null) {
|
||||
chairEffects.restart();
|
||||
}
|
||||
}
|
||||
|
||||
private void createConfig() {
|
||||
@ -90,6 +108,11 @@ public class Chairs extends JavaPlugin {
|
||||
invertedStepCheck = getConfig().getBoolean("upper-step-check");
|
||||
perItemPerms = getConfig().getBoolean("per-item-perms");
|
||||
opsOverridePerms = getConfig().getBoolean("ops-override-perms");
|
||||
|
||||
sitEffectsEnabled = getConfig().getBoolean("sit-effects.enabled", false);
|
||||
sitEffectInterval = getConfig().getInt("sit-effects.interval",20);
|
||||
sitMaxHealth = getConfig().getInt("sit-effects.healing.max-percent",100);
|
||||
sitHealthPerInterval = getConfig().getInt("sit-effects.healing.amount",1);
|
||||
|
||||
for (String s : getConfig().getStringList("allowed-blocks")) {
|
||||
String type;
|
||||
@ -137,6 +160,7 @@ public class Chairs extends JavaPlugin {
|
||||
perms.add("chairs.sit");
|
||||
perms.add("chairs.reload");
|
||||
perms.add("chairs.self");
|
||||
perms.add("chairs.sit.health");
|
||||
for (String s : perms) {
|
||||
if (pm.getPermission(s) != null) {
|
||||
pm.removePermission(s);
|
||||
|
@ -33,6 +33,7 @@ public class ChairsCommand implements CommandExecutor {
|
||||
if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) {
|
||||
plugin.reloadConfig();
|
||||
plugin.loadConfig();
|
||||
plugin.restartEffectsTask();
|
||||
sender.sendMessage("Chairs configuration file reloaded.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.GRAY + "No permission to do this!");
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: Chairs
|
||||
version: 1.18.1
|
||||
version: 1.20.0
|
||||
description: Let players sit on blocks.
|
||||
authors:
|
||||
- spoothie
|
||||
|
Loading…
Reference in New Issue
Block a user