mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 11:33:06 +00:00
Added isGUIOpen() function, and setPosition function with a dimensionId parameter to ScriptPlayer.
This commit is contained in:
1 parent
27b88c1fce
commit
0d807b36d9
13 files changed
+84
-17
No files matched your search
@@ -178,4 +178,8 @@ public class CommonProxy implements IGuiHandler {
|
||||
public String getAchievementDesc(Achievement achievement) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isGUIOpen(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -397,5 +397,7 @@ public class NoppesUtilPlayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void isGUIOpen(EntityPlayerMP player){
|
||||
Server.sendData(player, EnumPacketClient.ISGUIOPEN);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ import net.minecraft.tileentity.TileEntityMobSpawner;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
@@ -706,4 +705,18 @@ public class NoppesUtilServer {
|
||||
|
||||
return (Entity)entity;
|
||||
}
|
||||
|
||||
public static void isGUIOpen(ByteBuf buffer, EntityPlayer player) throws IOException {
|
||||
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(player.getDisplayName());
|
||||
PlayerData playerdata;
|
||||
if(pl == null)
|
||||
playerdata = PlayerDataController.instance.getDataFromUsername(player.getDisplayName());
|
||||
else
|
||||
playerdata = PlayerDataController.instance.getPlayerData(pl);
|
||||
|
||||
boolean isGUIOpen = buffer.readBoolean();
|
||||
playerdata.setGUIOpen(isGUIOpen);
|
||||
|
||||
sendPlayerData(EnumPlayerData.Players, (EntityPlayerMP)player, player.getDisplayName());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
@@ -90,13 +89,19 @@ public class PacketHandlerServer{
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
|
||||
if(type == EnumPacketServer.IsGuiOpen) {
|
||||
isGuiOpenPacket(buffer, player);
|
||||
return;
|
||||
}
|
||||
|
||||
if(type.needsNpc && npc == null){
|
||||
|
||||
}
|
||||
else if(type.hasPermission() && !CustomNpcsPermissions.Instance.hasPermission(player, type.permission)){
|
||||
//player doesnt have permission todo this
|
||||
//player doesnt have permission to do this
|
||||
}
|
||||
else if(item == null )
|
||||
else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave))
|
||||
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
|
||||
else if(item.getItem() == CustomItems.wand)
|
||||
wandPackets(type, buffer, player, npc);
|
||||
@@ -120,7 +125,11 @@ public class PacketHandlerServer{
|
||||
LogWriter.error("Error with EnumPacketServer." + type, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void isGuiOpenPacket(ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
||||
NoppesUtilServer.isGUIOpen(buffer, player);
|
||||
}
|
||||
|
||||
private void scriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception {
|
||||
if(type == EnumPacketServer.ScriptDataSave){
|
||||
npc.script.readFromNBT(Server.readNBT(buffer));
|
||||
|
||||
@@ -588,6 +588,11 @@ public class ClientProxy extends CommonProxy {
|
||||
return achievement.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGUIOpen(){
|
||||
return Minecraft.getMinecraft().currentScreen != null;
|
||||
}
|
||||
|
||||
public static class FontContainer {
|
||||
private StringCache textFont = null;
|
||||
public boolean useCustomFont = true;
|
||||
|
||||
@@ -47,7 +47,6 @@ public class ClientTickHandler{
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouse(InputEvent.MouseInputEvent event){
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if(Mouse.getEventButton() == -1 && Mouse.getDWheel() == 0)
|
||||
return;
|
||||
|
||||
@@ -73,7 +72,7 @@ public class ClientTickHandler{
|
||||
}
|
||||
}
|
||||
|
||||
if((Keyboard.getEventKeyState() && time-this.buttonTime == 0) || !Keyboard.getEventKeyState()) {
|
||||
if(time-this.buttonTime == 0 || !Keyboard.getEventKeyState()) {
|
||||
boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29);
|
||||
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
|
||||
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
|
||||
|
||||
@@ -21,7 +21,6 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.ModelPartData;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.client.fx.EntityCustomFX;
|
||||
@@ -289,4 +288,7 @@ public class NoppesUtil {
|
||||
CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.Waypoint, player);
|
||||
}
|
||||
|
||||
public static void isGUIOpen(boolean isGUIOpen) {
|
||||
Client.sendData(EnumPacketServer.IsGuiOpen, isGUIOpen);
|
||||
}
|
||||
}
|
||||
@@ -254,8 +254,10 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
player.addChatMessage(new ChatComponentTranslation("Current font is %s", ClientProxy.Font.getName()));
|
||||
}
|
||||
}
|
||||
else if(type == EnumPacketClient.ISGUIOPEN){
|
||||
boolean isGUIOpen = Minecraft.getMinecraft().currentScreen != null;
|
||||
|
||||
NoppesUtil.isGUIOpen(isGUIOpen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
public enum EnumPacketClient {
|
||||
CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG
|
||||
CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN
|
||||
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public enum EnumPacketServer {
|
||||
RemoteTpToNpc,QuestGet, QuestCategoryGet,
|
||||
SaveTileEntity,
|
||||
NaturalSpawnGetAll, MailOpenSetup,
|
||||
DimensionsGet, DimensionTeleport, GetTileEntity, Gui, ;
|
||||
DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen;
|
||||
|
||||
public CustomNpcsPermissions.Permission permission = null;
|
||||
public boolean needsNpc = false;
|
||||
|
||||
@@ -39,10 +39,12 @@ public class PlayerData implements IExtendedEntityProperties{
|
||||
|
||||
public String playername = "";
|
||||
public String uuid = "";
|
||||
|
||||
|
||||
private EntityNPCInterface activeCompanion = null;
|
||||
public int companionID = 0;
|
||||
|
||||
public boolean isGUIOpen = false;
|
||||
|
||||
@Override
|
||||
public void saveNBTData(NBTTagCompound compound) {
|
||||
PlayerDataController.instance.savePlayerData(this);
|
||||
@@ -86,6 +88,7 @@ public class PlayerData implements IExtendedEntityProperties{
|
||||
player.worldObj.spawnEntityInWorld(npc);
|
||||
}
|
||||
}
|
||||
isGUIOpen = data.getBoolean("isGUIOpen");
|
||||
}
|
||||
public NBTTagCompound getNBT() {
|
||||
if(player != null){
|
||||
@@ -105,6 +108,7 @@ public class PlayerData implements IExtendedEntityProperties{
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
compound.setInteger("PlayerCompanionId", companionID);
|
||||
compound.setBoolean("isGUIOpen",isGUIOpen);
|
||||
|
||||
if(hasCompanion()){
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
@@ -118,7 +122,17 @@ public class PlayerData implements IExtendedEntityProperties{
|
||||
public void init(Entity entity, World world) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setGUIOpen(boolean bool) {
|
||||
isGUIOpen = bool;
|
||||
saveNBTData(null);
|
||||
}
|
||||
|
||||
public boolean getGUIOpen() {
|
||||
loadNBTData(null);
|
||||
return isGUIOpen;
|
||||
}
|
||||
|
||||
public boolean hasCompanion(){
|
||||
return activeCompanion != null && !activeCompanion.isDead;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import noppes.npcs.controllers.PlayerQuestData;
|
||||
import noppes.npcs.controllers.Quest;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.QuestData;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.ScriptItemStack;
|
||||
import noppes.npcs.scripted.ScriptPixelmonPlayerData;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
@@ -33,7 +34,6 @@ import noppes.npcs.util.ValueUtil;
|
||||
|
||||
public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T> implements IPlayer {
|
||||
public T player;
|
||||
private PlayerData data;
|
||||
public ScriptPlayer(T player){
|
||||
super(player);
|
||||
this.player = player;
|
||||
@@ -58,6 +58,13 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
NoppesUtilPlayer.teleportPlayer(player, x, y, z, player.dimension);
|
||||
}
|
||||
|
||||
public void setPosition(double x, double y, double z, int dimensionId){
|
||||
if (NpcAPI.Instance().getIWorld(dimensionId) == null)
|
||||
return;
|
||||
|
||||
NoppesUtilPlayer.teleportPlayer(player, x, y, z, dimensionId);
|
||||
}
|
||||
|
||||
public int getDimension(){
|
||||
return player.dimension;
|
||||
}
|
||||
@@ -370,4 +377,10 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
PlayerQuestData playerdata = PlayerDataController.instance.getPlayerData(player).questData;
|
||||
playerdata.checkQuestCompletion((EntityPlayer)this.entity, EnumQuestType.Item);
|
||||
}
|
||||
|
||||
public boolean checkGUIOpen() {
|
||||
NoppesUtilPlayer.isGUIOpen(player);
|
||||
PlayerData data = PlayerDataController.instance.getPlayerData(player);
|
||||
return data.getGUIOpen();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
|
||||
public void setPosition(double x, double y, double z);
|
||||
|
||||
public void setPosition(double x, double y, double z, int dimensionId);
|
||||
|
||||
public boolean hasFinishedQuest(int id);
|
||||
|
||||
public boolean hasActiveQuest(int id);
|
||||
@@ -170,4 +172,6 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
public ITimers getTimers();
|
||||
|
||||
public void updatePlayerInventory();
|
||||
|
||||
public boolean checkGUIOpen();
|
||||
}
|
||||
Reference in new issue
Block a user