use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.
the class PlayerJoin method onJoin.
@EventHandler
public void onJoin(PlayerJoinEvent event) {
final UPlayer player = new UPlayer(event);
String pn = player.getName();
UUID uuid = player.getUniqueId();
PlayerInfo.resetHashMaps(player);
player.setCollidable(false);
event.setJoinMessage(DARK_AQUA + "" + BOLD + pn + RESET + AQUA + " has joined");
player.givePotionEffect(PotionEffectType.BLINDNESS, 1 * 20, 0);
player.givePotionEffect(PotionEffectType.NIGHT_VISION, 1 * 20, 0);
player.sendTitle(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Ublisk", ChatColor.YELLOW + "Welcome back, " + pn + "!");
if (player.getSetting(Setting.PLAY_MUSIC)) {
Town town = player.getTown();
if (town != null)
town.playThemeToPlayer(player);
}
player.tracker(PlayerInfo.JOIN_COUNT);
// String ip = player.getPlayer().getAddress().toString();
// ip = ip.replace("/", "");
String ip = player.getIP();
DataFile.IP.getConfig().set("ip." + uuid, ip);
player.updateXPBar();
// Disable builder mode if the player no longer has permission
if (!player.hasPermission(Permission.BUILDER_MODE)) {
player.setBuilderModeEnabled(false);
}
if (player.isInBuilderMode()) {
player.setGameMode(GameMode.CREATIVE);
} else {
player.setGameMode(GameMode.ADVENTURE);
}
player.setFlying(false);
player.setAttribute(Attribute.GENERIC_ATTACK_SPEED, 0.7);
new URunnable() {
public void run() {
player.sendSpacers(10);
final String[] fancyStrings = new String[] { " ", " # # ## # # ### # # ", " # # # # # # # # # ", " # # ## # # ### ## ", " # # # # # # # ## ", " ### ## ### # ### # # ", " " };
for (String string : fancyStrings) {
player.sendMessage(string.replace("#", ChatColor.AQUA + "" + ChatColor.BOLD + ImageChar.DARK_SHADE.getChar()).replace(" ", ChatColor.DARK_AQUA + "" + ChatColor.BOLD + ImageChar.DARK_SHADE.getChar()));
}
player.sendMessage(ChatColor.GRAY + "Welcome to Ublisk! If you find any bugs, please report them using /bug [description].");
}
}.runLater(4);
/*Ublisk.runAsync(() -> {
Connection connection = null;
PreparedStatement check = null;
ResultSet checkResult = null;
PreparedStatement insert = null;
try {
connection = Ublisk.getDatabaseConnection("Player join insert");
check = connection.prepareStatement("SELECT EXISTS(SELECT * FROM player_info_2 WHERE uuid=?) AS `exists`");
check.setString(1, uuid.toString());
checkResult = check.executeQuery();
checkResult.next();
boolean exists = checkResult.getBoolean("exists");
Logger.log(LogLevel.DEBUG, "Exists: " + exists);
if (!exists) {
insert = connection.prepareStatement("INSERT INTO `player_info_2) (uuid, name, xp) VALUES (?, ?, ?)");
insert.setString(1, uuid.toString());
insert.setString(2, pn);
insert.setInt(3, 0);
insert.execute();
}
} catch (SQLException e) {
Ublisk.exception(e, PlayerJoin.class);
} finally {
try {
if (check != null) check.close();
if (checkResult != null) checkResult.close();
if (insert != null) insert.close();
} catch (SQLException e) {
Ublisk.exception(e, PlayerJoin.class);
}
}
});*/
}
use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.
the class RegeneratingBlocks method onBreakBlock.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBreakBlock(BlockBreakEvent event) {
final Player player = event.getPlayer();
final PlayerInventory inv = player.getInventory();
if (inv.getItemInMainHand().getType() == Material.BEETROOT && player.getGameMode() == GameMode.CREATIVE) {
player.sendMessage("Block permanently broken!");
return;
}
final Block block = event.getBlock();
for (Material regeneratingMaterial : REGENERATING_MATERIALS) {
if (block.getType() == regeneratingMaterial) {
if (!Var.BLOCK_REGENERATION_ENABLED) {
player.sendMessage(ChatColor.DARK_GREEN + "Block regeneration is disabled. This block will not turn back into its original state.");
return;
}
Logger.log(LogLevel.INFO, "Regenerating block broken at (" + block.getX() + ", " + block.getY() + ", " + block.getZ() + ") by " + player.getName());
final Material originalMaterial = block.getType();
new URunnable() {
public void run() {
block.setType(originalMaterial);
}
}.runLater(REGENERATE_TIME * 20);
}
}
}
use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.
the class CustomXP method setXP.
public static void setXP(OfflinePlayer player, final int xp) {
Cache.removeCachedObject("xp:" + player.getUniqueId());
new URunnable() {
public void run() {
Connection connection = null;
PreparedStatement statement = null;
try {
connection = Ublisk.getDatabaseConnection(player.getName() + " set xp");
statement = connection.prepareStatement("UPDATE player_info_2 SET xp=? WHERE uuid=?");
statement.setInt(1, xp);
statement.setString(2, player.getUniqueId().toString());
statement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (statement != null)
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}.runAsync();
Cache.addCachedObject("xp:" + player.getUniqueId(), xp, 1000);
}
use of xyz.derkades.ublisk.utils.URunnable in project Ublisk by Derkades.
the class DoubleXP method startDoubleXP.
public static void startDoubleXP(final UPlayer player) {
if (DoubleXP.isActive()) {
Bukkit.broadcastMessage(Message.DOUBLE_XP_ALREADY_ACTIVE.toString());
new URunnable() {
public void run() {
startDoubleXP(player);
}
}.runLater(5 * 60 * 20);
return;
}
Ublisk.broadcastPrefixedMessage("Double XP started thanks to " + player.getName());
DoubleXP.DOUBLE_XP_PROGRESS = 1.0f;
DoubleXP.DOUBLE_XP_SECONDS_LEFT = DoubleXP.DOUBLE_XP_TOTAL_SECONDS;
final BossBar bar = Ublisk.createBossBar("Double XP - " + player.getName(), BarColor.GREEN, BarStyle.SOLID);
Ublisk.showBossBar(bar, DoubleXP.DOUBLE_XP_TOTAL_SECONDS * 20, Ublisk.getOnlinePlayers());
new BukkitRunnable() {
public void run() {
// Every second: remove 0.2 seconds from `DOUBLE_XP_SECONDS_LEFT` and recalculate percentage (0.2 seconds because this is ran 5 times every second).
DoubleXP.DOUBLE_XP_SECONDS_LEFT -= 0.2;
float percent = ((float) DoubleXP.DOUBLE_XP_SECONDS_LEFT) / ((float) DoubleXP.DOUBLE_XP_TOTAL_SECONDS);
DoubleXP.DOUBLE_XP_PROGRESS = percent;
Logger.log(LogLevel.DEBUG, "Seconds left: " + DoubleXP.DOUBLE_XP_SECONDS_LEFT + " | Total seconds: " + DoubleXP.DOUBLE_XP_TOTAL_SECONDS + " | Percentage float: " + DoubleXP.DOUBLE_XP_PROGRESS);
if (DoubleXP.DOUBLE_XP_SECONDS_LEFT == 0) {
this.cancel();
DoubleXP.DOUBLE_XP_PROGRESS = 0.0f;
Ublisk.broadcastPrefixedMessage("Double XP has ended.");
}
// Update bossbar
bar.setProgress(DOUBLE_XP_PROGRESS);
}
}.runTaskTimer(Main.getInstance(), 0L, 4);
}
Aggregations