Esempio n. 1
0
  public void openInventory(InventoryView inventory) {
    if (!(getHandle() instanceof EntityPlayer)) return; // TODO: NPC support?
    if (((EntityPlayer) getHandle()).playerConnection == null) return;
    if (getHandle().activeContainer != getHandle().defaultContainer) {
      // fire INVENTORY_CLOSE if one already open
      ((EntityPlayer) getHandle())
          .playerConnection.handleContainerClose(
              new Packet101CloseWindow(getHandle().activeContainer.windowId));
    }
    EntityPlayer player = (EntityPlayer) getHandle();
    Container container;
    if (inventory instanceof CraftInventoryView) {
      container = ((CraftInventoryView) inventory).getHandle();
    } else {
      container = new CraftContainer(inventory, player.nextContainerCounter());
    }

    // Trigger an INVENTORY_OPEN event
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) {
      return;
    }

    // Now open the window
    InventoryType type = inventory.getType();
    int windowType = CraftContainer.getNotchInventoryType(type);
    String title = inventory.getTitle();
    int size = inventory.getTopInventory().getSize();
    player.playerConnection.sendPacket(
        new Packet100OpenWindow(container.windowId, windowType, title, size, false));
    player.activeContainer = container;
    player.activeContainer.addSlotListener(player);
  }
Esempio n. 2
0
  public void b(ICommandListener icommandlistener, String[] astring) {
    if (astring.length > 0 && astring[0].length() > 1) {
      EntityPlayer entityplayer = MinecraftServer.getServer().getPlayerList().getPlayer(astring[0]);
      String s = "Kicked by an operator.";
      boolean flag = false;

      if (entityplayer == null) {
        throw new ExceptionPlayerNotFound();
      } else {
        if (astring.length >= 2) {
          s = a(icommandlistener, astring, 1).c();
          flag = true;
        }

        entityplayer.playerConnection.disconnect(s);
        if (flag) {
          a(
              icommandlistener,
              "commands.kick.success.reason",
              new Object[] {entityplayer.getName(), s});
        } else {
          a(icommandlistener, "commands.kick.success", new Object[] {entityplayer.getName()});
        }
      }
    } else {
      throw new ExceptionUsage("commands.kick.usage", new Object[0]);
    }
  }
Esempio n. 3
0
 @Override
 public double getFasterMovementAmplifier(final Player player) {
   final net.minecraft.server.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
   if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT))
     return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier();
   else return Double.NEGATIVE_INFINITY;
 }
  private boolean performChestCommand(CommandSender sender, String[] args) {
    if (sender instanceof CraftPlayer) {
      if (args.length == 0) {
        if (sender.hasPermission("alphachest.chest")) {
          VirtualChest chest = chestManager.getChest(sender.getName());
          EntityPlayer player = ((CraftPlayer) sender).getHandle();
          player.openContainer(chest);
        } else {
          Teller.tell(sender, Type.Error, "You're not allowed to use this command.");
        }
        return true;
      } else if (args.length == 1) {
        if (sender.hasPermission("alphachest.admin")) {
          VirtualChest chest = chestManager.getChest(args[0]);
          EntityPlayer player = ((CraftPlayer) sender).getHandle();
          player.openContainer(chest);
        } else {
          Teller.tell(sender, Type.Error, "You're not allowed to open other user's chests.");
        }
        return true;

      } else {
        return false;
      }
    } else {
      Teller.tell(sender, Type.Error, "Only players are able to open chests.");
      return true;
    }
  }
Esempio n. 5
0
  @Override
  public double getJumpAmplifier(final Player player) {
    final net.minecraft.server.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();

    if (mcPlayer.hasEffect(MobEffectList.JUMP))
      return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier();
    else return Double.NEGATIVE_INFINITY;
  }
