Finish handcuff, need debug test.

This commit is contained in:
Xamora64 2024-07-27 22:13:59 +02:00
parent 3fddd7482f
commit c22c061bbe
25 changed files with 882 additions and 144 deletions

View file

@ -89,41 +89,61 @@ public class CommandGP implements ICommand {
JGPlayerMP jgPlayer = new JGPlayerMP(player);
jgPlayer.connectBaseNBT();
int error = 0;
if (arg.equals(COMMANDS[0])) // Add
gp.addToGalaticPatrol(player, true);
error = gp.addToGalaticPatrol(player, true);
else if (arg.equals(COMMANDS[1])) // Remove
gp.removeFromGalaticPatrol(player, true);
error = 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>]"));
if (args.size() != 1) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp inmate sec [<player>]"));
return;
}
else {
try {
gp.jail.putPlayerInJail(sender, player, Long.parseLong(args.get(0)), true);
error = gp.jail.putPlayerInJail(sender, player, Long.parseLong(args.get(0)), true) != null ? 0 : 1;
} catch (Exception e) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp jail sec [<player>]"));
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp inmate sec [<player>]"));
return;
}
}
}
else if (arg.equals(COMMANDS[3])) { // freeInmate
gp.jail.removePlayerFromJail(sender, player, true);
error = 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 {
if (args.size() == 1) {
try {
if (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"));
error = gp.jail.removeCell(Integer.parseInt(args.get(0)));
} catch (Exception e) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp removeJail <x> <y> <z> <dimension> [<player>]"));
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp removeJail <id>"));
}
}
else if (args.size() == 4) {
try {
error = gp.jail.removeCell(Integer.parseInt(args.get(0)), Integer.parseInt(args.get(1)), Integer.parseInt(args.get(2)), Integer.parseInt(args.get(3)));
} catch (Exception e) {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp removeJail <x> <y> <z> <dimension>"));
}
else
}
else {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp removeJail <id>"));
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "/gp removeJail <x> <y> <z> <dimension>"));
return;
}
}
else {
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED.toString() + EnumChatFormatting.UNDERLINE.toString() + "Galactic Patrol:"
+ EnumChatFormatting.RESET.toString() + EnumChatFormatting.RED.toString() + " Command not found"));
return;
}
if (error == 0)
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Command success"));
else
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Command failed"));
}
@Override

View file

@ -39,10 +39,14 @@ public class ConfigManager {
public static byte MAX_ALIGN_TO_JOIN = 100;
public static int FORMAT_TIME_JAIL = 4;
public static int DEFAULT_PLACE_CELL = 2;
public static int TIME_HANDCUFFING = 10; // seconds
public static int TIME_HANDCUFFING = 5; // seconds
public static int TIME_UNHANDCUFFING = 10; // seconds
public static int TIME_TO_GO_IN_JAIL = 20; // seconds
public static boolean OP_JAIL_MANAGER = true;
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;
@ -83,11 +87,24 @@ public class ConfigManager {
}
TIME_HANDCUFFING = (byte)addVariableConfig(order, CATEGORY_GP, "TIME_HANDCUFFING",
"Time to handcuffing someone who is not K.O, in seconds. [default: 10]", "10").getInt();
"Time to handcuffing someone who is not K.O, in seconds. [default: 5]", "5").getInt();
TIME_UNHANDCUFFING = (byte)addVariableConfig(order, CATEGORY_GP, "TIME_UNHANDCUFFING",
"Time to unhandcuffing someone, in seconds. [default: 10]", "10").getInt();
TIME_TO_GO_IN_JAIL = (byte)addVariableConfig(order, CATEGORY_GP, "TIME_TO_GO_IN_JAIL",
"Time to go in jail when someone is handcuffed. [default: 20]", "20").getInt();
FORMAT_TIME_JAIL = addVariableConfig(order, CATEGORY_GP, "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();
DEFAULT_PLACE_CELL = addVariableConfig(order, CATEGORY_GP, "DEFAULT_PLACE_CELL",
"Number of place in each cell by default. [default: 2]", "2").getInt();
OP_JAIL_MANAGER = addVariableConfig(order, CATEGORY_GP, "OP_JAIL_MANAGER",
"Only op can use jail manager to create and delete cell. [default: true]", "true").getBoolean();
config.setCategoryPropertyOrder(CATEGORY_GP, order);

View file

@ -4,6 +4,7 @@ import JinRyuu.JRMCore.JRMCoreH;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gp_dbc.Main;
import gp_dbc.system.Handcuff;
import gp_dbc.system.Handcuffed;
import gp_dbc.utils.TextUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
@ -25,7 +26,6 @@ public class GuiHandcuffed extends Gui {
int guiHeight = 35 / 2 + 1;
public static long startTime = System.currentTimeMillis();
public static long timeToWait = 20;
// Client Side
public static boolean handcuffed = false;
@ -45,7 +45,7 @@ public class GuiHandcuffed extends Gui {
|| event.type == RenderGameOverlayEvent.ElementType.HOTBAR)
return;
long time_left = (startTime + (timeToWait * 1000) - System.currentTimeMillis()) / 1000;
long time_left = (startTime + (Handcuffed.timeToWait * 1000) - System.currentTimeMillis()) / 1000;
if (event.isCancelable())
return;

View file

@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import static gp_dbc.gui.JailManager.GuiJailManager.*;
import static gp_dbc.utils.DrawGui.drawLimited;
public class GuiButtonJailManager extends GuiButton {
@ -23,38 +24,105 @@ public class GuiButtonJailManager extends GuiButton {
this.id = buttonId;
this.xPosition = x;
this.yPosition = y;
this.origin_yPosition = y;
this.width = width;
this.height = height;
}
private int last_scroll_y;
private int origin_yPosition;
/**
* Draws this button to the screen.
**/
@Override
public void drawButton(Minecraft minecraft, int x, int y) {
public void drawButton(Minecraft mc, int x, int y) {
if (!this.visible)
return;
minecraft.getTextureManager().bindTexture(buttonTexturesNinjin);
mc.getTextureManager().bindTexture(buttonTexturesNinjin);
boolean flag = x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height;
boolean flag = x >= xPosition && y >= yPosition && x < xPosition + this.width && y < yPosition + this.height;
if (id < 0) { // cells
if (last_scroll_y != scroll_y) {
last_scroll_y = scroll_y;
yPosition = origin_yPosition + scroll_y;
}
int displayWidth = mc.displayWidth;
int displayHeight = mc.displayHeight;
int ratioWidth = (int) Math.round((double) displayWidth / wdth);
int ratioHeight = (int) Math.round((double) displayHeight / hght);
int newWidth = guiWidth * ratioWidth;
int newHeight = guiHeight * ratioHeight;
int displayGuiX = (int) Math.round((double) (displayWidth - newWidth) / 2);
int displayGuiY = (int) Math.round((double) (displayHeight - newHeight) / 2);
Cell cell = cells.get(-(id) - 1);
GL11.glPushMatrix();
GL11.glScissor(displayGuiX, displayGuiY + 54 * ratioHeight, newWidth, (int) (newHeight - 91 * ratioHeight));
GL11.glEnable(GL11.GL_SCISSOR_TEST);
if (flag || cell_selected == cell.getId()) {
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffd6d6d6);
} else {
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffffffff);
}
drawLimited(mc.fontRenderer, "Cell #" + cell.getId() + " " + cell.getInmates().size() + "/" + cell.getPlace(), xPosition, yPosition + 1, width - 1, height, 0xff000000);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GL11.glPopMatrix();
if (flag) {
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xffd6d6d6);
//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);
GL11.glPushMatrix();
GL11.glTranslated(0, 0, 1);
drawLimited(minecraft.fontRenderer, "Cell #" + -(id) + " " + cell.getInmates().size() + "/" + cell.getPlace(), xPosition, yPosition, width - 1, height, 0xff000000);
String text = "x: " + cell.getPos().x + " y :" + cell.getPos().y + " z: " + cell.getPos().z + " dim: " + cell.getPos().dimension;
int width = (int) (mc.fontRenderer.getStringWidth(text) * 0.8 - 1);
int height = 10;
drawRect(x, y, x + width, y + height, 0xffffffff);
drawLimited(mc.fontRenderer, text, x + 1, y + 1, width - 2, height - 1, 0xff000000);
GL11.glPopMatrix();
}
}
else if (id == 0) { // edit
GL11.glPushMatrix();
GL11.glColor4d(.6, .6, .6, 1);
if (flag && cell_selected != -1)
GL11.glColor4d(1, 1, 1, 1);
else
if (cell_selected != -1)
GL11.glColor4d(.8, .8, .8, 1);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 108, 0, this.width, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2 - 18 / 2 + 1, this.yPosition + this.height / 2 - 17 /2, 144, 0, 18, 17);
GL11.glPopMatrix();
}
else if (id == 1) { // Delete
GL11.glPushMatrix();
GL11.glColor4d(.6, .6, .6, 1);
if (flag && cell_selected != -1)
GL11.glColor4d(1, 1, 1, 1);
else
if (cell_selected != -1)
GL11.glColor4d(.8, .8, .8, 1);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 108, 0, this.width, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2 - 14 / 2 + 1, this.yPosition + this.height / 2 - 15 / 2, 130, 0, 14, 15);
GL11.glPopMatrix();
}
}
}

