Added healing while sitting.
Updated for CB1.5.0-R0.1
This commit is contained in:
parent
268ec403c1
commit
db1912445e
@ -43,3 +43,9 @@ seat-occupied-check: true
|
|||||||
upper-step-check: true
|
upper-step-check: true
|
||||||
per-item-perms: 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;
|
package net.spoothie.chairs;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import net.minecraft.server.v1_4_R1.DataWatcher;
|
import net.minecraft.server.v1_5_R1.DataWatcher;
|
||||||
import net.minecraft.server.v1_4_R1.WatchableObject;
|
import net.minecraft.server.v1_5_R1.WatchableObject;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,12 +6,12 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
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.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
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.entity.Player;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
@ -20,12 +20,17 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public class Chairs extends JavaPlugin {
|
public class Chairs extends JavaPlugin {
|
||||||
private static Chairs instance = null;
|
private static Chairs instance = null;
|
||||||
|
public static ChairEffects chairEffects;
|
||||||
public List<ChairBlock> allowedBlocks = new ArrayList<ChairBlock>();
|
public List<ChairBlock> allowedBlocks = new ArrayList<ChairBlock>();
|
||||||
public List<Material> validSigns = new ArrayList<Material>();
|
public List<Material> validSigns = new ArrayList<Material>();
|
||||||
public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
|
public boolean sneaking, autoRotate, signCheck, permissions, notifyplayer, opsOverridePerms;
|
||||||
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
|
public boolean invertedStairCheck, seatOccupiedCheck, invertedStepCheck, perItemPerms;
|
||||||
|
public boolean sitEffectsEnabled;
|
||||||
public double sittingHeight, sittingHeightAdj, distance;
|
public double sittingHeight, sittingHeightAdj, distance;
|
||||||
public int maxChairWidth;
|
public int maxChairWidth;
|
||||||
|
public int sitMaxHealth;
|
||||||
|
public int sitHealthPerInterval;
|
||||||
|
public int sitEffectInterval;
|
||||||
private File pluginFolder;
|
private File pluginFolder;
|
||||||
private File configFile;
|
private File configFile;
|
||||||
public byte metadata;
|
public byte metadata;
|
||||||
@ -50,11 +55,24 @@ public class Chairs extends JavaPlugin {
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
getServer().getPluginManager().registerEvents(new EventListener(this, ignoreList), this);
|
getServer().getPluginManager().registerEvents(new EventListener(this, ignoreList), this);
|
||||||
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
getCommand("chairs").setExecutor(new ChairsCommand(this, ignoreList));
|
||||||
|
if (sitEffectsEnabled) {
|
||||||
|
logInfo("Enabling sitting effects.");
|
||||||
|
chairEffects = new ChairEffects(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
ignoreList.save();
|
ignoreList.save();
|
||||||
|
if (chairEffects != null) {
|
||||||
|
chairEffects.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void restartEffectsTask() {
|
||||||
|
if (chairEffects != null) {
|
||||||
|
chairEffects.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createConfig() {
|
private void createConfig() {
|
||||||
@ -91,6 +109,11 @@ public class Chairs extends JavaPlugin {
|
|||||||
perItemPerms = getConfig().getBoolean("per-item-perms");
|
perItemPerms = getConfig().getBoolean("per-item-perms");
|
||||||
opsOverridePerms = getConfig().getBoolean("ops-override-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")) {
|
for (String s : getConfig().getStringList("allowed-blocks")) {
|
||||||
String type;
|
String type;
|
||||||
double sh = sittingHeight;
|
double sh = sittingHeight;
|
||||||
@ -137,6 +160,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
perms.add("chairs.sit");
|
perms.add("chairs.sit");
|
||||||
perms.add("chairs.reload");
|
perms.add("chairs.reload");
|
||||||
perms.add("chairs.self");
|
perms.add("chairs.self");
|
||||||
|
perms.add("chairs.sit.health");
|
||||||
for (String s : perms) {
|
for (String s : perms) {
|
||||||
if (pm.getPermission(s) != null) {
|
if (pm.getPermission(s) != null) {
|
||||||
pm.removePermission(s);
|
pm.removePermission(s);
|
||||||
|
@ -33,6 +33,7 @@ public class ChairsCommand implements CommandExecutor {
|
|||||||
if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) {
|
if (sender.hasPermission("chairs.reload") || !(sender instanceof Player)) {
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
plugin.loadConfig();
|
plugin.loadConfig();
|
||||||
|
plugin.restartEffectsTask();
|
||||||
sender.sendMessage("Chairs configuration file reloaded.");
|
sender.sendMessage("Chairs configuration file reloaded.");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.GRAY + "No permission to do this!");
|
sender.sendMessage(ChatColor.GRAY + "No permission to do this!");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: Chairs
|
name: Chairs
|
||||||
version: 1.18.1
|
version: 1.20.0
|
||||||
description: Let players sit on blocks.
|
description: Let players sit on blocks.
|
||||||
authors:
|
authors:
|
||||||
- spoothie
|
- spoothie
|
||||||
|
Loading…
Reference in New Issue
Block a user