Esempio n. 6
0
  public void b(ICommandListener icommandlistener, String[] astring) {
    if (astring.length < 2) {
      throw new ExceptionUsage("commands.enchant.usage", new Object[0]);
    } else {
      EntityPlayer entityplayer = d(icommandlistener, astring[0]);
      int i = a(icommandlistener, astring[1], 0, Enchantment.byId.length - 1);
      int j = 1;
      ItemStack itemstack = entityplayer.bx();

      if (itemstack == null) {
        throw new CommandException("commands.enchant.noItem", new Object[0]);
      } else {
        Enchantment enchantment = Enchantment.byId[i];

        if (enchantment == null) {
          throw new ExceptionInvalidNumber(
              "commands.enchant.notFound", new Object[] {Integer.valueOf(i)});
        } else if (!enchantment.canEnchant(itemstack)) {
          throw new CommandException("commands.enchant.cantEnchant", new Object[0]);
        } else {
          if (astring.length >= 3) {
            j =
                a(
                    icommandlistener,
                    astring[2],
                    enchantment.getStartLevel(),
                    enchantment.getMaxLevel());
          }

          if (itemstack.hasTag()) {
            NBTTagList nbttaglist = itemstack.getEnchantments();

            if (nbttaglist != null) {
              for (int k = 0; k < nbttaglist.size(); ++k) {
                short short1 = ((NBTTagCompound) nbttaglist.get(k)).getShort("id");

                if (Enchantment.byId[short1] != null) {
                  Enchantment enchantment1 = Enchantment.byId[short1];

                  if (!enchantment1.a(enchantment)) {
                    throw new CommandException(
                        "commands.enchant.cantCombine",
                        new Object[] {
                          enchantment.c(j),
                          enchantment1.c(((NBTTagCompound) nbttaglist.get(k)).getShort("lvl"))
                        });
                  }
                }
              }
            }
          }

          itemstack.addEnchantment(enchantment, j);
          a(icommandlistener, "commands.enchant.success", new Object[0]);
        }
      }
    }
  }
  public Player getPlayer() {
    for (Object obj : server.getHandle().players) {
      EntityPlayer player = (EntityPlayer) obj;
      if (player.getUniqueID().equals(getUniqueId())) {
        return (player.playerConnection != null) ? player.playerConnection.getPlayer() : null;
      }
    }

    return null;
  }
  public void a() {
    Iterator iterator = this.trackedPlayers.iterator();

    while (iterator.hasNext()) {
      EntityPlayer entityplayer = (EntityPlayer) iterator.next();

      this.tracker.c(entityplayer);
      entityplayer.c(this.tracker);
    }
  }
Esempio n. 9
0
 public MiracleConnection(
     XmasMiraclePlugin p,
     MinecraftServer minecraftserver,
     INetworkManager networkmanager,
     EntityPlayer player) {
   super(minecraftserver, networkmanager, player);
   this.pl = p;
   this.algo = p.default_algo;
   if (p.algo_pref.containsKey(player.getName())) {
     this.algo = p.algo_pref.get(player.getName());
   }
 }
Esempio n. 10
0
 @Override
 public AlmostBoolean isIllegalBounds(final Player player) {
   final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
   if (entityPlayer.dead) return AlmostBoolean.NO;
   final AxisAlignedBB box = entityPlayer.boundingBox;
   if (!entityPlayer.isSleeping()) {
     // This can not really test stance but height of bounding box.
     final double dY = Math.abs(box.e - box.b);
     if (dY > 1.8) return AlmostBoolean.YES; // dY > 1.65D ||
     if (dY < 0.1D && entityPlayer.length >= 0.1) return AlmostBoolean.YES;
   }
   return AlmostBoolean.MAYBE;
 }
  protected void a(WorldSettings.EnumGamemode worldsettings_enumgamemode) {
    MinecraftServer minecraftserver = MinecraftServer.getServer();

    minecraftserver.setGamemode(worldsettings_enumgamemode);
    EntityPlayer entityplayer;

    if (minecraftserver.getForceGamemode()) {
      for (Iterator iterator = MinecraftServer.getServer().getPlayerList().v().iterator();
          iterator.hasNext();
          entityplayer.fallDistance = 0.0F) {
        entityplayer = (EntityPlayer) iterator.next();
        entityplayer.a(worldsettings_enumgamemode);
      }
    }
  }
