new pvp timer management, fixed build house task, fixed incognito

This commit is contained in:
Ben 2016-03-18 01:18:35 +00:00
parent a3db70ad9c
commit 2cf59ced8b
12 changed files with 99 additions and 116 deletions

View File

@ -15,7 +15,6 @@ public abstract class MiniClientPlugin<DataType extends Object> extends MiniPlug
private NautHashMap<String, DataType> _clientData = new NautHashMap<String, DataType>();
public MiniClientPlugin(String moduleName, JavaPlugin plugin)
{
super(moduleName, plugin);

View File

@ -64,12 +64,6 @@ public class IncognitoManager extends MiniClientPlugin<IncognitoClient>
{
other.showPlayer(caller);
}
UtilServer.broadcast(F.sys("Join", caller.getName()));
}
else
{
UtilServer.broadcast(F.sys("Quit", caller.getName()));
}
runAsync(() -> _repository.SetStatus(_clientManager.getAccountId(caller), enabled));

View File

@ -10,9 +10,10 @@ import mineplex.serverdata.database.column.ColumnInt;
public class IncognitoRepository extends MinecraftRepository
{
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS incognitoStaff (accountId INT NOT NULL, status TINYINT(1) DEFAULT '0');";
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS incognitoStaff (accountId INT NOT NULL, status TINYINT(1) DEFAULT '0', PRIMARY KEY (accountId));";
private static final String GET_STATUS = "SELECT * FROM incognitoStaff WHERE accountId = ?;";
private static final String SET_STATUS = "INSERT INTO incognitoStaff (accountId, status) VALUES (?, ?);";
private static final String INSERT_STATUS = "INSERT INTO incognitoStaff (accountId, status) VALUES (?, ?);";
private static final String UPDATE_STATUS = "UPDATE incognitoStaff SET status=? WHERE accountId=?;";
private IncognitoManager _incognitoManager;
@ -29,8 +30,13 @@ public class IncognitoRepository extends MinecraftRepository
public void SetStatus(int accountId, boolean status)
{
System.out.println("[INCOGNITO] Updated status for " + accountId + " to " + status);
executeUpdate(SET_STATUS, new ColumnInt("accountId", accountId), new ColumnInt("status", status ? 1 : 0));
// Prevent duplicate entries for individuals
executeQuery(GET_STATUS, result -> {
if (result.next())
executeUpdate(UPDATE_STATUS, new ColumnInt("status", status ? 1 : 0), new ColumnInt("accountId", accountId));
else
executeUpdate(INSERT_STATUS, new ColumnInt("accountId", accountId), new ColumnInt("status", status ? 1 : 0));
}, new ColumnInt("accountId", accountId));
}
public boolean GetStatus(int accountId)

View File

@ -55,7 +55,7 @@ import net.minecraft.server.v1_8_R3.MinecraftServer;
public class Clans extends JavaPlugin
{
public static final String VERSION = "Beta 1.0_01";
public static final String VERSION = "Beta 1.0";
private String WEB_CONFIG = "webServer";
// Modules

View File

@ -1,75 +0,0 @@
package mineplex.game.clans.clans;
import java.util.Arrays;
import java.util.LinkedList;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.task.TaskManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ClansAlphaManager extends MiniPlugin
{
private static final LinkedList<LinkedList<String>> ANNOUNCEMENTS = new LinkedList<>(Arrays.asList(new LinkedList<>(Arrays.asList(C.cDAquaB + "Welcome to Clans Alpha", C.cAqua + "Clans is in early Alpha stages so expect there to be bugs/issues. Please report any bugs to staff, we hope you enjoy this early test!"))));
private static final boolean RANDOM_ANNOUNCEMENT = true;
/**
* This is useful if the above boolean (RANDOM_ANNOUNCEMENT) is set to
* false, then the announcement at index SET_ANNOUNCEMENT will be used every
* time.
*/
private static final int SET_ANNOUNCEMENT = 0;
private static final LinkedList<String> FIRST_JOIN_MESSAGES = new LinkedList<>(ANNOUNCEMENTS.getFirst());
private static final UpdateType ANNOUNCEMENT_DELAY = UpdateType.MIN_16;
private TaskManager _taskManager;
public ClansAlphaManager(ClansManager manager, TaskManager taskManager)
{
super("Announcements", manager.getPlugin());
_taskManager = taskManager;
}
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event)
{
if (!_taskManager.hasCompletedTask(event.getPlayer(), "ClansAlphaJoinMessage"))
{
_taskManager.completedTask(new Callback<Boolean>()
{
public void run(Boolean data)
{
UtilPlayer.message(event.getPlayer(), FIRST_JOIN_MESSAGES);
}
}, event.getPlayer(), "ClansAlphaJoinMessage");
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType().equals(ANNOUNCEMENT_DELAY))
{
if (RANDOM_ANNOUNCEMENT)
{
UtilServer.broadcast(UtilMath.randomElement(ANNOUNCEMENTS));
}
else
{
UtilServer.broadcast(ANNOUNCEMENTS.get(SET_ANNOUNCEMENT));
}
}
}
}

View File

@ -290,7 +290,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
new ClanEnergyTracker(plugin, this);
// new StuckManager(this);
// new ClansAlphaManager(this, taskManager);
new ClansBetaManager(this, taskManager);
new PotatoManager(plugin, this);
@ -324,7 +324,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
new ClanEnergyManager(plugin, this, clientManager, donationManager);
_playTracker = new Playtime(this, statsManager);
_pvpTimer = new PvpTimer(this, _playTracker, statsManager);
_pvpTimer = new PvpTimer(this, statsManager);
_tutorialManager = new mineplex.game.clans.legacytutorial.TutorialManager(plugin, _playTracker, _goldManager, taskManager, donationManager, preferencesManager, this, packetHandler);
TutorialManager tutorial = new TutorialManager(plugin, clientManager, donationManager, chat);
@ -567,6 +567,10 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{
UtilServer.broadcast(F.sys("Quit", event.getPlayer().getName()));
}
else
{
UtilServer.broadcast(F.sys("Join", event.getPlayer().getName()));
}
}
@EventHandler

