122 lines
4.7 KiB
Java
122 lines
4.7 KiB
Java
package cn.citycraft.JumpPlate;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.BlockFace;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.block.Action;
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
/**
|
|
*
|
|
* @since 2016年2月22日 上午10:57:37
|
|
* @author 喵♂呜
|
|
*/
|
|
public class JumpPlateListener implements Listener {
|
|
Set<String> fall = new HashSet<>();
|
|
List<Material> ml = new ArrayList<>();
|
|
|
|
public JumpPlateListener() {
|
|
ml.add(Material.IRON_BLOCK);
|
|
ml.add(Material.GOLD_BLOCK);
|
|
ml.add(Material.DIAMOND_BLOCK);
|
|
ml.add(Material.EMERALD_BLOCK);
|
|
ml.add(Material.BEDROCK);
|
|
}
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
public void onCreate(final BlockPlaceEvent e) {
|
|
final Player p = e.getPlayer();
|
|
if (e.getBlockPlaced().getType() == Material.GOLD_PLATE) {
|
|
final Location gb = e.getBlockPlaced().getLocation();
|
|
final Block loc = gb.add(0.0D, -1.0D, 0.0D).getBlock();
|
|
final Block loc_1 = gb.add(0.0D, -1.0D, 0.0D).getBlock();
|
|
final Block loc_2 = gb.add(0.0D, -1.0D, 0.0D).getBlock();
|
|
if (loc_1.getType() == Material.GLASS && loc_2.getType() == Material.LAPIS_BLOCK && ml.contains(loc.getType())) {
|
|
if (p.hasPermission("JumpPlate.create")) {
|
|
p.sendMessage(JumpPlate.instence.pluginname + JumpPlate.instence.getConfig().getMessage("create"));
|
|
} else {
|
|
e.setCancelled(true);
|
|
p.sendMessage(JumpPlate.instence.pluginname + JumpPlate.instence.getConfig().getMessage("no-permission"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onFallDamage(final EntityDamageEvent e) {
|
|
if (!JumpPlate.instence.removedamage) {
|
|
return;
|
|
}
|
|
if (e.getEntity() instanceof Player) {
|
|
final Player p = (Player) e.getEntity();
|
|
if (e.getCause() == DamageCause.FALL && fall.contains(p.getName())) {
|
|
final Block gb = p.getLocation().getBlock();
|
|
final Block loc = gb.getRelative(BlockFace.DOWN);
|
|
final Block loc_1 = gb.getRelative(BlockFace.DOWN, 2);
|
|
final Block loc_2 = gb.getRelative(BlockFace.DOWN, 3);
|
|
if (loc_1.getType() != Material.GLASS || loc_2.getType() != Material.LAPIS_BLOCK || !ml.contains(loc.getType())) {
|
|
fall.remove(p.getName());
|
|
}
|
|
e.setDamage(DamageModifier.BASE, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onJump(final PlayerInteractEvent e) {
|
|
final Player p = e.getPlayer();
|
|
if (e.getAction() != Action.PHYSICAL) {
|
|
return;
|
|
}
|
|
final Block gb = e.getClickedBlock();
|
|
if (gb.getType() != Material.GOLD_PLATE) {
|
|
return;
|
|
}
|
|
final Block loc = gb.getRelative(BlockFace.DOWN);
|
|
final Block loc_1 = gb.getRelative(BlockFace.DOWN, 2);
|
|
final Block loc_2 = gb.getRelative(BlockFace.DOWN, 3);
|
|
if (loc_1.getType() == Material.GLASS && loc_2.getType() == Material.LAPIS_BLOCK && ml.contains(loc.getType())) {
|
|
if (!p.hasPermission("JumpPlate.use")) {
|
|
p.sendMessage(JumpPlate.instence.pluginname + JumpPlate.instence.getConfig().getMessage("no-permission"));
|
|
return;
|
|
}
|
|
switch (loc.getType()) {
|
|
case IRON_BLOCK:
|
|
p.setVelocity(p.getVelocity().setY(1));
|
|
break;
|
|
case GOLD_BLOCK:
|
|
p.setVelocity(p.getVelocity().setY(1.5));
|
|
break;
|
|
case DIAMOND_BLOCK:
|
|
p.setVelocity(p.getVelocity().setY(2));
|
|
break;
|
|
case EMERALD_BLOCK:
|
|
p.setVelocity(p.getVelocity().setY(2.5));
|
|
break;
|
|
case BEDROCK:
|
|
p.setVelocity(p.getVelocity().setY(JumpPlate.instence.getConfig().getDouble("BEDROCK")));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if (JumpPlate.instence.removedamage) {
|
|
fall.add(p.getName());
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|