Esempio n. 12
0
 public void a(EntityPlayer entityplayer, boolean flag0) {
   super.a(entityplayer, flag0);
   this.cp = -1;
   this.cm = -1;
   this.cn = -1;
   this.g.addAll(((EntityPlayerMP) entityplayer).g);
 }
Esempio n. 13
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer entityplayer,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    super.onBlockActivated(world, x, y, z, entityplayer, side, hitX, hitY, hitZ);
    TileEntityQuern te = (TileEntityQuern) world.getBlockTileEntity(x, y, z);
    if (!world.isRemote) {
      if (!te.shouldRotate && hitX >= 0.65 && hitZ >= 0.65 && te.storage[2] != null) {
        te.shouldRotate = true;
        world.playSoundEffect(x, y, z, TFC_Sounds.STONEDRAG, 1, 1);
      } else if ((!te.shouldRotate && (hitX < 0.65 || hitZ < 0.65)) || te.storage[2] == null) {
        entityplayer.openGui(TerraFirmaCraft.instance, 33, world, x, y, z);
      }
    } else if (!te.shouldRotate && hitX >= 0.65 && hitZ >= 0.65 && te.hasQuern) {
      te.shouldRotate = true;
    }

    return true;
  }
 public void a(EntityPlayer entityplayer) {
   if (this.trackedPlayers.contains(entityplayer)) {
     this.tracker.c(entityplayer);
     entityplayer.c(this.tracker);
     this.trackedPlayers.remove(entityplayer);
   }
 }
 public void clear(EntityPlayer entityplayer) {
   org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot
   if (this.trackedPlayers.contains(entityplayer)) {
     this.trackedPlayers.remove(entityplayer);
     this.tracker.c(entityplayer);
     entityplayer.c(this.tracker);
   }
 }
Esempio n. 16
0
 // CanaryMod
 // Start: Custom Display name
 @Override
 public void setDisplayName(String name) {
   super.setDisplayName(name);
   Packet20NamedEntitySpawn pkt = new Packet20NamedEntitySpawn(this);
   for (Player p : Canary.getServer().getPlayerList()) {
     if (!p.getName().equals(this.bS)) {
       ((CanaryPlayer) p).getHandle().a.b(pkt);
     }
   }
 }
Esempio n. 17
0
 public void a(NBTTagCompound nbttagcompound) {
   super.a(nbttagcompound);
   if (nbttagcompound.b("playerGameType")) {
     // XXX Check this, it was only the last call to this.c.a
     if (MinecraftServer.D().am()) {
       this.c.a(MinecraftServer.D().g());
     } else {
       this.c.a(EnumGameType.a(nbttagcompound.e("playerGameType")));
     }
   }
 }
Esempio n. 18
0
  public NetServerHandler(
      MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
    this.minecraftServer = minecraftserver;
    this.networkManager = networkmanager;
    networkmanager.a((NetHandler) this);
    this.player = entityplayer;
    entityplayer.netServerHandler = this;

    // CraftBukkit start
    server = minecraftserver.server;
  }
Esempio n. 19
0
  public void b(int i0) {
    super.b(i0);
    Collection collection = this.cr().a(ScoreObjectiveCriteria.f);
    Iterator iterator = collection.iterator();

    while (iterator.hasNext()) {
      ScoreObjective scoreobjective = (ScoreObjective) iterator.next();

      this.cr().a(this.am(), scoreobjective).a(Arrays.asList(new EntityPlayer[] {this}));
    }
  }
Esempio n. 20
0
 public void b(EntityPlayer entityplayer) {
   if (f && ak == entityplayer && a <= 0 && entityplayer.an.a(new ItemStack(Item.j, 1))) {
     l.a(
         ((Entity) (this)),
         "random.pop",
         0.2F,
         ((W.nextFloat() - W.nextFloat()) * 0.7F + 1.0F) * 2.0F);
     entityplayer.c(((Entity) (this)), 1);
     q();
   }
 }
