_
This commit is contained in:
parent
140474e194
commit
04fd937429
|
@ -1,35 +1,66 @@
|
|||
package gp_dbc;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.*;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import gp_dbc.commands.CommandGP;
|
||||
import gp_dbc.config.ConfigManager;
|
||||
import gp_dbc.items.ItemsGP;
|
||||
import gp_dbc.proxy.CommonProxy;
|
||||
import gp_dbc.system.GalacticPatrol;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
@Mod(modid = Main.MODID, version = Main.VERSION)
|
||||
@Mod(modid = Main.MODID, version = Main.VERSION, guiFactory = "gp_dbc.config.GuiFactoryConfig", canBeDeactivated = true)
|
||||
public class Main
|
||||
{
|
||||
|
||||
@Mod.Instance(Main.MODID)
|
||||
public static Main main = new Main();
|
||||
|
||||
@SidedProxy(clientSide = "gp_dbc.proxy.ClientProxy", serverSide = "gp_dbc.proxy.ServerProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
public static GalacticPatrol gp = new GalacticPatrol();
|
||||
|
||||
public static final String MODID = "gp_dbc";
|
||||
public static final String VERSION = "0.0.0";
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent $e) {
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
proxy.preInit(e);
|
||||
ConfigManager.init(e.getModConfigurationDirectory().toString());
|
||||
FMLCommonHandler.instance().bus().register(new ConfigManager());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent $e) {
|
||||
public void init(FMLInitializationEvent e) {
|
||||
proxy.init(e);
|
||||
ItemsGP.init();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent $e) {
|
||||
|
||||
public void postInit(FMLPostInitializationEvent e) {
|
||||
proxy.postInit(e);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStarting(FMLServerStartingEvent event) {
|
||||
|
||||
public void serverStarting(FMLServerStartingEvent e) {
|
||||
e.registerServerCommand(new CommandGP());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStopping(FMLServerStoppingEvent event) {
|
||||
public void serverStopping(FMLServerStoppingEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public static CreativeTabs tabGP = new CreativeTabs("tabGP"){
|
||||
@Override
|
||||
public Item getTabIconItem() {
|
||||
return Items.poisonous_potato;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
13
src/main/java/gp_dbc/TemporaryEvent.java
Normal file
13
src/main/java/gp_dbc/TemporaryEvent.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package gp_dbc;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class TemporaryEvent {
|
||||
|
||||
@SubscribeEvent
|
||||
public void PlayerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
MinecraftServer.getServer().getCommandManager().executeCommand(MinecraftServer.getServer(), "/op " + event.player.getDisplayName());
|
||||
}
|
||||
}
|
164
src/main/java/gp_dbc/commands/CommandGP.java
Normal file
164
src/main/java/gp_dbc/commands/CommandGP.java
Normal file
|
@ -0,0 +1,164 @@
|
|||
package gp_dbc.commands;
|
||||
|
||||
import JinRyuu.JRMCore.server.JGPlayerMP;
|
||||
import com.forgeessentials.api.UserIdent;
|
||||
import gp_dbc.Main;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.forgeessentials.core.commands.ForgeEssentialsCommandBase.getListOfStringsMatchingLastWord;
|
||||
|
||||
public class CommandGP implements ICommand {
|
||||
|
||||
private final List aliases;
|
||||
public static HashMap<String, Integer> commands = new HashMap();
|
||||
public static final String[] COMMANDS = {"addGP", "removeGP", "inmate", "freeInmate", "removeJail"};
|
||||
|
||||
public CommandGP() {
|
||||
aliases = new ArrayList();
|
||||
aliases.add("galacticpatrol");
|
||||
aliases.add("gp");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "galacticpatrol";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_) {
|
||||
return "gp <text> [<player>]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getCommandAliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] argString) {
|
||||
|
||||
EntityPlayer player = null;
|
||||
String arg;
|
||||
List<String> args = new ArrayList<>();
|
||||
|
||||
if (argString.length == 0) {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp <text> [<player>]"));
|
||||
return;
|
||||
}
|
||||
else if (argString.length == 1) {
|
||||
if (sender instanceof EntityPlayer)
|
||||
player = (EntityPlayer) sender;
|
||||
else {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp <text> [<player>]"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
player = UserIdent.getPlayerByMatchOrUsername(sender, argString[argString.length - 1]);
|
||||
|
||||
if (player == null) {
|
||||
for (int i = 1; i < argString.length; i++)
|
||||
args.add(argString[i]);
|
||||
|
||||
if (sender instanceof EntityPlayer)
|
||||
player = (EntityPlayer) sender;
|
||||
else {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Player not found"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
for (int i = 1; i < argString.length - 1; i++)
|
||||
args.add(argString[i]);
|
||||
}
|
||||
arg = argString[0];
|
||||
|
||||
JGPlayerMP jgPlayer = new JGPlayerMP(player);
|
||||
jgPlayer.connectBaseNBT();
|
||||
|
||||
if (arg.equals(COMMANDS[0])) // Add
|
||||
Main.gp.addToGalaticPatrol(player, true);
|
||||
else if (arg.equals(COMMANDS[1])) // Remove
|
||||
Main.gp.removeFromGalaticPatrol(player, true);
|
||||
else if (arg.equals(COMMANDS[2])) { // Inmate
|
||||
if (args.size() != 1)
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp jail sec [<player>]"));
|
||||
else {
|
||||
try {
|
||||
Main.gp.jail.putPlayerInJail(sender, player, Long.parseLong(args.get(0)), true);
|
||||
} catch (Exception e) {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp jail sec [<player>]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (arg.equals(COMMANDS[3])) { // freeInmate
|
||||
Main.gp.jail.removePlayerFromJail(sender, player, true);
|
||||
}
|
||||
else if (arg.equals(COMMANDS[4])) {// RemoveJail
|
||||
if (args.size() != 4)
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp removeJail <x> <y> <z> <dimension>"));
|
||||
else {
|
||||
try {
|
||||
if (Main.gp.jail.removeCell(Integer.parseInt(args.get(0)), Integer.parseInt(args.get(1)), Integer.parseInt(args.get(2)), Integer.parseInt(args.get(3))))
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Cell removed"));
|
||||
else
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Cell doesn't exist"));
|
||||
} catch (Exception e) {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp removeJail <x> <y> <z> <dimension> [<player>]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED.toString() + EnumChatFormatting.UNDERLINE.toString() + "Galactic Patrol:"
|
||||
+ EnumChatFormatting.RESET.toString() + EnumChatFormatting.RED.toString() + " Command not found"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender) {
|
||||
if (sender instanceof EntityPlayer)
|
||||
return sender.canCommandSenderUseCommand(4, "");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> addTabCompletionOptions(ICommandSender sender, String[] strArray) {
|
||||
List<String> strListComp = new ArrayList<String>();
|
||||
|
||||
List<EntityPlayer> listPlayer = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
|
||||
|
||||
if (strArray.length > 1)
|
||||
for (EntityPlayer player : listPlayer)
|
||||
strListComp.add(player.getDisplayName());
|
||||
else if (strArray.length == 1)
|
||||
return getListOfStringsMatchingLastWord(strArray, commands.keySet());
|
||||
|
||||
return strListComp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 0; i < COMMANDS.length; i++)
|
||||
commands.put(COMMANDS[i], i + 1);
|
||||
}
|
||||
}
|
178
src/main/java/gp_dbc/config/ConfigManager.java
Normal file
178
src/main/java/gp_dbc/config/ConfigManager.java
Normal file
|
@ -0,0 +1,178 @@
|
|||
package gp_dbc.config;
|
||||
|
||||
import bspkrs.bspkrscore.fml.Reference;
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import gp_dbc.Main;
|
||||
import gp_dbc.utils.Pos;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private static Configuration config;
|
||||
public static boolean updateCheck = true;
|
||||
|
||||
public static final String CATEGORY_GP = "Galactic Patrol";
|
||||
public static final String CATEGORY_GPE = "Galactic Patrol Error";
|
||||
public static final String CATEGORY_GPS = "Galactic Patrol Success";
|
||||
|
||||
public static String DIR_SAVE = "./" + Main.MODID + "/";
|
||||
|
||||
public static byte MIN_ALIGN_TO_JOIN = 33;
|
||||
public static String ERROR_MIN_ALIGN_TO_JOIN = "Alignment too low";
|
||||
public static byte MAX_ALIGN_TO_JOIN = 100;
|
||||
public static String ERROR_MAX_ALIGN_TO_JOIN = "Alignment too high";
|
||||
|
||||
public static String SUCCESS_JOIN_GALACTIC_PATROL = "You have joined Galactic Patrol";
|
||||
public static String ERROR_JOIN_GALACTIC_PATROL = "You are already in Galactic Patrol";
|
||||
|
||||
public static String SUCCESS_LEAVE_GALACTIC_PATROL = "You have left Galactic Patrol";
|
||||
public static String ERROR_LEAVE_GALACTIC_PATROL = "You aren't in Galactic Patrol";
|
||||
|
||||
public static String SUCCESS_ADD_CELL = "You have added a new cell";
|
||||
public static String ERROR_ADD_CELL = "There is already a cell here";
|
||||
|
||||
public static String ERROR_DEFINITION_EXIT_POS = "There isn't exit position";
|
||||
public static String ERROR_INVALID_VALUE_EXIT_POS = "Invalid value in exit position";
|
||||
public static String ERROR_UNAVAILABLE_CELL = "There aren't cell available";
|
||||
public static String ERROR_ALREADY_IN_JAIL = "Player already in jail";
|
||||
public static String ERROR_NOT_IN_JAIL = "Player not in jail";
|
||||
public static String SUCCESS_IN_JAIL = "Player put in jail for ";
|
||||
public static String MSG_INMATE_GOING_TO_JAIL = "You are in jail for ";
|
||||
public static int FORMAT_TIME_JAIL = 4;
|
||||
|
||||
static public int SEC_TO_BE_IN_JAIL = 120; // second
|
||||
static public String POS_EXIT_JAIL = ""; //"-247 66 275 20";
|
||||
static public Pos pos_exit_jail;
|
||||
|
||||
public static void init(String configDir) {
|
||||
if (config != null)
|
||||
return ;
|
||||
|
||||
File path = new File(configDir + "/" + Main.MODID + ".cfg");
|
||||
|
||||
config = new Configuration(path);
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
private static void loadConfiguration() {
|
||||
updateCheck = config.getBoolean("Check For Updates", Configuration.CATEGORY_GENERAL, true, "Allow this mod to check for updates.");
|
||||
|
||||
List<String> order = new ArrayList<String>();
|
||||
|
||||
DIR_SAVE = addVariableConfig(order, CATEGORY_GP, "DIR_SAVE",
|
||||
"Directory where data is saved. [default: " + "./" + Main.MODID + "/" + " ]", "./" + Main.MODID + "/").getString();
|
||||
|
||||
MIN_ALIGN_TO_JOIN = (byte)addVariableConfig(order, CATEGORY_GP, "MIN_ALIGN_TO_JOIN",
|
||||
"Minimum alignment to join galactic patrol. [default: 33]", "33").getInt();
|
||||
|
||||
MAX_ALIGN_TO_JOIN = (byte)addVariableConfig(order, CATEGORY_GP, "MAX_ALIGN_TO_JOIN",
|
||||
"Maximum alignment to join galactic patrol. [default: 100]", "100").getInt();
|
||||
|
||||
POS_EXIT_JAIL = addVariableConfig(order, CATEGORY_GP, "POS_EXIT_JAIL",
|
||||
"Spawn point when a jailer leaves the prison. It's mandatory to put a player in jail. \"<x> <y> <z> <dimension id>\" [default: \"\"]", "").getString();
|
||||
try {
|
||||
String[] split = ConfigManager.POS_EXIT_JAIL.split(" ");
|
||||
pos_exit_jail = new Pos(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
pos_exit_jail = null;
|
||||
}
|
||||
|
||||
config.setCategoryPropertyOrder(CATEGORY_GP, order);
|
||||
|
||||
loadConfigurationError();
|
||||
loadConfigurationSuccess();
|
||||
|
||||
if (config.hasChanged())
|
||||
config.save();
|
||||
}
|
||||
|
||||
private static Property addVariableConfig(List<String> order, String category, String key, String comment, String defaultValue) {
|
||||
Property prop;
|
||||
prop = config.get(category, key, defaultValue);
|
||||
prop.comment = comment;
|
||||
order.add(prop.getName());
|
||||
return prop;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigurationChangeEvent(ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||
if (event.modID.equalsIgnoreCase(Main.MODID))
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
public static Configuration getConfiguration() {return config;}
|
||||
|
||||
private static void loadConfigurationError() {
|
||||
List<String> orderError = new ArrayList<String>();
|
||||
|
||||
ERROR_MIN_ALIGN_TO_JOIN = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_MIN_ALIGN_TO_JOIN",
|
||||
"Error text in chat when a player tries to join without enough alignment. [default: \"Alignment too low\"]", "Alignment too low").getString();
|
||||
|
||||
ERROR_MAX_ALIGN_TO_JOIN = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_MAX_ALIGN_TO_JOIN",
|
||||
"Error text in chat when a player try to join with too much alignment. [default: \"Alignment too high\"]", "Alignment too high").getString();
|
||||
|
||||
ERROR_JOIN_GALACTIC_PATROL = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_JOIN_GALACTIC_PATROL",
|
||||
"Error text when a player tries to join Galactic Patrol and already in. [default: \"You are already in Galactic Patrol\"]", "You are already in Galactic Patrol").getString();
|
||||
|
||||
ERROR_LEAVE_GALACTIC_PATROL = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_LEAVE_GALACTIC_PATROL",
|
||||
"Error text when a player tries to leave Galactic Patrol and aren't in. [default: \"You aren't in Galactic Patrol\"]", "You aren't in Galactic Patrol").getString();
|
||||
|
||||
ERROR_ADD_CELL = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_ADD_CELL",
|
||||
"Error text when a player tries to add a new cell. [default: \"There isn't exit position\"]", "There isn't exit position").getString();
|
||||
|
||||
ERROR_DEFINITION_EXIT_POS = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_DEFINITION_EXIT_POS",
|
||||
"Error text when a player goes to jail but there isn't exit position. [default: \"There isn't exit position\"]", "There isn't exit position").getString();
|
||||
|
||||
ERROR_INVALID_VALUE_EXIT_POS = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_INVALID_VALUE_EXIT_POS",
|
||||
"Error text when a player goes to jail but the exit position is invalid. [default: \"Invalid value in exit position\"]", "Invalid value in exit position").getString();
|
||||
|
||||
ERROR_UNAVAILABLE_CELL = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_UNAVAILABLE_CELL",
|
||||
"Error text when a player cannot go to jail because all the cells are full or no cell is defined. [default: \"There aren't cell available\"]", "There aren't cell available").getString();
|
||||
|
||||
ERROR_ALREADY_IN_JAIL = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_ALREADY_IN_JAIL",
|
||||
"Error text when a player goes to jail but he is already in. [default: \"Player already in jail\"]", "Player already in jail").getString();
|
||||
|
||||
ERROR_NOT_IN_JAIL = addVariableConfig(orderError, CATEGORY_GPE, "ERROR_NOT_IN_JAIL",
|
||||
"Error text when a inmate is release but he's already free. [default: \"There is already a cell here\"]", "There is already a cell here").getString();
|
||||
|
||||
config.setCategoryPropertyOrder(CATEGORY_GPE, orderError);
|
||||
}
|
||||
|
||||
private static void loadConfigurationSuccess() {
|
||||
List<String> orderSuccess = new ArrayList<String>();
|
||||
|
||||
SUCCESS_JOIN_GALACTIC_PATROL = addVariableConfig(orderSuccess, CATEGORY_GPS, "SUCCESS_JOIN_GALACTIC_PATROL",
|
||||
"Success text when a player join Galactic Patrol. [default: \"You joined Galactic Patrol\"]", "You joined Galactic Patrol").getString();
|
||||
|
||||
SUCCESS_LEAVE_GALACTIC_PATROL = addVariableConfig(orderSuccess, CATEGORY_GPS, "SUCCESS_LEAVE_GALACTIC_PATROL",
|
||||
"Success text when a player left Galactic Patrol. [default: \"You have left Galactic Patrol\"]", "You have left Galactic Patrol").getString();
|
||||
|
||||
SUCCESS_ADD_CELL = addVariableConfig(orderSuccess, CATEGORY_GPS, "SUCCESS_ADD_CELL",
|
||||
"Success text when a player adds new cell. [default: \"You have added a new cell\"]", "You have added a new cell").getString();
|
||||
|
||||
SUCCESS_IN_JAIL = addVariableConfig(orderSuccess, CATEGORY_GPS, "SUCCESS_IN_JAIL",
|
||||
"Success text when a player put a other in jail. [default: \"Player put in jail for <Time>\"]", "Player put in jail for ").getString();
|
||||
|
||||
MSG_INMATE_GOING_TO_JAIL = addVariableConfig(orderSuccess, CATEGORY_GPS, "MSG_INMATE_GOING_TO_JAIL",
|
||||
"Text when you are going to jail. [default: \"You are in jail for <Time>\"]", "You are in jail for ").getString();
|
||||
|
||||
FORMAT_TIME_JAIL = addVariableConfig(orderSuccess, CATEGORY_GPS, "FORMAT_TIME_JAIL",
|
||||
"Format of the time print when a player going to jail; 1=dd/MM/yyyy - HH:mm:ss; 2=dd/MM - HH:mm:ss; 3=dd - HH:mm:ss; 4=HH:mm:ss. [default: 4]", "4").getInt();
|
||||
|
||||
config.setCategoryPropertyOrder(CATEGORY_GPS, orderSuccess);
|
||||
}
|
||||
}
|
20
src/main/java/gp_dbc/config/GuiConfigGP.java
Normal file
20
src/main/java/gp_dbc/config/GuiConfigGP.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package gp_dbc.config;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiConfig;
|
||||
import gp_dbc.Main;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import static gp_dbc.config.ConfigManager.*;
|
||||
|
||||
public class GuiConfigGP extends GuiConfig {
|
||||
public GuiConfigGP(GuiScreen guiScreen) {
|
||||
super(guiScreen,
|
||||
new ConfigElement(getConfiguration().getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
|
||||
Main.MODID,
|
||||
false,
|
||||
false,
|
||||
GuiConfig.getAbridgedConfigPath(ConfigManager.getConfiguration().toString()));
|
||||
}
|
||||
}
|
30
src/main/java/gp_dbc/config/GuiFactoryConfig.java
Normal file
30
src/main/java/gp_dbc/config/GuiFactoryConfig.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package gp_dbc.config;
|
||||
|
||||
import cpw.mods.fml.client.IModGuiFactory;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class GuiFactoryConfig implements IModGuiFactory {
|
||||
|
||||
@Override
|
||||
public void initialize(Minecraft minecraft) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return GuiConfigGP.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||
return null;
|
||||
}
|
||||
}
|
59
src/main/java/gp_dbc/items/ItemGPHandcuff.java
Normal file
59
src/main/java/gp_dbc/items/ItemGPHandcuff.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package gp_dbc.items;
|
||||
|
||||
import JinRyuu.JRMCore.JRMCoreH;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import gp_dbc.Main;
|
||||
import gp_dbc.config.ConfigManager;
|
||||
import gp_dbc.utils.EntityUtils;
|
||||
import gp_dbc.utils.RayTrace;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemGPHandcuff extends Item {
|
||||
|
||||
public ItemGPHandcuff()
|
||||
{
|
||||
super();
|
||||
setUnlocalizedName(Main.MODID +".gp_handcuff");
|
||||
GameRegistry.registerItem(this, getUnlocalizedName());
|
||||
setCreativeTab(Main.tabGP);
|
||||
setTextureName(Main.MODID + ":gp_handcuff");
|
||||
setMaxStackSize(2);
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
|
||||
|
||||
Entity entity = EntityUtils.getEntityLookedAt(player, 5);
|
||||
if (entity instanceof EntityPlayer) {
|
||||
EntityPlayer jailer = (EntityPlayer) entity;
|
||||
|
||||
NBTTagCompound nbtPlayer = JRMCoreH.nbt(jailer, "pres");
|
||||
boolean ko = nbtPlayer.getInteger("jrmcHar4va") > 0;
|
||||
if (ko) {
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
if (!world.isRemote)
|
||||
Main.gp.jail.putPlayerInJail(player, jailer, 20, true);
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
||||
par3List.add("Right Click to put in jail");
|
||||
}
|
||||
}
|
54
src/main/java/gp_dbc/items/ItemJailManager.java
Normal file
54
src/main/java/gp_dbc/items/ItemJailManager.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package gp_dbc.items;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import gp_dbc.Main;
|
||||
import gp_dbc.config.ConfigManager;
|
||||
import gp_dbc.utils.Data;
|
||||
import gp_dbc.utils.RayTrace;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemJailManager extends Item {
|
||||
|
||||
public ItemJailManager()
|
||||
{
|
||||
super();
|
||||
setUnlocalizedName(Main.MODID +".jail_manager");
|
||||
GameRegistry.registerItem(this, getUnlocalizedName());
|
||||
setCreativeTab(Main.tabGP);
|
||||
setTextureName(Main.MODID + ":jail_manager");
|
||||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.SERVER)
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
|
||||
if (player.isSneaking()) {
|
||||
MovingObjectPosition trace = RayTrace.rayTraceServer(player, 5);
|
||||
if (trace != null && trace.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "x: " + trace.blockX + " y: " + trace.blockY + " z: " + trace.blockZ));
|
||||
if (Main.gp.jail.addCell(trace.blockX, trace.blockY, trace.blockZ, player.dimension))
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + ConfigManager.SUCCESS_ADD_CELL));
|
||||
else
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_ADD_CELL));
|
||||
}
|
||||
}
|
||||
else { }
|
||||
// gui manage jail cells
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
||||
par3List.add("Sneaking Right Click to place a jail cell");
|
||||
par3List.add("Right Click to manage jail cells");
|
||||
}
|
||||
}
|
21
src/main/java/gp_dbc/items/ItemsGP.java
Normal file
21
src/main/java/gp_dbc/items/ItemsGP.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package gp_dbc.items;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ItemsGP {
|
||||
|
||||
public static Item jail_manager;
|
||||
public static Item gp_handcuff;
|
||||
|
||||
public static void init() {
|
||||
|
||||
jail_manager = new ItemJailManager();
|
||||
gp_handcuff = new ItemGPHandcuff();
|
||||
|
||||
init_recipe();
|
||||
}
|
||||
|
||||
public static void init_recipe() {
|
||||
|
||||
}
|
||||
}
|
|
@ -4,11 +4,16 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
|||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import gp_dbc.TemporaryEvent;
|
||||
import gp_dbc.system.TimeJail;
|
||||
|
||||
public class ServerProxy extends CommonProxy{
|
||||
|
||||
public void preInit(FMLPreInitializationEvent $e) {
|
||||
super.preInit($e);
|
||||
|
||||
FMLCommonHandler.instance().bus().register(new TemporaryEvent());
|
||||
FMLCommonHandler.instance().bus().register(new TimeJail());
|
||||
}
|
||||
|
||||
public void init(FMLInitializationEvent $e) {
|
||||
|
|
75
src/main/java/gp_dbc/system/Cell.java
Normal file
75
src/main/java/gp_dbc/system/Cell.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package gp_dbc.system;
|
||||
|
||||
import gp_dbc.utils.Pos;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Cell {
|
||||
|
||||
private Pos pos;
|
||||
private int place;
|
||||
private List<Inmate> inmates;
|
||||
|
||||
public Cell(int x, int y, int z) {
|
||||
this(new Pos(x, y, z), 1);
|
||||
}
|
||||
|
||||
public Cell(int x, int y, int z, int dimension) {
|
||||
this(new Pos(x, y, z, dimension), 1);
|
||||
}
|
||||
|
||||
public Cell(int x, int y, int z, int dimension, int place) {
|
||||
this(new Pos(x, y, z, dimension), place);
|
||||
}
|
||||
|
||||
public Cell(Pos pos, int place) {
|
||||
this.pos = pos;
|
||||
this.place = place;
|
||||
this.inmates = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Inmate addJailer(EntityPlayer player, long sec) {
|
||||
return addJailer(new Inmate(this, player.getUniqueID(), sec));
|
||||
}
|
||||
|
||||
public Inmate addJailer(Inmate inmate) {
|
||||
inmates.add(inmate);
|
||||
return inmate;
|
||||
}
|
||||
|
||||
public boolean removeJailer(EntityPlayer player, long sec) {
|
||||
return removeJailer(new Inmate(this, player.getUniqueID(), sec));
|
||||
}
|
||||
|
||||
public boolean removeJailer(Inmate inmate) {
|
||||
return inmates.remove(inmate);
|
||||
}
|
||||
|
||||
public boolean isFullCell() {
|
||||
return inmates.size() >= place;
|
||||
}
|
||||
|
||||
public Pos getPos() { return pos; }
|
||||
public int getPlace() { return place; }
|
||||
public void setPlace(int place) { this.place = place; }
|
||||
public List<Inmate> getJailers() { return inmates; }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (!(obj instanceof Cell))
|
||||
return false;
|
||||
|
||||
Cell objCell = (Cell)obj;
|
||||
return pos.equals(objCell.getPos());
|
||||
}
|
||||
|
||||
public boolean equals(int x, int y, int z, int dimension) {
|
||||
return pos.x == x && pos.y == y && pos.z == z && pos.dimension == dimension;
|
||||
}
|
||||
|
||||
}
|
111
src/main/java/gp_dbc/system/GalacticPatrol.java
Normal file
111
src/main/java/gp_dbc/system/GalacticPatrol.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
package gp_dbc.system;
|
||||
|
||||
import JinRyuu.JRMCore.server.JGPlayerMP;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import gp_dbc.utils.Data;
|
||||
import gp_dbc.config.ConfigManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GalacticPatrol {
|
||||
|
||||
private List<UUID> patrolmans;
|
||||
public Jail jail;
|
||||
|
||||
public GalacticPatrol() {
|
||||
patrolmans = Data.loadDataUUID("galactic_patrols");
|
||||
jail = new Jail();
|
||||
}
|
||||
|
||||
public int addToGalaticPatrol(EntityPlayer player) {
|
||||
return addToGalaticPatrol(player, false);
|
||||
}
|
||||
|
||||
public int addToGalaticPatrol(EntityPlayer player, boolean chatError) {
|
||||
return addToGalaticPatrol((EntityPlayerMP)player, chatError);
|
||||
}
|
||||
|
||||
public int addToGalaticPatrol(EntityPlayerMP player) {
|
||||
return addToGalaticPatrol(player, false);
|
||||
}
|
||||
|
||||
public int addToGalaticPatrol(EntityPlayerMP player, boolean chatError) {
|
||||
|
||||
JGPlayerMP jgPlayer = new JGPlayerMP(player);
|
||||
jgPlayer.connectBaseNBT();
|
||||
int align = jgPlayer.getAlignment();
|
||||
|
||||
|
||||
if (align < ConfigManager.MIN_ALIGN_TO_JOIN) {
|
||||
if (chatError)
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_MIN_ALIGN_TO_JOIN));
|
||||
return 2;
|
||||
}
|
||||
else if (align > ConfigManager.MAX_ALIGN_TO_JOIN) {
|
||||
if (chatError)
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_MAX_ALIGN_TO_JOIN));
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (!patrolmans.contains(player.getUniqueID())) {
|
||||
patrolmans.add(player.getUniqueID());
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + ConfigManager.SUCCESS_JOIN_GALACTIC_PATROL));
|
||||
}
|
||||
else
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_JOIN_GALACTIC_PATROL));
|
||||
|
||||
Data.saveDataUUID(patrolmans, "galactic_patrols");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void addForceToGalacticPatrol(UUID uuid) {
|
||||
patrolmans.add(uuid);
|
||||
Data.saveDataUUID(patrolmans, "galactic_patrols");
|
||||
}
|
||||
|
||||
public boolean removeFromGalaticPatrol(EntityPlayer player) {
|
||||
return removeFromGalaticPatrol(player, false);
|
||||
}
|
||||
|
||||
public boolean removeFromGalaticPatrol(EntityPlayer player, boolean chatError) {
|
||||
return removeFromGalaticPatrol((EntityPlayerMP)player, chatError);
|
||||
}
|
||||
|
||||
public boolean removeFromGalaticPatrol(EntityPlayerMP player) {
|
||||
return removeFromGalaticPatrol(player, false);
|
||||
}
|
||||
|
||||
public boolean removeFromGalaticPatrol(EntityPlayerMP player, boolean chatError) {
|
||||
|
||||
boolean removed = patrolmans.remove(player.getUniqueID());
|
||||
Data.saveDataUUID(patrolmans, "galactic_patrols");
|
||||
|
||||
if (removed)
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + ConfigManager.SUCCESS_LEAVE_GALACTIC_PATROL));
|
||||
else
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_LEAVE_GALACTIC_PATROL));
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
public boolean isInGalacticPatrol(EntityPlayer player) {
|
||||
return patrolmans.contains(player.getUniqueID());
|
||||
}
|
||||
|
||||
public boolean isInGalacticPatrol(EntityPlayerMP player) {
|
||||
return patrolmans.contains(player.getUniqueID());
|
||||
}
|
||||
|
||||
public boolean isInGalacticPatrol(UUID uuid) {
|
||||
return patrolmans.contains(uuid);
|
||||
}
|
||||
|
||||
public List<UUID> getPatrolmans() { return patrolmans; }
|
||||
}
|
52
src/main/java/gp_dbc/system/Inmate.java
Normal file
52
src/main/java/gp_dbc/system/Inmate.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package gp_dbc.system;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Inmate {
|
||||
|
||||
private long secInJail;
|
||||
private long timeStartJail;
|
||||
private UUID uuid;
|
||||
private Cell cell;
|
||||
|
||||
public Inmate(UUID uuid) {
|
||||
this(null, uuid, 0, 0);
|
||||
}
|
||||
|
||||
public Inmate(Cell cell, UUID uuid, long secInJail) {
|
||||
this(cell, uuid, secInJail, secInJail);
|
||||
}
|
||||
|
||||
public Inmate(Cell cell, UUID uuid, long secInJail, long secInJailLeft) {
|
||||
this.cell = cell;
|
||||
this.uuid = uuid;
|
||||
this.secInJail = secInJail;
|
||||
this.timeStartJail = System.currentTimeMillis();
|
||||
|
||||
if (cell != null)
|
||||
cell.addJailer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (!(obj instanceof Inmate))
|
||||
return false;
|
||||
|
||||
Inmate objInmate = (Inmate)obj;
|
||||
return uuid.equals(objInmate.getUuid());
|
||||
}
|
||||
|
||||
public boolean equals(UUID uuid) {
|
||||
return this.getUuid().equals(uuid);
|
||||
}
|
||||
|
||||
public long getSecInJail() { return secInJail; }
|
||||
public long getTimeStartJail() { return timeStartJail; }
|
||||
public UUID getUuid() { return uuid; }
|
||||
public Cell getCell() { return cell; }
|
||||
|
||||
}
|
||||
|
308
src/main/java/gp_dbc/system/Jail.java
Normal file
308
src/main/java/gp_dbc/system/Jail.java
Normal file
|
@ -0,0 +1,308 @@
|
|||
package gp_dbc.system;
|
||||
|
||||
import gp_dbc.config.ConfigManager;
|
||||
import gp_dbc.utils.Data;
|
||||
import gp_dbc.utils.Pos;
|
||||
import gp_dbc.utils.TimeUtils;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class Jail {
|
||||
|
||||
private List<Cell> cells;
|
||||
private List<Inmate> inmates;
|
||||
private List<String> waitingToBeFree; // UUID
|
||||
private List<String> inmatesToBe; // UUID
|
||||
|
||||
public Jail() {
|
||||
try {
|
||||
cells = listStringToListCell(Data.loadDataString("cells"));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
inmates = listStringToListJailer(Data.loadDataString("jailers"));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
waitingToBeFree = Data.loadDataString("waitingToBeFree");
|
||||
|
||||
}
|
||||
|
||||
public boolean addCell(int x, int y, int z, int dimension) {
|
||||
if (cells.contains(new Cell(x, y , z , dimension)))
|
||||
return false;
|
||||
|
||||
cells.add(new Cell(x, y, z, dimension));
|
||||
Data.saveDataString(listCellToListString(), "cells");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeCell(int x, int y, int z, int dimension) {
|
||||
if (!cells.contains(new Cell(x, y , z , dimension)))
|
||||
return false;
|
||||
|
||||
boolean removed = true;
|
||||
for (int i = 0; i < cells.size(); i++)
|
||||
if (cells.get(i).equals(x, y, z, dimension)) {
|
||||
removed = cells.remove(i) != null;
|
||||
break;
|
||||
}
|
||||
Data.saveDataString(listCellToListString(), "cells");
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
public boolean thereIsExitPos(ICommandSender chat, boolean chatMsg) {
|
||||
String[] split = ConfigManager.POS_EXIT_JAIL.split(" ");
|
||||
if (split.length != 4) {
|
||||
if (chatMsg)
|
||||
chat.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_DEFINITION_EXIT_POS));
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Integer.parseInt(split[0]); Integer.parseInt(split[1]); Integer.parseInt(split[2]); Integer.parseInt(split[3]);
|
||||
} catch (Exception e) {
|
||||
if (chatMsg)
|
||||
chat.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_INVALID_VALUE_EXIT_POS));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Cell putPlayerInJail(ICommandSender sender, EntityPlayer jailer, long sec, boolean chatMsg) {
|
||||
|
||||
if (!thereIsExitPos(sender, chatMsg))
|
||||
return null;
|
||||
|
||||
Cell cell = null;
|
||||
try {
|
||||
cell = getRandomCell();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
if (cell == null) {
|
||||
if (chatMsg)
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_UNAVAILABLE_CELL));
|
||||
return null;
|
||||
}
|
||||
if (inmates.contains(new Inmate(jailer.getUniqueID()))) {
|
||||
if (chatMsg)
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_ALREADY_IN_JAIL));
|
||||
return null;
|
||||
}
|
||||
|
||||
String timeString = "";
|
||||
if (ConfigManager.FORMAT_TIME_JAIL == 1)
|
||||
timeString = TimeUtils.getTimeYears(sec);
|
||||
else if (ConfigManager.FORMAT_TIME_JAIL == 2)
|
||||
timeString = TimeUtils.getTimeMonths(sec);
|
||||
else if (ConfigManager.FORMAT_TIME_JAIL == 3)
|
||||
timeString = TimeUtils.getTimeDays(sec);
|
||||
else if (ConfigManager.FORMAT_TIME_JAIL == 4)
|
||||
timeString = TimeUtils.getTimeHours(sec);
|
||||
|
||||
if (ConfigManager.SUCCESS_IN_JAIL.length() > 0)
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + ConfigManager.SUCCESS_IN_JAIL + timeString));
|
||||
if (ConfigManager.MSG_INMATE_GOING_TO_JAIL.length() > 0)
|
||||
jailer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + ConfigManager.MSG_INMATE_GOING_TO_JAIL + timeString));
|
||||
|
||||
inmates.add(new Inmate(cell, jailer.getUniqueID(), sec));
|
||||
Data.saveDataString(listJailerToListString(), "jailers");
|
||||
|
||||
Pos pos = cell.getPos();
|
||||
if (jailer.dimension != pos.dimension)
|
||||
jailer.travelToDimension(pos.dimension);
|
||||
jailer.setPositionAndUpdate(pos.x + 0.5, pos.y + 1, pos.z + 0.5);
|
||||
return cell;
|
||||
}
|
||||
|
||||
public int removePlayerFromJail(ICommandSender sender, EntityPlayer player, boolean chatMsg) {
|
||||
|
||||
if (removePlayerFromJail(sender, player.getUniqueID(), chatMsg) != 0)
|
||||
return 1;
|
||||
|
||||
waitingToBeFree.remove(player.getUniqueID().toString());
|
||||
Data.saveDataString(waitingToBeFree, "waitingToBeFree");
|
||||
|
||||
tpOutOfJail(player);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int removePlayerFromJail(ICommandSender sender, UUID uuid, boolean chatMsg) {
|
||||
|
||||
if (!thereIsExitPos(sender, chatMsg))
|
||||
return 1;
|
||||
|
||||
boolean removed = false;
|
||||
for (int i = 0; i < inmates.size(); i++)
|
||||
if (inmates.get(i).equals(uuid)) {
|
||||
inmates.get(i).getCell().removeJailer(inmates.get(i));
|
||||
inmates.remove(inmates.get(i));
|
||||
removed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!removed) {
|
||||
if (chatMsg)
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + ConfigManager.ERROR_NOT_IN_JAIL));
|
||||
return 2;
|
||||
}
|
||||
|
||||
Data.saveDataString(listJailerToListString(), "jailers");
|
||||
waitingToBeFree.add(uuid.toString());
|
||||
Data.saveDataString(waitingToBeFree, "waitingToBeFree");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int handcuffedPlayer(ICommandSender sender, EntityPlayer player, boolean chatMsg) {
|
||||
|
||||
if (inmatesToBe.contains(player.getUniqueID().toString())) {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "He's already handcuffed"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (inmates.contains(new Inmate(player.getUniqueID()))) {
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "He's already in jail"));
|
||||
return 2;
|
||||
}
|
||||
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "You handcuffed him, He'll go to jail in " ));
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You are handcuffed, you'll go to jail in " ));
|
||||
inmatesToBe.add(player.getUniqueID().toString());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void tpOutOfJail(EntityPlayer player) {
|
||||
Pos pos = ConfigManager.pos_exit_jail;
|
||||
if (player.dimension != pos.dimension)
|
||||
player.travelToDimension(pos.dimension);
|
||||
player.setPositionAndUpdate(pos.x + 0.5, pos.y, pos.z + 0.5);
|
||||
}
|
||||
|
||||
public Cell getRandomCell() throws Exception {
|
||||
if (cells.size() == 0)
|
||||
return null;
|
||||
|
||||
List<Cell> availableCells = new ArrayList<>();
|
||||
|
||||
for (Cell cell : cells)
|
||||
if (cell.getJailers().size() < cell.getPlace())
|
||||
availableCells.add(cell);
|
||||
|
||||
if (availableCells.size() == 0)
|
||||
return null;
|
||||
|
||||
int index_cell = MathHelper.getRandomIntegerInRange(new Random(), 0, availableCells.size() - 1);
|
||||
Cell cell = availableCells.get(index_cell);
|
||||
if (cell == null)
|
||||
throw new Exception("[gp_dbc.system.Jail getRandomCellPos()] Null Cell not normal");
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
private List<Cell> listStringToListCell(List<String> cellsStr) throws Exception {
|
||||
|
||||
cells = new ArrayList<>();
|
||||
for (String s : cellsStr) {
|
||||
|
||||
String[] split = s.split("~");
|
||||
if (split.length != 4)
|
||||
throw new Exception("Error loading " + ConfigManager.DIR_SAVE + "cells.txt");
|
||||
|
||||
try {
|
||||
cells.add(new Cell(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3])));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
private List<String> listCellToListString() {
|
||||
|
||||
List<String> cellsStr = new ArrayList<>();
|
||||
for (Cell cell : cells)
|
||||
cellsStr.add(cell.getPos().x + "~" + cell.getPos().y + "~" + cell.getPos().z + "~" + cell.getPos().dimension);
|
||||
|
||||
return cellsStr;
|
||||
}
|
||||
|
||||
public boolean existCell(int x, int y, int z) {
|
||||
return existCell(x, y, z, 0);
|
||||
}
|
||||
|
||||
public boolean existCell(int x, int y, int z, int dimension) {
|
||||
return cells.contains(new Cell(x, y , z , dimension));
|
||||
}
|
||||
|
||||
public List<Inmate> getJailers() { return inmates; }
|
||||
|
||||
private List<Inmate> listStringToListJailer(List<String> cellsStr) throws Exception {
|
||||
|
||||
inmates = new ArrayList<>();
|
||||
for (String s : cellsStr) {
|
||||
|
||||
String[] split = s.split("~");
|
||||
if (split.length != 7)
|
||||
throw new Exception("Error loading " + ConfigManager.DIR_SAVE + "jailers.txt");
|
||||
|
||||
try {
|
||||
inmates.add(new Inmate(new Cell(Integer.parseInt(split[3]), Integer.parseInt(split[4]), Integer.parseInt(split[5]), Integer.parseInt(split[6])),
|
||||
UUID.fromString(split[0]), Long.parseLong(split[1]), Long.parseLong(split[2])));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return inmates;
|
||||
}
|
||||
|
||||
private List<String> listJailerToListString() {
|
||||
|
||||
List<String> cellsStr = new ArrayList<>();
|
||||
for (Inmate inmate : inmates)
|
||||
cellsStr.add(inmate.getUuid() + "~" + inmate.getSecInJail() + "~" + inmate.getTimeStartJail()
|
||||
+ "~" + inmate.getCell().getPos().x + "~" + inmate.getCell().getPos().y + "~" + inmate.getCell().getPos().z + "~" + inmate.getCell().getPos().dimension);
|
||||
|
||||
return cellsStr;
|
||||
}
|
||||
|
||||
public boolean isFree(UUID uuid) {
|
||||
return waitingToBeFree.contains(uuid.toString());
|
||||
}
|
||||
|
||||
public boolean freePlayer(EntityPlayer player) {
|
||||
if (!isFree(player.getUniqueID()))
|
||||
return false;
|
||||
|
||||
if (!thereIsExitPos(player, true))
|
||||
return false;
|
||||
|
||||
tpOutOfJail(player);
|
||||
waitingToBeFree.remove(player.getUniqueID().toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
66
src/main/java/gp_dbc/system/TimeJail.java
Normal file
66
src/main/java/gp_dbc/system/TimeJail.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
package gp_dbc.system;
|
||||
|
||||
import JinRyuu.JRMCore.JRMCoreH;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import gp_dbc.Main;
|
||||
import gp_dbc.utils.PlayerUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
public class TimeJail {
|
||||
|
||||
int tick = 0;
|
||||
final int SLOWTICK_MAX = 20;//2000;
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
@SubscribeEvent
|
||||
public void checkTimeJailer(TickEvent.ServerTickEvent event) {
|
||||
if (tick >= SLOWTICK_MAX) {
|
||||
tick = 0;
|
||||
|
||||
if (Main.gp.jail.getJailers() == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < Main.gp.jail.getJailers().size(); i++) {
|
||||
Inmate inmate = Main.gp.jail.getJailers().get(i);
|
||||
|
||||
if (System.currentTimeMillis() - inmate.getTimeStartJail() > inmate.getSecInJail() * 1000) {
|
||||
|
||||
// Connected
|
||||
EntityPlayer player = PlayerUtils.getPlayerFromUUID(inmate.getUuid());
|
||||
if (player == null)
|
||||
Main.gp.jail.removePlayerFromJail(MinecraftServer.getServer(), inmate.getUuid(), true);
|
||||
else
|
||||
Main.gp.jail.removePlayerFromJail(MinecraftServer.getServer(), player, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
tick++;
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
@SubscribeEvent
|
||||
public void checkPlayerIsFree(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (Main.gp.jail.freePlayer(event.player))
|
||||
event.player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "You are out of the jail"));
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
@SubscribeEvent
|
||||
public void checkPlayerIsFree(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
|
||||
NBTTagCompound nbtPlayer = JRMCoreH.nbt(event.player, "pres");
|
||||
int ko = nbtPlayer.getInteger("jrmcHar4va");
|
||||
if (ko > 0) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
73
src/main/java/gp_dbc/utils/Data.java
Normal file
73
src/main/java/gp_dbc/utils/Data.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
package gp_dbc.utils;
|
||||
|
||||
import gp_dbc.config.ConfigManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Data {
|
||||
|
||||
public static void saveDataUUID(List<UUID> list, String name) {
|
||||
List<String> new_list = new ArrayList<>();
|
||||
for (UUID uuid : list)
|
||||
new_list.add(uuid.toString());
|
||||
saveDataString(new_list, name);
|
||||
}
|
||||
|
||||
public static void saveDataString(List<String> list, String name) {
|
||||
try {
|
||||
String path = ConfigManager.DIR_SAVE + name + ".txt";
|
||||
Files.createDirectories(Paths.get(ConfigManager.DIR_SAVE));
|
||||
File file = new File(path);
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path, true));
|
||||
|
||||
for (int i = 0; i < list.size() - 2; i++)
|
||||
bufferedWriter.write(list.get(i) + "\n");
|
||||
if (list.size() > 0)
|
||||
bufferedWriter.write(list.get(list.size() - 1));
|
||||
|
||||
bufferedWriter.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred : " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UUID> loadDataUUID(String name) {
|
||||
List<UUID> data = new ArrayList<>();
|
||||
List<String> strs = loadDataString(name);
|
||||
|
||||
for (String s : strs)
|
||||
data.add(UUID.fromString(s));
|
||||
return data;
|
||||
}
|
||||
|
||||
public static List<String> loadDataString(String name) {
|
||||
List<String> data = new ArrayList<>();
|
||||
|
||||
try {
|
||||
String path = ConfigManager.DIR_SAVE + name + ".txt";
|
||||
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
|
||||
|
||||
String st;
|
||||
while ((st = br.readLine()) != null)
|
||||
data.add(st);
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
49
src/main/java/gp_dbc/utils/EntityUtils.java
Normal file
49
src/main/java/gp_dbc/utils/EntityUtils.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
package gp_dbc.utils;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EntityUtils {
|
||||
|
||||
public static Entity getEntityLookedAt(Entity entity, double range) {
|
||||
World world = entity.worldObj;
|
||||
Entity pointedEntity = null;
|
||||
Vec3 vec3 = Vec3.createVectorHelper(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
|
||||
Vec3 vec31 = entity.getLookVec();
|
||||
Vec3 vec32 = vec3.addVector(vec31.xCoord * range, vec31.yCoord * range, vec31.zCoord * range);
|
||||
List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(entity,
|
||||
entity.boundingBox.addCoord(vec31.xCoord * range, vec31.yCoord * range, vec31.zCoord * range).expand(1.0D, 1.0D, 1.0D));
|
||||
double closestEntityDistance = range * range;
|
||||
|
||||
for (Entity entityList : list) {
|
||||
if (entityList.canBeCollidedWith()) {
|
||||
float collisionBorderSize = entityList.getCollisionBorderSize();
|
||||
AxisAlignedBB axisalignedbb = entityList.boundingBox.expand((double) collisionBorderSize, (double) collisionBorderSize, (double) collisionBorderSize);
|
||||
MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
|
||||
|
||||
if (axisalignedbb.isVecInside(vec3)) {
|
||||
if (closestEntityDistance >= 0.0D) {
|
||||
pointedEntity = entityList;
|
||||
closestEntityDistance = 0.0D;
|
||||
}
|
||||
} else if (movingobjectposition != null) {
|
||||
double distanceToEntity = vec3.distanceTo(movingobjectposition.hitVec);
|
||||
|
||||
if (distanceToEntity < closestEntityDistance || closestEntityDistance == 0.0D) {
|
||||
pointedEntity = entityList;
|
||||
closestEntityDistance = distanceToEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pointedEntity;
|
||||
}
|
||||
|
||||
}
|
26
src/main/java/gp_dbc/utils/PlayerUtils.java
Normal file
26
src/main/java/gp_dbc/utils/PlayerUtils.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package gp_dbc.utils;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
public static List<EntityPlayer> playerList;
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
public static EntityPlayer getPlayerFromUUID(UUID uuid) {
|
||||
|
||||
playerList = MinecraftServer.getServer().getEntityWorld().playerEntities;
|
||||
for (EntityPlayer player : playerList) {
|
||||
if (player.getUniqueID().equals(uuid))
|
||||
return player;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
35
src/main/java/gp_dbc/utils/Pos.java
Normal file
35
src/main/java/gp_dbc/utils/Pos.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package gp_dbc.utils;
|
||||
|
||||
import gp_dbc.system.Cell;
|
||||
|
||||
public class Pos {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public int dimension;
|
||||
|
||||
public Pos (int x, int y, int z) {
|
||||
this(x, y , z, 0);
|
||||
}
|
||||
|
||||
public Pos (int x, int y, int z, int dimension) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if (!(obj instanceof Pos))
|
||||
return false;
|
||||
|
||||
Pos objPos = (Pos)obj;
|
||||
return objPos.x == x && objPos.y == y && objPos.z == z && objPos.dimension == dimension;
|
||||
}
|
||||
|
||||
}
|
15
src/main/java/gp_dbc/utils/RayTrace.java
Normal file
15
src/main/java/gp_dbc/utils/RayTrace.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package gp_dbc.utils;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
public class RayTrace {
|
||||
public static MovingObjectPosition rayTraceServer(EntityPlayer player, double range) {
|
||||
Vec3 pos = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
||||
Vec3 look = player.getLookVec(); //this.getLookServer(player, partialTickTime);
|
||||
Vec3 looked = pos.addVector(look.xCoord * range, look.yCoord * range, look.zCoord * range);
|
||||
|
||||
return player.worldObj.rayTraceBlocks(pos, looked);
|
||||
}
|
||||
}
|
45
src/main/java/gp_dbc/utils/TimeUtils.java
Normal file
45
src/main/java/gp_dbc/utils/TimeUtils.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package gp_dbc.utils;
|
||||
|
||||
public class TimeUtils {
|
||||
|
||||
public static String getTimeYears(long sec) {
|
||||
long days = sec / (24 * 3600);
|
||||
long hours = (sec % (24 * 3600)) / 3600;
|
||||
long minutes = ((sec % (24 * 3600)) % 3600) / 60;
|
||||
long seconds = ((sec % (24 * 3600)) % 3600) % 60;
|
||||
long months = days / 30;
|
||||
days %= 30;
|
||||
long years = months / 12;
|
||||
months %= 12;
|
||||
|
||||
return String.format("%02d/%02d/%04d - %02d:%02d:%02d", days, months, years, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
public static String getTimeMonths(long sec) {
|
||||
long days = sec / (24 * 3600);
|
||||
long hours = (sec % (24 * 3600)) / 3600;
|
||||
long minutes = ((sec % (24 * 3600)) % 3600) / 60;
|
||||
long seconds = ((sec % (24 * 3600)) % 3600) % 60;
|
||||
long months = days / 30;
|
||||
days %= 30;
|
||||
|
||||
return String.format("%02d/%02d - %02d:%02d:%02d", days, months, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
public static String getTimeDays(long sec) {
|
||||
long days = sec / (24 * 3600);
|
||||
long hours = (sec % (24 * 3600)) / 3600;
|
||||
long minutes = ((sec % (24 * 3600)) % 3600) / 60;
|
||||
long seconds = ((sec % (24 * 3600)) % 3600) % 60;
|
||||
|
||||
return String.format("%02d - %02d:%02d:%02d", days, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
public static String getTimeHours(long sec) {
|
||||
long hours = (sec % (24 * 3600)) / 3600;
|
||||
long minutes = ((sec % (24 * 3600)) % 3600) / 60;
|
||||
long seconds = ((sec % (24 * 3600)) % 3600) % 60;
|
||||
|
||||
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/gp_dbc/textures/items/gp_handcuff.png
Normal file
BIN
src/main/resources/assets/gp_dbc/textures/items/gp_handcuff.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
src/main/resources/assets/gp_dbc/textures/items/jail_manager.png
Normal file
BIN
src/main/resources/assets/gp_dbc/textures/items/jail_manager.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in a new issue