-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
302 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
api/src/main/java/me/tofaa/entitylib/storage/ByteEntitySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package me.tofaa.entitylib.storage; | ||
|
||
import me.tofaa.entitylib.wrapper.WrapperEntity; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class ByteEntitySerializer implements EntitySerializer<ByteBuffer, ByteBuffer> { | ||
@Override | ||
public WrapperEntity read(ByteBuffer reader) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void write(ByteBuffer writer, WrapperEntity wrapper) { | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/java/me/tofaa/entitylib/storage/EntitySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.tofaa.entitylib.storage; | ||
|
||
import me.tofaa.entitylib.wrapper.WrapperEntity; | ||
|
||
/** | ||
* An interface that represents a way to serialize and deserialize {@link WrapperEntity} and its subclasses. | ||
* @param <R> the reader generic | ||
* @param <W> the writer generic | ||
*/ | ||
public interface EntitySerializer<R, W> { | ||
|
||
WrapperEntity read(R reader); | ||
|
||
void write(W writer, WrapperEntity wrapper); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
api/src/main/java/me/tofaa/entitylib/storage/EntityStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package me.tofaa.entitylib.storage; | ||
|
||
import me.tofaa.entitylib.wrapper.WrapperEntity; | ||
|
||
import java.util.Collection; | ||
|
||
public interface EntityStorage { | ||
|
||
|
||
Collection<WrapperEntity> readAll(); | ||
|
||
void writeAll(Collection<WrapperEntity> entities); | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/me/tofaa/entitylib/storage/FSEntityStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.tofaa.entitylib.storage; | ||
|
||
import me.tofaa.entitylib.wrapper.WrapperEntity; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public class FSEntityStorage implements EntityStorage{ | ||
@Override | ||
public Collection<WrapperEntity> readAll() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public void writeAll(Collection<WrapperEntity> entities) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package me.tofaa.entitylib.wrapper; | ||
|
||
import com.github.retrooper.packetevents.protocol.attribute.Attribute; | ||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes; | ||
import org.w3c.dom.Attr; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.function.Consumer; | ||
|
||
public final class WrapperEntityAttributes { | ||
|
||
|
||
public static final WrapperPlayServerUpdateAttributes.PropertyModifier.Operation ADDITION = WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.ADDITION; | ||
public static final WrapperPlayServerUpdateAttributes.PropertyModifier.Operation MULTIPLY_BASE = WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.MULTIPLY_BASE; | ||
public static final WrapperPlayServerUpdateAttributes.PropertyModifier.Operation MULTIPLY_TOTAL = WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.MULTIPLY_TOTAL; | ||
|
||
private final WrapperEntity entity; | ||
private final List<WrapperPlayServerUpdateAttributes.Property> properties; | ||
|
||
public WrapperEntityAttributes(WrapperEntity entity) { | ||
this.entity = entity; | ||
this.properties = new CopyOnWriteArrayList<>(); | ||
} | ||
|
||
public void setAttribute(Attribute attribute, double value, List<WrapperPlayServerUpdateAttributes.PropertyModifier> modifiers) { | ||
this.properties.stream() | ||
.filter(property -> property.getAttribute() == attribute) | ||
.findFirst().ifPresent(properties::remove); | ||
this.properties.add(new WrapperPlayServerUpdateAttributes.Property(attribute, value, modifiers)); | ||
refresh(); | ||
} | ||
|
||
public void setAttribute(Attribute attribute, double value, WrapperPlayServerUpdateAttributes.PropertyModifier modifier) { | ||
setAttribute(attribute, value, Collections.singletonList(modifier)); | ||
} | ||
|
||
public void setAttribute(Attribute attribute, double value) { | ||
setAttribute(attribute, value, Collections.emptyList()); | ||
} | ||
|
||
public List<WrapperPlayServerUpdateAttributes.Property> getProperties() { | ||
return new ArrayList<>(properties); | ||
} | ||
|
||
public void forEach(Consumer<WrapperPlayServerUpdateAttributes.Property> action) { | ||
properties.forEach(action); | ||
} | ||
|
||
public void clear() { | ||
properties.clear(); | ||
refresh(); | ||
} | ||
|
||
public void removeAttribute(Attribute attribute, WrapperPlayServerUpdateAttributes.PropertyModifier modifier) { | ||
this.properties.stream() | ||
.filter(property -> property.getAttribute() == attribute) | ||
.findFirst().ifPresent(property -> { | ||
property.getModifiers().remove(modifier); | ||
if (property.getModifiers().isEmpty()) { | ||
properties.remove(property); | ||
} | ||
}); | ||
refresh(); | ||
} | ||
|
||
public void removeAttribute(Attribute attribute) { | ||
this.properties.stream() | ||
.filter(property -> property.getAttribute() == attribute) | ||
.findFirst().ifPresent(properties::remove); | ||
refresh(); | ||
} | ||
|
||
|
||
public void refresh() { | ||
entity.sendPacketToViewers(createPacket()); | ||
} | ||
|
||
public WrapperPlayServerUpdateAttributes createPacket() { | ||
return new WrapperPlayServerUpdateAttributes(entity.getEntityId(), properties); | ||
} | ||
|
||
} |
Oops, something went wrong.