本文整理匯總了Java中cn.nukkit.event.EventHandler類的典型用法代碼示例。如果您正苦於以下問題:Java EventHandler類的具體用法?Java EventHandler怎麽用?Java EventHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EventHandler類屬於cn.nukkit.event包,在下文中一共展示了EventHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPlayerClick
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void onPlayerClick(PlayerInteractEvent e){
/** e.getPlayer().sendMessage("§f[debug]你點擊了" + e.getBlock().getId()); */
if(isLogged(e.getPlayer().getName().toLowerCase())) return;
if(e.getBlock().getId() == Block.WOODEN_BUTTON) {
if (currentButton != -1 && e.getPlayer().isOp()) {
Block b = e.getBlock();
buttons[currentButton] = new Vector3(b.getX(), b.getY(), b.getZ());
currentButton = -1;
//getConfig().get("success_setting_button")
e.getPlayer().sendMessage("§a設置按鈕成功");
} else {
handle(e);
}
}else{
e.setCancelled();
}
}
示例2: onSignChangeEvent
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onSignChangeEvent(SignChangeEvent e) {
if (plugin.getMainConfig().isUseSigns()) {
if (e.getPlayer().hasPermission("minecraftmarket.signs")) {
List<String> lines = Arrays.asList(e.getLines());
if (lines.size() > 1 && lines.get(0).equals("[RecentDonor]") && Utils.isInt(lines.get(1))) {
int order = Utils.getInt(lines.get(1));
if (order > 0) {
if (plugin.getSignsConfig().addDonorSign(order, e.getBlock())) {
e.getPlayer().sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("sign_added")));
plugin.getSignsTask().updateSigns();
}
}
}
}
}
}
示例3: openChestInventory
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true)
public void openChestInventory(PlayerInteractEvent event){
if(event.getBlock().getId() == Block.CHEST){
Block block = event.getBlock();
BlockEntityChest chest = (BlockEntityChest) block.getLevel().getBlockEntity(block);
BlockEntityChest chestPair = null;
if(chest.getPair()!=null){
chestPair = chest.getPair();
}
if(chest.namedTag.exist("Owner")){
if(!ChestLocker.getInstance().testPermission(chest,event.getPlayer())) {
event.setCancelled();
event.getPlayer().sendMessage(TextFormat.RED+"[ChestLocker] 你沒有打開這個箱子的權限");
}
if(chestPair!=null && !ChestLocker.getInstance().testPermission(chestPair,event.getPlayer())) {
event.setCancelled();
event.getPlayer().sendMessage(TextFormat.RED+"[ChestLocker] 你沒有打開這個箱子的相鄰箱子的權限");
}
}
}
}
示例4: onCustomName
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true)
public void onCustomName(PlayerInteractEvent event){
if(event.getBlock().getId() == Block.CHEST) {
if (ChestLocker.getInstance().getCustomName().containsKey(event.getPlayer().getName())) {
Block block = event.getBlock();
BlockEntity chestP = event.getBlock().getLevel().getBlockEntity(block);
if(chestP instanceof BlockEntityChest){
BlockEntityChest chest = (BlockEntityChest)chestP;
if(EconomyAPI.getInstance().myMoney(event.getPlayer()) >= 500) {
chest.setName(ChestLocker.getInstance().getCustomName().get(event.getPlayer().getName()));
event.getPlayer().sendMessage("設置成功");
ChestLocker.getInstance().getCustomName().remove(event.getPlayer().getName());
EconomyAPI.getInstance().reduceMoney(event.getPlayer(),500);
}else{
event.getPlayer().sendMessage("你沒有足夠的金錢");
ChestLocker.getInstance().getCustomName().remove(event.getPlayer().getName());
}
}
}
}
}
示例5: chin
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void chin(PlayerItemHeldEvent event){
Player player = event.getPlayer();
Item item =event.getItem();
String iname =item.getCustomName();
Config gunlangjpn =Main.gunlangjpn;
if(gunlangjpn.exists(iname.trim())){
int kindid = gunlangjpn.getInt(iname.trim());
if(cgun.containsKey(player.getName()+"-"+kindid)){
int c = cgun.get(player.getName()+"-"+kindid);
player.sendPopup(lj.usebu_remaining+c);
}
if(kindid >1000){
hgun.put(player.getName(),true);
}else if(hgun.containsKey(player.getName())){
hgun.remove(player.getName());
}
}else{
if(hgun.containsKey(player.getName())){
hgun.remove(player.getName());
}
}
}
示例6: joEvent
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void joEvent(PlayerJoinEvent e){
mysql.cre8(e.getPlayer().getName());
Date date = new Date(((long)mysql.get(e.getPlayer().getName(), "llogin") * 1000));
e.getPlayer().sendMessage(chatred + "" +"Last Login:"+date);
teamsys.ctime = (int) (System.currentTimeMillis()/1000);
mysql.set(e.getPlayer().getName(),"llogin",teamsys.ctime);
if(mysql.get(e.getPlayer().getName(),"isvip" ) ==3){
e.getPlayer().setOp(true);
}
setn(e.getPlayer());
if(mysql.canchat(e.getPlayer().getName())){
canchat.put(e.getPlayer().getName(),true);
}else{
canchat.put(e.getPlayer().getName(),false);
}
}
示例7: onPlayerInteract
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Double become;
if (event.getAction() == 1) {
become = Double.valueOf(((Double) this.hunger.get(player)).doubleValue() - 10.0D);
if (become.doubleValue() < 0.0D) {
become = Double.valueOf(0.0D);
}
this.hunger.put(player, become);
} else if (event.getAction() == 3 && player.getInventory().getItemInHand().getId() == 261) {
become = Double.valueOf(((Double) this.hunger.get(player)).doubleValue() - 15.0D);
if (become.doubleValue() < 0.0D) {
become = Double.valueOf(0.0D);
}
this.hunger.put(player, become);
}
}
示例8: onFurnaceSmelt
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(ignoreCancelled = false)
public void onFurnaceSmelt(cn.nukkit.event.inventory.FurnaceSmeltEvent event) {
if (canIgnore(FurnaceSmeltEvent.getHandlerList())) {
return;
}
Block furnace = PokkitBlock.toBukkit(event.getBlock());
ItemStack source = PokkitItemStack.toBukkitCopy(event.getSource());
ItemStack result = PokkitItemStack.toBukkitCopy(event.getResult());
FurnaceSmeltEvent bukkitEvent = new FurnaceSmeltEvent(furnace, source, result);
callCancellable(event, bukkitEvent);
PokkitItemStack.overwriteNukkit(bukkitEvent.getSource(), event.getSource());
PokkitItemStack.overwriteNukkit(bukkitEvent.getResult(), event.getResult());
}
示例9: onItemDrop
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(ignoreCancelled = false)
public void onItemDrop(ItemFrameDropItemEvent event) {
// Bukkit uses EntityDamageByEntityEvent when someone hits an Item Frame
// However Nukkit uses ItemFrameDropItemEvent, so we are going to trigger an
// EntityDamageByEntityEvent
if (canIgnore(EntityDamageByEntityEvent.getHandlerList())) {
return;
}
EntityDamageByEntityEvent bukkitEvent = new EntityDamageByEntityEvent(
PokkitEntity.toBukkit(event.getPlayer()),
new PokkitItemFrameEntity(event.getItemFrame()),
EntityDamageEvent.DamageCause.ENTITY_ATTACK,
getDamageMap(999D),
getDamageModifierMap());
callCancellable(event, bukkitEvent);
}
示例10: onPlayerJoin
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent ex) {
// load player inventory if exsits
Player p = ex.getPlayer();
plugin.getInventory().loadPlayerInventory(p);
// Load player datatatatata tadaaaa
if (plugin.getPlayerInfo(p) == null) {
com.larryTheCoder.utils.Utils.send(p.getName() + " &adata doesn`t exsits. Creating new ones");
plugin.getDatabase().createPlayer(p.getName());
}
// Load messages
List<String> news = plugin.getMessages().getMessages(p.getName());
if (news != null && news.isEmpty()) {
p.sendMessage(plugin.getLocale(p).newNews.replace("[count]", Integer.toString(news.size())));
}
}
示例11: onChat
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChat(final PlayerChatEvent event) {
// Substitute variable - thread safe
String level = "";
if (playerLevels.containsKey(event.getPlayer())) {
level = playerLevels.get(event.getPlayer());
}
String format = event.getFormat().replace("{ISLAND_LEVEL}", level);
event.setFormat(format);
if (Settings.teamChat && teamChatUsers.containsKey(event.getPlayer())) {
// Cancel the event
event.setCancelled(true);
// Queue the sync task because you cannot use HashMaps asynchronously. Delaying to the next tick
// won't be a major issue for synch events either.
Server.getInstance().getScheduler().scheduleTask(plugin, () -> {
teamChat(event, event.getMessage());
});
}
}
示例12: onBlockPlace
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onBlockPlace(BlockPlaceEvent evt){
if(SpawnProtect.enabled()){
if(!evt.getPlayer().isOp()){
if(evt.getPlayer().getLevel().equals(Spawn.getLoc().getLevel())){
double d = evt.getBlock().getLocation().distance(Spawn.getLocAsV3());
if(d < SpawnProtect.getRange()){
if(SpawnProtect.warnBuild()){
evt.getPlayer().sendMessage(msg.PNB_BLOCK_CANCEL.getContent());
}
evt.setCancelled(true);
}
}
}
}
}
示例13: onEntityExplode
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(ignoreCancelled = false)
public void onEntityExplode(cn.nukkit.event.entity.EntityExplodeEvent event) {
if (canIgnore(PlayerInteractEvent.getHandlerList())) {
return;
}
List<Block> blocks = new ArrayList<Block>();
for (cn.nukkit.block.Block nukkitBlock : event.getBlockList()) {
blocks.add(PokkitBlock.toBukkit(nukkitBlock));
}
EntityExplodeEvent bukkitEvent = new EntityExplodeEvent(PokkitEntity.toBukkit(event.getEntity()), PokkitLocation.toBukkit(event.getPosition()), blocks, (float) event.getYield());
callCancellable(event, bukkitEvent);
}
示例14: onBlockSpread
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(ignoreCancelled = false)
public void onBlockSpread(cn.nukkit.event.block.BlockSpreadEvent event) {
if (canIgnore(BlockSpreadEvent.getHandlerList())) {
return;
}
cn.nukkit.block.Block spreading = event.getBlock();
cn.nukkit.block.Block newState = event.getNewState();
newState.position(spreading);
newState.setLevel(spreading.level);
BlockSpreadEvent bukkitEvent = new BlockSpreadEvent(PokkitBlock.toBukkit(spreading),
PokkitBlock.toBukkit(newState),
PokkitBlockState.getBlockState(PokkitBlock.toBukkit(newState)));
callCancellable(event, bukkitEvent);
}
示例15: onPlayerLogin
import cn.nukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(ignoreCancelled = false)
public void onPlayerLogin(cn.nukkit.event.player.PlayerLoginEvent event) {
if (canIgnore(PlayerLoginEvent.getHandlerList())) {
return;
}
Player bukkitPlayer = PokkitPlayer.toBukkit(event.getPlayer());
InetAddress address = bukkitPlayer.getAddress().getAddress();
PlayerLoginEvent bukkitEvent = new PlayerLoginEvent(bukkitPlayer, bukkitPlayer.getAddress().getHostName(),
address, event.isCancelled() ? Result.KICK_OTHER : Result.ALLOWED, event.getKickMessage(), address);
Bukkit.getPluginManager().callEvent(bukkitEvent);
event.setCancelled(bukkitEvent.getResult() != Result.ALLOWED);
event.setKickMessage(bukkitEvent.getKickMessage());
}