Format Code, Fixed 2 NPE's

This commit is contained in:
Driftay 2019-12-19 14:23:41 -05:00
parent fec07b6fac
commit 368a605d31
23 changed files with 54 additions and 57 deletions

View File

@ -70,8 +70,8 @@ public class FLocation implements Serializable {
String worldName = string.substring(start, index);
start = index + 1;
index = string.indexOf(",", start);
int x = Integer.valueOf(string.substring(start, index));
int y = Integer.valueOf(string.substring(index + 1, string.length() - 1));
int x = Integer.parseInt(string.substring(start, index));
int y = Integer.parseInt(string.substring(index + 1, string.length() - 1));
return new FLocation(worldName, x, y);
}

View File

@ -84,7 +84,9 @@ public class CmdAdmin extends FCommand {
// Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
fplayer.msg(TL.COMMAND_ADMIN_PROMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer));
fplayer.msg(TL.COMMAND_ADMIN_PROMOTED,
context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true),
fyou.describeTo(fplayer), targetFaction.describeTo(fplayer));
}
}

View File

@ -19,12 +19,12 @@ public class CmdDiscord extends FCommand {
if (context.fPlayer.discordSetup()) {
context.fPlayer.msg(TL.DISCORD_ALREADY_LINKED, context.fPlayer.discordUser().getName());
} else {
if (Discord.waitingLink.values().contains(context.fPlayer)) {
if (Discord.waitingLink.containsValue(context.fPlayer)) {
context.fPlayer.msg(TL.DISCORD_CODE_SENT, Discord.waitingLinkk.get(context.fPlayer), Discord.mainGuild.getSelfMember().getEffectiveName());
return;
}
Integer random = new Random().nextInt(9999);
while (Discord.waitingLink.values().contains(random)) {
while (Discord.waitingLink.containsValue(random)) {
random = new Random().nextInt(9999);
}
Discord.waitingLink.put(random, context.fPlayer);

View File

@ -63,7 +63,7 @@ public class CmdCheck extends FCommand {
}
}
List<Map.Entry<UUID, Integer>> entryList = players.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());
for (int max = (entryList.size() > 10) ? 10 : entryList.size(), current = 0; current < max; ++current) {
for (int max = Math.min(entryList.size(), 10), current = 0; current < max; ++current) {
Map.Entry<UUID, Integer> entry = entryList.get(current);
OfflinePlayer offlinePlayer = FactionsPlugin.getInstance().getServer().getOfflinePlayer(entry.getKey());
context.msg(TL.CHECK_LEADERBOARD_LINE.format(current + 1, offlinePlayer.getName(), entry.getValue(), context.faction.getPlayerBufferCheckCount().getOrDefault(entry.getKey(), 0), context.faction.getPlayerWallCheckCount().getOrDefault(entry.getKey(), 0)));

View File

@ -29,7 +29,7 @@ public class WildGUI implements FactionGUI {
}
@Override
public void onClick(int slot, ClickType action) {
if (map.keySet().contains(slot)) {
if (map.containsKey(slot)) {
String zone = map.get(slot);
if (fplayer.hasMoney(FactionsPlugin.getInstance().getConfig().getInt("Wild.Zones." + zone + ".Cost"))) {
CmdWild.waitingTeleport.put(player, FactionsPlugin.getInstance().getConfig().getInt("Wild.Wait"));

View File

@ -46,6 +46,7 @@ public class CmdSetGuild extends FCommand {
JDA jda = Discord.jda;
if (jda != null) {
if (!this.waiterAdded) {
//Do Not Change, Must Remain EventWaiter[]
jda.addEventListener(new EventWaiter[]{this.eventWaiter});
this.waiterAdded = true;
}

View File

@ -15,6 +15,7 @@ import net.dv8tion.jda.core.exceptions.RateLimitedException;
import javax.security.auth.login.LoginException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;
import java.util.logging.Level;
public class Discord {
@ -37,7 +38,7 @@ public class Discord {
public static Emote negative;
public Discord(FactionsPlugin plugin) {
this.plugin = plugin;
Discord.plugin = plugin;
setupLog = new HashSet<>();
waitingLink = new HashMap<>();
waitingLinkk = new HashMap<>();
@ -216,8 +217,8 @@ public class Discord {
mainGuild.getController().setNickname(m, Discord.getNicknameString(fp)).queue();
}
if (Conf.factionRoles) {
mainGuild.getController().removeSingleRoleFromMember(m, getRoleFromName(oldTag)).queue();
mainGuild.getController().addSingleRoleToMember(m, createFactionRole(f.getTag())).queue();
mainGuild.getController().removeSingleRoleFromMember(m, Objects.requireNonNull(getRoleFromName(oldTag))).queue();
mainGuild.getController().addSingleRoleToMember(m, Objects.requireNonNull(createFactionRole(f.getTag()))).queue();
}
} catch (HierarchyException e) {System.out.print(e.getMessage());}
}

View File

@ -6,7 +6,6 @@ import com.massivecraft.factions.zcore.util.TL;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.core.exceptions.PermissionException;
@ -38,7 +37,7 @@ public class DiscordListener extends ListenerAdapter {
this.decimalFormat = new DecimalFormat("$#,###.##");
this.plugin = plugin;
int minute = 3600;
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, DiscordListener::saveGuilds, (long) (minute * 15), (long) (minute * 15));
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, DiscordListener::saveGuilds, minute * 15, minute * 15);
}
private static JSONGuilds loadGuilds() {
@ -59,29 +58,33 @@ public class DiscordListener extends ListenerAdapter {
try {
String content = FactionsPlugin.getInstance().gson.toJson(guilds);
Files.write(file.toPath(), content.getBytes());
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
throw new NullPointerException();
}
}
public void onPrivateMessageReceived(PrivateMessageReceivedEvent e) {
Integer i = 0;
if (e.getAuthor().isBot()) {return;}
Integer i;
if (e.getAuthor().isBot()) {
return;
}
try {
i = Integer.valueOf(e.getMessage().getContentDisplay());
} catch (NumberFormatException ex) {e.getChannel().sendMessage(TL.DISCORD_CODE_INVALID_FORMAT.toString()).queue();
return;}
if (Discord.waitingLink.keySet().contains(i)) {
} catch (NumberFormatException ex) {
e.getChannel().sendMessage(TL.DISCORD_CODE_INVALID_FORMAT.toString()).queue();
return;
}
if (Discord.waitingLink.containsKey(i)) {
FPlayer f = Discord.waitingLink.get(i);
f.setDiscordSetup(true);
f.setDiscordUserID(e.getAuthor().getId());
e.getChannel().sendMessage(TL.DISCORD_LINK_SUCCESS.toString()).queue();
Discord.waitingLink.remove(i);
Discord.waitingLinkk.remove(f);
} else {e.getChannel().sendMessage(TL.DISCORD_CODE_INVALID_KEY.toString()).queue();
return;}
} else {
e.getChannel().sendMessage(TL.DISCORD_CODE_INVALID_KEY.toString()).queue();
}
}
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
@ -469,7 +472,7 @@ public class DiscordListener extends ListenerAdapter {
List<Map.Entry<UUID, Integer>> entryList = players.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Check Leaderboard").setColor(Color.MAGENTA);
StringBuilder stringBuilder = new StringBuilder();
for (int max = (entryList.size() > 10) ? 10 : entryList.size(), current = 0; current < max; ++current) {
for (int max = Math.min(entryList.size(), 10), current = 0; current < max; ++current) {
Map.Entry<UUID, Integer> entry2 = entryList.get(current);
OfflinePlayer offlinePlayer = this.plugin.getServer().getOfflinePlayer(entry2.getKey());
stringBuilder.append("**").append(current + 1).append(".** ").append(offlinePlayer.getName()).append(" __").append(entry2.getValue()).append(" Total (").append(faction.getPlayerBufferCheckCount().getOrDefault(entry2.getKey(), 0)).append(" Buffer, ").append(faction.getPlayerWallCheckCount().getOrDefault(entry2.getKey(), 0)).append(" Wall)__\n");

View File

@ -71,15 +71,15 @@ public class FactionChatHandler extends ListenerAdapter {
} else if (y.contains("@")) {
List<Integer> ii = new ArrayList<>();
int i = x.indexOf(y);
String mention = "";
StringBuilder mention = new StringBuilder();
while (i <= x.size() - 1) {
mention = mention + " " + x.get(i);
mention.append(" ").append(x.get(i));
ii.add(i);
if (mention.contains("#")) {break;}
if (mention.toString().contains("#")) {break;}
i++;
}
if (mention.contains("#")) {
String[] mentionA = mention.replace(" @", "").split("#");
if (mention.toString().contains("#")) {
String[] mentionA = mention.toString().replace(" @", "").split("#");
for (User u : Discord.jda.getUsersByName(mentionA[0], false)) {
if (u.getDiscriminator().equals(mentionA[1])) {

View File

@ -125,7 +125,7 @@ public class Econ {
}
// Factions can be controlled by members that are moderators... or any member if any member can withdraw.
if (you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) {
if (i instanceof FPlayer && you instanceof Faction && fI == fYou && (Conf.bankMembersCanWithdraw || ((FPlayer) i).getRole().value >= Role.MODERATOR.value)) {
return true;
}

View File

@ -352,7 +352,7 @@ public class FactionsBlockListener implements Listener {
int radius = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Effect-Radius");
List<String> effects = FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Effects");
int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), (double) radius, 255.0, (double) radius)) {
for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), radius, 255.0, radius)) {
if (e1 instanceof Player) {
Player player = (Player) e1;
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
@ -468,7 +468,6 @@ public class FactionsBlockListener implements Listener {
boolean isSpawner = event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial();
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), !isSpawner ? "destroy" : "mine spawners", false)) {
event.setCancelled(true);
return;
}
}

View File

@ -171,7 +171,6 @@ public class FactionsPlayerListener implements Listener {
return CheckPlayerAccess(player, me, loc, otherFaction, access, permissableAction, false);
}
@SuppressWarnings("deprecation")
public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) {
if (Conf.playersWhoBypassAllProtection.contains(player.getName()))
return true;

View File

@ -46,7 +46,7 @@ public class MissionGUI implements FactionGUI {
int pick = r.nextInt(keys.size() - 1);
if (!keys.toArray()[pick].toString().equals("FillItem")) {
missionName = keys.toArray()[pick].toString();
if (!fPlayer.getFaction().getMissions().keySet().contains(missionName)) {
if (!fPlayer.getFaction().getMissions().containsKey(missionName)) {
pickedMission = new Mission(missionName, plugin.getConfig().getString("Missions." + missionName + ".Mission.Type"));
fPlayer.getFaction().getMissions().put(missionName, pickedMission);
fPlayer.msg(TL.MISSION_MISSION_STARTED, fPlayer.describeTo(fPlayer.getFaction()), plugin.color(plugin.getConfig().getString("Missions." + missionName + ".Name")));
@ -132,7 +132,7 @@ public class MissionGUI implements FactionGUI {
}
}
if (plugin.getConfig().getBoolean("Randomization.Enabled")) {
ItemStack start = null;
ItemStack start;
ItemMeta meta;
start = XMaterial.matchXMaterial(plugin.getConfig().getString("Randomization.Start-Item.Allowed.Material")).parseItem();
meta = start.getItemMeta();

View File

@ -42,11 +42,11 @@ public class ShopConfig {
getShop().set("items.1.slot", 1);
getShop().set("items.1.block", "STONE");
getShop().set("items.1.name", "&aTest Shop");
ArrayList lore = new ArrayList();
ArrayList lore = new ArrayList<>();
lore.add("&cFully Customizable Lore!");
lore.add("&b&l{cost} &7Points");
getShop().set("items.1.lore", lore);
ArrayList t = new ArrayList();
ArrayList t = new ArrayList<>();
t.add("broadcast %player% bought Test Shop!");
getShop().set("items.1.cmds", t);
getShop().set("items.1.cost", 5);

View File

@ -30,13 +30,11 @@ public class ShopGUIFrame {
*/
private Gui gui;
private String s;
public ShopGUIFrame(Faction f) {
gui = new Gui(FactionsPlugin.getInstance(),
FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Rows", 4),
FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("F-Shop.GUI.Name")));
this.s = s;
}
public void buildGUI(FPlayer fplayer) {

View File

@ -449,7 +449,7 @@ public final class ReflectionUtils {
DOUBLE(double.class, Double.class),
BOOLEAN(boolean.class, Boolean.class);
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>();
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<>();
// Initialize map for quick class lookup
static {

View File

@ -17,7 +17,7 @@ public class InventoryItem {
private Runnable runnable;
public InventoryItem(ItemStack original) {
this.clickMap = new HashMap();
this.clickMap = new HashMap<>();
this.item = original;
}

View File

@ -18,8 +18,8 @@ import java.util.function.Consumer;
public abstract class SaberGUI {
public static Set<String> allGUINames = new HashSet();
public static Map<UUID, SaberGUI> activeGUIs = new ConcurrentHashMap();
public static Set<String> allGUINames = new HashSet<>();
public static Map<UUID, SaberGUI> activeGUIs = new ConcurrentHashMap<>();
public SaberGUI parentGUI;
protected String title;
protected int size;
@ -34,7 +34,7 @@ public abstract class SaberGUI {
}
public SaberGUI(Player player, String title, int size, InventoryType type) {
this.inventoryItems = new HashMap();
this.inventoryItems = new HashMap<>();
this.inventory = type == InventoryType.CHEST ? Bukkit.createInventory(null, size, title) : Bukkit.createInventory(null, type, title);
this.player = player;
this.size = size;

View File

@ -652,10 +652,7 @@ public class FUpgradesGUI implements Listener {
}
private boolean takeMoney(FPlayer fme, int amt) {
if (fme.takeMoney(amt)) {
return true;
}
return false;
return fme.takeMoney(amt);
}
private boolean upgradeItem(FPlayer fme, UpgradeType upgrade, int level, int cost) {

View File

@ -280,7 +280,7 @@ public abstract class MemoryBoard extends Board {
//----------------------------------------------//
private List<String> oneLineToolTip(Faction faction, FPlayer to) {
return Arrays.asList(faction.describeTo(to));
return Collections.singletonList(faction.describeTo(to));
}
@SuppressWarnings("unused")

View File

@ -419,7 +419,7 @@ public abstract class MemoryFPlayer implements FPlayer {
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Discord.leader).queue();
}
if (Conf.factionRoles) {
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Discord.createFactionRole(this.getFaction().getTag())).queue();
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Objects.requireNonNull(Discord.createFactionRole(this.getFaction().getTag()))).queue();
}
if (Conf.factionDiscordTags) {
Discord.resetNick(this);
@ -1130,7 +1130,7 @@ public abstract class MemoryFPlayer implements FPlayer {
}
public void setMapHeight(int height) {
this.mapHeight = height > (Conf.mapHeight * 2) ? (Conf.mapHeight * 2) : height;
this.mapHeight = Math.min(height, (Conf.mapHeight * 2));
}
public String getNameAndTitle(FPlayer fplayer) {

View File

@ -356,7 +356,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Discord.mainGuild.getRoleById(Conf.leaderRole)).queue();
}
if (Conf.factionRoles) {
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Discord.createFactionRole(this.getTag())).queue();
Discord.mainGuild.getController().removeSingleRoleFromMember(m, Objects.requireNonNull(Discord.createFactionRole(this.getTag()))).queue();
}
if (Conf.factionDiscordTags) {
Discord.resetNick(fplayer);
@ -455,7 +455,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
public int getUpgrade(UpgradeType upgrade) {
if (upgrades.keySet().contains(upgrade.toString())) return upgrades.get(upgrade.toString());
if (upgrades.containsKey(upgrade.toString())) return upgrades.get(upgrade.toString());
return 0;
}
@ -1330,7 +1330,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
if (Discord.useDiscord && replacements.get(0).discordSetup() && Discord.isInMainGuild(replacements.get(0).discordUser()) && Discord.mainGuild != null) {
Member m = Discord.mainGuild.getMember(replacements.get(0).discordUser());
if (Conf.factionRoles) {
Discord.mainGuild.getController().addSingleRoleToMember(m, Discord.createFactionRole(this.getTag())).queue();
Discord.mainGuild.getController().addSingleRoleToMember(m, Objects.requireNonNull(Discord.createFactionRole(this.getTag()))).queue();
}
if (Conf.leaderRoles) {
Discord.mainGuild.getController().addSingleRoleToMember(m, Discord.mainGuild.getRoleById(Conf.leaderRole)).queue();

View File

@ -60,10 +60,8 @@ public class TextUtil {
message.then(text).style(color);
}
text = "";
color = ChatColor.getByChar(chars[i + 1]);
} else {
color = ChatColor.getByChar(chars[i + 1]);
}
color = ChatColor.getByChar(chars[i + 1]);
i++; // skip color char
} else {
text += chars[i];
@ -119,8 +117,7 @@ public class TextUtil {
public static String implode(List<String> list, String glue) {
StringBuilder ret = new StringBuilder();
for (int i = 0; i < list.size(); i++)
ret.append(glue).append(list.get(i));
for (String s : list) ret.append(glue).append(s);
return ret.length() > 0 ? ret.toString().substring(glue.length()) : "";
}