本文整理汇总了Java中org.bukkit.event.Event类的典型用法代码示例。如果您正苦于以下问题:Java Event类的具体用法?Java Event怎么用?Java Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Event类属于org.bukkit.event包,在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public void call(Event event) {
final Player player = profile.getPlayer();
if (event instanceof PlayerMoveEvent) {
if ((player.isSprinting() || player.isBlocking() || player.isConversing()) && player.isSneaking()) {
callback(true);
return;
}
callback(false);
} else if (event instanceof AsyncPlayerChatEvent) {
if ((player.isBlocking() || player.isSprinting() || player.isSneaking())) {
callback(true);
return;
}
callback(false);
}
}
示例2: call
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public void call(Event event) {
if (event instanceof EntityDamageEvent) {
final EntityDamageEvent ede = (EntityDamageEvent) event;
final DamageCause cause = ede.getCause();
if (cause == DamageCause.FIRE || cause == DamageCause.CONTACT) {
final Player player = profile.getPlayer();
if (cause == DamageCause.FIRE && player.getFoodLevel() < 20) {
// The AntiFire cheat only works when the hunger bar is
// full.
return;
}
final double previousHealth = player.getHealth();
// Check a little later.
Bukkit.getScheduler().runTaskLater(Crescent.getInstance(), () -> {
if (player.getHealth() > previousHealth - ede.getDamage()) {
callback(true);
}
}, 2L);
}
}
}
示例3: check
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public boolean check(Event arg0) {
@SuppressWarnings("unused")
Boolean goodip = IpTools.validIP(ip.getSingle(arg0));
if (!goodip) {
Skript.error("\"" + ip + "\" is not a valid IPv4 address!");
return false;
}
JSONObject jsonparsed = null;
try {
jsonparsed = JsonReader.readJsonFromUrl("http://proxycheck.io/v1/" + ip.getSingle(arg0) + "&vpn=1&asn=0&node=1&time=1&tag=skLib");
} catch (JSONException | IOException e) {
e.printStackTrace();
}
String jsonvalue = (String) jsonparsed.get("proxy");
if (jsonvalue.equalsIgnoreCase("yes")) {
return true;
}
return false;
}
示例4: execute
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
// 计算调用次数和花费总时间以及花费最多的时间
public void execute(Listener listener, Event e) throws EventException {
if (e.isAsynchronous()) {
this.eventExecutor.execute(listener, e);
} else {
long startTime = System.nanoTime();
try {
this.eventExecutor.execute(listener, e);
} finally {
long endTime = System.nanoTime();
long executeTime = endTime - startTime;
this.record(e.getEventName(), executeTime);
}
}
}
示例5: healWithPotion
import org.bukkit.event.Event; //导入依赖的package包/类
public static void healWithPotion(int amount, String name, Event event, Player p) {
if (!(event instanceof PlayerInteractEvent))
return;
PlayerInteractEvent e = (PlayerInteractEvent) event;
if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK))
return;
if (lastHealItem.containsKey(p.getName()) && System.currentTimeMillis() - lastHealItem.get(p.getName()) < 500) {
return;
}
lastHealItem.put(p.getName(), System.currentTimeMillis());
p.getEquipment().setItemInMainHand(new ItemStack(Material.AIR));
PlayerDataRPG pd = plugin.getPD(p);
pd.heal(amount, HealType.POTION);
for (int k = 0; k < p.getInventory().getContents().length; k++) {
if (ItemManager.isItem(p.getInventory().getItem(k), name)) {
p.getEquipment().setItemInMainHand(p.getInventory().getItem(k));
p.getInventory().setItem(k, new ItemStack(Material.AIR));
break;
}
}
RSound.playSound(p, Sound.ENTITY_GENERIC_DRINK);
}
示例6: change
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
Object target = targetArg.getSingle(e);
if (target == null) {
return;
}
Object[] args = new Object[1];
switch (mode) {
case SET:
args[0] = delta[0];
break;
case DELETE:
args[0] = null;
break;
}
invoke(target, args, getDescriptor(e));
}
示例7: execute
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
protected void execute(Event event) {
String[] commands = this.commands.getAll(event);
Object[] senders = this.senders.getAll(event);
if (commands == null || senders == null) {
return;
}
Arrays.stream(getBungeeMaster().convertObjectsToNamesAndUUIDs(senders))
.forEach(sender ->
Arrays.stream(commands)
.filter(Objects::nonNull)
.forEach(command -> {
if (command.startsWith("/")) {
command = command.substring(1);
}
send(new SendMessageAsPlayerPacket(sender, "/" + command));
})
);
}
示例8: change
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
Trigger trigger = changerHandlers.get(which);
ExpressionChangeEvent expressionEvent =
new ExpressionChangeEvent(e, exprs, parseResult, delta, mode);
if (trigger == null) {
Skript.error(
String.format("The custom expression '%s' no longer has a change handler.",
which.getPattern())
);
} else {
trigger.execute(expressionEvent);
}
}
示例9: execute
import org.bukkit.event.Event; //导入依赖的package包/类
protected void execute(final Event arg0) {
final Jedis jedis = Main.pool.getResource();
new BukkitRunnable(){
public void run() {
try {
jedis.set((String)EffectSetVariable.this.key.getSingle(arg0), (String)EffectSetVariable.this.value.getSingle(arg0));
}
catch (Exception e) {
e.printStackTrace();
}
jedis.close();
}
}.runTaskAsynchronously(Main.plugin);
}
示例10: call
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public void call(Event event) {
if (event instanceof PlayerMoveEvent) {
final PlayerMoveEvent pme = (PlayerMoveEvent) event;
final Behaviour behaviour = profile.getBehaviour();
if (!behaviour.isOnGround() && !behaviour.isInLiquid() && !behaviour.isInWeb()) {
if (behaviour.getMotion().isDescending()) {
final double difference = Math.abs((behaviour.getMotion()
.calculateGravityEffect() /*
* Expected y difference
*/)
- (pme.getTo().getY() - pme.getFrom()
.getY()) /* Actual y difference */);
if (difference > ALLOWED_MAX_GRAVITY_DIFFERENCE && behaviour
.getBlocksBelowGround() > 2 /*
* The player being too
* close to the ground
* causes false
* positives.
*/) {
callback(true);
}
}
}
}
}
示例11: get
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
@Nullable
protected Number[] get(Event e) {
InventoryType container = ((InventoryClickEvent)e).getClickedInventory().getType();
if (container != InventoryType.CHEST || container != InventoryType.DISPENSER || container != InventoryType.DROPPER || container != InventoryType.WORKBENCH || container != InventoryType.ENDER_CHEST || container != InventoryType.PLAYER) {
for (int i = 1; i < ((InventoryClickEvent)e).getClickedInventory().getSize() + 1; i++) {
if (rowType(i, ((InventoryClickEvent)e).getSlot(), ((InventoryClickEvent)e).getInventory())) {
return new Number[]{i};
}
}
}
return null;
}
示例12: change
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
Number num = numbers.getSingle(e);
Number f = from.getSingle(e);
Number t = to.getSingle(e);
if (num == null || f == null || t == null) {
return;
}
long mask = getRangeMaskIndexed(f.intValue(), t.intValue());
long number = num.longValue();
switch (mode) {
case SET:
if (delta[0] instanceof Number) {
number &= ~mask;
mask &= (((Number) delta[0]).longValue()) << f.intValue();
} else if (delta[0] instanceof Boolean) {
if (!((Boolean) delta[0])) {
mask = ~mask;
}
} else {
throw new IllegalStateException();
}
number |= mask;
break;
case DELETE:
number &= ~mask;
break;
default:
throw new IllegalStateException();
}
numbers.change(e, new Object[]{number}, Changer.ChangeMode.SET);
}
示例13: destroy
import org.bukkit.event.Event; //导入依赖的package包/类
@Override
public void destroy() {
if (!this.dead) {
Bukkit.getPluginManager().callEvent((Event)new LoggerRemovedEvent(this));
this.dead = true;
this.cancelTask();
}
}
示例14: get
import org.bukkit.event.Event; //导入依赖的package包/类
@Nullable
@Override
protected Pattern[] get(Event e) {
Color c = color.getSingle(e);
PatternType p = pattern.getSingle(e);
if (c == null || p == null) {
return null;
}
return new Pattern[]{new Pattern(c.getWoolColor(), p)};
}
示例15: PlayerItemTransferEvent
import org.bukkit.event.Event; //导入依赖的package包/类
public PlayerItemTransferEvent(Event cause,
Type type,
Player player,
Optional<InventorySlot<?>> from,
Optional<InventorySlot<?>> to,
ItemStack itemStack,
@Nullable Item itemEntity,
int quantity,
@Nullable ItemStack cursorItems) {
super(cause, type, from, to, itemStack, itemEntity, quantity);
this.player = checkNotNull(player);
this.cursorItems = cursorItems;
}