View file

@ -1,6 +1,8 @@
package gp_dbc.gui.JailManager;
import gp_dbc.Main;
import gp_dbc.network.server.NetworkJailManager;
import gp_dbc.proxy.CommonProxy;
import gp_dbc.system.Cell;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
@ -20,10 +22,13 @@ import static gp_dbc.utils.DrawGui.drawLimited;
public class GuiJailManager extends GuiScreen {
final int guiWidth = 212 / 2 + 1;
final int guiHeight = 320 / 2 + 1;
final static int guiWidth = 212 / 2 + 1;
final static int guiHeight = 320 / 2 + 1;
private int scroll_y = 0;
public static int scroll_y = 0;
public static int wdth;
public static int hght;
public static List<Cell> cells;
int gap_y = 1;
@ -38,6 +43,7 @@ public class GuiJailManager extends GuiScreen {
public GuiJailManager(List<Cell> cells) {
GuiJailManager.cells = cells;
cell_selected = -1;
scroll_y = 0;
}
@Override
@ -61,42 +67,14 @@ public class GuiJailManager extends GuiScreen {
drawTexturedModalRect(guiX, guiY - 10, 0, 0, guiWidth, guiHeight);
GL11.glPopMatrix();
int displayWidth = mc.displayWidth;
int displayHeight = mc.displayHeight;
int ratioWidth = (int) Math.round((double)displayWidth / width);
int ratioHeight = (int) Math.round((double)displayHeight / height);
int newWidth = guiWidth * ratioWidth;
int newHeight = guiHeight * ratioHeight;
int displayGuiX = (int)Math.round((double)(displayWidth - newWidth) / 2);
int displayGuiY = (int)Math.round((double)(displayHeight - newHeight) / 2);
GL11.glPushMatrix();
GL11.glScissor(displayGuiX, displayGuiY + 54 * ratioHeight , newWidth, (int) (newHeight - 91 * ratioHeight));
GL11.glEnable(GL11.GL_SCISSOR_TEST);
for (int i = 0; i < cells.size(); i++) {
//GL11.glColor4d(0.1, 0.6, 0.96, 0.95);
//GL11.glTranslated(0,0, 1);
int pos_x = guiX + 13;
int pos_y = guiY + 37 + (i * (cell_height + gap_y)) + scroll_y ;
drawRect(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height, 0xffffffff);
drawLimited(fontRendererObj, "Cell #" + cells.get(i).getId(), pos_x, pos_y, cell_width / 2, cell_height, 0xff000000);
}
//drawRect(0, 0, this.width, this.height, 0x60ffffff);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
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 = 71;
int max_height = 66;
int scrollbar_add = -((scroll_y * max_height) / scrollable_cells);
int scrollbar_y = (int) (guiY + 38 + scrollbar_add); // 98 - 163
int scrollbar_y = (int) (guiY + 42 + scrollbar_add); // 98 - 163
drawRect(scrollbar_x, scrollbar_y, scrollbar_x + 6, scrollbar_y + 6, 0xff000000);
}
@ -113,27 +91,23 @@ public class GuiJailManager extends GuiScreen {
return;
}
wdth = width;
hght = height;
int guiX = (width - guiWidth) / 2;
int guiY = (height - guiHeight) / 2;
buttonList.clear();
for (int i = 0; i < cells.size(); i++) {
//GL11.glColor4d(0.1, 0.6, 0.96, 0.95);
//GL11.glTranslated(0,0, 1);
int pos_x = guiX + 13;
int pos_y = guiY + 37 + (i * (cell_height + gap_y)) + scroll_y ;
drawRect(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height, 0xffffffff);
drawLimited(fontRendererObj, "Cell #" + cells.get(i).getId(), pos_x, pos_y, cell_width / 2, cell_height, 0xff000000);
}
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 ;
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));
@ -142,9 +116,22 @@ public class GuiJailManager extends GuiScreen {
@Override
protected void actionPerformed(GuiButton button) {
switch (button.id) {
case 0:
break;
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
}
else if (button.id == 1) { // Delete
if (cell_selected == -1)
return;
CommonProxy.network.sendToServer(new NetworkJailManager("delete~" + cell_selected));
}
super.actionPerformed(button);
}

View file

@ -9,6 +9,7 @@ import gp_dbc.Main;
import gp_dbc.config.ConfigManager;
import gp_dbc.network.client.NetworkDeleteItemC;
import gp_dbc.proxy.CommonProxy;
import gp_dbc.system.Cell;
import gp_dbc.system.Handcuff;
import gp_dbc.utils.EntityUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -78,20 +79,8 @@ public class ItemGPHandcuff extends Item {
if (entity instanceof EntityPlayer) {
EntityPlayer inmate = (EntityPlayer) entity;
/*if (Handcuff.isHandcuffed(inmate)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.already_handcuffed")));
if (errorManager(inmate, player))
return stack;
}*/
if (gp.jail.isInJail(inmate)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.already_in_jail")));
return stack;
}
if (!gp.isInGalacticPatrol(player)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.not_galactic_patrol")));
return stack;
}
NBTTagCompound nbtPlayer = JRMCoreH.nbt(inmate, "pres");
boolean ko = nbtPlayer.getInteger("jrmcHar4va") > 0;
@ -106,13 +95,44 @@ public class ItemGPHandcuff extends Item {
}
}
}
player.setItemInUse(stack, getMaxItemUseDuration(stack));
else
timeStart = System.currentTimeMillis();
player.setItemInUse(stack, getMaxItemUseDuration(stack));
//System.out.println(itemStack.stackSize);
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;
}
if (gp.jail.getCells().isEmpty()) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.unavailable_cell")));
return true;
}
try { // Look if there is a place in one cell
if (gp.jail.getRandomCell() == null) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.unavailable_cell")));
return true;
}
} catch (Exception e){System.out.println(e.getMessage());};
if (gp.jail.isInJail(inmate)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.already_in_jail")));
return true;
}
if (!gp.isInGalacticPatrol(player)) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.not_galactic_patrol")));
return true;
}
return false;
}
@SuppressWarnings({ "unchecked" })
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {

View file

@ -9,6 +9,7 @@ import gp_dbc.network.client.NetworkJailManagerC;
import gp_dbc.proxy.CommonProxy;
import gp_dbc.system.Cell;
import gp_dbc.utils.Data;
import gp_dbc.utils.PlayerUtils;
import gp_dbc.utils.RayTrace;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@ -38,6 +39,9 @@ public class ItemJailManager extends Item {
@Override
@SideOnly(Side.SERVER)
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
if (OP_JAIL_MANAGER && !PlayerUtils.isOP(player))
return itemStack;
if (player.isSneaking()) {
MovingObjectPosition trace = RayTrace.rayTraceServer(player, 5);
if (trace != null && trace.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {

View file

@ -7,8 +7,13 @@ import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gp_dbc.gui.GuiHandcuffed;
import gp_dbc.render.RenderHandcuffIcon;
import gp_dbc.system.Handcuff;
import gp_dbc.system.Handcuffed;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
public class NetworkHandcuffedC implements IMessage {
private String toSend;
@ -44,7 +49,7 @@ public class NetworkHandcuffedC implements IMessage {
if (key.equals("start")) {
try {
GuiHandcuffed.startTime = Long.parseLong(split[1]);
GuiHandcuffed.timeToWait = Long.parseLong(split[2]);
Handcuffed.timeToWait = Long.parseLong(split[2]);
} catch (Exception e) {
}
@ -52,6 +57,17 @@ public class NetworkHandcuffedC implements IMessage {
}
else if (key.equals("end"))
GuiHandcuffed.handcuffed = false;
else if (key.equals("delete")) {
RenderHandcuffIcon.playerAroundHandcuffed.remove(UUID.fromString(split[1]));
}
else if (key.equals("update")) {
try {
RenderHandcuffIcon.playerAroundHandcuffed.put(UUID.fromString(split[1]), Long.parseLong(split[2]));
Handcuffed.timeToWait = Long.parseLong(split[3]);
} catch (Exception e) {
System.out.println(e);
}
}
return null;
}

View file

@ -48,7 +48,7 @@ public class NetworkJailManagerC implements IMessage {
String[] split = message.toSend.split("~");
String key = split[0];
if (key.equals("open")) {
if (key.equals("open") || key.equals("refresh")) {
List<Cell> cells = new ArrayList<>();
@ -79,8 +79,7 @@ public class NetworkJailManagerC implements IMessage {
UUID uuid = UUID.fromString(info_inmate[2]);
Inmate inmate = new Inmate(cell, uuid, sec_in_jail, time_start_jail);
cell.addInmate(inmate);
new Inmate(cell, uuid, sec_in_jail, time_start_jail);
}
}
cells.add(cell);

View file

@ -0,0 +1,80 @@
package gp_dbc.network.server;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import gp_dbc.network.client.NetworkJailManagerC;
import gp_dbc.proxy.CommonProxy;
import gp_dbc.system.Cell;
import gp_dbc.utils.PlayerUtils;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import static gp_dbc.Main.gp;
import static gp_dbc.config.ConfigManager.*;
public class NetworkJailManager implements IMessage {
private String toSend;
public NetworkJailManager() {}
public NetworkJailManager(String toSend) {
this.toSend = toSend;
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf,toSend);
}
@Override
public void fromBytes(ByteBuf buf) {
toSend = ByteBufUtils.readUTF8String(buf);
}
public static class MyMessageHandler implements
IMessageHandler<NetworkJailManager, IMessage> {
@Override
public IMessage onMessage(NetworkJailManager message,
MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
if (OP_JAIL_MANAGER && !PlayerUtils.isOP(player))
return null;
String[] split = message.toSend.split("~");
String key = split[0];
if (key.equals("delete")) {
try {
int id_cell = Integer.parseInt(split[1]);
gp.jail.removeCell(id_cell);
String cells = "";
for (Cell cell : gp.jail.getCells())
cells += cell.toString() + "#";
CommonProxy.network.sendTo(new NetworkJailManagerC("refresh~" + cells), (EntityPlayerMP) player);
} catch (Exception e) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Error delete cell"));
}
}
else if (key.equals("edit")) {
}
return null;
}
}
}

View file

@ -0,0 +1,51 @@
package gp_dbc.network.server;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import gp_dbc.utils.InputUtils;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
public class NetworkKeyManage implements IMessage {
private String toSend;
public NetworkKeyManage() {}
public NetworkKeyManage(String toSend) {
this.toSend = toSend;
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf,toSend);
}
@Override
public void fromBytes(ByteBuf buf) {
toSend = ByteBufUtils.readUTF8String(buf);
}
public static class MyMessageHandler implements
IMessageHandler<NetworkKeyManage, IMessage> {
@Override
public IMessage onMessage(NetworkKeyManage message,
MessageContext ctx) {
String[] split = message.toSend.split("~");
String key = split[0];
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
try {
if (key.equals("useItem"))
InputUtils.useItemPressedPlayers.put(player.getUniqueID(), Boolean.parseBoolean(split[1]));
} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
}
}

View file

@ -4,12 +4,15 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import gp_dbc.gui.GuiHandcuffed;
import gp_dbc.render.RenderHandcuffIcon;
import net.minecraftforge.common.MinecraftForge;
public class ClientProxy extends CommonProxy {
public void preInit(FMLPreInitializationEvent $e) {
super.preInit($e);
MinecraftForge.EVENT_BUS.register(new RenderHandcuffIcon());
}
public void init(FMLInitializationEvent $e) {

View file

@ -1,5 +1,6 @@
package gp_dbc.proxy;
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;
@ -10,6 +11,11 @@ import gp_dbc.Main;
import gp_dbc.network.client.NetworkDeleteItemC;
import gp_dbc.network.client.NetworkHandcuffedC;
import gp_dbc.network.client.NetworkJailManagerC;
import gp_dbc.network.server.NetworkJailManager;
import gp_dbc.network.server.NetworkKeyManage;
import gp_dbc.system.Handcuff;
import gp_dbc.utils.InputUtils;
import net.minecraftforge.common.MinecraftForge;
public class CommonProxy {
@ -17,6 +23,8 @@ public class CommonProxy {
public void preInit(FMLPreInitializationEvent $e) {
FMLCommonHandler.instance().bus().register(new InputUtils());
network = NetworkRegistry.INSTANCE.newSimpleChannel(Main.MODID + "_1");
int i = 0;
@ -27,6 +35,8 @@ public class CommonProxy {
network.registerMessage(NetworkJailManagerC.MyMessageHandlerC.class, NetworkJailManagerC.class, i++, Side.CLIENT);
// Client to Server
network.registerMessage(NetworkJailManager.MyMessageHandler.class, NetworkJailManager.class, i++, Side.SERVER);
network.registerMessage(NetworkKeyManage.MyMessageHandler.class, NetworkKeyManage.class, i++, Side.SERVER);
}

View file

@ -4,10 +4,12 @@ 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 fastcraft.H;
import gp_dbc.TemporaryEvent;
import gp_dbc.config.ConfigManager;
import gp_dbc.system.Handcuff;
import gp_dbc.system.TimeJail;
import net.minecraftforge.common.MinecraftForge;
public class ServerProxy extends CommonProxy{
@ -18,7 +20,10 @@ public class ServerProxy extends CommonProxy{
FMLCommonHandler.instance().bus().register(new TemporaryEvent());
FMLCommonHandler.instance().bus().register(new TimeJail());
FMLCommonHandler.instance().bus().register(new Handcuff());
Handcuff handcuff = new Handcuff();
FMLCommonHandler.instance().bus().register(handcuff);
MinecraftForge.EVENT_BUS.register(handcuff);
ConfigManager.init($e.getModConfigurationDirectory().toString());
}

View file

@ -0,0 +1,152 @@
package gp_dbc.render;
import JinRyuu.JRMCore.JRMCoreH;
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.gui.GuiHandcuffed;
import gp_dbc.system.Handcuffed;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.culling.Frustrum;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
public class RenderHandcuffIcon extends Gui {
// UUID | start
@SideOnly(Side.CLIENT)
public static HashMap<UUID, Long> playerAroundHandcuffed = new HashMap<>();
public static boolean renderInF1 = false;
public static double heightAbove = 0.6D;
public static List<EntityPlayer> listPlayers;
Minecraft mc = Minecraft.getMinecraft();
public String helmet;
@SubscribeEvent
public void onRenderWorldLast(RenderWorldLastEvent event) {
if (!renderInF1 && !Minecraft.isGuiEnabled())
return;
EntityLivingBase cameraEntity = mc.renderViewEntity;
Vec3 renderingVector = cameraEntity.getPosition(event.partialTicks);
Frustrum frustrum = new Frustrum();
double viewX = cameraEntity.lastTickPosX + (cameraEntity.posX - cameraEntity.lastTickPosX) * event.partialTicks;
double viewY = cameraEntity.lastTickPosY + (cameraEntity.posY - cameraEntity.lastTickPosY) * event.partialTicks;
double viewZ = cameraEntity.lastTickPosZ + (cameraEntity.posZ - cameraEntity.lastTickPosZ) * event.partialTicks;
frustrum.setPosition(viewX, viewY, viewZ);
WorldClient client = mc.theWorld;
EntityPlayer mainPlayer = mc.thePlayer;
listPlayers = Minecraft.getMinecraft().theWorld.playerEntities;
//Set<Entity> entities = (Set<Entity>)ReflectionHelper.getPrivateValue(WorldClient.class, client, new String[] { "entityList", "field_73032_d", "J" });
for (EntityPlayer player : listPlayers) {
if (player != null
&& player.isInRangeToRender3d(renderingVector.xCoord, renderingVector.yCoord, renderingVector.zCoord) && (player.ignoreFrustumCheck || frustrum.isBoundingBoxInFrustum(player.boundingBox))
&& player.isEntityAlive()
&& playerAroundHandcuffed.containsKey(player.getUniqueID()))
renderPseudo((EntityLivingBase) player, event.partialTicks, (Entity) cameraEntity, 13816530);
}
}
public void renderPseudo(EntityLivingBase passedEntity, float partialTicks, Entity viewPoint, int opacity) {
if (passedEntity.riddenByEntity != null)
return;
EntityPlayer player = (EntityPlayer) passedEntity;
Minecraft mc = Minecraft.getMinecraft();
float pastTranslate = 0.0F;
float distance = passedEntity.getDistanceToEntity(viewPoint);
double x = passedEntity.lastTickPosX + (passedEntity.posX - passedEntity.lastTickPosX) * partialTicks;
double y = passedEntity.lastTickPosY + (passedEntity.posY - passedEntity.lastTickPosY) * partialTicks;
double z = passedEntity.lastTickPosZ + (passedEntity.posZ - passedEntity.lastTickPosZ) * partialTicks;
float scale = 0.026666673F;
GL11.glPushMatrix();
GL11.glTranslatef((float) (x - RenderManager.renderPosX), (float) (y - RenderManager.renderPosY + passedEntity.height + heightAbove), (float) (z - RenderManager.renderPosZ));
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
GL11.glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
float viewX = RenderManager.instance.playerViewX;
if (passedEntity == mc.thePlayer)
viewX = Math.min(Math.max(RenderManager.instance.playerViewX, -5), 5);
GL11.glRotatef(viewX, 1.0F, 0.0F, 0.0F);
//System.out.println(RenderManager.instance.playerViewX);
GL11.glScalef(-scale, -scale, scale);
GL11.glDisable(2896);
GL11.glDepthMask(false);
GL11.glDisable(2929);
GL11.glDisable(3553);
GL11.glEnable(3042);
GL11.glBlendFunc(770, 771);
GL11.glTranslatef(0.0F, pastTranslate, 0.0F);
float s = 0.60F;
int pos_y = 0;
if (passedEntity == mc.thePlayer)
pos_y = 120;
float size = 20;
long time_left = (playerAroundHandcuffed.get(player.getUniqueID()) + (Handcuffed.timeToWait * 1000) - System.currentTimeMillis()) / 1000;
GL11.glEnable(3553);
GL11.glPushMatrix();
GL11.glTranslatef(-size, 6.0F, 0.0F);
GL11.glScalef(s, s, s);
mc.fontRenderer.drawString(String.valueOf(time_left), 40, pos_y - 25, opacity, true); // String, x, y, color, shadow(true,false)
mc.renderEngine.bindTexture(new ResourceLocation(Main.MODID, "textures/gui/handcuffed.png"));
int guiWidth = 212 / 2 + 1;
int guiHeight = 320 / 2 + 1;
// Texture
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//GL11.glColor4d(0.1, 0.6, 0.96, 0.95);
//GL11.glTranslated(0,0, 1);
drawTexturedModalRect(0, pos_y-30, 0, 0, guiWidth, guiHeight);
GL11.glPopMatrix();
GL11.glPushMatrix();
float s1 = 0.75F;
GL11.glScalef(s1, s1, s1);
GL11.glPopMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int off = 0;
s1 = 0.5F;
GL11.glScalef(s1, s1, s1);
GL11.glTranslatef(size / s * s1 * 2.0F - 16.0F, 0.0F, 0.0F);
mc.renderEngine.bindTexture(TextureMap.locationItemsTexture);
GL11.glPopMatrix();
GL11.glEnable(2929);
GL11.glDepthMask(true);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
}
}

View file

@ -88,6 +88,10 @@ public class Cell {
return pos.x == x && pos.y == y && pos.z == z && pos.dimension == dimension;
}
public boolean equals(int id) {
return this.id == id;
}
@Override
public String toString() {
String inmates = "";

View file

@ -57,8 +57,10 @@ public class GalacticPatrol {
patrolmans.add(player.getUniqueID());
player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + translateToLocal("success.join_galactic_patrol")));
}
else
else {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.join_galactic_patrol")));
return 4;
}
Data.saveDataUUID(patrolmans, "galactic_patrols");
@ -70,19 +72,19 @@ public class GalacticPatrol {
Data.saveDataUUID(patrolmans, "galactic_patrols");
}
public boolean removeFromGalaticPatrol(EntityPlayer player) {
public int removeFromGalaticPatrol(EntityPlayer player) {
return removeFromGalaticPatrol(player, false);
}
public boolean removeFromGalaticPatrol(EntityPlayer player, boolean chatError) {
public int removeFromGalaticPatrol(EntityPlayer player, boolean chatError) {
return removeFromGalaticPatrol((EntityPlayerMP)player, chatError);
}
public boolean removeFromGalaticPatrol(EntityPlayerMP player) {
public int removeFromGalaticPatrol(EntityPlayerMP player) {
return removeFromGalaticPatrol(player, false);
}
public boolean removeFromGalaticPatrol(EntityPlayerMP player, boolean chatError) {
public int removeFromGalaticPatrol(EntityPlayerMP player, boolean chatError) {
boolean removed = patrolmans.remove(player.getUniqueID());
Data.saveDataUUID(patrolmans, "galactic_patrols");
@ -92,7 +94,7 @@ public class GalacticPatrol {
else
player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + translateToLocal("error.leave_galactic_patrol")));
return removed;
return removed ? 0 : 1;
}
public boolean isInGalacticPatrol(EntityPlayer player) {

View file

@ -6,32 +6,37 @@ 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.network.client.NetworkHandcuffedC;
import gp_dbc.proxy.CommonProxy;
import gp_dbc.utils.InputUtils;
import gp_dbc.utils.PlayerUtils;
import gp_dbc.utils.TextUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import static gp_dbc.Main.gp;
import static gp_dbc.config.ConfigManager.*;
import static gp_dbc.utils.PlayerUtils.getPlayerFromUUID;
import static gp_dbc.utils.PlayerUtils.*;
import static net.minecraft.util.StatCollector.translateToLocal;
public class Handcuff {
// patrol~handcuffed|StartTimeHandcuffed
@SideOnly(Side.SERVER)
public static HashMap<String, Long> handcuffed = new HashMap<>();
//public static HashMap<String, Long> handcuffed = new HashMap<>();
public static List<Handcuffed> handcuffed = new ArrayList<>();
//@SideOnly(Side.CLIENT)
//public static HashMap<UUID, Long> playerAroundHandcuffed = new HashMap<>();
@SideOnly(Side.SERVER)
public static HashMap<UUID, List<Handcuffed>> playersAroundHandcuffed = new HashMap<>();
int tick = 0;
final int SLOWTICK_MAX = 20;//2000;
@ -45,30 +50,32 @@ public class Handcuff {
if (tick >= SLOWTICK_MAX) {
tick = 0;
Iterator<Map.Entry<String, Long>> iterator = handcuffed.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Long> entry = iterator.next();
UUID uuid_patrol = UUID.fromString(entry.getKey().split("~")[0]);
UUID uuid_inmate = UUID.fromString(entry.getKey().split("~")[1]);
long time_start = entry.getValue();
for (int i = 0; i < handcuffed.size(); i++) {
Handcuffed hdfd = handcuffed.get(i);
UUID uuid_patrol = hdfd.jailer;
UUID uuid_inmate = hdfd.inmate;
long time_start = hdfd.start_time;
long time_left = (time_start + (TIME_TO_GO_IN_JAIL * 1000L) - System.currentTimeMillis()) / 1000;
if (time_left <= 0) {
EntityPlayer inmate = getPlayerFromUUID(uuid_inmate);
if (inmate != null)
updateHandcuffedPlayersAround(inmate);
if (time_left <= 0) {
if (inmate != null) {
if (!isHandcuffed(inmate))
continue;
CommonProxy.network.sendTo(new NetworkHandcuffedC("end~"), (EntityPlayerMP) inmate);
JGPlayerMP jgInmate = new JGPlayerMP(inmate);
NBTTagCompound nbt = jgInmate.connectBaseNBT();
nbt.setInteger("jrmcHar4va", 0);
iterator.remove();
removeHandcuffed(inmate);
i--;
EntityPlayer patrol = getPlayerFromUUID(uuid_patrol);
gp.jail.putPlayerInJail(patrol, inmate, 20, patrol != null);
}
else
entry.setValue(-1L);
hdfd.start_time = -1L;
}
}
@ -77,6 +84,49 @@ public class Handcuff {
tick++;
}
// Update les autres joueurs sur le fait qu'ils soient menottés ou non
@SideOnly(Side.SERVER)
public static void updateHandcuffedPlayersAround(EntityPlayer inmate) {
if (!isHandcuffed(inmate)) {
if (playersAroundHandcuffed.containsKey(inmate.getUniqueID())) {
playersAroundHandcuffed.remove(inmate.getUniqueID());
List<EntityPlayer> nearbyPlayers = getNearbyPlayers(inmate, 10);
for (EntityPlayer player : nearbyPlayers)
CommonProxy.network.sendTo(new NetworkHandcuffedC("delete~" + inmate.getUniqueID()), (EntityPlayerMP) player);
}
return;
}
UUID uuid_inmate = inmate.getUniqueID();
List<Handcuffed> playerAroundHandcuffed = new ArrayList<>();
List<Handcuffed> initPlayerAroundHandcuffed = null;
if (playersAroundHandcuffed.containsKey(uuid_inmate)) // already handcuffed
initPlayerAroundHandcuffed = playersAroundHandcuffed.get(uuid_inmate);
boolean different = false;
long time_start_handcuffed = getTimeHandcuffed(inmate);
List<EntityPlayer> nearbyPlayers = getNearbyPlayers(inmate, 10);
for (EntityPlayer player : nearbyPlayers) {
UUID uuid_player = player.getUniqueID();
playerAroundHandcuffed.add(new Handcuffed(uuid_player, time_start_handcuffed));
if (initPlayerAroundHandcuffed == null ||
!Handcuffed.contains_handcuffed(initPlayerAroundHandcuffed, uuid_player, time_start_handcuffed)) {
CommonProxy.network.sendTo(new NetworkHandcuffedC("update~" + inmate.getUniqueID() + "~" + time_start_handcuffed + "~" + TIME_TO_GO_IN_JAIL), (EntityPlayerMP) player);
different = true;
}
}
if (!different && !playerAroundHandcuffed.equals(initPlayerAroundHandcuffed))
different = true;
if (different)
playersAroundHandcuffed.put(uuid_inmate, playerAroundHandcuffed);
}
@SubscribeEvent
public void LogInCheckKOHandcuff(PlayerEvent.PlayerLoggedInEvent event) {
EntityPlayer inmate = event.player;
@ -96,7 +146,7 @@ public class Handcuff {
}*/
long current_time = System.currentTimeMillis();
handcuffed.put(jailer.getUniqueID() + "~" + inmate.getUniqueID(), current_time);
handcuffed.add(new Handcuffed(inmate.getUniqueID(), jailer.getUniqueID(), current_time));
jailer.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + translateToLocal("success.you_handcuffed_him")));
@ -105,16 +155,61 @@ public class Handcuff {
JGPlayerMP jgInmate = new JGPlayerMP(inmate);
NBTTagCompound nbt = jgInmate.connectBaseNBT();
nbt.setInteger("jrmcHar4va", Integer.MAX_VALUE);
nbt.setInteger("jrmcHar4va", TIME_TO_GO_IN_JAIL * 2);
CommonProxy.network.sendTo(new NetworkHandcuffedC("start~" + current_time + "~" + TIME_TO_GO_IN_JAIL), (EntityPlayerMP) inmate);
updateHandcuffedPlayersAround(inmate);
return true;
}
@SideOnly(Side.SERVER)
public static String getHandcuffed(EntityPlayer inmate) {
for (String uuids : handcuffed.keySet()) {
public static Handcuffed getHandcuffed(EntityPlayer inmate) {
for (Handcuffed hdfd : handcuffed) {
if (hdfd.inmate.equals(inmate.getUniqueID()))
return hdfd;
}
return null;
}
@SideOnly(Side.SERVER)
public static long getTimeHandcuffed(EntityPlayer inmate) {
Handcuffed hdfd = getHandcuffed(inmate);
if (hdfd == null)
return 0;
return hdfd.start_time;
}
@SideOnly(Side.SERVER)
public static boolean isHandcuffed(EntityPlayer inmate) {
return getHandcuffed(inmate) != null;
}
@SideOnly(Side.SERVER)
public static boolean removeHandcuffed(EntityPlayer inmate) {
Handcuffed handcuff = getHandcuffed(inmate);
if (handcuff == null)
return false;
handcuffed.remove(handcuff);
JGPlayerMP jgInmate = new JGPlayerMP(inmate);
NBTTagCompound nbt = jgInmate.connectBaseNBT();
nbt.setInteger("jrmcHar4va", 0);
inmate.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + translateToLocal("success.you_are_free")));
updateHandcuffedPlayersAround(inmate);
return true;
}
// liberator~inmate|StartTimeUnhandcuffing
@SideOnly(Side.SERVER)
public static HashMap<String, Long> unhandcuffing = new HashMap<>();
@SideOnly(Side.SERVER)
public static String getUnhandcuffing(EntityPlayer inmate) {
for (String uuids : unhandcuffing.keySet()) {
String[] split = uuids.split("~");
if (split[1].equals(inmate.getUniqueID().toString()))
return uuids;
@ -122,16 +217,65 @@ public class Handcuff {
return null;
}
@SideOnly(Side.SERVER)
public static long getTimeHandcuffed(EntityPlayer inmate) {
String uuids = getHandcuffed(inmate);
if (uuids == null)
return 0;
return handcuffed.get(uuids);
}
@SideOnly(Side.SERVER)
public static boolean isHandcuffed(EntityPlayer inmate) {
return getHandcuffed(inmate) != null;
@SubscribeEvent
public void RemoveHandcuff(EntityInteractEvent event) {
if (event.target instanceof EntityPlayer) {
EntityPlayer target = (EntityPlayer) event.target;
EntityPlayer player = event.entityPlayer;
if (isHandcuffed(target) && player.isSneaking() && getUnhandcuffing(target) == null) {
player.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + translateToLocal("msg.unhandcuffing_someone")));
target.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + translateToLocal("msg.unhandcuffing_you")));
unhandcuffing.put(player.getUniqueID() + "~" + target.getUniqueID(), System.currentTimeMillis());
}
}
}
int tick2 = 0;
@SideOnly(Side.SERVER)
@SubscribeEvent
public void checkAlwaysUnhandcuffing(TickEvent.ServerTickEvent event) {
if (unhandcuffing.isEmpty())
return;
if (tick2 >= SLOWTICK_MAX) {
tick2 = 0;
Iterator<Map.Entry<String, Long>> iterator = unhandcuffing.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Long> entry = iterator.next();
String[] split = entry.getKey().split("~");
UUID liberator_uuid = UUID.fromString(split[0]);
EntityPlayer liberator = PlayerUtils.getPlayerFromUUID(liberator_uuid);
if (liberator == null)
continue;
if ((InputUtils.useItemPressedPlayers.containsKey(liberator_uuid) && !InputUtils.useItemPressedPlayers.get(liberator_uuid))
|| !liberator.isSneaking()) {
iterator.remove();
liberator.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + translateToLocal("msg.stop_unhandcuffing_someone")));
}
else {
EntityPlayer inmate = PlayerUtils.getPlayerFromUUID(UUID.fromString(split[1]));
if (inmate == null)
continue;
long start_time_unhandcuffing = entry.getValue();
long current_time = System.currentTimeMillis();
if (current_time - start_time_unhandcuffing > TIME_UNHANDCUFFING * 1000L) {
removeHandcuffed(inmate);
iterator.remove();
}
}
}
}
else
tick2++;
}
}

View file

@ -0,0 +1,66 @@
package gp_dbc.system;
import org.lwjgl.Sys;
import java.util.List;
import java.util.UUID;
import static gp_dbc.config.ConfigManager.TIME_TO_GO_IN_JAIL;
public class Handcuffed {
public long start_time;
public UUID inmate;
public UUID jailer;
public static long timeToWait = TIME_TO_GO_IN_JAIL;
public Handcuffed(UUID inmate, long start_time) {
this(inmate, null, start_time);
}
public Handcuffed(UUID inmate, UUID jailer, long start_time) {
this.inmate = inmate;
this.jailer = jailer;
this.start_time = start_time;
}
public boolean equals(UUID inmate) {
return this.inmate == inmate;
}
public boolean equals(UUID inmate, long start_time) {
return this.inmate == inmate && this.start_time == start_time;
}
public boolean equals(UUID inmate, UUID jailer, long start_time) {
return this.inmate == inmate && this.start_time == start_time && this.jailer == jailer;
}
public static boolean contains_handcuffed(List<Handcuffed> handcuffeds, UUID inmate) {
return contains_handcuffed(handcuffeds, inmate, null);
}
public static boolean contains_handcuffed(List<Handcuffed> handcuffeds, UUID inmate, Long start_time) {
return contains_handcuffed(handcuffeds, inmate, null, null);
}
public static boolean contains_handcuffed(List<Handcuffed> handcuffeds, UUID inmate, UUID jailer, Long start_time) {
for (Handcuffed hdfd : handcuffeds) {
if (start_time == null && jailer == null) {
if (hdfd.equals(inmate))
return true;
}
else if (start_time == null) {
if (hdfd.equals(inmate, start_time))
return true;
}
else
if (hdfd.equals(inmate, jailer, start_time))
return true;
}
return false;
}
}

View file

@ -48,19 +48,31 @@ public class Jail {
return false;
}
private boolean contains_cells(int id) {
for (Cell cell : cells)
if (cell.equals(id))
return true;
return false;
}
public boolean addCell(int x, int y, int z, int dimension) {
if (contains_cells(x, y , z , dimension))
return false;
cells.add(new Cell(x, y, z, dimension));
int id = 0;
while (contains_cells(id) && !cells.isEmpty() && id < 99)
id++;
cells.add(new Cell(x, y, z, dimension, DEFAULT_PLACE_CELL, id));
Data.saveDataString(listCellToListString(), "cells");
return true;
}
public boolean removeCell(int x, int y, int z, int dimension) {
public int removeCell(int x, int y, int z, int dimension) {
if (!contains_cells(x, y , z , dimension))
return false;
return 1;
boolean removed = true;
for (int i = 0; i < cells.size(); i++)
@ -70,7 +82,22 @@ public class Jail {
}
Data.saveDataString(listCellToListString(), "cells");
return removed;
return removed ? 0 : 1;
}
public int removeCell(int id) {
if (!contains_cells(id))
return 1;
boolean removed = true;
for (int i = 0; i < cells.size(); i++)
if (cells.get(i).equals(id)) {
removed = cells.remove(i) != null;
break;
}
Data.saveDataString(listCellToListString(), "cells");
return removed ? 0 : 1;
}
public List<Cell>getCells() {

View file

@ -46,4 +46,13 @@ public class EntityUtils {
return pointedEntity;
}
public static List<Entity> getNearbyEntities(EntityPlayer player, double radius) {
World world = player.worldObj;
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(
player.posX - radius, player.posY - radius, player.posZ - radius,
player.posX + radius, player.posY + radius, player.posZ + radius
);
return world.getEntitiesWithinAABB(Entity.class, aabb);
}
}

View file

@ -0,0 +1,34 @@
package gp_dbc.utils;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gp_dbc.network.server.NetworkKeyManage;
import gp_dbc.proxy.CommonProxy;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import java.util.HashMap;
import java.util.UUID;
public class InputUtils {
public static HashMap<UUID, Boolean> useItemPressedPlayers = new HashMap<>();
public boolean useItemPressed;
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void handleMouseInput (InputEvent.MouseInputEvent event) {
GameSettings gameSettings = Minecraft.getMinecraft().gameSettings;
boolean pressed = gameSettings.keyBindUseItem.isPressed();
if (pressed == useItemPressed)
return;
useItemPressed = pressed;
CommonProxy.network.sendToServer(new NetworkKeyManage("useItem~" + useItemPressed));
System.out.println(useItemPressed);
}
}

View file

@ -9,6 +9,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import java.util.List;
import java.util.UUID;
@ -40,6 +42,20 @@ public class PlayerUtils {
CommonProxy.network.sendTo(new NetworkDeleteItemC(stack.getDisplayName() + "~" + number), (EntityPlayerMP) player);
}
@SideOnly(Side.SERVER)
public static boolean isOP(EntityPlayer player) {
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
}
public static List<EntityPlayer> getNearbyPlayers(EntityPlayer player, double radius) {
World world = player.worldObj;
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(
player.posX - radius, player.posY - radius, player.posZ - radius,
player.posX + radius, player.posY + radius, player.posZ + radius
);
return world.getEntitiesWithinAABB(EntityPlayer.class, aabb);
}
@SideOnly(Side.CLIENT)
public static void removeCurrentItem(int number) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;

View file

@ -22,3 +22,7 @@ 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
msg.unhandcuffing_someone=You are unhandcuffing...
msg.unhandcuffing_you=Someone try to unhandcuffing you...
msg.stop_unhandcuffing_someone=You stop unhandcuffing someone
success.you_are_free=You are free!

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB