mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 20:44:08 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
e585f11bb2
305 files changed
+7832
-3047
No files matched your search
@@ -2,7 +2,6 @@ package kamkeel.npcs.addon.client;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.client.gui.mainmenu.GuiNpcStats;
|
||||
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface2;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -34,7 +33,4 @@ public class DBCClient {
|
||||
public GuiNPCInterface2 manageCustomForms(EntityNPCInterface npcInterface){ return null; }
|
||||
// Manage Custom Forms
|
||||
public GuiNPCInterface2 manageCustomAuras(EntityNPCInterface npcInterface){ return null; }
|
||||
|
||||
// Inventory GUI
|
||||
public GuiCNPCInventory inventoryGUI(){ return null; }
|
||||
}
|
||||
@@ -9,6 +9,9 @@ import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class AnimationCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.*;
|
||||
|
||||
public class CloneCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,6 +10,9 @@ import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class CommandCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,7 @@ public class CommandKamkeel extends CommandBase{
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "kamkeel/npcs";
|
||||
return "kamkeel";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -55,18 +54,6 @@ public abstract class CommandKamkeelBase extends CommandBase{
|
||||
return !subcommands.isEmpty();
|
||||
}
|
||||
|
||||
protected static void sendMessage(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation(message, obs));
|
||||
}
|
||||
|
||||
protected static void sendResult(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A77 " + message, obs));
|
||||
}
|
||||
|
||||
protected static void sendError(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A74 Error:\u00A7c " + message, obs));
|
||||
}
|
||||
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SubCommand {
|
||||
|
||||
@@ -20,6 +20,9 @@ import noppes.npcs.controllers.PlayerDataController;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class ConfigCommand extends CommandKamkeelBase {
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ import noppes.npcs.controllers.data.PlayerData;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class DialogCategoryCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,9 @@ import noppes.npcs.entity.EntityDialogNpc;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class DialogCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,8 +2,8 @@ package kamkeel.npcs.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.scripted.event.PlayerEvent.EffectEvent.ExpirationType;
|
||||
@@ -13,6 +13,9 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class EffectCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
@@ -26,7 +29,7 @@ public class EffectCommand extends CommandKamkeelBase {
|
||||
}
|
||||
|
||||
@SubCommand(desc = "Lists all Effects")
|
||||
public void infoAll(ICommandSender sender, String[] args) throws CommandException {
|
||||
public void list(ICommandSender sender, String[] args) throws CommandException {
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
if (controller.indexMapper.isEmpty()) {
|
||||
sendError(sender, "No effects found.");
|
||||
|
||||
@@ -11,6 +11,9 @@ import noppes.npcs.controllers.data.PlayerFactionData;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class FactionCommand extends CommandKamkeelBase {
|
||||
|
||||
public Faction selectedFaction;
|
||||
|
||||
@@ -7,6 +7,9 @@ import net.minecraft.util.ChatComponentTranslation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class HelpCommand extends CommandKamkeelBase{
|
||||
private CommandKamkeel parent;
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class NpcCommand extends CommandKamkeelBase {
|
||||
|
||||
public EntityNPCInterface selectedNpc;
|
||||
|
||||
@@ -9,6 +9,9 @@ import noppes.npcs.controllers.data.SkinOverlay;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class OverlayCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumProfileSync;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.PlayerQuestController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
@@ -16,6 +20,9 @@ import noppes.npcs.controllers.data.QuestData;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
@@ -82,15 +89,20 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
|
||||
int count = 0;
|
||||
for(PlayerData playerdata : data){
|
||||
count = 0;
|
||||
for(Quest quest : questCategory.quests.values()){
|
||||
if(playerdata.questData.activeQuests.containsKey(quest.id)){
|
||||
playerdata.questData.activeQuests.remove(quest.id);
|
||||
playerdata.questData.activeQuests.remove(quest.id);
|
||||
long completeTime;
|
||||
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM){
|
||||
completeTime = System.currentTimeMillis();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
} else {
|
||||
completeTime = sender.getEntityWorld().getTotalWorldTime();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
|
||||
playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis());
|
||||
else
|
||||
playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime());
|
||||
if(ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime);;
|
||||
|
||||
if(playerdata.player != null){
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.completed", quest.title);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
@@ -8,6 +9,8 @@ import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.api.handler.data.IQuestObjective;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumProfileSync;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
@@ -21,6 +24,9 @@ import noppes.npcs.util.ValueUtil;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class QuestCommand extends CommandKamkeelBase {
|
||||
|
||||
@Override
|
||||
@@ -100,14 +106,18 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
return;
|
||||
}
|
||||
for(PlayerData playerdata : data){
|
||||
if(playerdata.questData.activeQuests.containsKey(questid)){
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
playerdata.questData.activeQuests.remove(questid);
|
||||
long completeTime;
|
||||
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM){
|
||||
completeTime = System.currentTimeMillis();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
} else {
|
||||
completeTime = sender.getEntityWorld().getTotalWorldTime();
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
|
||||
playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis());
|
||||
else
|
||||
playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime());
|
||||
if(ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime);
|
||||
|
||||
playerdata.save();
|
||||
if(playerdata.player != null){
|
||||
|
||||
@@ -3,6 +3,9 @@ package kamkeel.npcs.command;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
|
||||
public class ScriptCommand extends CommandKamkeelBase {
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendResult;
|
||||
|
||||
public class SlayCommand extends CommandKamkeelBase {
|
||||
public Map<String, Class<?>> SlayMap = new LinkedHashMap<String, Class<?>>();
|
||||
|
||||
|
||||
@@ -2,69 +2,92 @@ package kamkeel.npcs.command.profile;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class CommandHelpProfile extends CommandProfileBase {
|
||||
private CommandProfile parent;
|
||||
private CommandProfile parent;
|
||||
|
||||
public CommandHelpProfile(CommandProfile parent){
|
||||
this.parent = parent;
|
||||
}
|
||||
public CommandHelpProfile(CommandProfile parent){
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "help";
|
||||
}
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "help [command]";
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "help [command]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length == 0){
|
||||
sendMessage(sender, "\u00A78------ \u00A7aProfile Commands \u00A78------");
|
||||
for(Entry<String, CommandProfileBase> entry : parent.map.entrySet()){
|
||||
sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getCommandUsage(sender));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length == 0){
|
||||
sendMessage(sender, "\u00A78------ \u00A7aProfile Commands \u00A78------");
|
||||
for(Entry<String, CommandProfileBase> entry : parent.map.entrySet()){
|
||||
sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77"
|
||||
+ entry.getValue().getCommandUsage(sender));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CommandProfileBase command = parent.getCommand(args);
|
||||
if(command == null){
|
||||
sendError(sender, "Unknown command " + args[0]);
|
||||
return;
|
||||
}
|
||||
if(command == null){
|
||||
sendError(sender, "Unknown command " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if(command.subcommands.isEmpty()){
|
||||
sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender)));
|
||||
return;
|
||||
}
|
||||
if(command.subcommands.isEmpty()){
|
||||
sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender)));
|
||||
return;
|
||||
}
|
||||
|
||||
Method m = null;
|
||||
if(args.length > 1){
|
||||
m = command.subcommands.get(args[1].toLowerCase());
|
||||
}
|
||||
if(m == null){
|
||||
sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase() + " SubCommands \u00A78------");
|
||||
sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage());
|
||||
for(Entry<String, Method> entry : command.subcommands.entrySet()){
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getAnnotation(SubCommand.class).desc()));
|
||||
}
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + CommandProfile.getCommandPermission(command.getCommandName())));
|
||||
}
|
||||
else{
|
||||
sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + "." + args[1].toUpperCase() + " Command \u00A78------");
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc()));
|
||||
if(!sc.usage().isEmpty())
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage()));
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1])));
|
||||
}
|
||||
}
|
||||
Method m = null;
|
||||
if(args.length > 1){
|
||||
m = command.subcommands.get(args[1].toLowerCase());
|
||||
}
|
||||
if(m == null){
|
||||
sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase()
|
||||
+ " SubCommands \u00A78------");
|
||||
sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage());
|
||||
for(Entry<String, Method> entry : command.subcommands.entrySet()){
|
||||
SubCommand sc = entry.getValue().getAnnotation(SubCommand.class);
|
||||
// For players, only list subcommands if they have permission; for console, show all.
|
||||
if(!(sender instanceof EntityPlayer) || command.canSendCommand(sender, sc, entry.getKey())){
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77> "
|
||||
+ "\u00A7e" + entry.getKey()
|
||||
+ "\u00A78: \u00A77" + sc.desc()));
|
||||
}
|
||||
}
|
||||
// Show permission node only if sender is console or has permission.
|
||||
if(!(sender instanceof EntityPlayer) ||
|
||||
CustomNpcsPermissions.hasPermission((EntityPlayer)sender, CustomNpcsPermissions.PROFILE_ADMIN)){
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 "
|
||||
+ CommandProfile.getCommandPermission(command.getCommandName())));
|
||||
}
|
||||
}
|
||||
else{
|
||||
sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase()
|
||||
+ "." + args[1].toUpperCase() + " Command \u00A78------");
|
||||
SubCommand sc = m.getAnnotation(SubCommand.class);
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc()));
|
||||
if(!sc.usage().isEmpty()){
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage()));
|
||||
}
|
||||
if(!(sender instanceof EntityPlayer) ||
|
||||
CustomNpcsPermissions.hasPermission((EntityPlayer)sender, CustomNpcsPermissions.PROFILE_ADMIN)){
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 "
|
||||
+ getSubCommandPermission(args[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,10 @@ public class CommandProfile extends CommandBase {
|
||||
public CommandProfile(){
|
||||
registerCommand(help);
|
||||
registerCommand(new CommandProfileChange());
|
||||
registerCommand(new CommandProfileCreate());
|
||||
registerCommand(new CommandProfileRemove());
|
||||
registerCommand(new CommandProfileAdmin());
|
||||
registerCommand(new CommandProfileRegion());
|
||||
registerCommand(new CommandProfileList());
|
||||
registerCommand(new CommandProfileRename());
|
||||
}
|
||||
@@ -99,7 +101,8 @@ public class CommandProfile extends CommandBase {
|
||||
if(args.length <= useArgs.length + 2) {
|
||||
if(args.length - 3 >= 0){
|
||||
String usage = useArgs[args.length - 3];
|
||||
if(usage.equals("<player>") || usage.equals("[player]")) {
|
||||
if(usage.equals("<player>") || usage.equals("[player]") || usage.equals("<targetPlayer>")
|
||||
|| usage.equals("<sourcePlayer>") || usage.equals("<destinationPlayer>")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
}
|
||||
@@ -115,7 +118,7 @@ public class CommandProfile extends CommandBase {
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel(){
|
||||
return 0;
|
||||
return 4;
|
||||
}
|
||||
|
||||
public static String getCommandPermission(String command){
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.EnumProfileOperation;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.controllers.data.ProfileOperation;
|
||||
import kamkeel.npcs.controllers.data.Slot;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.LogWriter;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.*;
|
||||
|
||||
public class CommandProfileAdmin extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
@@ -21,7 +23,7 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Admin profile management: clone, remove, change, and list a player's slots.";
|
||||
return "Admin profile management: clone, remove, change, list, rename, and rollback profiles.";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,7 +36,7 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
usage = "<sourcePlayer> <destinationPlayer> <sourceSlot> <destinationSlot> [temp]"
|
||||
)
|
||||
public void clone(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 4) {
|
||||
if(args.length < 4) {
|
||||
sendError(sender, "Usage: /profile admin clone <sourcePlayer> <destinationPlayer> <sourceSlot> <destinationSlot> [temp]");
|
||||
return;
|
||||
}
|
||||
@@ -45,55 +47,20 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
sourceSlot = Integer.parseInt(args[2]);
|
||||
destinationSlot = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException ex) {
|
||||
sendError(sender, "Source and destination slot IDs must be numbers.");
|
||||
sendError(sender, "Slot IDs must be numbers.");
|
||||
return;
|
||||
}
|
||||
boolean temporary = (args.length >= 5 && args[4].equalsIgnoreCase("temp"));
|
||||
|
||||
Profile sourceProfile = ProfileController.getProfile(sourcePlayer);
|
||||
if (sourceProfile == null) {
|
||||
sendError(sender, "Source profile not found for player: " + sourcePlayer);
|
||||
return;
|
||||
}
|
||||
Profile destProfile = ProfileController.getProfile(destinationPlayer);
|
||||
if (destProfile == null) {
|
||||
sendError(sender, "Destination profile not found for player: " + destinationPlayer);
|
||||
return;
|
||||
}
|
||||
if (destProfile.locked) {
|
||||
sendError(sender, "Destination profile is locked. Please try again later.");
|
||||
return;
|
||||
}
|
||||
if (!sourceProfile.slots.containsKey(sourceSlot)) {
|
||||
sendError(sender, "Source slot " + sourceSlot + " does not exist for player: " + sourcePlayer);
|
||||
return;
|
||||
}
|
||||
if (destinationSlot == destProfile.currentID) {
|
||||
sendError(sender, "Cannot clone into the destination's active slot.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Slot sourceSlotObj = sourceProfile.slots.get(sourceSlot);
|
||||
if (sourceSlotObj == null) {
|
||||
sendError(sender, "Source slot is invalid.");
|
||||
return;
|
||||
}
|
||||
NBTTagCompound clonedData = (NBTTagCompound) sourceSlotObj.getCompound().copy();
|
||||
Slot clonedSlot = new Slot(destinationSlot, "Admin Cloned Slot " + destinationSlot, clonedData, System.currentTimeMillis(), temporary);
|
||||
destProfile.slots.put(destinationSlot, clonedSlot);
|
||||
|
||||
if (destProfile.player != null) {
|
||||
ProfileController.save(destProfile.player, destProfile);
|
||||
} else {
|
||||
UUID destUUID = ProfileController.getUUIDFromUsername(destinationPlayer);
|
||||
if (destUUID != null)
|
||||
ProfileController.saveOffline(destProfile, destUUID);
|
||||
}
|
||||
sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s%s.",
|
||||
sourceSlot, sourcePlayer, destinationSlot, destinationPlayer, (temporary ? " (temporary)" : ""));
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error cloning slot", e);
|
||||
sendError(sender, "An error occurred while cloning slot.");
|
||||
ProfileOperation result = ProfileController.Instance.cloneSlot(sourcePlayer, sourceSlot, destinationSlot, temporary);
|
||||
if(result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer);
|
||||
} else if(result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
// Detail message for admins – note: using result.getMessage() for further details.
|
||||
sendError(sender, "Clone failed for %s: Profile is locked. Details: %s", sourcePlayer, result.getMessage());
|
||||
} else if(result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error cloning slot for %s: %s", sourcePlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error cloning slot: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +69,7 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
usage = "<targetPlayer> <slotId>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
if(args.length < 2) {
|
||||
sendError(sender, "Usage: /profile admin remove <targetPlayer> <slotId>");
|
||||
return;
|
||||
}
|
||||
@@ -110,29 +77,19 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch(NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
Profile targetProfile = ProfileController.getProfile(targetPlayer);
|
||||
if (targetProfile == null) {
|
||||
sendError(sender, "Profile not found for player: " + targetPlayer);
|
||||
return;
|
||||
}
|
||||
if (targetProfile.locked) {
|
||||
sendError(sender, "Profile for " + targetPlayer + " is locked. Please try again later.");
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.removeSlot(targetPlayer, slotId);
|
||||
switch (result) {
|
||||
case SUCCESS:
|
||||
sendResult(sender, "Successfully removed slot %d from %s.", slotId, targetPlayer);
|
||||
break;
|
||||
case LOCKED:
|
||||
sendError(sender, "Profile for " + targetPlayer + " is locked.");
|
||||
break;
|
||||
default:
|
||||
sendError(sender, "Error removing slot %d from %s.", slotId, targetPlayer);
|
||||
ProfileOperation result = ProfileController.Instance.removeSlot(targetPlayer, slotId);
|
||||
if(result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully removed slot %d from %s.", slotId, targetPlayer);
|
||||
} else if(result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Remove failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage());
|
||||
} else if(result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error removing slot %d from %s: %s", slotId, targetPlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error during removal: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +98,7 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
usage = "<targetPlayer> <newSlotId>"
|
||||
)
|
||||
public void change(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 2) {
|
||||
if(args.length < 2) {
|
||||
sendError(sender, "Usage: /profile admin change <targetPlayer> <newSlotId>");
|
||||
return;
|
||||
}
|
||||
@@ -149,29 +106,46 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
int newSlotId;
|
||||
try {
|
||||
newSlotId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch(NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
Profile targetProfile = ProfileController.getProfile(targetPlayer);
|
||||
if (targetProfile == null) {
|
||||
sendError(sender, "Profile not found for player: " + targetPlayer);
|
||||
ProfileOperation result = ProfileController.Instance.changeSlot(targetPlayer, newSlotId);
|
||||
if(result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully changed %s's active slot to %d.", targetPlayer, newSlotId);
|
||||
} else if(result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Change failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage());
|
||||
} else if(result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error changing active slot for %s: %s", targetPlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error during change: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
if (targetProfile.locked) {
|
||||
sendError(sender, "Profile for " + targetPlayer + " is locked. Please try again later.");
|
||||
String targetPlayer = args[0];
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if(profile == null) {
|
||||
sendError(sender, "Profile not found for player: %s", targetPlayer);
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.changeSlot(targetPlayer, newSlotId);
|
||||
switch (result) {
|
||||
case SUCCESS:
|
||||
sendResult(sender, "Successfully changed %s's active slot to %d.", targetPlayer, newSlotId);
|
||||
break;
|
||||
case LOCKED:
|
||||
sendError(sender, "Profile for " + targetPlayer + " is locked.");
|
||||
break;
|
||||
default:
|
||||
sendError(sender, "Error changing active slot for " + targetPlayer);
|
||||
ProfileOperation result = ProfileController.Instance.createSlotInternal(profile);
|
||||
if(result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "New slot created successfully for %s.", targetPlayer);
|
||||
} else if(result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Create failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage());
|
||||
} else if(result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error creating new slot for %s: %s", targetPlayer, result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error during slot creation: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,21 +154,21 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
usage = "<targetPlayer>"
|
||||
)
|
||||
public void list(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 1) {
|
||||
if(args.length < 1) {
|
||||
sendError(sender, "Usage: /profile admin list <targetPlayer>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
Profile targetProfile = ProfileController.getProfile(targetPlayer);
|
||||
if (targetProfile == null) {
|
||||
sendError(sender, "Profile not found for player: " + targetPlayer);
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if(profile == null) {
|
||||
sendError(sender, "Profile not found for player: %s", targetPlayer);
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "Profile Slots for " + targetPlayer + ":");
|
||||
for (Map.Entry<Integer, Slot> entry : targetProfile.slots.entrySet()) {
|
||||
sendMessage(sender, "Profile Slots for %s:", targetPlayer);
|
||||
for(Map.Entry<Integer, ISlot> entry : profile.getSlots().entrySet()) {
|
||||
int id = entry.getKey();
|
||||
String name = entry.getValue().getName();
|
||||
String prefix = (id == targetProfile.currentID) ? "* " : "- ";
|
||||
String prefix = (id == profile.currentSlotId) ? "* " : "- ";
|
||||
sendMessage(sender, prefix + "Slot " + id + ": " + name);
|
||||
}
|
||||
}
|
||||
@@ -204,7 +178,7 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
usage = "<targetPlayer> <slotId> <newName>"
|
||||
)
|
||||
public void rename(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length < 3) {
|
||||
if(args.length < 3) {
|
||||
sendError(sender, "Usage: /profile admin rename <targetPlayer> <slotId> <newName>");
|
||||
return;
|
||||
}
|
||||
@@ -212,50 +186,74 @@ public class CommandProfileAdmin extends CommandProfileBase {
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch(NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
// Combine remaining arguments for the new name.
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if (i > 2) sb.append(" ");
|
||||
for(int i = 2; i < args.length; i++){
|
||||
if(i > 2) sb.append(" ");
|
||||
sb.append(args[i]);
|
||||
}
|
||||
String newName = sb.toString().trim();
|
||||
// Cap name at 20 characters.
|
||||
if (newName.length() > 20) {
|
||||
if(newName.length() > 20) {
|
||||
newName = newName.substring(0, 20);
|
||||
}
|
||||
// Validate that name contains only letters and spaces.
|
||||
if (!newName.matches("[A-Za-z ]+")) {
|
||||
if(!newName.matches("[A-Za-z ]+")){
|
||||
sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed.");
|
||||
return;
|
||||
}
|
||||
Profile targetProfile = ProfileController.getProfile(targetPlayer);
|
||||
if (targetProfile == null) {
|
||||
sendError(sender, "Profile not found for player: " + targetPlayer);
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if(profile == null) {
|
||||
sendError(sender, "Profile not found for player: %s", targetPlayer);
|
||||
return;
|
||||
}
|
||||
if (targetProfile.locked) {
|
||||
sendError(sender, "Profile for " + targetPlayer + " is locked. Please try again later.");
|
||||
if(profile.isLocked()) {
|
||||
sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer);
|
||||
return;
|
||||
}
|
||||
if (!targetProfile.slots.containsKey(slotId)) {
|
||||
sendError(sender, "Slot " + slotId + " not found in " + targetPlayer + "'s profile.");
|
||||
if(!profile.getSlots().containsKey(slotId)) {
|
||||
sendError(sender, "Slot %d not found in %s's profile.", slotId, targetPlayer);
|
||||
return;
|
||||
}
|
||||
// Rename the slot.
|
||||
Slot targetSlot = targetProfile.slots.get(slotId);
|
||||
targetSlot.setName(newName);
|
||||
// Save the updated profile.
|
||||
if (targetProfile.player != null) {
|
||||
ProfileController.save(targetProfile.player, targetProfile);
|
||||
profile.getSlots().get(slotId).setName(newName);
|
||||
if(profile.getPlayer() != null) {
|
||||
ProfileController.Instance.save(profile.player, profile);
|
||||
} else {
|
||||
UUID uuid = ProfileController.getUUIDFromUsername(targetPlayer);
|
||||
if (uuid != null)
|
||||
ProfileController.saveOffline(targetProfile, uuid);
|
||||
UUID uuid = ProfileController.Instance.getUUIDFromUsername(targetPlayer);
|
||||
if(uuid != null)
|
||||
ProfileController.Instance.saveOffline(profile, uuid);
|
||||
}
|
||||
sendResult(sender, "Successfully renamed slot %d for %s to '%s'.", slotId, targetPlayer, newName);
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Rollback a player's profile to one of their backups.",
|
||||
usage = "<targetPlayer> <backupFileName>"
|
||||
)
|
||||
public void rollback(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length < 2) {
|
||||
sendError(sender, "Usage: /profile admin rollback <targetPlayer> <backupFileName>");
|
||||
return;
|
||||
}
|
||||
String targetPlayer = args[0];
|
||||
String backupFileName = args[1] + ".dat";
|
||||
|
||||
Profile profile = ProfileController.Instance.getProfile(targetPlayer);
|
||||
if(profile == null || profile.player == null)
|
||||
return;
|
||||
|
||||
File backupDir = new File(ProfileController.getBackupDir(), profile.getPlayer().getUniqueID().toString());
|
||||
File backupFile = new File(backupDir, backupFileName);
|
||||
if(!backupFile.exists()){
|
||||
sendError(sender, "Backup file %s not found for player %s.", backupFileName, targetPlayer);
|
||||
return;
|
||||
}
|
||||
boolean success = ProfileController.Instance.rollbackProfile(targetPlayer, backupFile);
|
||||
if(success) {
|
||||
sendResult(sender, "Successfully rolled back %s's profile to backup %s.", targetPlayer, backupFileName);
|
||||
} else {
|
||||
sendError(sender, "Failed to rollback %s's profile.", targetPlayer);
|
||||
}
|
||||
sendResult(sender, "Successfully renamed slot %s for %s to '%s'.", slotId, targetPlayer, newName);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -55,19 +54,7 @@ public abstract class CommandProfileBase extends CommandBase{
|
||||
return !subcommands.isEmpty();
|
||||
}
|
||||
|
||||
protected static void sendMessage(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation(message, obs));
|
||||
}
|
||||
|
||||
protected static void sendResult(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A77 " + message, obs));
|
||||
}
|
||||
|
||||
protected static void sendError(ICommandSender sender, String message, Object... obs) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A74 Error:\u00A7c " + message, obs));
|
||||
}
|
||||
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SubCommand {
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.EnumProfileOperation;
|
||||
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 CommandProfileChange extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
@@ -30,35 +34,31 @@ public class CommandProfileChange extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
if(!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
if(args.length < 1) {
|
||||
sendError(sender, "Usage: " + getUsage());
|
||||
return;
|
||||
}
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch(NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number: " + args[0]);
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
ProfileOperation result = ProfileController.changeSlot(player, slotId);
|
||||
switch(result) {
|
||||
case SUCCESS:
|
||||
sendResult(sender, "Successfully changed profile slot to %s.", slotId);
|
||||
break;
|
||||
case LOCKED:
|
||||
sendError(sender, "Profile is locked. Please try again later.");
|
||||
break;
|
||||
case ERROR:
|
||||
sendError(sender, "Error occurred while changing your profile slot.");
|
||||
break;
|
||||
default:
|
||||
sendError(sender, "Operation could not be completed.");
|
||||
EntityPlayer player = (EntityPlayer)sender;
|
||||
ProfileOperation result = ProfileController.Instance.changeSlot(player, slotId);
|
||||
if(result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully changed profile slot to %d.", slotId);
|
||||
} else if(result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Profile is locked. Details: %s", result.getMessage());
|
||||
} else if(result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error changing your profile slot: %s", result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.EnumProfileOperation;
|
||||
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;
|
||||
if(ProfileController.Instance.getProfile(player) == null) {
|
||||
sendError(sender, "Profile not found.");
|
||||
return;
|
||||
}
|
||||
ProfileOperation result = ProfileController.Instance.createSlotInternal(ProfileController.Instance.getProfile(player));
|
||||
if(result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "New profile slot created successfully.");
|
||||
} else if(result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Profile is locked. Details: %s", result.getMessage());
|
||||
} else if(result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error creating new profile slot: %s", result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.controllers.data.Slot;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.sendError;
|
||||
import static kamkeel.npcs.util.ColorUtil.sendMessage;
|
||||
|
||||
public class CommandProfileList extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
@@ -28,21 +31,24 @@ public class CommandProfileList extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
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) {
|
||||
EntityPlayer player = (EntityPlayer)sender;
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
if(profile == null) {
|
||||
sendError(sender, "Profile not found.");
|
||||
return;
|
||||
}
|
||||
if(profile.getSlots().isEmpty()){
|
||||
sendMessage(sender, "No slots found. Using default slot 0.");
|
||||
}
|
||||
sendMessage(sender, "Your Profile Slots:");
|
||||
for (Map.Entry<Integer, Slot> entry : profile.slots.entrySet()) {
|
||||
for(Map.Entry<Integer, ISlot> entry : profile.getSlots().entrySet()) {
|
||||
int id = entry.getKey();
|
||||
String name = entry.getValue().getName();
|
||||
String prefix = (id == profile.currentID) ? "* " : "- ";
|
||||
String prefix = (id == profile.currentSlotId) ? "* " : "- ";
|
||||
sendMessage(sender, prefix + "Slot " + id + ": " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static kamkeel.npcs.util.ColorUtil.*;
|
||||
|
||||
public class CommandProfileRegion extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Manage profile region switching and restricted regions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<subcommand>";
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Enable region-based profile switching",
|
||||
usage = ""
|
||||
)
|
||||
public void enable(ICommandSender sender, String[] args) throws CommandException {
|
||||
ConfigMain.RegionProfileSwitching = true;
|
||||
ConfigMain.RegionProfileSwitchingProperty.set(true);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Profile region switching enabled.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Disable region-based profile switching",
|
||||
usage = ""
|
||||
)
|
||||
public void disable(ICommandSender sender, String[] args) throws CommandException {
|
||||
ConfigMain.RegionProfileSwitching = false;
|
||||
ConfigMain.RegionProfileSwitchingProperty.set(false);
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Profile region switching disabled.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Add a new region. Format: DIM, X1, Y1, Z1, X2, Y2, Z2",
|
||||
usage = "<dim> <x1> <y1> <z1> <x2> <y2> <z2>"
|
||||
)
|
||||
public void add(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length < 1){
|
||||
sendError(sender, "Usage: /profile region add <DIM, X1, Y1, Z1, X2, Y2, Z2>");
|
||||
return;
|
||||
}
|
||||
// Combine args in case the region data was split by spaces
|
||||
String regionStr = String.join(" ", args).trim();
|
||||
String[] parts = regionStr.split(",");
|
||||
if(parts.length != 7){
|
||||
sendError(sender, "Invalid region format. Must contain 7 integers separated by commas.");
|
||||
return;
|
||||
}
|
||||
List<Integer> regionList = new ArrayList<>();
|
||||
try {
|
||||
for(String part : parts){
|
||||
regionList.add(Integer.parseInt(part.trim()));
|
||||
}
|
||||
} catch(NumberFormatException e){
|
||||
sendError(sender, "Invalid number format in region data.");
|
||||
return;
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegions.add(regionList);
|
||||
// Update config property value
|
||||
List<String> regionStrings = new ArrayList<>();
|
||||
for(List<Integer> region : ConfigMain.RestrictedProfileRegions) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < region.size(); i++) {
|
||||
if(i > 0) sb.append(", ");
|
||||
sb.append(region.get(i));
|
||||
}
|
||||
regionStrings.add(sb.toString());
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegionsProperty.set(regionStrings.toArray(new String[0]));
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Region added successfully.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "Remove a region by its index (1-based).",
|
||||
usage = "<index>"
|
||||
)
|
||||
public void remove(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(args.length < 1){
|
||||
sendError(sender, "Usage: /profile region remove <index>");
|
||||
return;
|
||||
}
|
||||
int index;
|
||||
try {
|
||||
index = Integer.parseInt(args[0]);
|
||||
} catch(NumberFormatException e){
|
||||
sendError(sender, "Index must be a number.");
|
||||
return;
|
||||
}
|
||||
index = index - 1; // Convert to 0-based index
|
||||
if(index < 0 || index >= ConfigMain.RestrictedProfileRegions.size()){
|
||||
sendError(sender, "Invalid index. Must be between 1 and " + ConfigMain.RestrictedProfileRegions.size());
|
||||
return;
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegions.remove(index);
|
||||
// Update config property value
|
||||
List<String> regionStrings = new ArrayList<>();
|
||||
for(List<Integer> region : ConfigMain.RestrictedProfileRegions) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < region.size(); i++) {
|
||||
if(i > 0) sb.append(", ");
|
||||
sb.append(region.get(i));
|
||||
}
|
||||
regionStrings.add(sb.toString());
|
||||
}
|
||||
ConfigMain.RestrictedProfileRegionsProperty.set(regionStrings.toArray(new String[0]));
|
||||
if(ConfigMain.config.hasChanged()){
|
||||
ConfigMain.config.save();
|
||||
}
|
||||
sendResult(sender, "Region removed successfully.");
|
||||
}
|
||||
|
||||
@SubCommand(
|
||||
desc = "List all restricted profile regions.",
|
||||
usage = ""
|
||||
)
|
||||
public void list(ICommandSender sender, String[] args) throws CommandException {
|
||||
if(ConfigMain.RestrictedProfileRegions.isEmpty()){
|
||||
sendMessage(sender, "No restricted profile regions configured.");
|
||||
return;
|
||||
}
|
||||
sendMessage(sender, "Restricted Profile Regions:");
|
||||
int i = 1;
|
||||
for(List<Integer> region : ConfigMain.RestrictedProfileRegions) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(i).append(": ");
|
||||
for (int j = 0; j < region.size(); j++) {
|
||||
if(j > 0) sb.append(", ");
|
||||
sb.append(region.get(j));
|
||||
}
|
||||
sendMessage(sender, sb.toString());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.EnumProfileOperation;
|
||||
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 CommandProfileRemove extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
@@ -30,35 +34,31 @@ public class CommandProfileRemove extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
if(!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
if(args.length < 1) {
|
||||
sendError(sender, "Usage: " + getUsage());
|
||||
return;
|
||||
}
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch(NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number: " + args[0]);
|
||||
return;
|
||||
}
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
ProfileOperation result = ProfileController.removeSlot(player, slotId);
|
||||
switch(result) {
|
||||
case SUCCESS:
|
||||
sendResult(sender, "Successfully removed slot %d from your profile.", slotId);
|
||||
break;
|
||||
case LOCKED:
|
||||
sendError(sender, "Profile is locked. Please try again later.");
|
||||
break;
|
||||
case ERROR:
|
||||
sendError(sender, "Error removing slot. Ensure the slot exists and is not your active slot.");
|
||||
break;
|
||||
default:
|
||||
sendError(sender, "Operation could not be completed.");
|
||||
EntityPlayer player = (EntityPlayer)sender;
|
||||
ProfileOperation result = ProfileController.Instance.removeSlot(player, slotId);
|
||||
if(result.getResult() == EnumProfileOperation.SUCCESS) {
|
||||
sendResult(sender, "Successfully removed slot %d from your profile.", slotId);
|
||||
} else if(result.getResult() == EnumProfileOperation.LOCKED) {
|
||||
sendError(sender, "Profile is locked. Details: %s", result.getMessage());
|
||||
} else if(result.getResult() == EnumProfileOperation.ERROR) {
|
||||
sendError(sender, "Error removing slot: %s", result.getMessage());
|
||||
} else {
|
||||
sendError(sender, "Unexpected error: %s", result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
package kamkeel.npcs.command.profile;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
import kamkeel.npcs.controllers.data.Slot;
|
||||
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 CommandProfileRename extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
@@ -26,52 +27,45 @@ public class CommandProfileRename extends CommandProfileBase {
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (!(sender instanceof EntityPlayer)) {
|
||||
if(!(sender instanceof EntityPlayer)) {
|
||||
sendError(sender, "This command can only be used by a player.");
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
if(args.length < 2) {
|
||||
sendError(sender, "Usage: " + getUsage());
|
||||
return;
|
||||
}
|
||||
int slotId;
|
||||
try {
|
||||
slotId = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
} catch(NumberFormatException ex) {
|
||||
sendError(sender, "Slot ID must be a number.");
|
||||
return;
|
||||
}
|
||||
// Combine remaining arguments into one name string.
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (i > 1) sb.append(" ");
|
||||
for(int i = 1; i < args.length; i++){
|
||||
if(i > 1) sb.append(" ");
|
||||
sb.append(args[i]);
|
||||
}
|
||||
String newName = sb.toString().trim();
|
||||
// Cap at 20 characters.
|
||||
if (newName.length() > 20) {
|
||||
if(newName.length() > 20) {
|
||||
newName = newName.substring(0, 20);
|
||||
}
|
||||
// Validate that the new name contains only letters and spaces.
|
||||
if (!newName.matches("[A-Za-z ]+")) {
|
||||
if(!newName.matches("[A-Za-z ]+")){
|
||||
sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed.");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityPlayer player = (EntityPlayer) sender;
|
||||
Profile profile = ProfileController.getProfile(player);
|
||||
if (profile == null) {
|
||||
EntityPlayer player = (EntityPlayer)sender;
|
||||
if(ProfileController.Instance.getProfile(player) == null) {
|
||||
sendError(sender, "Profile not found.");
|
||||
return;
|
||||
}
|
||||
if (!profile.slots.containsKey(slotId)) {
|
||||
sendError(sender, "Slot " + slotId + " not found in your profile.");
|
||||
if(!ProfileController.Instance.getProfile(player).getSlots().containsKey(slotId)) {
|
||||
sendError(sender, "Slot %d not found in your profile.", slotId);
|
||||
return;
|
||||
}
|
||||
Slot slot = profile.slots.get(slotId);
|
||||
slot.setName(newName);
|
||||
// Save the profile after renaming.
|
||||
ProfileController.save(player, profile);
|
||||
sendResult(sender, "Successfully renamed slot %s to '%s'.", slotId, newName);
|
||||
ProfileController.Instance.getProfile(player).getSlots().get(slotId).setName(newName);
|
||||
ProfileController.Instance.save(player, ProfileController.Instance.getProfile(player));
|
||||
sendResult(sender, "Successfully renamed slot %d to '%s'.", slotId, newName);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -4,10 +4,11 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncPacket;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.packets.data.LoginPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -17,12 +18,15 @@ import noppes.npcs.controllers.*;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class SyncController {
|
||||
|
||||
public static void syncPlayer(EntityPlayerMP player){
|
||||
|
||||
// Login Packet
|
||||
PacketHandler.Instance.sendToPlayer(new LoginPacket(), player);
|
||||
|
||||
// 1) Factions
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.FACTION,
|
||||
|
||||
@@ -6,11 +6,14 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CNPCData implements IProfileData {
|
||||
|
||||
@Override
|
||||
public String getTagName() {
|
||||
return "CustomNPC+";
|
||||
return "CNPC+";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,4 +42,31 @@ public class CNPCData implements IProfileData {
|
||||
}
|
||||
customNPCData.updateClient = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSwitchPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileOperation verifySwitch(EntityPlayer player) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if(playerData.partyUUID != null)
|
||||
return ProfileOperation.error("Cannot switch while in Party");
|
||||
|
||||
return ProfileOperation.success("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InfoEntry> getInfo(EntityPlayer player, NBTTagCompound compound) {
|
||||
PlayerData playerData = new PlayerData();
|
||||
playerData.player = player;
|
||||
playerData.setNBT(compound);
|
||||
|
||||
List<InfoEntry> info = new ArrayList<>();
|
||||
info.add(new InfoEntry("profile.info.quest.finished", 0x60fa57, playerData.questData.finishedQuests.size(), 0xFFFFFF));
|
||||
info.add(new InfoEntry("profile.info.quest.active", 0xf75336, playerData.questData.activeQuests.size(), 0xFFFFFF));
|
||||
info.add(new InfoEntry("profile.info.dialog.read", 0x47acf5, playerData.dialogData.dialogsRead.size(), 0xFFFFFF));
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package kamkeel.npcs.controllers.data;
|
||||
|
||||
public enum EnumProfileOperation {
|
||||
SUCCESS,
|
||||
ERROR,
|
||||
LOCKED
|
||||
}
|
||||
@@ -3,27 +3,50 @@ package kamkeel.npcs.controllers.data;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IProfileData {
|
||||
|
||||
/**
|
||||
* Do not use the tag: - Name, lastLoaded, ID
|
||||
*
|
||||
* @return The Save Tag utilized in the Profile
|
||||
* Do not use the tags: Name, lastLoaded, ID.
|
||||
* @return The save tag utilized in the Profile.
|
||||
*/
|
||||
public String getTagName();
|
||||
|
||||
/**
|
||||
* @return NBTTagCompound of their Current Data for a given Entity Player
|
||||
* @return NBTTagCompound of the current data for a given EntityPlayer.
|
||||
*/
|
||||
public NBTTagCompound getCurrentNBT(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* Called immediately after setNBT() Replaces existing NBT
|
||||
* Called immediately after setNBT() to replace existing NBT.
|
||||
*/
|
||||
public void save(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* Replaces their Current Data operation when changing Profiles
|
||||
* Replaces the current data operation when changing profiles.
|
||||
*/
|
||||
public void setNBT(EntityPlayer player, NBTTagCompound replace);
|
||||
|
||||
/**
|
||||
* Returns the priority for this ProfileData's verification check.
|
||||
* Lower numbers run first.
|
||||
*/
|
||||
public int getSwitchPriority();
|
||||
|
||||
/**
|
||||
* Called before a profile switch occurs.
|
||||
* @param player The player switching profiles.
|
||||
* @return true if allowed, false if not.
|
||||
*/
|
||||
public ProfileOperation verifySwitch(EntityPlayer player);
|
||||
|
||||
/**
|
||||
* NEW: Builds and returns a list of informational strings about this profile data,
|
||||
* based on the provided NBTTagCompound from the slot.
|
||||
* @param player The player in question.
|
||||
* @param compound The NBT data from the slot under this profile data's tag.
|
||||
* @return A list of InfoEntry with information
|
||||
*/
|
||||
public List<InfoEntry> getInfo(EntityPlayer player, NBTTagCompound compound);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package kamkeel.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class InfoEntry {
|
||||
private String label;
|
||||
private String result;
|
||||
private int labelColor;
|
||||
private int resultColor;
|
||||
|
||||
public InfoEntry() {}
|
||||
|
||||
public InfoEntry(String label, int labelColor, String result, int resultColor) {
|
||||
this.label = label;
|
||||
this.result = result;
|
||||
this.labelColor = labelColor;
|
||||
this.resultColor = resultColor;
|
||||
}
|
||||
|
||||
public InfoEntry(String label, int labelColor, int result, int resultColor) {
|
||||
this(label, labelColor, String.valueOf(result), resultColor);
|
||||
}
|
||||
|
||||
public InfoEntry(String label, String result) {
|
||||
this(label, 0xFFFFFF, result, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setString("Label", label);
|
||||
tag.setInteger("LabelColor", labelColor);
|
||||
tag.setString("Result", result);
|
||||
tag.setInteger("ResultColor", resultColor);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static InfoEntry readFromNBT(NBTTagCompound tag) {
|
||||
return new InfoEntry(
|
||||
tag.getString("Label"),
|
||||
tag.getInteger("LabelColor"),
|
||||
tag.getString("Result"),
|
||||
tag.getInteger("ResultColor")
|
||||
);
|
||||
}
|
||||
|
||||
public String getLabel() { return label; }
|
||||
public String getResult() { return result; }
|
||||
public int getLabelColor() { return labelColor; }
|
||||
public int getResultColor() { return resultColor; }
|
||||
}
|
||||
@@ -2,56 +2,91 @@ package kamkeel.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Profile {
|
||||
|
||||
public class Profile implements IProfile {
|
||||
public EntityPlayer player;
|
||||
public int currentID;
|
||||
public HashMap<Integer, Slot> slots = new HashMap<>();
|
||||
public boolean locked = false; // Prevent modifications while saving
|
||||
public int currentSlotId;
|
||||
private Map<Integer, ISlot> slots = new HashMap<>();
|
||||
private boolean locked = false;
|
||||
|
||||
public Profile(EntityPlayer player, NBTTagCompound compound){
|
||||
public Profile(EntityPlayer player, NBTTagCompound compound) {
|
||||
this.player = player;
|
||||
if(compound.hasKey("CurrentID")){
|
||||
this.currentID = compound.getInteger("CurrentID");
|
||||
if(compound.hasKey("CurrentSlotId")){
|
||||
this.currentSlotId = compound.getInteger("CurrentSlotId");
|
||||
} else {
|
||||
this.currentID = 0;
|
||||
this.currentSlotId = 0;
|
||||
}
|
||||
|
||||
if (compound.hasKey("Slots")) {
|
||||
if(compound.hasKey("Slots")){
|
||||
NBTTagCompound slotsCompound = compound.getCompoundTag("Slots");
|
||||
for (String key : (Set<String>) slotsCompound.func_150296_c()) {
|
||||
int slotID = Integer.parseInt(key);
|
||||
NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key);
|
||||
Slot slot = Slot.fromNBT(slotID, slotNBT);
|
||||
slots.put(slotID, slot);
|
||||
Set<String> keys = slotsCompound.func_150296_c();
|
||||
for(String key : keys) {
|
||||
try {
|
||||
int slotId = Integer.parseInt(key);
|
||||
NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key);
|
||||
ISlot slot = Slot.fromNBT(slotId, slotNBT);
|
||||
slots.put(slotId, slot);
|
||||
} catch (NumberFormatException e) {
|
||||
// Skip keys that are not valid slot IDs.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Profile(EntityPlayer player) {
|
||||
this.player = player;
|
||||
this.currentSlotId = 0;
|
||||
// Create a default slot.
|
||||
Slot defaultSlot = new Slot(0, "Default Slot");
|
||||
defaultSlot.setLastLoaded(System.currentTimeMillis());
|
||||
slots.put(0, defaultSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return NoppesUtilServer.getIPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentSlotId() {
|
||||
return currentSlotId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ISlot> getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound fullCompound = new NBTTagCompound();
|
||||
|
||||
if(this.player != null)
|
||||
fullCompound.setString("Name", player.getCommandSenderName());
|
||||
fullCompound.setInteger("CurrentID", currentID);
|
||||
|
||||
if(!slots.isEmpty()){
|
||||
NBTTagCompound slotsCompound = new NBTTagCompound();
|
||||
for (HashMap.Entry<Integer, Slot> entry : slots.entrySet()) {
|
||||
Slot slot = entry.getValue();
|
||||
if(slot.isTemporary())
|
||||
continue; // Do not save temporary slots
|
||||
int id = entry.getKey();
|
||||
slot.setId(id);
|
||||
NBTTagCompound slotTag = slot.toNBT();
|
||||
slotsCompound.setTag(String.valueOf(id), slotTag);
|
||||
}
|
||||
fullCompound.setTag("Slots", slotsCompound);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
if(player != null)
|
||||
compound.setString("Name", player.getCommandSenderName());
|
||||
compound.setInteger("CurrentSlotId", currentSlotId);
|
||||
NBTTagCompound slotsCompound = new NBTTagCompound();
|
||||
for(Map.Entry<Integer, ISlot> entry : slots.entrySet()) {
|
||||
// Save only non-temporary slots.
|
||||
if(entry.getValue().isTemporary())
|
||||
continue;
|
||||
slotsCompound.setTag(String.valueOf(entry.getKey()), entry.getValue().toNBT());
|
||||
}
|
||||
return fullCompound;
|
||||
compound.setTag("Slots", slotsCompound);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,31 @@
|
||||
package kamkeel.npcs.controllers.data;
|
||||
|
||||
public enum ProfileOperation {
|
||||
SUCCESS,
|
||||
ERROR,
|
||||
LOCKED,
|
||||
PLAYER_NOT_FOUND
|
||||
public class ProfileOperation {
|
||||
private final EnumProfileOperation result;
|
||||
private final String message;
|
||||
|
||||
public ProfileOperation(EnumProfileOperation result, String message) {
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public EnumProfileOperation getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static ProfileOperation success(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.SUCCESS, message);
|
||||
}
|
||||
|
||||
public static ProfileOperation error(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.ERROR, message);
|
||||
}
|
||||
|
||||
public static ProfileOperation locked(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.LOCKED, message);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,114 @@
|
||||
package kamkeel.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
|
||||
public class Slot {
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Slot implements ISlot {
|
||||
private int id;
|
||||
private String name;
|
||||
private long lastLoaded;
|
||||
private NBTTagCompound compound;
|
||||
private boolean temporary = false;
|
||||
private boolean temporary;
|
||||
private Map<String, NBTTagCompound> components = new HashMap<>();
|
||||
|
||||
public Slot(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Slot(int id, String name, NBTTagCompound compound, long last, boolean temporary) {
|
||||
public Slot(int id, String name, long lastLoaded, boolean temporary, Map<String, NBTTagCompound> components) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.compound = compound;
|
||||
this.lastLoaded = last;
|
||||
this.lastLoaded = lastLoaded;
|
||||
this.temporary = temporary;
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
// Getters and setters
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastLoaded() {
|
||||
return lastLoaded;
|
||||
}
|
||||
public void setLastLoaded(long lastLoaded) {
|
||||
this.lastLoaded = lastLoaded;
|
||||
}
|
||||
public NBTTagCompound getCompound() {
|
||||
return compound;
|
||||
}
|
||||
public void setCompound(NBTTagCompound compound) {
|
||||
this.compound = compound;
|
||||
|
||||
@Override
|
||||
public void setLastLoaded(long time) {
|
||||
this.lastLoaded = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemporary() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemporary(boolean temporary) {
|
||||
this.temporary = temporary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, NBTTagCompound> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComponentData(String key, NBTTagCompound data) {
|
||||
components.put(key, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getComponentData(String key) {
|
||||
return components.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound toNBT() {
|
||||
NBTTagCompound slotNBT = new NBTTagCompound();
|
||||
slotNBT.setString("Name", name);
|
||||
slotNBT.setLong("LastLoaded", lastLoaded);
|
||||
slotNBT.setTag("Data", compound);
|
||||
slotNBT.setBoolean("Temporary", temporary);
|
||||
NBTTagCompound compCompound = new NBTTagCompound();
|
||||
for (Map.Entry<String, NBTTagCompound> entry : components.entrySet()) {
|
||||
compCompound.setTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
slotNBT.setTag("Components", compCompound);
|
||||
return slotNBT;
|
||||
}
|
||||
|
||||
public static Slot fromNBT(int id, NBTTagCompound slotNBT) {
|
||||
String name = slotNBT.getString("Name");
|
||||
long lastLoaded = slotNBT.getLong("LastLoaded");
|
||||
NBTTagCompound compound = slotNBT.getCompoundTag("Data");
|
||||
boolean temporary = slotNBT.hasKey("Temporary") && slotNBT.getBoolean("Temporary");
|
||||
return new Slot(id, name, compound, lastLoaded, temporary);
|
||||
boolean temporary = slotNBT.getBoolean("Temporary");
|
||||
Slot slot = new Slot(id, name);
|
||||
slot.setLastLoaded(lastLoaded);
|
||||
slot.setTemporary(temporary);
|
||||
if (slotNBT.hasKey("Components")) {
|
||||
NBTTagCompound compCompound = slotNBT.getCompoundTag("Components");
|
||||
Set<String> keys = compCompound.func_150296_c();
|
||||
for (String key : keys) {
|
||||
slot.setComponentData(key, compCompound.getCompoundTag(key));
|
||||
}
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.LogWriter;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -53,9 +53,8 @@ import kamkeel.npcs.network.packets.request.npc.*;
|
||||
import kamkeel.npcs.network.packets.request.party.*;
|
||||
import kamkeel.npcs.network.packets.request.pather.MovingPathGetPacket;
|
||||
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.playerdata.*;
|
||||
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;
|
||||
@@ -224,8 +223,12 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new TagRemovePacket());
|
||||
|
||||
// PlayerData Packets
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataGetPacket());
|
||||
|
||||
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataGetNamesPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataGetInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataRemoveInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerDataMapRegenPacket());
|
||||
|
||||
// Main Menu Packets
|
||||
@@ -323,6 +326,14 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new EffectSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new EffectRemovePacket());
|
||||
|
||||
// Profile Packets
|
||||
REQUEST_PACKET.registerPacket(new ProfileGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileGetInfoPacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileCreatePacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileRenamePacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileChangePacket());
|
||||
|
||||
// Other Packets
|
||||
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
|
||||
REQUEST_PACKET.registerPacket(new GuiRequestPacket());
|
||||
@@ -338,6 +349,7 @@ public class PacketHandler {
|
||||
|
||||
public void registerDataPackets(){
|
||||
// Data Packets
|
||||
DATA_PACKET.registerPacket(new LoginPacket());
|
||||
DATA_PACKET.registerPacket(new AchievementPacket());
|
||||
DATA_PACKET.registerPacket(new ChatAlertPacket());
|
||||
DATA_PACKET.registerPacket(new ChatBubblePacket());
|
||||
@@ -353,6 +365,7 @@ public class PacketHandler {
|
||||
DATA_PACKET.registerPacket(new SwingPlayerArmPacket());
|
||||
DATA_PACKET.registerPacket(new UpdateAnimationsPacket());
|
||||
DATA_PACKET.registerPacket(new VillagerListPacket());
|
||||
DATA_PACKET.registerPacket(new PlayerDataInfoPacket());
|
||||
|
||||
// Data | GUI Packets
|
||||
DATA_PACKET.registerPacket(new GuiClosePacket());
|
||||
|
||||
@@ -17,7 +17,6 @@ import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -38,6 +38,7 @@ public enum EnumDataPacket {
|
||||
GUI_TELEPORTER,
|
||||
GUI_BOOK,
|
||||
GUI_DATA,
|
||||
PLAYER_DATA,
|
||||
GUI_ERROR,
|
||||
GUI_CLOSE,
|
||||
ISGUIOPEN,
|
||||
|
||||
@@ -136,7 +136,9 @@ public enum EnumRequestPacket {
|
||||
|
||||
QuestCategoryGet,
|
||||
|
||||
PlayerDataGet,
|
||||
PlayerDataInfo,
|
||||
PlayerDataGetNames,
|
||||
PlayerDataDelete,
|
||||
PlayerDataRemove,
|
||||
PlayerDataMapRegen,
|
||||
|
||||
@@ -185,5 +187,13 @@ public enum EnumRequestPacket {
|
||||
EffectSave,
|
||||
|
||||
ColorSet,
|
||||
ColorBrush
|
||||
ColorBrush,
|
||||
|
||||
ProfileGet,
|
||||
ProfileGetAll,
|
||||
ProfileGetInfo,
|
||||
ProfileCreate,
|
||||
ProfileRemove,
|
||||
ProfileRename,
|
||||
ProfileChange
|
||||
}
|
||||
@@ -8,12 +8,16 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import kamkeel.npcs.util.ColorUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ChatAlertPacket extends AbstractPacket {
|
||||
public static final String packetName = "Data|ChatAlert";
|
||||
@@ -53,11 +57,20 @@ public final class ChatAlertPacket extends AbstractPacket {
|
||||
if (!ConfigClient.ChatAlerts)
|
||||
return;
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
String str;
|
||||
while ((str = ByteBufUtils.readString(in)) != null && !str.isEmpty()) {
|
||||
message.append(str);
|
||||
// Read all objects (sent as strings) from the buffer.
|
||||
List<String> parts = new ArrayList<>();
|
||||
String part;
|
||||
while ((part = ByteBufUtils.readString(in)) != null && !part.isEmpty()) {
|
||||
parts.add(part);
|
||||
}
|
||||
player.addChatMessage(new ChatComponentTranslation(message.toString()));
|
||||
|
||||
StringBuilder finalMessage = new StringBuilder();
|
||||
for (String s : parts) {
|
||||
finalMessage.append(StatCollector.translateToLocal(s));
|
||||
}
|
||||
|
||||
String text = finalMessage.toString();
|
||||
IChatComponent comp = ColorUtil.assembleComponent(text);
|
||||
player.addChatMessage(comp);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
package kamkeel.npcs.network.packets.data;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LoginPacket extends AbstractPacket {
|
||||
public static final String packetName = "CNPC+|Login";
|
||||
|
||||
public LoginPacket() {
|
||||
}
|
||||
|
||||
public LoginPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
@@ -29,13 +29,14 @@ public final class LoginPacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// ByteBufUtils.writeUTF8String(out, this.data.player.getCommandSenderName());
|
||||
// ByteBufUtils.writeNBT(out,this.data.saveFromNBT(new NBTTagCompound()));
|
||||
out.writeBoolean(ConfigMain.PartiesEnabled);
|
||||
out.writeBoolean(ConfigMain.ProfilesEnabled);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
String playerName = ByteBufUtils.readUTF8String(in);
|
||||
|
||||
ClientCacheHandler.allowParties = in.readBoolean();
|
||||
ClientCacheHandler.allowProfiles = in.readBoolean();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,9 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.gui.OverlayQuestTracking;
|
||||
import noppes.npcs.client.gui.hud.ClientHudManager;
|
||||
import noppes.npcs.client.gui.hud.EnumHudComponent;
|
||||
import noppes.npcs.client.gui.hud.HudComponent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -46,12 +48,14 @@ public final class OverlayQuestTrackingPacket extends AbstractPacket {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker);
|
||||
try {
|
||||
NBTTagCompound nbt = ByteBufUtils.readNBT(in);
|
||||
ClientCacheHandler.questTrackingOverlay = new OverlayQuestTracking(Minecraft.getMinecraft());
|
||||
ClientCacheHandler.questTrackingOverlay.setOverlayData(nbt);
|
||||
component.loadData(nbt);
|
||||
if(nbt.hasNoTags())
|
||||
component.hasData = false;
|
||||
} catch (IOException e) {
|
||||
ClientCacheHandler.questTrackingOverlay = null;
|
||||
component.hasData = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package kamkeel.npcs.network.packets.data;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public final class PlayerDataInfoPacket extends LargeAbstractPacket {
|
||||
public static final String packetName = "Large|PlayerDataSendNew";
|
||||
|
||||
private String playerName;
|
||||
private Map<String, Integer> questCategories;
|
||||
private Map<String, Integer> questActive;
|
||||
private Map<String, Integer> questFinished;
|
||||
|
||||
private Map<String, Integer> dialogCategories;
|
||||
private Map<String, Integer> dialogRead;
|
||||
|
||||
private Map<String, Integer> transportCategories;
|
||||
private Map<String, Integer> transportLocations;
|
||||
|
||||
private Map<String, Integer> bankData;
|
||||
private Map<String, Integer> factionData;
|
||||
|
||||
public PlayerDataInfoPacket() {}
|
||||
|
||||
public PlayerDataInfoPacket(String playerName,
|
||||
Map<String, Integer> questCategories, Map<String, Integer> questActive, Map<String, Integer> questFinished,
|
||||
Map<String, Integer> dialogCategories, Map<String, Integer> dialogRead,
|
||||
Map<String, Integer> transportCategories, Map<String, Integer> transportLocations,
|
||||
Map<String, Integer> bankData, Map<String, Integer> factionData) {
|
||||
this.playerName = playerName;
|
||||
this.questCategories = questCategories;
|
||||
this.questActive = questActive;
|
||||
this.questFinished = questFinished;
|
||||
this.dialogCategories = dialogCategories;
|
||||
this.dialogRead = dialogRead;
|
||||
this.transportCategories = transportCategories;
|
||||
this.transportLocations = transportLocations;
|
||||
this.bankData = bankData;
|
||||
this.factionData = factionData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumDataPacket.PLAYER_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.DATA_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getData() throws IOException {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
// Write player name:
|
||||
ByteBufUtils.writeString(buffer, playerName);
|
||||
// Write quest data maps:
|
||||
writeMap(buffer, questCategories);
|
||||
writeMap(buffer, questActive);
|
||||
writeMap(buffer, questFinished);
|
||||
// Write dialog data maps:
|
||||
writeMap(buffer, dialogCategories);
|
||||
writeMap(buffer, dialogRead);
|
||||
// Write transport data maps:
|
||||
writeMap(buffer, transportCategories);
|
||||
writeMap(buffer, transportLocations);
|
||||
// Write bank data map:
|
||||
writeMap(buffer, bankData);
|
||||
// Write faction data map:
|
||||
writeMap(buffer, factionData);
|
||||
|
||||
byte[] bytes = new byte[buffer.readableBytes()];
|
||||
buffer.readBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private void writeMap(ByteBuf buffer, Map<String, Integer> map) {
|
||||
if (map != null) {
|
||||
buffer.writeInt(map.size());
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
ByteBufUtils.writeString(buffer, entry.getKey());
|
||||
buffer.writeInt(entry.getValue());
|
||||
}
|
||||
} else {
|
||||
buffer.writeInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
NoppesUtil.handlePlayerData(data, player);
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,6 @@ import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -8,8 +8,6 @@ import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import noppes.npcs.blocks.tiles.TileBigSign;
|
||||
|
||||
|
||||
@@ -10,16 +10,12 @@ import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class TileEntityGetPacket extends AbstractPacket {
|
||||
public static final String packetName = "Request|TileEntityGet";
|
||||
|
||||
@@ -14,10 +14,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.ServerTagMapController;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
import noppes.npcs.controllers.data.TagMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package kamkeel.npcs.network.packets.request.clone;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -17,9 +16,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
|
||||
@@ -10,16 +10,11 @@ import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
import noppes.npcs.controllers.ServerTagMapController;
|
||||
import noppes.npcs.controllers.data.TagMap;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package kamkeel.npcs.network.packets.request.clone;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -11,18 +10,13 @@ import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
-3
@@ -9,13 +9,10 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.data.DialogCategory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ 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.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
|
||||
@@ -15,7 +15,6 @@ import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class EffectGetPacket extends AbstractPacket {
|
||||
public static final String packetName = "NPC|GetEffect";
|
||||
|
||||
@@ -12,8 +12,6 @@ import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.QuestCategory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
-5
@@ -9,17 +9,12 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@ package kamkeel.npcs.network.packets.request.item;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.*;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
@@ -9,18 +9,11 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptLinkedItem;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
-1
@@ -13,7 +13,6 @@ 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;
|
||||
|
||||
|
||||
-1
@@ -13,7 +13,6 @@ 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;
|
||||
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package kamkeel.npcs.network.packets.request.playerdata;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
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.NoppesUtilServer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PlayerDataGetInfoPacket extends AbstractPacket {
|
||||
public static final String packetName = "Request|PlayerDataGetNew";
|
||||
private String playerName;
|
||||
|
||||
public PlayerDataGetInfoPacket() {}
|
||||
|
||||
public PlayerDataGetInfoPacket(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.PlayerDataInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
String playerName = ByteBufUtils.readString(in);
|
||||
NoppesUtilServer.sendPlayerDataInfo(playerName, (EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -17,22 +17,22 @@ import noppes.npcs.constants.EnumPlayerData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PlayerDataGetPacket extends AbstractPacket {
|
||||
public final class PlayerDataGetNamesPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|PlayerDataGet";
|
||||
|
||||
private EnumPlayerData playerData;
|
||||
private String name;
|
||||
|
||||
public PlayerDataGetPacket() {}
|
||||
public PlayerDataGetNamesPacket() {}
|
||||
|
||||
public PlayerDataGetPacket(EnumPlayerData playerData, String name) {
|
||||
public PlayerDataGetNamesPacket(EnumPlayerData playerData, String name) {
|
||||
this.playerData = playerData;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.PlayerDataGet;
|
||||
return EnumRequestPacket.PlayerDataGetNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package kamkeel.npcs.network.packets.request.playerdata;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
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.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumPlayerData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PlayerDataRemoveInfoPacket extends AbstractPacket {
|
||||
public static final String packetName = "Request|PlayerDataRemoveNew";
|
||||
|
||||
private String playerName;
|
||||
private EnumPlayerData tabType;
|
||||
private int value;
|
||||
|
||||
public PlayerDataRemoveInfoPacket() {}
|
||||
|
||||
public PlayerDataRemoveInfoPacket(String playerName, EnumPlayerData tabType, int selectedKey) {
|
||||
this.playerName = playerName;
|
||||
this.tabType = tabType;
|
||||
this.value = selectedKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.PlayerDataDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, playerName);
|
||||
out.writeInt(tabType.ordinal());
|
||||
out.writeInt(this.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
String playerName = ByteBufUtils.readString(in);
|
||||
int tabType = in.readInt();
|
||||
int value = in.readInt();
|
||||
NoppesUtilServer.removePlayerDataInfo(playerName, tabType, value, (EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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 kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
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;
|
||||
|
||||
if(!ConfigMain.ProfilesEnabled)
|
||||
return;
|
||||
|
||||
int slot = in.readInt();
|
||||
ProfileOperation operation = ProfileController.Instance.changeSlot(player, slot);
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
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.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
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;
|
||||
|
||||
if(!ConfigMain.ProfilesEnabled)
|
||||
return;
|
||||
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
ProfileOperation operation = ProfileController.Instance.createSlotInternal(profile);
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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 noppes.npcs.api.handler.data.ISlot;
|
||||
import kamkeel.npcs.controllers.data.InfoEntry;
|
||||
import kamkeel.npcs.controllers.data.Profile;
|
||||
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 net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public final class ProfileGetInfoPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileGetInfo";
|
||||
|
||||
public ProfileGetInfoPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ProfileGetInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
if(!ConfigMain.ProfilesEnabled)
|
||||
return;
|
||||
|
||||
sendProfileInfo(player);
|
||||
}
|
||||
|
||||
public static void sendProfileInfo(EntityPlayer player){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("PROFILE_INFO", true);
|
||||
NBTTagList slotList = new NBTTagList();
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
if(profile != null){
|
||||
for(ISlot slot : profile.getSlots().values()){
|
||||
NBTTagCompound slotCompound = new NBTTagCompound();
|
||||
NBTTagList infoList = new NBTTagList();
|
||||
slotCompound.setInteger("ID", slot.getId());
|
||||
List<InfoEntry> profileInfo = ProfileController.Instance.getProfileInfo(player, slot.getId());
|
||||
for(InfoEntry infoEntry : profileInfo){
|
||||
infoList.appendTag(infoEntry.writeToNBT());
|
||||
}
|
||||
slotCompound.setTag("INFO", infoList);
|
||||
slotList.appendTag(slotCompound);
|
||||
}
|
||||
compound.setTag("SLOTS", slotList);
|
||||
}
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
|
||||
public static HashMap<Integer, List<InfoEntry>> readProfileInfo(NBTTagCompound compound) {
|
||||
HashMap<Integer, List<InfoEntry>> slotInfoMap = new HashMap<>();
|
||||
|
||||
if (!compound.getBoolean("PROFILE_INFO")) return slotInfoMap;
|
||||
|
||||
NBTTagList slotList = compound.getTagList("SLOTS", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < slotList.tagCount(); i++) {
|
||||
NBTTagCompound slotCompound = slotList.getCompoundTagAt(i);
|
||||
|
||||
int slotId = slotCompound.getInteger("ID");
|
||||
NBTTagList infoList = slotCompound.getTagList("INFO", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
List<InfoEntry> infoEntries = new ArrayList<>();
|
||||
for (int j = 0; j < infoList.tagCount(); j++) {
|
||||
NBTTagCompound infoTag = infoList.getCompoundTagAt(j);
|
||||
infoEntries.add(InfoEntry.readFromNBT(infoTag)); // Convert back to InfoEntry
|
||||
}
|
||||
|
||||
slotInfoMap.put(slotId, infoEntries);
|
||||
}
|
||||
|
||||
return slotInfoMap;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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.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.config.ConfigMain;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ProfileGetPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ProfileGet";
|
||||
|
||||
public ProfileGetPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ProfileGet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
if(!ConfigMain.ProfilesEnabled)
|
||||
return;
|
||||
|
||||
sendProfileNBT(player);
|
||||
}
|
||||
|
||||
public static void sendProfileNBT(EntityPlayer player){
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
NBTTagCompound compound = profile.writeToNBT();
|
||||
compound.setBoolean("PROFILE", true);
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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 kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
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;
|
||||
|
||||
if(!ConfigMain.ProfilesEnabled)
|
||||
return;
|
||||
|
||||
int slot = in.readInt();
|
||||
ProfileOperation operation = ProfileController.Instance.removeSlot(player, slot);
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
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.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
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;
|
||||
|
||||
if(!ConfigMain.ProfilesEnabled)
|
||||
return;
|
||||
|
||||
int slot = in.readInt();
|
||||
String newName = ByteBufUtils.readString(in);
|
||||
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
if(!profile.getSlots().containsKey(slot)) {
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "No slot found");
|
||||
return;
|
||||
}
|
||||
|
||||
ProfileController.Instance.getProfile(player).getSlots().get(slot).setName(newName);
|
||||
ProfileController.Instance.save(player, ProfileController.Instance.getProfile(player));
|
||||
|
||||
ProfileGetPacket.sendProfileNBT(player);
|
||||
ProfileGetInfoPacket.sendProfileInfo(player);
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,9 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -10,9 +10,7 @@ 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.controllers.DialogController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -13,9 +13,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -12,7 +12,6 @@ import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.QuestCategory;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ 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;
|
||||
|
||||
|
||||
@@ -18,9 +18,6 @@ import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.GlobalNPCDataScript;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.GlobalNPCDataScript;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package kamkeel.npcs.network.packets.request.script;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -12,11 +11,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.DataScript;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package kamkeel.npcs.network.packets.request.script;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -13,10 +12,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
-3
@@ -9,17 +9,14 @@ import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.client.gui.script.GuiScriptItem;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
|
||||
|
||||
+4
-1
@@ -3,7 +3,10 @@ package kamkeel.npcs.network.packets.request.script.item;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.*;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
|
||||
+3
-1
@@ -15,7 +15,9 @@ import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
import noppes.npcs.controllers.data.LinkedItemScript;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ 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.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -9,18 +9,14 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.constants.EnumJobType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
import noppes.npcs.controllers.TransportController;
|
||||
import noppes.npcs.controllers.data.TransportLocation;
|
||||
import noppes.npcs.roles.JobSpawner;
|
||||
import noppes.npcs.roles.RoleTransporter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -7,10 +7,8 @@ import net.minecraft.nbt.NBTSizeTracker;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import noppes.npcs.LogWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -102,7 +100,7 @@ public class ByteBufUtils extends cpw.mods.fml.common.network.ByteBufUtils {
|
||||
int length = buffer.readInt();
|
||||
byte[] bytes = new byte[length];
|
||||
buffer.readBytes(bytes);
|
||||
return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(15728640L));
|
||||
return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(31457280L));
|
||||
}
|
||||
|
||||
public static void writeString(ByteBuf buffer, String s){
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package kamkeel.npcs.util;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
public class ColorUtil {
|
||||
|
||||
|
||||
@@ -28,4 +34,133 @@ public class ColorUtil {
|
||||
float b = (hex & 0xFF) / 255.0F;
|
||||
return new float[]{r, g, b};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method that retrieves the EnumChatFormatting associated with a given formatting code character.
|
||||
*
|
||||
* @param c The formatting code character (e.g., '6' or 'l').
|
||||
* @return The matching EnumChatFormatting, or null if not found.
|
||||
*/
|
||||
public static EnumChatFormatting getFormattingByChar(char c) {
|
||||
for (EnumChatFormatting format : EnumChatFormatting.values()) {
|
||||
if (format.getFormattingCode() == c) {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles a composite IChatComponent from a raw text string with formatting codes (using §).
|
||||
* Each time the formatting changes, a new component is created and appended as a sibling.
|
||||
*
|
||||
* @param text The raw text with formatting codes.
|
||||
* @return A composite IChatComponent reflecting the formatting changes.
|
||||
*/
|
||||
public static IChatComponent assembleComponent(String text) {
|
||||
// Final composite component
|
||||
ChatComponentText composite = new ChatComponentText("");
|
||||
// Accumulates text until a formatting code change
|
||||
ChatComponentText current = new ChatComponentText("");
|
||||
// Start with a fresh ChatStyle
|
||||
ChatStyle currentStyle = new ChatStyle();
|
||||
|
||||
int i = 0;
|
||||
while (i < text.length()) {
|
||||
char c = text.charAt(i);
|
||||
if (c == '\u00A7' && i + 1 < text.length()) {
|
||||
// When a formatting code is encountered, first add any accumulated text as a sibling.
|
||||
if (current.getUnformattedText().length() > 0) {
|
||||
current.setChatStyle(currentStyle.createDeepCopy());
|
||||
composite.appendSibling(current);
|
||||
current = new ChatComponentText("");
|
||||
}
|
||||
char code = text.charAt(i + 1);
|
||||
EnumChatFormatting formatting = getFormattingByChar(code);
|
||||
if (formatting != null) {
|
||||
// If it’s a color code (0-9, a-f), then it resets previous formatting.
|
||||
if ("0123456789abcdef".indexOf(Character.toLowerCase(code)) >= 0) {
|
||||
currentStyle = new ChatStyle().setColor(formatting);
|
||||
} else {
|
||||
// For modifiers (BOLD, ITALIC, etc.)
|
||||
if (formatting == EnumChatFormatting.RESET) {
|
||||
currentStyle = new ChatStyle();
|
||||
} else {
|
||||
switch (formatting) {
|
||||
case BOLD:
|
||||
currentStyle = currentStyle.setBold(Boolean.TRUE);
|
||||
break;
|
||||
case ITALIC:
|
||||
currentStyle = currentStyle.setItalic(Boolean.TRUE);
|
||||
break;
|
||||
case UNDERLINE:
|
||||
currentStyle = currentStyle.setUnderlined(Boolean.TRUE);
|
||||
break;
|
||||
case STRIKETHROUGH:
|
||||
currentStyle = currentStyle.setStrikethrough(Boolean.TRUE);
|
||||
break;
|
||||
case OBFUSCATED:
|
||||
currentStyle = currentStyle.setObfuscated(Boolean.TRUE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
i += 2; // Skip the § and the code character.
|
||||
} else {
|
||||
// Accumulate normal characters.
|
||||
current.appendText(String.valueOf(c));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Append any trailing text.
|
||||
if (current.getUnformattedText().length() > 0) {
|
||||
current.setChatStyle(currentStyle.createDeepCopy());
|
||||
composite.appendSibling(current);
|
||||
}
|
||||
return composite;
|
||||
}
|
||||
|
||||
private static String LABEL = "\u00A76[\u00A7eCNPC+\u00A76] ";
|
||||
|
||||
/**
|
||||
* Assembles a composite chat component from a raw text string with formatting codes,
|
||||
* and immediately sends it to the specified ICommandSender.
|
||||
*
|
||||
* @param sender The ICommandSender to send the message to.
|
||||
* @param text The raw text (with § codes) to be assembled and sent.
|
||||
*/
|
||||
public static void sendMessage(ICommandSender sender, String text) {
|
||||
text = "\u00A77" + text;
|
||||
IChatComponent component = assembleComponent(text);
|
||||
sender.addChatMessage(component);
|
||||
}
|
||||
|
||||
public static void sendMessage(ICommandSender sender, String format, Object... obs) {
|
||||
sendMessage(sender, String.format(format, obs));
|
||||
}
|
||||
|
||||
public static void sendResult(ICommandSender sender, String text) {
|
||||
text = LABEL + "\u00A7a" + text;
|
||||
IChatComponent component = assembleComponent(text);
|
||||
sender.addChatMessage(component);
|
||||
}
|
||||
|
||||
public static void sendResult(ICommandSender sender, String format, Object... obs) {
|
||||
sendResult(sender, String.format(format, obs));
|
||||
}
|
||||
|
||||
public static void sendError(ICommandSender sender, String text) {
|
||||
text = LABEL + "\u00A74Error: \u00A7c" + text;
|
||||
IChatComponent component = assembleComponent(text);
|
||||
sender.addChatMessage(component);
|
||||
}
|
||||
|
||||
public static void sendError(ICommandSender sender, String format, Object... obs) {
|
||||
sendError(sender, String.format(format, obs));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -267,7 +267,8 @@ public class CustomNpcs {
|
||||
public void serverstart(FMLServerStartingEvent event) {
|
||||
event.registerServerCommand(new CommandNoppes());
|
||||
event.registerServerCommand(new CommandKamkeel());
|
||||
event.registerServerCommand(new CommandProfile());
|
||||
if(ConfigMain.ProfilesEnabled)
|
||||
event.registerServerCommand(new CommandProfile());
|
||||
}
|
||||
|
||||
private void registerNpc(Class<? extends Entity> cl, String name) {
|
||||
|
||||
@@ -88,6 +88,15 @@ public class CustomNpcsPermissions{
|
||||
public static final Permission SCRIPT_ITEM = new Permission("customnpcs.script.item");
|
||||
public static final Permission SCRIPT_BLOCK = new Permission("customnpcs.script.block");
|
||||
|
||||
// Profiles
|
||||
public static final Permission PROFILE_ADMIN = new Permission("customnpcs.profile.admin");
|
||||
public static final Permission PROFILE_CREATE = new Permission("customnpcs.profile.create");
|
||||
public static final Permission PROFILE_DELETE = new Permission("customnpcs.profile.delete");
|
||||
public static final Permission PROFILE_RENAME = new Permission("customnpcs.profile.rename");
|
||||
public static final Permission PROFILE_CHANGE = new Permission("customnpcs.profile.change");
|
||||
public static final Permission PROFILE_REGION_BYPASS = new Permission("customnpcs.profile.region-bypass");
|
||||
public static final Permission PROFILE_MAX = new Permission("customnpcs.profile.max.*");
|
||||
|
||||
public static CustomNpcsPermissions Instance;
|
||||
private Class<?> bukkit;
|
||||
private Method getPlayer;
|
||||
|
||||
@@ -17,7 +17,6 @@ import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.*;
|
||||
import noppes.npcs.api.event.IAnimationEvent;
|
||||
import noppes.npcs.api.event.IItemEvent;
|
||||
import noppes.npcs.api.gui.ICustomGui;
|
||||
import noppes.npcs.api.gui.IItemSlot;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||
import kamkeel.npcs.network.packets.data.*;
|
||||
|
||||
@@ -3,19 +3,20 @@ package noppes.npcs;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.ParticlePacket;
|
||||
import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiClosePacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiErrorPacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiTeleporterPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.DialogPacket;
|
||||
import kamkeel.npcs.network.packets.data.ParticlePacket;
|
||||
import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.DeleteNpcPacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.DialogPacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.EditNpcPacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.RolePacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiTeleporterPacket;
|
||||
import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.command.server.CommandBlockLogic;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -975,4 +976,142 @@ public class NoppesUtilServer {
|
||||
sb.append(seconds).append(" second").append(seconds == 1 ? "" : "s");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the player's data from the existing PlayerDataController and sends
|
||||
* a large packet to the client containing all the maps, including categories.
|
||||
*/
|
||||
public static void sendPlayerDataInfo(String playerName, EntityPlayerMP player) {
|
||||
PlayerData playerdata;
|
||||
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
|
||||
if(pl == null)
|
||||
playerdata = PlayerDataController.Instance.getDataFromUsername(playerName);
|
||||
else
|
||||
playerdata = PlayerDataController.Instance.getPlayerData(pl);
|
||||
|
||||
// Assemble quest maps:
|
||||
Map<String, Integer> questActiveMap = new HashMap<>();
|
||||
Map<String, Integer> questFinishedMap = new HashMap<>();
|
||||
Map<String, Integer> questCategoriesMap = new HashMap<>();
|
||||
QuestController qc = QuestController.Instance;
|
||||
PlayerQuestData qData = playerdata.questData;
|
||||
for (Integer questId : qData.activeQuests.keySet()) {
|
||||
if(!qc.quests.containsKey(questId))
|
||||
continue;
|
||||
Quest quest = qc.quests.get(questId);
|
||||
questActiveMap.put(quest.category.title + ": " + quest.title, questId);
|
||||
if (!questCategoriesMap.containsKey(quest.category.title))
|
||||
questCategoriesMap.put(quest.category.title, quest.category.id);
|
||||
}
|
||||
for (Integer questId : qData.finishedQuests.keySet()) {
|
||||
if(!qc.quests.containsKey(questId))
|
||||
continue;
|
||||
Quest quest = qc.quests.get(questId);
|
||||
questFinishedMap.put(quest.category.title + ": " + quest.title, questId);
|
||||
if (!questCategoriesMap.containsKey(quest.category.title))
|
||||
questCategoriesMap.put(quest.category.title, quest.category.id);
|
||||
}
|
||||
|
||||
// Assemble dialog maps:
|
||||
Map<String, Integer> dialogReadMap = new HashMap<>();
|
||||
Map<String, Integer> dialogCategoriesMap = new HashMap<>();
|
||||
PlayerDialogData dData = playerdata.dialogData;
|
||||
for (Integer dialogId : dData.dialogsRead) {
|
||||
if(!DialogController.Instance.dialogs.containsKey(dialogId))
|
||||
continue;
|
||||
Dialog dialog = DialogController.Instance.dialogs.get(dialogId);
|
||||
dialogReadMap.put(dialog.category.title + ": " + dialog.title, dialogId);
|
||||
if (!dialogCategoriesMap.containsKey(dialog.category.title))
|
||||
dialogCategoriesMap.put(dialog.category.title, dialog.category.id);
|
||||
}
|
||||
|
||||
// Assemble transport maps:
|
||||
Map<String, Integer> transportLocationsMap = new HashMap<>();
|
||||
Map<String, Integer> transportCategoriesMap = new HashMap<>();
|
||||
PlayerTransportData tData = playerdata.transportData;
|
||||
TransportController tc = TransportController.getInstance();
|
||||
for (Integer id : tData.transports) {
|
||||
TransportLocation location = tc.getTransport(id);
|
||||
if(location == null)
|
||||
continue;
|
||||
transportLocationsMap.put(location.category.title + ": " + location.name, id);
|
||||
if (!transportCategoriesMap.containsKey(location.category.title))
|
||||
transportCategoriesMap.put(location.category.title, location.category.id);
|
||||
}
|
||||
|
||||
// Assemble bank map:
|
||||
Map<String, Integer> bankMap = new HashMap<>();
|
||||
PlayerBankData bData = playerdata.bankData;
|
||||
BankController bc = BankController.getInstance();
|
||||
for (Integer bankId : bData.banks.keySet()) {
|
||||
if(!bc.banks.containsKey(bankId))
|
||||
continue;
|
||||
Bank bank = bc.banks.get(bankId);
|
||||
bankMap.put(bank.name, bankId);
|
||||
}
|
||||
|
||||
// Assemble faction map:
|
||||
Map<String, Integer> factionMap = new HashMap<>();
|
||||
PlayerFactionData fData = playerdata.factionData;
|
||||
FactionController fc = FactionController.getInstance();
|
||||
for (Integer factionId : fData.factionData.keySet()) {
|
||||
if(!fc.factions.containsKey(factionId))
|
||||
continue;
|
||||
Faction faction = fc.factions.get(factionId);
|
||||
factionMap.put(faction.name + "(" + fData.getFactionPoints(factionId) + ")", factionId);
|
||||
}
|
||||
|
||||
// Send the full packet with categories, active/finished data, dialogs, transports, banks, and factions.
|
||||
PlayerDataInfoPacket packet = new PlayerDataInfoPacket(playerName,
|
||||
questCategoriesMap, questActiveMap, questFinishedMap,
|
||||
dialogCategoriesMap, dialogReadMap,
|
||||
transportCategoriesMap, transportLocationsMap,
|
||||
bankMap, factionMap);
|
||||
PacketHandler.Instance.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a specific data entry from the player's data.
|
||||
*
|
||||
* The tabType parameter is used as follows:
|
||||
* 0: Quest – remove from both activeQuests and finishedQuests.
|
||||
* 1: Dialog – remove from dialogsRead.
|
||||
* 2: Transport – remove from transports.
|
||||
* 3: Bank – remove from banks.
|
||||
* 4: Factions – remove from factionData.
|
||||
*
|
||||
* The selectedKey is expected to be the string representation of the entry's ID.
|
||||
*/
|
||||
public static void removePlayerDataInfo(String playerName, int tabType, int value, EntityPlayerMP player) {
|
||||
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
|
||||
PlayerData playerdata;
|
||||
|
||||
EnumPlayerData enumPlayerData = EnumPlayerData.values()[tabType];
|
||||
if(pl == null)
|
||||
playerdata = PlayerDataController.Instance.getDataFromUsername(playerName);
|
||||
else
|
||||
playerdata = PlayerDataController.Instance.getPlayerData(pl);
|
||||
|
||||
if(enumPlayerData == EnumPlayerData.Quest) { // Quest removal
|
||||
playerdata.questData.activeQuests.remove(value);
|
||||
playerdata.questData.finishedQuests.remove(value);
|
||||
}
|
||||
if(enumPlayerData == EnumPlayerData.Dialog){ // Dialog removal
|
||||
playerdata.dialogData.dialogsRead.remove(value);
|
||||
}
|
||||
if(enumPlayerData == EnumPlayerData.Transport) { // Transport removal
|
||||
playerdata.transportData.transports.remove(value);
|
||||
}
|
||||
if(enumPlayerData == EnumPlayerData.Bank) { // Bank removal
|
||||
playerdata.bankData.banks.remove(value);
|
||||
}
|
||||
if(enumPlayerData == EnumPlayerData.Factions) { // Faction removal
|
||||
playerdata.factionData.factionData.remove(value);
|
||||
}
|
||||
playerdata.save();
|
||||
|
||||
if(pl != null) {
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import net.minecraftforge.event.entity.player.*;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.attribute.PlayerAttributeManager;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.PartyController;
|
||||
@@ -30,9 +31,9 @@ import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.items.ItemNpcTool;
|
||||
import noppes.npcs.quests.QuestItem;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
|
||||
import static noppes.npcs.config.ConfigMain.TrackedQuestUpdateFrequency;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class ScriptPlayerEventHandler {
|
||||
if (event.side == Side.SERVER && event.phase == TickEvent.Phase.START) {
|
||||
EntityPlayer player = event.player;
|
||||
|
||||
if (player.ticksExisted%10 == 0) {
|
||||
if (player.ticksExisted % 10 == 0) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
EventHooks.onPlayerTick(handler, scriptPlayer);
|
||||
@@ -59,6 +60,8 @@ public class ScriptPlayerEventHandler {
|
||||
EventHooks.onScriptItemUpdate(isw, player);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerAttributeManager.getTracker(player.getUniqueID()).updateIfChanged(player);
|
||||
}
|
||||
|
||||
if (PlayerDataController.Instance != null) {
|
||||
@@ -155,6 +158,11 @@ public class ScriptPlayerEventHandler {
|
||||
if(event.getPlayer() == null || event.getPlayer().worldObj == null)
|
||||
return;
|
||||
|
||||
if(event.getPlayer().getHeldItem() != null && event.getPlayer().getHeldItem().getItem() instanceof ItemNpcTool){
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!event.getPlayer().worldObj.isRemote && event.world instanceof WorldServer) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.getPlayer());
|
||||
|
||||
@@ -22,7 +22,6 @@ import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -41,10 +40,12 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
|
||||
import noppes.npcs.blocks.tiles.ITileIcon;
|
||||
import noppes.npcs.blocks.tiles.TileBanner;
|
||||
import noppes.npcs.config.ConfigDebug;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.*;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumPartyObjectives;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.controllers.PartyController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ServerTickHandler {
|
||||
|
||||
SyncController.syncPlayer(player);
|
||||
SyncController.syncEffects(player);
|
||||
ProfileController.login(player);
|
||||
ProfileController.Instance.login(player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package noppes.npcs.attribute;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* AttributeController is the central registry for attribute definitions.
|
||||
* It ensures that keys are unique.
|
||||
*/
|
||||
public class AttributeController {
|
||||
private static final Map<String, AttributeDefinition> definitions = new HashMap<>();
|
||||
|
||||
public static AttributeDefinition registerAttribute(String key, String displayName, AttributeValueType valueType) {
|
||||
if (definitions.containsKey(key)) {
|
||||
throw new IllegalArgumentException("Attribute already registered with key: " + key);
|
||||
}
|
||||
AttributeDefinition def = new AttributeDefinition(key, displayName, valueType);
|
||||
definitions.put(key, def);
|
||||
return def;
|
||||
}
|
||||
|
||||
public static AttributeDefinition getAttribute(String key) {
|
||||
return definitions.get(key);
|
||||
}
|
||||
|
||||
public static Collection<AttributeDefinition> getAllAttributes() {
|
||||
return definitions.values();
|
||||
}
|
||||
}
|
||||
Loaded 100 of 305 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user