mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 23:09:05 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
8c10235ee2
16 files changed
+205
-82
No files matched your search
@@ -442,17 +442,19 @@ public class ScriptPlayerEventHandler {
|
||||
return;
|
||||
|
||||
if(event.entityLiving.worldObj instanceof WorldServer) {
|
||||
boolean cancel = event.isCanceled();
|
||||
Entity source = NoppesUtilServer.GetDamageSource(event.source);
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
if(event.entityLiving instanceof EntityPlayer) {
|
||||
noppes.npcs.scripted.event.PlayerEvent.AttackedEvent pevent = new noppes.npcs.scripted.event.PlayerEvent.AttackedEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.entityLiving), source, event.ammount, event.source);
|
||||
event.setCanceled(EventHooks.onPlayerAttacked(handler, pevent));
|
||||
cancel = EventHooks.onPlayerAttacked(handler, pevent);
|
||||
}
|
||||
|
||||
if(event.source.getEntity() instanceof EntityPlayer) {
|
||||
noppes.npcs.scripted.event.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.AttackEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.source.getEntity()), event.entityLiving, event.ammount, event.source);
|
||||
event.setCanceled(EventHooks.onPlayerAttack(handler, pevent1));
|
||||
cancel = cancel || EventHooks.onPlayerAttack(handler, pevent1);
|
||||
}
|
||||
event.setCanceled(cancel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,19 +464,22 @@ public class ScriptPlayerEventHandler {
|
||||
return;
|
||||
|
||||
if(event.entityLiving.worldObj instanceof WorldServer) {
|
||||
boolean cancel = event.isCanceled();
|
||||
Entity source = NoppesUtilServer.GetDamageSource(event.source);
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
if(event.entityLiving instanceof EntityPlayer) {
|
||||
noppes.npcs.scripted.event.PlayerEvent.DamagedEvent pevent = new noppes.npcs.scripted.event.PlayerEvent.DamagedEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.entityLiving), source, event.ammount, event.source);
|
||||
event.setCanceled(EventHooks.onPlayerDamaged(handler, pevent));
|
||||
cancel = EventHooks.onPlayerDamaged(handler, pevent);
|
||||
event.ammount = pevent.damage;
|
||||
}
|
||||
|
||||
if(source instanceof EntityPlayer) {
|
||||
noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent((IPlayer)NpcAPI.Instance().getIEntity(source), event.entityLiving, event.ammount, event.source);
|
||||
event.setCanceled(EventHooks.onPlayerDamagedEntity(handler, pevent1));
|
||||
cancel = cancel || EventHooks.onPlayerDamagedEntity(handler, pevent1);
|
||||
event.ammount = pevent1.damage;
|
||||
}
|
||||
|
||||
event.setCanceled(cancel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.village.MerchantRecipeList;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -45,6 +46,7 @@ public class Server {
|
||||
CustomNpcs.Channel.sendToAllAround(new FMLProxyPacket(buffer,"CustomNPCs"), point);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LogWriter.error(enu + " Errored", e);
|
||||
}
|
||||
}
|
||||
public static void sendToAll(EnumPacketClient enu, Object... obs) {
|
||||
@@ -55,6 +57,7 @@ public class Server {
|
||||
CustomNpcs.Channel.sendToAll(new FMLProxyPacket(buffer,"CustomNPCs"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LogWriter.error(enu + " Errored", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +109,8 @@ public class Server {
|
||||
}
|
||||
if(buffer.array().length >= 32767){
|
||||
LogWriter.error("Packet " + enu + " was too big to be send");
|
||||
return false;
|
||||
LogWriter.script( "Issue occurred with the following Packet - " + enu + ":\n" + Arrays.toString(obs));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -324,8 +324,15 @@ public class ServerEventsHandler {
|
||||
|
||||
private void doQuest(EntityPlayer player, EntityLivingBase entity, boolean all) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
PlayerQuestData questData = playerData.questData;
|
||||
boolean checkCompletion = false;
|
||||
if (playerData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerQuestData questData = playerData.questData;
|
||||
if (questData == null) {
|
||||
return;
|
||||
}
|
||||
boolean checkCompletion = false;
|
||||
String entityName = EntityList.getEntityString(entity);
|
||||
|
||||
|
||||
@@ -343,6 +350,10 @@ public class ServerEventsHandler {
|
||||
|
||||
ArrayList<QuestData> activeQuestValues = new ArrayList<>(questData.activeQuests.values());
|
||||
for(QuestData data : activeQuestValues){
|
||||
if (data.quest == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data.quest.type != EnumQuestType.Kill && data.quest.type != EnumQuestType.AreaKill)
|
||||
continue;
|
||||
|
||||
@@ -360,9 +371,12 @@ public class ServerEventsHandler {
|
||||
|
||||
}
|
||||
|
||||
String name = entityName;
|
||||
QuestKill quest = (QuestKill) data.quest.questInterface;
|
||||
String name = entityName;
|
||||
if (entityName == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QuestKill quest = (QuestKill) data.quest.questInterface;
|
||||
Class entityType = EntityNPCInterface.class;
|
||||
if (quest.targetType == 2) {
|
||||
try {
|
||||
@@ -375,14 +389,19 @@ public class ServerEventsHandler {
|
||||
if (quest.targetType > 0 && !(entityType.isInstance(entity)))
|
||||
continue;
|
||||
|
||||
if (entity.getCommandSenderName() != null && quest.targets.containsKey(entity.getCommandSenderName()))
|
||||
name = entity.getCommandSenderName();
|
||||
else if (entity.getCommandSenderName() == null || !quest.targets.containsKey(name))
|
||||
continue;
|
||||
if (entity.getCommandSenderName() != null && quest.targets != null && quest.targets.containsKey(entity.getCommandSenderName())) {
|
||||
name = entity.getCommandSenderName();
|
||||
} else if (entity.getCommandSenderName() == null || quest.targets == null || !quest.targets.containsKey(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
checkCompletion = true;
|
||||
|
||||
HashMap<String, Integer> killed = quest.getKilled(data);
|
||||
HashMap<String, Integer> killed = quest.getKilled(data);
|
||||
if (killed == null) {
|
||||
killed = new HashMap<>();
|
||||
}
|
||||
|
||||
if (!killed.containsKey(name)) {
|
||||
killed.put(name, 1);
|
||||
} else if(killed.get(name) < quest.targets.get(name)) {
|
||||
|
||||
@@ -6,11 +6,13 @@ import net.minecraft.client.audio.SoundHandler;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class MusicController {
|
||||
public static MusicController Instance;
|
||||
private final HashSet<ScriptClientSound> sounds = new HashSet<>();
|
||||
private final HashMap<String, ScriptClientSound> sounds = new HashMap<>();
|
||||
private int playDelay;
|
||||
public ScriptClientSound playingSound;
|
||||
|
||||
@@ -36,7 +38,16 @@ public class MusicController {
|
||||
}
|
||||
|
||||
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
|
||||
this.sounds.removeIf(sound -> !soundHandler.isSoundPlaying(sound) && !sound.canRepeat() && !sound.paused);
|
||||
HashSet<String> keys = new HashSet<>();
|
||||
for (Map.Entry<String, ScriptClientSound> entry : this.sounds.entrySet()) {
|
||||
ScriptClientSound sound = entry.getValue();
|
||||
if (!soundHandler.isSoundPlaying(sound) && !sound.canRepeat() && !sound.paused) {
|
||||
keys.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
for (String key : keys) {
|
||||
this.sounds.remove(key);
|
||||
}
|
||||
|
||||
if (this.playDelay > 0) {
|
||||
this.playDelay--;
|
||||
@@ -75,7 +86,7 @@ public class MusicController {
|
||||
this.playingSound = clientSound;
|
||||
this.entity = entity;
|
||||
this.offRange = offRange;
|
||||
this.sounds.add(clientSound);
|
||||
this.sounds.put(clientSound.sound, clientSound);
|
||||
|
||||
try {
|
||||
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
|
||||
@@ -102,7 +113,7 @@ public class MusicController {
|
||||
this.playingSound = clientSound;
|
||||
this.entity = entity;
|
||||
this.offRange = offRange;
|
||||
this.sounds.add(clientSound);
|
||||
this.sounds.put(clientSound.sound, clientSound);
|
||||
|
||||
try {
|
||||
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
|
||||
@@ -131,10 +142,12 @@ public class MusicController {
|
||||
this.stopAllSounds();
|
||||
return;
|
||||
}
|
||||
this.sounds.add(clientSound);
|
||||
this.sounds.put(clientSound.sound, clientSound);
|
||||
}
|
||||
|
||||
public boolean isPlaying(String music) {
|
||||
if (this.sounds.containsKey(music)) return true;
|
||||
|
||||
if (this.playingSound != null && this.playingSound.sound.equals(music)) {
|
||||
ResourceLocation resource = new ResourceLocation(music);
|
||||
if (!this.playingSound.getPositionedSoundLocation().equals(resource)) {
|
||||
@@ -168,7 +181,7 @@ public class MusicController {
|
||||
|
||||
public void stopAllSounds() {
|
||||
this.stopMusic();
|
||||
for (ScriptClientSound sound : this.sounds) {
|
||||
for (ScriptClientSound sound : this.sounds.values()) {
|
||||
sound.stopSound();
|
||||
}
|
||||
this.sounds.clear();
|
||||
|
||||
@@ -169,14 +169,16 @@ public class ConfigScript
|
||||
}
|
||||
|
||||
public static boolean isScriptDev(EntityPlayer player) {
|
||||
boolean isOp = MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
|
||||
return (!ScriptOpsOnly || isOp) &&
|
||||
(Developer.ScriptUser.contains(player.getUniqueID()) ||
|
||||
Developer.Universal.contains(player.getUniqueID()));
|
||||
return Developer.ScriptUser.contains(player.getUniqueID()) || Developer.Universal.contains(player.getUniqueID());
|
||||
}
|
||||
|
||||
public static boolean canScript(EntityPlayer player, CustomNpcsPermissions.Permission perm) {
|
||||
boolean scriptDev = (!ScriptOpsOnly && Developer.ScriptUser.isEmpty()) || isScriptDev(player);
|
||||
return scriptDev && CustomNpcsPermissions.hasPermission(player, perm);
|
||||
boolean isOp = MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
|
||||
boolean scriptDev = isScriptDev(player);
|
||||
if(ScriptOpsOnly){
|
||||
return isOp || scriptDev;
|
||||
}
|
||||
|
||||
return scriptDev || CustomNpcsPermissions.hasPermission(player, perm);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class SyncController {
|
||||
for(int questID : category.quests.keySet()){
|
||||
Quest quest = category.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
if(questList.tagCount() > 40){
|
||||
if(questList.tagCount() > 20){
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
@@ -69,7 +69,7 @@ public class SyncController {
|
||||
for(int dialogID : category.dialogs.keySet()){
|
||||
Dialog dialog = category.dialogs.get(dialogID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
if(dialogList.tagCount() > 40){
|
||||
if(dialogList.tagCount() > 20){
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
@@ -100,7 +100,7 @@ public class SyncController {
|
||||
for(int dialogID : category.dialogs.keySet()){
|
||||
Dialog dialog = category.dialogs.get(dialogID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
if(dialogList.tagCount() > 40){
|
||||
if(dialogList.tagCount() > 20){
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
@@ -123,7 +123,7 @@ public class SyncController {
|
||||
for(int questID : category.quests.keySet()){
|
||||
Quest quest = category.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
if(questList.tagCount() > 40){
|
||||
if(questList.tagCount() > 20){
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
@@ -145,7 +145,7 @@ public class SyncController {
|
||||
for(int questID : questCategory.quests.keySet()){
|
||||
Quest quest = questCategory.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
if(questList.tagCount() > 40){
|
||||
if(questList.tagCount() > 20){
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
@@ -165,7 +165,7 @@ public class SyncController {
|
||||
for(int questID : dialogCategory.dialogs.keySet()){
|
||||
Dialog dialog = dialogCategory.dialogs.get(questID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
if(dialogList.tagCount() > 40){
|
||||
if(dialogList.tagCount() > 20){
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
@@ -284,7 +284,7 @@ public class SyncController {
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categoriesSync.put(category.id, category);
|
||||
DialogController.Instance.categories.put(category.id, category);
|
||||
}
|
||||
else if(synctype == SyncType.QUEST){
|
||||
QuestCategory category = QuestController.Instance.categories.get(buffer.readInt());
|
||||
|
||||
@@ -35,13 +35,13 @@ public class ItemNpcScripter extends Item{
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player){
|
||||
if(!world.isRemote)
|
||||
if (!world.isRemote) {
|
||||
if(!ConfigScript.canScript(player, CustomNpcsPermissions.TOOL_SCRIPTER)){
|
||||
player.addChatMessage(new ChatComponentTranslation("availability.permission"));
|
||||
}
|
||||
return itemStack;
|
||||
if(!ConfigScript.canScript(player, CustomNpcsPermissions.TOOL_SCRIPTER)){
|
||||
player.addChatMessage(new ChatComponentTranslation("availability.permission"));
|
||||
} else {
|
||||
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptEvent, player);
|
||||
}
|
||||
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptEvent, player);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
@@ -195,29 +195,51 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
return ((EntityNPCInterface)entity).wrappedNPC;
|
||||
else{
|
||||
ScriptEntityData data = (ScriptEntityData) entity.getExtendedProperties("ScriptedObject");
|
||||
if(data != null)
|
||||
return data.base;
|
||||
if(entity instanceof EntityPlayerMP)
|
||||
data = new ScriptEntityData(new ScriptPlayer<>((EntityPlayerMP) entity));
|
||||
else if(PixelmonHelper.isPixelmon(entity))
|
||||
return new ScriptPixelmon<EntityTameable>((EntityTameable) entity);
|
||||
else if(entity instanceof EntityAnimal)
|
||||
data = new ScriptEntityData(new ScriptAnimal<>((EntityAnimal) entity));
|
||||
else if(entity instanceof EntityMob)
|
||||
data = new ScriptEntityData(new ScriptMonster<>((EntityMob) entity));
|
||||
else if(entity instanceof EntityVillager)
|
||||
data = new ScriptEntityData(new ScriptVillager<>((EntityVillager) entity));
|
||||
else if(entity instanceof EntityLiving)
|
||||
data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity));
|
||||
else if(entity instanceof EntityLivingBase)
|
||||
data = new ScriptEntityData(new ScriptLivingBase<>((EntityLivingBase)entity));
|
||||
else if(entity instanceof EntityProjectile)
|
||||
data = new ScriptEntityData(new ScriptProjectile<>((EntityProjectile)entity));
|
||||
else if(entity instanceof EntityItem)
|
||||
data = new ScriptEntityData(new ScriptEntityItem<>((EntityItem)entity));
|
||||
else
|
||||
data = new ScriptEntityData(new ScriptEntity<>(entity));
|
||||
entity.registerExtendedProperties("ScriptedObject", data);
|
||||
boolean isDBC = false;
|
||||
if(entity instanceof EntityPlayerMP) {
|
||||
Set<?> keySet = entity.getEntityData().getCompoundTag("PlayerPersisted").func_150296_c();
|
||||
for (Object o : keySet) {
|
||||
String s = (String) o;
|
||||
if (s.contains("jrmc")) {
|
||||
isDBC = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data == null || data.base instanceof ScriptDBCPlayer != isDBC) {
|
||||
if (entity instanceof EntityPlayerMP) {
|
||||
ScriptEntityData newData;
|
||||
if (isDBC) {
|
||||
newData = new ScriptEntityData(new ScriptDBCPlayer<>((EntityPlayerMP) entity));
|
||||
} else {
|
||||
newData = new ScriptEntityData(new ScriptPlayer<>((EntityPlayerMP) entity));
|
||||
}
|
||||
if (data != null) {
|
||||
((ScriptEntity<?>) newData.base).copyTempData(data.base);
|
||||
}
|
||||
data = newData;
|
||||
}
|
||||
else if (PixelmonHelper.isPixelmon(entity))
|
||||
return new ScriptPixelmon<EntityTameable>((EntityTameable) entity);
|
||||
else if (entity instanceof EntityAnimal)
|
||||
data = new ScriptEntityData(new ScriptAnimal<>((EntityAnimal) entity));
|
||||
else if (entity instanceof EntityMob)
|
||||
data = new ScriptEntityData(new ScriptMonster<>((EntityMob) entity));
|
||||
else if (entity instanceof EntityVillager)
|
||||
data = new ScriptEntityData(new ScriptVillager<>((EntityVillager) entity));
|
||||
else if (entity instanceof EntityLiving)
|
||||
data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity));
|
||||
else if (entity instanceof EntityLivingBase)
|
||||
data = new ScriptEntityData(new ScriptLivingBase<>((EntityLivingBase) entity));
|
||||
else if (entity instanceof EntityProjectile)
|
||||
data = new ScriptEntityData(new ScriptProjectile<>((EntityProjectile) entity));
|
||||
else if (entity instanceof EntityItem)
|
||||
data = new ScriptEntityData(new ScriptEntityItem<>((EntityItem) entity));
|
||||
else
|
||||
data = new ScriptEntityData(new ScriptEntity<>(entity));
|
||||
entity.registerExtendedProperties("ScriptedObject", data);
|
||||
}
|
||||
return data.base;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.*;
|
||||
|
||||
public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
protected T entity;
|
||||
private Map<String,Object> tempData = new HashMap<String,Object>();
|
||||
private Map<String,Object> tempData = new HashMap<>();
|
||||
|
||||
public ScriptEntity(T entity){
|
||||
this.entity = entity;
|
||||
@@ -513,6 +513,12 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
return tempData.get(key);
|
||||
}
|
||||
|
||||
public void copyTempData(IEntity<?> scriptEntity) {
|
||||
if (scriptEntity != null) {
|
||||
this.tempData = ((ScriptEntity<?>) scriptEntity).tempData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tempdata gets cleared when the entity gets unloaded or the world restarts
|
||||
* @param key The key for the data stored
|
||||
|
||||
@@ -705,17 +705,9 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
return data.getGUIOpen();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ScriptDBCPlayer<T> getDBCPlayer() {
|
||||
Set keySet = player.getEntityData().getCompoundTag("PlayerPersisted").func_150296_c();
|
||||
Iterator iterator = keySet.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
String s = (String)iterator.next();
|
||||
if(s.contains("jrmc"))
|
||||
return new ScriptDBCPlayer<T>(this.player);
|
||||
}
|
||||
return null;
|
||||
return this instanceof ScriptDBCPlayer ? (ScriptDBCPlayer<T>) this : null;
|
||||
}
|
||||
|
||||
public boolean blocking() {
|
||||
|
||||
Reference in new issue
Block a user