Added F Notifcations Command (Allows Players To Disable Notifications From Land Claiming)

This commit is contained in:
Driftay 2020-04-02 15:15:59 -04:00
parent 95a202d2cf
commit c237667def
8 changed files with 49 additions and 110 deletions

View File

@ -10,6 +10,7 @@ public class Aliases {
/**
* @author DroppingAnvil
*/
public static ArrayList<String> notifications = new ArrayList<>(Arrays.asList("notifications", "notis"));
public static ArrayList<String> alts_alts = new ArrayList<>(Arrays.asList("alts", "alt"));
public static ArrayList<String> alts_list = new ArrayList<>(Arrays.asList("list", "l"));
public static ArrayList<String> alts_invite = new ArrayList<>(Collections.singletonList("invite"));

View File

@ -0,0 +1,38 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
/**
* Factions - Developed by Driftay.
* All rights reserved 2020.
* Creation Date: 4/2/2020
*/
public class CmdNotifications extends FCommand {
public CmdNotifications() {
super();
this.aliases.addAll(Aliases.notifications);
this.requirements = new CommandRequirements.Builder(Permission.NOTIFICATIONS)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
if (context.fPlayer.hasNotificationsEnabled()) {
context.fPlayer.setNotificationsEnabled(false);
context.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_OFF);
} else {
context.fPlayer.setNotificationsEnabled(true);
context.msg(TL.COMMAND_NOTIFICATIONS_TOGGLED_ON);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_NOTIFICATIONS_DESCRIPTION;
}
}

View File

@ -170,6 +170,8 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
public CmdReserve cmdReserve = new CmdReserve();
public CmdDelHome cmdDelHome = new CmdDelHome();
public CmdClaimFill cmdClaimFill = new CmdClaimFill();
public CmdNotifications cmdNotifications = new CmdNotifications();
//Variables to know if we already setup certain sub commands
public Boolean discordEnabled = false;
public Boolean checkEnabled = false;
@ -303,6 +305,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdSpawnerLock);
this.addSubCommand(this.cmdDrain);
this.addSubCommand(this.cmdLookup);
this.addSubCommand(this.cmdNotifications);
addVariableCommands();
if (CommodoreProvider.isSupported()) brigadierManager.build();
}

View File

@ -74,6 +74,7 @@ public enum Permission {
MAP("map"),
MAPHEIGHT("mapheight"),
MOD("mod"),
NOTIFICATIONS("notifications"),
COLEADER("coleader"),
MOD_ANY("mod.any"),
COLEADER_ANY("coleader.any"),

View File

@ -1,51 +0,0 @@
package com.massivecraft.factions.util;
/**
* @author Saser
*/
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.HashMap;
import java.util.Map;
public class ItemUtil {
private static Map<String, ItemStack> cachedSkulls = new HashMap<>();
public ItemUtil() {
}
public static int getItemCount(Inventory inventory) {
if (inventory == null) {
return 0;
} else {
int itemsFound = 0;
for (int i = 0; i < inventory.getSize(); ++i) {
ItemStack item = inventory.getItem(i);
if (item != null && item.getType() != Material.AIR) {
++itemsFound;
}
}
return itemsFound;
}
}
public static ItemStack createPlayerHead(String name) {
ItemStack skull = cachedSkulls.get(name);
if (skull != null) {
return skull.clone();
} else {
skull = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial());
SkullMeta sm = (SkullMeta) skull.getItemMeta();
sm.setOwner(name);
skull.setItemMeta(sm);
cachedSkulls.put(name, skull.clone());
return skull;
}
}
}

View File

@ -1,26 +0,0 @@
package com.massivecraft.factions.util;
/**
* Factions - Developed by FactionsUUID Team.
*/
public class Pair<Left, Right> {
private final Left left;
private final Right right;
private Pair(Left left, Right right) {
this.left = left;
this.right = right;
}
public static <Left, Right> Pair<Left, Right> of(Left left, Right right) {
return new Pair<>(left, right);
}
public Left getLeft() {
return this.left;
}
public Right getRight() {
return this.right;
}
}

View File

@ -1,31 +0,0 @@
package com.massivecraft.factions.util;
import java.util.TreeMap;
public class RomanNumber {
private static TreeMap<Integer, String> map;
static {
(map = new TreeMap<>()).put(1000, "M");
RomanNumber.map.put(900, "CM");
RomanNumber.map.put(500, "D");
RomanNumber.map.put(400, "CD");
RomanNumber.map.put(100, "C");
RomanNumber.map.put(90, "XC");
RomanNumber.map.put(50, "L");
RomanNumber.map.put(40, "XL");
RomanNumber.map.put(10, "X");
RomanNumber.map.put(9, "IX");
RomanNumber.map.put(5, "V");
RomanNumber.map.put(4, "IV");
RomanNumber.map.put(1, "I");
}
public static String toRoman(int number) {
int l = RomanNumber.map.floorKey(number);
if (number == l) {
return RomanNumber.map.get(number);
}
return RomanNumber.map.get(l) + toRoman(number - l);
}
}

View File

@ -86,7 +86,7 @@ public abstract class MemoryFPlayer implements FPlayer {
protected transient long lastFrostwalkerMessage;
protected transient boolean shouldTakeFallDamage = true;
protected boolean isStealthEnabled = false;
protected boolean notificationsEnabled = true;
protected boolean notificationsEnabled;
protected boolean titlesEnabled = true;
protected boolean isAlt = false;
boolean inspectMode = false;
@ -112,6 +112,7 @@ public abstract class MemoryFPlayer implements FPlayer {
this.getDeaths();
this.showScoreboard = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", false);
this.mapHeight = Conf.mapHeight;
this.notificationsEnabled = true;
if (!Conf.newPlayerStartingFactionID.equals("0") && Factions.getInstance().isValidFactionId(Conf.newPlayerStartingFactionID)) {
this.factionId = Conf.newPlayerStartingFactionID;
@ -141,6 +142,7 @@ public abstract class MemoryFPlayer implements FPlayer {
this.notificationsEnabled = other.notificationsEnabled;
this.showScoreboard = FactionsPlugin.getInstance().getConfig().getBoolean("scoreboard.default-enabled", true);
this.mapHeight = Conf.mapHeight;
this.notificationsEnabled = true;
}
public boolean isAlt() {
@ -1255,8 +1257,10 @@ public abstract class MemoryFPlayer implements FPlayer {
Set<FPlayer> informTheseFPlayers = new HashSet<>();
informTheseFPlayers.add(this);
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true));
for (FPlayer fp : informTheseFPlayers)
for (FPlayer fp : informTheseFPlayers) {
if (!fp.hasNotificationsEnabled()) continue;
fp.msg(TL.CLAIM_CLAIMED, this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
}
Board.getInstance().setFactionAt(forFaction, flocation);