Compare commits

...

13 Commits

Author SHA1 Message Date
PretzelJohn 61bcea37b9 Version 1.5.6:
* Added "ghast_spawn_egg" to IgnoreHeldItems list in config.yml (supports SafariNet by default) - Thanks to Turjoy9
* Added "name_tag" to IgnoreHeldItems list in config.yml (fixes nametagging villagers with professions) - Thanks to Turjoy9
* Added a few more comments in VillagerTradeLimiter.java
2022-05-21 08:34:23 -04:00
PretzelJohn 8a46c9ab1c
Merge pull request #3 from Turjoy9/master
Disabling nametag by default so that name can be applied to villagers with professions.
2022-05-21 02:21:12 -04:00
Turjoy9 18e47efef4
Update config.yml
Disabling nametag by default so that name can be applied to villagers with professions.
2022-05-21 12:10:46 +06:00
PretzelJohn ec76d44e0d Version 1.5.6-pre1:
* Updated version number to 1.5.6
2022-05-02 10:12:10 -04:00
PretzelJohn 3513e97253
Merge pull request #2 from Turjoy9/master
Update config.yml
2022-05-02 10:09:53 -04:00
Turjoy9 b06f9c9871
Update config.yml 2022-05-02 19:57:54 +06:00
Turjoy9 4097d9d8f3
Update config.yml 2022-05-02 19:48:37 +06:00
Turjoy9 af2cd73737
Update config.yml
Adding support for Safarinet plugin by default.
2022-05-02 19:38:51 +06:00
PretzelJohn d328a575aa Version 1.5.5:
* Fixed MaxDemand bug when you buy something around 1500+ times back-to-back
2022-05-01 08:59:38 -04:00
PretzelJohn 2d97903db6 Version 1.5.5:
* Hopefully fixed MaxDemand bug when you buy something around 1500+ times back-to-back
2022-04-30 01:57:06 -04:00
PretzelJohn 030974f065 Version 1.5.4:
* Fixed IgnoreHeldItems again
2022-04-23 20:53:52 -04:00
PretzelJohn a3995b6adb Version 1.5.4:
* Fixed IgnoreHeldItems typo
2022-04-23 18:44:01 -04:00
PretzelJohn 72e2423741 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
2022-04-10 21:32:26 -04:00
10 changed files with 59 additions and 31 deletions

View File

@ -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> &lt;Number&gt;&lt;interval&gt;<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> &lt;Number&gt;&lt;interval&gt;<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>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.pretzel.dev</groupId>
<artifactId>VillagerTradeLimiter</artifactId>
<version>1.5.3</version>
<version>1.5.6</version>
<properties>
<java.version>1.8</java.version>
@ -46,7 +46,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
<version>8.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -107,18 +107,19 @@ public class VillagerTradeLimiter extends JavaPlugin {
// ------------------------- Getters -------------------------
/** Returns the settings from config.yml */
/** @return the settings from config.yml */
public FileConfiguration getCfg() { return this.cfg; }
/** Returns a language setting from messages.yml */
/** @param path the key you want the value for
* @return a language setting from messages.yml */
public String getLang(final String path) { return this.lang.get(path); }
/** Returns this plugin's player listener */
/** @return this plugin's player listener */
public PlayerListener getPlayerListener() { return this.playerListener; }
/** Returns a player's data container */
/** @return a player's data container */
public HashMap<UUID, PlayerData> getPlayerData() { return this.playerData; }
/** Returns the invsee inventory's barrier block */
/** @return the invsee inventory's barrier block */
public ItemStack getBarrier() { return this.commandManager.getBarrier(); }
}

View File

@ -25,7 +25,7 @@ public class MySQL extends Database {
try {
this.source.setCharacterEncoding(cfg.getString("encoding", "utf8"));
this.source.setUseSSL(cfg.getBoolean("useSSL", false));
} catch (SQLException e) {}
} catch (SQLException ignored) {}
this.test();
}

View File

