mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 13:49:05 +00:00
Fixed player script enabled button not working right on servers. Added more player events and a getDimension() method to ScriptPlayer. Set player scripts to be off by default.
This commit is contained in:
1 parent
047552d9e5
commit
a9bce4a3e3
9 files changed
+178
-44
No files matched your search
@@ -110,7 +110,7 @@ public class EventHooks {
|
||||
}
|
||||
|
||||
public static boolean onPlayerPickUp(PlayerDataScript handler, EntityItem entityItem) {
|
||||
PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem()));
|
||||
PickUpEvent event = new PickUpEvent(handler.getPlayer(), new ScriptItemStack(entityItem.getEntityItem()));//NpcAPI.Instance().getIItemStack(entityItem.getEntityItem()));
|
||||
handler.callScript(EnumScriptType.PICKUP, event, "item", event.item);
|
||||
return WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
@@ -138,6 +138,18 @@ public class EventHooks {
|
||||
return WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerLightning(PlayerDataScript handler) {
|
||||
PlayerEvent.LightningEvent event = new PlayerEvent.LightningEvent(handler.getPlayer());
|
||||
handler.callScript(EnumScriptType.LIGHTNING, event);
|
||||
return WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerSound(PlayerDataScript handler, String name, float pitch, float volume) {
|
||||
PlayerEvent.SoundEvent event = new PlayerEvent.SoundEvent(handler.getPlayer(), name, pitch, volume);
|
||||
handler.callScript(EnumScriptType.PLAYSOUND, event, "name", name, "pitch", pitch, "volume", volume);
|
||||
return WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerFall(PlayerDataScript handler, float distance) {
|
||||
PlayerEvent.FallEvent event = new PlayerEvent.FallEvent(handler.getPlayer(),distance);
|
||||
handler.callScript(EnumScriptType.FALL, event, "distance", event.distance);
|
||||
@@ -150,6 +162,13 @@ public class EventHooks {
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
|
||||
public static void onPlayerRespawn(PlayerDataScript handler) {
|
||||
PlayerEvent.RespawnEvent event = new PlayerEvent.RespawnEvent(handler.getPlayer());
|
||||
handler.callScript(EnumScriptType.RESPAWN, event);
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerLogout(PlayerDataScript handler) {
|
||||
LogoutEvent event = new LogoutEvent(handler.getPlayer());
|
||||
handler.callScript(EnumScriptType.LOGOUT, event);
|
||||
@@ -171,6 +190,12 @@ public class EventHooks {
|
||||
return WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerChangeDim(PlayerDataScript handler, int fromDim, int toDim) {
|
||||
PlayerEvent.ChangedDimension event = new PlayerEvent.ChangedDimension(handler.getPlayer(), fromDim, toDim);
|
||||
handler.callScript(EnumScriptType.CHANGED_DIM, event, "fromDim", event.fromDim, "toDim", event.toDim);
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerMouseClicked(EntityPlayerMP player, int button, int mouseWheel) {
|
||||
PlayerDataScript handler = PlayerData.get(player).scriptData;
|
||||
PlayerEvent.MouseClickedEvent event = new PlayerEvent.MouseClickedEvent(handler.getPlayer(), button, mouseWheel);
|
||||
|
||||
@@ -34,6 +34,8 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
|
||||
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
@@ -139,6 +141,14 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(PlayerEvent.PlayerChangedDimensionEvent event) {
|
||||
if(event.player.worldObj instanceof WorldServer) {
|
||||
PlayerDataScript handler = PlayerData.get(event.player).scriptData;
|
||||
EventHooks.onPlayerChangeDim(handler, event.fromDim, event.toDim);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(PlayerEvent.ItemPickupEvent event) {
|
||||
if(event.player.worldObj instanceof WorldServer) {
|
||||
@@ -166,6 +176,28 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(EntityStruckByLightningEvent event) {
|
||||
if(event.entity.worldObj instanceof WorldServer) {
|
||||
PlayerDataScript handler;
|
||||
if (event.entity instanceof EntityPlayer) {
|
||||
handler = PlayerData.get((EntityPlayer)event.entity).scriptData;
|
||||
EventHooks.onPlayerLightning(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(PlaySoundAtEntityEvent event) {
|
||||
if(event.entity.worldObj instanceof WorldServer) {
|
||||
PlayerDataScript handler;
|
||||
if (event.entity instanceof EntityPlayer) {
|
||||
handler = PlayerData.get((EntityPlayer)event.entity).scriptData;
|
||||
EventHooks.onPlayerSound(handler,event.name,event.pitch,event.volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(LivingDeathEvent event) {
|
||||
if(event.entityLiving.worldObj instanceof WorldServer) {
|
||||
@@ -206,6 +238,14 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(PlayerEvent.PlayerRespawnEvent event) {
|
||||
if(event.player.worldObj instanceof WorldServer) {
|
||||
PlayerDataScript handler = PlayerData.get(event.player).scriptData;
|
||||
EventHooks.onPlayerRespawn(handler);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void invoke(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if(event.player.worldObj instanceof WorldServer) {
|
||||
|
||||
@@ -26,11 +26,13 @@ import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
|
||||
public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener {
|
||||
private int activeTab = 0;
|
||||
public IScriptHandler handler;
|
||||
public PlayerDataScript handler;
|
||||
public Map<String, List<String>> languages = new HashMap();
|
||||
private int scriptLimit = 1;
|
||||
|
||||
public GuiScriptInterface() {
|
||||
this.drawDefaultBackground = true;
|
||||
@@ -54,14 +56,53 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
GuiMenuTopButton top;
|
||||
this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings"));
|
||||
|
||||
List<String> hookList = new ArrayList<String>();
|
||||
hookList.add("playerscript.disabled");
|
||||
hookList.add("playerscript.init");
|
||||
hookList.add("playerscript.tick");
|
||||
hookList.add("playerscript.interact");
|
||||
hookList.add("playerscript.damaged");
|
||||
hookList.add("playerscript.killed");
|
||||
hookList.add("playerscript.kills");
|
||||
hookList.add("playerscript.chat");
|
||||
hookList.add("playerscript.drop");
|
||||
hookList.add("playerscript.containerOpen");
|
||||
hookList.add("playerscript.login");
|
||||
hookList.add("playerscript.logout");
|
||||
hookList.add("playerscript.chat");
|
||||
hookList.add("playerscript.damagedentity");
|
||||
hookList.add("playerscript.keyPressed");
|
||||
hookList.add("playerscript.mouseClicked");
|
||||
hookList.add("playerscript.pickUp");
|
||||
hookList.add("playerscript.rangedLaunched");
|
||||
hookList.add("playerscript.pickupXP");
|
||||
hookList.add("playerscript.timer");
|
||||
hookList.add("playerscript.startItem");
|
||||
hookList.add("playerscript.usingItem");
|
||||
hookList.add("playerscript.stopItem");
|
||||
hookList.add("playerscript.finishItem");
|
||||
hookList.add("playerscript.fall");
|
||||
hookList.add("playerscript.playSound");
|
||||
hookList.add("playerscript.lightning");
|
||||
hookList.add("playerscript.break");
|
||||
hookList.add("playerscript.changedDim");
|
||||
hookList.add("playerscript.respawn");
|
||||
|
||||
int topXoffset = 0;
|
||||
int topYoffset = 0;
|
||||
for(int ta = 0; ta < this.handler.getScripts().size(); ++ta) {
|
||||
PlayerScriptContainer var10000 = (PlayerScriptContainer)this.handler.getScripts().get(ta);
|
||||
this.addTopButton(top = new GuiMenuTopButton(ta + 1, top, ta + 1 + ""));
|
||||
if(ta%15 == 0 && ta > 0) {
|
||||
topYoffset -= 20;
|
||||
topXoffset -= top.width+260;
|
||||
}
|
||||
this.addTopButton(top = new GuiMenuTopButton(ta + 1, top.xPosition+top.width + topXoffset, top.yPosition + topYoffset, ta + 1 + ""));
|
||||
topXoffset = 0;
|
||||
topYoffset = 0;
|
||||
scriptLimit = ta + 2;
|
||||
}
|
||||
|
||||
if(this.handler.getScripts().size() < 16) {
|
||||
this.addTopButton(new GuiMenuTopButton(12, top, "+"));
|
||||
}
|
||||
if(this.handler.getScripts().size() < 75)
|
||||
this.addTopButton(new GuiMenuTopButton(scriptLimit, top.xPosition+top.width, top.yPosition, "+"));
|
||||
|
||||
top = this.getTopButton(this.activeTab);
|
||||
if(top == null) {
|
||||
@@ -69,34 +110,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
top = this.getTopButton(0);
|
||||
}
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("playerscript.disabled");
|
||||
list.add("playerscript.init");
|
||||
list.add("playerscript.tick");
|
||||
list.add("playerscript.interact");
|
||||
list.add("playerscript.damaged");
|
||||
list.add("playerscript.killed");
|
||||
list.add("playerscript.kills");
|
||||
list.add("playerscript.chat");
|
||||
list.add("playerscript.drop");
|
||||
list.add("playerscript.containerOpen");
|
||||
list.add("playerscript.login");
|
||||
list.add("playerscript.logout");
|
||||
list.add("playerscript.chat");
|
||||
list.add("playerscript.damagedentity");
|
||||
list.add("playerscript.keyPressed");
|
||||
list.add("playerscript.mouseClicked");
|
||||
list.add("playerscript.pickUp");
|
||||
list.add("playerscript.rangedLaunched");
|
||||
list.add("playerscript.pickupXP");
|
||||
list.add("playerscript.timer");
|
||||
list.add("playerscript.startItem");
|
||||
list.add("playerscript.usingItem");
|
||||
list.add("playerscript.stopItem");
|
||||
list.add("playerscript.finishItem");
|
||||
list.add("playerscript.fall");
|
||||
list.add("playerscript.break");
|
||||
|
||||
top.active = true;
|
||||
if(this.activeTab > 0) {
|
||||
addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5));
|
||||
@@ -104,8 +117,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hooks.setSize(68, 198);
|
||||
hooks.guiLeft = guiLeft + 4;
|
||||
hooks.guiTop = guiTop + 14;
|
||||
hooks.setUnsortedList(list);
|
||||
hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),list);
|
||||
hooks.setUnsortedList(hookList);
|
||||
hooks.selected = getScriptHook(this.handler.getScripts().get(this.activeTab - 1),hookList);
|
||||
addScroll(hooks);
|
||||
|
||||
PlayerScriptContainer var7 = (PlayerScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
@@ -219,14 +232,15 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
this.displayGuiScreen(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
if(guibutton.id >= 0 && guibutton.id < 12) {
|
||||
if(guibutton.id >= 0 && guibutton.id < scriptLimit) {
|
||||
this.setScript();
|
||||
this.activeTab = guibutton.id;
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
if(guibutton.id == 12) {
|
||||
if(guibutton.id == scriptLimit) {
|
||||
this.handler.getScripts().add(new PlayerScriptContainer(this.handler));
|
||||
this.activeTab = this.handler.getScripts().size();
|
||||
this.initGui();
|
||||
@@ -273,7 +287,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
if(guibutton.id == 104) {
|
||||
this.handler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1);
|
||||
//ScriptController.Instance.playerScripts.enabled = (((GuiNpcButton)guibutton).getValue() == 1);
|
||||
this.handler.setEnabled((((GuiNpcButton)guibutton).getValue() == 1));
|
||||
}
|
||||
|
||||
if(guibutton.id == 105) {
|
||||
|
||||
@@ -60,6 +60,10 @@ public enum EnumScriptType {
|
||||
STOP_USING_ITEM("stopItem"),
|
||||
FINISH_USING_ITEM("finishItem"),
|
||||
FALL("fall"),
|
||||
LIGHTNING("lightning"),
|
||||
PLAYSOUND("playSound"),
|
||||
RESPAWN("respawn"),
|
||||
CHANGED_DIM("changedDim"),
|
||||
BREAK("break");
|
||||
|
||||
public String function;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
private long lastPlayerUpdate = 0L;
|
||||
public long lastInited = -1L;
|
||||
public boolean hadInteract = true;
|
||||
public boolean enabled = true;
|
||||
public boolean enabled = false;
|
||||
private static Map<Long, String> console = new TreeMap();
|
||||
private static List<Integer> errored = new ArrayList();
|
||||
|
||||
@@ -155,6 +155,7 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
}
|
||||
|
||||
public void setEnabled(boolean bo) {
|
||||
ScriptController.Instance.playerScripts.enabled = bo;
|
||||
this.enabled = bo;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface IItemStack {
|
||||
/**
|
||||
* @return The minecraft name for this item
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
@@ -114,6 +111,11 @@ public interface IItemStack {
|
||||
* @return Returns whether or not this item is a block
|
||||
*/
|
||||
public boolean isBlock();
|
||||
|
||||
public INbt getNbt();
|
||||
|
||||
public INbt getItemNbt();
|
||||
|
||||
/**
|
||||
* No support is given for this method. Dont use if you dont know what you are doing.
|
||||
* @return Minecraft ItemStack
|
||||
|
||||
@@ -50,6 +50,11 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
public void setPosition(double x, double y, double z){
|
||||
NoppesUtilPlayer.teleportPlayer(player, x, y, z, player.dimension);
|
||||
}
|
||||
|
||||
public int getDimension(){
|
||||
return player.dimension;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasFinishedQuest(int id){
|
||||
PlayerQuestData data = PlayerDataController.instance.getPlayerData(player).questData;
|
||||
|
||||
@@ -89,6 +89,23 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
}
|
||||
}
|
||||
|
||||
public static class RespawnEvent extends PlayerEvent {
|
||||
public RespawnEvent(IPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChangedDimension extends PlayerEvent {
|
||||
public final int fromDim;
|
||||
public final int toDim;
|
||||
|
||||
public ChangedDimension(IPlayer player, int fromDim, int toDim){
|
||||
super(player);
|
||||
this.fromDim = fromDim;
|
||||
this.toDim = toDim;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TimerEvent extends PlayerEvent {
|
||||
public final int id;
|
||||
|
||||
@@ -113,6 +130,27 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class LightningEvent extends PlayerEvent {
|
||||
public LightningEvent(IPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class SoundEvent extends PlayerEvent {
|
||||
public final String name;
|
||||
public final float pitch;
|
||||
public final float volume;
|
||||
|
||||
public SoundEvent(ScriptPlayer player, String name, float pitch, float volume) {
|
||||
super(player);
|
||||
this.name = name;
|
||||
this.pitch = pitch;
|
||||
this.volume = volume;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FallEvent extends PlayerEvent {
|
||||
public final float distance;
|
||||
|
||||
|
||||
Reference in new issue
Block a user