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
|
||||
public void postInit(FMLPostInitializationEvent e) {
|
||||
proxy.postInit(e);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStarting(FMLServerStartingEvent e) {
|
||||
e.registerServerCommand(new CommandGP());
|
||||
|
||||
ConfigManager.setExitJail();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -11,6 +11,7 @@ import gp_dbc.utils.Pos;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
|
@ -28,6 +29,7 @@ public class ConfigManager {
|
|||
|
||||
private static Configuration config;
|
||||
public static boolean updateCheck = true;
|
||||
public static String configDir;
|
||||
|
||||
public static final String CATEGORY_GP = "Galactic Patrol";
|
||||
|
||||
|
@ -49,6 +51,7 @@ public class ConfigManager {
|
|||
if (config != null)
|
||||
return ;
|
||||
|
||||
ConfigManager.configDir = configDir;
|
||||
File path = new File(configDir + "/" + Main.MODID + ".cfg");
|
||||
|
||||
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]));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
ChunkCoordinates spawnPoint = MinecraftServer.getServer().worldServerForDimension(0).getSpawnPoint();;
|
||||
pos_exit_jail = new Pos(spawnPoint.posX, spawnPoint.posY, spawnPoint.posZ, 0);
|
||||
pos_exit_jail = null;
|
||||
}
|
||||
|
||||
TIME_HANDCUFFING = (byte)addVariableConfig(order, CATEGORY_GP, "TIME_HANDCUFFING",
|
||||
|
@ -107,6 +109,21 @@ public class ConfigManager {
|
|||
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;}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package gp_dbc.gui.JailManager;
|
||||
|
||||
import gp_dbc.Main;
|
||||
import gp_dbc.system.Cell;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static gp_dbc.utils.DrawGui.drawLimited;
|
||||
|
||||
public class GuiButtonJailManager extends GuiButton {
|
||||
|
||||
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.xPosition = x;
|
||||
this.yPosition = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
**/
|
||||
@Override
|
||||
public void drawButton(Minecraft minecraft, int x, int y) {
|
||||
if (!this.visible)
|
||||
|
@ -37,11 +42,16 @@ public class GuiButtonJailManager extends GuiButton {
|
|||
GL11.glPushMatrix();
|
||||
|
||||
if (flag) {
|
||||
GL11.glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 130, 7, this.width, this.height);
|
||||
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffd6d6d6);
|
||||
//this.drawTexturedModalRect(this.xPosition, this.yPosition, 130, 7, this.width, this.height);
|
||||
}
|
||||
else
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 130, 7, this.width, this.height);
|
||||
else {
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import net.minecraft.util.ResourceLocation;
|
|||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static gp_dbc.utils.DrawGui.drawLimited;
|
||||
|
@ -23,18 +25,18 @@ public class GuiJailManager extends GuiScreen {
|
|||
|
||||
private int scroll_y = 0;
|
||||
|
||||
private List<Cell> cells;
|
||||
public static List<Cell> cells;
|
||||
int gap_y = 1;
|
||||
int cell_width = 76;
|
||||
int cell_height = 10;
|
||||
|
||||
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 edit_cell;
|
||||
|
||||
public GuiJailManager(List<Cell> cells) {
|
||||
this.cells = cells;
|
||||
GuiJailManager.cells = cells;
|
||||
cell_selected = -1;
|
||||
}
|
||||
|
||||
|
@ -129,7 +131,7 @@ public class GuiJailManager extends GuiScreen {
|
|||
for (int i = 0 ; i < cells.size(); i++) {
|
||||
int pos_x = guiX + 13;
|
||||
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));
|
||||
|
|
|
@ -14,12 +14,13 @@ public class ServerProxy extends CommonProxy{
|
|||
public void preInit(FMLPreInitializationEvent $e) {
|
||||
super.preInit($e);
|
||||
|
||||
ConfigManager.init($e.getModConfigurationDirectory().toString());
|
||||
FMLCommonHandler.instance().bus().register(new ConfigManager());
|
||||
|
||||
FMLCommonHandler.instance().bus().register(new TemporaryEvent());
|
||||
FMLCommonHandler.instance().bus().register(new TimeJail());
|
||||
FMLCommonHandler.instance().bus().register(new Handcuff());
|
||||
|
||||
ConfigManager.init($e.getModConfigurationDirectory().toString());
|
||||
}
|
||||
|
||||
public void init(FMLInitializationEvent $e) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class Handcuff {
|
|||
UUID uuid_patrol = UUID.fromString(entry.getKey().split("~")[0]);
|
||||
UUID uuid_inmate = UUID.fromString(entry.getKey().split("~")[1]);
|
||||
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) {
|
||||
EntityPlayer inmate = getPlayerFromUUID(uuid_inmate);
|
||||
|
|
|
@ -77,29 +77,13 @@ public class Jail {
|
|||
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) {
|
||||
|
||||
if (!thereIsExitPos(sender, chatMsg))
|
||||
if (pos_exit_jail == null) {
|
||||
if (chatMsg)
|
||||
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.definition_exit_pos")));
|
||||
return null;
|
||||
}
|
||||
|
||||
Cell cell = null;
|
||||
try {
|
||||
|
@ -163,8 +147,11 @@ public class Jail {
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
boolean removed = false;
|
||||
for (int i = 0; i < inmates.size(); i++)
|
||||
|
@ -197,7 +184,7 @@ public class Jail {
|
|||
}
|
||||
|
||||
public Cell getRandomCell() throws Exception {
|
||||
if (cells.size() == 0)
|
||||
if (cells.isEmpty())
|
||||
return null;
|
||||
|
||||
List<Cell> availableCells = new ArrayList<>();
|
||||
|
@ -206,7 +193,7 @@ public class Jail {
|
|||
if (cell.getInmates().size() < cell.getPlace())
|
||||
availableCells.add(cell);
|
||||
|
||||
if (availableCells.size() == 0)
|
||||
if (availableCells.isEmpty())
|
||||
return null;
|
||||
|
||||
int index_cell = MathHelper.getRandomIntegerInRange(new Random(), 0, availableCells.size() - 1);
|
||||
|
@ -295,8 +282,10 @@ public class Jail {
|
|||
if (!isFree(player.getUniqueID()))
|
||||
return false;
|
||||
|
||||
if (!thereIsExitPos(player, true))
|
||||
if (pos_exit_jail == null) {
|
||||
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.definition_exit_pos")));
|
||||
return false;
|
||||
}
|
||||
|
||||
tpOutOfJail(player);
|
||||
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
|
||||
warning.going_in_jail=%% second(s) left(s)
|
||||
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