Skip to content

Commit 1184006

Browse files
committed
いろいろ
1 parent 7c97271 commit 1184006

File tree

5 files changed

+61
-31
lines changed

5 files changed

+61
-31
lines changed

src/main/java/com/github/elic0de/thejpspit/database/SqLiteDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public void updatePitPreferences(PitPreferences pitPreferences) {
333333
UPDATE `%pit_preferences%`
334334
SET `preferences` = ?
335335
"""))) {
336-
statement.setBytes(2, plugin.getGson().toJson(pitPreferences).getBytes(StandardCharsets.UTF_8));
336+
statement.setBytes(1, plugin.getGson().toJson(pitPreferences).getBytes(StandardCharsets.UTF_8));
337337
statement.executeUpdate();
338338
} catch (SQLException e) {
339339
getLogger().log(Level.SEVERE, "Failed to update preferences in table", e);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Optional;
99
import org.bukkit.Bukkit;
1010
import org.bukkit.GameMode;
11+
import org.bukkit.Location;
1112
import org.bukkit.Material;
1213
import org.bukkit.entity.Player;
1314
import org.bukkit.event.EventHandler;
@@ -49,7 +50,11 @@ public void onJoin(PlayerJoinEvent event) {
4950
Object packet = packetManager.buildScoreboardTeam(player);
5051
packetManager.sendPacket(packet, player);
5152

52-
plugin.getPitPreferences().ifPresent(pitPreferences -> player.teleport(pitPreferences.getSpawn().orElse(player.getLocation())));
53+
/*plugin.getPitPreferences().ifPresent(pitPreferences -> {
54+
final Location location = pitPreferences.getSpawn().get();
55+
56+
if (location != null) player.teleport(location);
57+
});*/
5358
if (userData.isEmpty()) {
5459
plugin.getDatabase().createPitPlayer(player);
5560
PitPlayerManager.registerUser(new PitPlayer(player));
@@ -163,6 +168,8 @@ public void onXpGain(PlayerExpChangeEvent event) {
163168

164169
@EventHandler
165170
public void on(PlayerInteractEvent event) {
171+
/*final PitPlayer pitPlayer = PitPlayerManager.getPitPlayer(event.getPlayer());
172+
pitPlayer.increaseStreaks();*/
166173
if (event.getHand() != EquipmentSlot.HAND) {
167174
return;
168175
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public interface PacketManager {
8181
@NotNull
8282
Object buildScoreboardTeam(@NotNull Player player) throws IllegalArgumentException;
8383

84+
@NotNull
85+
Object buildTeleportPacket(@NotNull Object entity, Location loc) throws IllegalArgumentException;
86+
8487
/**
8588
* Queues a new packet in the packet queue of a player.
8689
* 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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import java.lang.reflect.Field;
55
import java.lang.reflect.Method;
66
import java.util.Arrays;
7+
import java.util.List;
78
import java.util.Optional;
89
import java.util.UUID;
910
import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy;
1011
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
12+
import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
1113
import net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam;
1214
import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
1315
import net.minecraft.network.syncher.DataWatcher;
1416
import net.minecraft.server.level.WorldServer;
17+
import net.minecraft.world.entity.Entity;
1518
import net.minecraft.world.entity.EntityLiving;
1619
import net.minecraft.world.entity.decoration.EntityArmorStand;
1720
import net.minecraft.world.scores.Scoreboard;
@@ -106,14 +109,15 @@ public Object buildScoreboardTeam(Player player) {
106109
sc.setAccessible(true);
107110
collisionRule.setAccessible(true);
108111
collisionRule.set(packetPlayOutScoreTeamB, "never");
109-
return sc.newInstance("", 0, Optional.of(packetPlayOutScoreTeamB), Arrays.asList(player.getName()));
112+
return sc.newInstance("", 0, Optional.of(packetPlayOutScoreTeamB),
113+
List.of(player.getName()));
110114
} catch (final ReflectiveOperationException e) {
111115
throw new NMSAccessException("Failed to create entity metadata packet", e);
112116
}
113117
}
114118

115119
private Constructor<?> getConstructor(Class<?> clazz, int numParams) {
116-
return Arrays.stream((Constructor[])clazz.getDeclaredConstructors()).filter(constructor -> (constructor.getParameterCount() == numParams)).findFirst().orElse(null);
120+
return Arrays.stream(clazz.getDeclaredConstructors()).filter(constructor -> (constructor.getParameterCount() == numParams)).findFirst().orElse(null);
117121
}
118122

119123
@NotNull
@@ -156,12 +160,24 @@ public Object buildEntityArmorStand(@NotNull Location location, @NotNull String
156160
armorStand.setCustomNameVisible(true);
157161
armorStand.setCustomName(name);
158162

163+
159164
return entityArmorStand;
160165
} catch (final ReflectiveOperationException e) {
161166
throw new NMSAccessException("Failed to create new entity armor stand", e);
162167
}
163168
}
164169

170+
public Object buildTeleportPacket(@NotNull Object entity, Location loc) {
171+
try {
172+
final ArmorStand armorStand = (ArmorStand) this.entityGetBukkitEntityMethod.invoke(entity);
173+
armorStand.teleport(loc);
174+
175+
return new PacketPlayOutEntityTeleport((Entity) entity);
176+
} catch (final ReflectiveOperationException e) {
177+
throw new NMSAccessException("Failed to create new entity armor stand", e);
178+
}
179+
}
180+
165181
@Override
166182
public void sendPacket(@NotNull Object packet, @NotNull Player player) {
167183
try {

src/main/java/com/github/elic0de/thejpspit/task/GameTask.java

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import com.github.elic0de.thejpspit.TheJpsPit;
44
import com.github.elic0de.thejpspit.nms.PacketManager;
55
import com.github.elic0de.thejpspit.player.PitPlayer;
6+
import de.themoep.minedown.MineDown;
67
import java.text.DecimalFormat;
78
import java.util.ArrayList;
89
import java.util.List;
910
import java.util.concurrent.ThreadLocalRandom;
1011
import java.util.concurrent.atomic.AtomicInteger;
12+
import org.bukkit.ChatColor;
1113
import org.bukkit.Location;
1214
import org.bukkit.entity.Entity;
1315
import org.bukkit.entity.Player;
@@ -57,8 +59,6 @@ public void run() {
5759
if (nearbyEntity instanceof Player) packetRecipients.add((Player) nearbyEntity);
5860
}
5961

60-
final Location finalSpawnLocation = spawnLocation;
61-
6262
// Queue packet sending.
6363
pit.getServer().getScheduler().runTaskAsynchronously(pit,
6464
() -> {
@@ -68,37 +68,18 @@ public void run() {
6868
100 * streaks,
6969
packetRecipients
7070
);
71-
summonAndQueueBountyDeletion(
72-
TheJpsPit.getInstance().getPacketManager(),
73-
player.getLocation().add(random.nextDouble(0, 2) - 1d, random.nextDouble(0, 2), random.nextDouble(0, 2) - 1d),
74-
100 * streaks,
75-
packetRecipients
76-
);
77-
summonAndQueueBountyDeletion(
78-
TheJpsPit.getInstance().getPacketManager(),
79-
player.getLocation().add(random.nextDouble(0, 2) - 1d, random.nextDouble(0, 2), random.nextDouble(0, 2) - 1d),
80-
100 * streaks,
81-
packetRecipients
82-
);
83-
summonAndQueueBountyDeletion(
84-
TheJpsPit.getInstance().getPacketManager(),
85-
player.getLocation().add(random.nextDouble(0, 2) - 1d, random.nextDouble(0, 2), random.nextDouble(0, 2) - 1d),
86-
100 * streaks,
87-
packetRecipients
88-
);
8971
}
9072
);
9173
}
9274
}
93-
}.runTaskTimer(pit, 0, 20);
75+
}.runTaskTimer(pit, 0, 5);
9476
}
9577

9678
private void summonAndQueueBountyDeletion(PacketManager packetManager, Location location,
9779
long cost, List<Player> packetRecipients) {
9880

9981
//Create the entity
100-
final Object indicatorEntity = packetManager.buildEntityArmorStand(location,
101-
String.valueOf(cost));
82+
final Object indicatorEntity = packetManager.buildEntityArmorStand(location, ChatColor.GOLD + "" +cost);
10283

10384
//Create the packets
10485
final Object entitySpawnPacket = packetManager.buildEntitySpawnPacket(indicatorEntity);
@@ -110,13 +91,36 @@ private void summonAndQueueBountyDeletion(PacketManager packetManager, Location
11091
packetManager.sendPacket(entityMetadataPacket, recipient);
11192
}
11293

113-
pit.getServer().getScheduler().runTaskLaterAsynchronously(pit, () -> {
94+
final double startY = location.getY();
95+
final double speed = 0.15;
96+
final int[] tick = {0};
97+
final double[] dy = new double[1];
98+
final double duration = 10;
99+
100+
pit.getServer().getScheduler().runTaskTimerAsynchronously(pit, runnable -> {
114101
//Create the destroy packet
102+
115103
final Object entityDestroyPacket = packetManager.buildEntityDestroyPacket(indicatorEntity);
104+
dy[0] = 1;
105+
106+
location.setY(startY + dy[0]);
107+
final Object teleportPacket = packetManager.buildTeleportPacket(indicatorEntity, location);
108+
for (final Player recipient : packetRecipients) {
109+
packetManager.sendPacket(teleportPacket, recipient);
110+
}
111+
dy[0] += speed;
112+
113+
tick[0]++;
114+
if (tick[0] > duration) {
115+
//Send the destroy packet
116+
for (final Player recipient : packetRecipients) {
117+
//packetManager.sendPacket(teleportPacket, recipient);
118+
packetManager.sendPacket(entityDestroyPacket, recipient);
119+
}
120+
runnable.cancel();
121+
}
116122

117-
//Send the destroy packet
118-
for (final Player recipient : packetRecipients) packetManager.sendPacket(entityDestroyPacket, recipient);
119-
}, (long) (.5 * 20));
123+
}, 0, 1);
120124
}
121125

122126

0 commit comments

Comments
 (0)