View File

@ -9,30 +9,31 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.MiniClientPlugin;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.stats.StatsManager;
import mineplex.core.task.TaskManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClanTipEvent;
import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent;
import mineplex.game.clans.clans.playtime.Playtime;
import mineplex.game.clans.clans.playtime.command.cemde;
import mineplex.game.clans.clans.pvptimer.command.PvPTimerCommand;
import mineplex.game.clans.clans.pvptimer.repository.PvpTimerRepository;
import mineplex.game.clans.clans.pvptimer.repository.TimerClientToken;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.spawn.Spawn;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
@ -41,20 +42,33 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
{
public static final String SKIPPED_TASK = "PvpTimer.Skipped";
private final int[] DISPLAY_TIMES = { 5, 10, 30, 1 * 60, 2 * 60, 5 * 60, 10 * 60, 20 * 60 };
private final int[] DISPLAY_TIMES = {
5,
10,
30,
1 * 60,
2 * 60,
5 * 60,
10 * 60,
20 * 60
};
private PvpTimerRepository _repository;
private CoreClientManager _clientManager;
private ClansManager _clansManager;
private Playtime _tracker;
private static long TIMER_LENGTH = 30 * 60;
public PvpTimer(ClansManager clans, Playtime playtime, StatsManager statsManager)
public PvpTimer(ClansManager clans, StatsManager statsManager)
{
super("PvP Timer", clans.getPlugin());
_tracker = playtime;
_clansManager = clans;
_clientManager = clans.getClientManager();
_repository = new PvpTimerRepository(this, clans.getClientManager());
addCommand(new cemde(statsManager, this));
}
@ -69,7 +83,7 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
Get(caller).Skipped = true;
caller.playSound(caller.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 0.75f);
TaskManager.Instance.completedTask(null, caller, "PvpTimer.Skipped");
_repository.Save(_clientManager.getAccountId(caller), Get(caller).Skipped, Get(caller).Elapsed);
}
@EventHandler
@ -89,9 +103,26 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
runAsync(() -> _repository.Save(_clientManager.getAccountId(event.getPlayer()), Get(event.getPlayer()).Skipped, Get(event.getPlayer()).Elapsed + (int) (elapsed(event.getPlayer()) / 1000)));
}
@EventHandler
public void outYouGo(UpdateEvent event)
{
if (event.getType() == UpdateType.SLOWER)
{
UtilServer.getPlayersCollection().forEach(player -> {
PvpTimerClient client = Get(player);
client.StartTime = System.currentTimeMillis();
runAsync(() -> _repository.Save(_clientManager.getAccountId(player), client.Skipped, client.Elapsed += (int) (elapsed(player))));
});
}
if (event.getType() == UpdateType.SEC)
{
for (Player player : Bukkit.getOnlinePlayers())
@ -149,9 +180,9 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
}
}, 10);
UtilPlayer.message(player, F.main("Clans", "You are currently safe from PvP because you are a new player. This safety will end in " + F.time(UtilTime.MakeStr(getPvPTimerLeft(player) * 1000))));
UtilPlayer.message(player, F.main("Clans", "Until it ends, you are immune to, and unable to deal PvP damage."));
UtilPlayer.message(player, F.main("Clans", "If you would like to disable the PvP safety permanently, then type " + F.elem("/pvp") + "."));
UtilPlayer.message(player, C.cAqua + "You are currently safe from PvP because you are a new player. This safety will end in " + F.time(UtilTime.MakeStr(getPvPTimerLeft(player) * 1000)));
UtilPlayer.message(player, C.cAqua + "Until it ends, you are immune to, and are unable to deal PvP damage.");
UtilPlayer.message(player, C.cAqua + "If you would like to disable the PvP safety permanently, then type " + F.elem("/pvp") + ".");
}
}
@ -171,17 +202,17 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
{
UtilPlayer.message(player, F.main("Clans", "PvP Safety has ended!"));
UtilPlayer.message(player, F.main("Clans", "You are now completely open to attacks, and you can also attack others."));
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 0.75f);
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 0.2f, 0.75f);
continue;
}
for (int unit : DISPLAY_TIMES)
{
if (time <= unit && !client.InformedTimes.contains(unit))
if (time <= unit && !client.InformedTimes.contains(Integer.valueOf(unit)))
{
UtilPlayer.message(player, F.main("Clans", "PvP Safety will end in " + F.time(UtilTime.MakeStr(unit * 1000))));
UtilTextMiddle.display(C.cGreen + "Pvp Safety", C.cGray + "ending in " + UtilTime.MakeStr(unit * 1000), 20, 80, 20, player);
client.InformedTimes.add(unit);
client.InformedTimes.add(Integer.valueOf(unit));
}
}
}
@ -255,7 +286,10 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
{
if (victimTimer)
{
if (!bothMsg) UtilPlayer.message(damager, F.main("Clans", "You and " + F.name(victim.getName()) + " are still under PvP Safety. Type " + F.elem("/pvp") + " to disable."));
if (!bothMsg)
{
UtilPlayer.message(damager, F.main("Clans", "You and " + F.name(victim.getName()) + " are still under PvP Safety. Type " + F.elem("/pvp") + " to disable."));
}
}
else if (damager != null)
{
@ -267,13 +301,29 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
}
@EventHandler(priority = EventPriority.LOWEST)
public void ClientLoad(AsyncPlayerPreLoginEvent event)
{
_clientManager.getRepository().getAccountId(event.getUniqueId(), accountId -> {
TimerClientToken token = _repository.Get(accountId.intValue());
Get(event.getName()).Skipped = token.Skipped;
Get(event.getName()).Elapsed = token.Elapsed;
});
}
public long getPvPTimerLeft(Player player)
{
long time = (_tracker.getPlaytime(player) + _tracker.getUnsavedPlaytime(player));
long time = Get(player).Elapsed + (elapsed(player) / 1000);
return (TIMER_LENGTH <= time ? 0 : TIMER_LENGTH - time);
}
public long elapsed(Player player)
{
return System.currentTimeMillis() - Get(player).StartTime;
}
public boolean hasTimer(Player victim)
{
return victim != null && getPvPTimerLeft(victim) > 0 && !Get(victim).Skipped;
@ -282,6 +332,6 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
@Override
protected PvpTimerClient AddPlayer(String player)
{
return new PvpTimerClient(Bukkit.getPlayer(player));
return new PvpTimerClient();
}
}

View File

@ -6,15 +6,18 @@ import java.util.List;
import org.bukkit.entity.Player;
import mineplex.core.task.TaskManager;
import mineplex.game.clans.clans.ClansPlayerTasks;
public class PvpTimerClient
{
public boolean Skipped;
public List<Integer> InformedTimes;
public long StartTime;
public int Elapsed;
public PvpTimerClient(Player player)
public PvpTimerClient()
{
Skipped = TaskManager.Instance.hasCompletedTask(player, PvpTimer.SKIPPED_TASK);
StartTime = System.currentTimeMillis();
InformedTimes = new ArrayList<>();
}
}

View File

@ -34,7 +34,8 @@ public class OutpostRepository extends MinecraftRepository
+ "outpostType TINYINT NOT NULL,"
+ "ownerClan INT NOT NULL,"
+ "timeSpawned LONG,"
+ "outpostState TINYINT NOT NULL);";
+ "outpostState TINYINT NOT NULL,"
+ "PRIMARY KEY (uniqueId));";
private static final String GET_OUTPOST_BY_ID = "SELECT * FROM clansOutposts WHERE uniqueId=?;";
private static final String GET_OUTPOST_BY_CLAN = "SELECT * FROM clansOutposts WHERE ownerClan=?;";

View File

@ -32,7 +32,8 @@ public class SiegeWeaponRepository extends MinecraftRepository
+ "health INT NOT NULL,"
+ "yaw INT NOT NULL,"
+ "lastFired LONG,"
+ "entities VARCHAR(200));";
+ "entities VARCHAR(200),"
+ "PRIMARY KEY (uniqueId));";
private static final String GET_WEAPON_BY_ID = "SELECT * FROM clansSiegeWeapons WHERE uniqueId=?;";
private static final String GET_WEAPONS_BY_CLAN = "SELECT * FROM clansSiegeWeapons WHERE ownerClan=?;";

View File

@ -94,7 +94,7 @@ public class RunedPickaxe extends RareItem
{
event.getBlock().breakNaturally();
event.getBlock().getWorld().playEffect(event.getBlock().getLocation(), Effect.TILE_BREAK, event.getBlock().getType(), 10);
event.getBlock().getWorld().playEffect(event.getBlock().getLocation(), Effect.TILE_BREAK, event.getBlock().getTypeId(), 10);
event.getPlayer().playSound(event.getBlock().getLocation(), Sound.LAVA_POP, 1.f, 1.f);
}