Skip to content

Commit 7c97271

Browse files
committed
当たり判定を削除
1 parent 8f58939 commit 7c97271

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

src/main/java/com/github/elic0de/thejpspit/TheJpsPit.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@
3131
import java.util.logging.Level;
3232
import org.bukkit.Bukkit;
3333
import org.bukkit.GameRule;
34-
import org.bukkit.entity.Player;
3534
import org.bukkit.plugin.PluginManager;
3635
import org.bukkit.plugin.java.JavaPlugin;
37-
import org.bukkit.scoreboard.Scoreboard;
38-
import org.bukkit.scoreboard.Team;
39-
import org.bukkit.scoreboard.Team.Option;
40-
import org.bukkit.scoreboard.Team.OptionStatus;
36+
37+
4138

4239
public final class TheJpsPit extends JavaPlugin {
4340

@@ -51,8 +48,6 @@ public final class TheJpsPit extends JavaPlugin {
5148
private QueueTask queueTask;
5249
private List<Hook> hooks = new ArrayList<>();
5350

54-
private Scoreboard scoreboard;
55-
private Team team;
5651
private Optional<PitPreferences> pitPreferences;
5752

5853
private PacketManager packetManager;
@@ -89,7 +84,6 @@ public void onEnable() {
8984
ratingHelper = new KillRatingHelper(0);
9085
queueManager = new QueueManager();
9186

92-
optionScoreboard();
9387
setPreferences();
9488
setPacketManager();
9589

@@ -131,19 +125,6 @@ public void onEnable() {
131125
});
132126
}
133127

134-
public void addPitTeam(Player player) {
135-
team.addEntry(player.getName());
136-
}
137-
138-
public void removePitTeam(Player player) {
139-
team.removeEntry(player.getName());
140-
}
141-
142-
private void optionScoreboard() {
143-
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
144-
team = scoreboard.registerNewTeam("pit");
145-
team.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
146-
}
147128

148129
private void setPreferences() {
149130
final Optional<PitPreferences> preferences = database.getPitPreferences();

src/main/java/com/github/elic0de/thejpspit/game/Game.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ public void join(PitPlayer player) {
2424
pitPlayers.add(player);
2525
player.addItem();
2626
player.getBoard().updateLines();
27-
pit.addPitTeam(player.getPlayer());
2827
player.updateDisplayName();
2928
player.setLastDamager(null);
3029
}
3130

3231
public void leave(PitPlayer player) {
3332
pit.getDatabase().updateUserData(player);
3433
pitPlayers.remove(player);
35-
pit.removePitTeam(player.getPlayer());
3634
}
3735

3836
public void death(PitPlayer player) {

src/main/java/com/github/elic0de/thejpspit/listener/EventListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.elic0de.thejpspit.TheJpsPit;
44
import com.github.elic0de.thejpspit.gui.ServerQueueMenu;
5+
import com.github.elic0de.thejpspit.nms.PacketManager;
56
import com.github.elic0de.thejpspit.player.PitPlayer;
67
import com.github.elic0de.thejpspit.player.PitPlayerManager;
78
import java.util.Optional;
@@ -43,6 +44,12 @@ public void onJoin(PlayerJoinEvent event) {
4344

4445
final Player player = event.getPlayer();
4546
final Optional<PitPlayer> userData = plugin.getDatabase().getPitPlayer(player);
47+
48+
final PacketManager packetManager = TheJpsPit.getInstance().getPacketManager();
49+
Object packet = packetManager.buildScoreboardTeam(player);
50+
packetManager.sendPacket(packet, player);
51+
52+
plugin.getPitPreferences().ifPresent(pitPreferences -> player.teleport(pitPreferences.getSpawn().orElse(player.getLocation())));
4653
if (userData.isEmpty()) {
4754
plugin.getDatabase().createPitPlayer(player);
4855
PitPlayerManager.registerUser(new PitPlayer(player));
@@ -56,7 +63,6 @@ public void onJoin(PlayerJoinEvent event) {
5663
if (updateNeeded) {
5764
plugin.getDatabase().updateUserData(pitPlayer);
5865
}
59-
plugin.getPitPreferences().ifPresent(pitPreferences -> player.teleport(pitPreferences.getSpawn().orElse(player.getLocation())));
6066
}
6167

6268
@EventHandler

src/main/java/com/github/elic0de/thejpspit/nms/PacketManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public interface PacketManager {
7878
@NotNull
7979
Object buildEntityArmorStand(@NotNull Location location, @NotNull String name) throws IllegalArgumentException;
8080

81+
@NotNull
82+
Object buildScoreboardTeam(@NotNull Player player) throws IllegalArgumentException;
83+
8184
/**
8285
* Queues a new packet in the packet queue of a player.
8386
* This method will not flush the packet queue, the passed packet will hence be published to the player in the next

src/main/java/com/github/elic0de/thejpspit/nms/PacketManager1_19_R1.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
package com.github.elic0de.thejpspit.nms;
22

3+
import java.lang.reflect.Constructor;
4+
import java.lang.reflect.Field;
5+
import java.lang.reflect.Method;
6+
import java.util.Arrays;
7+
import java.util.Optional;
8+
import java.util.UUID;
39
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
410
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
11+
import net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam;
512
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
613
import net.minecraft.network.syncher.DataWatcher;
714
import net.minecraft.server.level.WorldServer;
815
import net.minecraft.world.entity.EntityLiving;
916
import net.minecraft.world.entity.decoration.EntityArmorStand;
17+
import net.minecraft.world.scores.Scoreboard;
18+
import net.minecraft.world.scores.ScoreboardTeam;
1019
import org.bukkit.Bukkit;
1120
import org.bukkit.Location;
1221
import org.bukkit.World;
1322
import org.bukkit.entity.ArmorStand;
1423
import org.bukkit.entity.Player;
1524
import org.jetbrains.annotations.NotNull;
1625

17-
import java.lang.reflect.Field;
18-
import java.lang.reflect.Method;
19-
2026
/**
2127
* Implementation of the packet manager for the 1.19 minecraft java version.
2228
* The implementation uses a mixture of direct calls against the re-obfuscated server internals and reflection.
2329
*/
2430
public final class PacketManager1_19_R1 implements PacketManager {
2531

32+
private final Class<?> scoreboardClass;
2633
private final Method entityGetIdMethod;
2734
private final Method entityGetDataWatcherMethod;
2835
private final Method entityGetHandleMethod;
@@ -32,13 +39,15 @@ public final class PacketManager1_19_R1 implements PacketManager {
3239

3340
private final Field entityPlayerPlayerConnectionField;
3441

35-
public PacketManager1_19_R1(final @NotNull Method entityGetIdMethod,
42+
public PacketManager1_19_R1(final @NotNull Class scoreboardClass,
43+
final @NotNull Method entityGetIdMethod,
3644
final @NotNull Method entityGetDataWatcherMethod,
3745
final @NotNull Method entityGetHandleMethod,
3846
final @NotNull Method entityGetBukkitEntityMethod,
3947
final @NotNull Method worldGetHandleMethod,
4048
final @NotNull Method playerConnectionSendPacketMethod,
4149
final @NotNull Field entityPlayerPlayerConnectionField) {
50+
this.scoreboardClass = scoreboardClass;
4251
this.entityGetIdMethod = entityGetIdMethod;
4352
this.entityGetDataWatcherMethod = entityGetDataWatcherMethod;
4453
this.entityGetHandleMethod = entityGetHandleMethod;
@@ -52,6 +61,7 @@ public PacketManager1_19_R1(final @NotNull Method entityGetIdMethod,
5261
public static PacketManager1_19_R1 make() {
5362
try {
5463
return new PacketManager1_19_R1(
64+
getMojangClass("network.protocol.game.PacketPlayOutScoreboardTeam"),
5565
getMojangClass("world.entity.Entity").getMethod("ae"),
5666
getMojangClass("world.entity.Entity").getMethod("ai"),
5767
getCBClass("entity.CraftEntity").getMethod("getHandle"),
@@ -83,6 +93,29 @@ public Object buildEntitySpawnPacket(@NotNull Object entity) {
8393
return new PacketPlayOutSpawnEntity((EntityLiving) entity);
8494
}
8595

96+
@NotNull
97+
@Override
98+
public Object buildScoreboardTeam(Player player) {
99+
try {
100+
final Scoreboard scoreboard = new Scoreboard();
101+
final ScoreboardTeam scoreboardTeam = new ScoreboardTeam(scoreboard, UUID.randomUUID().toString().substring(0, 15));
102+
final PacketPlayOutScoreboardTeam.b packetPlayOutScoreTeamB = new PacketPlayOutScoreboardTeam.b(scoreboardTeam);
103+
final Constructor<?> sc = getConstructor(scoreboardClass, 4);
104+
final Field collisionRule = packetPlayOutScoreTeamB.getClass().getDeclaredField("e");
105+
106+
sc.setAccessible(true);
107+
collisionRule.setAccessible(true);
108+
collisionRule.set(packetPlayOutScoreTeamB, "never");
109+
return sc.newInstance("", 0, Optional.of(packetPlayOutScoreTeamB), Arrays.asList(player.getName()));
110+
} catch (final ReflectiveOperationException e) {
111+
throw new NMSAccessException("Failed to create entity metadata packet", e);
112+
}
113+
}
114+
115+
private Constructor<?> getConstructor(Class<?> clazz, int numParams) {
116+
return Arrays.stream((Constructor[])clazz.getDeclaredConstructors()).filter(constructor -> (constructor.getParameterCount() == numParams)).findFirst().orElse(null);
117+
}
118+
86119
@NotNull
87120
@Override
88121
public Object buildEntityMetadataPacket(@NotNull Object entity, boolean forceUpdateAll) {

0 commit comments

Comments
 (0)