mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 11:04:25 +00:00
Profile Operations + Packets for GUI Handling
This commit is contained in:
1 parent
cd12397927
commit
d62b02410e
16 files changed
+542
-86
No files matched your search
@@ -23,6 +23,7 @@ public class CommandProfile extends CommandBase {
|
||||
public CommandProfile(){
|
||||
registerCommand(help);
|
||||
registerCommand(new CommandProfileChange());
|
||||
registerCommand(new CommandProfileCreate());
|
||||
registerCommand(new CommandProfileRemove());
|
||||
registerCommand(new CommandProfileAdmin());
|
||||
registerCommand(new CommandProfileList());
|
||||
@@ -116,7 +117,7 @@ public class CommandProfile extends CommandBase {
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel(){
|
||||
return 0;
|
||||
return 4;
|
||||
}
|
||||
|
||||
public static String getCommandPermission(String command){
|
||||
|
||||
@@ -105,6 +105,7 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
}
|
||||
}
|
||||
|
||||
// Existing change subcommand update:
|
||||
@SubCommand(
|
||||
desc = "Change a specified player's active slot.",
|
||||
usage = "<targetPlayer> <newSlotId>"
|
||||
@@ -144,6 +145,41 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
}
|
||||
}
|
||||
|
||||
// New admin create subcommand:
|
||||
@SubCommand(
|
||||
desc = "Create a new slot for a specified player's profile.",
|
||||
usage = "<targetPlayer>"
|
||||
)
|
||||
public void create(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length < 1) {
|
||||
sendError(sender, "Usage: /profile admin create <targetPlayer>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
Profile profile = ProfileController.getProfile(targetPlayer);
|
||||
if(profile == null) {
|
||||
sendError(sender, "Profile not found for player: " + targetPlayer);
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.createSlotInternal(profile);
|
||||
switch(result) {
|
||||
case NEW_SLOT_CREATED:
|
||||
sendResult(sender, "New slot created successfully for %s.", targetPlayer);
|
||||
break;
|
||||
case MAX_SLOTS:
|
||||
sendError(sender, "Player %s has reached maximum allowed slots.", targetPlayer);
|
||||
break;
|
||||
case LOCKED:
|
||||
sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer);
|
||||
break;
|
||||
case VERIFICATION_FAILED:
|
||||
sendError(sender, "Profile verification failed for %s.", targetPlayer);
|
||||
break;
|
||||
default:
|
||||
sendError(sender, "Error creating new slot for %s.", targetPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "List all slots (IDs and names) for a specified player's profile.",
|
||||
usage = "<targetPlayer>"
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.controllers.data.ProfileOperation;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class CommandProfileCreate extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "create";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Create a new profile slot.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean runSubCommands() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer)sender;
|
||||
Profile profile = ProfileController.getProfile(player);
|
||||
if(profile == null) {
|
||||
sendError(sender, "Profile not found.");
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.createSlotInternal(profile);
|
||||
switch(result) {
|
||||
case NEW_SLOT_CREATED:
|
||||
sendResult(sender, "New profile slot created successfully.");
|
||||
break;
|
||||
case MAX_SLOTS:
|
||||
sendError(sender, "You have reached the maximum allowed slots.");
|
||||
break;
|
||||
case LOCKED:
|
||||
sendError(sender, "Profile is locked. Please try again later.");
|
||||
break;
|
||||
case VERIFICATION_FAILED:
|
||||
sendError(sender, "Profile verification failed. Creation not permitted.");
|
||||
break;
|
||||
default:
|
||||
sendError(sender, "Error occurred while creating a new profile slot.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
package kamkeel.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.data.*;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
@@ -357,52 +359,78 @@ public class ProfileController {
|
||||
return ProfileOperation.SUCCESS;
|
||||
}
|
||||
|
||||
// Change the active slot in a Profile.
|
||||
// If the new slot doesn't exist, it is created and NEW_SLOT_CREATED is returned.
|
||||
// Saves current slot data before switching.
|
||||
private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) {
|
||||
if(profile.locked) {
|
||||
LogWriter.error("Profile is locked; cannot change slot.");
|
||||
public static ProfileOperation createSlotInternal(Profile profile) {
|
||||
if (profile.locked) {
|
||||
LogWriter.error("Profile is locked; cannot create slot.");
|
||||
return ProfileOperation.LOCKED;
|
||||
}
|
||||
// Disallow switching to the same active slot.
|
||||
if(profile.currentID == newSlotId) {
|
||||
LogWriter.error("Slot " + newSlotId + " is already active.");
|
||||
return ProfileOperation.ALREADY_ACTIVE;
|
||||
int newSlotId = 0;
|
||||
while (profile.slots.containsKey(newSlotId)) {
|
||||
newSlotId++;
|
||||
}
|
||||
|
||||
// Check if the player is allowed to create a new slot.
|
||||
if (!allowSlotPermission(profile.player)) {
|
||||
LogWriter.error("Player has reached maximum allowed slots.");
|
||||
return ProfileOperation.MAX_SLOTS;
|
||||
}
|
||||
// Run verification checks from all IProfileData in order of priority.
|
||||
if(profile.player != null) {
|
||||
if (profile.player != null) {
|
||||
List<IProfileData> dataList = new ArrayList<>(profileTypes.values());
|
||||
dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));
|
||||
for(IProfileData pd : dataList) {
|
||||
if(!pd.verifySwitch(profile.player)) {
|
||||
for (IProfileData pd : dataList) {
|
||||
if (!pd.verifySwitch(profile.player)) {
|
||||
LogWriter.error("Verification check failed for profile type: " + pd.getTagName());
|
||||
return ProfileOperation.VERIFICATION_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(profile.player != null) {
|
||||
// Create and add the new slot.
|
||||
Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId);
|
||||
newSlot.setCompound(new NBTTagCompound());
|
||||
profile.slots.put(newSlotId, newSlot);
|
||||
return ProfileOperation.NEW_SLOT_CREATED;
|
||||
}
|
||||
|
||||
// Change the active slot in a profile without automatically creating a new one.
|
||||
// If the target slot does not exist, the operation fails.
|
||||
private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) {
|
||||
if (profile.locked) {
|
||||
LogWriter.error("Profile is locked; cannot change slot.");
|
||||
return ProfileOperation.LOCKED;
|
||||
}
|
||||
if (profile.currentID == newSlotId) {
|
||||
LogWriter.error("Slot " + newSlotId + " is already active.");
|
||||
return ProfileOperation.ALREADY_ACTIVE;
|
||||
}
|
||||
if (!profile.slots.containsKey(newSlotId)) {
|
||||
LogWriter.error("Slot " + newSlotId + " does not exist.");
|
||||
return ProfileOperation.ERROR;
|
||||
}
|
||||
// Run verification checks on all IProfileData in priority order.
|
||||
if (profile.player != null) {
|
||||
List<IProfileData> dataList = new ArrayList<>(profileTypes.values());
|
||||
dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));
|
||||
for (IProfileData pd : dataList) {
|
||||
if (!pd.verifySwitch(profile.player)) {
|
||||
LogWriter.error("Verification check failed for profile type: " + pd.getTagName());
|
||||
return ProfileOperation.VERIFICATION_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (profile.player != null) {
|
||||
saveSlotData(profile.player);
|
||||
}
|
||||
boolean createdNewSlot = false;
|
||||
// If the new slot doesn't exist, create it.
|
||||
if(!profile.slots.containsKey(newSlotId)) {
|
||||
Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId);
|
||||
newSlot.setCompound(new NBTTagCompound());
|
||||
profile.slots.put(newSlotId, newSlot);
|
||||
createdNewSlot = true;
|
||||
}
|
||||
profile.currentID = newSlotId;
|
||||
if(profile.player != null) {
|
||||
if (profile.player != null) {
|
||||
loadSlotData(profile.player);
|
||||
}
|
||||
// Update PlayerData so that PlayerData.get(player).profileSlot matches Profile.currentID.
|
||||
if(profile.player != null) {
|
||||
if (profile.player != null) {
|
||||
PlayerData pdata = PlayerData.get(profile.player);
|
||||
pdata.profileSlot = newSlotId;
|
||||
pdata.save();
|
||||
}
|
||||
return createdNewSlot ? ProfileOperation.NEW_SLOT_CREATED : ProfileOperation.SUCCESS;
|
||||
return ProfileOperation.SUCCESS;
|
||||
}
|
||||
|
||||
// ---------- Public Operations (Overloaded for EntityPlayer, UUID, or username) ----------
|
||||
@@ -607,6 +635,51 @@ public class ProfileController {
|
||||
}
|
||||
|
||||
|
||||
public static boolean allowSlotPermission(EntityPlayer player) {
|
||||
Profile profile = ProfileController.getProfile(player);
|
||||
int currentSlots = profile.slots.size();
|
||||
|
||||
// Unlimited slots if the player has the wildcard permission.
|
||||
if (CustomNpcsPermissions.hasCustomPermission(player, "customnpcs.profile.max.*")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int highestAllowed = 0;
|
||||
for (int i = 1; i <= 50; i++) {
|
||||
String perm = "customnpcs.profile.max." + i;
|
||||
if (CustomNpcsPermissions.hasCustomPermission(player, perm)) {
|
||||
highestAllowed = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (highestAllowed == 0) {
|
||||
highestAllowed = 1;
|
||||
}
|
||||
|
||||
return currentSlots < highestAllowed;
|
||||
}
|
||||
|
||||
public void sendChatAlert(ProfileOperation operation, EntityPlayerMP player){
|
||||
switch (operation){
|
||||
case SUCCESS:
|
||||
ChatAlertPacket.sendChatAlert(player, "quest.newquest", ": ", "");
|
||||
break;
|
||||
case ERROR:
|
||||
break;
|
||||
case LOCKED:
|
||||
break;
|
||||
case PLAYER_NOT_FOUND:
|
||||
break;
|
||||
case NEW_SLOT_CREATED:
|
||||
break;
|
||||
case ALREADY_ACTIVE:
|
||||
break;
|
||||
case VERIFICATION_FAILED:
|
||||
break;
|
||||
case MAX_SLOTS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityPlayerMP getPlayer(String username){
|
||||
return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username);
|
||||
|
||||
@@ -7,6 +7,7 @@ public enum ProfileOperation {
|
||||
PLAYER_NOT_FOUND,
|
||||
NEW_SLOT_CREATED,
|
||||
ALREADY_ACTIVE,
|
||||
VERIFICATION_FAILED
|
||||
VERIFICATION_FAILED,
|
||||
MAX_SLOTS
|
||||
}
|
||||
|
||||
@@ -56,8 +56,7 @@ import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket;
|
||||
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.profile.ProfileGetInfoPacket;
|
||||
import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.profile.*;
|
||||
import kamkeel.npcs.network.packets.request.quest.*;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.recipe.RecipeRemovePacket;
|
||||
@@ -328,6 +327,10 @@ public class PacketHandler {
|
||||
// Profile Packets
|
||||
REQUEST_PACKET.registerPacket(new ProfileGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileGetInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileCreatePacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileRenamePacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileRenamePacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileChangePacket());
|
||||
|
||||
// Other Packets
|
||||
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
|
||||
|
||||
@@ -185,5 +185,6 @@ public enum EnumRequestPacket {
|
||||
EffectSave,
|
||||
|
||||
ColorSet,
|
||||
ProfileGet, ProfileGetAll, ProfileGetInfo, ColorBrush
|
||||
ColorBrush,
|
||||
ProfileGet, ProfileGetAll, ProfileGetInfo, ProfileCreate, ProfileRemove, ProfileRename, ProfileChange,
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package kamkeel.npcs.network.packets.request.profile;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.ProfileOperation;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ProfileChangePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileChange";
|
||||
|
||||
private int slotID;
|
||||
|
||||
public ProfileChangePacket() {}
|
||||
|
||||
public ProfileChangePacket(int slotID) {
|
||||
this.slotID = slotID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ProfileChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.PROFILE_CHANGE;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.slotID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
int slot = in.readInt();
|
||||
ProfileOperation operation = ProfileController.changeSlot(player, slot);
|
||||
// TODO: Check Operation and Send Message
|
||||
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package kamkeel.npcs.network.packets.request.profile;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.controllers.data.ProfileOperation;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ProfileCreatePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileCreate";
|
||||
|
||||
public ProfileCreatePacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ProfileCreate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.PROFILE_CREATE;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
Profile profile = ProfileController.getProfile(player);
|
||||
ProfileOperation operation = ProfileController.createSlotInternal(profile);
|
||||
// TODO: Check Operation and Send Message
|
||||
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -22,7 +22,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class ProfileGetInfoPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileGetInfo";
|
||||
@@ -48,6 +47,10 @@ public final class ProfileGetInfoPacket extends AbstractPacket {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
sendProfileInfo(player);
|
||||
}
|
||||
|
||||
public static void sendProfileInfo(EntityPlayer player){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("PROFILE_INFO", true);
|
||||
NBTTagList slotList = new NBTTagList();
|
||||
@@ -69,7 +72,7 @@ public final class ProfileGetInfoPacket extends AbstractPacket {
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
|
||||
public static HashMap<Integer, List<InfoEntry>> readSlotsFromNBT(NBTTagCompound compound) {
|
||||
public static HashMap<Integer, List<InfoEntry>> readProfileInfo(NBTTagCompound compound) {
|
||||
HashMap<Integer, List<InfoEntry>> slotInfoMap = new HashMap<>();
|
||||
|
||||
if (!compound.getBoolean("PROFILE_INFO")) return slotInfoMap;
|
||||
|
||||
@@ -43,6 +43,10 @@ public final class ProfileGetPacket extends AbstractPacket {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
sendProfileNBT(player);
|
||||
}
|
||||
|
||||
public static void sendProfileNBT(EntityPlayer player){
|
||||
Profile profile = ProfileController.getProfile(player);
|
||||
NBTTagCompound compound = profile.writeToNBT();
|
||||
compound.setBoolean("PROFILE", true);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package kamkeel.npcs.network.packets.request.profile;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.controllers.data.ProfileOperation;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ProfileRemovePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileRemove";
|
||||
|
||||
private int slotID;
|
||||
|
||||
public ProfileRemovePacket() {}
|
||||
|
||||
public ProfileRemovePacket(int slotID) {
|
||||
this.slotID = slotID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ProfileRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.PROFILE_DELETE;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.slotID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
int slot = in.readInt();
|
||||
ProfileOperation operation = ProfileController.removeSlot(player, slot);
|
||||
// TODO: Check Operation and Send Message
|
||||
|
||||
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package kamkeel.npcs.network.packets.request.profile;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.controllers.data.ProfileOperation;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
|
||||
public final class ProfileRenamePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileRename";
|
||||
|
||||
private int slotID;
|
||||
private String name;
|
||||
|
||||
public ProfileRenamePacket() {}
|
||||
|
||||
public ProfileRenamePacket(int slotID, String name) {
|
||||
this.slotID = slotID;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ProfileRename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.PROFILE_RENAME;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.slotID);
|
||||
ByteBufUtils.writeString(out, this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
int slot = in.readInt();
|
||||
String newName = ByteBufUtils.readString(in);
|
||||
|
||||
Profile profile = ProfileController.getProfile(player);
|
||||
if(!profile.slots.containsKey(slot)) {
|
||||
// TODO: Check Operation and Send Message
|
||||
return;
|
||||
}
|
||||
|
||||
ProfileController.getProfile(player).slots.get(slot).setName(newName);
|
||||
ProfileController.save(player, ProfileController.getProfile(player));
|
||||
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user