use spaces

This commit is contained in:
Gerrygames 2019-05-09 15:07:20 +02:00
parent 44183f19cd
commit 2442520ef3
3 changed files with 56 additions and 56 deletions

View File

@ -2,8 +2,8 @@ package us.myles.ViaVersion.api.entities;
public interface IEntityType { public interface IEntityType {
int getId(); int getId();
IEntityType getParent(); IEntityType getParent();
} }

View File

@ -14,37 +14,37 @@ import java.util.logging.Logger;
public abstract class MetadataRewriter<T extends IEntityType> { public abstract class MetadataRewriter<T extends IEntityType> {
public final void handleMetadata(int entityId, T type, List<Metadata> metadatas, UserConnection connection) { public final void handleMetadata(int entityId, T type, List<Metadata> metadatas, UserConnection connection) {
Map<Integer, Metadata> metadataMap = new HashMap<>(metadatas.size()); Map<Integer, Metadata> metadataMap = new HashMap<>(metadatas.size());
for (Metadata metadata : metadatas) { for (Metadata metadata : metadatas) {
metadataMap.put(metadata.getId(), metadata); metadataMap.put(metadata.getId(), metadata);
} }
metadataMap = Collections.unmodifiableMap(metadataMap); metadataMap = Collections.unmodifiableMap(metadataMap);
for (Metadata metadata : new ArrayList<>(metadatas)) { for (Metadata metadata : new ArrayList<>(metadatas)) {
int oldId = metadata.getId(); int oldId = metadata.getId();
try { try {
handleMetadata(entityId, type, metadata, metadatas, metadataMap, connection); handleMetadata(entityId, type, metadata, metadatas, metadataMap, connection);
} catch (Exception e) { } catch (Exception e) {
metadatas.remove(metadata); metadatas.remove(metadata);
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
Logger logger = Via.getPlatform().getLogger(); Logger logger = Via.getPlatform().getLogger();
logger.warning("An error occurred with entity metadata handler"); logger.warning("An error occurred with entity metadata handler");
logger.warning("This is most likely down to one of your plugins sending bad datawatchers. Please test if this occurs without any plugins except ViaVersion before reporting it on GitHub"); logger.warning("This is most likely down to one of your plugins sending bad datawatchers. Please test if this occurs without any plugins except ViaVersion before reporting it on GitHub");
logger.warning("Also make sure that all your plugins are compatible with your server version."); logger.warning("Also make sure that all your plugins are compatible with your server version.");
logger.warning("Entity type: " + type); logger.warning("Entity type: " + type);
logger.warning("Metadata: " + metadata); logger.warning("Metadata: " + metadata);
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {} protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {}
protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception { protected void handleMetadata(int entityId, T type, Metadata metadata, List<Metadata> metadatas, Map<Integer, Metadata> metadataMap, UserConnection connection) throws Exception {
handleMetadata(entityId, type, metadata, metadatas, connection); handleMetadata(entityId, type, metadata, metadatas, connection);
} }
} }

View File

@ -12,36 +12,36 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public abstract class EntityTracker<T extends IEntityType> extends StoredObject implements ExternalJoinGameListener { public abstract class EntityTracker<T extends IEntityType> extends StoredObject implements ExternalJoinGameListener {
private final Map<Integer, T> clientEntityTypes = new ConcurrentHashMap<>(); private final Map<Integer, T> clientEntityTypes = new ConcurrentHashMap<>();
@Getter @Getter
@Setter @Setter
private int clientEntityId; private int clientEntityId;
private final T playerType; private final T playerType;
protected EntityTracker(UserConnection user, T playerType) { protected EntityTracker(UserConnection user, T playerType) {
super(user); super(user);
this.playerType = playerType; this.playerType = playerType;
} }
public void removeEntity(int entityId) { public void removeEntity(int entityId) {
clientEntityTypes.remove(entityId); clientEntityTypes.remove(entityId);
} }
public void addEntity(int entityId, T type) { public void addEntity(int entityId, T type) {
clientEntityTypes.put(entityId, type); clientEntityTypes.put(entityId, type);
} }
public boolean hasEntity(int entityId) { public boolean hasEntity(int entityId) {
return clientEntityTypes.containsKey(entityId); return clientEntityTypes.containsKey(entityId);
} }
public Optional<T> getEntity(int entityId) { public Optional<T> getEntity(int entityId) {
return Optional.fromNullable(clientEntityTypes.get(entityId)); return Optional.fromNullable(clientEntityTypes.get(entityId));
} }
@Override @Override
public void onExternalJoinGame(int playerEntityId) { public void onExternalJoinGame(int playerEntityId) {
clientEntityId = playerEntityId; clientEntityId = playerEntityId;
clientEntityTypes.put(playerEntityId, playerType); clientEntityTypes.put(playerEntityId, playerType);
} }
} }