2.5.18 #2

Merged
JaTiTV merged 5 commits from 2.5.18 into main 2022-01-07 17:17:45 +00:00
7 changed files with 104 additions and 92 deletions
Showing only changes of commit 75ab60bbaa - Show all commits

View File

@ -5,7 +5,6 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.t2code.lib.Bungee.Lib.messages.Bsend; import net.t2code.lib.Bungee.Lib.messages.Bsend;
import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
public final class BMain extends Plugin { public final class BMain extends Plugin {
@ -86,7 +85,6 @@ public final class BMain extends Plugin {
} }
public static Boolean pluginNotFound(String pl, Integer spigotID, double ver) { public static Boolean pluginNotFound(String pl, Integer spigotID, double ver) {
if (ProxyServer.getInstance().getPluginManager().getPlugin(pl) == null) { if (ProxyServer.getInstance().getPluginManager().getPlugin(pl) == null) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!"); plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
ProxyServer.getInstance().getConsole().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " + ProxyServer.getInstance().getConsole().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " +

View File

@ -11,9 +11,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class ItemChange { public class ItemChange {
public static void itemChange(Player player) { public static void itemChange(Player player, Boolean setCursor) {
Integer slot; Integer slot;
if (SelectConfig.UseItem_InventorySlotEnforce){ if (SelectConfig.UseItem_InventorySlotEnforce) {
slot = SelectConfig.UseItem_InventorySlot; slot = SelectConfig.UseItem_InventorySlot;
} else { } else {
if (Select_Database.selectSlot(player) == null) { if (Select_Database.selectSlot(player) == null) {
@ -26,6 +26,16 @@ public class ItemChange {
if (!SelectConfig.UseItem_Enable) { if (!SelectConfig.UseItem_Enable) {
return; return;
} }
if (SelectConfig.UseItemGameModeProtection) {
if (SelectConfig.UseItemGameModeMode.equalsIgnoreCase("blacklist") && SelectConfig.UseItemGameModeList.contains(player.getGameMode().toString())) {
removeItem(player);
return;
}
if (SelectConfig.UseItemGameModeMode.equalsIgnoreCase("whitelist") && !SelectConfig.UseItemGameModeList.contains(player.getGameMode().toString())) {
removeItem(player);
return;
}
}
if (SelectConfig.UseItem_GiveOnlyOnFirstJoin) { if (SelectConfig.UseItem_GiveOnlyOnFirstJoin) {
if (!SelectConfig.UseItem_AllowToggle || Select_Database.selectItemStatus(player)) { if (!SelectConfig.UseItem_AllowToggle || Select_Database.selectItemStatus(player)) {
if (!player.hasPlayedBefore()) { if (!player.hasPlayedBefore()) {
@ -42,58 +52,74 @@ public class ItemChange {
} }
return; return;
} }
if (SelectConfig.UseItem_GiveOnEveryJoin) { if (!SelectConfig.UseItem_GiveOnEveryJoin) {
new BukkitRunnable() { return;
@Override }
public void run() { new BukkitRunnable() {
for (int iam = 0; iam < player.getInventory().getSize() - 5; iam++) { @Override
ItemStack itm = player.getInventory().getItem(iam); public void run() {
if (itm != null) { removeItem(player);
if (itm.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm.getType() == ItemVersion.getHead()) { if (!SelectConfig.UseItem_AllowToggle || Select_Database.selectItemStatus(player)) {
if (itm.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) { if (SelectConfig.UseItem_InventorySlotEnforce || player.getInventory().getItem(slot - 1) == null) {
player.getInventory().remove(itm); Give_UseItem.onGive(player);
player.updateInventory(); if (setCursor) {
break; setCursor(player, slot);
} }
} else if (SelectConfig.UseItem_InventorySlot_FreeSlot) {
boolean empty = false;
for (int i = 0; i < 9; i++) {
if (player.getInventory().getItem(i) == null) {
empty = true;
break;
} }
} }
} if (empty) {
if (!SelectConfig.UseItem_AllowToggle || Select_Database.selectItemStatus(player)) { Give_UseItem.onGiveADD(player);
if (SelectConfig.UseItem_InventorySlotEnforce || player.getInventory().getItem(slot - 1) == null) {
Give_UseItem.onGive(player);
if (SelectConfig.Cursor_ToGUIItem_OnLogin) {
if (SelectConfig.Cursor_ToGUIItem_OnlyOnFirstLogin) {
if (!player.hasPlayedBefore()) {
player.getInventory().setHeldItemSlot(slot - 1);
}
} else {
if (SelectConfig.Bungee) {
if (SelectConfig.UseItem_ServerChange) {
player.getInventory().setHeldItemSlot(slot - 1);
} else {
if (Main.bungeejoinplayers.contains(player.getName())) {
player.getInventory().setHeldItemSlot(slot - 1);
Main.bungeejoinplayers.remove(player.getName());
}
}
} else player.getInventory().setHeldItemSlot(slot - 1);
}
}
} else if (SelectConfig.UseItem_InventorySlot_FreeSlot) {
boolean empty = false;
for (int i = 0; i < 9; i++) {
if (player.getInventory().getItem(i) == null) {
empty = true;
break;
}
}
if (empty) {
Give_UseItem.onGiveADD(player);
}
} }
} }
} }
}.runTaskLater(Main.plugin, 1L * 1); }
}.runTaskLater(Main.plugin, 1L * 1);
}
private static void setCursor(Player player, int slot) {
if (!SelectConfig.Cursor_ToGUIItem_OnLogin) {
return;
}
if (SelectConfig.Cursor_ToGUIItem_OnlyOnFirstLogin) {
if (!player.hasPlayedBefore()) {
player.getInventory().setHeldItemSlot(slot - 1);
}
return;
}
if (!SelectConfig.Bungee) {
player.getInventory().setHeldItemSlot(slot - 1);
return;
}
if (SelectConfig.UseItem_ServerChange) {
player.getInventory().setHeldItemSlot(slot - 1);
return;
}
if (Main.bungeejoinplayers.contains(player.getName())) {
player.getInventory().setHeldItemSlot(slot - 1);
Main.bungeejoinplayers.remove(player.getName());
} }
} }
private static void removeItem(Player player) {
for (int iam = 0; iam < player.getInventory().getSize() - 5; iam++) {
ItemStack itm = player.getInventory().getItem(iam);
if (itm != null) {
if (itm.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm.getType() == ItemVersion.getHead()) {
if (itm.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
player.getInventory().remove(itm);
player.updateInventory();
break;
}
}
}
}
}
} }

View File

@ -74,6 +74,6 @@ public class PluginEvent implements Listener {
} }
private static void clearGive(Player player) { private static void clearGive(Player player) {
ItemChange.itemChange(player); ItemChange.itemChange(player, false);
} }
} }

View File

@ -36,7 +36,7 @@ public class Events implements Listener {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
ItemChange.itemChange(e.getPlayer()); ItemChange.itemChange(e.getPlayer(), true);
} }
}.runTaskLater(Main.plugin, 20L * 1); }.runTaskLater(Main.plugin, 20L * 1);
} }
@ -73,7 +73,7 @@ public class Events implements Listener {
public void onRespawn(PlayerRespawnEvent e) { public void onRespawn(PlayerRespawnEvent e) {
Player player = e.getPlayer(); Player player = e.getPlayer();
if (SelectConfig.UseItem_Enable) { if (SelectConfig.UseItem_Enable) {
ItemChange.itemChange(player); ItemChange.itemChange(player, false);
//if (!SelectConfig.UseItem_AllowToggle || Select_Database.selectItemStatus(player)) { //if (!SelectConfig.UseItem_AllowToggle || Select_Database.selectItemStatus(player)) {
// if (SelectConfig.UseItem_GiveOnlyOnFirstJoin) { // if (SelectConfig.UseItem_GiveOnlyOnFirstJoin) {
// if (!player.hasPlayedBefore()) { // if (!player.hasPlayedBefore()) {
@ -99,38 +99,17 @@ public class Events implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onGameModeChange(PlayerGameModeChangeEvent e) { public void onGameModeChange(PlayerGameModeChangeEvent e) {
Player player = e.getPlayer(); Player player = e.getPlayer();
if (!SelectConfig.UseItemGameModeChangeEnable) {
return;
}
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
if (SelectConfig.UseItemGameModeChangeEnable) { ItemChange.itemChange(player, false);
if (SelectConfig.UseItemGameModeMode.equalsIgnoreCase("blacklist") && SelectConfig.UseItemGameModeList.contains(player.getGameMode().toString())) {
removeItem(player);
return;
}
if (SelectConfig.UseItemGameModeMode.equalsIgnoreCase("whitelist") && !SelectConfig.UseItemGameModeList.contains(player.getGameMode().toString())) {
removeItem(player);
return;
}
ItemChange.itemChange(player);
}
} }
}.runTaskLater(Main.plugin, SelectConfig.UseItemGameModeChangeDelayInTicks * 1L); }.runTaskLater(Main.plugin, SelectConfig.UseItemGameModeChangeDelayInTicks * 1L);
} }
private static void removeItem(Player player) {
for (int iam = 0; iam < player.getInventory().getSize() - 5; iam++) {
ItemStack itm = player.getInventory().getItem(iam);
if (itm != null) {
if (itm.getType() == Material.valueOf(SelectConfig.UseItem_Material) || itm.getType() == ItemVersion.getHead()) {
if (itm.getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
player.getInventory().remove(itm);
player.updateInventory();
break;
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent e) { public void onInteract(PlayerInteractEvent e) {
@ -204,14 +183,14 @@ public class Events implements Listener {
&& e.getCursor().getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) { && e.getCursor().getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
p.closeInventory(); p.closeInventory();
e.setCancelled(true); e.setCancelled(true);
ItemChange.itemChange(p); ItemChange.itemChange(p, false);
} }
if (e.getOldCursor() != null && e.getOldCursor().hasItemMeta() && e.getOldCursor().getItemMeta().hasDisplayName() if (e.getOldCursor() != null && e.getOldCursor().hasItemMeta() && e.getOldCursor().getItemMeta().hasDisplayName()
&& e.getOldCursor().getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) { && e.getOldCursor().getItemMeta().getDisplayName().equals(SelectConfig.UseItem_Name)) {
p.closeInventory(); p.closeInventory();
e.setCancelled(true); e.setCancelled(true);
ItemChange.itemChange(p); ItemChange.itemChange(p, false);
} }
} }
} }

View File

@ -96,11 +96,11 @@ public class ConfigCreate {
Config.set("UseItem.Join.Cursor.ToGUIItem.Spigot.OnOnlyFirstLogin", true, yamlConfiguration); Config.set("UseItem.Join.Cursor.ToGUIItem.Spigot.OnOnlyFirstLogin", true, yamlConfiguration);
Config.set("UseItem.Join.Cursor.ToGUIItem.Bungee.OnServerChange", false, yamlConfiguration); Config.set("UseItem.Join.Cursor.ToGUIItem.Bungee.OnServerChange", false, yamlConfiguration);
Config.set("Advanced.UseItem.GameModeChange.Enable", true, yamlConfiguration); Config.set("Advanced.UseItem.GameMode.Change.Enable", true, yamlConfiguration);
Config.set("Advanced.UseItem.GameModeChange.DelayInTicks", 1, yamlConfiguration); Config.set("Advanced.UseItem.GameMode.Change.DelayInTicks", 1, yamlConfiguration);
Config.set("Advanced.UseItem.GameModeChange.Protection.Enable", false, yamlConfiguration); Config.set("Advanced.UseItem.GameMode.Protection.Enable", false, yamlConfiguration);
Config.set("Advanced.UseItem.GameModeChange.Protection.Mode", "blacklist", yamlConfiguration); Config.set("Advanced.UseItem.GameMode.Protection.Mode", "blacklist", yamlConfiguration);
Config.set("Advanced.UseItem.GameModeChange.Protection.List", Arrays.asList("CREATIVE", "Spectator"), yamlConfiguration); Config.set("Advanced.UseItem.GameMode.Protection.List", Arrays.asList("CREATIVE", "Spectator"), yamlConfiguration);
Config.set("Sound.Enable", true, yamlConfiguration); Config.set("Sound.Enable", true, yamlConfiguration);

View File

@ -11,6 +11,7 @@ import org.bukkit.Sound;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class SelectConfig { public class SelectConfig {
@ -145,11 +146,16 @@ public class SelectConfig {
Cursor_ToGUIItem_OnlyOnFirstLogin = yamlConfiguration.getBoolean("UseItem.Join.Cursor.ToGUIItem.Spigot.OnlyOnFirstLogin"); Cursor_ToGUIItem_OnlyOnFirstLogin = yamlConfiguration.getBoolean("UseItem.Join.Cursor.ToGUIItem.Spigot.OnlyOnFirstLogin");
UseItem_ServerChange = yamlConfiguration.getBoolean("UseItem.Join.Cursor.ToGUIItem.Bungee.OnServerChange"); UseItem_ServerChange = yamlConfiguration.getBoolean("UseItem.Join.Cursor.ToGUIItem.Bungee.OnServerChange");
UseItemGameModeChangeEnable = yamlConfiguration.getBoolean("Advanced.UseItem.GameModeChange.Enable"); UseItemGameModeChangeEnable = yamlConfiguration.getBoolean("Advanced.UseItem.GameMode.Change.Enable");
UseItemGameModeChangeDelayInTicks = yamlConfiguration.getInt("Advanced.UseItem.GameModeChange.DelayInTicks"); UseItemGameModeChangeDelayInTicks = yamlConfiguration.getInt("Advanced.UseItem.GameMode.Change.DelayInTicks");
UseItemGameModeProtection = yamlConfiguration.getBoolean("Advanced.UseItem.GameModeChange.Protection.Enable"); UseItemGameModeProtection = yamlConfiguration.getBoolean("Advanced.UseItem.GameMode.Protection.Enable");
UseItemGameModeMode = yamlConfiguration.getString("Advanced.UseItem.GameModeChange.Protection.Mode"); UseItemGameModeMode = yamlConfiguration.getString("Advanced.UseItem.GameMode.Protection.Mode");
UseItemGameModeList = yamlConfiguration.getStringList("Advanced.UseItem.GameModeChange.Protection.List"); List<String> gml = new ArrayList<>();
for (String gm : yamlConfiguration.getStringList("Advanced.UseItem.GameMode.Protection.List")){
gml.add(gm.toUpperCase());
}
UseItemGameModeList = gml;
Sound_Enable = yamlConfiguration.getBoolean("Sound.Enable"); Sound_Enable = yamlConfiguration.getBoolean("Sound.Enable");

View File

@ -14,7 +14,10 @@ public class CGuiAPI {
public static Boolean JoinDisable = false; public static Boolean JoinDisable = false;
public static void onItemChange(Player player) { public static void onItemChange(Player player) {
ItemChange.itemChange(player); ItemChange.itemChange(player, false);
}
public static void onItemChange(Player player, Boolean setCursor) {
ItemChange.itemChange(player, setCursor);
} }
public static void disableItemGiveOnJoin(Boolean disableItemGiveOnJoin) { public static void disableItemGiveOnJoin(Boolean disableItemGiveOnJoin) {