<commit_before>package com.gamingmesh.jobs.CMIGUI;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map.Entry;

import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMIGUI.GUIManager.CmiInventoryType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.CommandType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIButtonLocation;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIClickType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIFieldType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIRows;
import com.gamingmesh.jobs.CMIGUI.GUIManager.InvType;
import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.stuff.PageInfo;

public class CMIGui {

    private InventoryType invType;
    private GUIRows gUIRows;
    private Player player;
    private Inventory inv;
    private String title;
    private HashMap<Integer, CMIGuiButton> buttons = new HashMap<Integer, CMIGuiButton>();
    private LinkedHashSet<CMIGuiButton> noSlotButtons = new LinkedHashSet<CMIGuiButton>();

    private HashMap<InvType, GUIFieldType> lock = new HashMap<InvType, GUIFieldType>();
    private HashMap<InvType, String> permLock = new HashMap<InvType, String>();

    private CmiInventoryType type = CmiInventoryType.regular;
    private Object whatShows;

    private boolean allowShift = false;

    public CMIGui() {
    }

    public CMIGui(Player player) {
	this.player = player;
    }

    @Override
    public CMIGui clone() {
	CMIGui g = new CMIGui(player);
	g.setInvSize(gUIRows);
	g.setButtons(buttons);
	g.setInv(inv);
	g.setInvType(invType);
	g.setTitle(title);
	g.setCmiInventoryType(type);
	g.setWhatShows(whatShows);
	return g;
    }

    public boolean isSimilar(CMIGui gui) {

	if (this.getInvSize() != gui.getInvSize())
	    return false;

	if (this.getInvType() != gui.getInvType())
	    return false;

	return true;
    }

    public CMIGui open() {
	GUIManager.openGui(this);
	return this;
    }

    public CMIGui update() {
	GUIManager.softUpdateContent(this);
	return this;
    }

    public InventoryType getInvType() {
	if (invType == null)
	    invType = InventoryType.CHEST;
	return invType;
    }

    public void setInvType(InventoryType invType) {
	this.invType = invType;
    }

    public GUIRows getInvSize() {
	if (gUIRows == null)
	    autoResize();
	return gUIRows;
    }

    public void setInvSize(GUIRows GUIRows) {
	this.gUIRows = GUIRows;
    }

    public void setInvSize(int rows) {
	this.gUIRows = GUIRows.getByRows(rows);
    }

    public void autoResize() {
	this.combineButtons();
	int max = 0;
	for (Entry<Integer, CMIGuiButton> one : this.buttons.entrySet()) {
	    if (one.getKey() > max)
		max = one.getKey();
	}

	if (max < 9) {
	    this.gUIRows = GUIRows.r1;
	} else if (max < 18) {
	    this.gUIRows = GUIRows.r2;
	} else if (max < 27) {
	    this.gUIRows = GUIRows.r3;
	} else if (max < 36) {
	    this.gUIRows = GUIRows.r4;
	} else if (max < 45) {
	    this.gUIRows = GUIRows.r5;
	} else {
	    this.gUIRows = GUIRows.r6;
	}
    }

    public Player getPlayer() {
	return player;
    }

    public void setPlayer(Player player) {
	this.player = player;
    }

    public Inventory getInv() {
	if (inv == null)
	    GUIManager.generateInventory(this);
	return inv;
    }

    public void setInv(Inventory inv) {
	this.inv = inv;
    }

    public String getTitle() {
	if (title == null)
	    title = "";
	return CMIChatColor.translate(title);
    }

    public void updateTitle(String title) {
	setTitle(title);
//	Jobs.getNms().updateInventoryTitle(player, this.title);
    }

    public void setTitle(String title) {
	this.title = title;
    }

    public HashMap<Integer, CMIGuiButton> getButtons() {
	combineButtons();
	return buttons;
    }

    public CMIGui addButton(CMIGuiButton button) {
	return addButton(button, 54);
    }

