
Andrew2070
Members-
Posts
14 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Andrew2070's Achievements

Tree Puncher (2/8)
0
Reputation
-
[1.12.2] Intercepting/Editing Player Chat
Andrew2070 replied to Andrew2070's topic in Modder Support
Thank you for the feedback, I'll edit my code accordingly. -
Hi. I'm working on a permissions mod, thus I need to modify chat to include a player's prefix/suffix. I'm currently using the forge provided ServerChatEvent to accomplish this endeavor. I set the event cancellation to true, intercepted the message, performed my modifications and created a TextComponent out of it. However I can't find a method to send a chat message on behalf of the player. Essentially looking to sudo a message from the player to the rest of the server. Back in 1.7.10 this was possible through the player.addChatMessage() method. Now in 1.12.2 there is only the player.sendMessage() method, which only sends the intercepted chat message to the player and not to the rest of the server. Here's my code: package EmpireCoreLib.Events.Player; import java.awt.TextComponent; import java.util.List; import EmpireCoreLib.EmpireCoreLib; import EmpireCoreLib.Permissions.PermissionsList; import EmpireCoreLib.Permissions.User; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.text.TextComponentString; import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @Mod.EventBusSubscriber(modid = EmpireCoreLib.MODID) public class PlayerChatEvent { @SubscribeEvent public static void onPlayerChatEvent(ServerChatEvent event) { EntityPlayer player = (EntityPlayer) event.getPlayer(); if (event.getPlayer() != null) { event.setCanceled(true); for (User user : PermissionsList.users) { if (user.getUUID().equals(player.getUniqueID())) { String suffix = ""; String prefix = ""; String username = player.getName(); if (user.getPrefix().length() > 0) { prefix = "[" + user.getPrefix() + "] "; } if (user.getSuffix().length() > 0) { suffix = " [" + user.getSuffix() + "] "; } String message = prefix + username + suffix + ": " + event.getMessage(); event.setComponent((new TextComponentString(message))); player.sendMessage(new TextComponentString(message)); } } } } }
-
tried i got this: 01:25:47.801 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'com.github.johnrengelman.shadow' not found. 01:25:47.802 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultPluginRegistry.getTypeForId(DefaultPluginRegistry.java:91) 01:25:47.802 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultPluginContainer.getTypeForId(DefaultPluginContainer.java:105) 01:25:47.803 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:35) 01:25:47.803 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:117) 01:25:47.804 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36) 01:25:47.804 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:85) 01:25:47.805 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:130) 01:25:47.805 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:41) 01:25:47.806 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.Project$apply$0.call(Unknown Source) 01:25:47.807 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34) 01:25:47.809 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.Script$apply$0.callCurrent(Unknown Source) 01:25:47.810 [ERROR] [org.gradle.BuildExceptionReporter] at build_51m775vl65nq24j22lepeptkm0.run(/Users/Ali/Desktop/Eclipse/WorkSpace/Minecraft/Mods/1.7.10/Empires-Mod/build.gradle:18) 01:25:47.810 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52) 01:25:47.811 [ERROR] [org.gradle.BuildExceptionReporter] ... 34 more 01:25:47.811 [ERROR] [org.gradle.BuildExceptionReporter] 01:25:47.814 [LIFECYCLE] [org.gradle.BuildResultLogger] 01:25:47.814 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED 01:25:47.818 [LIFECYCLE] [org.gradle.BuildResultLogger] 01:25:47.819 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 12.017 secs
-
how do i instal it
-
Hi, so i was trying to build my mod after the 10 months of bug-testing and development. My friend set up the gradle scripts and i had nothing to worry about before when building test versions. Today I tried to build a official release by using ./gradlew -debug --stacktrace. It yielded me a jar file 600kb in size despite my dependencies being greater than 1Mb. (Build Successful) Furthermore when run in game the world would not load because of the dependencies not being provided: Minecraft Error: [B#349] UCHIJAAAAAAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) [B#349] UCHIJAAAAAAAAA FML{7.10.99.99} [Forge Mod Loader] (modpack.jar) [B#349] UCHIJAAAAAAAAA Forge{10.13.4.1614} [Minecraft Forge] (modpack.jar) [B#349] UCHIJAAEEEEEEE Empires{1.0.0} [Empires] (Empires-1.7.10-1.0.0A.jar) [B#349] [15:32:29] [Server thread/ERROR] [FML]: The following problems were captured during this phase [B#349] [15:32:29] [Server thread/ERROR] [FML]: Caught exception from Empires [B#349] java.lang.NoClassDefFoundError: org/sqlite/JDBC [B#349] at com.EmpireMod.Empires.Datasource.Bridge.BridgeSQLite.initConnection(BridgeSQLite.java:41) ~[BridgeSQLite.class:?] [B#349] at com.EmpireMod.Empires.Datasource.Bridge.BridgeSQLite.<init>(BridgeSQLite.java:28) ~[BridgeSQLite.class:?] Build.gradle: https://github.com/Andrew2070/Empires-Mod/blob/master/build.gradle Yes i have all the dependencies imported in my project libraries (eclipse). I don't know what to do at this point having spent hours trying to understand and solve the problem. My friend is too busy to explain it to me and i was wondering if anyone else out there knows? Thanks for your time.
-
I am trying to create a task that every hour updates a player's power. Similar to what the factions server plugin does, but i need it for my mod. Someone told me that i have to get a list of entities and keep filtering it down till i get players. What i don't understand is why can't i find a pre-done playerlist method in the libraries. There is 0 documentation on player lists, and there are methods for getting total players online. Factions also does their own timer in similar fashion to mine, it just has to work every hour of real time. Also if you pay some attention to my code you can see that i am getting a list of entities in the world.
-
Hi. I need to create a task that cycles through a list of players and executes a certain task: For some reason eclipse keeps on providing an error on my EntityPlayer player = (EntityPlayer) player; statement. I cannot figure out why, if anyone can provide me a hand it would be much appreciated: Additionally I would like if someone could tell me how best i could update my citizen profile of a player's power value. Should i just go into the citizen profile and where it says double power, make it double Power = newPower (from this class)? As much specific and detailed help that can be given will be greatly appreciated as i am still learning Java and forge modding. public class PowerUpdateTask { private double power = Config.instance.defaultPower.get(); private double maxpower = Config.instance.defaultMaxPower.get(); private void StartTimer(){ Timer timer = new Timer (); TimerTask hourlyTask = new TimerTask () { @Override public void run () { //Get A List of Entities: for(int i=0; i>MinecraftServer.getServer().getEntityWorld().loadedEntityList.size(); i++) { //Cycle Through List of Entities and choose one: Entity entity = (Entity) MinecraftServer.getServer().getEntityWorld().loadedEntityList.get(i); //Check To See if this probable Player Entity Exists: if (entity != null) { //Check To See if Entity is actually 100% a Player: EntityPlayer player = (EntityPlayer) player; if ( entity == player) { //Check To See if Player is Alive: if (player.isDead) continue; //Check To See if Player Has A Citizen Profile, If Not Then Make One: String playerName = player.getDisplayName(); Citizen res = EmpiresUniverse.instance.getOrMakeCitizen(playerName); //Calculate New Power For This Selected Player: double newPower = res.getPower() + Config.instance.PowerPerHour.get(); //Assign This New Power Through An Event? } } } } }; timer.schedule (hourlyTask, 0l, 1000*60*60); }; };
-
Hi. So i was designing a chat handler that provides a prefix to a user based on their "Empire". An "Empire" is essentially a "faction" that a player can join, create and invite others to. Now, what I am having problems with is when a player without a "Empire" chats: #1: Players with Empires get this printed: [Rank] [Empire] playername: message #2: Players without Empires that chat, crash the game because of the null. Now I know why it crashes, The code searches a database of Empires using their username to find their empire/rank. If they do not have one, then it just crashes the game despite my else statements. Here is my revised code: public class ChatHandler { public static final ChatHandler instance = new ChatHandler(); @SubscribeEvent public void onServerChatReceivedEvent(ServerChatEvent event) { EntityPlayer player = (EntityPlayer) event.player; if (event.player!=null) { event.setCanceled(true); List players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for (int i = 0; i < + players.size();i++) { EntityPlayer target = (EntityPlayer) players.get(i); Citizen res = EmpiresUniverse.instance.getOrMakeCitizen(target); Empire empire; Rank rank; if (CommandsEMP.getEmpireFromCitizen(res) == null) { String chat2 = player.getDisplayName() + ": " + event.message; target.addChatMessage(new ChatComponentTranslation(chat2)); } empire = CommandsEMP.getEmpireFromCitizen(res); rank = CommandsEMP.getRankFromCitizen(res); //TODO Add herochat support? //TODO Fix Crash when empire = null //TODO Abbreviate ranks (Leader = [L], Officer = [O], Member = [M]) String chat = "[" + rank +"]" + "§6[" + empire + "]" + "§f " + player.getDisplayName() + ": " + event.message; target.addChatMessage(new ChatComponentTranslation(chat)); } } } } hope someone can tell me what i am doing wrong, and how i can fix it.
-
Mc Version 1.7.10: Here is the crash report: https://hastebin.com/tewevevide.pas Also i just recently started modding so I don't understand what you mean by: EntityPlayer#addPrefix or at least ServerChatEvent#setComponent?
-
Added the subscribe event annotation, tried changing to static and non static. Now my game crashes whenever i chat.
-
So I don't understand why this won't work: package com.andrew2070.Empires.API.Chat; import java.util.List; import com.andrew2070.Empires.entities.Empire.Empire; import com.andrew2070.Empires.API.commands.CommandsEMP; import com.andrew2070.Empires.Datasource.EmpiresUniverse; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentTranslation; import net.minecraftforge.event.ServerChatEvent; //check player's selected Empire: public class Prefix { public static final Prefix instance = new Prefix(); public static void onServerChatReceivedEvent(ServerChatEvent event) { if (event.player != null) { EntityPlayer player = (EntityPlayer) event.player; if (player != null) { event.setCanceled(true); List players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for (int i = 0; i < + players.size(); i++) { EntityPlayer target = (EntityPlayer) players.get(i); if(target.getDisplayName().contains("Player")) { String name = player.getDisplayName(); Empire empire = CommandsEMP.getEmpireFromName(name); String chat = "[" + empire + "]" + player.getDisplayName() + event.message; target.addChatMessage(new ChatComponentTranslation(chat)); } } } } } } What it does is finds players, makes a list of them and then finds each of their "Empire" names. Then when they chat, it would print [Empire] Player: Message. Isn't working. My main class has this: FMLCommonHandler.instance().bus().register(Prefix.instance); MinecraftForge.EVENT_BUS.register(Prefix.instance);
-
Could you go into more detail, I haven't done much with Chat other than commands.
-
Hi. I have been working on a new protection system mod. It is essentially a combination of MyTown2 and Factions. I had a question that i need specifically answered to move on. #1: How do I add prefixes? ex: [Faction_Rank] [Faction] Player: Message Note --> I do have classes for the "Faction" and "Faction_Rank" part. I just wanted to know how many classes and the methods to add these to chat. If someone could give me a very specific breakdown that would be nice. (Looking around I don't see any explanation and I would rather learn than just be handed an answer) (But in this case, i am looking for both an answer and an explanation). Thanks.
-
Hello. I am relatively new to Minecraft Modding and have watched 46 Java tutorials already and read a few as well. Not to mention the other 30 something videos I watched for Minecraft Modding. In an effort to further my understanding I wanted to create a Mod that added a wide range of commands, and as i learn i'll let them yield things. I have about 28 command classes already made and they all implement the ICommand interface, but I had questions on how to improve them. #1. If i have a command that is /home and another that is /home 1 the game will only let me execute the /home, not the /home 1. #2. How can command creation be more efficient? I see lots of people use CommandMapper, CommandBase, CommandWrapper classes. #3. How can I color the message or text that is being printed to the user when they enter a command? #4. How can I add permission nodes to each command? Additionally I wanted to keep each Command's class simple with relatively 10-15 lines of code depending on what they have to yield. This is why I wanted to create some sort of CommandHandler or CommandManager that acts like an interface or annotation. That way I could just create a new command class and do @ Command { name, alias, usage, message} to create a command. This helps because instead of having to fill out the "template" from iCommand, i can do it in far less lines. Many thanks in advance.