Switch to arrow method
This commit is contained in:
parent
1dabe40aad
commit
b919975d1c
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package com.cnaude.chairs;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import net.minecraft.server.v1_6_R2.DataWatcher;
|
|
||||||
import net.minecraft.server.v1_6_R2.WatchableObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author cnaude
|
|
||||||
*/
|
|
||||||
public class ChairWatcher extends DataWatcher {
|
|
||||||
|
|
||||||
private byte metadata;
|
|
||||||
|
|
||||||
public ChairWatcher(byte i) {
|
|
||||||
this.metadata = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<WatchableObject> b() {
|
|
||||||
ArrayList<WatchableObject> list = new ArrayList<WatchableObject>();
|
|
||||||
WatchableObject wo = new WatchableObject(0, 0, this.metadata);
|
|
||||||
list.add(wo);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,5 @@
|
|||||||
package com.cnaude.chairs;
|
package com.cnaude.chairs;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -42,7 +40,6 @@ public class Chairs extends JavaPlugin {
|
|||||||
public PluginManager pm;
|
public PluginManager pm;
|
||||||
public static ChairsIgnoreList ignoreList;
|
public static ChairsIgnoreList ignoreList;
|
||||||
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled;
|
public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled;
|
||||||
private ProtocolManager protocolManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -62,12 +59,6 @@ public class Chairs extends JavaPlugin {
|
|||||||
logInfo("Enabling sitting effects.");
|
logInfo("Enabling sitting effects.");
|
||||||
chairEffects = new ChairEffects(this);
|
chairEffects = new ChairEffects(this);
|
||||||
}
|
}
|
||||||
if (isProtocolLibLoaded()) {
|
|
||||||
logInfo("ProtocolLib detected.");
|
|
||||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
|
||||||
} else {
|
|
||||||
logInfo("ProtocolLib not detected. Using NMS code methods instead.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,7 +11,8 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.material.Directional;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||||
import org.bukkit.material.Stairs;
|
import org.bukkit.material.Stairs;
|
||||||
import org.bukkit.material.Step;
|
import org.bukkit.material.Step;
|
||||||
import org.bukkit.material.WoodenStep;
|
import org.bukkit.material.WoodenStep;
|
||||||
@ -38,9 +39,54 @@ public class EventListener implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onVehicleExitEvent(VehicleExitEvent event) {
|
||||||
|
Entity e = event.getVehicle().getPassenger();
|
||||||
|
if (e instanceof Player) {
|
||||||
|
Player player = (Player) e;
|
||||||
|
if (plugin.sit.containsKey(player.getName())) {
|
||||||
|
unSit(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMoveEvent(PlayerMoveEvent event) {
|
||||||
|
if (event.getFrom().distance(event.getTo()) > 0) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (plugin.sit.containsKey(player.getName())) {
|
||||||
|
if (plugin.sit.get(player.getName()).getLocation().distance(player.getLocation()) > 0.5) {
|
||||||
|
unSit(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unSit(Player player) {
|
||||||
|
plugin.sit.get(player.getName()).remove();
|
||||||
|
plugin.sit.remove(player.getName());
|
||||||
|
if (plugin.notifyplayer && !plugin.msgStanding.isEmpty()) {
|
||||||
|
player.sendMessage(plugin.msgStanding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSitting(Player player) {
|
||||||
|
if (player.isInsideVehicle()) {
|
||||||
|
if (plugin.sit.containsKey(player.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (plugin.sit.containsKey(player.getName())) {
|
||||||
|
unSit(player);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
if (isSitting(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.getPlayer().getItemInHand().getType().isBlock()
|
if (event.getPlayer().getItemInHand().getType().isBlock()
|
||||||
&& (event.getPlayer().getItemInHand().getTypeId() != 0)
|
&& (event.getPlayer().getItemInHand().getTypeId() != 0)
|
||||||
&& plugin.ignoreIfBlockInHand) {
|
&& plugin.ignoreIfBlockInHand) {
|
||||||
@ -136,23 +182,6 @@ public class EventListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if player is sitting.
|
|
||||||
if (plugin.sit.containsKey(player.getName())) {
|
|
||||||
if (plugin.sit.containsKey(player.getName())) {
|
|
||||||
// Eject from arrow
|
|
||||||
plugin.sit.get(player.getName()).eject();
|
|
||||||
// Remove arrow
|
|
||||||
plugin.sit.get(player.getName()).remove();
|
|
||||||
}
|
|
||||||
plugin.sit.remove(player.getName());
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (plugin.notifyplayer && !plugin.msgStanding.isEmpty()) {
|
|
||||||
player.sendMessage(plugin.msgStanding);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for distance distance between player and chair.
|
// Check for distance distance between player and chair.
|
||||||
if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) {
|
if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) {
|
||||||
return;
|
return;
|
||||||
@ -222,48 +251,40 @@ public class EventListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Location chairLoc = event.getClickedBlock().getLocation().add(0.5, 0, 0.5);
|
Location plocation = block.getLocation().clone();
|
||||||
|
plocation.add(0.5D, (sh - 0.5D), 0.5D);
|
||||||
|
|
||||||
// Rotate the player's view to the descending side of the block.
|
// Rotate the player's view to the descending side of the block.
|
||||||
if (plugin.autoRotate && stairs != null) {
|
if (plugin.autoRotate && stairs != null) {
|
||||||
BlockFace direction = ((Directional) event.getClickedBlock().getState().getData()).getFacing();
|
switch (stairs.getDescendingDirection()) {
|
||||||
|
case NORTH:
|
||||||
double dx = direction.getModX();
|
plocation.setYaw(180);
|
||||||
double dy = direction.getModY();
|
break;
|
||||||
double dz = direction.getModZ();
|
case EAST:
|
||||||
|
plocation.setYaw(-90);
|
||||||
if (dx != 0) {
|
break;
|
||||||
if (dx < 0) {
|
case SOUTH:
|
||||||
chairLoc.setYaw((float) (1.5 * Math.PI));
|
plocation.setYaw(0);
|
||||||
} else {
|
break;
|
||||||
chairLoc.setYaw((float) (0.5 * Math.PI));
|
case WEST:
|
||||||
}
|
plocation.setYaw(90);
|
||||||
chairLoc.setYaw((float) (chairLoc.getYaw() - Math.atan(dz / dx)));
|
|
||||||
} else if (dz < 0) {
|
|
||||||
chairLoc.setYaw((float) Math.PI);
|
|
||||||
}
|
}
|
||||||
|
player.teleport(plocation);
|
||||||
double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));
|
|
||||||
|
|
||||||
chairLoc.setPitch((float) -Math.atan(dy / dxz));
|
|
||||||
|
|
||||||
chairLoc.setYaw(-chairLoc.getYaw() * 180f / (float) Math.PI);
|
|
||||||
chairLoc.setPitch(chairLoc.getPitch() * 180f / (float) Math.PI);
|
|
||||||
} else {
|
} else {
|
||||||
chairLoc.setPitch(player.getPlayer().getLocation().getPitch());
|
plocation.setYaw(player.getLocation().getYaw());
|
||||||
chairLoc.setYaw(player.getPlayer().getLocation().getYaw());
|
|
||||||
}
|
}
|
||||||
//player.setSneaking(true);
|
|
||||||
if (plugin.notifyplayer && !plugin.msgSitting.isEmpty()) {
|
if (plugin.notifyplayer && !plugin.msgSitting.isEmpty()) {
|
||||||
player.sendMessage(plugin.msgSitting);
|
player.sendMessage(plugin.msgSitting);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getPlayer().teleport(chairLoc);
|
player.getPlayer().teleport(plocation);
|
||||||
Entity ar = block.getWorld().spawnArrow(getBlockCentre(block).subtract(0, 0.5, 0), new Vector(0, 0, 0), 0, 0);
|
Entity arrow = block.getWorld().spawnArrow(getBlockCentre(block).subtract(0, 0.5, 0), new Vector(0, 0, 0), 0, 0);
|
||||||
player.setSneaking(false);
|
|
||||||
ar.setPassenger(player);
|
arrow.setPassenger(player);
|
||||||
ar.setTicksLived(1);
|
player.setSneaking(false);
|
||||||
plugin.sit.put(player.getName(), ar);
|
arrow.setTicksLived(1);
|
||||||
|
plugin.sit.put(player.getName(), arrow);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ authors:
|
|||||||
- spoothie
|
- spoothie
|
||||||
- cnaude
|
- cnaude
|
||||||
main: com.cnaude.chairs.Chairs
|
main: com.cnaude.chairs.Chairs
|
||||||
softdepend:
|
|
||||||
- ProtocolLib
|
|
||||||
commands:
|
commands:
|
||||||
chairs:
|
chairs:
|
||||||
description: Various commands for Chairs.
|
description: Various commands for Chairs.
|
||||||
|
Loading…
Reference in New Issue
Block a user