Esempio n. 21
0
 public void a(Entity entity) {
   super.a(entity);
   this.a.b(new Packet39AttachEntity(this, this.o));
   this.a.a(
       this.u,
       this.v,
       this.w,
       this.A,
       this.B,
       getCanaryWorld().getType().getId(),
       getCanaryWorld().getName());
 }
  @Override
  public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l) {
    // we need to make sure the player has the correct tool out
    boolean isAxeorSaw = false;
    boolean isHammer = false;
    ItemStack equip = entityplayer.getCurrentEquippedItem();
    if (!world.isRemote) {
      if (equip != null) {
        for (int cnt = 0; cnt < Recipes.Axes.length && !isAxeorSaw; cnt++) {
          if (equip.getItem() == Recipes.Axes[cnt]) {
            isAxeorSaw = true;
            if (cnt < 4) isStone = true;
          }
        }
        //				for(int cnt = 0; cnt < Recipes.Saws.length && !isAxeorSaw; cnt++)
        //				{
        //					if(equip.getItem() == Recipes.Saws[cnt])
        //					{
        //						isAxeorSaw = true;
        //					}
        //				}
        for (int cnt = 0; cnt < Recipes.Hammers.length && !isAxeorSaw; cnt++) {
          if (equip.getItem() == Recipes.Hammers[cnt]) {
            isHammer = true;
          }
        }
      }
      if (isAxeorSaw) {
        damage = -1;
        ProcessTree(world, i, j, k, l, equip);

        if (damage + equip.getItemDamage() > equip.getMaxDamage()) {
          int ind = entityplayer.inventory.currentItem;
          entityplayer.inventory.setInventorySlotContents(ind, null);
          world.setBlockAndMetadataWithNotify(i, j, k, blockID, l, 3);
        } else {
          equip.damageItem(damage, entityplayer);
        }
      } else if (isHammer) {
        EntityItem item =
            new EntityItem(
                world,
                i + 0.5,
                j + 0.5,
                k + 0.5,
                new ItemStack(Item.stick, 1 + world.rand.nextInt(3)));
        world.spawnEntityInWorld(item);
      } else {
        world.setBlockAndMetadataWithNotify(i, j, k, blockID, l, 3);
      }
    }
  }
Esempio n. 23
0
 @Override
 public void onPlayerRespawn(PlayerRespawnEvent event) {
   Player player = event.getPlayer();
   final Hero hero = plugin.getHeroManager().getHero(player);
   hero.setHealth(hero.getMaxHealth());
   hero.setMana(0);
   CraftPlayer craftPlayer = (CraftPlayer) player;
   EntityPlayer entityPlayer = craftPlayer.getHandle();
   entityPlayer.exp = 0;
   entityPlayer.expTotal = 0;
   entityPlayer.expLevel = 0;
   Bukkit.getScheduler()
       .scheduleSyncDelayedTask(
           plugin,
           new Runnable() {
             @Override
             public void run() {
               hero.syncExperience();
             }
           },
           20L);
 }
Esempio n. 24
0
 /**
  * Attempt to check for some exploits (!).
  *
  * @return
  */
 public boolean isIllegal() {
   if (entityPlayer.dead) return false;
   if (!entityPlayer.isSleeping()) {
     // This can not really test stance but height of bounding box.
     final double dY = Math.abs(maxY - minY);
     if (dY > 1.8) return true; // dY > 1.65D ||
     if (dY < 0.1D) return true;
   }
   if (Math.abs(minX) > 3.2E7D
       || Math.abs(maxX) > 3.2E7D
       || Math.abs(minZ) > 3.2E7D
       || Math.abs(maxZ) > 3.2E7D) return true;
   return false;
 }
