mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-14 02:34:10 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
b848dc0d7a
8 files changed
+84
-8
No files matched your search
@@ -49,9 +49,6 @@ public final class CustomGuiClosePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player.openContainer instanceof ContainerCustomGui))
|
||||
return;
|
||||
|
||||
NBTTagCompound comp = ByteBufUtils.readNBT(in);
|
||||
EventHooks.onCustomGuiClose((IPlayer) NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(comp));
|
||||
}
|
||||
|
||||
@@ -390,6 +390,11 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerRightClick(PlayerDataScript handler, PlayerEvent.RightClickEvent event) {
|
||||
handler.callScript(EnumScriptType.RIGHT_CLICK, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onProfileChange(PlayerDataScript handler, IPlayer player, IProfile profile, int newSlot, int prevSlot, boolean post) {
|
||||
PlayerEvent.ProfileEvent.Changed event = new PlayerEvent.ProfileEvent.Changed(player, profile, newSlot, prevSlot, post);
|
||||
handler.callScript(EnumScriptType.PROFILE_CHANGE, event);
|
||||
|
||||
@@ -154,6 +154,7 @@ public class ScriptItemEventHandler {
|
||||
|
||||
ItemNpcTool.setColor(held.getTagCompound(), color);
|
||||
e.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraftforge.event.entity.item.ItemTossEvent;
|
||||
import net.minecraftforge.event.entity.living.*;
|
||||
import net.minecraftforge.event.entity.player.*;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
@@ -34,8 +35,10 @@ import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.items.ItemNpcTool;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
import noppes.npcs.quests.QuestItem;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.ItemEvent;
|
||||
|
||||
import static noppes.npcs.config.ConfigMain.TrackedQuestUpdateFrequency;
|
||||
|
||||
@@ -123,9 +126,43 @@ public class ScriptPlayerEventHandler {
|
||||
|
||||
if (!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer && event.entityPlayer instanceof EntityPlayerMP) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.entityPlayer);
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent(scriptPlayer, 1, NpcAPI.Instance().getIEntity(event.target));
|
||||
event.setCanceled(EventHooks.onPlayerInteract(handler, ev));
|
||||
IPlayer ip = NoppesUtilServer.getIPlayer(event.entityPlayer);
|
||||
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent rightClickEvent = new noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent(ip, 1, NpcAPI.Instance().getIEntity(event.target));
|
||||
boolean rightClick = EventHooks.onPlayerRightClick(handler, rightClickEvent);
|
||||
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent(ip, 1, NpcAPI.Instance().getIEntity(event.target));
|
||||
boolean interact = EventHooks.onPlayerInteract(handler, ev);
|
||||
|
||||
event.setCanceled(rightClick || interact);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(PlayerInteractEvent event) {
|
||||
if (event.entityPlayer == null || event.entityPlayer.worldObj == null || event.entityPlayer.worldObj.isRemote || !(event.entityPlayer instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
IPlayer ip = NoppesUtilServer.getIPlayer(event.entityPlayer);
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.entityPlayer);
|
||||
PlayerData pd = PlayerData.get(event.entityPlayer);
|
||||
if (pd == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR){
|
||||
if (pd.hadInteract) {
|
||||
pd.hadInteract = false;
|
||||
return;
|
||||
}
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent rightClickEvent = new noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent(ip, 0, null);
|
||||
event.setCanceled(EventHooks.onPlayerRightClick(handler, rightClickEvent));
|
||||
} else if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){
|
||||
pd.hadInteract = true;
|
||||
IWorld iw = (IWorld) NpcAPI.Instance().getIWorld(event.world);
|
||||
Object blockCtx = NpcAPI.Instance().getIBlock(iw, event.x, event.y, event.z);
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent rightClickEvent = new noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent(ip, 2, blockCtx);
|
||||
event.setCanceled(EventHooks.onPlayerRightClick(handler, rightClickEvent));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
||||
hookList.add(EnumScriptType.INIT.function);
|
||||
hookList.add(EnumScriptType.TICK.function);
|
||||
hookList.add(EnumScriptType.INTERACT.function);
|
||||
hookList.add(EnumScriptType.RIGHT_CLICK.function);
|
||||
hookList.add(EnumScriptType.ATTACK.function);
|
||||
hookList.add(EnumScriptType.ATTACKED.function);
|
||||
hookList.add(EnumScriptType.DAMAGED_ENTITY.function);
|
||||
|
||||
@@ -242,7 +242,7 @@ public class DataScript implements INpcScriptHandler {
|
||||
@Override
|
||||
public void callScript(String hookName, Event event) {
|
||||
try {
|
||||
EnumScriptType enumScriptType = EnumScriptType.valueOf(hookName);
|
||||
EnumScriptType enumScriptType = EnumScriptType.valueOfIgnoreCase(hookName);
|
||||
this.callScript(enumScriptType, event);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
@@ -13,13 +13,16 @@ import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.event.IItemEvent;
|
||||
import noppes.npcs.api.event.IPlayerEvent;
|
||||
import noppes.npcs.api.handler.data.IPlayerEffect;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
||||
import noppes.npcs.scripted.event.ItemEvent;
|
||||
|
||||
public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent {
|
||||
public final IPlayer player;
|
||||
@@ -650,6 +653,38 @@ public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class RightClickEvent extends PlayerEvent implements IPlayerEvent.RightClickEvent {
|
||||
|
||||
/**
|
||||
* 0:air, 1:entity, 2:block
|
||||
*/
|
||||
public final int type;
|
||||
public final Object target;
|
||||
|
||||
public RightClickEvent(IPlayer player, int type, Object target) {
|
||||
super(player);
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getHookName() {
|
||||
return EnumScriptType.RIGHT_CLICK.function;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Object getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpdateEvent extends PlayerEvent implements IPlayerEvent.UpdateEvent {
|
||||
public UpdateEvent(IPlayer player) {
|
||||
super(player);
|
||||
|
||||
Reference in new issue
Block a user