Skip to content

Commit

Permalink
Merge pull request #17 from LaBoulangerie/1.20.2
Browse files Browse the repository at this point in the history
1.20.2
  • Loading branch information
PainOchoco authored Dec 22, 2023
2 parents d1c0d2a + 47ea854 commit 7038b1d
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 82 deletions.
22 changes: 14 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<url>https://betonquest.org/nexus/repository/betonquest/</url>
</repository>
<repository>
<id>quickshop-repo</id>
<id>codemc</id>
<url>https://repo.codemc.io/repository/maven-public/</url>
</repository>
<repository>
Expand All @@ -70,19 +70,19 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version>
<version>1.20.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.palmergames.bukkit.towny</groupId>
<artifactId>towny</artifactId>
<version>0.99.0.0</version>
<version>0.100.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.3</version>
<version>2.11.4</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -110,10 +110,16 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.maxgamer</groupId>
<artifactId>QuickShop</artifactId>
<version>5.1.0.9</version>
<groupId>com.ghostchu</groupId>
<artifactId>quickshop-bukkit</artifactId>
<version>5.2.0.6</version>
<scope>provided</scope>
<classifier>shaded</classifier>
</dependency>
<dependency>
<groupId>com.ghostchu</groupId>
<artifactId>simplereloadlib</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.github.LaBoulangerie</groupId>
Expand All @@ -123,7 +129,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.laboulangerie.laboulangeriecore.eastereggs.eEggUtil;
import net.laboulangerie.laboulangeriecore.eco.ConversionInv;
import net.laboulangerie.laboulangeriecore.misc.ChestShopListener;
import net.laboulangerie.laboulangeriecore.misc.DisableCraftListener;
import net.laboulangerie.laboulangeriecore.misc.ElytraGenRemover;
import net.laboulangerie.laboulangeriecore.misc.LaBoulangerieExpansion;
import net.laboulangerie.laboulangeriecore.misc.MiscListener;
Expand Down Expand Up @@ -242,7 +243,7 @@ private void registerListeners() {
new TabListener(), new NameTagListener(), new ElytraGenRemover(), new SpeedPathListener(),
new TradesHook(), new HouseShop(), new HouseWandListener(), new HouseListener(), new eEggHeadClick(),
new ConversionInv(), miscListener, new AdvancementListeners(), new DragonsListener(),
new TradeOverflowListener(), new AuthenticateListener());
new TradeOverflowListener(), new AuthenticateListener(), new DisableCraftListener());