    public CMIGui addButton(CMIGuiButton button, int maxSlot) {
	if (button.getSlot() != null && buttons.get(button.getSlot()) != null) {
	    for (int ii = button.getSlot(); ii < maxSlot; ii++) {
		CMIGuiButton b = buttons.get(ii);
		if (b == null) {
		    buttons.put(ii, button);
		    break;
		}
	    }
	    return this;<commit_msg>GUI title length is limited in older versions.<commit_after>package com.gamingmesh.jobs.CMIGUI;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map.Entry;

import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMIGUI.GUIManager.CmiInventoryType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.CommandType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIButtonLocation;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIClickType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIFieldType;
import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIRows;
import com.gamingmesh.jobs.CMIGUI.GUIManager.InvType;
import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.CMILib.Version;
import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.stuff.PageInfo;

public class CMIGui {

    private InventoryType invType;
    private GUIRows gUIRows;
    private Player player;
    private Inventory inv;
    private String title;
    private HashMap<Integer, CMIGuiButton> buttons = new HashMap<Integer, CMIGuiButton>();
    private LinkedHashSet<CMIGuiButton> noSlotButtons = new LinkedHashSet<CMIGuiButton>();

    private HashMap<InvType, GUIFieldType> lock = new HashMap<InvType, GUIFieldType>();
    private HashMap<InvType, String> permLock = new HashMap<InvType, String>();

    private CmiInventoryType type = CmiInventoryType.regular;
    private Object whatShows;

    private boolean allowShift = false;

    public CMIGui() {
    }

    public CMIGui(Player player) {
	this.player = player;
    }

    @Override
    public CMIGui clone() {
	CMIGui g = new CMIGui(player);
	g.setInvSize(gUIRows);
	g.setButtons(buttons);
	g.setInv(inv);
	g.setInvType(invType);
	g.setTitle(title);
	g.setCmiInventoryType(type);
	g.setWhatShows(whatShows);
	return g;
    }

    public boolean isSimilar(CMIGui gui) {

	if (this.getInvSize() != gui.getInvSize())
	    return false;

	if (this.getInvType() != gui.getInvType())
	    return false;

	return true;
    }

    public CMIGui open() {
	GUIManager.openGui(this);
	return this;
    }

    public CMIGui update() {
	GUIManager.softUpdateContent(this);
	return this;
    }

    public InventoryType getInvType() {
	if (invType == null)
	    invType = InventoryType.CHEST;
	return invType;
    }

    public void setInvType(InventoryType invType) {
	this.invType = invType;
    }

    public GUIRows getInvSize() {
	if (gUIRows == null)
	    autoResize();
	return gUIRows;
    }

    public void setInvSize(GUIRows GUIRows) {
	this.gUIRows = GUIRows;
    }

    public void setInvSize(int rows) {
	this.gUIRows = GUIRows.getByRows(rows);
    }

    public void autoResize() {
	this.combineButtons();
	int max = 0;
	for (Entry<Integer, CMIGuiButton> one : this.buttons.entrySet()) {
	    if (one.getKey() > max)
		max = one.getKey();
	}

	if (max < 9) {
	    this.gUIRows = GUIRows.r1;
	} else if (max < 18) {
	    this.gUIRows = GUIRows.r2;
	} else if (max < 27) {
	    this.gUIRows = GUIRows.r3;
	} else if (max < 36) {
	    this.gUIRows = GUIRows.r4;
	} else if (max < 45) {
	    this.gUIRows = GUIRows.r5;
	} else {
	    this.gUIRows = GUIRows.r6;
	}
    }

    public Player getPlayer() {
	return player;
    }

    public void setPlayer(Player player) {
	this.player = player;
    }

    public Inventory getInv() {
	if (inv == null)
	    GUIManager.generateInventory(this);
	return inv;
    }

    public void setInv(Inventory inv) {
	this.inv = inv;
    }

    public String getTitle() {
	if (title == null)
	    title = "";
	return CMIChatColor.translate(title);
    }

    public void updateTitle(String title) {
	setTitle(title);
//	Jobs.getNms().updateInventoryTitle(player, this.title);
    }

    public void setTitle(String title) {
	if (Version.isCurrentEqualOrHigher(Version.v1_16_R1)) {
	    if (CMIChatColor.stripColor(title).length() > 64) {
		title = title.substring(0, 63) + "~";
	    }
	} else {
	    if (title.length() > 32) {
		title = title.substring(0, 31) + "~";
	    }
	}
	this.title = title;
    }
    

    public HashMap<Integer, CMIGuiButton> getButtons() {
	combineButtons();
	return buttons;
    }

    public CMIGui addButton(CMIGuiButton button) {
	return addButton(button, 54);
    }

    public CMIGui addButton(CMIGuiButton button, int maxSlot) {
	if (button.getSlot() != null && buttons.get(button.getSlot()) != null) {
	    for (int ii = button.getSlot(); ii < maxSlot; ii++) {
		CMIGuiButton b = buttons.get(ii);
		if (b == null) {
		    buttons.put(ii, button);
		    break;
		}
	    }
	    return this;
{'fraction_non_alphanumeric': 0.1195980985306828, 'fraction_numerical': 0.0054019014693171994, 'mean_word_length': 3.5533694048204625, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5102655', 'n_tokens_mistral': 3475, 'n_tokens_neox': 3310, 'n_words': 675}