This repository has been archived by the owner on Jul 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Magma command and Added a start to the API
- Loading branch information
Showing
7 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- ../src-base/minecraft/net/minecraftforge/fml/common/Loader.java | ||
+++ ../src-work/minecraft/net/minecraftforge/fml/common/Loader.java | ||
@@ -97,6 +97,7 @@ | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
+import org.magmafoundation.magma.api.ServerAPI; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@@ -757,6 +758,7 @@ | ||
modController.distributeStateMessage(LoaderState.AVAILABLE); | ||
GameData.freezeData(); | ||
FMLLog.log.info("Forge Mod Loader has successfully loaded {} mod{}", mods.size(), mods.size() == 1 ? "" : "s"); | ||
+ ServerAPI.mods.put("mods", mods.size()); | ||
progressBar.step("Completing Minecraft initialization"); | ||
} | ||
|
||
@@ -904,8 +906,10 @@ | ||
} | ||
} | ||
|
||
- if (difference.size() > 0) | ||
+ if (difference.size() > 0){ | ||
+ ServerAPI.modList.addAll(difference); | ||
FMLLog.log.info("Attempting connection with missing mods {} at {}", difference, side); | ||
+ } | ||
return true; | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
patches/net/minecraftforge/fml/common/network/handshake/FMLHandshakeServerState.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- ../src-base/minecraft/net/minecraftforge/fml/common/network/handshake/FMLHandshakeServerState.java | ||
+++ ../src-work/minecraft/net/minecraftforge/fml/common/network/handshake/FMLHandshakeServerState.java | ||
@@ -36,6 +36,7 @@ | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.registries.ForgeRegistry; | ||
import net.minecraftforge.registries.RegistryManager; | ||
+import org.magmafoundation.magma.api.PlayerAPI; | ||
|
||
enum FMLHandshakeServerState implements IHandshakeState<FMLHandshakeServerState> | ||
{ | ||
@@ -67,6 +68,10 @@ | ||
NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(); | ||
dispatcher.setModList(client.modList()); | ||
FMLLog.log.info("Client attempting to join with {} mods : {}", client.modListSize(), client.modListAsString()); | ||
+ if(client.modListSize() > 0) { | ||
+ PlayerAPI.mods.put(dispatcher.player, client.modListSize()); | ||
+ PlayerAPI.modList.put(dispatcher.player, client.modListAsString()); | ||
+ } | ||
String modRejections = FMLNetworkHandler.checkModList(client, Side.CLIENT); | ||
if (modRejections != null) | ||
{ |
11 changes: 11 additions & 0 deletions
11
patches/net/minecraftforge/fml/common/network/handshake/NetworkDispatcher.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- ../src-base/minecraft/net/minecraftforge/fml/common/network/handshake/NetworkDispatcher.java | ||
+++ ../src-work/minecraft/net/minecraftforge/fml/common/network/handshake/NetworkDispatcher.java | ||
@@ -103,7 +103,7 @@ | ||
public static final AttributeKey<Map<ResourceLocation, ForgeRegistry.Snapshot>> FML_GAMEDATA_SNAPSHOT = AttributeKey.valueOf("fml:gameDataSnapshot"); | ||
public final NetworkManager manager; | ||
private final PlayerList scm; | ||
- private EntityPlayerMP player; | ||
+ public EntityPlayerMP player; // Kettle - private -> public | ||
private ConnectionState state; | ||
private ConnectionType connectionType; | ||
private final Side side; |
83 changes: 83 additions & 0 deletions
83
src/main/java/org/magmafoundation/magma/api/PlayerAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.magmafoundation.magma.api; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.entity.player.EntityPlayerMP; | ||
import org.bukkit.craftbukkit.entity.CraftPlayer; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* PlayerAPI | ||
* | ||
* @author Hexeption [email protected] | ||
* @since 19/08/2019 - 04:57 pm | ||
*/ | ||
public class PlayerAPI { | ||
|
||
public static Map<EntityPlayerMP, Integer> mods = new ConcurrentHashMap<>(); | ||
public static Map<EntityPlayerMP, String> modList = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* Gets the NMS Player. | ||
* | ||
* @param player - A Bukkit player. | ||
* @return NMS player. | ||
*/ | ||
public static EntityPlayerMP getNMSPlayer(Player player) { | ||
return ((CraftPlayer) player).getHandle(); | ||
} | ||
|
||
/** | ||
* Gets the CraftBukkit Player. | ||
* | ||
* @param playerMP - NMS MpPlayer. | ||
* @return player - Bukkit Player | ||
*/ | ||
public static Player getCBPlayer(EntityPlayerMP playerMP) { | ||
return playerMP.getBukkitEntity().getPlayer(); | ||
} | ||
|
||
/** | ||
* Check is the player has access to Op. | ||
* | ||
* @param entityPlayer - The player. | ||
* @return boolean - is op or not. | ||
*/ | ||
public static boolean isOp(EntityPlayer entityPlayer) { | ||
return ServerAPI.getNMSServer().getPlayerList().canSendCommands(entityPlayer.getGameProfile()); | ||
} | ||
|
||
/** | ||
* Get player mod count. | ||
* | ||
* @param player - The player. | ||
* @return loaded mod count. | ||
*/ | ||
public static int getModSize(Player player) { | ||
return mods.get(getNMSPlayer(player)) == null ? 0 : mods.get(getNMSPlayer(player)); | ||
} | ||
|
||
/** | ||
* Gets the list of loaded mods. | ||
* | ||
* @param player - The player | ||
* @return list of loaded mods. | ||
*/ | ||
public static String getModlist(Player player) { | ||
return modList.get(getNMSPlayer(player)) == null ? "null" : modList.get(getNMSPlayer(player)); | ||
} | ||
|
||
/** | ||
* Checks if a mod is in the list. | ||
* | ||
* @param player - The player | ||
* @param modid for the mod wanted to check. | ||
* @return boolean - if it's in the list or not. | ||
*/ | ||
public static boolean hasMod(Player player, String modid) { | ||
return getModlist(player).contains(modid); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/org/magmafoundation/magma/api/ServerAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.magmafoundation.magma.api; | ||
|
||
import io.netty.util.internal.ConcurrentSet; | ||
import net.minecraft.server.MinecraftServer; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.craftbukkit.CraftServer; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* ServerAPI | ||
* | ||
* @author Hexeption [email protected] | ||
* @since 19/08/2019 - 04:47 pm | ||
*/ | ||
public class ServerAPI { | ||
|
||
public static Map<String, Integer> mods = new ConcurrentHashMap<>(); | ||
public static Set<String> modList = new ConcurrentSet<>(); | ||
|
||
/** | ||
* How many mods are loaded. | ||
* | ||
* @return int - loaded mods. | ||
*/ | ||
public static int getModSize() { | ||
return mods.get("mods") == null ? 0 : mods.get("mods"); | ||
} | ||
|
||
/** | ||
* List all loaded mods by name. | ||
* | ||
* @return String - List of mods. | ||
*/ | ||
public static String getModList() { | ||
return modList.toString(); | ||
} | ||
|
||
/** | ||
* Checks if a mod is in the list. | ||
* | ||
* @param modid for the mod to check. | ||
* @return boolean - if it's in the list or not. | ||
*/ | ||
public static boolean hasMod(String modid) { | ||
return getModList().contains(modid); | ||
} | ||
|
||
/** | ||
* Gets the Minecraft Server instance. | ||
* | ||
* @return MinecraftServer instance. | ||
*/ | ||
public static MinecraftServer getNMSServer() { | ||
return MinecraftServer.getServerInstance(); | ||
} | ||
|
||
/** | ||
* Gets the CraftBukkit Server | ||
* | ||
* @return CraftServer instance. | ||
*/ | ||
public static CraftServer getCBServer() { | ||
return (CraftServer) Bukkit.getServer(); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/org/magmafoundation/magma/commands/MagmaCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.magmafoundation.magma.commands; | ||
|
||
import net.minecraft.command.CommandBase; | ||
import net.minecraft.util.text.TextFormatting; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Location; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.magmafoundation.magma.api.PlayerAPI; | ||
import org.magmafoundation.magma.api.ServerAPI; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* MagmaCommand | ||
* | ||
* @author Hexeption [email protected] | ||
* @since 19/08/2019 - 04:40 pm | ||
*/ | ||
public class MagmaCommand extends Command { | ||
|
||
public MagmaCommand(String name) { | ||
super(name); | ||
|
||
this.description = "Magma commands"; | ||
this.usageMessage = "/magma [mods|playermods]"; | ||
this.setPermission("magma.commands.magma"); | ||
} | ||
|
||
@Override | ||
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException { | ||
if (args.length <= 1) { | ||
return CommandBase.getListOfStringsMatchingLastWord(args, "mods", "playermods"); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String commandLabel, String[] args) { | ||
|
||
if(!sender.hasPermission("magma.commands.magma")) { | ||
sender.sendMessage(ChatColor.RED + "You don't got the permission to execute this command!"); | ||
return false; | ||
} | ||
|
||
if(args.length == 0){ | ||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); | ||
return false; | ||
} | ||
|
||
switch (args[0].toLowerCase()){ | ||
case "mods": | ||
sender.sendMessage(ChatColor.GREEN + "" + ServerAPI.getModSize() + " " + ServerAPI.getModList()); | ||
break; | ||
case "playermods": | ||
if(args.length == 1){ | ||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); | ||
return false; | ||
} | ||
|
||
Player player = Bukkit.getPlayer(args[1].toString()); | ||
if(player != null){ | ||
sender.sendMessage(ChatColor.GREEN + "" + PlayerAPI.getModSize(player) + " " + PlayerAPI.getModlist(player)); | ||
}else{ | ||
sender.sendMessage(ChatColor.RED + "The player [" + args[1] + "] is not online."); | ||
} | ||
break; | ||
default: | ||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters