From ddc8d4a90160c82063891ae1bdadc9d9a6592e86 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Mon, 22 Jan 2024 23:36:07 +0300
Subject: [PATCH 1/7] Update workspace.xml
---
.idea/workspace.xml | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index addaac9..c2701a4 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,18 +4,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -220,7 +209,7 @@
-
+
@@ -237,7 +226,7 @@
file://$PROJECT_DIR$/src/main/java/me/tofaa/entitylib/meta/types/DisplayMeta.java
- 153
+ 173
From a318500c4e455973d232db638eba6d1afd2803d5 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Wed, 31 Jan 2024 17:47:23 +0400
Subject: [PATCH 2/7] Update WrapperEntity.java
---
.../me/tofaa/entitylib/entity/WrapperEntity.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
index 83c583e..b5f19e2 100644
--- a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
+++ b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
@@ -303,6 +303,22 @@ public class WrapperEntity implements Tickable {
addViewer(user.getUUID());
}
+ public void addViewerSilently(UUID viewer) {
+ viewers.add(viewer);
+ }
+
+ public void addViewerSilently(User user) {
+ viewers.add(user.getUUID());
+ }
+
+ public void removeViewerSilently(UUID uuid) {
+ viewers.remove(uuid);
+ }
+
+ public void removeViewerSilently(User user) {
+ viewers.remove(user.getUUID());
+ }
+
public void removeViewer(UUID uuid) {
if (!viewers.remove(uuid)) {
return;
From 88dbb7a474a369d1c2c100926a07953e14f58350 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Sun, 11 Feb 2024 22:51:17 +0400
Subject: [PATCH 3/7] add setLocation
---
src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
index b5f19e2..1d7e120 100644
--- a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
+++ b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
@@ -33,6 +33,13 @@ public class WrapperEntity implements Tickable {
this.entityId = entityId;
}
+ /**
+ Internally sets the location of this entity. This does not inform any of the entities viewers about this change.
+ */
+ public void setLocation(Location location) {
+ this.location = location;
+ }
+
public void refresh() {
if (!spawned) return;
sendPacketToViewers(meta.createPacket());
From 9a04858686286648ec5839ea7ecf3ae1acd15b29 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Sun, 11 Feb 2024 23:04:05 +0400
Subject: [PATCH 4/7] migrate both passenger and viewer to concurrent hash set
---
.idea/workspace.xml | 51 ++++++++++---------
.../tofaa/entitylib/entity/WrapperEntity.java | 6 ++-
2 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c2701a4..0cd6305 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,9 @@
-
+
+
+
@@ -66,30 +68,30 @@
- {
+ "keyToString": {
+ "Gradle.Build EntityLib.executor": "Run",
+ "Gradle.EntityLib:test-plugin [runServer].executor": "Run",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "WebServerToolWindowFactoryState": "false",
+ "git-widget-placeholder": "master",
+ "ignore.virus.scanning.warn.message": "true",
+ "jdk.selected.JAVA_MODULE": "corretto-17",
+ "kotlin-language-version-configured": "true",
+ "last_opened_file_path": "D:/Github/EntityLib",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "project.structure.last.edited": "Modules",
+ "project.structure.proportion": "0.0",
+ "project.structure.side.proportion": "0.0",
+ "settings.editor.selected.configurable": "preferences.pluginManager",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -210,6 +212,7 @@
+
diff --git a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
index b5f19e2..fe36565 100644
--- a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
+++ b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java
@@ -12,19 +12,21 @@ import me.tofaa.entitylib.meta.EntityMeta;
import me.tofaa.entitylib.meta.types.ObjectData;
import org.jetbrains.annotations.NotNull;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArraySet;
public class WrapperEntity implements Tickable {
private final EntityType entityType;
private final int entityId;
private final Optional uuid;
private final EntityMeta meta;
- private final Set viewers = new HashSet<>();
+ private final Set viewers = ConcurrentHashMap.newKeySet();
private Location location;
private boolean onGround;
private boolean spawned;
protected Vector3d velocity = Vector3d.zero();
private int riding = -1;
- private Set passengers = new HashSet<>();
+ private Set passengers = ConcurrentHashMap.newKeySet();
public WrapperEntity(int entityId, @NotNull UUID uuid, EntityType entityType, EntityMeta meta) {
this.uuid = Optional.of(uuid);
From d8bd671f20509bbfa2e22632a280aa3ce0bb7494 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Sun, 11 Feb 2024 23:06:17 +0400
Subject: [PATCH 5/7] add removing
---
.../java/me/tofaa/entitylib/EntityLib.java | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/main/java/me/tofaa/entitylib/EntityLib.java b/src/main/java/me/tofaa/entitylib/EntityLib.java
index f536679..dd2b180 100644
--- a/src/main/java/me/tofaa/entitylib/EntityLib.java
+++ b/src/main/java/me/tofaa/entitylib/EntityLib.java
@@ -105,6 +105,28 @@ public final class EntityLib {
return entitiesById.get(entityId);
}
+ /**
+ * Removes the entity completely from EntityLib and the platform.
+ * The viewer will no longer be able to see the entity.
+ */
+ public static boolean removeEntity(int entityId) {
+ checkInit();
+ WrapperEntity e = entitiesById.get(entityId);
+ if (e == null) return false;
+ entities.remove(e.getUuid());
+ entitiesById.remove(entityId);
+ e.remove();
+ return true;
+ }
+
+ /**
+ * Removes the entity completely from EntityLib and the platform.
+ * The viewer will no longer be able to see the entity.
+ */
+ public static boolean removeEntity(WrapperEntity entity) {
+ return removeEntity(entity.getEntityId());
+ }
+
/**
* @param uuid the entity uuid
* @return the entity with the given uuid, or null if an entity with that uuid does not exist
From 62fc93c4c9b44672316de39634fb1cc9ccf996c3 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Mon, 12 Feb 2024 18:21:23 +0400
Subject: [PATCH 6/7] Fix exception if channel is null
---
src/main/java/me/tofaa/entitylib/EntityLib.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/main/java/me/tofaa/entitylib/EntityLib.java b/src/main/java/me/tofaa/entitylib/EntityLib.java
index dd2b180..49251e8 100644
--- a/src/main/java/me/tofaa/entitylib/EntityLib.java
+++ b/src/main/java/me/tofaa/entitylib/EntityLib.java
@@ -327,7 +327,12 @@ public final class EntityLib {
@ApiStatus.Internal
public static void sendPacket(UUID user, PacketWrapper> wrapper) {
checkInit();
- packetEvents.getProtocolManager().sendPacket(packetEvents.getProtocolManager().getChannel(user), wrapper);
+ Object channel = packetEvents.getProtocolManager().getChannel(user);
+ if (channel == null) {
+ System.out.println("EntityLib could not send packet to user " + user);
+ return;
+ }
+ packetEvents.getProtocolManager().sendPacket(channel, wrapper);
}
private static void checkInit() {
From e7b9e9fff367e496184f215c1bc51c25ba2aa9c3 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Fri, 16 Feb 2024 18:21:59 +0400
Subject: [PATCH 7/7] Update EntityLib.java
---
src/main/java/me/tofaa/entitylib/EntityLib.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/me/tofaa/entitylib/EntityLib.java b/src/main/java/me/tofaa/entitylib/EntityLib.java
index 49251e8..d8f9ebf 100644
--- a/src/main/java/me/tofaa/entitylib/EntityLib.java
+++ b/src/main/java/me/tofaa/entitylib/EntityLib.java
@@ -329,7 +329,10 @@ public final class EntityLib {
checkInit();
Object channel = packetEvents.getProtocolManager().getChannel(user);
if (channel == null) {
- System.out.println("EntityLib could not send packet to user " + user);
+ boolean b = Boolean.parseBoolean(System.getenv("entitylib_debug"));
+ if (b) {
+ System.out.println("EntityLib could not send packet to user " + user);
+ }
return;
}
packetEvents.getProtocolManager().sendPacket(channel, wrapper);