@ -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;
@ -35,12 +36,21 @@ 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("IgnoreHeldItems")) {
if(heldItemType.equals(Material.matchMaterial(ignoredType))) {
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")) {
@ -111,7 +121,7 @@ public class PlayerListener implements Listener {
setIngredient(override.getConfigurationSection("Result"), recipe.getResult());
}
//Set the maximum number of uses (trades/day)
//Set the maximum number of uses (trades/restock)
recipe.setMaxUses(getMaxUses(recipe, other));
}
@ -136,7 +146,11 @@ public class PlayerListener implements Listener {
private int getDemand(final RecipeWrapper recipe) {
int demand = recipe.getDemand();
int maxDemand = settings.fetchInt(recipe, "MaxDemand", -1);
if(maxDemand >= 0 && demand > maxDemand) return maxDemand;
if(maxDemand < 0) maxDemand = 1000000;
if(demand > maxDemand) {
recipe.setDemand(maxDemand);
return maxDemand;
}
return demand;
}
@ -153,7 +167,7 @@ public class PlayerListener implements Listener {
float priceMultiplier = recipe.getPriceMultiplier();
int discount = -(int)(totalReputation * priceMultiplier) - (int)(hotvDiscount * basePrice) + Math.max(0, (int)(demand * priceMultiplier * basePrice));
double maxDiscount = settings.fetchDouble(recipe, "MaxDiscount", 0.3);
double maxDiscount = settings.fetchDouble(recipe, "MaxDiscount", 0.3); //0.1
if(maxDiscount >= 0.0 && maxDiscount <= 1.0) {
//Change the discount to the smaller MaxDiscount
if(basePrice + discount < basePrice * (1.0 - maxDiscount)) {

View File

@ -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 {

View File

@ -26,6 +26,9 @@ public class RecipeWrapper {
this.specialPrice = getSpecialPrice();
}
/** @param demand The demand, which increases prices if you buy too often. Negative values are ignored. */
public void setDemand(int demand) { recipe.setInteger("demand", demand); }
/** @param specialPrice The discount, which is added to the base price. A negative value will decrease the price, and a positive value will increase the price. */
public void setSpecialPrice(int specialPrice) { recipe.setInteger("specialPrice", specialPrice); }

View File

@ -23,6 +23,14 @@ database:
IgnoreCitizens: true
IgnoreShopkeepers: true
# Ignore interactions when the player is holding one of these item types (e.g. spawn_egg, name_tag)
# Without disabling nametag, you cannot rename a villager with a profession. Do not remove name_tag if you want to retain vanilla behavior.
# Ghast spawn egg is added to add compatibility with Safarinet plugin. If your server doesn't give ghast egg to noromal players you can ignore it.
# Set to [] to disable this feature.
IgnoreHeldItems:
- "name_tag"
- "ghast_spawn_egg"
# Add world names for worlds that you want to completely disable ALL villager trading. Set to [] to disable this feature.
DisableTrading:
- world_nether
@ -102,4 +110,4 @@ Overrides:
MaxDemand: 12
paper:
MaxUses: 1
Restock: 1h
Restock: 1h

View File

@ -2,14 +2,14 @@
help: |-
[villagertradelimiter.use]&a----- VTL Commands -----
[villagertradelimiter.use]&b/vtl;&fshows this help message
[villagertradelimiter.reload]&b/vtl reload;&freloads config.yml
[villagertradelimiter.reload]&b/vtl reload;&freloads config.yml and messages.yml
[villagertradelimiter.see]&b/vtl see <player>;&fshows the adjusted trades for another player
# Common messages:
common:
reloaded: "&eVillagerTradeLimiter (VTL) &ahas been reloaded!"
noconsole: "&cYou cannot use this command from the console."
noargs: "&cNot enough arguments! For command usage, see /vtl"
noargs: "&cNot enough arguments! For command usage, see &b/vtl"
# Messages for the /vtl see <player> command:
see:

View File

@ -1,7 +1,7 @@
name: VillagerTradeLimiter
author: PretzelJohn
main: com.pretzel.dev.villagertradelimiter.VillagerTradeLimiter
version: 1.5.3
version: 1.5.6
api-version: 1.14
commands: