Added a regen energy values command. It will reload values from file, recalculate energy values, then send the new values to everyone on the server
This commit is contained in:
parent
a09dc48699
commit
71ed8e2508
|
@ -66,6 +66,7 @@ public class CommandEE extends CommandBase
|
|||
modCommands.add(new CommandSetEnergyValue());
|
||||
modCommands.add(new CommandSetEnergyValueCurrentItem());
|
||||
modCommands.add(new CommandSyncEnergyValues());
|
||||
modCommands.add(new CommandRegenEnergyValues());
|
||||
modCommands.add(new CommandPlayerLearnItem());
|
||||
modCommands.add(new CommandPlayerLearnCurrentItem());
|
||||
modCommands.add(new CommandPlayerForgetEverything());
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.handler.ConfigurationHandler;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSyncEnergyValues;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandRegenEnergyValues extends CommandBase {
|
||||
|
||||
private static Map<UUID, Long> requesterMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return Names.Commands.REGEN_ENERGY_VALUES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender commandSender) {
|
||||
return Messages.Commands.SYNC_ENERGY_VALUES_USAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender commandSender, String[] args) {
|
||||
|
||||
boolean shouldRegen = true;
|
||||
float coolDown = 0f;
|
||||
UUID commandSenderUUID = ((EntityPlayer) commandSender).getUniqueID();
|
||||
|
||||
if (requesterMap.containsKey(commandSenderUUID)) {
|
||||
|
||||
// TODO Switch to nanoTime from currentTimeMillis
|
||||
long timeDifference = System.currentTimeMillis() - requesterMap.get(commandSenderUUID).longValue();
|
||||
|
||||
if (timeDifference >= (ConfigurationHandler.Settings.serverSyncThreshold * 1000)) {
|
||||
requesterMap.remove(commandSenderUUID);
|
||||
}
|
||||
else {
|
||||
coolDown = (ConfigurationHandler.Settings.serverSyncThreshold * 1000) - timeDifference;
|
||||
shouldRegen = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
requesterMap.put(commandSenderUUID, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (shouldRegen) {
|
||||
LogHelper.info(EnergyValueRegistry.ENERGY_VALUE_MARKER, "Regenerating energy values at {}'s request", commandSender.getCommandSenderName());
|
||||
LogHelper.info(EnergyValueRegistry.ENERGY_VALUE_MARKER, "Reloading energy values from file");
|
||||
EnergyValueRegistry.INSTANCE.load();
|
||||
LogHelper.info(EnergyValueRegistry.ENERGY_VALUE_MARKER, "Recalculating energy values");
|
||||
EnergyValueRegistry.INSTANCE.compute();
|
||||
PacketHandler.INSTANCE.sendToAll(new MessageSyncEnergyValues());
|
||||
commandSender.addChatMessage(new ChatComponentTranslation(Messages.Commands.REGEN_ENERGY_VALUES_SUCCESS));
|
||||
}
|
||||
else {
|
||||
throw new WrongUsageException(Messages.Commands.REGEN_ENERGY_VALUES_DENIED, new Object[]{coolDown / 1000f});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.pahimar.ee3.command;
|
|||
|
||||
import com.pahimar.ee3.api.exchange.EnergyValue;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
|
@ -98,6 +99,7 @@ public class CommandSetEnergyValue extends CommandBase
|
|||
throw new WrongUsageException(Messages.Commands.SET_ENERGY_VALUE_USAGE);
|
||||
}
|
||||
|
||||
EnergyValueRegistry.INSTANCE.save();
|
||||
// Notify admins and log the value change
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ENERGY_VALUE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), args[1], itemStack.func_151000_E(), newEnergyValue.getChatComponent()});
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.pahimar.ee3.command;
|
|||
|
||||
import com.pahimar.ee3.api.exchange.EnergyValue;
|
||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
|
@ -78,6 +79,8 @@ public class CommandSetEnergyValueCurrentItem extends CommandBase
|
|||
{
|
||||
throw new WrongUsageException(Messages.Commands.SET_ENERGY_VALUE_CURRENT_ITEM_USAGE);
|
||||
}
|
||||
|
||||
EnergyValueRegistry.INSTANCE.save();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -20,59 +20,53 @@ import java.util.UUID;
|
|||
|
||||
public class CommandSyncEnergyValues extends CommandBase
|
||||
{
|
||||
private static Map<UUID, Long> requesterMap = new HashMap<UUID, Long>();
|
||||
private static Map<UUID, Long> requesterMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
public String getCommandName() {
|
||||
return Names.Commands.SYNC_ENERGY_VALUES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender commandSender)
|
||||
{
|
||||
public String getCommandUsage(ICommandSender commandSender) {
|
||||
return Messages.Commands.SYNC_ENERGY_VALUES_USAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender commandSender, String[] args)
|
||||
{
|
||||
public void processCommand(ICommandSender commandSender, String[] args) {
|
||||
|
||||
boolean shouldSync = true;
|
||||
float coolDown = 0f;
|
||||
UUID commandSenderUUID = ((EntityPlayer) commandSender).getUniqueID();
|
||||
|
||||
if (requesterMap.containsKey(commandSenderUUID))
|
||||
{
|
||||
if (requesterMap.containsKey(commandSenderUUID)) {
|
||||
|
||||
// TODO Switch to nanoTime from currentTimeMillis
|
||||
long timeDifference = System.currentTimeMillis() - requesterMap.get(commandSenderUUID).longValue();
|
||||
if (timeDifference >= (ConfigurationHandler.Settings.serverSyncThreshold * 1000))
|
||||
{
|
||||
|
||||
if (timeDifference >= (ConfigurationHandler.Settings.serverSyncThreshold * 1000)) {
|
||||
requesterMap.remove(commandSenderUUID);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
coolDown = (ConfigurationHandler.Settings.serverSyncThreshold * 1000) - timeDifference;
|
||||
shouldSync = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
requesterMap.put(commandSenderUUID, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (shouldSync)
|
||||
{
|
||||
if (shouldSync) {
|
||||
LogHelper.info(EnergyValueRegistry.ENERGY_VALUE_MARKER, "Syncing energy values with player '{}' at their request", commandSender.getCommandSenderName());
|
||||
PacketHandler.INSTANCE.sendTo(new MessageSyncEnergyValues(), (EntityPlayerMP) commandSender);
|
||||
commandSender.addChatMessage(new ChatComponentTranslation(Messages.Commands.SYNC_ENERGY_VALUES_SUCCESS));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
throw new WrongUsageException(Messages.Commands.SYNC_ENERGY_VALUES_DENIED, new Object[]{coolDown / 1000f});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,14 @@ public final class Messages {
|
|||
public static final String SET_ENERGY_VALUE_CURRENT_ITEM_USAGE = COMMAND_PREFIX + Names.Commands.SET_ENERGY_VALUE_CURRENT_ITEM + ".usage";
|
||||
public static final String SET_ENERGY_VALUE_CURRENT_ITEM_SUCCESS = COMMAND_PREFIX + Names.Commands.SET_ENERGY_VALUE_CURRENT_ITEM + ".success";
|
||||
|
||||
public static final String REGEN_ENERGY_VALUES_USAGE = COMMAND_PREFIX + Names.Commands.REGEN_ENERGY_VALUES + ".usage";
|
||||
public static final String REGEN_ENERGY_VALUES_SUCCESS = COMMAND_PREFIX + Names.Commands.REGEN_ENERGY_VALUES + ".success";
|
||||
public static final String REGEN_ENERGY_VALUES_DENIED = COMMAND_PREFIX + Names.Commands.REGEN_ENERGY_VALUES + ".denied";
|
||||
|
||||
public static final String SYNC_ENERGY_VALUES_USAGE = COMMAND_PREFIX + Names.Commands.SYNC_ENERGY_VALUES + ".usage";
|
||||
public static final String SYNC_ENERGY_VALUES_SUCCESS = COMMAND_PREFIX + Names.Commands.SYNC_ENERGY_VALUES + ".success";
|
||||
public static final String SYNC_ENERGY_VALUES_DENIED = COMMAND_PREFIX + Names.Commands.SYNC_ENERGY_VALUES + ".denied";
|
||||
|
||||
public static final String PLAYER_LEARN_EVERYTHING_USAGE = COMMAND_PREFIX + Names.Commands.PLAYER_LEARN_EVERYTHING + ".usage";
|
||||
public static final String PLAYER_LEARN_EVERYTHING_SUCCESS = COMMAND_PREFIX + Names.Commands.PLAYER_LEARN_EVERYTHING + ".success";
|
||||
|
||||
public static final String PLAYER_LEARN_ITEM_USAGE = COMMAND_PREFIX + Names.Commands.PLAYER_LEARN_ITEM + ".usage";
|
||||
public static final String PLAYER_LEARN_ITEM_SUCCESS = COMMAND_PREFIX + Names.Commands.PLAYER_LEARN_ITEM + ".success";
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ public class Names
|
|||
public static final String BASE_COMMAND = Reference.LOWERCASE_MOD_ID;
|
||||
public static final String SET_ENERGY_VALUE = "set-energy-value";
|
||||
public static final String SET_ENERGY_VALUE_CURRENT_ITEM = "set-energy-value-current-item";
|
||||
public static final String REGEN_ENERGY_VALUES = "regen-energy-values";
|
||||
public static final String SYNC_ENERGY_VALUES = "sync-energy-values";
|
||||
public static final String PLAYER_LEARN_EVERYTHING = "player-learn-everything";
|
||||
public static final String PLAYER_LEARN_ITEM = "player-learn-item";
|
||||
|
|
|
@ -139,6 +139,9 @@ commands.ee3.set-energy-value.usage=/ee3 set-energy-value <pre|global-pre|post|g
|
|||
commands.ee3.set-energy-value.success=%s set a %s EnergyValue of %s to %s
|
||||
commands.ee3.set-energy-value-current-item.usage=/ee3 set-energy-value-current-item <pre|global-pre|post|global-post> <value>
|
||||
commands.ee3.set-energy-value-current-item.success=%s set a %s EnergyValue of %s to %s
|
||||
commands.ee3.regen-energy-values.usage=/ee3 regen-energy-values
|
||||
commands.ee3.regen-energy-values.success=Successfully recalculated energy values
|
||||
commands.ee3.regen-energy-values.denied=Please wait %s more seconds and try again
|
||||
commands.ee3.sync-energy-values.usage=/ee3 sync-energy-values
|
||||
commands.ee3.sync-energy-values.success=Successfully synchronized energy values with the server
|
||||
commands.ee3.sync-energy-values.denied=Please wait %s more seconds and try again
|
||||
|
|
Loading…
Reference in a new issue