mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2026-01-06 15:51:50 +00:00
checkpoint - 25
This commit is contained in:
@@ -70,7 +70,7 @@ public class McMMOTreasureProvider implements ItemProvider {
|
||||
times++;
|
||||
}
|
||||
}
|
||||
return itemStack == null ? new ItemStack(Material.COD) : itemStack;
|
||||
return itemStack == null ? (Math.random() > 0.5 ? new ItemStack(Material.COD) : (Math.random() > 0.2) ? new ItemStack(Material.SALMON) : new ItemStack(Material.PUFFERFISH)) : itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,144 +1,147 @@
|
||||
///*
|
||||
// * Copyright (C) <2022> <XiaoMoMi>
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// */
|
||||
//
|
||||
//package net.momirealms.customfishing.bukkit.integration.papi;
|
||||
//
|
||||
//import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
//import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
//import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
|
||||
//import org.bukkit.OfflinePlayer;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//import org.jetbrains.annotations.Nullable;
|
||||
//
|
||||
//import java.util.Optional;
|
||||
//
|
||||
//public class CompetitionPapi extends PlaceholderExpansion {
|
||||
//
|
||||
// private final BukkitCustomFishingPlugin plugin;
|
||||
//
|
||||
// public CompetitionPapi(BukkitCustomFishingPlugin plugin) {
|
||||
// this.plugin = plugin;
|
||||
// }
|
||||
//
|
||||
// public void load() {
|
||||
// super.register();
|
||||
// }
|
||||
//
|
||||
// public void unload() {
|
||||
// super.unregister();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getIdentifier() {
|
||||
// return "cfcompetition";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getAuthor() {
|
||||
// return "XiaoMoMi";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getVersion() {
|
||||
// return "2.0";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean persist() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
// switch (params) {
|
||||
// case "goingon" -> {
|
||||
// return String.valueOf(plugin.getCompetitionManager().getOnGoingCompetition() != null);
|
||||
// }
|
||||
// case "nextseconds" -> {
|
||||
// return String.valueOf(plugin.getCompetitionManager().getNextCompetitionInSeconds());
|
||||
// }
|
||||
// case "nextsecond" -> {
|
||||
// return plugin.getCompetitionManager().getNextCompetitionInSeconds() % 60 + CFLocale.FORMAT_Second;
|
||||
// }
|
||||
// case "nextminute" -> {
|
||||
// int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds();
|
||||
// int min = (sec % 3600) / 60;
|
||||
// return sec < 60 ? "" : min + CFLocale.FORMAT_Minute;
|
||||
// }
|
||||
// case "nexthour" -> {
|
||||
// int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds();
|
||||
// int h = (sec % (3600 * 24)) / 3600;
|
||||
// return sec < 3600 ? "" : h + CFLocale.FORMAT_Hour;
|
||||
// }
|
||||
// case "nextday" -> {
|
||||
// int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds();
|
||||
// int day = sec / (3600 * 24);
|
||||
// return day == 0 ? "" : day + CFLocale.FORMAT_Day;
|
||||
// }
|
||||
// case "rank" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// else return String.valueOf(competition.getRanking().getPlayerRank(player.getName()));
|
||||
// }
|
||||
// case "goal" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// else return competition.getGoal().name();
|
||||
// }
|
||||
// case "seconds" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// return competition.getCachedPlaceholder("{seconds}");
|
||||
// }
|
||||
// case "second" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// return competition.getCachedPlaceholder("{second}");
|
||||
// }
|
||||
// case "minute" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// return competition.getCachedPlaceholder("{minute}");
|
||||
// }
|
||||
// case "hour" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// return competition.getCachedPlaceholder("{hour}");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String[] split = params.split("_", 2);
|
||||
// switch (split[0]) {
|
||||
// case "score" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// if (split.length == 1) {
|
||||
// return String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()));
|
||||
// } else {
|
||||
// return String.format("%.2f", competition.getRanking().getScoreAt(Integer.parseInt(split[1])));
|
||||
// }
|
||||
// }
|
||||
// case "player" -> {
|
||||
// FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
// if (competition == null) return "";
|
||||
// if (split.length == 1) return "Invalid format";
|
||||
// return Optional.ofNullable(competition.getRanking().getPlayerAt(Integer.parseInt(split[1]))).orElse("");
|
||||
// }
|
||||
// }
|
||||
// return "null";
|
||||
// }
|
||||
//}
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.integration.papi;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition;
|
||||
import net.momirealms.customfishing.api.mechanic.context.ContextKeys;
|
||||
import net.momirealms.customfishing.common.locale.MessageConstants;
|
||||
import net.momirealms.customfishing.common.locale.TranslationManager;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class CompetitionPapi extends PlaceholderExpansion {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
|
||||
public CompetitionPapi(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
super.register();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
super.unregister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "cfcompetition";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "XiaoMoMi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "2.2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
switch (params) {
|
||||
case "goingon" -> {
|
||||
return String.valueOf(plugin.getCompetitionManager().getOnGoingCompetition() != null);
|
||||
}
|
||||
case "nextseconds" -> {
|
||||
return String.valueOf(plugin.getCompetitionManager().getNextCompetitionInSeconds());
|
||||
}
|
||||
case "nextsecond" -> {
|
||||
return plugin.getCompetitionManager().getNextCompetitionInSeconds() % 60 + TranslationManager.miniMessageTranslation(MessageConstants.FORMAT_SECOND.build().key());
|
||||
}
|
||||
case "nextminute" -> {
|
||||
int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds();
|
||||
int min = (sec % 3600) / 60;
|
||||
return sec < 60 ? "" : min + TranslationManager.miniMessageTranslation(MessageConstants.FORMAT_MINUTE.build().key());
|
||||
}
|
||||
case "nexthour" -> {
|
||||
int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds();
|
||||
int h = (sec % (3600 * 24)) / 3600;
|
||||
return sec < 3600 ? "" : h + TranslationManager.miniMessageTranslation(MessageConstants.FORMAT_HOUR.build().key());
|
||||
}
|
||||
case "nextday" -> {
|
||||
int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds();
|
||||
int day = sec / (3600 * 24);
|
||||
return day == 0 ? "" : day + TranslationManager.miniMessageTranslation(MessageConstants.FORMAT_DAY.build().key());
|
||||
}
|
||||
case "rank" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
else return String.valueOf(competition.getRanking().getPlayerRank(player.getName()));
|
||||
}
|
||||
case "goal" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
else return competition.getGoal().toString();
|
||||
}
|
||||
case "seconds" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
return String.valueOf(competition.getPublicContext().arg(ContextKeys.SECONDS));
|
||||
}
|
||||
case "second" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
return String.valueOf(competition.getPublicContext().arg(ContextKeys.SECOND));
|
||||
}
|
||||
case "minute" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
return String.valueOf(competition.getPublicContext().arg(ContextKeys.MINUTE));
|
||||
}
|
||||
case "hour" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
return String.valueOf(competition.getPublicContext().arg(ContextKeys.HOUR));
|
||||
}
|
||||
}
|
||||
|
||||
String[] split = params.split("_", 2);
|
||||
switch (split[0]) {
|
||||
case "score" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
if (split.length == 1) {
|
||||
return String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()));
|
||||
} else {
|
||||
return String.format("%.2f", competition.getRanking().getScoreAt(Integer.parseInt(split[1])));
|
||||
}
|
||||
}
|
||||
case "player" -> {
|
||||
FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition();
|
||||
if (competition == null) return "";
|
||||
if (split.length == 1) return "Invalid format";
|
||||
return Optional.ofNullable(competition.getRanking().getPlayerAt(Integer.parseInt(split[1]))).orElse("");
|
||||
}
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,126 +1,125 @@
|
||||
///*
|
||||
// * Copyright (C) <2022> <XiaoMoMi>
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// */
|
||||
//
|
||||
//package net.momirealms.customfishing.bukkit.integration.papi;
|
||||
//
|
||||
//import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
//import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
//import org.bukkit.Bukkit;
|
||||
//import org.bukkit.OfflinePlayer;
|
||||
//import org.bukkit.entity.Player;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//import org.jetbrains.annotations.Nullable;
|
||||
//
|
||||
//public class CustomFishingPapi extends PlaceholderExpansion {
|
||||
//
|
||||
// private final BukkitCustomFishingPlugin plugin;
|
||||
//
|
||||
// public CustomFishingPapi(BukkitCustomFishingPlugin plugin) {
|
||||
// this.plugin = plugin;
|
||||
// }
|
||||
//
|
||||
// public void load() {
|
||||
// super.register();
|
||||
// }
|
||||
//
|
||||
// public void unload() {
|
||||
// super.unregister();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getIdentifier() {
|
||||
// return "customfishing";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getAuthor() {
|
||||
// return "XiaoMoMi";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getVersion() {
|
||||
// return "2.0";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean persist() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @Nullable String onRequest(OfflinePlayer offlinePlayer, @NotNull String params) {
|
||||
// String[] split = params.split("_");
|
||||
//
|
||||
// Player player = offlinePlayer.getPlayer();
|
||||
// if (player == null)
|
||||
// return "";
|
||||
//
|
||||
// switch (split[0]) {
|
||||
// case "market" -> {
|
||||
// if (split.length < 2)
|
||||
// return null;
|
||||
// switch (split[1]) {
|
||||
// case "limit" -> {
|
||||
// if (split.length < 3) {
|
||||
// return String.format("%.2f", plugin.getMarketManager().earningLimit(player));
|
||||
// } else {
|
||||
// Player another = Bukkit.getPlayer(split[2]);
|
||||
// if (another == null) {
|
||||
// return "";
|
||||
// }
|
||||
// return String.format("%.2f", plugin.getMarketManager().earningLimit(another));
|
||||
// }
|
||||
// }
|
||||
// case "earnings" -> {
|
||||
// OnlineUserData user;
|
||||
// if (split.length < 3) {
|
||||
// user = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
||||
// } else {
|
||||
// Player another = Bukkit.getPlayer(split[2]);
|
||||
// if (another == null) {
|
||||
// return "";
|
||||
// }
|
||||
// user = plugin.getStorageManager().getOnlineUser(another.getUniqueId());
|
||||
// }
|
||||
// if (user == null)
|
||||
// return "";
|
||||
// return String.format("%.2f", user.getEarningData().earnings);
|
||||
// }
|
||||
// case "canearn" -> {
|
||||
// if (split.length < 3) {
|
||||
// OnlineUserData user = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
||||
// if (user == null)
|
||||
// return "";
|
||||
// return String.format("%.2f", plugin.getMarketManager().earningLimit(player) - user.getEarningData().earnings);
|
||||
// } else {
|
||||
// Player another = Bukkit.getPlayer(split[2]);
|
||||
// if (another == null) {
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// OnlineUserData user = plugin.getStorageManager().getOnlineUser(another.getUniqueId());
|
||||
// if (user == null)
|
||||
// return "";
|
||||
// return String.format("%.2f", plugin.getMarketManager().earningLimit(another) - user.getEarningData().earnings);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.integration.papi;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.context.Context;
|
||||
import net.momirealms.customfishing.api.storage.user.UserData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CustomFishingPapi extends PlaceholderExpansion {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
|
||||
public CustomFishingPapi(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
super.register();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
super.unregister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "customfishing";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "XiaoMoMi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "2.2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer offlinePlayer, @NotNull String params) {
|
||||
String[] split = params.split("_");
|
||||
Player player = offlinePlayer.getPlayer();
|
||||
if (player == null)
|
||||
return "";
|
||||
switch (split[0]) {
|
||||
case "market" -> {
|
||||
if (split.length < 2)
|
||||
return null;
|
||||
switch (split[1]) {
|
||||
case "limit" -> {
|
||||
if (split.length < 3) {
|
||||
return String.format("%.2f", plugin.getMarketManager().earningLimit(Context.player(player)));
|
||||
} else {
|
||||
Player another = Bukkit.getPlayer(split[2]);
|
||||
if (another == null) {
|
||||
return "";
|
||||
}
|
||||
return String.format("%.2f", plugin.getMarketManager().earningLimit(Context.player(another)));
|
||||
}
|
||||
}
|
||||
case "earnings" -> {
|
||||
UserData user;
|
||||
if (split.length < 3) {
|
||||
user = plugin.getStorageManager().getOnlineUser(player.getUniqueId()).orElse(null);
|
||||
} else {
|
||||
Player another = Bukkit.getPlayer(split[2]);
|
||||
if (another == null) {
|
||||
return "";
|
||||
}
|
||||
user = plugin.getStorageManager().getOnlineUser(another.getUniqueId()).orElse(null);
|
||||
}
|
||||
if (user == null)
|
||||
return "";
|
||||
return String.format("%.2f", user.earningData().earnings());
|
||||
}
|
||||
case "canearn" -> {
|
||||
if (split.length < 3) {
|
||||
UserData user = plugin.getStorageManager().getOnlineUser(player.getUniqueId()).orElse(null);
|
||||
if (user == null)
|
||||
return "";
|
||||
return String.format("%.2f", plugin.getMarketManager().earningLimit(Context.player(player)) - user.earningData().earnings());
|
||||
} else {
|
||||
Player another = Bukkit.getPlayer(split[2]);
|
||||
if (another == null) {
|
||||
return "";
|
||||
}
|
||||
UserData user = plugin.getStorageManager().getOnlineUser(another.getUniqueId()).orElse(null);
|
||||
if (user == null)
|
||||
return "";
|
||||
return String.format("%.2f", plugin.getMarketManager().earningLimit(Context.player(another)) - user.earningData().earnings());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,112 +1,116 @@
|
||||
///*
|
||||
// * Copyright (C) <2022> <XiaoMoMi>
|
||||
// *
|
||||
// * This program is free software: you can redistribute it and/or modify
|
||||
// * it under the terms of the GNU General Public License as published by
|
||||
// * the Free Software Foundation, either version 3 of the License, or
|
||||
// * any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have received a copy of the GNU General Public License
|
||||
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// */
|
||||
//
|
||||
//package net.momirealms.customfishing.bukkit.integration.papi;
|
||||
//
|
||||
//import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
//import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
//import org.bukkit.OfflinePlayer;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//import org.jetbrains.annotations.Nullable;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class StatisticsPapi extends PlaceholderExpansion {
|
||||
//
|
||||
// private final BukkitCustomFishingPlugin plugin;
|
||||
//
|
||||
// public StatisticsPapi(BukkitCustomFishingPlugin plugin) {
|
||||
// this.plugin = plugin;
|
||||
// }
|
||||
//
|
||||
// public void load() {
|
||||
// super.register();
|
||||
// }
|
||||
//
|
||||
// public void unload() {
|
||||
// super.unregister();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getIdentifier() {
|
||||
// return "fishingstats";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getAuthor() {
|
||||
// return "XiaoMoMi";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @NotNull String getVersion() {
|
||||
// return "2.0";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean persist() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
// OnlineUserData onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
||||
// if (onlineUser == null) return "Data not loaded";
|
||||
// Statistics statistics = onlineUser.getStatistics();
|
||||
// String[] split = params.split("_", 2);
|
||||
// switch (split[0]) {
|
||||
// case "total" -> {
|
||||
// return String.valueOf(statistics.getTotalCatchAmount());
|
||||
// }
|
||||
// case "hascaught" -> {
|
||||
// if (split.length == 1) return "Invalid format";
|
||||
// return String.valueOf(statistics.getLootAmount(split[1]) != 0);
|
||||
// }
|
||||
// case "amount" -> {
|
||||
// if (split.length == 1) return "Invalid format";
|
||||
// return String.valueOf(statistics.getLootAmount(split[1]));
|
||||
// }
|
||||
// case "size-record" -> {
|
||||
// return String.format("%.2f", statistics.getSizeRecord(split[1]));
|
||||
// }
|
||||
// case "category" -> {
|
||||
// if (split.length == 1) return "Invalid format";
|
||||
// String[] categorySplit = split[1].split("_", 2);
|
||||
// if (categorySplit.length == 1) return "Invalid format";
|
||||
// List<String> category = plugin.getStatisticsManager().getCategory(categorySplit[1]);
|
||||
// if (category == null) return "Category Not Exists";
|
||||
// if (categorySplit[0].equals("total")) {
|
||||
// int total = 0;
|
||||
// for (String loot : category) {
|
||||
// total += statistics.getLootAmount(loot);
|
||||
// }
|
||||
// return String.valueOf(total);
|
||||
// } else if (categorySplit[0].equals("progress")) {
|
||||
// int size = category.size();
|
||||
// int unlocked = 0;
|
||||
// for (String loot : category) {
|
||||
// if (statistics.getLootAmount(loot) != 0) unlocked++;
|
||||
// }
|
||||
// double percent = ((double) unlocked * 100) / size;
|
||||
// String progress = String.format("%.1f", percent);
|
||||
// return progress.equals("100.0") ? "100" : progress;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return "null";
|
||||
// }
|
||||
//}
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.integration.papi;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.momirealms.customfishing.api.BukkitCustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.mechanic.statistic.FishingStatistics;
|
||||
import net.momirealms.customfishing.api.storage.user.UserData;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class StatisticsPapi extends PlaceholderExpansion {
|
||||
|
||||
private final BukkitCustomFishingPlugin plugin;
|
||||
|
||||
public StatisticsPapi(BukkitCustomFishingPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
super.register();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
super.unregister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "fishingstats";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "XiaoMoMi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "2.2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
Optional<UserData> onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
||||
return onlineUser.map(
|
||||
data -> {
|
||||
FishingStatistics statistics = data.statistics();
|
||||
String[] split = params.split("_", 2);
|
||||
switch (split[0]) {
|
||||
case "total" -> {
|
||||
return String.valueOf(statistics.amountOfFishCaught());
|
||||
}
|
||||
case "hascaught" -> {
|
||||
if (split.length == 1) return "Invalid format";
|
||||
return String.valueOf(statistics.getAmount(split[1]) != 0);
|
||||
}
|
||||
case "amount" -> {
|
||||
if (split.length == 1) return "Invalid format";
|
||||
return String.valueOf(statistics.getAmount(split[1]));
|
||||
}
|
||||
case "size-record" -> {
|
||||
return String.format("%.2f", statistics.getMaxSize(split[1]));
|
||||
}
|
||||
case "category" -> {
|
||||
if (split.length == 1) return "Invalid format";
|
||||
String[] categorySplit = split[1].split("_", 2);
|
||||
if (categorySplit.length == 1) return "Invalid format";
|
||||
List<String> category = plugin.getStatisticsManager().getCategoryMembers(categorySplit[1]);
|
||||
if (categorySplit[0].equals("total")) {
|
||||
int total = 0;
|
||||
for (String loot : category) {
|
||||
total += statistics.getAmount(loot);
|
||||
}
|
||||
return String.valueOf(total);
|
||||
} else if (categorySplit[0].equals("progress")) {
|
||||
int size = category.size();
|
||||
int unlocked = 0;
|
||||
for (String loot : category) {
|
||||
if (statistics.getAmount(loot) != 0) unlocked++;
|
||||
}
|
||||
double percent = ((double) unlocked * 100) / size;
|
||||
String progress = String.format("%.1f", percent);
|
||||
return progress.equals("100.0") ? "100" : progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
).orElse("Data not loaded");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customfishing.bukkit.integration.season;
|
||||
|
||||
import net.advancedplugins.seasons.api.AdvancedSeasonsAPI;
|
||||
|
||||
Reference in New Issue
Block a user