org.bukkit.event.Event Java Examples
The following examples show how to use
org.bukkit.event.Event.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExprFromBin.java From skUtilities with GNU General Public License v3.0 | 6 votes |
@Override @Nullable protected String[] get(Event e) { String bin = str.getSingle(e); String binV = bin.trim(); for (char character : binV.toCharArray()) { if (character != '0' && character != '1' && character != ' ') { skUtilities.prSysE("Binary Strings can only contain 1's, 0's or spaces!", getClass().getSimpleName()); return null; } } if (ty == 0) { StringBuilder sb = new StringBuilder(); for (String s : bin.split(" ")) { sb.append((char) Integer.parseInt(s, 2)); } return new String[]{sb.toString()}; } else if (ty == 1) { return new String[]{Integer.toString(Integer.parseInt(bin, 2))}; } else if (ty == 2) { return new String[]{Integer.toHexString(Integer.parseInt(bin, 2))}; } else { return new String[]{Integer.toOctalString(Integer.parseInt(bin, 2))}; } }
Example #2
Source File: ExprSpectatorTarget.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public void change(Event e, @Nullable Object[] delta, Changer.ChangeMode mode) { for (Player player : getExpr().getArray(e)) { if (player.getGameMode() == GameMode.SPECTATOR) { switch (mode) { case SET: assert delta != null; player.setSpectatorTarget((Entity) delta[0]); break; case RESET: case DELETE: player.setSpectatorTarget(null); } } } }
Example #3
Source File: EffTabTitlesV1_9.java From skRayFall with GNU General Public License v3.0 | 6 votes |
@Override protected void execute(Event evt) { IChatBaseComponent header = ChatSerializer.a("{\"text\": \"" + coreHeader.getSingle(evt).replace("\"", "") + "\"}"); IChatBaseComponent footer = ChatSerializer.a("{\"text\": \"" + coreFooter.getSingle(evt).replace("\"", "") + "\"}"); PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); try { Field headerField = packet.getClass().getDeclaredField("a"); headerField.setAccessible(true); headerField.set(packet, header); headerField.setAccessible(!headerField.isAccessible()); Field footerField = packet.getClass().getDeclaredField("b"); footerField.setAccessible(true); footerField.set(packet, footer); footerField.setAccessible(!footerField.isAccessible()); } catch (Exception exception) { exception.printStackTrace(); } ((CraftPlayer) player.getSingle(evt)).getHandle().playerConnection.sendPacket(packet); }
Example #4
Source File: Variable.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Nullable private Object get(final Event e) { final Object val = getRaw(e); if (!list) return val; if (val == null) return Array.newInstance(types[0], 0); final List<Object> l = new ArrayList<>(); final String name = StringUtils.substring(this.name.toString(e), 0, -1); for (final Entry<String, ?> v : ((Map<String, ?>) val).entrySet()) { if (v.getKey() != null && v.getValue() != null) { Object o; if (v.getValue() instanceof Map) o = ((Map<String, ?>) v.getValue()).get(null); else o = v.getValue(); l.add(convertIfOldPlayer(name + v.getKey(), e, o)); } } return l.toArray(); }
Example #5
Source File: ExprUrlResponseCode.java From skUtilities with GNU General Public License v3.0 | 6 votes |
@Override @Nullable protected Integer[] get(Event e) { try { HttpURLConnection.setFollowRedirects(false); HttpURLConnection c = (HttpURLConnection) new URL(url.getSingle(e)).openConnection(); c.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); c.setRequestMethod("HEAD"); int r = c.getResponseCode(); c.disconnect(); return new Integer[]{r}; } catch (Exception x) { skUtilities.prSysE("Error Reading from: '" + url.getSingle(e) + "' Is the site down?", getClass().getSimpleName(), x); } return null; }
Example #6
Source File: CondCanBuild.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean check(final Event e) { return players.check(e, new Checker<Player>() { @Override public boolean check(final Player p) { return locations.check(e, new Checker<Location>() { @Override public boolean check(final Location l) { return RegionsPlugin.canBuild(p, l); } }, isNegated()); } }); }
Example #7
Source File: EffCitizenAttack.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPC attacker = registry.getById(id.getSingle(evt).intValue()); if (attacker != null) { attacker.getNavigator().setTarget(toBeAttacked.getSingle(evt), true); } }
Example #8
Source File: ExprSpawn.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { assert mode == ChangeMode.SET; assert delta != null; final Location l = (Location) delta[0]; final int x = l.getBlockX(), y = l.getBlockY(), z = l.getBlockZ(); for (final World w : getExpr().getArray(e)) { w.setSpawnLocation(x, y, z); } }
Example #9
Source File: CondYamlIsLoaded.java From skript-yaml with MIT License | 5 votes |
@Override public boolean check(final Event event) { return file.check(event, new Checker<String>() { @Override public boolean check(final String s) { if (!SkriptYaml.YAML_STORE.containsKey(file.getSingle(event))) return false; return true; } }, isNegated()); }
Example #10
Source File: EffParticlesV1_8_4.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { float hx = 0f; float hy = 0f; float hz = 0f; float id = 0; int[] array = new int[0]; if (xoffset != null) { hx = xoffset.getSingle(evt).floatValue(); } if (yoffset != null) { hy = yoffset.getSingle(evt).floatValue(); } if (zoffset != null) { hz = zoffset.getSingle(evt).floatValue(); } String core = type.getSingle(evt); if (core.toUpperCase().replace(" ", "_").contains("BLOCK_CRACK") || core.toUpperCase().replace(" ", "_").contains("BLOCK_DUST")) { int index = type.getSingle(evt).lastIndexOf("_"); try { id = Integer.parseInt(type.getSingle(evt).substring(index + 1)); } catch (Exception exception) { Skript.error("Could not parse datavalue!"); id = 0; } core = core.substring(0, index); array = new int[1]; } EnumParticle part = PacketParticleGetterV1_8_4.get(core); PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(part, true, (float) location.getSingle(evt).getX(), (float) location.getSingle(evt).getY(), (float) location.getSingle(evt).getZ(), hx, hy, hz, id, partNum.getSingle(evt).intValue(), array); ((CraftPlayer) player.getSingle(evt)).getHandle().playerConnection.sendPacket(packet); }
Example #11
Source File: SimplePluginManager.java From Kettle with GNU General Public License v3.0 | 5 votes |
private Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) { try { clazz.getDeclaredMethod("getHandlerList"); return clazz; } catch (NoSuchMethodException e) { if (clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Event.class) && Event.class.isAssignableFrom(clazz.getSuperclass())) { return getRegistrationClass(clazz.getSuperclass().asSubclass(Event.class)); } else { throw new IllegalPluginAccessException("Unable to find handler list for event " + clazz.getName() + ". Static getHandlerList method required!"); } } }
Example #12
Source File: CondIsEnchanted.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean check(final Event e) { if (enchs != null) return items.check(e, item -> enchs.check(e, ench -> item.hasEnchantments(ench)), isNegated()); else return items.check(e, ItemType::hasEnchantments, isNegated()); }
Example #13
Source File: CondYamlExists.java From skUtilities with GNU General Public License v3.0 | 5 votes |
@Override public boolean check(Event e) { File pth = new File(skUtilities.getDefaultPath(path.getSingle(e))); FileConfiguration con = YamlConfiguration.loadConfiguration(pth); Boolean v = con.contains(yaml.getSingle(e)); return (isNegated() ? !v : v); }
Example #14
Source File: EventHandler.java From VoxelGamesLibv2 with MIT License | 5 votes |
@SuppressWarnings("unchecked") public <T extends Event> void callEvent(@Nonnull T event) { Class<Event> eventClass = (Class<Event>) event.getClass(); while (!eventClass.equals(Object.class)) { if (activeEvents.containsKey(eventClass)) { activeEvents.get(eventClass).forEach(registeredListener -> { Optional<User> user = Optional.empty(); boolean tried = false; for (EventFilter filter : registeredListener.getFilters()) { if (!user.isPresent() && !tried) { user = figureOutUser(event); tried = true; } if (!filter.filter(event, registeredListener, user)) { return; } } try { if (registeredListener.getMethod().getParameterCount() == 2) { registeredListener.getMethod().invoke(registeredListener.getListener(), event, user.orElse(null)); } else { registeredListener.getMethod().invoke(registeredListener.getListener(), event); } } catch (IllegalAccessException | InvocationTargetException e) { log.log(Level.SEVERE, "Error while calling eventhandler!", e); } }); break; } else { eventClass = (Class<Event>) eventClass.getSuperclass(); } } }
Example #15
Source File: WorldInventoriesDupingPatch.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onCreativeSlotChange(InventoryCreativeEvent event) { if (timeouts.isEmpty()) { return; // Saves performance for most common case } InventoryHolder holder = event.getInventory().getHolder(); if (holder instanceof Player && timeouts.containsKey(((Player) holder).getUniqueId())) { event.setResult(Event.Result.DENY); } }
Example #16
Source File: ExprFileDirSize.java From skUtilities with GNU General Public License v3.0 | 5 votes |
@Override @Nullable protected String[] get(Event e) { Path pth = Paths.get(skUtilities.getDefaultPath(path.getSingle(e))); try { if (ty == 0) { return new String[]{skUtilities.getFileSize(Files.size(pth))}; } else { return new String[]{skUtilities.getFileSize(FileUtils.sizeOfDirectory(pth.toFile()))}; } } catch (Exception x) { skUtilities.prSysE("'" + pth + "' doesn't exist!", getClass().getSimpleName()); } return null; }
Example #17
Source File: ExprAbsorbedBlocks.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Iterator<BlockStateBlock> iterator(Event e) { List<BlockState> bs = ((SpongeAbsorbEvent) e).getBlocks(); return bs.stream() .map(BlockStateBlock::new) .iterator(); }
Example #18
Source File: EffEffectLibWave.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event evt) { Object tar = target.getSingle(evt); WaveEffect effect = new WaveEffect(Core.effectManager); if (tar instanceof Entity) { effect.setDynamicOrigin(new DynamicLocation((Entity) tar)); if (particle != null) { effect.particle = particle.getSingle(evt); } effect.infinite(); effect.start(); Boolean check = Core.rayfallEffectManager.setEffect(effect, id.getSingle(evt).replace("\"", "")); if (!check) { effect.cancel(); } } else if (tar instanceof Location) { effect.setDynamicOrigin(new DynamicLocation((Location) tar)); effect.infinite(); if (particle != null) { effect.particle = particle.getSingle(evt); } effect.start(); Boolean check = Core.rayfallEffectManager.setEffect(effect, id.getSingle(evt).replace("\"", "")); if (!check) { effect.cancel(); } } else { assert false; } }
Example #19
Source File: ExprDifficulty.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { if (delta == null) return; Difficulty difficulty = (Difficulty) delta[0]; for (World world : getExpr().getArray(e)) { world.setDifficulty(difficulty); } }
Example #20
Source File: PlayerPostActionHandler.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
public <T extends Event> void addPostAction(SpleefPlayer player, Class<T> event, PostActionCallback<T> callback, Object cookie) { Validate.notNull(player, "player cannot be null"); Validate.notNull(event, "event class cannot be null"); Validate.notNull(callback, "callback cannot be null"); PostDataContainer<T> container = new PostDataContainer<T>(event, callback, cookie); awaitingPostAction.put(player, container); }
Example #21
Source File: EvtUnscope.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override public boolean check(Event evt) { if (evt instanceof WeaponScopeEvent && !((WeaponScopeEvent) evt).isZoomIn()) { return true; } else { return false; } }
Example #22
Source File: ExprCreeperMaxFuseTicks.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { int d = delta == null ? 0 : ((Number) delta[0]).intValue(); for (LivingEntity le : getExpr().getArray(e)) { if (le instanceof Creeper) { Creeper c = (Creeper) le; switch (mode) { case ADD: int r1 = c.getMaxFuseTicks() + d; if (r1 < 0) r1 = 0; c.setMaxFuseTicks(r1); break; case SET: c.setMaxFuseTicks(d); break; case DELETE: c.setMaxFuseTicks(0); break; case RESET: c.setMaxFuseTicks(30); //Seems to be the same for powered creepers? break; case REMOVE: int r2 = c.getMaxFuseTicks() - d; if (r2 < 0) r2 = 0; c.setMaxFuseTicks(r2); break; case REMOVE_ALL: assert false; } } } }
Example #23
Source File: CondIsFile.java From skUtilities with GNU General Public License v3.0 | 5 votes |
@Override public boolean check(Event e) { Path pth = Paths.get(skUtilities.getDefaultPath(path.getSingle(e))); if (!Files.exists(pth)) return false; Boolean b = !Files.isRegularFile(pth); return (isNegated() ? !b : b); }
Example #24
Source File: ExprCitizenIdFromEntity.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@Override @Nullable protected Number[] get(Event evt) { if (entity.getSingle(evt) != null && entity.getSingle(evt).hasMetadata("NPC")) { NPCRegistry registry = CitizensAPI.getNPCRegistry(); return new Number[]{registry.getNPC(entity.getSingle(evt)).getId()}; } return null; }
Example #25
Source File: EffMakeFly.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override protected void execute(Event e) { for (Player player : players.getArray(e)) { player.setAllowFlight(flying); player.setFlying(flying); } }
Example #26
Source File: Gooey.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void effect(Event e, ItemStack item, final int level) { final EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e; new BukkitRunnable() { @Override public void run() { event.getEntity().setVelocity(event.getEntity().getVelocity().setY((strength * level * 0.05) + 0.75)); event.getEntity().getWorld().playEffect(event.getEntity().getLocation(), Effect.SMOKE, 60); } }.runTaskLater(getPlugin(), 1l); }
Example #27
Source File: ExprEnchantmentLevel.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { if (delta == null) return; ItemType[] source = items.getArray(e); Enchantment[] enchantments = enchants.getArray(e); int newLevel = ((Number) delta[0]).intValue(); for (ItemType item : source) { if (!item.hasAnyEnchantments(enchantments)) continue; EnchantmentType[] enchants = item.getEnchantmentTypes(); assert enchants != null; // Can't be null at this point due to the above check for (EnchantmentType enchant : enchants) { item.removeEnchantments(enchant); Enchantment type = enchant.getType(); int changed = newLevel; assert type != null; if (mode == ChangeMode.ADD) changed = Math.max(0, enchant.getLevel() + changed); else if (mode == ChangeMode.REMOVE) changed = Math.max(0, enchant.getLevel() - changed); if (changed > 0) item.addEnchantments(new EnchantmentType(type, newLevel)); } } }
Example #28
Source File: SimpleExpressionFork.java From skript-yaml with MIT License | 5 votes |
protected final boolean setTime(final int time, final Class<? extends Event> applicableEvent, final Expression<?>... mustbeDefaultVars) { if (ScriptLoader.hasDelayBefore == Kleenean.TRUE && time != 0) { Skript.error("Can't use time states after the event has already passed"); return false; } if (!ScriptLoader.isCurrentEvent(applicableEvent)) return false; for (final Expression<?> var : mustbeDefaultVars) { if (!var.isDefault()) { return false; } } this.time = time; return true; }
Example #29
Source File: ExprLocationVectorOffset.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override protected Location[] get(Event e) { Location l = location.getSingle(e); if (l == null) return null; Location clone = l.clone(); for (Vector v : vectors.getArray(e)) clone.add(v); return CollectionUtils.array(clone); }
Example #30
Source File: ExprBlocksInRegion.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @NonNull public Iterator<Block> iterator(final Event e) { final Region[] rs = regions.getArray(e); if (rs.length == 0) return EmptyIterator.get(); return new Iterator<Block>() { private Iterator<Block> current = rs[0].getBlocks(); private final Iterator<Region> iter = new ArrayIterator<>(rs, 1); @Override public boolean hasNext() { while (!current.hasNext() && iter.hasNext()) { final Region r = iter.next(); if (r != null) current = r.getBlocks(); } return current.hasNext(); } @SuppressWarnings("null") @Override public Block next() { if (!hasNext()) throw new NoSuchElementException(); return current.next(); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }