Skip to content

Commit ca1cf14

Browse files
committed
Fix this plugin
1 parent fa6b556 commit ca1cf14

File tree

6 files changed

+53
-57
lines changed

6 files changed

+53
-57
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.settings
2+
.classpath
3+
.project
4+
target/

README.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>maru</groupId>
66
<artifactId>pmchair</artifactId>
7-
<version>1.3</version>
7+
<version>2.0</version>
88
<packaging>jar</packaging>
99

1010
<repositories>

src/main/java/maru/PmChair.java

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
import cn.nukkit.block.BlockStairs;
1010
import cn.nukkit.entity.Entity;
1111
import cn.nukkit.entity.data.EntityMetadata;
12-
import cn.nukkit.entity.item.EntityItem;
1312
import cn.nukkit.event.EventHandler;
1413
import cn.nukkit.event.Listener;
1514
import cn.nukkit.event.player.PlayerInteractEvent;
1615
import cn.nukkit.event.player.PlayerQuitEvent;
1716
import cn.nukkit.event.server.DataPacketReceiveEvent;
1817
import cn.nukkit.network.protocol.AddEntityPacket;
19-
import cn.nukkit.network.protocol.MoveEntityPacket;
18+
import cn.nukkit.network.protocol.MoveEntityAbsolutePacket;
2019
import cn.nukkit.network.protocol.PlayerActionPacket;
2120
import cn.nukkit.network.protocol.ProtocolInfo;
2221
import cn.nukkit.network.protocol.RemoveEntityPacket;
@@ -35,77 +34,78 @@ public class PmChair extends PluginBase implements Listener {
3534
public static final int m_version = 1;
3635

3736
@Override
38-
public void onEnable(){
37+
public void onEnable() {
3938
this.getServer().getPluginManager().registerEvents(this, this);
4039
this.loadMessage();
4140
}
4241

43-
public void loadMessage(){
42+
public void loadMessage() {
4443
this.saveResource("messages.yml");
4544
this.messages = new Config(new File(this.getDataFolder(), "messages.yml"), Config.YAML).getAll();
4645
this.updateMessage();
4746
}
4847

49-
public void updateMessage(){
50-
if((int) this.messages.get("m_version") < m_version) {
48+
public void updateMessage() {
49+
if ((int) this.messages.get("m_version") < m_version) {
5150
this.saveResource("messages.yml", true);
5251
new Config(new File(this.getDataFolder(), "messages.yml"), Config.YAML).getAll().forEach((k, v) -> this.messages.put(k, (String) v));
5352
}
5453
}
5554

56-
public String get(String m){
55+
public String get(String m) {
5756
return (String) this.messages.get(this.messages.get("default-language") + "-" + m);
5857
}
5958

6059
@EventHandler
61-
public void onTouch(PlayerInteractEvent event){
60+
public void onTouch(PlayerInteractEvent event) {
6261
Player player = event.getPlayer();
63-
if(player.isSneaking() || event.getAction() != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){
62+
if (player.isSneaking() || event.getAction() != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
6463
return;
6564
}
6665

6766
String name = player.getName().toLowerCase();
6867
Block block = event.getBlock();
6968

70-
if(! this.onChair.containsKey(name)){
71-
if(block instanceof BlockStairs){
72-
if(! this.doubleTap.containsKey(name)){
69+
if (!this.onChair.containsKey(name)) {
70+
if (block instanceof BlockStairs) {
71+
if (!this.doubleTap.containsKey(name)) {
7372
this.doubleTap.put(name, System.currentTimeMillis());
7473
player.sendPopup(TextFormat.RED + this.get("touch-popup"));
7574
return;
7675
}
77-
if(System.currentTimeMillis() - this.doubleTap.get(name) < 500){
78-
79-
AddEntityPacket AddTagblockPacket = new AddEntityPacket();
76+
77+
if (System.currentTimeMillis() - this.doubleTap.get(name) < 500) {
78+
79+
AddEntityPacket addTagblockPacket = new AddEntityPacket();
8080
long eid = Entity.entityCount++;
8181
this.tagblock.put(name, eid);
82-
AddTagblockPacket.entityRuntimeId = eid;
83-
AddTagblockPacket.entityUniqueId = eid;
84-
AddTagblockPacket.speedX = 0;
85-
AddTagblockPacket.speedY = 0;
86-
AddTagblockPacket.speedZ = 0;
87-
AddTagblockPacket.pitch = 0;
88-
AddTagblockPacket.yaw = 0;
89-
AddTagblockPacket.x = (float) (block.getX() + 0.5);
90-
AddTagblockPacket.y = (float) (block.getY() + 0.3);
91-
AddTagblockPacket.z = (float) (block.getZ() + 0.5);
92-
AddTagblockPacket.type = 15;
82+
addTagblockPacket.entityRuntimeId = eid;
83+
addTagblockPacket.entityUniqueId = eid;
84+
addTagblockPacket.speedX = 0;
85+
addTagblockPacket.speedY = 0;
86+
addTagblockPacket.speedZ = 0;
87+
addTagblockPacket.pitch = 0;
88+
addTagblockPacket.yaw = 0;
89+
addTagblockPacket.x = (float) (block.getX() + 0.5);
90+
addTagblockPacket.y = (float) (block.getY() + 0.3);
91+
addTagblockPacket.z = (float) (block.getZ() + 0.5);
92+
addTagblockPacket.type = 84;
9393

9494
long flags = 0;
9595
flags |= 1 << Entity.DATA_FLAG_CAN_SHOW_NAMETAG;
9696
flags |= 1 << Entity.DATA_FLAG_INVISIBLE;
9797
flags |= 1 << Entity.DATA_FLAG_NO_AI;
9898
flags |= 1 << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG;
9999

100-
AddTagblockPacket.metadata = new EntityMetadata()
100+
addTagblockPacket.metadata = new EntityMetadata()
101101
.putLong(Entity.DATA_FLAGS, flags)
102102
.putShort(Entity.DATA_AIR, 400)
103103
.putShort(Entity.DATA_MAX_AIR, 400)
104104
.putString(Entity.DATA_NAMETAG, TextFormat.AQUA + this.get("tagblock-message"))
105105
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
106106
.putFloat(Entity.DATA_SCALE, 0.0001f);
107107

108-
MoveEntityPacket moveTagblockPacket = new MoveEntityPacket();
108+
MoveEntityAbsolutePacket moveTagblockPacket = new MoveEntityAbsolutePacket();
109109
moveTagblockPacket.eid = eid;
110110
moveTagblockPacket.x = (float) (block.getX() + 0.5);
111111
moveTagblockPacket.y = (float) (block.getY() + 0.7);
@@ -126,22 +126,22 @@ public void onTouch(PlayerInteractEvent event){
126126
addEntityPacket.x = (float) (block.getX() + 0.5);
127127
addEntityPacket.y = (float) (block.getY() + 1.6);
128128
addEntityPacket.z = (float) (block.getZ() + 0.5);
129-
addEntityPacket.type = 15;
129+
addEntityPacket.type = 84;
130130

131131
flags = 0;
132-
//flags |= 1 << Entity.DATA_FLAG_CAN_SHOW_NAMETAG;
132+
flags |= 1 << Entity.DATA_FLAG_CAN_SHOW_NAMETAG;
133133
flags |= 1 << Entity.DATA_FLAG_INVISIBLE;
134134
flags |= 1 << Entity.DATA_FLAG_NO_AI;
135-
//flags |= 1 << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG;
135+
flags |= 1 << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG;
136136

137137
addEntityPacket.metadata = new EntityMetadata()
138138
.putLong(Entity.DATA_FLAGS, flags)
139139
.putShort(Entity.DATA_AIR, 400)
140140
.putShort(Entity.DATA_MAX_AIR, 400)
141-
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1);
142-
//.putFloat(Entity.DATA_SCALE, 0.0001f);
141+
.putLong(Entity.DATA_LEAD_HOLDER_EID, -1)
142+
.putFloat(Entity.DATA_SCALE, 0.0001f);
143143

144-
MoveEntityPacket moveEntityPacket = new MoveEntityPacket();
144+
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
145145
moveEntityPacket.eid = eid;
146146
moveEntityPacket.x = (float) (block.getX() + 0.5);
147147
moveEntityPacket.y = (float) (block.getY() + 1.6);
@@ -153,29 +153,28 @@ public void onTouch(PlayerInteractEvent event){
153153
SetEntityLinkPacket setEntityLinkPacket = new SetEntityLinkPacket();
154154
setEntityLinkPacket.rider = eid;
155155
setEntityLinkPacket.riding = player.getId();
156-
setEntityLinkPacket.type = SetEntityLinkPacket.TYPE_RIDE;
156+
setEntityLinkPacket.type = SetEntityLinkPacket.TYPE_PASSENGER;
157157

158158
this.getServer().getOnlinePlayers().values().forEach((target) -> {
159159
target.dataPacket(addEntityPacket);
160160
target.dataPacket(moveEntityPacket);
161-
162-
target.dataPacket(AddTagblockPacket);
161+
target.dataPacket(addTagblockPacket);
163162
target.dataPacket(moveTagblockPacket);
164-
if(target != player){
163+
if (target != player) {
165164
target.dataPacket(setEntityLinkPacket);
166165
}
167166
});
168167

169-
setEntityLinkPacket.riding = 0;
170168
player.dataPacket(setEntityLinkPacket);
169+
player.setDataFlag(Entity.DATA_FLAGS, Entity.DATA_FLAG_RIDING, true);
171170
this.doubleTap.remove(name);
172-
}else{
171+
} else {
173172
this.doubleTap.put(name, System.currentTimeMillis());
174173
player.sendPopup(TextFormat.RED + this.get("touch-popup"));
175174
return;
176175
}
177176
}
178-
}else{
177+
} else {
179178
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
180179
removeEntityPacket.eid = this.onChair.remove(name);
181180
RemoveEntityPacket removeTagblockPacket = new RemoveEntityPacket();
@@ -188,11 +187,11 @@ public void onTouch(PlayerInteractEvent event){
188187
}
189188

190189
@EventHandler
191-
public void onJump(DataPacketReceiveEvent event){
192-
if(event.getPacket().pid() == ProtocolInfo.PLAYER_ACTION_PACKET){
190+
public void onJump(DataPacketReceiveEvent event) {
191+
if (event.getPacket().pid() == ProtocolInfo.PLAYER_ACTION_PACKET) {
193192
PlayerActionPacket packet = (PlayerActionPacket) event.getPacket();
194193
String name = event.getPlayer().getName().toLowerCase();
195-
if (packet.action == PlayerActionPacket.ACTION_JUMP && this.onChair.containsKey(name)){
194+
if (packet.action == PlayerActionPacket.ACTION_JUMP && this.onChair.containsKey(name)) {
196195
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
197196
removeEntityPacket.eid = this.onChair.remove(name);
198197
RemoveEntityPacket removeTagblockPacket = new RemoveEntityPacket();
@@ -206,9 +205,9 @@ public void onJump(DataPacketReceiveEvent event){
206205
}
207206

208207
@EventHandler
209-
public void onQuit(PlayerQuitEvent event){
208+
public void onQuit(PlayerQuitEvent event) {
210209
String name = event.getPlayer().getName().toLowerCase();
211-
if(! this.onChair.containsKey(name)){
210+
if (!this.onChair.containsKey(name)) {
212211
return;
213212
}
214213
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();

src/main/resources/messages.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@ default-language: eng
22

33
m_version: 1
44

5-
eng-touch-popup: Please touch again if you want it to sit on the stairs.
5+
eng-touch-popup: Touch again to sit on the stairs
66
eng-tagblock-message: ""
7-
8-
kor-touch-popup: 계단에 앉으려면 한번 더 터치해 주세요.
9-
kor-tagblock-message: "휴식중.."

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: PmChair
22
main: maru.PmChair
3-
author: maru
4-
version: "1.3"
3+
author: maru, PetteriM1
4+
version: "2.0"
55
api: 1.0.0

0 commit comments

Comments
 (0)