use of com.minecolonies.coremod.network.messages.client.SyncPathMessage in project minecolonies by ldtteam.
the class CommandEntityTrack method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
if (!(sender instanceof PlayerEntity)) {
return 1;
}
try {
final Collection<? extends Entity> entities = EntityArgument.getEntities(context, "entity");
if (entities.isEmpty()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.noentityfound"), true);
return 0;
}
final Entity entity = entities.iterator().next();
if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entity.getUUID())) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.disable"), true);
AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
} else {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.enable"), true);
AbstractPathJob.trackingMap.put((PlayerEntity) sender, entity.getUUID());
}
return 1;
} catch (CommandSyntaxException e) {
Log.getLogger().error("Error attemting to track entity", e);
}
return 0;
}
use of com.minecolonies.coremod.network.messages.client.SyncPathMessage in project minecolonies by Minecolonies.
the class CommandCitizenTrack method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
if (!(sender instanceof PlayerEntity)) {
return 1;
}
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND, colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_FOUND), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_LOADED), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_DISABLED), true);
AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
} else {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_ENABLED), true);
AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
}
return 1;
}
use of com.minecolonies.coremod.network.messages.client.SyncPathMessage in project minecolonies by Minecolonies.
the class CommandEntityTrack method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
if (!(sender instanceof PlayerEntity)) {
return 1;
}
try {
final Collection<? extends Entity> entities = EntityArgument.getEntities(context, "entity");
if (entities.isEmpty()) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_NOT_FOUND), true);
return 0;
}
final Entity entity = entities.iterator().next();
if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entity.getUUID())) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_DISABLED), true);
AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
} else {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_ENABLED), true);
AbstractPathJob.trackingMap.put((PlayerEntity) sender, entity.getUUID());
}
return 1;
} catch (CommandSyntaxException e) {
Log.getLogger().error("Error attemting to track entity", e);
}
return 0;
}
use of com.minecolonies.coremod.network.messages.client.SyncPathMessage in project minecolonies by ldtteam.
the class CommandCitizenTrack method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
if (!(sender instanceof PlayerEntity)) {
return 1;
}
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.disable"), true);
AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
} else {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.enable"), true);
AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
}
return 1;
}
Aggregations