Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
beito123 committed Oct 13, 2018
1 parent 5e98d95 commit c1e003b
Show file tree
Hide file tree
Showing 12 changed files with 828 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# for IntelliJ IDEA
/.idea/*

# no need
/dist/*
/.gradle/*
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# Nukkit-Plugins-sub

My bad plugins for NukkiX

## Build

Run the following command to build plugins.


./gradlew build

## License

These plugins are released under the MIT license.

About the license, see the LICENSE file or the under link.

MIT License
https://opensource.org/licenses/mit-license.php
2 changes: 2 additions & 0 deletions Sit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group 'Sit'
version '1.1.0'
206 changes: 206 additions & 0 deletions Sit/src/main/java/ru/bk/beito3/sit/Chair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
package ru.bk.beito3.sit;

/*
* Sit
*
* Copyright (c) 2018 beito
*
* This software is released under the MIT License.
* http://opensource.org/licenses/mit-license.php
*/

import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityRideable;
import cn.nukkit.entity.data.EntityMetadata;
import cn.nukkit.entity.data.Vector3fEntityData;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.Vector3f;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.network.protocol.AddEntityPacket;
import cn.nukkit.network.protocol.SetEntityLinkPacket;

import java.util.Map;

public class Chair extends Entity implements EntityRideable {

private static final byte STAND_ACTION_ID = 0;
private static final byte SIT_ACTION_ID = 2;
public int NETWORK_ID = -1;
private EntityMetadata defaultProperties = new EntityMetadata()
.putLong(DATA_FLAGS, (1L << DATA_FLAG_NO_AI) |
(1L << DATA_FLAG_INVISIBLE));


public Chair(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}

@Override
public int getNetworkId() {
return NETWORK_ID;
}

@Override
protected void initEntity() {
super.initEntity();

if (namedTag.exist("remove")) {
this.close();
}
}

@Override
public void spawnTo(Player player) {
super.spawnTo(player); // Bad hacks // it needs for hasSpawned, but send a player a spawn packet

AddEntityPacket pk = new AddEntityPacket();
pk.type = NETWORK_ID;// specification for our server
//pk.type = EntityItem.NETWORK_ID;//invisible if you like
pk.entityUniqueId = this.getId();
pk.entityRuntimeId = this.getId();
pk.x = (float) this.x;
pk.y = (float) this.y;
pk.z = (float) this.z;
pk.speedX = (float) this.motionX;
pk.speedY = (float) this.motionY;
pk.speedZ = (float) this.motionZ;
pk.metadata = defaultProperties;

player.dataPacket(pk);

if (this.hasSat() && player != this.getRider()) {
this.sendLinkPacket(player, SIT_ACTION_ID);
}
}

@Override
public void close() {
if (!this.closed) {
if (this.getRider() != null) {
this.standupSittingEntity();
}
}

super.close();
}

@Override
public void saveNBT() {
super.saveNBT();
namedTag.putByte("remove", 1); //Remove Flag
}

//

public Entity getRider() {
return this.linkedEntity;
}

public boolean sitEntity(Entity entity) {
return this.sitEntity(entity, null);
}

public boolean sitEntity(Entity entity, Vector3f offset) {
if (this.getRider() != null) {
return false;
}

entity.setLinkedEntity(this);
this.setLinkedEntity(entity);

entity.setDataFlag(DATA_FLAGS, DATA_FLAG_RIDING, true);

this.sendLinkPacketToAll(SIT_ACTION_ID);

if (this.getRider() instanceof Player) {
this.sendLinkPacketToRider(SIT_ACTION_ID, offset);
}

return true;
}

public boolean standupSittingEntity() {
if (this.getRider() == null) {
return false;
}

this.getRider().setDataFlag(DATA_FLAGS, DATA_FLAG_RIDING, false);

this.getRider().setLinkedEntity(null);
this.setLinkedEntity(null);

this.sendLinkPacketToAll(STAND_ACTION_ID);

if (this.getRider() instanceof Player) {
this.sendLinkPacketToRider(STAND_ACTION_ID, new Vector3f(0, 0, 0));
}

return true;
}

public boolean hasSat() {
Entity entity = this.getRider();
return entity != null && entity.isAlive() && !entity.closed;
}

public boolean sendLinkPacket(Player player, byte type) {
if (this.getRider() == null) {
return false;
}

SetEntityLinkPacket pk = new SetEntityLinkPacket();
pk.rider = this.getId();
pk.riding = this.getRider().getId();
pk.type = type;

player.dataPacket(pk);

return true;
}

public boolean sendLinkPacketToRider(byte type) {
return sendLinkPacketToRider(type, null);
}

public boolean sendLinkPacketToRider(byte type, Vector3f offset) {
if (!(this.getRider() instanceof Player)) {
return false;
}

Player player = (Player) this.getRider();

SetEntityLinkPacket pk = new SetEntityLinkPacket();
pk.rider = 0;
pk.riding = this.getRider().getId();
pk.type = type;

player.dataPacket(pk);

if (offset != null) {
player.setDataProperty(new Vector3fEntityData(Entity.DATA_RIDER_SEAT_POSITION, offset));
}

return true;
}

public boolean sendLinkPacketToAll(byte type) {
if (this.getRider() == null) {
return false;
}

Map<Long, Player> players = this.getLevel().getPlayers();


for (Map.Entry<Long, Player> entry : players.entrySet()) {
sendLinkPacket(entry.getValue(), type);
}

return true;
}

@Override
public boolean mountEntity(Entity entity) {
return false;
}
}
Loading

0 comments on commit c1e003b

Please sign in to comment.