forked from Upstream/VillagerTradeLimiter
Version 1.5.3-pre2:
* Add support for other plugins that cancel the PlayerInteractEntityEvent. No longer runs the interaction code when the event has already been cancelled. * Add support for other plugins that use special items. For example, SafariNet captures villagers when a player uses a custom spawn egg on them. No longer runs the interaction code when the player is holding one of the items listed in config.yml
This commit is contained in:
parent
40c31a13c7
commit
72e2423741
21
README.md
21
README.md
@ -2,7 +2,7 @@
|
||||
<h6>by PretzelJohn</h6>
|
||||
|
||||
<h2>Description:</h2>
|
||||
<p>This Minecraft plugin limits the villager trade deals that players can get.<br/>Click <a href="https://www.spigotmc.org/resources/87210/">here</a> to see this plugin on Spigot.</p>
|
||||
<p>This Minecraft plugin limits the villager trade deals that players can get.<br/>Supports Spigot, Paper, and Purpur servers from 1.14.1 to the current version.<br/>Click <a href="https://www.spigotmc.org/resources/87210/">here</a> to see this plugin on Spigot.</p>
|
||||
<p>Some information has moved to the <a href="https://github.com/PretzelJohn/VillagerTradeLimiter/wiki">Wiki</a>!</p>
|
||||
<br/>
|
||||
|
||||
@ -59,6 +59,15 @@
|
||||
<td><code>IgnoreShopkeepers:</code></td>
|
||||
<td>Whether to ignore Shopkeepers NPCs from the Shopkeepers plugin. If set to true, Shopkeepers NPCs won't be affected by this plugin.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>IgnoreHeldItems:</code></td>
|
||||
<td>A list of item types where, when the player interacts with a villager while holding one of these items, VTL doesn't affect the interaction. This is used for compatibility with other plugins, like the custom spawn eggs in <a href="https://www.spigotmc.org/resources/%E2%9C%85-safarinet-premium-mob-catcher-plugin.9732/">SafariNet</a>.<br><b>Options:</b>
|
||||
<ul>
|
||||
<li>Add material names for special items used by other plugins</li>
|
||||
<li>Remove all list items and set to [] to disable this feature</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>DisableTrading:</code></td>
|
||||
<td>Whether to disable all villager trading for all worlds, some worlds, or no worlds.<br/><strong>Options:</strong>
|
||||
@ -110,7 +119,7 @@
|
||||
</table>
|
||||
</li>
|
||||
<li>
|
||||
<p>Per-item settings: (<code>Overrides:</code>)</p>
|
||||
<p>Per-item override settings: (<code>Overrides:</code>)</p>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Setting</th>
|
||||
@ -138,19 +147,19 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>.Cooldown:</code></td>
|
||||
<td>Sets the time between restocks for the trade, and applies to ALL villagers. Once the player reaches the <code>MaxUses</code>, the cooldown begins. The trade is disabled for all villagers until the cooldown expires.<br><strong>FORMAT:</strong> <Number><interval><br><strong>EXAMPLE:</strong> 30s = 30 seconds, 5m = 5 minutes, 4h = 4 hours, 7d = 7 days</td>
|
||||
<td>Sets the time between restocks for the trade, and applies to ALL villagers. Once the player reaches the <code>MaxUses</code>, the cooldown begins. The trade is disabled for all villagers until the cooldown expires.<br><strong>Format:</strong> <Number><interval><br><strong>Examples:</strong> 30s = 30 seconds, 5m = 5 minutes, 4h = 4 hours, 7d = 7 days</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>.Item1.Material:</code><br><code>.Item2.Material:</code><br><code>.Result.Material:</code></td>
|
||||
<td>Sets the material of the 1st or 2nd item in the trade<br><strong>WARNING:</strong> This cannot be undone!</td>
|
||||
<td>Sets the material of the 1st, 2nd, or result item in the trade<br><strong>WARNING:</strong> This cannot be undone!</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>.Item1.Amount:</code><br><code>.Item2.Amount:</code><br><code>.Result.Amount:</code></td>
|
||||
<td>Sets the amount of the 1st or 2nd item in the trade<br><strong>WARNING:</strong> This cannot be undone!</td>
|
||||
<td>Sets the amount of the 1st, 2nd, or result item in the trade<br><strong>WARNING:</strong> This cannot be undone!</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
<li>
|
||||
<p>For the default config.yml, see: <code>src/main/resources/config.yml</code></p>
|
||||
<p>For the default config.yml, see <code>src/main/resources/config.yml</code></p>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -5,6 +5,7 @@ import com.pretzel.dev.villagertradelimiter.data.Cooldown;
|
||||
import com.pretzel.dev.villagertradelimiter.data.PlayerData;
|
||||
import com.pretzel.dev.villagertradelimiter.settings.Settings;
|
||||
import com.pretzel.dev.villagertradelimiter.wrappers.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,6 +13,7 @@ import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
@ -35,12 +37,22 @@ public class PlayerListener implements Listener {
|
||||
/** Handles when a player begins trading with a villager */
|
||||
@EventHandler
|
||||
public void onPlayerBeginTrading(final PlayerInteractEntityEvent event) {
|
||||
if(!(event.getRightClicked() instanceof Villager)) return;
|
||||
if(event.isCancelled()) return; //Skips when event is already cancelled
|
||||
if(!(event.getRightClicked() instanceof Villager)) return; //Skips non-villager entities
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final Villager villager = (Villager)event.getRightClicked();
|
||||
|
||||
//Skips when player is holding an ignored item
|
||||
Material heldItemType = player.getInventory().getItem(event.getHand()).getType();
|
||||
for(String ignoredType : instance.getCfg().getStringList("IgnoredHeldItems")) {
|
||||
if(heldItemType.equals(Material.matchMaterial(ignoredType))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(settings.shouldSkipNPC(event.getPlayer()) || settings.shouldSkipNPC(villager)) return; //Skips NPCs
|
||||
if(villager.getProfession() == Villager.Profession.NONE || villager.getProfession() == Villager.Profession.NITWIT) return; //Skips non-trading villagers
|
||||
if(villager.getRecipeCount() == 0) return; //Skips non-trading villagers
|
||||
if(villager.getProfession() == Villager.Profession.NONE || villager.getProfession() == Villager.Profession.NITWIT || villager.getRecipeCount() == 0) return; //Skips non-trading villagers
|
||||
|
||||
//DisableTrading feature
|
||||
if(instance.getCfg().isBoolean("DisableTrading")) {
|
||||
|
@ -117,13 +117,6 @@ public enum MinecraftVersion {
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
try {
|
||||
if (hasGsonSupport() && !bStatsDisabled)
|
||||
new ApiMetricsLite();
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.WARNING, "[NBTAPI] Error enabling Metrics!", ex);
|
||||
}
|
||||
|
||||
if (hasGsonSupport() && !updateCheckDisabled)
|
||||
new Thread(() -> {
|
||||
try {
|
||||
|
@ -23,6 +23,9 @@ database:
|
||||
IgnoreCitizens: true
|
||||
IgnoreShopkeepers: true
|
||||
|
||||
# Ignore interactions when the player is holding one of these item types (e.g. spawn_egg)
|
||||
IgnoreHeldItems: []
|
||||
|
||||
# Add world names for worlds that you want to completely disable ALL villager trading. Set to [] to disable this feature.
|
||||
DisableTrading:
|
||||
- world_nether
|
||||
|
Loading…
Reference in New Issue
Block a user