Jail Manager almost done, multiple inmate when one go in jail
This commit is contained in:
parent
d9b140274f
commit
3fddd7482f
|
@ -44,11 +44,14 @@ public class Main
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void postInit(FMLPostInitializationEvent e) {
|
public void postInit(FMLPostInitializationEvent e) {
|
||||||
proxy.postInit(e);
|
proxy.postInit(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void serverStarting(FMLServerStartingEvent e) {
|
public void serverStarting(FMLServerStartingEvent e) {
|
||||||
e.registerServerCommand(new CommandGP());
|
e.registerServerCommand(new CommandGP());
|
||||||
|
|
||||||
|
ConfigManager.setExitJail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
|
@ -11,6 +11,7 @@ import gp_dbc.utils.Pos;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.util.ChunkCoordinates;
|
import net.minecraft.util.ChunkCoordinates;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraftforge.common.config.Configuration;
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.common.config.Property;
|
import net.minecraftforge.common.config.Property;
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ public class ConfigManager {
|
||||||
|
|
||||||
private static Configuration config;
|
private static Configuration config;
|
||||||
public static boolean updateCheck = true;
|
public static boolean updateCheck = true;
|
||||||
|
public static String configDir;
|
||||||
|
|
||||||
public static final String CATEGORY_GP = "Galactic Patrol";
|
public static final String CATEGORY_GP = "Galactic Patrol";
|
||||||
|
|
||||||
|
@ -49,6 +51,7 @@ public class ConfigManager {
|
||||||
if (config != null)
|
if (config != null)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
|
ConfigManager.configDir = configDir;
|
||||||
File path = new File(configDir + "/" + Main.MODID + ".cfg");
|
File path = new File(configDir + "/" + Main.MODID + ".cfg");
|
||||||
|
|
||||||
config = new Configuration(path);
|
config = new Configuration(path);
|
||||||
|
@ -76,8 +79,7 @@ public class ConfigManager {
|
||||||
pos_exit_jail = new Pos(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
|
pos_exit_jail = new Pos(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
ChunkCoordinates spawnPoint = MinecraftServer.getServer().worldServerForDimension(0).getSpawnPoint();;
|
pos_exit_jail = null;
|
||||||
pos_exit_jail = new Pos(spawnPoint.posX, spawnPoint.posY, spawnPoint.posZ, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TIME_HANDCUFFING = (byte)addVariableConfig(order, CATEGORY_GP, "TIME_HANDCUFFING",
|
TIME_HANDCUFFING = (byte)addVariableConfig(order, CATEGORY_GP, "TIME_HANDCUFFING",
|
||||||
|
@ -107,6 +109,21 @@ public class ConfigManager {
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setExitJail() {
|
||||||
|
if (pos_exit_jail != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
MinecraftServer server = MinecraftServer.getServer();
|
||||||
|
WorldServer world = server.worldServerForDimension(0);
|
||||||
|
ChunkCoordinates spawnPoint = world.getSpawnPoint();
|
||||||
|
pos_exit_jail = new Pos(spawnPoint.posX, spawnPoint.posY, spawnPoint.posZ, 0);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Configuration getConfiguration() {return config;}
|
public static Configuration getConfiguration() {return config;}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package gp_dbc.gui.JailManager;
|
package gp_dbc.gui.JailManager;
|
||||||
|
|
||||||
import gp_dbc.Main;
|
import gp_dbc.Main;
|
||||||
|
import gp_dbc.system.Cell;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import static gp_dbc.utils.DrawGui.drawLimited;
|
||||||
|
|
||||||
public class GuiButtonJailManager extends GuiButton {
|
public class GuiButtonJailManager extends GuiButton {
|
||||||
|
|
||||||
private static final ResourceLocation buttonTexturesNinjin = new ResourceLocation(Main.MODID, "textures/gui/jailManager.png");
|
private static final ResourceLocation buttonTexturesNinjin = new ResourceLocation(Main.MODID, "textures/gui/jailManager.png");
|
||||||
|
@ -20,11 +23,13 @@ public class GuiButtonJailManager extends GuiButton {
|
||||||
this.id = buttonId;
|
this.id = buttonId;
|
||||||
this.xPosition = x;
|
this.xPosition = x;
|
||||||
this.yPosition = y;
|
this.yPosition = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws this button to the screen.
|
* Draws this button to the screen.
|
||||||
*/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void drawButton(Minecraft minecraft, int x, int y) {
|
public void drawButton(Minecraft minecraft, int x, int y) {
|
||||||
if (!this.visible)
|
if (!this.visible)
|
||||||
|
@ -37,11 +42,16 @@ public class GuiButtonJailManager extends GuiButton {
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
GL11.glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
|
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffd6d6d6);
|
||||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 130, 7, this.width, this.height);
|
//this.drawTexturedModalRect(this.xPosition, this.yPosition, 130, 7, this.width, this.height);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 130, 7, this.width, this.height);
|
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffffffff);
|
||||||
|
//this.drawTexturedModalRect(this.xPosition, this.yPosition, 130, 7, this.width, this.height);
|
||||||
|
}
|
||||||
|
Cell cell = GuiJailManager.cells.get(-(id) - 1);
|
||||||
|
|
||||||
|
drawLimited(minecraft.fontRenderer, "Cell #" + -(id) + " " + cell.getInmates().size() + "/" + cell.getPlace(), xPosition, yPosition, width - 1, height, 0xff000000);
|
||||||
|
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.sql.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static gp_dbc.utils.DrawGui.drawLimited;
|
import static gp_dbc.utils.DrawGui.drawLimited;
|
||||||
|
@ -23,18 +25,18 @@ public class GuiJailManager extends GuiScreen {
|
||||||
|
|
||||||
private int scroll_y = 0;
|
private int scroll_y = 0;
|
||||||
|
|
||||||
private List<Cell> cells;
|
public static List<Cell> cells;
|
||||||
int gap_y = 1;
|
int gap_y = 1;
|
||||||
int cell_width = 76;
|
int cell_width = 76;
|
||||||
int cell_height = 10;
|
int cell_height = 10;
|
||||||
|
|
||||||
public static int cell_selected = -1; // ID of cell
|
public static int cell_selected = -1; // ID of cell
|
||||||
private GuiButtonJailManager[] cells_buttons;
|
//private List<GuiButtonJailManager> cells_buttons = new ArrayList<>();
|
||||||
private GuiButtonJailManager delete_cell;
|
private GuiButtonJailManager delete_cell;
|
||||||
private GuiButtonJailManager edit_cell;
|
private GuiButtonJailManager edit_cell;
|
||||||
|
|
||||||
public GuiJailManager(List<Cell> cells) {
|
public GuiJailManager(List<Cell> cells) {
|
||||||
this.cells = cells;
|
GuiJailManager.cells = cells;
|
||||||
cell_selected = -1;
|
cell_selected = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +131,7 @@ public class GuiJailManager extends GuiScreen {
|
||||||
for (int i = 0 ; i < cells.size(); i++) {
|
for (int i = 0 ; i < cells.size(); i++) {
|
||||||
int pos_x = guiX + 13;
|
int pos_x = guiX + 13;
|
||||||
int pos_y = guiY + 37 + (i * (cell_height + gap_y)) + scroll_y ;
|
int pos_y = guiY + 37 + (i * (cell_height + gap_y)) + scroll_y ;
|
||||||
buttonList.add(cells_buttons[i] = new GuiButtonJailManager(-(i + 1), pos_x, pos_y, pos_x + cell_width, pos_y + cell_height));
|
buttonList.add(new GuiButtonJailManager(-(i + 1), pos_x, pos_y, cell_width, cell_height));
|
||||||
}
|
}
|
||||||
|
|
||||||
//buttonList.add(buttonClose = new CyborgSoftwareGuiButton(1, guiX + 4, guiY - 3, 7, 7));
|
//buttonList.add(buttonClose = new CyborgSoftwareGuiButton(1, guiX + 4, guiY - 3, 7, 7));
|
||||||
|
|
|
@ -14,12 +14,13 @@ public class ServerProxy extends CommonProxy{
|
||||||
public void preInit(FMLPreInitializationEvent $e) {
|
public void preInit(FMLPreInitializationEvent $e) {
|
||||||
super.preInit($e);
|
super.preInit($e);
|
||||||
|
|
||||||
ConfigManager.init($e.getModConfigurationDirectory().toString());
|
|
||||||
FMLCommonHandler.instance().bus().register(new ConfigManager());
|
FMLCommonHandler.instance().bus().register(new ConfigManager());
|
||||||
|
|
||||||
FMLCommonHandler.instance().bus().register(new TemporaryEvent());
|
FMLCommonHandler.instance().bus().register(new TemporaryEvent());
|
||||||
FMLCommonHandler.instance().bus().register(new TimeJail());
|
FMLCommonHandler.instance().bus().register(new TimeJail());
|
||||||
FMLCommonHandler.instance().bus().register(new Handcuff());
|
FMLCommonHandler.instance().bus().register(new Handcuff());
|
||||||
|
|
||||||
|
ConfigManager.init($e.getModConfigurationDirectory().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(FMLInitializationEvent $e) {
|
public void init(FMLInitializationEvent $e) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class Handcuff {
|
||||||
UUID uuid_patrol = UUID.fromString(entry.getKey().split("~")[0]);
|
UUID uuid_patrol = UUID.fromString(entry.getKey().split("~")[0]);
|
||||||
UUID uuid_inmate = UUID.fromString(entry.getKey().split("~")[1]);
|
UUID uuid_inmate = UUID.fromString(entry.getKey().split("~")[1]);
|
||||||
long time_start = entry.getValue();
|
long time_start = entry.getValue();
|
||||||
long time_left = (time_start + (TIME_TO_GO_IN_JAIL * 1000) - System.currentTimeMillis()) / 1000;
|
long time_left = (time_start + (TIME_TO_GO_IN_JAIL * 1000L) - System.currentTimeMillis()) / 1000;
|
||||||
|
|
||||||
if (time_left <= 0) {
|
if (time_left <= 0) {
|
||||||
EntityPlayer inmate = getPlayerFromUUID(uuid_inmate);
|
EntityPlayer inmate = getPlayerFromUUID(uuid_inmate);
|
||||||
|
|
|
@ -77,29 +77,13 @@ public class Jail {
|
||||||
return cells;
|
return cells;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean thereIsExitPos(ICommandSender chat, boolean chatMsg) {
|
|
||||||
String[] split = POS_EXIT_JAIL.split(" ");
|
|
||||||
if (split.length != 4) {
|
|
||||||
if (chatMsg)
|
|
||||||
chat.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("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 + translateToLocal("error.invalid_value_exit_pos")));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cell putPlayerInJail(ICommandSender sender, EntityPlayer inmate, long sec, boolean chatMsg) {
|
public Cell putPlayerInJail(ICommandSender sender, EntityPlayer inmate, long sec, boolean chatMsg) {
|
||||||
|
|
||||||
if (!thereIsExitPos(sender, chatMsg))
|
if (pos_exit_jail == null) {
|
||||||
|
if (chatMsg)
|
||||||
|
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.definition_exit_pos")));
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Cell cell = null;
|
Cell cell = null;
|
||||||
try {
|
try {
|
||||||
|
@ -163,8 +147,11 @@ public class Jail {
|
||||||
|
|
||||||
public int removePlayerFromJail(ICommandSender sender, UUID uuid, boolean chatMsg) {
|
public int removePlayerFromJail(ICommandSender sender, UUID uuid, boolean chatMsg) {
|
||||||
|
|
||||||
if (!thereIsExitPos(sender, chatMsg))
|
if (pos_exit_jail == null) {
|
||||||
|
if (chatMsg)
|
||||||
|
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.definition_exit_pos")));
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
for (int i = 0; i < inmates.size(); i++)
|
for (int i = 0; i < inmates.size(); i++)
|
||||||
|
@ -197,7 +184,7 @@ public class Jail {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getRandomCell() throws Exception {
|
public Cell getRandomCell() throws Exception {
|
||||||
if (cells.size() == 0)
|
if (cells.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List<Cell> availableCells = new ArrayList<>();
|
List<Cell> availableCells = new ArrayList<>();
|
||||||
|
@ -206,7 +193,7 @@ public class Jail {
|
||||||
if (cell.getInmates().size() < cell.getPlace())
|
if (cell.getInmates().size() < cell.getPlace())
|
||||||
availableCells.add(cell);
|
availableCells.add(cell);
|
||||||
|
|
||||||
if (availableCells.size() == 0)
|
if (availableCells.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int index_cell = MathHelper.getRandomIntegerInRange(new Random(), 0, availableCells.size() - 1);
|
int index_cell = MathHelper.getRandomIntegerInRange(new Random(), 0, availableCells.size() - 1);
|
||||||
|
@ -295,8 +282,10 @@ public class Jail {
|
||||||
if (!isFree(player.getUniqueID()))
|
if (!isFree(player.getUniqueID()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!thereIsExitPos(player, true))
|
if (pos_exit_jail == null) {
|
||||||
|
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.definition_exit_pos")));
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
tpOutOfJail(player);
|
tpOutOfJail(player);
|
||||||
waitingToBeFree.remove(player.getUniqueID().toString());
|
waitingToBeFree.remove(player.getUniqueID().toString());
|
||||||
|
|
|
@ -21,4 +21,4 @@ success.you_handcuffed_him=You handcuffed him
|
||||||
success.you_are_handcuffed=You are handcuffed, going in %% seconds
|
success.you_are_handcuffed=You are handcuffed, going in %% seconds
|
||||||
warning.going_in_jail=%% second(s) left(s)
|
warning.going_in_jail=%% second(s) left(s)
|
||||||
error.cancel_handcuffing=Handcuffing cancel
|
error.cancel_handcuffing=Handcuffing cancel
|
||||||
error.not_galactic_patrol=You are not a galactic patrol
|
error.not_galactic_patrol=You are not a galactic patrol
|
||||||
|
|
Loading…
Reference in a new issue