Skip to content

Commit

Permalink
v1.7.4-pre-release.14 bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jonagamerpro1234 committed Jan 30, 2022
1 parent 23f5efc commit 89d3cb9
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package jss.customjoinandquitmessages;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -12,7 +14,9 @@
import jss.customjoinandquitmessages.config.Lang;
import jss.customjoinandquitmessages.config.PreConfigLoader;
import jss.customjoinandquitmessages.hook.HookManager;
import jss.customjoinandquitmessages.listener.InventoryListener;
import jss.customjoinandquitmessages.listener.JoinListener;
import jss.customjoinandquitmessages.manager.InventoryView;
import jss.customjoinandquitmessages.utils.EventUtils;
import jss.customjoinandquitmessages.utils.Logger;
import jss.customjoinandquitmessages.utils.Logger.Level;
Expand Down Expand Up @@ -40,8 +44,12 @@ public class CustomJoinAndQuitMessages extends JavaPlugin{
private String updateVersion;
private boolean useLegacyConfig = false;

private ArrayList<InventoryView> inventoryViews;


public void onLoad() {
Utils.sendLoadTitle(version);
inventoryViews = new ArrayList<>();
}
public void onEnable() {
plugin = this;
Expand Down Expand Up @@ -120,6 +128,7 @@ public void setupCommands() {

public void setupEvents() {
new JoinListener(this);
new InventoryListener(this);
}

public void reloadAllFiles() {
Expand All @@ -128,11 +137,6 @@ public void reloadAllFiles() {
preConfigLoader.loadLangs();
}

@Deprecated
public static CustomJoinAndQuitMessages getPlugin() {
return plugin;
}

public static CustomJoinAndQuitMessages getInstance() {
return plugin;
}
Expand Down Expand Up @@ -168,4 +172,27 @@ public PreConfigLoader getPreConfigLoader() {
public String getUpdateVersion() {
return updateVersion;
}

public void registerInventory(Player player, String inventoryName) {
if(getInventoryView(player) == null) {
inventoryViews.add(new InventoryView(player, inventoryName));
}
}

public void unregisterInventory(Player player) {
for(int i = 0; i < inventoryViews.size(); i++) {
if(((InventoryView)inventoryViews.get(i)).getPlayer().getName().equals(player.getName())) {
inventoryViews.remove(i);
}
}
}

public InventoryView getInventoryView(Player player) {
for(int i = 0; i < inventoryViews.size(); i++) {
if(((InventoryView) inventoryViews.get(i)).getPlayer().getName().equals(player.getName())) {
return (InventoryView) inventoryViews.get(i);
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}

if(args[1].equalsIgnoreCase("title")) {

displayManager.showTitleMessage();
return true;
}

if(args[1].equalsIgnoreCase("actionbar")) {

displayManager.showActionbar();
return true;
}

Expand All @@ -117,6 +117,24 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

if(args[1].equalsIgnoreCase("sound")) {


if(args.length <= 2) {

if(args[2].equalsIgnoreCase("join")) {
displayManager.showJoinSound();
return true;
}

if(args[2].equalsIgnoreCase("quit")) {
displayManager.showQuitSound();
return true;
}

Utils.sendColorMessage(j, Utils.getPrefixPlayer() + " " + plugin.Locale().Error_Cmd);
return true;
}

Utils.sendColorMessage(j, "Please select one of these two options to execute the function <join|quit>");
return true;
}

Expand All @@ -126,7 +144,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}

if(args[1].equalsIgnoreCase("all")) {

displayManager.showAllMessage();
return true;
}

Expand Down Expand Up @@ -205,6 +223,12 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String labe
options.add("welcome");
}
break;
case 3:
if(args[0].equalsIgnoreCase("sound")) {
options.add("join");
options.add("quit");
}
break;
}
}
return Utils.TabLimit(options, lastArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ public DisplayGui(Player player, CustomJoinAndQuitMessages plugin) {
}

public void create() {
inv = Bukkit.createInventory(null, 27, Utils.color("&6&lDisplay Option"));
inv = Bukkit.createInventory(null, 54, Utils.color("&6&lDisplay Option"));

for(int i = 0; i < 27; i++) {
for(int i = 0; i < 54; i++) {
inv.setItem(i, setDecoration());
if(i == 27) {
if(i == 54) {
break;
}
}
setItems();
}



public ItemStack setDecoration() {
item = XMaterial.BLACK_STAINED_GLASS_PANE.parseItem();
meta = item.getItemMeta();
Expand All @@ -46,11 +49,64 @@ public ItemStack setDecoration() {

public void setItems() {

item = XMaterial.RED_STAINED_GLASS.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&cGroup - (Coming Soon)"));
item.setItemMeta(meta);
inv.setItem(8, item);

item = XMaterial.OAK_SIGN.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aJoin Message"));
item.setItemMeta(meta);
inv.setItem(11, item);

item = XMaterial.OAK_SIGN.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aQuit Message"));
item.setItemMeta(meta);
inv.setItem(13, item);

item = XMaterial.OAK_SIGN.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aWelcome Message"));
item.setItemMeta(meta);
inv.setItem(15, item);

item = XMaterial.OAK_SIGN.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aTitle Message"));
item.setItemMeta(meta);
inv.setItem(29, item);

item = XMaterial.OAK_SIGN.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aActionBar Message"));
item.setItemMeta(meta);
inv.setItem(31, item);

item = XMaterial.OAK_SIGN.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aFirst Join Message"));
item.setItemMeta(meta);
inv.setItem(33, item);

item = XMaterial.NOTE_BLOCK.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aJoin Sound"));
item.setItemMeta(meta);
inv.setItem(39, item);

item = XMaterial.NOTE_BLOCK.parseItem();
meta = item.getItemMeta();
meta.setDisplayName(Utils.color("&aQuit Sound"));
item.setItemMeta(meta);
inv.setItem(41, item);

}

public void open() {
plugin.registerInventory(player, "displaygui");
player.openInventory(inv);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package jss.customjoinandquitmessages.listener;

import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;

import jss.customjoinandquitmessages.CustomJoinAndQuitMessages;
import jss.customjoinandquitmessages.manager.DisplayManager;
import jss.customjoinandquitmessages.manager.InventoryView;
import jss.customjoinandquitmessages.utils.EventUtils;

public class InventoryListener implements Listener{

private CustomJoinAndQuitMessages plugin;
private EventUtils eventUtils = new EventUtils(plugin);

public InventoryListener(CustomJoinAndQuitMessages plugin) {
this.plugin = plugin;
eventUtils.getEventManager().registerEvents(this, plugin);
}

public void onInventoryClick(InventoryClickEvent e) {
Player j = (Player) e.getWhoClicked();
InventoryView view = plugin.getInventoryView(j);

if(view == null) return;
if(!view.getInventoryName().contains("displaygui")) return;
if(e.isShiftClick()) return;
if(e.getCurrentItem() == null || e.getCurrentItem().getType().name().contains("AIR")) {
e.setCancelled(true);
return;
}

if(e.getSlotType() == null) {
e.setCancelled(true);
return;
}else {
if(!e.getClickedInventory().equals(j.getOpenInventory().getTopInventory())) return;

int slot = e.getSlot();
e.setCancelled(true);

DisplayManager displayManager = new DisplayManager(j);

if(slot == 11) {
displayManager.showJoinMessage();
}

if(slot == 13) {
displayManager.showQuitMessage();
}

if(slot == 15) {
displayManager.showWelcomeMessage();
}

if(slot == 29) {
displayManager.showTitleMessage();
}

if(slot == 31) {
displayManager.showActionbar();
}

if(slot == 33) {
displayManager.showFirstJoinMessage();
}

if(slot == 39) {
displayManager.showJoinSound();
}

if(slot == 41) {
displayManager.showQuitSound();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public JoinListener(CustomJoinAndQuitMessages plugin) {
}

@EventHandler
public void onJoin(PlayerJoinEvent e) {
public void onJoinListener(PlayerJoinEvent e) {
FileConfiguration config = plugin.getConfigFile().getConfig();
Player p = e.getPlayer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import com.cryptomorin.xseries.messages.ActionBar;
import com.cryptomorin.xseries.messages.Titles;

import jss.customjoinandquitmessages.CustomJoinAndQuitMessages;
import jss.customjoinandquitmessages.json.Json;
import jss.customjoinandquitmessages.utils.Logger;
Expand All @@ -20,6 +23,16 @@ public DisplayManager(Player player) {
this.player = player;
}

public void showAllMessage() {
this.showFirstJoinMessage();
this.showJoinMessage();
this.showQuitMessage();
this.showTitleMessage();
this.showActionbar();
this.showWelcomeMessage();

}

public void showFirstJoinMessage() {
if(!Settings.firstjoin) {
Logger.warning("&e[showFirstJoinMessage] &b-> &7This feature is disabled and you will not be able to see the preview");
Expand Down Expand Up @@ -217,5 +230,28 @@ public void showWelcomeMessage() {
});
}

public void showTitleMessage() {
if(!Settings.join_title) {
Logger.warning("&e[showTitleMessage] &b-> &7This feature is disabled and you will not be able to see the preview");
return;
}
Titles.sendTitle(player, Settings.join_title_fadein, Settings.join_title_stay, Settings.join_title_fadeout, Settings.join_message_title_title, Settings.join_message_title_subtitle);
}

public void showActionbar() {
if(!Settings.join_actionbar) {
Logger.warning("&e[showActionbar] &b-> &7This feature is disabled and you will not be able to see the preview");
return;
}
ActionBar.sendActionBar(player, Settings.join_message_actionbar_text);
}

public void showJoinSound() {
Utils.sendColorMessage(player, "Test join sound");
}

public void showQuitSound() {
Utils.sendColorMessage(player, "Test quit sound");
}

}
Loading

0 comments on commit 89d3cb9

Please sign in to comment.