if (getServer().getPluginManager().getPlugin("QuickShop") != null)
getServer().getPluginManager().registerEvents(new ChestShopListener(), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Authenticable(ItemStack item) {
}

public boolean isAuthenticated() {
return item.getItemMeta() != null && item.getItemMeta().getPersistentDataContainer()
return item != null && item.getItemMeta() != null && item.getItemMeta().getPersistentDataContainer()
.get(new NamespacedKey(LaBoulangerieCore.PLUGIN, "authority"), PersistentDataType.STRING) != null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,75 @@
package net.laboulangerie.laboulangeriecore.authenticate;

import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;

import com.destroystokyo.paper.event.inventory.PrepareResultEvent;

import io.papermc.paper.event.player.PlayerLoomPatternSelectEvent;
import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent;

public class AuthenticateListener implements Listener {

@EventHandler(priority = EventPriority.MONITOR)
private void onInventoryClickWithAuthenticate(InventoryClickEvent event) {
Inventory inventory = event.getInventory();

int resultSlot = inventory.getSize() - 1;
switch (inventory.getType()) {
case WORKBENCH:
case CRAFTING:
resultSlot = 0;
break;
case CARTOGRAPHY:
case ENCHANTING:
case ANVIL:
break;
default:
return;
// Anvil, Grindstone, Smithing
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onPrepareResult(PrepareResultEvent event) {
ItemStack[] items = event.getInventory().getContents();
if (containsAuthenticated(items)) {
event.setResult(null);
return;
}
}

if (!containsAuthenticate(inventory)
|| !isAuthenticated(event.getCurrentItem()))
// Crafting table
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onCraftItem(CraftItemEvent event) {
ItemStack[] matrix = event.getInventory().getMatrix();
if (containsAuthenticated(matrix)) {
event.setCancelled(true);
return;
}
}

inventory.setItem(resultSlot, new ItemStack(Material.AIR));
// Loom
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onLoomPatternSelect(PlayerLoomPatternSelectEvent event) {
ItemStack[] items = event.getLoomInventory().getContents();
if (containsAuthenticated(items)) {
event.setCancelled(true);
return;
}
}

private boolean containsAuthenticate(Inventory inventory) {
ItemStack[] items = inventory.getContents();
boolean containsAuthenticated = false;
// Stonecutter
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onStonecutterSelect(PlayerStonecutterRecipeSelectEvent event) {
ItemStack[] items = event.getStonecutterInventory().getContents();
if (containsAuthenticated(items)) {
event.setCancelled(true);
return;
}
}

for (int i = 0; i < items.length; i++) {
if (isAuthenticated(items[i])) {
containsAuthenticated = true;
break;
}
// Enchanting table
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onEnchantItem(EnchantItemEvent event) {
ItemStack[] items = event.getInventory().getContents();
if (containsAuthenticated(items)) {
event.setCancelled(true);
return;
}
return containsAuthenticated;
}

private boolean isAuthenticated(ItemStack item) {
return item != null && new Authenticable(item).isAuthenticated();
private boolean containsAuthenticated(ItemStack[] items) {
for (ItemStack item : items) {
if (new Authenticable(item).isAuthenticated()) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.laboulangerie.laboulangeriecore.LaBoulangerieCore;
import net.laboulangerie.laboulangeriecore.core.UsersData;
import net.laboulangerie.laboulangeriecore.core.end.Dragon;
import net.laboulangerie.laboulangeriecore.core.nametag.PlayerNameTag;
import net.laboulangerie.laboulangeriecore.eco.ConversionInv;

public class CoreCommand implements TabExecutor {
Expand Down Expand Up @@ -125,6 +126,50 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String
sender.sendMessage("§aNickname reset successfully!");
return true;
}

if (args[0].equalsIgnoreCase("nametag") && args.length > 1) {
Player target = Bukkit.getPlayer(args[1]);
if (target == null || !target.isOnline()) {
sender.sendMessage("§4Player is offline!");
return true;
}
PlayerNameTag tag = PlayerNameTag.get(target);

if (args.length == 2) {
sender.sendMessage("Debugging "+target.getName()+"'s nametag");
sender.sendMessage("* Number of viewers: §e"+tag.getViewers().size());
sender.sendMessage("* Viewers:");
for (Player p : tag.getViewers()) {
sender.sendMessage(" - §e"+p.getName());
}
return true;
}else {
Player secondPlayer = null;
switch (args[2].toLowerCase()) {
case "hide":

break;

default:
if (args.length >= 4) {
secondPlayer = Bukkit.getPlayer(args[3]);
if (secondPlayer == null || !secondPlayer.isOnline()) {
sender.sendMessage("§4Player isn't online");
return true;
}
}else return false;
case "addViewer":
tag.addViewer(secondPlayer);
return true;
case "removeViewer":
tag.removeViewer(secondPlayer);
return true;
case "sendNametag":
tag.sendEntities(secondPlayer);
return true;
}
}
}
return false;
}

Expand All @@ -133,9 +178,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String alias, String
@NotNull String alias, @NotNull String[] args) {
List<String> suggestions = Arrays.asList("");
if (args.length == 1)
suggestions = Arrays.asList("reload", "rl", "conversion", "nick", "unnick", "spawnDragon");
if (args.length == 2 && (args[0].equalsIgnoreCase("nick") || args[0].equalsIgnoreCase("unnick")))
return null;
suggestions = Arrays.asList("reload", "rl", "conversion", "nick", "unnick", "spawnDragon", "nametag");
if (args.length == 2 && (
args[0].equalsIgnoreCase("nick") ||
args[0].equalsIgnoreCase("unnick") ||
args[0].equalsIgnoreCase("nametag")
)) return null;
if (args.length == 3 && args[0].equalsIgnoreCase("nametag"))
suggestions = Arrays.asList("addViewer", "removeViewer", "sendNametag");

return suggestions.stream().filter(str -> str.startsWith(args[args.length == 0 ? 0 : args.length - 1]))
.collect(Collectors.toList());
Expand Down
Loading

0 comments on commit 7038b1d

Please sign in to comment.