mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 12:38:40 +01:00
Added /cstoggle to disable spam messages.
This commit is contained in:
parent
bd0a40e16c
commit
dffbb7f06a
@ -3,6 +3,7 @@ package com.Acrobot.ChestShop;
|
||||
import com.Acrobot.Breeze.Configuration.Configuration;
|
||||
import com.Acrobot.ChestShop.Commands.Give;
|
||||
import com.Acrobot.ChestShop.Commands.ItemInfo;
|
||||
import com.Acrobot.ChestShop.Commands.Toggle;
|
||||
import com.Acrobot.ChestShop.Commands.Version;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
@ -19,10 +20,7 @@ import com.Acrobot.ChestShop.Listeners.Item.ItemMoveListener;
|
||||
import com.Acrobot.ChestShop.Listeners.ItemInfoListener;
|
||||
import com.Acrobot.ChestShop.Listeners.Modules.DiscountModule;
|
||||
import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule;
|
||||
import com.Acrobot.ChestShop.Listeners.Player.PlayerConnect;
|
||||
import com.Acrobot.ChestShop.Listeners.Player.PlayerInteract;
|
||||
import com.Acrobot.ChestShop.Listeners.Player.PlayerInventory;
|
||||
import com.Acrobot.ChestShop.Listeners.Player.PlayerTeleport;
|
||||
import com.Acrobot.ChestShop.Listeners.Player.*;
|
||||
import com.Acrobot.ChestShop.Listeners.PostShopCreation.CreationFeeGetter;
|
||||
import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender;
|
||||
import com.Acrobot.ChestShop.Listeners.PostShopCreation.ShopCreationLogger;
|
||||
@ -133,6 +131,7 @@ public class ChestShop extends JavaPlugin {
|
||||
getCommand("iteminfo").setExecutor(new ItemInfo());
|
||||
getCommand("csVersion").setExecutor(new Version());
|
||||
getCommand("csGive").setExecutor(new Give());
|
||||
getCommand("cstoggle").setExecutor(new Toggle());
|
||||
|
||||
startStatistics();
|
||||
startUpdater();
|
||||
@ -240,6 +239,8 @@ public class ChestShop extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
|
||||
Toggle.clearToggledPlayers();
|
||||
|
||||
if (handler != null) {
|
||||
handler.close();
|
||||
getLogger().removeHandler(handler);
|
||||
@ -266,6 +267,7 @@ public class ChestShop extends JavaPlugin {
|
||||
registerEvent(new PlayerConnect());
|
||||
registerEvent(new PlayerInteract());
|
||||
registerEvent(new PlayerInventory());
|
||||
registerEvent(new PlayerLeave());
|
||||
registerEvent(new PlayerTeleport());
|
||||
|
||||
registerEvent(new ItemInfoListener());
|
||||
|
57
src/main/java/com/Acrobot/ChestShop/Commands/Toggle.java
Normal file
57
src/main/java/com/Acrobot/ChestShop/Commands/Toggle.java
Normal file
@ -0,0 +1,57 @@
|
||||
package com.Acrobot.ChestShop.Commands;
|
||||
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author KingFaris10
|
||||
*/
|
||||
public class Toggle implements CommandExecutor {
|
||||
private static final List<String> toggledPlayers = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (Permission.has(player, Permission.NOTIFY_TOGGLE)) {
|
||||
if (setIgnoring(player, !toggledPlayers.contains(player.getName()))) player.sendMessage(Messages.TOGGLE_MESSAGES_OFF);
|
||||
else player.sendMessage(Messages.TOGGLE_MESSAGES_ON);
|
||||
} else {
|
||||
player.sendMessage(Messages.ACCESS_DENIED);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearToggledPlayers() {
|
||||
toggledPlayers.clear();
|
||||
}
|
||||
|
||||
public static boolean isIgnoring(OfflinePlayer player) {
|
||||
return player != null && toggledPlayers.contains(player.getName());
|
||||
}
|
||||
|
||||
public static boolean setIgnoring(Player player, boolean ignoring) {
|
||||
Validate.notNull(player); // Make sure the player instance is not null. I believe this should be here instead of (object != null) because if the player is null, it shows there is an error with the code.
|
||||
if (ignoring) {
|
||||
if (!toggledPlayers.contains(player.getName()))
|
||||
toggledPlayers.add(player.getName());
|
||||
} else {
|
||||
if (toggledPlayers.contains(player.getName()))
|
||||
toggledPlayers.remove(player.getName());
|
||||
}
|
||||
return ignoring;
|
||||
}
|
||||
|
||||
}
|
@ -67,6 +67,10 @@ public class Messages {
|
||||
@PrecededBySpace
|
||||
public static String CANNOT_CREATE_SHOP_HERE = "You can't create shop here!";
|
||||
|
||||
@PrecededBySpace
|
||||
public static String TOGGLE_MESSAGES_OFF = "You will no longer receive messages from your shop(s).";
|
||||
public static String TOGGLE_MESSAGES_ON = "You will now receive messages from your shop(s)..";
|
||||
|
||||
public static String prefix(String message) {
|
||||
return prefix + message;
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.Acrobot.ChestShop.Listeners.Player;
|
||||
|
||||
/**
|
||||
* @author KingFaris10
|
||||
*/
|
||||
public class PlayerLeave {
|
||||
}
|
@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
||||
|
||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||
import com.Acrobot.ChestShop.Commands.Toggle;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
@ -45,7 +46,7 @@ public class TransactionMessageSender implements Listener {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER) {
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwner())) {
|
||||
String message = formatMessage(Messages.SOMEBODY_BOUGHT_FROM_YOUR_SHOP, itemName, price);
|
||||
message = message.replace("%buyer", player.getName());
|
||||
|
||||
@ -68,7 +69,7 @@ public class TransactionMessageSender implements Listener {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER) {
|
||||
if (Properties.SHOW_TRANSACTION_INFORMATION_OWNER && !Toggle.isIgnoring(event.getOwner())) {
|
||||
String message = formatMessage(Messages.SOMEBODY_SOLD_TO_YOUR_SHOP, itemName, price);
|
||||
message = message.replace("%seller", player.getName());
|
||||
|
||||
|
@ -24,7 +24,9 @@ public enum Permission {
|
||||
GROUP("ChestShop.group."),
|
||||
|
||||
NOFEE("ChestShop.nofee"),
|
||||
DISCOUNT("ChestShop.discount.");
|
||||
DISCOUNT("ChestShop.discount."),
|
||||
|
||||
NOTIFY_TOGGLE("ChestShop.toggle");
|
||||
|
||||
private final String permission;
|
||||
|
||||
|
@ -31,6 +31,9 @@ commands:
|
||||
aliases: [chestshop]
|
||||
description: Shows the ChestShop's version
|
||||
usage: /<command>
|
||||
cstoggle:
|
||||
description: Toggle messages to the owner of a shop
|
||||
usage: /<command>
|
||||
|
||||
permissions:
|
||||
ChestShop.*:
|
||||
@ -67,6 +70,9 @@ permissions:
|
||||
description: Allows user to sell to a shop
|
||||
ChestShop.nofee:
|
||||
description: User doesn't have to pay the shop creation fee.
|
||||
ChestShop.toggle:
|
||||
description: Allows user to toggle messages.
|
||||
default: true
|
||||
ChestShop.admin:
|
||||
description: Allows user to modify/destroy other stores and create an Admin Shops
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user