From 8694296523b96c217d3d83430e7a3c9a5925ff62 Mon Sep 17 00:00:00 2001 From: MrsHerobrine <57451966+mrsherobrine@users.noreply.github.com> Date: Thu, 5 Aug 2021 16:43:44 +0200 Subject: [PATCH] Add files via upload --- .../monkegame/monkeonetap/Listeners.java | 93 ++++++++++++++++ .../online/monkegame/monkeonetap/Main.java | 102 ++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 src/main/java/online/monkegame/monkeonetap/Listeners.java create mode 100644 src/main/java/online/monkegame/monkeonetap/Main.java diff --git a/src/main/java/online/monkegame/monkeonetap/Listeners.java b/src/main/java/online/monkegame/monkeonetap/Listeners.java new file mode 100644 index 0000000..061f418 --- /dev/null +++ b/src/main/java/online/monkegame/monkeonetap/Listeners.java @@ -0,0 +1,93 @@ +package online.monkegame.monkeonetap; + + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextDecoration; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Statistic; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitScheduler; + +import java.util.logging.Logger; + +public class Listeners implements Listener { + + public Main plugin; + public Logger log; + public String tappingItem; + public String tappingItemName; + public long updateRate; + + public Listeners(Main main, Logger logger, String tappingItem, String tappingItemName, long dbUpdate) { + this.plugin = main; + this.log = logger; + this.tappingItem = tappingItem; + this.tappingItemName = tappingItemName; + this.updateRate = dbUpdate; + } + + //event handlers + @EventHandler + public void onJoin(PlayerJoinEvent evt) { + final Player p = evt.getPlayer(); + evt.joinMessage(Component.text(p.getName() + " has joined the battle!")); + PotionEffect speed = new PotionEffect(PotionEffectType.SPEED, (int) updateRate, 3, false, false); + PotionEffect saturation = new PotionEffect(PotionEffectType.SATURATION, (int) updateRate, 0, false, false); + p.addPotionEffect(speed); + p.addPotionEffect(saturation); + BukkitScheduler scheduler = Bukkit.getScheduler(); + scheduler.runTaskLaterAsynchronously(plugin, () -> { + PlayerInventory inv = p.getInventory(); + ItemStack tapper = new ItemStack(Material.valueOf(tappingItem)); + ItemMeta meta = tapper.getItemMeta(); + assert tappingItemName != null; + meta.displayName(Component.text(tappingItemName).decoration(TextDecoration.ITALIC, false)); + meta.addEnchant(Enchantment.DAMAGE_ALL, 1000, true); + tapper.setItemMeta(meta); + inv.setItem(0, tapper); + }, 10L); + } + + @EventHandler + public void onQuit(PlayerQuitEvent qevt) { + final Player p = qevt.getPlayer(); + qevt.quitMessage(Component.text(p.getName() + " took the coward's way out...")); + PlayerInventory inv = p.getInventory(); + inv.clear(); + } + + @EventHandler + public void onDrop(PlayerDropItemEvent dievt) { + dievt.setCancelled(true); + } + + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent revt) { + PotionEffect speed = new PotionEffect(PotionEffectType.SPEED, (int) updateRate, 3, false, false); + PotionEffect saturation = new PotionEffect(PotionEffectType.SATURATION, (int) updateRate, 0, false, false); + revt.getPlayer().addPotionEffect(speed); + revt.getPlayer().addPotionEffect(saturation); + } + + @EventHandler + public void setExp(PlayerDeathEvent devt) { + Player epic = devt.getEntity().getKiller(); + float playerkills = epic.getStatistic(Statistic.PLAYER_KILLS); + epic.setExp(playerkills); + } + +} diff --git a/src/main/java/online/monkegame/monkeonetap/Main.java b/src/main/java/online/monkegame/monkeonetap/Main.java new file mode 100644 index 0000000..80ee9ac --- /dev/null +++ b/src/main/java/online/monkegame/monkeonetap/Main.java @@ -0,0 +1,102 @@ +package online.monkegame.monkeonetap; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.TextColor; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.Statistic; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitScheduler; + +import java.sql.*; +import java.util.UUID; + +/* + * made by monkegame team + * Mrs_Herobrine_ + * contact here: mrsherobrinenaomi@gmail.com + * discord: mrsherobrine (naomi)#6263 + * play.monkegame.online + */ + +public final class Main extends JavaPlugin { + + public TextComponent updateMessage = Component.text("[monkebot] ",TextColor.color(0x4bcc7f)) + .append(Component.text("UPDATING THE DATABASE! EXPECT SOME LAG!")).color(TextColor.color(0xa61111)); + public TextComponent updatedMessage = Component.text("[monkebot] ", TextColor.color(0x4bcc7f)) + .append(Component.text("Database updated!")).color(TextColor.color(0xbaffe6)); + public long updateRate; + public String databaseLocation; + public String databaseTable; + public String tappingItem; + public String tappingItemName; + + @Override + public void onEnable() { + + this.saveDefaultConfig(); + + updateRate = (this.getConfig().getLong("db.dbupdaterate") * 20); + databaseLocation = this.getConfig().getString("db.dblocation"); + databaseTable = this.getConfig().getString("db.dbtable"); + tappingItem = this.getConfig().getString("onetapper.item"); + tappingItemName = (this.getConfig().getString("onetapper.name")); + + if (databaseLocation == null) { + getLogger().info("You haven't linked your database! Please do so!"); + getServer().getPluginManager().disablePlugin(this); + } else if (databaseTable == null) { + getLogger().info("No table found! Have you checked your database?"); + getServer().getPluginManager().disablePlugin(this); + } else { + getServer().getPluginManager().registerEvents(new Listeners(this, getLogger(), tappingItem, tappingItemName, updateRate), this); + main(); + getLogger().info("Database found! Updates will now be made every " + updateRate/20 + " seconds."); + } + } + + public String playerName = ""; + public int playerKills = 0; + public UUID playerUuid; + + public void main() { + String sql = "INSERT INTO " + databaseTable + " (uuid, username, killcount)\n" + + "VALUES ('" + playerUuid + "','" + playerName + "','" + playerKills + "')" + + "ON CONFLICT(uuid) DO UPDATE SET " + + "username=excluded.username, " + + "killcount=excluded.killcount;"; + String url = "jdbc:sqlite:" + databaseLocation; + + BukkitScheduler scheduler = getServer().getScheduler(); + scheduler.scheduleSyncRepeatingTask(this, () -> { + Bukkit.broadcast(updateMessage, "*.*"); + long startTime = System.currentTimeMillis(); + + for (OfflinePlayer player : Bukkit.getServer().getOfflinePlayers()) { + playerKills = player.getStatistic(Statistic.PLAYER_KILLS); + playerName = player.getName(); + playerUuid = player.getUniqueId(); + scheduler.runTaskAsynchronously(this, ()-> { + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + stmt.execute(sql); + } catch (SQLException e) { + getLogger().severe("Encountered an error: " + e.getMessage()); + getLogger().info("Are you sure you configured your database correctly?"); + } + }); + } + + long endTime = System.currentTimeMillis(); + getLogger().info("DB update took " + (endTime - startTime) + " ms"); + Bukkit.broadcast(updatedMessage, "*.*"); + }, 0L, updateRate); + } + + @Override + public void onDisable() { + getLogger().info("database will no longer update periodically"); + } + +} \ No newline at end of file