Esempio n. 25
0
 private void handleArea(
     World world,
     int i,
     int j,
     int k,
     EntityPlayer entityplayer,
     TileEntityToolRack te,
     int slot,
     int dir) {
   boolean hasToolInHand =
       entityplayer.getCurrentEquippedItem() != null
           && (entityplayer.getCurrentEquippedItem().getItem() instanceof ItemTool
               || entityplayer.getCurrentEquippedItem().getItem() instanceof ItemWeapon
               || entityplayer.getCurrentEquippedItem().getItem() instanceof ItemHoe
               || entityplayer.getCurrentEquippedItem().getItem() instanceof ItemProPick);
   if (te.storage[slot] == null && hasToolInHand) {
     te.storage[slot] = entityplayer.getCurrentEquippedItem().copy();
     entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null;
   } else if (te.storage[slot] != null) {
     te.ejectItem(slot, dir);
     te.storage[slot] = null;
   }
 }
Esempio n. 26
0
  // CREDITS TO: lishid (OpenInv Author)
  public static Player getPlayer(String name) {
    Player target = Bukkit.getServer().getPlayer(name);

    if (target == null) {
      try {
        // See if the player has data files
        // Default player folder
        File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
        if (!playerfolder.exists()) {
          return null;
        }

        String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
        if (playername == null) {
          return null;
        }

        // Create an entity to load the player data
        final MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
        final EntityPlayer entity =
            new EntityPlayer(
                server,
                server.getWorldServer(0),
                playername,
                new ItemInWorldManager(server.getWorldServer(0)));
        target = (entity == null) ? null : (Player) entity.getBukkitEntity();
        if (target != null) {
          target.loadData();
        } else {
          return null;
        }
      } catch (Exception e) {
        return null;
      }
    }
    return target;
  }
Esempio n. 27
0
  private void openCustomInventory(Inventory inventory, EntityPlayer player, int windowType) {
    if (player.playerConnection == null) return;
    Container container = new CraftContainer(inventory, this, player.nextContainerCounter());

    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) return;

    String title = container.getBukkitView().getTitle();
    int size = container.getBukkitView().getTopInventory().getSize();

    player.playerConnection.sendPacket(
        new Packet100OpenWindow(container.windowId, windowType, title, size, true));
    getHandle().activeContainer = container;
    getHandle().activeContainer.addSlotListener(player);
  }
  @Override
  public void b(EntityHuman entity) {
    if (lastTargetId == -1 || lastTargetId != entity.id) {
      EntityTargetEvent event =
          new NpcEntityTargetEvent(
              getBukkitEntity(),
              entity.getBukkitEntity(),
              NpcEntityTargetEvent.NpcTargetReason.CLOSEST_PLAYER);
      CraftServer server = ((WorldServer) this.world).getServer();
      server.getPluginManager().callEvent(event);
    }
    lastTargetId = entity.id;

    super.b(entity);
  }
Esempio n. 29
0
  public void a(boolean flag0, boolean flag1, boolean flag2) {
    if (this.bz()) {
      this.o().q().b(this, new Packet18Animation(this, 3));
    }

    super.a(flag0, flag1, flag2);
    if (this.a != null) {
      this.a.a(
          this.u,
          this.v,
          this.w,
          this.A,
          this.B,
          getCanaryWorld().getType().getId(),
          getCanaryWorld().getName());
    }
  }
  @Override
  public void c(Entity entity) {
    if (lastBounceId != entity.id || System.currentTimeMillis() - lastBounceTick > 1000) {
      EntityTargetEvent event =
          new NpcEntityTargetEvent(
              getBukkitEntity(),
              entity.getBukkitEntity(),
              NpcEntityTargetEvent.NpcTargetReason.NPC_BOUNCED);
      CraftServer server = ((WorldServer) this.world).getServer();
      server.getPluginManager().callEvent(event);

      lastBounceTick = System.currentTimeMillis();
    }

    lastBounceId = entity.id;

    super.c(entity);
  }