Skip to content

Commit

Permalink
Prevent two corpses with same name and showTags is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
unldenis committed Jan 24, 2022
1 parent 34f93ff commit b0d80fa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.unldenis.corpse</groupId>
<artifactId>Corpse</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -55,4 +55,17 @@
</dependency>
-->
</dependencies>

<build>
<!-- The jarname on build. -->
<finalName>${project.artifactId}-${project.version}</finalName>
<!-- Replace all the ${} markers for all files in the supplied dir.. -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

</build>
</project>
5 changes: 5 additions & 0 deletions src/main/java/com/github/unldenis/corpse/logic/Corpse.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public int getId() {
return id;
}

@NotNull
public String getName() {
return name;
}

@NotNull
public Location getLocation() {
return location;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/github/unldenis/corpse/manager/CorpsePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public Optional<Corpse> getCorpse(int entityId) {
return Optional.ofNullable(this.corpseMap.get(entityId));
}

@NotNull
public Optional<Corpse> getCorpse(String name) {
return this.getCorpses()
.stream()
.filter(corpse -> corpse.getName().equals(name))
.findFirst();
}

public void remove(int entityId) {
this.getCorpse(entityId).ifPresent(corpse -> {
this.corpseMap.remove(entityId);
Expand All @@ -124,6 +132,14 @@ public Collection<Corpse> getCorpses() {
}

public void takeCareOf(@NotNull Corpse corpse) {
// Prevent two corpses with same name and showTags is enabled
if(this.showTags) {
this.getCorpse(corpse.getName()).ifPresent(c -> {
this.corpseMap.remove(c.getId());
c.getSeeingPlayers()
.forEach(c::hide);
});
}
this.corpseMap.put(corpse.getId(), corpse);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Corpse
version: 1.0-SNAPSHOT
name: ${project.artifactId}
version: ${project.version}
api-version: "1.13"
depend: [ProtocolLib]
author: unldenis
Expand Down

0 comments on commit b0d80fa

Please sign in to comment.