Only check damage values for non stairs.

This commit is contained in:
cnaude 2013-07-07 22:38:51 -07:00
parent b3e9003c35
commit e1d69b75d0
7 changed files with 47 additions and 16 deletions

View File

@ -42,7 +42,7 @@ public class ChairEffects {
double pHealthPcnt = (double) p.getHealth() / (double) p.getMaxHealth() * 100d; double pHealthPcnt = (double) p.getHealth() / (double) p.getMaxHealth() * 100d;
if ((pHealthPcnt < plugin.sitMaxHealth) if ((pHealthPcnt < plugin.sitMaxHealth)
&& (p.getHealth() < p.getMaxHealth())) { && (p.getHealth() < p.getMaxHealth())) {
double newHealth = plugin.sitHealthPerInterval + p.getHealth(); int newHealth = plugin.sitHealthPerInterval + p.getHealth();
if (newHealth > p.getMaxHealth()) { if (newHealth > p.getMaxHealth()) {
newHealth = p.getMaxHealth(); newHealth = p.getMaxHealth();
} }

View File

@ -5,8 +5,8 @@
package com.cnaude.chairs; package com.cnaude.chairs;
import java.util.ArrayList; import java.util.ArrayList;
import net.minecraft.server.v1_6_R1.DataWatcher; import net.minecraft.server.v1_5_R3.DataWatcher;
import net.minecraft.server.v1_6_R1.WatchableObject; import net.minecraft.server.v1_5_R3.WatchableObject;
/** /**
* *
@ -24,6 +24,7 @@ public class ChairWatcher extends DataWatcher {
public ArrayList<WatchableObject> b() { public ArrayList<WatchableObject> b() {
ArrayList<WatchableObject> list = new ArrayList<WatchableObject>(); ArrayList<WatchableObject> list = new ArrayList<WatchableObject>();
WatchableObject wo = new WatchableObject(0, 0, Byte.valueOf(this.metadata)); WatchableObject wo = new WatchableObject(0, 0, Byte.valueOf(this.metadata));
//WatchableObject wo = new WatchableObject(0, 0, 4);
list.add(wo); list.add(wo);
return list; return list;
} }

View File

@ -10,12 +10,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_6_R1.Packet40EntityMetadata; import net.minecraft.server.v1_5_R3.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_6_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
@ -39,6 +39,7 @@ public class Chairs extends JavaPlugin {
private File pluginFolder; private File pluginFolder;
private File configFile; private File configFile;
public byte metadata; public byte metadata;
public int packet;
public HashMap<String, Location> sit = new HashMap<String, Location>(); public HashMap<String, Location> sit = new HashMap<String, Location>();
public static final String PLUGIN_NAME = "Chairs"; public static final String PLUGIN_NAME = "Chairs";
public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]"; public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]";
@ -120,6 +121,8 @@ public class Chairs extends JavaPlugin {
} }
public void loadConfig() { public void loadConfig() {
packet = getConfig().getInt("packet");
logInfo("Sitting packet byte: " + packet);
autoRotate = getConfig().getBoolean("auto-rotate"); autoRotate = getConfig().getBoolean("auto-rotate");
sneaking = getConfig().getBoolean("sneaking"); sneaking = getConfig().getBoolean("sneaking");
signCheck = getConfig().getBoolean("sign-check"); signCheck = getConfig().getBoolean("sign-check");
@ -225,7 +228,7 @@ public class Chairs extends JavaPlugin {
PacketContainer fakeSit = protocolManager.createPacket(40); PacketContainer fakeSit = protocolManager.createPacket(40);
fakeSit.getSpecificModifier(int.class).write(0, p.getEntityId()); fakeSit.getSpecificModifier(int.class).write(0, p.getEntityId());
WrappedDataWatcher watcher = new WrappedDataWatcher(); WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setObject(0, (byte)4); watcher.setObject(0, (byte)packet);
fakeSit.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); fakeSit.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
return fakeSit; return fakeSit;
} }
@ -244,8 +247,16 @@ public class Chairs extends JavaPlugin {
if (protocolManager != null) { if (protocolManager != null) {
sendPacketToPlayers(getSitPacket(p),p); sendPacketToPlayers(getSitPacket(p),p);
} else { } else {
Packet40EntityMetadata packet = new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) 4), false); sendPacketToPlayers(new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) packet), false),p);
sendPacketToPlayers(packet,p); }
}
public void sendSit(Player p, int i) {
if (protocolManager != null) {
sendPacketToPlayers(getSitPacket(p),p);
} else {
p.sendMessage("sit: " + i);
sendPacketToPlayers(new Packet40EntityMetadata(p.getPlayer().getEntityId(), new ChairWatcher((byte) i), false),p);
} }
} }

View File

@ -68,6 +68,7 @@ public class ChairsCommand implements CommandExecutor {
} }
} }
} }
plugin.sendSit(p,Integer.parseInt(args[0]));
} }
return true; return true;
} }

View File

@ -35,6 +35,7 @@ public class EventListener implements Listener {
this.ignoreList = ignoreList; this.ignoreList = ignoreList;
} }
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -148,12 +149,28 @@ public class EventListener implements Listener {
"Allow players to sit on a '" + block.getType().name() + "'", "Allow players to sit on a '" + block.getType().name() + "'",
PermissionDefault.FALSE)); PermissionDefault.FALSE));
} }
if (plugin.pm.getPermission("chairs.sit." + block.getTypeId() + ":" + block.getData()) == null) {
plugin.pm.addPermission(new Permission("chairs.sit." + block.getTypeId() + ":" + block.getData(),
"Allow players to sit on a '" + block.getType().name() + "'",
PermissionDefault.FALSE));
}
if (plugin.pm.getPermission("chairs.sit." + block.getType().toString() + ":" + block.getData()) == null) {
plugin.pm.addPermission(new Permission("chairs.sit." + block.getType().toString() + ":" + block.getData(),
"Allow players to sit on a '" + block.getType().name() + "'",
PermissionDefault.FALSE));
}
} }
for (ChairBlock cb : plugin.allowedBlocks) { for (ChairBlock cb : plugin.allowedBlocks) {
//plugin.logInfo("Comparing: (" + cb.getMat().name() + " ? " + block.getType().name() + ") (" plugin.logInfo("Comparing: (" + cb.getMat().name() + " ? " + block.getType().name() + ") ("
// + cb.getDamage() + " ? " + block.getData() + ")"); + cb.getDamage() + " ? " + block.getData() + ")");
if (cb.getMat().equals(block.getType()) if (cb.getMat().toString().contains("STAIRS")) {
if (cb.getMat().equals(block.getType())) {
blockOkay = true;
sh = cb.getSitHeight();
continue;
}
} else if (cb.getMat().equals(block.getType())
&& cb.getDamage() == block.getData()) { && cb.getDamage() == block.getData()) {
blockOkay = true; blockOkay = true;
sh = cb.getSitHeight(); sh = cb.getSitHeight();

View File

@ -61,4 +61,5 @@ messages:
no-permission: '&cYou do not have permission to do this!' no-permission: '&cYou do not have permission to do this!'
enabled: '&7You have enabled chairs for yourself!' enabled: '&7You have enabled chairs for yourself!'
disabled: '&7You have disabled chairs for yourself!' disabled: '&7You have disabled chairs for yourself!'
packet: 4

View File

@ -1,5 +1,5 @@
name: Chairs name: Chairs
version: 2.1.5 version: 2.1.4a
description: Let players sit on blocks. description: Let players sit on blocks.
website: http://dev.bukkit.org/bukkit-plugins/chairsreloaded/ website: http://dev.bukkit.org/bukkit-plugins/chairsreloaded/
authors: authors: