add fomer inmate; add minimun criminal rate to be jailed

This commit is contained in:
xamora 2026-04-22 17:04:17 +02:00
parent 44612c402e
commit ec81c836fc
12 changed files with 138 additions and 85 deletions

View file

@ -48,9 +48,13 @@ public class ConfigManager {
static public int MAX_RATE_CRIMINAL = 10000;
static public long RATE_CRIMINAL_NOT_SAFE = 5000; // Not use
static public int RATE_TO_HAVE_POSITION = 1000;
static public int MIN_RATE_TO_GO_JAIL = 200;
static public long MIN_TIME_BETWEEN_EACH_POSITION = 2 * 60; // 2 min
static public long MAX_TIME_BETWEEN_EACH_POSITION = 4 * 60 * 60; // 4 hours
static public long TIME_FORMER_INMATE = 86400; // seconds (1 day)
static public int MULTI_FORMER_INMATE = 2; //
static public boolean REINCARNATION_RESET_CRIMINAL = true;
static public boolean REINCARNATION_RESET_GP = true;
@ -132,6 +136,9 @@ public class ConfigManager {
RATE_TO_HAVE_POSITION = addVariableConfig(order, CATEGORY_GP, "MIN_RATE_TO_HAVE_POSITION",
"Min rate to display position for galactic patrol. [default: 1000]", "1000").getInt();
MIN_RATE_TO_GO_JAIL = addVariableConfig(order, CATEGORY_GP, "MIN_RATE_TO_GO_JAIL",
"Min criminal rate to be send to jail. [default: 200]", "200").getInt();
MAX_TIME_BETWEEN_EACH_POSITION = addVariableConfig(order, CATEGORY_GP, "MAX_TIME_BETWEEN_EACH_POSITION",
"Max time between each position give to galactic patrol in seconds. [default: 14400]", "14400").getInt();
MAX_TIME_BETWEEN_EACH_POSITION *= 1000L;
@ -140,6 +147,13 @@ public class ConfigManager {
"Min time between each position give to galactic patrol in seconds. [default: 120]", "120").getInt();
MIN_TIME_BETWEEN_EACH_POSITION *= 1000L;
TIME_FORMER_INMATE = addVariableConfig(order, CATEGORY_GP, "TIME_FORMER_INMATE",
"Time if he commits another crime, a multiplier will be applied to his crime rate in seconds. [default: 86400]", "86400").getInt();
TIME_FORMER_INMATE *= 1000L;
MULTI_FORMER_INMATE = addVariableConfig(order, CATEGORY_GP, "MULTI_FORMER_INMATE",
"Multiplier if he commits another crime will be applied to his crime rate. [default: 2]", "2").getInt();
REINCARNATION_RESET_CRIMINAL = addVariableConfig(order, CATEGORY_GP, "REINCARNATION_RESET_CRIMINAL",
"Reincarnation reset criminal rate. [default: true]", "true").getBoolean();

View file

@ -72,7 +72,6 @@ public class GuiButtonJailManager extends GuiButton {
if (flag || cell_selected == cell.getId()) {
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffd6d6d6);
} else {
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffffffff);
}
@ -81,6 +80,7 @@ public class GuiButtonJailManager extends GuiButton {
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GL11.glPopMatrix();
// System.out.println((newHeight - 91 * ratioHeight) + " " + y);
if (flag) {
GL11.glPushMatrix();
GL11.glTranslated(0, 0, 1);

View file

@ -13,6 +13,7 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.util.Comparator;
import java.util.List;
public class GuiJailManager extends GuiScreen {
@ -29,6 +30,8 @@ public class GuiJailManager extends GuiScreen {
int gap_y = 1;
int cell_width = 76;
int cell_height = 10;
int number_by_line = 1;
int nbr_visible = 6;
public static int cell_selected = -1; // ID of cell
//private List<GuiButtonJailManager> cells_buttons = new ArrayList<>();
@ -36,6 +39,7 @@ public class GuiJailManager extends GuiScreen {
private GuiButtonJailManager edit_cell;
public GuiJailManager(List<Cell> cells) {
cells.sort(Comparator.comparingInt(cell -> cell.getId()));
GuiJailManager.cells = cells;
cell_selected = -1;
scroll_y = 0;
@ -62,17 +66,29 @@ public class GuiJailManager extends GuiScreen {
drawTexturedModalRect(guiX, guiY - 10, 0, 0, guiWidth, guiHeight);
GL11.glPopMatrix();
if (cells.size() > 6) {
int scrollbar_x = guiX + 90;
int all_cells = cells.size() * (cell_height + gap_y);
int cells_visible = 6 * (cell_height + gap_y);
int scrollable_cells = all_cells - cells_visible;
int max_height = 66;
int scrollbar_add = -((scroll_y * max_height) / scrollable_cells);
int scrollbar_y = (int) (guiY + 42 + scrollbar_add); // 98 - 163
drawRect(scrollbar_x, scrollbar_y, scrollbar_x + 6, scrollbar_y + 6, 0xff000000);
int scrollbar_x = guiX + 90;
int scrollbar_y = guiY + 38;
int scrollbar_add = 0;
if (cells.size() > nbr_visible) {
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslated(0,0, 1);
scrollbar_add = (int)(60D / getMaxScrollY() * scroll_y); // doit varier entre 0 et 108
scrollbar_add = Math.max(scrollbar_add, 0);
GL11.glPopMatrix();
}
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if (cells.size() > nbr_visible)
drawRect(scrollbar_x, scrollbar_y + scrollbar_add, scrollbar_x + 6, scrollbar_y + scrollbar_add + 6, 0xff000000);
GL11.glPopMatrix();
super.drawScreen(mouse_x, mouse_y, ticks);
}
@ -94,32 +110,21 @@ public class GuiJailManager extends GuiScreen {
buttonList.clear();
buttonList.add(edit_cell = new GuiButtonJailManager(0, guiX + 20, guiY + 115, 21, 21));
buttonList.add(delete_cell = new GuiButtonJailManager(1, guiX + 65, guiY + 115, 21, 21 ));
for (int i = 0 ; i < cells.size(); i++) {
int pos_x = guiX + 13;
int pos_y = guiY + 37 + (i * (cell_height + gap_y)) ;
buttonList.add(new GuiButtonJailManager(-(i + 1), pos_x, pos_y, cell_width, cell_height));
}
buttonList.add(edit_cell = new GuiButtonJailManager(0, guiX + 20, guiY + 115, 21, 21));
buttonList.add(delete_cell = new GuiButtonJailManager(1, guiX + 65, guiY + 115, 21, 21 ));
//buttonList.add(buttonClose = new CyborgSoftwareGuiButton(1, guiX + 4, guiY - 3, 7, 7));
super.initGui();
}
@Override
protected void actionPerformed(GuiButton button) {
if (button.id < 0) {
Cell cell = cells.get(-(button.id) - 1);
if (cell_selected == cell.getId())
cell_selected = -1;
else
cell_selected = cell.getId();
}
else if (button.id == 0) { // Edit
if (button.id == 0) { // Edit
}
else if (button.id == 1) { // Delete
@ -127,6 +132,16 @@ public class GuiJailManager extends GuiScreen {
return;
CommonProxy.network.sendToServer(new NetworkJailManager("delete~" + cell_selected));
cell_selected = -1;
}
else if (button.id < 0) {
Cell cell = cells.get(-(button.id) - 1);
if (cell_selected == cell.getId())
cell_selected = -1;
else
cell_selected = cell.getId();
System.out.println("id:" + cell.getId());
}
super.actionPerformed(button);
}
@ -140,7 +155,7 @@ public class GuiJailManager extends GuiScreen {
public void handleMouseInput() {
super.handleMouseInput();
if (cells.size() <= 6)
if (cells.size() <= nbr_visible)
return;
int dWheel = Mouse.getEventDWheel();
@ -153,12 +168,19 @@ public class GuiJailManager extends GuiScreen {
//System.out.println("Molette vers le haut");
} else {
scroll_y -= 5;
scroll_y = Math.max(-((cells.size() - 6) * (cell_height)), scroll_y);
scroll_y = Math.max(-((cells.size() - nbr_visible) * (cell_height + gap_y)), scroll_y);
//System.out.println("Molette vers le bas");
}
}
}
public int getMaxScrollY() {
int size = cells.size();
int visible_criminal_line = (int) Math.ceil((size - nbr_visible) / (double)number_by_line);
int scroll_y_max = visible_criminal_line * (cell_height + gap_y) - cell_height / 2;
return -scroll_y_max;
}
@Override
public void updateScreen() {
super.updateScreen();

View file

@ -7,6 +7,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import xamora.gp_dbc.Main;
import xamora.gp_dbc.system.Criminal;
import xamora.gp_dbc.system.Handcuff;
import xamora.gp_dbc.utils.EntityUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -97,62 +98,53 @@ public class ItemGPHandcuff extends Item {
return stack;
}
public boolean errorManager(EntityPlayer inmate, EntityPlayer player) {
if (Handcuff.isHandcuffed(inmate)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.already_handcuffed")));
return true;
}
public boolean errorManager(EntityPlayer inmate, EntityPlayer jailer) {
Criminal criminal = Main.gp.criminals.getCriminal(inmate.getUniqueID());
if (Main.gp.jail.getCells().isEmpty()) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.unavailable_cell")));
return true;
}
if (Handcuff.isHandcuffed(inmate))
return printError(jailer, true, "error.already_handcuffed");
if (Main.gp.jail.getCells().isEmpty())
return printError(jailer, true, "error.unavailable_cell");
try { // Look if there is a place in one cell
if (Main.gp.jail.getRandomCell() == null) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.unavailable_cell")));
return true;
}
if (Main.gp.jail.getRandomCell() == null)
return printError(jailer, true, "error.unavailable_cell");
} catch (Exception e){System.out.println(e.getMessage());};
if (Main.gp.jail.isInJail(inmate)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.already_in_jail")));
return true;
}
if (Main.gp.jail.isInJail(inmate))
return printError(jailer, true, "error.already_in_jail");
if (!Main.gp.isInGalacticPatrol(player)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.not_galactic_patrol")));
return true;
}
if (!Main.gp.isInGalacticPatrol(jailer))
return printError(jailer, true, "error.not_galactic_patrol");
if (Main.gp.isInGalacticPatrol(inmate)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.is_galactic_patrol")));
return true;
}
if (Main.gp.isInGalacticPatrol(inmate))
return printError(jailer, true, "error.is_galactic_patrol");
if (!Main.gp.criminals.isCriminal(inmate.getUniqueID())) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.is_not_criminal")));
return true;
}
if (criminal == null)
return printError(jailer, true, "error.is_not_criminal");
if (criminal.getRate() < MIN_RATE_TO_GO_JAIL)
return printError(jailer, true, "error.not_enough_criminal_rate");
JGPlayerMP jgInmate = new JGPlayerMP(inmate);
NBTTagCompound nbt = jgInmate.connectBaseNBT();
boolean alive = nbt.getByte("jrmcAlv") == 0;
if (!alive) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.cant_handcuff_dead")));
return true;
}
if (inmate.dimension == 22) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.cant_handcuff_in_hell")));
return true;
}
if (!alive)
return printError(jailer, true, "error.cant_handcuff_dead");
if (inmate.dimension == 22)
return printError(jailer, true, "error.cant_handcuff_in_hell");
return false;
}
public boolean printError(EntityPlayer player, boolean errorReturn, String StatName) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal(StatName)));
return errorReturn;
}
@SuppressWarnings({ "unchecked" })
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {

View file

@ -51,6 +51,9 @@ public class Criminal {
int add = Math.max(jgKilled.getAlignment() - 33, 0);
if (Main.gp.isInGalacticPatrol(killed))
add *= 2;
if (System.currentTimeMillis() <= Main.gp.criminals.formerInmate.getOrDefault(uuid, 0L) + TIME_FORMER_INMATE)
add *= 2;
rate += add;
victims_alignLoose.put(killed.getUniqueID(), add);

View file

@ -4,7 +4,6 @@ import JinRyuu.JRMCore.server.JGPlayerMP;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import fastcraft.U;
import xamora.gp_dbc.config.ConfigManager;
import xamora.gp_dbc.utils.Data;
import xamora.gp_dbc.utils.PlayerUtils;
@ -14,18 +13,16 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;
import static xamora.gp_dbc.Main.gp;
import static xamora.gp_dbc.config.ConfigManager.BAN_TIME_KILLING_OTHER_GP;
import static xamora.gp_dbc.config.ConfigManager.RATE_TO_HAVE_POSITION;
import static xamora.gp_dbc.config.ConfigManager.*;
public class Criminals {
public List<Criminal> criminals = new ArrayList<>();
// recent criminals to increase faster the rate
public HashMap<UUID, Long> formerInmate = new HashMap<>();
public Criminals() {
try {
@ -33,6 +30,14 @@ public class Criminals {
} catch (Exception e) {
System.out.println(e.getMessage());
}
try {
formerInmate = Data.loadDataUUIDLong("formerInmate");
formerInmate.entrySet().removeIf(entry -> System.currentTimeMillis() > entry.getValue() + TIME_FORMER_INMATE);
Data.saveDataUUIDLong(gp.criminals.formerInmate, "formerInmate");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@SideOnly(Side.SERVER)

View file

@ -155,7 +155,6 @@ public class Handcuff {
handcuffed.add(new Handcuffed(inmate.getUniqueID(), jailer.getUniqueID(), current_time, false));
jailer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + translateToLocal("success.you_handcuffed_him")));
String[] texts = TextUtils.getSeparateText(translateToLocal("success.you_are_handcuffed"), "%%");
inmate.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + texts[0] + ConfigManager.TIME_TO_GO_IN_JAIL + texts[1]));

View file

@ -185,6 +185,8 @@ public class Jail {
Data.saveDataString(waitingToBeFree, "waitingToBeFree");
tpOutOfJail(player);
gp.criminals.formerInmate.put(player.getUniqueID(), System.currentTimeMillis());
Data.saveDataUUIDLong(gp.criminals.formerInmate, "formerInmate");
return 0;
}
@ -198,13 +200,12 @@ public class Jail {
}
boolean removed = false;
for (int i = 0; i < inmates.size(); i++)
if (inmates.get(i).equals(uuid)) {
inmates.get(i).getCell().removeInmate(inmates.get(i));
inmates.remove(inmates.get(i));
removed = true;
break;
}
Inmate inmate = getInmate(uuid);
if (inmate != null) {
inmate.getCell().removeInmate(inmate);
inmates.remove(inmate);
removed = true;
}
if (!removed) {
if (chatMsg)

View file

@ -6,7 +6,6 @@ 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 fastcraft.J;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

View file

@ -5,12 +5,17 @@ import xamora.gp_dbc.config.ConfigManager;
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;
import java.util.*;
public class Data {
public static void saveDataUUIDLong(HashMap<UUID, Long> map, String name) {
List<String> new_list = new ArrayList<>();
for (Map.Entry<UUID, Long> entry : map.entrySet())
new_list.add(entry.getKey() + "~" + entry.getValue());
saveDataString(new_list, name);
}
public static void saveDataUUID(List<UUID> list, String name) {
List<String> new_list = new ArrayList<>();
for (UUID uuid : list)
@ -41,6 +46,17 @@ public class Data {
}
}
public static HashMap<UUID, Long> loadDataUUIDLong(String name) {
HashMap<UUID, Long> new_map = new HashMap<>();
for (String s : loadDataString(name)) {
String[] split = s.split("~");
UUID uuid = UUID.fromString(split[0]);
Long value = Long.parseLong(split[1]);
new_map.put(uuid, value);
}
return new_map;
}
public static List<UUID> loadDataUUID(String name) {
List<UUID> data = new ArrayList<>();
List<String> strs = loadDataString(name);

View file

@ -33,6 +33,7 @@ error.banned_for_being_bad=For having bad alignment
error.banned_for_killing_patrolman=For killing another patrolman
error.criminal_try_join_galactic_patrol=You are a criminal
error.cant_handcuff_dead=You can't handcuff a death
error.not_enough_criminal_rate=He hasn't committed enough crimes to go to jail
gui.jail.cell=Cell
gui.criminal.position=No Position

View file

@ -33,6 +33,7 @@ error.banned_for_being_bad=Pour avoir un alignement mauvais
error.banned_for_killing_patrolman=Pour avoir tué un autre patrouilleur
error.criminal_try_join_galactic_patrol=Vous êtes un criminel
error.cant_handcuff_dead=Vous ne pouvez pas menotter un mort
error.not_enough_criminal_rate=Il n'a pas commis suffisant de crime pour aller en prison
gui.jail.cell=Prison
gui.criminal.position=Aucune Position