Version 1.0.0 - Added to server for testing

This commit is contained in:
Michael Ziluck
2019-06-03 14:08:28 -05:00
parent a5e6e3d818
commit f9204b2abe
14 changed files with 152 additions and 537 deletions
@@ -1,5 +1,6 @@
package com.alttd.altitudetag;
import java.io.File;
import java.util.UUID;
import java.util.function.Consumer;
@@ -12,6 +13,7 @@ import com.alttd.altitudetag.listeners.ConnectionListener;
import com.alttd.altitudetag.listeners.InteractListener;
import org.bukkit.Bukkit;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class AltitudeTag extends JavaPlugin
@@ -37,7 +39,7 @@ public class AltitudeTag extends JavaPlugin
return;
}
Lang.update();
reloadConfiguration();
// update the CommandLang values
CommandLang.NO_PERMISSION.setValue(Lang.NO_PERMS.getRawMessage()[0]);
@@ -46,10 +48,21 @@ public class AltitudeTag extends JavaPlugin
CommandLang.ONLY_PLAYERS.setValue(Lang.ONLY_PLAYERS.getRawMessage()[0]);
CommandLang.USAGE_FORMAT.setValue(Lang.USAGE.getRawMessage()[0]);
Config.update();
TagConnection.initialize();
try
{
TagConnection.initialize();
}
catch (Exception ex)
{
getLogger().severe("*** Could not connect to the database. ***");
getLogger().severe("*** This plugin will be disabled. ***");
this.setEnabled(false);
return;
}
Leaderboard.initialize();
NotificationHandler.loadBossBar();
CommandHandler.initialize();
CommandHandler.getInstance().registerCommand(new TagCommand(), this);
@@ -57,6 +70,25 @@ public class AltitudeTag extends JavaPlugin
Bukkit.getPluginManager().registerEvents(new InteractListener(), this);
}
private static void reloadConfiguration()
{
// check lang
File langFile = new File(instance.getDataFolder(), "lang.yml");
if (!langFile.exists())
{
instance.saveResource("lang.yml", false);
}
Lang.update();
// check config
File configFile = new File(instance.getDataFolder(), "config.yml");
if (!configFile.exists())
{
instance.saveDefaultConfig();
}
Config.update();
}
public static BossBar getBossBar()
{
return instance.bossBar;
@@ -67,24 +99,6 @@ public class AltitudeTag extends JavaPlugin
instance.bossBar = bossBar;
}
/**
* Set the current tagger.
*
* @param tagger the new tagger.
*
* @return the previous tagger.
*/
public static UUID setTagger(UUID tagger)
{
UUID prev = instance.tagger;
instance.tagger = tagger;
// announce that a new person is it
Bukkit.getOnlinePlayers().stream().filter(player -> !player.getUniqueId().equals(tagger)).forEach(player -> player.sendMessage());
return prev;
}
/**
* Returns the current tagger.
*
@@ -95,6 +109,25 @@ public class AltitudeTag extends JavaPlugin
return instance.tagger;
}
/**
* Set the current tagger.
*
* @param tagger the new tagger.
*/
public static void setTagger(UUID tagger)
{
// announce that a new person is it
Player previousPlayer = Bukkit.getPlayer(instance.tagger);
if (tagger != null)
{
NotificationHandler.sendGlobalNotifications(previousPlayer != null
? previousPlayer.getName()
: null, Bukkit.getPlayer(tagger).getName());
}
instance.tagger = tagger;
}
/**
* Adds a tag for the given player.
*
@@ -43,7 +43,7 @@ public class Leaderboard
ex.printStackTrace();
}
initializeLeaderboard();
Bukkit.getScheduler().runTaskLater(AltitudeTag.getInstance(), Leaderboard::initializeLeaderboard, 20);
}
/**
@@ -99,9 +99,9 @@ public class Leaderboard
{
ps.setString(1, uuid.toString());
ResultSet rs = ps.getResultSet();
ResultSet rs = ps.executeQuery();
if (rs.next())
if (rs != null && rs.next())
{
// call the consumer when the query returns back
consumer.accept(rs.getInt(1));
@@ -134,8 +134,8 @@ public class Leaderboard
config.set("leaderboard.location.z", Config.LEADERBOARD_LOCATION_Z.getValue());
AltitudeTag.getInstance().saveConfig();
hologram.delete();
initializeLeaderboard();
hologram.teleport(location);
refreshLeaderboard();
}
private static void initializeLeaderboard()
@@ -160,8 +160,11 @@ public class Leaderboard
private static void refreshLeaderboard()
{
if (Config.LEADERBOARD_ENABLED.getValue())
if (!Config.LEADERBOARD_ENABLED.getValue())
{
return;
}
Objects.requireNonNull(hologram);
Bukkit.getScheduler().runTaskAsynchronously(AltitudeTag.getInstance(), () ->
@@ -170,22 +173,26 @@ public class Leaderboard
try (PreparedStatement ps = TagConnection.getConnection().prepareStatement(sql))
{
ps.setInt(1, Config.LEADERBOARD_TOP.getValue());
ResultSet rs = ps.getResultSet();
ResultSet rs = ps.executeQuery();
for (int i = 0; i < Config.LEADERBOARD_TOP.getValue(); i++)
{
final int finalInt = i;
String text;
if (rs.next())
if (rs != null && rs.next())
{
text = Lang.renderString(Config.LEADERBOARD_FORMAT.getValue(),
"{rank}", i,
"{player}", Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("player_uuid"))),
"{player}", Bukkit.getOfflinePlayer(UUID.fromString(rs.getString("player_uuid"))).getName(),
"{tags}", rs.getInt("player_tags"));
}
else
{
text = "";
}
((TextLine) hologram.getLine(i)).setText(text);
if (!((TextLine) hologram.getLine(finalInt + 1)).getText().equals(text))
{
Bukkit.getScheduler().runTask(AltitudeTag.getInstance(), () -> ((TextLine) hologram.getLine(finalInt + 1)).setText(text));
}
}
}
catch (SQLException ex)
@@ -193,6 +200,6 @@ public class Leaderboard
ex.printStackTrace();
}
});
}
}
}
@@ -68,18 +68,26 @@ public class NotificationHandler
{
if (attacker == null && Config.NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_ENABLED.getValue())
{
// TODO make this actually do what it's supposed to
Bukkit.getOnlinePlayers().forEach(p -> p.sendMessage(Lang.renderString(Config.NOTIFICATION_GLOBAL_CHAT_OTHER_REASON_MESSAGE.getValue(),
"{victim}", victim)));
"{target}", victim)));
}
if (attacker != null && Config.NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_ENABLED.getValue())
{
Bukkit.getOnlinePlayers().forEach(p -> p.sendMessage(Lang.renderString(Config.NOTIFICATION_GLOBAL_CHAT_AFTER_TAG_MESSAGE.getValue(),
"{victim}", victim,
"{target}", victim,
"{attacker}", attacker)));
}
if (Config.NOTIFICATION_GLOBAL_BOSS_BAR_ENABLED.getValue())
{
AltitudeTag.getBossBar().setTitle(Lang.renderString(Config.NOTIFICATION_GLOBAL_BOSS_BAR_MESSAGE.getValue(), "{player}", victim,
BarUtils.parseBarColor(Config.NOTIFICATION_GLOBAL_BOSS_BAR_COLOR.getValue()),
BarUtils.parseBarStyle(Config.NOTIFICATION_GLOBAL_BOSS_BAR_SEGMENTS.getValue())));
}
}
public static void sendBossBar()
public static void loadBossBar()
{
if (Config.NOTIFICATION_GLOBAL_BOSS_BAR_ENABLED.getValue())
{
@@ -3,8 +3,7 @@ package com.alttd.altitudetag;
public enum Permission
{
COMMAND_ADMIN("tag.commands.admin"),
COMMAND_ADMIN_LOCATION("tag.commands.admin.location"),
QUEUE_COMMAND("altiqueue.queue-command");
COMMAND_ADMIN_LOCATION("tag.commands.admin.location");
private String permission;
@@ -19,7 +19,7 @@ public class TagConnection
private int port;
private String description;
private TagConnection()
private TagConnection() throws SQLException, ClassNotFoundException
{
this.host = Config.DATABASE_HOSTNAME.getValue();
this.database = Config.DATABASE_DATABASE.getValue();
@@ -28,14 +28,9 @@ public class TagConnection
this.port = Config.DATABASE_PORT.getValue();
this.description = Config.DATABASE_DESCRIPTION.getValue();
try
{
instance.openConnection();
}
catch (SQLException | ClassNotFoundException ex)
{
ex.printStackTrace();
}
instance = this;
instance.openConnection();
}
private void openConnection() throws SQLException, ClassNotFoundException
@@ -70,7 +65,7 @@ public class TagConnection
return instance.connection;
}
public static void initialize()
public static void initialize() throws SQLException, ClassNotFoundException
{
instance = new TagConnection();
}
@@ -11,7 +11,7 @@ public class TagCommand extends ValidBaseCommand
{
public TagCommand()
{
super("tag", "Tag, you're it!", new String[]{ "tags", "tagging", "tagger" });
super("tag", "Tag, you're it!", "tag.play", new String[]{ "tags", "tagging", "tagger" });
addSubCommand(new TagAdminCommand());
}
@@ -0,0 +1,22 @@
package com.alttd.altitudetag.commands.parsers;
import java.util.List;
import com.alttd.altitudeapi.commands.CommandHandler;
import com.alttd.altitudeapi.commands.Parser;
import org.bukkit.command.CommandSender;
public class StringParser implements Parser<String>
{
@Override
public String parseArgument(CommandSender sender, String[] label, String rawArgument)
{
return rawArgument;
}
@Override
public List<String> getRecommendations(CommandSender sender, String lastWord)
{
return CommandHandler.defaultTabComplete(sender, lastWord);
}
}
@@ -20,8 +20,10 @@ public class ConnectionListener implements Listener
if (AltitudeTag.getTagger() == null)
{
AltitudeTag.setTagger(event.getPlayer().getUniqueId());
NotificationHandler.sendVictimTitle(event.getPlayer(), true);
}
if (AltitudeTag.getBossBar() != null)
{
AltitudeTag.getBossBar().addPlayer(event.getPlayer());
}
}
@@ -15,24 +15,26 @@ public class InteractListener implements Listener
if (event.getDamager() instanceof Player && event.getEntity() instanceof Player)
{
final Player tagger = (Player) event.getDamager();
if (!AltitudeTag.getTagger().equals(tagger.getUniqueId()))
{
return;
}
final Player tagged = (Player) event.getEntity();
// add the new tag
AltitudeTag.addTag(tagger.getUniqueId(), () ->
{
// if they left, we can stop
if (!tagger.isOnline())
if (tagger.isOnline())
{
return;
NotificationHandler.sendTaggerNotifications(tagger, tagged.getName());
}
NotificationHandler.sendTaggerNotifications(tagger, tagged.getName());
});
AltitudeTag.setTagger(tagged.getUniqueId());
NotificationHandler.sendVictimTitle(tagged, false);
NotificationHandler.sendGlobalNotifications(tagger.getName(), tagged.getName());
}
}
}