├── Episode_01 └── Cooldowns │ ├── README │ ├── bin │ ├── com │ │ └── tsccoding │ │ │ └── main │ │ │ ├── EventsClass.class │ │ │ ├── MainCooldown$1.class │ │ │ └── MainCooldown.class │ └── plugin.yml │ └── src │ ├── com │ └── tsccoding │ │ └── main │ │ ├── EventsClass.java │ │ └── MainCooldown.java │ └── plugin.yml ├── Episode_03 └── mysqlTest │ ├── bin │ ├── me │ │ └── tscoding │ │ │ └── mysql │ │ │ └── MysqlMain.class │ └── plugin.yml │ └── src │ ├── me │ └── tscoding │ │ └── mysql │ │ └── MysqlMain.java │ └── plugin.yml ├── Episode_04 └── mysqlTest │ ├── bin │ ├── config.yml │ ├── me │ │ └── tscoding │ │ │ └── mysql │ │ │ ├── MysqlMain.class │ │ │ └── MysqlSetterGetter.class │ └── plugin.yml │ └── src │ ├── config.yml │ ├── me │ └── tscoding │ │ └── mysql │ │ ├── MysqlMain.java │ │ └── MysqlSetterGetter.java │ └── plugin.yml ├── Episode_05 └── RandomLoot │ ├── bin │ ├── config.yml │ ├── me │ │ └── tsccoding │ │ │ └── com │ │ │ └── lootchest │ │ │ └── MainLoot.class │ └── plugin.yml │ └── src │ ├── config.yml │ ├── me │ └── tsccoding │ │ └── com │ │ └── lootchest │ │ └── MainLoot.java │ └── plugin.yml ├── Episode_06 └── CustomEnchants │ ├── bin │ ├── me │ │ └── tsccoding │ │ │ └── enchants │ │ │ ├── CustomEnchantment.class │ │ │ └── MainEnchants.class │ └── plugin.yml │ └── src │ ├── me │ └── tsccoding │ │ └── enchants │ │ ├── CustomEnchantment.java │ │ └── MainEnchants.java │ └── plugin.yml ├── Episode_07 └── PacketTitles │ ├── bin │ ├── config.yml │ ├── me │ │ └── tsccoding │ │ │ └── com │ │ │ └── lootchest │ │ │ └── MainLoot.class │ └── plugin.yml │ └── src │ ├── config.yml │ ├── me │ └── tsccoding │ │ └── com │ │ └── lootchest │ │ └── MainLoot.java │ └── plugin.yml ├── Episode_08 └── JSON_Messages │ ├── bin │ ├── config.yml │ ├── me │ │ └── tsccoding │ │ │ └── com │ │ │ └── lootchest │ │ │ └── MainLoot.class │ └── plugin.yml │ └── src │ ├── config.yml │ ├── me │ └── tsccoding │ │ └── com │ │ └── lootchest │ │ └── MainLoot.java │ └── plugin.yml ├── Episode_09 └── CustomMobs │ ├── bin │ ├── me │ │ └── tsccoding │ │ │ └── custommob │ │ │ ├── CustomEntityRegistry.class │ │ │ ├── CustomMobMain (LAPTOP-O4LCTMNL's conflicted copy 2017-06-12).class │ │ │ ├── CustomMobMain.class │ │ │ └── CustomZombie.class │ └── plugin.yml │ └── src │ ├── me │ └── tsccoding │ │ └── custommob │ │ ├── CustomEntityRegistry.java │ │ ├── CustomMobMain.java │ │ └── CustomZombie.java │ └── plugin.yml ├── Episode_10 ├── TestPlugin │ ├── bin │ │ ├── config.yml │ │ ├── me │ │ │ └── tsccoding │ │ │ │ └── com │ │ │ │ └── lootchest │ │ │ │ └── MainLoot.class │ │ └── plugin.yml │ └── src │ │ ├── config.yml │ │ ├── me │ │ └── tsccoding │ │ │ └── com │ │ │ └── lootchest │ │ │ └── MainLoot.java │ │ └── plugin.yml └── TutorialAPI │ ├── bin │ ├── me │ │ └── tutorial │ │ │ └── api │ │ │ ├── GameManager.class │ │ │ └── TutorialAPI.class │ └── plugin.yml │ └── src │ ├── me │ └── tutorial │ │ └── api │ │ ├── GameManager.java │ │ └── TutorialAPI.java │ └── plugin.yml ├── Episode_11 └── WorldGuardAPI │ ├── FirstIntellij.iml │ └── src │ ├── me │ └── tsccoding │ │ └── tutorial │ │ └── TutorialMain.java │ └── plugin.yml ├── Episode_12 └── ParticleTrails │ ├── FirstIntellij.iml │ └── src │ ├── me │ └── tsccoding │ │ └── tutorial │ │ └── TutorialMain.java │ └── plugin.yml ├── Episode_13 └── PermissionsPlugin │ └── src │ ├── config.yml │ ├── me │ └── tsccoding │ │ └── tutorial │ │ └── TutorialMain.java │ └── plugin.yml ├── Episode_14 └── ArenaManager │ └── src │ ├── me │ └── tsccoding │ │ └── tutorial │ │ ├── ArenaManager.java │ │ ├── ArenaMethods.java │ │ ├── CreateArenaCMD.java │ │ └── TutorialMain.java │ └── plugin.yml ├── Episode_15 └── VaultAPI │ ├── VaultAPI.iml │ └── src │ ├── me │ └── tsc │ │ └── tutorial │ │ └── vault │ │ ├── EconomyCommands.java │ │ └── VaultMain.java │ └── plugin.yml ├── Episode_16 └── src │ ├── me │ └── tsctutorial │ │ └── economy │ │ ├── EconomyCommands.java │ │ ├── EconomyImplementer.java │ │ ├── EconomyMain.java │ │ └── VaultHook.java │ └── plugin.yml ├── Episode_17 └── FakePlayers │ ├── FakePlayers.iml │ └── src │ ├── me │ └── tsctutorial │ │ └── fakeplayers │ │ ├── FPCommand.java │ │ ├── FakePlayersMain.java │ │ └── NPCManager.java │ └── plugin.yml ├── Episode_18 └── JsonReader │ ├── JsonReader.iml │ └── src │ ├── me │ └── tsctutorial │ │ └── jsonreader │ │ └── JsonReaderMain.java │ └── plugin.yml ├── Episode_19 └── FakePlayerSkins │ ├── FakePlayers.iml │ └── src │ ├── config.yml │ ├── me │ └── tsctutorial │ │ └── fakeplayers │ │ ├── FPCommand.java │ │ ├── FakePlayersMain.java │ │ └── NPCManager.java │ └── plugin.yml ├── Episode_20 └── maventest │ ├── maventest.iml │ ├── pom.xml │ ├── src │ └── main │ │ ├── java │ │ └── me │ │ │ └── tsccoding │ │ │ └── maven │ │ │ └── MavenMain.java │ │ └── resources │ │ └── plugin.yml │ └── target │ └── classes │ ├── me │ └── tsccoding │ │ └── maven │ │ └── MavenMain.class │ └── plugin.yml ├── Episode_21 └── CommandManager │ ├── CommandManager.iml │ └── src │ ├── me │ └── tsctutorial │ │ └── command │ │ ├── CommandMain.java │ │ └── commands │ │ ├── CommandManager.java │ │ ├── HelpCommand.java │ │ ├── InfoCommand.java │ │ └── SubCommand.java │ └── plugin.yml ├── Episode_22 └── PacketListener │ ├── PacketListener.iml │ └── src │ ├── me │ └── tsccoding │ │ └── packets │ │ └── PacketMain.java │ └── plugin.yml ├── Episode_23 └── TutorialMetrics │ ├── SourceTutorialMetrics.iml │ └── src │ ├── me │ └── tsctutorial │ │ └── metrics │ │ ├── Metrics.java │ │ └── SourceTutorialMetrics.java │ └── plugin.yml ├── Episode_24 └── TabList │ ├── PreTutorial.iml │ └── src │ ├── me │ └── tsccoding │ │ └── pretutorial │ │ ├── PreTutorial.java │ │ └── TestInterface.java │ └── plugin.yml ├── Episode_25 └── Animated_Scoreboard(No Flicker) │ └── src │ ├── me │ └── tsccoding │ │ └── pretutorial │ │ └── PreTutorial.java │ └── plugin.yml ├── Episode_26 └── Load_Schematics │ └── schematic.java ├── Episode_27 └── Player_Leveling │ ├── PreTutorial.iml │ ├── PreTutorial1.iml │ └── src │ ├── config.yml │ ├── me │ └── tsccoding │ │ └── pretutorial │ │ ├── PlayerLevelManager.java │ │ └── PreTutorial.java │ └── plugin.yml ├── Episode_28 └── Updater │ └── src │ ├── config.yml │ ├── me │ └── tsccoding │ │ └── pretutorial │ │ └── Updater.java │ └── plugin.yml ├── Episode_29 └── GoogleAuth │ ├── GoogleAuth.iml │ ├── pom.xml │ ├── src │ └── main │ │ ├── java │ │ └── me │ │ │ └── tutorial │ │ │ └── google │ │ │ └── GoogleMain.java │ │ └── resources │ │ ├── config.yml │ │ └── plugin.yml │ └── target │ └── classes │ ├── config.yml │ ├── me │ └── tutorial │ │ └── google │ │ └── GoogleMain.class │ └── plugin.yml ├── Episode_30 └── Sorry.exe ├── Episode_31 └── KitUpgrades │ ├── Commands.java │ ├── KitUpgrader.java │ ├── Kits.java │ └── PreTutorial.java ├── Episode_32 └── MongoDB │ ├── MongoDB.iml │ ├── pom.xml │ ├── src │ └── main │ │ ├── java │ │ └── me │ │ │ └── tsccoding │ │ │ └── mongodb │ │ │ ├── MongoMain.java │ │ │ └── PlayerData.java │ │ └── resources │ │ └── plugin.yml │ └── target │ └── classes │ ├── me │ └── tsccoding │ │ └── mongodb │ │ ├── MongoMain.class │ │ └── PlayerData.class │ └── plugin.yml ├── Episode_33 └── Exploding_Pigman_Summoner │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C01.java │ │ └── Main.java │ └── plugin.yml ├── Episode_34 └── Boss_Skeleton │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C02.java │ │ └── Main.java │ └── plugin.yml ├── Episode_35 └── How_To_Use_ProtocolLib │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C03.java │ │ └── Main.java │ └── plugin.yml ├── Episode_36 └── How_To_Use_ProtocolLib_2 │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C04.java │ │ └── Main.java │ └── plugin.yml ├── Episode_37 └── How_to_integrate_discord │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C05.java │ │ └── Main.java │ └── plugin.yml ├── Episode_38 └── Discord_Minecraft_Verification_Sytem │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C06.java │ │ └── Main.java │ ├── data.yml │ └── plugin.yml ├── Episode_39 └── Minecraft_Discord_Role_Sync │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C06.java │ │ ├── C07.java │ │ └── Main.java │ ├── config.yml │ ├── data.yml │ └── plugin.yml ├── Episode_40 └── Using_LibDisguise │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C08.java │ │ └── Main.java │ ├── config.yml │ ├── data.yml │ └── plugin.yml ├── Episode_41 └── PlaceholderAPI │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C09.java │ │ └── Main.java │ ├── config.yml │ ├── data.yml │ └── plugin.yml ├── Episode_42 └── Making_Lucky_Blocks │ └── src │ ├── com │ └── alonsoaliaga │ │ └── tscplugin │ │ ├── C10.java │ │ └── Main.java │ ├── config.yml │ ├── data.yml │ └── plugin.yml └── README.md /Episode_01/Cooldowns/README: -------------------------------------------------------------------------------- 1 | This is the folder for episode 1 & 2 2 | -------------------------------------------------------------------------------- /Episode_01/Cooldowns/bin/com/tsccoding/main/EventsClass.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_01/Cooldowns/bin/com/tsccoding/main/EventsClass.class -------------------------------------------------------------------------------- /Episode_01/Cooldowns/bin/com/tsccoding/main/MainCooldown$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_01/Cooldowns/bin/com/tsccoding/main/MainCooldown$1.class -------------------------------------------------------------------------------- /Episode_01/Cooldowns/bin/com/tsccoding/main/MainCooldown.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_01/Cooldowns/bin/com/tsccoding/main/MainCooldown.class -------------------------------------------------------------------------------- /Episode_01/Cooldowns/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Cooldowns 2 | author: dabuseck 3 | version: 1.0 4 | main: com.tsccoding.main.MainCooldown 5 | description: Cooldowns plugin -------------------------------------------------------------------------------- /Episode_01/Cooldowns/src/com/tsccoding/main/EventsClass.java: -------------------------------------------------------------------------------- 1 | package com.tsccoding.main; 2 | 3 | import java.util.UUID; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.block.Block; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.block.BlockPlaceEvent; 11 | import org.bukkit.event.player.PlayerJoinEvent; 12 | import org.bukkit.event.player.PlayerQuitEvent; 13 | 14 | import net.md_5.bungee.api.ChatColor; 15 | 16 | public class EventsClass implements Listener { 17 | 18 | private MainCooldown plugin = MainCooldown.getPlugin(MainCooldown.class); 19 | 20 | @EventHandler 21 | public void onjoin(PlayerJoinEvent event) { 22 | Player player = event.getPlayer(); 23 | UUID uuid = player.getUniqueId(); 24 | int cdtime = plugin.getConfig().getInt(uuid + ".Cooldown_Left"); 25 | 26 | if (cdtime <= 0) { 27 | return; 28 | } else { 29 | plugin.cdtime.put(uuid, cdtime); 30 | } 31 | } 32 | 33 | @EventHandler 34 | public void onquit(PlayerQuitEvent event) { 35 | Player player = event.getPlayer(); 36 | UUID uuid = player.getUniqueId(); 37 | 38 | plugin.getConfig().set(uuid + ".Cooldown_Left", plugin.cdtime.get(uuid)); 39 | plugin.saveConfig(); 40 | plugin.cdtime.remove(uuid); 41 | } 42 | 43 | @EventHandler 44 | public void blockplace(BlockPlaceEvent event) { 45 | Block block = event.getBlock(); 46 | Player player = event.getPlayer(); 47 | UUID uuid = player.getUniqueId(); 48 | 49 | if (!plugin.cdtime.containsKey(uuid)) { 50 | if (block.getType().equals(Material.DIAMOND_BLOCK)) { 51 | plugin.cdtime.put(uuid, plugin.mastercd); 52 | player.sendMessage(ChatColor.GREEN + "You have been added to the cooldown!"); 53 | } 54 | } else { 55 | event.setCancelled(true); 56 | player.sendMessage(ChatColor.RED + "You still have " + ChatColor.YELLOW + plugin.cdtime.get(uuid) 57 | + " seconds " + ChatColor.RED + "left till you can place Diamond Blocks!"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Episode_01/Cooldowns/src/com/tsccoding/main/MainCooldown.java: -------------------------------------------------------------------------------- 1 | package com.tsccoding.main; 2 | 3 | import java.util.HashMap; 4 | import java.util.UUID; 5 | 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | import org.bukkit.scheduler.BukkitRunnable; 9 | 10 | public class MainCooldown extends JavaPlugin implements Listener { 11 | 12 | public HashMap cdtime = new HashMap(); 13 | public int mastercd = 10; 14 | 15 | public void onEnable() { 16 | getServer().getPluginManager().registerEvents(new EventsClass(), this); 17 | loadConfig(); 18 | runnablerunner(); 19 | 20 | } 21 | 22 | public void loadConfig() { 23 | getConfig().options().copyDefaults(true); 24 | saveConfig(); 25 | } 26 | 27 | public void runnablerunner() { 28 | new BukkitRunnable() { 29 | 30 | @Override 31 | public void run() { 32 | 33 | if (cdtime.isEmpty()) { 34 | return; 35 | } 36 | 37 | for (UUID uuid : cdtime.keySet()) { 38 | int timeleft = cdtime.get(uuid); 39 | 40 | if (timeleft <= 0) { 41 | cdtime.remove(uuid); 42 | }else{ 43 | cdtime.put(uuid, timeleft - 1); 44 | } 45 | } 46 | 47 | } 48 | 49 | }.runTaskTimer(this, 0, 20); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Episode_01/Cooldowns/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Cooldowns 2 | author: dabuseck 3 | version: 1.0 4 | main: com.tsccoding.main.MainCooldown 5 | description: Cooldowns plugin -------------------------------------------------------------------------------- /Episode_03/mysqlTest/bin/me/tscoding/mysql/MysqlMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_03/mysqlTest/bin/me/tscoding/mysql/MysqlMain.class -------------------------------------------------------------------------------- /Episode_03/mysqlTest/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MYSQLTest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tscoding.mysql.MysqlMain 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_03/mysqlTest/src/me/tscoding/mysql/MysqlMain.java: -------------------------------------------------------------------------------- 1 | package me.tscoding.mysql; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.ChatColor; 9 | import org.bukkit.plugin.java.JavaPlugin; 10 | 11 | public class MysqlMain extends JavaPlugin { 12 | private Connection connection; 13 | public String host, database, username, password; 14 | public int port; 15 | 16 | public void onEnable() { 17 | mysqlSetup(); 18 | } 19 | 20 | public void mysqlSetup(){ 21 | host = "localhost"; 22 | port = 3306; 23 | database = "tutorial"; 24 | username = "root"; 25 | password = "password"; 26 | 27 | try{ 28 | 29 | synchronized (this){ 30 | if(getConnection() != null && !getConnection().isClosed()){ 31 | return; 32 | } 33 | 34 | Class.forName("com.mysql.jdbc.Driver"); 35 | setConnection( DriverManager.getConnection("jdbc:mysql://" + this.host + ":" 36 | + this.port + "/" + this.database, this.username, this.password)); 37 | 38 | Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MYSQL CONNECTED"); 39 | } 40 | }catch(SQLException e){ 41 | e.printStackTrace(); 42 | }catch(ClassNotFoundException e){ 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | public Connection getConnection() { 48 | return connection; 49 | } 50 | 51 | public void setConnection(Connection connection) { 52 | this.connection = connection; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Episode_03/mysqlTest/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MYSQLTest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tscoding.mysql.MysqlMain 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_04/mysqlTest/bin/config.yml: -------------------------------------------------------------------------------- 1 | host: 'localhost' 2 | port: 3306 3 | database: 'tutorial' 4 | username: 'root' 5 | password: 'password' 6 | table: 'player_data' -------------------------------------------------------------------------------- /Episode_04/mysqlTest/bin/me/tscoding/mysql/MysqlMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_04/mysqlTest/bin/me/tscoding/mysql/MysqlMain.class -------------------------------------------------------------------------------- /Episode_04/mysqlTest/bin/me/tscoding/mysql/MysqlSetterGetter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_04/mysqlTest/bin/me/tscoding/mysql/MysqlSetterGetter.class -------------------------------------------------------------------------------- /Episode_04/mysqlTest/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MYSQLTest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tscoding.mysql.MysqlMain 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_04/mysqlTest/src/config.yml: -------------------------------------------------------------------------------- 1 | host: 'localhost' 2 | port: 3306 3 | database: 'tutorial' 4 | username: 'root' 5 | password: 'password' 6 | table: 'player_data' -------------------------------------------------------------------------------- /Episode_04/mysqlTest/src/me/tscoding/mysql/MysqlMain.java: -------------------------------------------------------------------------------- 1 | package me.tscoding.mysql; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.ChatColor; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.plugin.java.JavaPlugin; 11 | 12 | public class MysqlMain extends JavaPlugin implements Listener { 13 | private Connection connection; 14 | public String host, database, username, password, table; 15 | public int port; 16 | 17 | public void onEnable() { 18 | loadConfig(); 19 | mysqlSetup(); 20 | 21 | this.getServer().getPluginManager().registerEvents(new MysqlSetterGetter(), this); 22 | } 23 | 24 | public void loadConfig(){ 25 | getConfig().options().copyDefaults(true); 26 | saveConfig(); 27 | } 28 | 29 | public void mysqlSetup() { 30 | host = this.getConfig().getString("host"); 31 | port = this.getConfig().getInt("port"); 32 | database = this.getConfig().getString("database"); 33 | username = this.getConfig().getString("username"); 34 | password = this.getConfig().getString("password"); 35 | table = this.getConfig().getString("table"); 36 | 37 | try { 38 | 39 | synchronized (this) { 40 | if (getConnection() != null && !getConnection().isClosed()) { 41 | return; 42 | } 43 | 44 | Class.forName("com.mysql.jdbc.Driver"); 45 | setConnection( 46 | DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, 47 | this.username, this.password)); 48 | 49 | Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MYSQL CONNECTED"); 50 | } 51 | } catch (SQLException e) { 52 | e.printStackTrace(); 53 | } catch (ClassNotFoundException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | 58 | public Connection getConnection() { 59 | return connection; 60 | } 61 | 62 | public void setConnection(Connection connection) { 63 | this.connection = connection; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Episode_04/mysqlTest/src/me/tscoding/mysql/MysqlSetterGetter.java: -------------------------------------------------------------------------------- 1 | package me.tscoding.mysql; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.UUID; 7 | 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.player.PlayerInteractEvent; 12 | import org.bukkit.event.player.PlayerJoinEvent; 13 | 14 | import net.md_5.bungee.api.ChatColor; 15 | 16 | public class MysqlSetterGetter implements Listener { 17 | 18 | MysqlMain plugin = MysqlMain.getPlugin(MysqlMain.class); 19 | 20 | @EventHandler 21 | public void onJoin(PlayerJoinEvent event) { 22 | Player player = event.getPlayer(); 23 | createPlayer(player.getUniqueId(), player); 24 | } 25 | 26 | @EventHandler 27 | public void hit(PlayerInteractEvent event) { 28 | updateCoins(event.getPlayer().getUniqueId()); 29 | getCoins(event.getPlayer().getUniqueId()); 30 | } 31 | 32 | public boolean playerExists(UUID uuid) { 33 | try { 34 | PreparedStatement statement = plugin.getConnection() 35 | .prepareStatement("SELECT * FROM " + plugin.table + " WHERE UUID=?"); 36 | statement.setString(1, uuid.toString()); 37 | 38 | ResultSet results = statement.executeQuery(); 39 | if (results.next()) { 40 | plugin.getServer().broadcastMessage(ChatColor.YELLOW + "Player Found"); 41 | return true; 42 | } 43 | plugin.getServer().broadcastMessage(ChatColor.RED + "Player NOT Found"); 44 | 45 | } catch (SQLException e) { 46 | e.printStackTrace(); 47 | } 48 | return false; 49 | } 50 | 51 | public void createPlayer(final UUID uuid, Player player) { 52 | try { 53 | PreparedStatement statement = plugin.getConnection() 54 | .prepareStatement("SELECT * FROM " + plugin.table + " WHERE UUID=?"); 55 | statement.setString(1, uuid.toString()); 56 | ResultSet results = statement.executeQuery(); 57 | results.next(); 58 | System.out.print(1); 59 | if (playerExists(uuid) != true) { 60 | PreparedStatement insert = plugin.getConnection() 61 | .prepareStatement("INSERT INTO " + plugin.table + " (UUID,NAME,COINS) VALUES (?,?,?)"); 62 | insert.setString(1, uuid.toString()); 63 | insert.setString(2, player.getName()); 64 | insert.setInt(3, 500); 65 | insert.executeUpdate(); 66 | 67 | plugin.getServer().broadcastMessage(ChatColor.GREEN + "Player Inserted"); 68 | } 69 | } catch (SQLException e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | 74 | public void updateCoins(UUID uuid) { 75 | try { 76 | PreparedStatement statement = plugin.getConnection() 77 | .prepareStatement("UPDATE " + plugin.table + " SET COINS=? WHERE UUID=?"); 78 | statement.setInt(1, 1000); 79 | statement.setString(2, uuid.toString()); 80 | statement.executeUpdate(); 81 | } catch (SQLException e) { 82 | e.printStackTrace(); 83 | } 84 | 85 | } 86 | 87 | public void getCoins(UUID uuid) { 88 | try { 89 | PreparedStatement statement = plugin.getConnection() 90 | .prepareStatement("SELECT * FROM " + plugin.table + " WHERE UUID=?"); 91 | statement.setString(1, uuid.toString()); 92 | ResultSet results = statement.executeQuery(); 93 | results.next(); 94 | 95 | System.out.print(results.getInt("COINS")); 96 | } catch (SQLException e) { 97 | e.printStackTrace(); 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /Episode_04/mysqlTest/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MYSQLTest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tscoding.mysql.MysqlMain 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_05/RandomLoot/bin/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_05/RandomLoot/bin/me/tsccoding/com/lootchest/MainLoot.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_05/RandomLoot/bin/me/tsccoding/com/lootchest/MainLoot.class -------------------------------------------------------------------------------- /Episode_05/RandomLoot/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_05/RandomLoot/src/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_05/RandomLoot/src/me/tsccoding/com/lootchest/MainLoot.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.com.lootchest; 2 | 3 | import java.util.List; 4 | import java.util.Random; 5 | 6 | import org.bukkit.Material; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.player.PlayerJoinEvent; 11 | import org.bukkit.inventory.ItemStack; 12 | import org.bukkit.plugin.java.JavaPlugin; 13 | 14 | public class MainLoot extends JavaPlugin implements Listener { 15 | public void onEnable(){ 16 | loadConfig(); 17 | this.getServer().getPluginManager().registerEvents(this, this); 18 | } 19 | 20 | private void loadConfig() { 21 | getConfig().options().copyDefaults(true); 22 | saveConfig(); 23 | } 24 | 25 | @EventHandler 26 | public void onJoin(PlayerJoinEvent event){ 27 | Player player = event.getPlayer(); 28 | setupLoot(player); 29 | } 30 | 31 | private void setupLoot(Player player) { 32 | List configItems = this.getConfig().getStringList("Items"); 33 | 34 | int index = new Random().nextInt(configItems.size()); 35 | String items = configItems.get(index); 36 | 37 | ItemStack newItem = new ItemStack(Material.getMaterial(items.toUpperCase())); 38 | 39 | player.getInventory().addItem(newItem); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Episode_05/RandomLoot/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_06/CustomEnchants/bin/me/tsccoding/enchants/CustomEnchantment.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_06/CustomEnchants/bin/me/tsccoding/enchants/CustomEnchantment.class -------------------------------------------------------------------------------- /Episode_06/CustomEnchants/bin/me/tsccoding/enchants/MainEnchants.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_06/CustomEnchants/bin/me/tsccoding/enchants/MainEnchants.class -------------------------------------------------------------------------------- /Episode_06/CustomEnchants/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: CustomEnchants 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.enchants.MainEnchants 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_06/CustomEnchants/src/me/tsccoding/enchants/CustomEnchantment.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.enchants; 2 | 3 | import org.bukkit.enchantments.Enchantment; 4 | import org.bukkit.enchantments.EnchantmentTarget; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 9 | import org.bukkit.inventory.ItemStack; 10 | 11 | public class CustomEnchantment extends Enchantment implements Listener { 12 | 13 | public CustomEnchantment(int id) { 14 | super(id); 15 | } 16 | 17 | @EventHandler 18 | public void onHit(EntityDamageByEntityEvent event) { 19 | if (event.getDamager() instanceof Player) { 20 | Player player = (Player) event.getDamager(); 21 | 22 | ItemStack mainhand = player.getInventory().getItemInMainHand(); 23 | 24 | if (mainhand.containsEnchantment(this)) { 25 | player.getWorld().createExplosion(event.getEntity().getLocation(), 1, false); 26 | } 27 | } 28 | } 29 | 30 | @Override 31 | public int getId() { 32 | return 101; 33 | } 34 | 35 | @Override 36 | public boolean canEnchantItem(ItemStack arg0) { 37 | return true; 38 | } 39 | 40 | @Override 41 | public boolean conflictsWith(Enchantment arg0) { 42 | return false; 43 | } 44 | 45 | @Override 46 | public EnchantmentTarget getItemTarget() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public int getMaxLevel() { 52 | return 2; 53 | } 54 | 55 | @Override 56 | public String getName() { 57 | return "Explosive Touch"; 58 | } 59 | 60 | @Override 61 | public int getStartLevel() { 62 | return 1; 63 | } 64 | 65 | @Override 66 | public boolean isCursed() { 67 | return false; 68 | } 69 | 70 | @Override 71 | public boolean isTreasure() { 72 | return false; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Episode_06/CustomEnchants/src/me/tsccoding/enchants/MainEnchants.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.enchants; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | 7 | import org.bukkit.Material; 8 | import org.bukkit.enchantments.Enchantment; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.player.PlayerJoinEvent; 13 | import org.bukkit.inventory.ItemStack; 14 | import org.bukkit.inventory.meta.ItemMeta; 15 | import org.bukkit.plugin.java.JavaPlugin; 16 | 17 | import net.md_5.bungee.api.ChatColor; 18 | 19 | public class MainEnchants extends JavaPlugin implements Listener { 20 | 21 | public CustomEnchantment ench = new CustomEnchantment(101); 22 | 23 | public void onEnable() { 24 | LoadEnchantments(); 25 | this.getServer().getPluginManager().registerEvents(this, this); 26 | this.getServer().getPluginManager().registerEvents(ench, this); 27 | } 28 | 29 | @EventHandler 30 | public void onJoin(PlayerJoinEvent event) { 31 | Player player = event.getPlayer(); 32 | 33 | ItemStack item = new ItemStack(Material.DIAMOND_AXE); 34 | ItemMeta meta = item.getItemMeta(); 35 | ArrayList lore = new ArrayList(); 36 | lore.add(ChatColor.GRAY + ench.getName() + " I"); 37 | meta.setDisplayName(ChatColor.GOLD + "Explosive Axe"); 38 | meta.setLore(lore); 39 | item.setItemMeta(meta); 40 | item.addUnsafeEnchantment(ench, 1); 41 | 42 | player.getInventory().addItem(item); 43 | } 44 | 45 | @SuppressWarnings("unchecked") 46 | public void onDisable() { 47 | try { 48 | Field byIdField = Enchantment.class.getDeclaredField("byId"); 49 | Field byNameField = Enchantment.class.getDeclaredField("byName"); 50 | 51 | byIdField.setAccessible(true); 52 | byNameField.setAccessible(true); 53 | 54 | HashMap byId = (HashMap) byIdField.get(null); 55 | HashMap byName = (HashMap) byNameField.get(null); 56 | 57 | if (byId.containsKey(ench.getId())) { 58 | byId.remove(ench.getId()); 59 | } 60 | 61 | if (byName.containsKey(ench.getName())) { 62 | byName.remove(ench.getName()); 63 | } 64 | } catch (Exception ignored) { 65 | } 66 | } 67 | 68 | private void LoadEnchantments() { 69 | try { 70 | try { 71 | Field f = Enchantment.class.getDeclaredField("acceptingNew"); 72 | f.setAccessible(true); 73 | f.set(null, true); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | try { 79 | Enchantment.registerEnchantment(ench); 80 | } catch (IllegalArgumentException e) { 81 | e.printStackTrace(); 82 | } 83 | } catch (Exception e) { 84 | e.printStackTrace(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Episode_06/CustomEnchants/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: CustomEnchants 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.enchants.MainEnchants 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_07/PacketTitles/bin/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_07/PacketTitles/bin/me/tsccoding/com/lootchest/MainLoot.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_07/PacketTitles/bin/me/tsccoding/com/lootchest/MainLoot.class -------------------------------------------------------------------------------- /Episode_07/PacketTitles/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_07/PacketTitles/src/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_07/PacketTitles/src/me/tsccoding/com/lootchest/MainLoot.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_07/PacketTitles/src/me/tsccoding/com/lootchest/MainLoot.java -------------------------------------------------------------------------------- /Episode_07/PacketTitles/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_08/JSON_Messages/bin/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_08/JSON_Messages/bin/me/tsccoding/com/lootchest/MainLoot.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_08/JSON_Messages/bin/me/tsccoding/com/lootchest/MainLoot.class -------------------------------------------------------------------------------- /Episode_08/JSON_Messages/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_08/JSON_Messages/src/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_08/JSON_Messages/src/me/tsccoding/com/lootchest/MainLoot.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_08/JSON_Messages/src/me/tsccoding/com/lootchest/MainLoot.java -------------------------------------------------------------------------------- /Episode_08/JSON_Messages/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomEntityRegistry.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomEntityRegistry.class -------------------------------------------------------------------------------- /Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomMobMain (LAPTOP-O4LCTMNL's conflicted copy 2017-06-12).class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomMobMain (LAPTOP-O4LCTMNL's conflicted copy 2017-06-12).class -------------------------------------------------------------------------------- /Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomMobMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomMobMain.class -------------------------------------------------------------------------------- /Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomZombie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_09/CustomMobs/bin/me/tsccoding/custommob/CustomZombie.class -------------------------------------------------------------------------------- /Episode_09/CustomMobs/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: CustomMob 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.custommob.CustomMobMain 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_09/CustomMobs/src/me/tsccoding/custommob/CustomEntityRegistry.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.custommob; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Modifier; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import com.google.common.collect.BiMap; 9 | import com.google.common.collect.HashBiMap; 10 | 11 | import net.minecraft.server.v1_11_R1.Entity; 12 | import net.minecraft.server.v1_11_R1.EntityTypes; 13 | import net.minecraft.server.v1_11_R1.MinecraftKey; 14 | import net.minecraft.server.v1_11_R1.RegistryMaterials; 15 | 16 | @SuppressWarnings("rawtypes") 17 | public class CustomEntityRegistry extends RegistryMaterials { 18 | 19 | private static CustomEntityRegistry instance = null; 20 | 21 | private final BiMap> customEntities = HashBiMap.create(); 22 | private final BiMap, MinecraftKey> customEntityClasses = this.customEntities.inverse(); 23 | private final Map, Integer> customEntityIds = new HashMap<>(); 24 | 25 | private final RegistryMaterials wrapped; 26 | 27 | private CustomEntityRegistry(RegistryMaterials original) { 28 | this.wrapped = original; 29 | } 30 | 31 | public static CustomEntityRegistry getInstance() { 32 | if (instance != null) { 33 | return instance; 34 | } 35 | 36 | instance = new CustomEntityRegistry(EntityTypes.b); 37 | 38 | try { 39 | //TODO: Update name on version change (RegistryMaterials) 40 | Field registryMaterialsField = EntityTypes.class.getDeclaredField("b"); 41 | registryMaterialsField.setAccessible(true); 42 | 43 | Field modifiersField = Field.class.getDeclaredField("modifiers"); 44 | modifiersField.setAccessible(true); 45 | modifiersField.setInt(registryMaterialsField, registryMaterialsField.getModifiers() & ~Modifier.FINAL); 46 | 47 | registryMaterialsField.set(null, instance); 48 | } catch (Exception e) { 49 | instance = null; 50 | 51 | throw new RuntimeException("Unable to override the old entity RegistryMaterials", e); 52 | } 53 | 54 | return instance; 55 | } 56 | 57 | public static void registerCustomEntity(int entityId, String entityName, Class entityClass) { 58 | getInstance().putCustomEntity(entityId, entityName, entityClass); 59 | } 60 | 61 | public void putCustomEntity(int entityId, String entityName, Class entityClass) { 62 | MinecraftKey minecraftKey = new MinecraftKey(entityName); 63 | 64 | this.customEntities.put(minecraftKey, entityClass); 65 | this.customEntityIds.put(entityClass, entityId); 66 | } 67 | 68 | @SuppressWarnings("unchecked") 69 | @Override 70 | public Class get(Object key) { 71 | if (this.customEntities.containsKey(key)) { 72 | return this.customEntities.get(key); 73 | } 74 | 75 | return (Class) wrapped.get(key); 76 | } 77 | 78 | @SuppressWarnings("unchecked") 79 | @Override 80 | public int a(Object key) { //TODO: Update name on version change (getId) 81 | if (this.customEntityIds.containsKey(key)) { 82 | return this.customEntityIds.get(key); 83 | } 84 | 85 | return this.wrapped.a(key); 86 | } 87 | 88 | @SuppressWarnings("unchecked") 89 | @Override 90 | public MinecraftKey b(Object value) { //TODO: Update name on version change (getKey) 91 | if (this.customEntityClasses.containsKey(value)) { 92 | return this.customEntityClasses.get(value); 93 | } 94 | 95 | return (MinecraftKey) wrapped.b(value); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Episode_09/CustomMobs/src/me/tsccoding/custommob/CustomMobMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.custommob; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.block.Action; 9 | import org.bukkit.event.player.PlayerInteractEvent; 10 | import org.bukkit.plugin.java.JavaPlugin; 11 | 12 | import net.minecraft.server.v1_11_R1.World; 13 | 14 | public class CustomMobMain extends JavaPlugin implements Listener { 15 | 16 | public void onEnable() { 17 | this.getServer().getPluginManager().registerEvents(this, this); 18 | CustomEntityRegistry.registerCustomEntity(54, "Zombie", CustomZombie.class); 19 | } 20 | 21 | @EventHandler 22 | public void hit(PlayerInteractEvent event) { 23 | if (event.getAction().equals(Action.LEFT_CLICK_AIR)) { 24 | Player player = event.getPlayer(); 25 | Location loc = player.getLocation(); 26 | 27 | World nmsworld = ((CraftWorld) loc.getWorld()).getHandle(); 28 | 29 | CustomZombie zombie = new CustomZombie(nmsworld); 30 | 31 | zombie.setPosition(loc.getX(), loc.getY(), loc.getZ()); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Episode_09/CustomMobs/src/me/tsccoding/custommob/CustomZombie.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.custommob; 2 | 3 | import org.bukkit.entity.Zombie; 4 | 5 | import net.md_5.bungee.api.ChatColor; 6 | import net.minecraft.server.v1_11_R1.EntityChicken; 7 | import net.minecraft.server.v1_11_R1.EntityPig; 8 | import net.minecraft.server.v1_11_R1.EntityZombie; 9 | import net.minecraft.server.v1_11_R1.PathfinderGoalNearestAttackableTarget; 10 | import net.minecraft.server.v1_11_R1.World; 11 | 12 | public class CustomZombie extends EntityZombie { 13 | 14 | @SuppressWarnings("deprecation") 15 | public CustomZombie(World world) { 16 | super(world); 17 | 18 | Zombie craftZombie = (Zombie) this.getBukkitEntity(); 19 | 20 | this.setBaby(true); 21 | 22 | craftZombie.setMaxHealth(50); 23 | 24 | this.setHealth(50); 25 | this.setCustomName(ChatColor.RED + "Zombie :D"); 26 | this.setCustomNameVisible(true); 27 | 28 | this.targetSelector.a(0, new PathfinderGoalNearestAttackableTarget(this, EntityPig.class, true)); 29 | this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityChicken.class, true)); 30 | 31 | this.getWorld().addEntity(this); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Episode_09/CustomMobs/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: CustomMob 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.custommob.CustomMobMain 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_10/TestPlugin/bin/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_10/TestPlugin/bin/me/tsccoding/com/lootchest/MainLoot.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_10/TestPlugin/bin/me/tsccoding/com/lootchest/MainLoot.class -------------------------------------------------------------------------------- /Episode_10/TestPlugin/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_10/TestPlugin/src/config.yml: -------------------------------------------------------------------------------- 1 | Items: 2 | - Diamond 3 | - Stone 4 | - gravel 5 | - gold_ingot 6 | - iron_ingot -------------------------------------------------------------------------------- /Episode_10/TestPlugin/src/me/tsccoding/com/lootchest/MainLoot.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.com.lootchest; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerJoinEvent; 8 | import org.bukkit.plugin.java.JavaPlugin; 9 | 10 | import me.tutorial.api.TutorialAPI; 11 | 12 | public class MainLoot extends JavaPlugin implements Listener { 13 | 14 | private TutorialAPI api = (TutorialAPI) Bukkit.getServer().getPluginManager().getPlugin("TutorialAPI"); 15 | 16 | public void onEnable(){ 17 | loadConfig(); 18 | this.getServer().getPluginManager().registerEvents(this, this); 19 | } 20 | 21 | private void loadConfig() { 22 | getConfig().options().copyDefaults(true); 23 | saveConfig(); 24 | } 25 | 26 | @EventHandler 27 | public void onJoin(PlayerJoinEvent event){ 28 | Player player = event.getPlayer(); 29 | api.gameManager.gamePlayerJoin(player); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Episode_10/TestPlugin/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: LootChest 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.com.lootchest.MainLoot 5 | description: YouTube Tut -------------------------------------------------------------------------------- /Episode_10/TutorialAPI/bin/me/tutorial/api/GameManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_10/TutorialAPI/bin/me/tutorial/api/GameManager.class -------------------------------------------------------------------------------- /Episode_10/TutorialAPI/bin/me/tutorial/api/TutorialAPI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_10/TutorialAPI/bin/me/tutorial/api/TutorialAPI.class -------------------------------------------------------------------------------- /Episode_10/TutorialAPI/bin/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TutorialAPI 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tutorial.api.TutorialAPI 5 | description: YouTube Tut API -------------------------------------------------------------------------------- /Episode_10/TutorialAPI/src/me/tutorial/api/GameManager.java: -------------------------------------------------------------------------------- 1 | package me.tutorial.api; 2 | 3 | import org.bukkit.ChatColor; 4 | import org.bukkit.Location; 5 | import org.bukkit.entity.Player; 6 | 7 | 8 | public class GameManager { 9 | 10 | public void gameStart(Player player, int i, Location loc){ 11 | } 12 | 13 | public void gameStop(Player player, int i, Location loc){ 14 | } 15 | 16 | public void gamePlayerLeave(Player player){ 17 | } 18 | 19 | public void gamePlayerJoin(Player player){ 20 | player.sendMessage(ChatColor.YELLOW + "Hey welcome to the server!"); 21 | } 22 | } -------------------------------------------------------------------------------- /Episode_10/TutorialAPI/src/me/tutorial/api/TutorialAPI.java: -------------------------------------------------------------------------------- 1 | package me.tutorial.api; 2 | 3 | import org.bukkit.event.Listener; 4 | import org.bukkit.plugin.java.JavaPlugin; 5 | 6 | public class TutorialAPI extends JavaPlugin implements Listener{ 7 | 8 | public GameManager gameManager; 9 | 10 | public void onEnable(){ 11 | gameManager = new GameManager(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Episode_10/TutorialAPI/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TutorialAPI 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tutorial.api.TutorialAPI 5 | description: YouTube Tut API -------------------------------------------------------------------------------- /Episode_11/WorldGuardAPI/FirstIntellij.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Episode_11/WorldGuardAPI/src/me/tsccoding/tutorial/TutorialMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.tutorial; 2 | 3 | import com.sk89q.worldedit.Vector; 4 | import com.sk89q.worldguard.LocalPlayer; 5 | import com.sk89q.worldguard.bukkit.WorldGuardPlugin; 6 | import com.sk89q.worldguard.protection.ApplicableRegionSet; 7 | import com.sk89q.worldguard.protection.managers.RegionManager; 8 | import com.sk89q.worldguard.protection.regions.ProtectedRegion; 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.ChatColor; 11 | import org.bukkit.Sound; 12 | import org.bukkit.entity.Player; 13 | import org.bukkit.event.EventHandler; 14 | import org.bukkit.event.Listener; 15 | import org.bukkit.event.player.PlayerMoveEvent; 16 | import org.bukkit.event.player.PlayerQuitEvent; 17 | import org.bukkit.plugin.Plugin; 18 | import org.bukkit.plugin.java.JavaPlugin; 19 | 20 | import java.util.ArrayList; 21 | import java.util.UUID; 22 | 23 | public class TutorialMain extends JavaPlugin implements Listener { 24 | 25 | public WorldGuardPlugin worldGuardPlugin; 26 | 27 | public void onEnable() { 28 | worldGuardPlugin = getWorldGuard(); 29 | this.getServer().getPluginManager().registerEvents(this, this); 30 | } 31 | 32 | private ArrayList entered = new ArrayList<>(); 33 | private ArrayList left = new ArrayList<>(); 34 | 35 | @EventHandler 36 | public void quitEvent(PlayerQuitEvent event) { 37 | Player player = event.getPlayer(); 38 | 39 | if (entered.contains(player) || left.contains(player)) { 40 | left.remove(player); 41 | entered.remove(player); 42 | } 43 | } 44 | 45 | @EventHandler 46 | public void moveEvent(PlayerMoveEvent event) { 47 | Player player = event.getPlayer(); 48 | enterRegion(player); 49 | } 50 | 51 | public void enterRegion(Player player) { 52 | LocalPlayer localPlayer = worldGuardPlugin.wrapPlayer(player); 53 | Vector playerVector = localPlayer.getPosition(); 54 | RegionManager regionManager = worldGuardPlugin.getRegionManager(player.getWorld()); 55 | ApplicableRegionSet applicableRegionSet = regionManager.getApplicableRegions(playerVector); 56 | 57 | for (ProtectedRegion regions : applicableRegionSet) { 58 | if (regions.contains(playerVector)) { 59 | if (!entered.contains(player)) { 60 | try { 61 | left.remove(player); 62 | entered.add(player); 63 | 64 | String owners = regions.getOwners().toPlayersString(); 65 | owners = owners.replace("uuid:", ""); 66 | 67 | Player regionPlayer = this.getServer().getPlayer(UUID.fromString(owners)); 68 | player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1); 69 | player.sendMessage(ChatColor.GREEN + "Now Entering: "); 70 | player.sendMessage(ChatColor.BLUE + regionPlayer.getName() + "'s property"); 71 | } catch (Exception e) { 72 | e.printStackTrace(); 73 | } 74 | 75 | } 76 | } 77 | } 78 | if (!left.contains(player)) { 79 | if (applicableRegionSet.size() == 0) { 80 | entered.remove(player); 81 | left.add(player); 82 | player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1); 83 | } 84 | } 85 | } 86 | 87 | public WorldGuardPlugin getWorldGuard() { 88 | Plugin plugin = this.getServer().getPluginManager().getPlugin("WorldGuard"); 89 | 90 | if (plugin == null || !(plugin instanceof WorldGuardPlugin)) { 91 | return null; 92 | } 93 | 94 | return (WorldGuardPlugin) plugin; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Episode_11/WorldGuardAPI/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Tutorial_Intellij 2 | description: 3 | version: 1.0 4 | main: me.tsccoding.tutorial.TutorialMain -------------------------------------------------------------------------------- /Episode_12/ParticleTrails/FirstIntellij.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Episode_12/ParticleTrails/src/me/tsccoding/tutorial/TutorialMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.tutorial; 2 | 3 | import net.minecraft.server.v1_12_R1.EnumParticle; 4 | import net.minecraft.server.v1_12_R1.PacketPlayOutWorldParticles; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; 7 | import org.bukkit.entity.Entity; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.plugin.java.JavaPlugin; 11 | import org.bukkit.scheduler.BukkitRunnable; 12 | import org.bukkit.Location; 13 | 14 | public class TutorialMain extends JavaPlugin implements Listener { 15 | 16 | public static TutorialMain plugin; 17 | 18 | public void onEnable() { 19 | plugin = this; 20 | this.getServer().getPluginManager().registerEvents(this, this); 21 | 22 | for (Entity entity : Bukkit.getWorld("world").getEntities()) { 23 | if (entity instanceof Player) { 24 | Player player = (Player) entity; 25 | 26 | new BukkitRunnable() { 27 | 28 | @Override 29 | public void run() { 30 | float red = 255; 31 | float green =0; 32 | float blue = 0; 33 | Location location = player.getLocation(); 34 | 35 | PacketPlayOutWorldParticles particles = new PacketPlayOutWorldParticles(EnumParticle.FLAME, true, (float) location.getX(), (float) location.getY(), (float) location.getZ(), red, green, blue, (float)255, 0, 10); 36 | ((CraftPlayer) player).getHandle().playerConnection.sendPacket(particles); 37 | } 38 | }.runTaskTimerAsynchronously(this, 0, 0); 39 | } 40 | } 41 | } 42 | 43 | 44 | } -------------------------------------------------------------------------------- /Episode_12/ParticleTrails/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Tutorial_Intellij 2 | description: 3 | version: 1.0 4 | main: me.tsccoding.tutorial.TutorialMain -------------------------------------------------------------------------------- /Episode_13/PermissionsPlugin/src/config.yml: -------------------------------------------------------------------------------- 1 | Groups: 2 | member: 3 | permissions: 4 | - tutorial.blockbreak 5 | 6 | -------------------------------------------------------------------------------- /Episode_13/PermissionsPlugin/src/me/tsccoding/tutorial/TutorialMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.tutorial; 2 | 3 | import org.bukkit.ChatColor; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.block.BlockBreakEvent; 8 | import org.bukkit.event.player.PlayerJoinEvent; 9 | import org.bukkit.event.player.PlayerQuitEvent; 10 | import org.bukkit.permissions.PermissionAttachment; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | 13 | import java.util.HashMap; 14 | import java.util.UUID; 15 | 16 | public class TutorialMain extends JavaPlugin implements Listener { 17 | 18 | public static TutorialMain plugin; 19 | public HashMap playerPermissions = new HashMap<>(); 20 | 21 | public void onEnable() { 22 | plugin = this; 23 | this.getConfig().options().copyDefaults(true); 24 | this.saveConfig(); 25 | 26 | this.getServer().getPluginManager().registerEvents(this, this); 27 | } 28 | 29 | public void onDisable() { 30 | playerPermissions.clear(); 31 | } 32 | 33 | @EventHandler 34 | public void breakBlock(BlockBreakEvent event) { 35 | Player player = event.getPlayer(); 36 | if (!player.hasPermission("tutorial.blockbreak")) { 37 | event.setCancelled(true); 38 | player.sendMessage(ChatColor.RED + "You do not have permission to do that!"); 39 | } 40 | } 41 | 42 | @EventHandler 43 | public void join(PlayerJoinEvent event) { 44 | Player player = event.getPlayer(); 45 | setupPermissions(player); 46 | } 47 | 48 | @EventHandler 49 | public void leave(PlayerQuitEvent event) { 50 | Player player = event.getPlayer(); 51 | playerPermissions.remove(player.getUniqueId()); 52 | } 53 | 54 | public void setupPermissions(Player player) { 55 | PermissionAttachment attachment = player.addAttachment(this); 56 | this.playerPermissions.put(player.getUniqueId(), attachment); 57 | permissionsSetter(player.getUniqueId()); 58 | } 59 | 60 | private void permissionsSetter(UUID uuid) { 61 | PermissionAttachment attachment = this.playerPermissions.get(uuid); 62 | for (String groups : this.getConfig().getConfigurationSection("Groups").getKeys(false)) { 63 | for (String permissions : this.getConfig().getStringList("Groups." + groups + ".permissions")) { 64 | System.out.print(permissions); 65 | attachment.setPermission(permissions, true); 66 | } 67 | } 68 | } 69 | 70 | 71 | } -------------------------------------------------------------------------------- /Episode_13/PermissionsPlugin/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Tutorial_Intellij 2 | description: 3 | version: 1.0 4 | main: me.tsccoding.tutorial.TutorialMain -------------------------------------------------------------------------------- /Episode_14/ArenaManager/src/me/tsccoding/tutorial/ArenaManager.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.tutorial; 2 | 3 | import org.bukkit.Location; 4 | 5 | import java.util.ArrayList; 6 | import java.util.UUID; 7 | 8 | public class ArenaManager { 9 | 10 | private String name; 11 | private int id; 12 | private boolean gameStarted; 13 | private boolean activated; 14 | private ArrayList playerInGame; 15 | private Location lobbySpawn; 16 | 17 | public ArenaManager(String name, int id, boolean gameStarted, boolean activated, ArrayList playerInGame, Location lobbySpawn) { 18 | this.name = name; 19 | this.id = id; 20 | this.gameStarted = gameStarted; 21 | this.activated = activated; 22 | this.playerInGame = playerInGame; 23 | this.lobbySpawn = lobbySpawn; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public int getId() { 35 | return id; 36 | } 37 | 38 | public void setId(int id) { 39 | this.id = id; 40 | } 41 | 42 | public boolean isGameStarted() { 43 | return gameStarted; 44 | } 45 | 46 | public void setGameStarted(boolean gameStarted) { 47 | this.gameStarted = gameStarted; 48 | } 49 | 50 | public boolean isActivated() { 51 | return activated; 52 | } 53 | 54 | public void setActivated(boolean activated) { 55 | this.activated = activated; 56 | } 57 | 58 | public ArrayList getPlayerInGame() { 59 | return playerInGame; 60 | } 61 | 62 | public void setPlayerInGame(ArrayList playerInGame) { 63 | this.playerInGame = playerInGame; 64 | } 65 | 66 | public Location getLobbySpawn() { 67 | return lobbySpawn; 68 | } 69 | 70 | public void setLobbySpawn(Location lobbySpawn) { 71 | this.lobbySpawn = lobbySpawn; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Episode_14/ArenaManager/src/me/tsccoding/tutorial/ArenaMethods.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.tutorial; 2 | 3 | public class ArenaMethods { 4 | private TutorialMain plugin = TutorialMain.plugin; 5 | 6 | public void onDisableSetupArenas() { 7 | for (ArenaManager arenas : plugin.arenaManagerHashMap.values()) { 8 | plugin.getConfig().set(arenas.getName() + ".lobbyspawn", arenas.getLobbySpawn()); 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Episode_14/ArenaManager/src/me/tsccoding/tutorial/CreateArenaCMD.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.tutorial; 2 | 3 | import org.bukkit.ChatColor; 4 | import org.bukkit.command.Command; 5 | import org.bukkit.command.CommandExecutor; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.entity.Player; 8 | 9 | import java.util.ArrayList; 10 | import java.util.UUID; 11 | 12 | public class CreateArenaCMD implements CommandExecutor { 13 | private TutorialMain plugin = TutorialMain.plugin; 14 | 15 | @Override 16 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { 17 | if (sender instanceof Player) { 18 | Player player = (Player) sender; 19 | 20 | if (command.getName().equalsIgnoreCase("arena")) { 21 | if (args.length == 4) { 22 | if (args[0].equalsIgnoreCase("create")) { 23 | try { 24 | String name = args[1]; 25 | int id = Integer.parseInt(args[2]); 26 | boolean activated = Boolean.parseBoolean(args[3]); 27 | plugin.arenaManagerHashMap.put(name, new ArenaManager(name, id, false, activated, new ArrayList(), player.getLocation())); 28 | player.sendMessage(ChatColor.GREEN + "Arena created"); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | }else{ 34 | player.sendMessage(ChatColor.RED + "Invalid argument length."); 35 | player.sendMessage(ChatColor.RED + "Usage: /arena create "); 36 | } 37 | } 38 | } 39 | 40 | return true; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Episode_14/ArenaManager/src/me/tsccoding/tutorial/TutorialMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.tutorial; 2 | 3 | import org.bukkit.event.Listener; 4 | import org.bukkit.plugin.java.JavaPlugin; 5 | 6 | import java.util.HashMap; 7 | 8 | public class TutorialMain extends JavaPlugin implements Listener { 9 | 10 | public static TutorialMain plugin; 11 | public HashMap arenaManagerHashMap = new HashMap<>(); 12 | 13 | public void onEnable() { 14 | plugin = this; 15 | this.getConfig().options().copyDefaults(true); 16 | this.saveConfig(); 17 | this.getCommand("arena").setExecutor(new CreateArenaCMD()); 18 | this.getServer().getPluginManager().registerEvents(this, this); 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /Episode_14/ArenaManager/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Tutorial_Intellij 2 | description: 3 | version: 1.0 4 | main: me.tsccoding.tutorial.TutorialMain 5 | 6 | commands: 7 | arena: 8 | usage: / 9 | description: Run main commands -------------------------------------------------------------------------------- /Episode_15/VaultAPI/VaultAPI.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Episode_15/VaultAPI/src/me/tsc/tutorial/vault/EconomyCommands.java: -------------------------------------------------------------------------------- 1 | package me.tsc.tutorial.vault; 2 | 3 | import net.milkbowl.vault.economy.Economy; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.Command; 7 | import org.bukkit.command.CommandExecutor; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | public class EconomyCommands implements CommandExecutor { 12 | 13 | private Economy economy = VaultMain.economy; 14 | 15 | @Override 16 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { 17 | 18 | if (sender instanceof Player) { 19 | Player player = (Player) sender; 20 | 21 | if (command.getName().equalsIgnoreCase("eco")) { 22 | if (args[0].equalsIgnoreCase("deposit")) { 23 | if (args.length == 3) { 24 | try { 25 | Player target = Bukkit.getPlayer(args[1]); 26 | int depositAmount = Integer.parseInt(args[2]); 27 | 28 | economy.depositPlayer(target, depositAmount); 29 | player.sendMessage(ChatColor.GRAY + "You have deposited §a$" + depositAmount + "§7 into §a" + target.getName() + "'s §7account"); 30 | 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | return true; 36 | } 37 | if (args[0].equalsIgnoreCase("balance")) { 38 | if (args.length == 2) { 39 | try { 40 | Player target = Bukkit.getPlayer(args[1]); 41 | int balance = (int) economy.getBalance(target); 42 | player.sendMessage(ChatColor.GREEN + target.getName() + " §7has §a$" + balance + "§7 in their account"); 43 | 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | return true; 49 | } 50 | } 51 | } 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Episode_15/VaultAPI/src/me/tsc/tutorial/vault/VaultMain.java: -------------------------------------------------------------------------------- 1 | package me.tsc.tutorial.vault; 2 | 3 | import net.milkbowl.vault.economy.Economy; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.plugin.RegisteredServiceProvider; 6 | import org.bukkit.plugin.java.JavaPlugin; 7 | 8 | public class VaultMain extends JavaPlugin { 9 | 10 | public static Economy economy; 11 | 12 | public void onEnable() { 13 | if (!setupEconomy()) { 14 | Bukkit.shutdown(); 15 | } 16 | 17 | this.getCommand("eco").setExecutor(new EconomyCommands()); 18 | } 19 | 20 | private boolean setupEconomy() { 21 | RegisteredServiceProvider economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); 22 | if (economyProvider != null) { 23 | economy = economyProvider.getProvider(); 24 | } 25 | 26 | return (economy != null); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Episode_15/VaultAPI/src/plugin.yml: -------------------------------------------------------------------------------- 1 | main: me.tsc.tutorial.vault.VaultMain 2 | version: 1.0 3 | name: EconomyVault_Tutorial 4 | 5 | commands: 6 | eco: 7 | usage: / 8 | description: Run eco commands -------------------------------------------------------------------------------- /Episode_16/src/me/tsctutorial/economy/EconomyCommands.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.economy; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.ChatColor; 5 | import org.bukkit.command.Command; 6 | import org.bukkit.command.CommandExecutor; 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | public class EconomyCommands implements CommandExecutor { 11 | 12 | private EconomyMain plugin = EconomyMain.getInstance; 13 | 14 | @Override 15 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { 16 | 17 | if (sender instanceof Player) { 18 | Player player = (Player) sender; 19 | 20 | if (command.getName().equalsIgnoreCase("econo")) { 21 | 22 | if(!plugin.playerBank.containsKey(player.getUniqueId())){ 23 | plugin.playerBank.put(player.getUniqueId(), 0.0); 24 | } 25 | //DEPOSIT COMMAND 26 | if (args[0].equalsIgnoreCase("deposit")) { 27 | if (args.length == 3) { 28 | try { 29 | Player target = Bukkit.getPlayer(args[1]); 30 | int depositAmount = Integer.parseInt(args[2]); 31 | 32 | plugin.economyImplementer.depositPlayer(target, depositAmount); 33 | player.sendMessage(ChatColor.GRAY + "You have deposited §a$" + depositAmount + "§7 into §a" + target.getName() + "'s §7account"); 34 | 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | return true; 40 | } 41 | 42 | //BALANCE COMMAND 43 | if (args[0].equalsIgnoreCase("balance")) { 44 | if (args.length == 2) { 45 | try { 46 | Player target = Bukkit.getPlayer(args[1]); 47 | int balance = (int) plugin.economyImplementer.getBalance(target); 48 | player.sendMessage(ChatColor.GREEN + target.getName() + " §7has §a$" + balance + "§7 in their account"); 49 | 50 | } catch (Exception e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | return true; 55 | } 56 | } 57 | } 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Episode_16/src/me/tsctutorial/economy/EconomyImplementer.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.economy; 2 | 3 | import net.milkbowl.vault.economy.Economy; 4 | import net.milkbowl.vault.economy.EconomyResponse; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.OfflinePlayer; 7 | import org.bukkit.entity.Player; 8 | 9 | import java.nio.Buffer; 10 | import java.util.List; 11 | import java.util.UUID; 12 | 13 | public class EconomyImplementer implements Economy { 14 | 15 | private EconomyMain plugin = EconomyMain.getInstance; 16 | 17 | @Override 18 | public boolean isEnabled() { 19 | return false; 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return null; 25 | } 26 | 27 | @Override 28 | public boolean hasBankSupport() { 29 | return false; 30 | } 31 | 32 | @Override 33 | public int fractionalDigits() { 34 | return 0; 35 | } 36 | 37 | @Override 38 | public String format(double v) { 39 | return null; 40 | } 41 | 42 | @Override 43 | public String currencyNamePlural() { 44 | return null; 45 | } 46 | 47 | @Override 48 | public String currencyNameSingular() { 49 | return null; 50 | } 51 | 52 | @Override 53 | public boolean hasAccount(String s) { 54 | return false; 55 | } 56 | 57 | @Override 58 | public boolean hasAccount(OfflinePlayer offlinePlayer) { 59 | return false; 60 | } 61 | 62 | @Override 63 | public boolean hasAccount(String s, String s1) { 64 | return false; 65 | } 66 | 67 | @Override 68 | public boolean hasAccount(OfflinePlayer offlinePlayer, String s) { 69 | return false; 70 | } 71 | 72 | @Override 73 | public double getBalance(String s) { 74 | Player player = Bukkit.getPlayer(s); 75 | UUID uuid = player.getUniqueId(); 76 | return plugin.playerBank.get(uuid); 77 | } 78 | 79 | @Override 80 | public double getBalance(OfflinePlayer offlinePlayer) { 81 | UUID uuid = offlinePlayer.getUniqueId(); 82 | return plugin.playerBank.get(uuid); 83 | } 84 | 85 | @Override 86 | public double getBalance(String s, String s1) { 87 | Player player = Bukkit.getPlayer(s); 88 | UUID uuid = player.getUniqueId(); 89 | return plugin.playerBank.get(uuid); 90 | } 91 | 92 | @Override 93 | public double getBalance(OfflinePlayer offlinePlayer, String s) { 94 | UUID uuid = offlinePlayer.getUniqueId(); 95 | return plugin.playerBank.get(uuid); 96 | } 97 | 98 | @Override 99 | public boolean has(String s, double v) { 100 | return false; 101 | } 102 | 103 | @Override 104 | public boolean has(OfflinePlayer offlinePlayer, double v) { 105 | return false; 106 | } 107 | 108 | @Override 109 | public boolean has(String s, String s1, double v) { 110 | return false; 111 | } 112 | 113 | @Override 114 | public boolean has(OfflinePlayer offlinePlayer, String s, double v) { 115 | return false; 116 | } 117 | 118 | @Override 119 | public EconomyResponse withdrawPlayer(String s, double v) { 120 | return null; 121 | } 122 | 123 | @Override 124 | public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, double v) { 125 | return null; 126 | } 127 | 128 | @Override 129 | public EconomyResponse withdrawPlayer(String s, String s1, double v) { 130 | return null; 131 | } 132 | 133 | @Override 134 | public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, String s, double v) { 135 | return null; 136 | } 137 | 138 | @Override 139 | public EconomyResponse depositPlayer(String s, double v) { 140 | Player player = Bukkit.getPlayer(s); 141 | UUID uuid = player.getUniqueId(); 142 | double oldBalance = plugin.playerBank.get(uuid); 143 | plugin.playerBank.put(uuid, oldBalance + v); 144 | return null; 145 | } 146 | 147 | @Override 148 | public EconomyResponse depositPlayer(OfflinePlayer offlinePlayer, double v) { 149 | UUID uuid = offlinePlayer.getUniqueId(); 150 | double oldBalance = plugin.playerBank.get(uuid); 151 | plugin.playerBank.put(uuid, oldBalance + v); 152 | return null; 153 | } 154 | 155 | @Override 156 | public EconomyResponse depositPlayer(String s, String s1, double v) { 157 | Player player = Bukkit.getPlayer(s); 158 | UUID uuid = player.getUniqueId(); 159 | double oldBalance = plugin.playerBank.get(uuid); 160 | plugin.playerBank.put(uuid, oldBalance + v); 161 | return null; 162 | } 163 | 164 | @Override 165 | public EconomyResponse depositPlayer(OfflinePlayer offlinePlayer, String s, double v) { 166 | UUID uuid = offlinePlayer.getUniqueId(); 167 | double oldBalance = plugin.playerBank.get(uuid); 168 | plugin.playerBank.put(uuid, oldBalance + v); 169 | return null; 170 | } 171 | 172 | @Override 173 | public EconomyResponse createBank(String s, String s1) { 174 | return null; 175 | } 176 | 177 | @Override 178 | public EconomyResponse createBank(String s, OfflinePlayer offlinePlayer) { 179 | return null; 180 | } 181 | 182 | @Override 183 | public EconomyResponse deleteBank(String s) { 184 | return null; 185 | } 186 | 187 | @Override 188 | public EconomyResponse bankBalance(String s) { 189 | return null; 190 | } 191 | 192 | @Override 193 | public EconomyResponse bankHas(String s, double v) { 194 | return null; 195 | } 196 | 197 | @Override 198 | public EconomyResponse bankWithdraw(String s, double v) { 199 | return null; 200 | } 201 | 202 | @Override 203 | public EconomyResponse bankDeposit(String s, double v) { 204 | return null; 205 | } 206 | 207 | @Override 208 | public EconomyResponse isBankOwner(String s, String s1) { 209 | return null; 210 | } 211 | 212 | @Override 213 | public EconomyResponse isBankOwner(String s, OfflinePlayer offlinePlayer) { 214 | return null; 215 | } 216 | 217 | @Override 218 | public EconomyResponse isBankMember(String s, String s1) { 219 | return null; 220 | } 221 | 222 | @Override 223 | public EconomyResponse isBankMember(String s, OfflinePlayer offlinePlayer) { 224 | return null; 225 | } 226 | 227 | @Override 228 | public List getBanks() { 229 | return null; 230 | } 231 | 232 | @Override 233 | public boolean createPlayerAccount(String s) { 234 | return false; 235 | } 236 | 237 | @Override 238 | public boolean createPlayerAccount(OfflinePlayer offlinePlayer) { 239 | return false; 240 | } 241 | 242 | @Override 243 | public boolean createPlayerAccount(String s, String s1) { 244 | return false; 245 | } 246 | 247 | @Override 248 | public boolean createPlayerAccount(OfflinePlayer offlinePlayer, String s) { 249 | return false; 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /Episode_16/src/me/tsctutorial/economy/EconomyMain.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.economy; 2 | 3 | import org.bukkit.plugin.java.JavaPlugin; 4 | 5 | import java.util.HashMap; 6 | import java.util.UUID; 7 | 8 | public class EconomyMain extends JavaPlugin { 9 | 10 | public static EconomyMain getInstance; 11 | public EconomyImplementer economyImplementer; 12 | private VaultHook vaultHook; 13 | 14 | public final HashMap playerBank = new HashMap<>(); 15 | 16 | public void onEnable() { 17 | runOnEnable(); 18 | } 19 | 20 | private void instanceClasses() { 21 | getInstance = this; 22 | economyImplementer = new EconomyImplementer(); 23 | vaultHook = new VaultHook(); 24 | } 25 | 26 | public void runOnEnable(){ 27 | instanceClasses(); 28 | vaultHook.hook(); 29 | this.getCommand("econo").setExecutor(new EconomyCommands()); 30 | } 31 | 32 | public void onDisable() { 33 | vaultHook.unhook(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Episode_16/src/me/tsctutorial/economy/VaultHook.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.economy; 2 | 3 | import net.milkbowl.vault.economy.Economy; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.plugin.ServicePriority; 7 | 8 | public class VaultHook { 9 | 10 | private EconomyMain plugin = EconomyMain.getInstance; 11 | 12 | private Economy provider; 13 | 14 | public void hook() { 15 | provider = plugin.economyImplementer; 16 | Bukkit.getServicesManager().register(Economy.class, this.provider, this.plugin, ServicePriority.Normal); 17 | Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "VaultAPI hooked into " + ChatColor.AQUA + plugin.getName()); 18 | } 19 | 20 | public void unhook() { 21 | Bukkit.getServicesManager().unregister(Economy.class, this.provider); 22 | Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "VaultAPI unhooked from " + ChatColor.AQUA + plugin.getName()); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Episode_16/src/plugin.yml: -------------------------------------------------------------------------------- 1 | main: me.tsctutorial.economy.EconomyMain 2 | version: 1.0 3 | name: Econo 4 | 5 | commands: 6 | econo: 7 | usage: / 8 | description: Run eco commands -------------------------------------------------------------------------------- /Episode_17/FakePlayers/FakePlayers.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Episode_17/FakePlayers/src/me/tsctutorial/fakeplayers/FPCommand.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.fakeplayers; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.ChatColor; 5 | import org.bukkit.command.Command; 6 | import org.bukkit.command.CommandExecutor; 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | public class FPCommand implements CommandExecutor { 11 | 12 | private FakePlayersMain plugin = FakePlayersMain.getInstance(); 13 | 14 | @Override 15 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { 16 | 17 | if (sender instanceof Player) { 18 | Player player = (Player) sender; 19 | 20 | if (command.getName().equalsIgnoreCase("fp")) { 21 | 22 | if (args.length == 2) { 23 | if (args[0].equalsIgnoreCase("create")) { 24 | String npcName = args[1]; 25 | plugin.npcManager.createNPC(player, npcName); 26 | } 27 | } 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Episode_17/FakePlayers/src/me/tsctutorial/fakeplayers/FakePlayersMain.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.fakeplayers; 2 | 3 | import org.bukkit.plugin.java.JavaPlugin; 4 | 5 | public class FakePlayersMain extends JavaPlugin { 6 | private static FakePlayersMain instance; 7 | 8 | public NPCManager npcManager; 9 | 10 | public static FakePlayersMain getInstance() { 11 | return instance; 12 | } 13 | 14 | private void setInstance(FakePlayersMain instance) { 15 | this.instance = instance; 16 | } 17 | 18 | public void onEnable() { 19 | setInstance(this); 20 | this.getCommand("fp").setExecutor(new FPCommand()); 21 | this.npcManager = new NPCManager(); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Episode_17/FakePlayers/src/me/tsctutorial/fakeplayers/NPCManager.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.fakeplayers; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import net.minecraft.server.v1_12_R1.*; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.craftbukkit.v1_12_R1.CraftServer; 7 | import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; 8 | import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.Location; 11 | 12 | import java.util.UUID; 13 | 14 | public class NPCManager { 15 | 16 | public void createNPC(Player player, String npcName) { 17 | Location location = player.getLocation(); 18 | MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); 19 | WorldServer nmsWorld = ((CraftWorld) player.getWorld()).getHandle(); 20 | GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "§a§l" + npcName); 21 | 22 | EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld)); 23 | Player npcPlayer = npc.getBukkitEntity().getPlayer(); 24 | npcPlayer.setPlayerListName(""); 25 | 26 | npc.setLocation(location.getX(), location.getY(), location.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch()); 27 | 28 | PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; 29 | connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc)); 30 | connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc)); 31 | connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, npc)); 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Episode_17/FakePlayers/src/plugin.yml: -------------------------------------------------------------------------------- 1 | main: me.tsctutorial.fakeplayers.FakePlayersMain 2 | version: 1.0 3 | name: FakePlayers 4 | 5 | commands: 6 | fp: 7 | usage: / 8 | description: Run commands -------------------------------------------------------------------------------- /Episode_18/JsonReader/JsonReader.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Episode_18/JsonReader/src/me/tsctutorial/jsonreader/JsonReaderMain.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.jsonreader; 2 | 3 | import com.mysql.fabric.xmlrpc.base.Array; 4 | import org.bukkit.ChatColor; 5 | import org.bukkit.Material; 6 | import org.bukkit.entity.Item; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.inventory.ItemStack; 9 | import org.bukkit.inventory.meta.ItemMeta; 10 | import org.bukkit.plugin.java.JavaPlugin; 11 | import org.json.simple.JSONArray; 12 | import org.json.simple.JSONObject; 13 | import org.json.simple.parser.JSONParser; 14 | import org.json.simple.parser.ParseException; 15 | 16 | import java.io.File; 17 | import java.io.FileReader; 18 | import java.io.IOException; 19 | import java.util.ArrayList; 20 | 21 | public class JsonReaderMain extends JavaPlugin { 22 | 23 | private File path = new File(this.getDataFolder() + "/custom_items"); 24 | private final ArrayList customItemsArray = new ArrayList<>(); 25 | 26 | public void onEnable() { 27 | 28 | if (this.getServer().getOnlinePlayers().size() == 0) { 29 | return; 30 | } 31 | for (Player online : this.getServer().getOnlinePlayers()) { 32 | setupItems(online); 33 | } 34 | } 35 | 36 | private void setupItems(Player player) { 37 | for (File file : path.listFiles()) { 38 | try { 39 | JSONParser jsonParser = new JSONParser(); 40 | Object parsed = jsonParser.parse(new FileReader(file.getPath())); 41 | JSONObject jsonObject = (JSONObject) parsed; 42 | String itemname = (String) jsonObject.get("itemname"); 43 | 44 | JSONObject itemObject = (JSONObject) jsonObject.get("item"); 45 | String itemType = (String) itemObject.get("id"); 46 | 47 | ItemStack itemStack = new ItemStack(Material.valueOf(itemType.toUpperCase())); 48 | ItemMeta itemMeta = itemStack.getItemMeta(); 49 | ArrayList lore = new ArrayList<>(); 50 | 51 | JSONArray loreArray = (JSONArray) jsonObject.get("lore"); 52 | 53 | for (Object lorelines : loreArray) { 54 | JSONObject loredata = (JSONObject) lorelines; 55 | String lore1 = (String) loredata.get("lore1"); 56 | String lore2 = (String) loredata.get("lore2"); 57 | String lore3 = (String) loredata.get("lore3"); 58 | 59 | lore.add(lore1); 60 | lore.add(lore2); 61 | lore.add(lore3); 62 | } 63 | 64 | itemMeta.setLore(lore); 65 | itemMeta.setDisplayName(ChatColor.LIGHT_PURPLE + itemname); 66 | itemStack.setItemMeta(itemMeta); 67 | 68 | player.getInventory().addItem(itemStack); 69 | 70 | 71 | } catch (ParseException | IOException e) { 72 | e.printStackTrace(); 73 | } 74 | } 75 | 76 | 77 | } 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /Episode_18/JsonReader/src/plugin.yml: -------------------------------------------------------------------------------- 1 | main: me.tsctutorial.jsonreader.JsonReaderMain 2 | version: 1.0 3 | name: JsonReader 4 | 5 | commands: 6 | js: 7 | usage: / 8 | description: Run commands -------------------------------------------------------------------------------- /Episode_19/FakePlayerSkins/FakePlayers.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Episode_19/FakePlayerSkins/src/config.yml: -------------------------------------------------------------------------------- 1 | Texture: 'eyJ0aW1lc3RhbXAiOjE1MDA3NzQzMjI0NDcsInByb2ZpbGVJZCI6ImVjMDcxODI1NTZiNDQ0ZDM4ZTlhZjQ4YmY3NGJkZTgyIiwicHJvZmlsZU5hbWUiOiJEb2ciLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2EzNzRmZDZkMTQ0OGZhMTMwZTkyNDlhZjE5OTAyMzg0NmI4ZmM4NzdmMTE3ZjNhYzFjNDM0MDNiYTdmZWYzIn0sIkNBUEUiOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS81YzNjYTdlZTJhNDk4ZjFiNWQyNThkNWZhOTI3ZTYzZTQzMzE0M2FkZDU1MzhjZjYzYjZhOWI3OGFlNzM1In19fQ==' 2 | Signature: 'yGUZXhcV0C38oUjNOtdMy1VHxfcicR91lKIrtByr71m/WbXN3Wueou08q9lfKyB5nBSH5i4vBfIKMb1HNVCminDssT8XRYQ0ost1QqMG94Ycv3x/6gHILQ7ww2BII95Um9nt0G28hIxktSlOLYnOWKmlL6fG1yXuNeis9NYR0EpYjsVFEFQVXgAhlSQeTbvcv7c5mnXqfLmYfKJ2hmIT51nc2Adv/6lUd8DHAZMA4mGdCYsQnyhvLcYDLAZgYhT3Qcs4q/mTgtPLgweMAfoHqyqlC4yZaXVSie97J+Ij/OSR/2d/RVhsATL4MbsJy/KJ+/ayihmY0OnDJnkbDUmNcm7125/eZXSj8fcrh2B6BSKfzoWqApGMFmgy4u35GC15aUBzXJ93t/mBBs3J7YV0Asx9aheL6dpOhpluwiXgvzObtvIdwqAY+mUkHI+OMzHKQT+IwfZp6BTbMwA0NhjTdxMWKTtI/uIgsJir1ButuDxFdJlP+y5nFHSARVYHd3MwScHe4feHOjr9sCxLTwn5n+0FsAQyw243AWV+S3EnqtZ+zHQo8DAC6g0p5+gUDVCj9DvmDukHpM/Du5aBFgnX5Ewu4mzr9Uu1fHSD9weE3gkD7Jb3RDSpxeYyDnZk/OHj8lfMsPcWMrdP8Sr46XZVocVgLNyNjCQ14vo+CqcohFk=' 3 | -------------------------------------------------------------------------------- /Episode_19/FakePlayerSkins/src/me/tsctutorial/fakeplayers/FPCommand.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.fakeplayers; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.ChatColor; 5 | import org.bukkit.command.Command; 6 | import org.bukkit.command.CommandExecutor; 7 | import org.bukkit.command.CommandSender; 8 | import org.bukkit.entity.Player; 9 | 10 | public class FPCommand implements CommandExecutor { 11 | 12 | private FakePlayersMain plugin = FakePlayersMain.getInstance(); 13 | 14 | @Override 15 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { 16 | 17 | if (sender instanceof Player) { 18 | Player player = (Player) sender; 19 | 20 | if (command.getName().equalsIgnoreCase("fp")) { 21 | 22 | if (args.length == 2) { 23 | if (args[0].equalsIgnoreCase("create")) { 24 | String npcName = args[1]; 25 | plugin.npcManager.createNPC(player, npcName); 26 | } 27 | } 28 | } 29 | } 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Episode_19/FakePlayerSkins/src/me/tsctutorial/fakeplayers/FakePlayersMain.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.fakeplayers; 2 | 3 | import org.bukkit.plugin.java.JavaPlugin; 4 | 5 | public class FakePlayersMain extends JavaPlugin { 6 | private static FakePlayersMain instance; 7 | 8 | public NPCManager npcManager; 9 | 10 | public static FakePlayersMain getInstance() { 11 | return instance; 12 | } 13 | 14 | private void setInstance(FakePlayersMain instance) { 15 | this.instance = instance; 16 | } 17 | 18 | public void onEnable() { 19 | setInstance(this); 20 | this.getCommand("fp").setExecutor(new FPCommand()); 21 | this.npcManager = new NPCManager(); 22 | 23 | this.getConfig().options().copyDefaults(true); 24 | this.saveConfig(); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Episode_19/FakePlayerSkins/src/me/tsctutorial/fakeplayers/NPCManager.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.fakeplayers; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import com.mojang.authlib.properties.Property; 5 | import net.minecraft.server.v1_12_R1.*; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.craftbukkit.v1_12_R1.CraftServer; 8 | import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; 9 | import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.Location; 12 | 13 | import java.util.UUID; 14 | 15 | public class NPCManager { 16 | 17 | private FakePlayersMain plugin = FakePlayersMain.getInstance(); 18 | 19 | public void createNPC(Player player, String npcName) { 20 | Location location = player.getLocation(); 21 | MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); 22 | WorldServer nmsWorld = ((CraftWorld) player.getWorld()).getHandle(); 23 | GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "§a§l" + npcName); 24 | changeSkin(gameProfile); 25 | EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld)); 26 | npc.setLocation(location.getX(), location.getY(), location.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch()); 27 | 28 | PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; 29 | connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc)); 30 | connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc)); 31 | } 32 | 33 | private void changeSkin(GameProfile profile){ 34 | String texture = plugin.getConfig().getString("Texture"); 35 | String signature = plugin.getConfig().getString("Signature"); 36 | profile.getProperties().put("textures", new Property("textures",texture,signature)); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Episode_19/FakePlayerSkins/src/plugin.yml: -------------------------------------------------------------------------------- 1 | main: me.tsctutorial.fakeplayers.FakePlayersMain 2 | version: 1.0 3 | name: FakePlayers 4 | 5 | commands: 6 | fp: 7 | usage: / 8 | description: Run commands -------------------------------------------------------------------------------- /Episode_20/maventest/maventest.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Episode_20/maventest/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | maven 8 | maven-test 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | spigot-repo 14 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 15 | 16 | 17 | 18 | 19 | 20 | 21 | org.spigotmc 22 | spigot-api 23 | 1.11.2-R0.1-SNAPSHOT 24 | provided 25 | 26 | 27 | 28 | org.bukkit 29 | bukkit 30 | 1.11.2-R0.1-SNAPSHOT 31 | provided 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Episode_20/maventest/src/main/java/me/tsccoding/maven/MavenMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.maven; 2 | 3 | import org.bukkit.plugin.java.JavaPlugin; 4 | 5 | public class MavenMain extends JavaPlugin { 6 | public void onEnable(){ 7 | this.getLogger().info("Maven Works"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Episode_20/maventest/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MavenPlugin 2 | version: 1.0 3 | main: me.tsccoding.maven.MavenMain 4 | author: TheSourceCode -------------------------------------------------------------------------------- /Episode_20/maventest/target/classes/me/tsccoding/maven/MavenMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_20/maventest/target/classes/me/tsccoding/maven/MavenMain.class -------------------------------------------------------------------------------- /Episode_20/maventest/target/classes/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MavenPlugin 2 | version: 1.0 3 | main: me.tsccoding.maven.MavenMain 4 | author: TheSourceCode -------------------------------------------------------------------------------- /Episode_21/CommandManager/CommandManager.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Episode_21/CommandManager/src/me/tsctutorial/command/CommandMain.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.command; 2 | 3 | import me.tsctutorial.command.commands.CommandManager; 4 | import org.bukkit.plugin.java.JavaPlugin; 5 | 6 | public class CommandMain extends JavaPlugin { 7 | private static CommandMain instance; 8 | public CommandManager commandManager; 9 | 10 | public void onEnable() { 11 | setInstance(this); 12 | commandManager = new CommandManager(); 13 | 14 | commandManager.setup(); 15 | } 16 | 17 | public static CommandMain getInstance() { 18 | return instance; 19 | } 20 | 21 | private static void setInstance(CommandMain instance) { 22 | CommandMain.instance = instance; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Episode_21/CommandManager/src/me/tsctutorial/command/commands/CommandManager.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.command.commands; 2 | 3 | import me.tsctutorial.command.CommandMain; 4 | import net.minecraft.server.v1_12_R1.WorldGenWoodlandMansion; 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.command.Command; 7 | import org.bukkit.command.CommandExecutor; 8 | import org.bukkit.command.CommandSender; 9 | import org.bukkit.entity.Player; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | import java.util.Iterator; 14 | 15 | public class CommandManager implements CommandExecutor { 16 | 17 | private ArrayList commands = new ArrayList(); 18 | private CommandMain plugin = CommandMain.getInstance(); 19 | 20 | public CommandManager() { 21 | } 22 | 23 | //Sub Commands 24 | public String main = "yt"; 25 | public String info = "info"; 26 | 27 | public void setup() { 28 | plugin.getCommand(main).setExecutor(this); 29 | 30 | this.commands.add(new InfoCommand()); 31 | this.commands.add(new HelpCommand()); 32 | } 33 | 34 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { 35 | 36 | if (!(sender instanceof Player)) { 37 | sender.sendMessage(ChatColor.RED + "Only players can use commands for this plugin."); 38 | return true; 39 | } 40 | 41 | Player player = (Player) sender; 42 | 43 | if (command.getName().equalsIgnoreCase(main)) { 44 | if (args.length == 0) { 45 | player.sendMessage(ChatColor.RED + "Please add arguments to your command. Type /yt help for info"); 46 | return true; 47 | } 48 | 49 | SubCommand target = this.get(args[0]); 50 | 51 | if (target == null) { 52 | player.sendMessage(ChatColor.RED + "Invalid subcommand"); 53 | return true; 54 | } 55 | 56 | ArrayList arrayList = new ArrayList(); 57 | 58 | arrayList.addAll(Arrays.asList(args)); 59 | arrayList.remove(0); 60 | 61 | try{ 62 | target.onCommand(player,args); 63 | }catch (Exception e){ 64 | player.sendMessage(ChatColor.RED + "An error has occurred."); 65 | 66 | e.printStackTrace(); 67 | } 68 | } 69 | 70 | return true; 71 | } 72 | 73 | private SubCommand get(String name) { 74 | Iterator subcommands = this.commands.iterator(); 75 | 76 | while (subcommands.hasNext()) { 77 | SubCommand sc = (SubCommand) subcommands.next(); 78 | 79 | if (sc.name().equalsIgnoreCase(name)) { 80 | return sc; 81 | } 82 | 83 | String[] aliases; 84 | int length = (aliases = sc.aliases()).length; 85 | 86 | for (int var5 = 0; var5 < length; ++var5) { 87 | String alias = aliases[var5]; 88 | if (name.equalsIgnoreCase(alias)) { 89 | return sc; 90 | } 91 | 92 | } 93 | } 94 | return null; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Episode_21/CommandManager/src/me/tsctutorial/command/commands/HelpCommand.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.command.commands; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public class HelpCommand extends SubCommand { 6 | @Override 7 | public void onCommand(Player player, String[] args) { 8 | 9 | } 10 | 11 | @Override 12 | public String name() { 13 | return "help"; 14 | } 15 | 16 | @Override 17 | public String info() { 18 | return null; 19 | } 20 | 21 | @Override 22 | public String[] aliases() { 23 | return new String[0]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Episode_21/CommandManager/src/me/tsctutorial/command/commands/InfoCommand.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.command.commands; 2 | 3 | import me.tsctutorial.command.CommandMain; 4 | import org.bukkit.entity.Player; 5 | 6 | public class InfoCommand extends SubCommand { 7 | private CommandMain plugin = CommandMain.getInstance(); 8 | 9 | @Override 10 | public void onCommand(Player player, String[] args) { 11 | player.sendMessage("This info is cool!"); 12 | } 13 | 14 | @Override 15 | public String name() { 16 | return plugin.commandManager.info; 17 | } 18 | 19 | @Override 20 | public String info() { 21 | return ""; 22 | } 23 | 24 | @Override 25 | public String[] aliases() { 26 | return new String[0]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Episode_21/CommandManager/src/me/tsctutorial/command/commands/SubCommand.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.command.commands; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | public abstract class SubCommand { 6 | 7 | /* 8 | / args[0] args[1] 9 | */ 10 | 11 | public SubCommand() { 12 | } 13 | 14 | public abstract void onCommand(Player player, String[] args); 15 | 16 | public abstract String name(); 17 | 18 | public abstract String info(); 19 | 20 | public abstract String[] aliases(); 21 | } 22 | -------------------------------------------------------------------------------- /Episode_21/CommandManager/src/plugin.yml: -------------------------------------------------------------------------------- 1 | main: me.tsctutorial.command.CommandMain 2 | version: 1.0 3 | name: Commands 4 | 5 | commands: 6 | yt: 7 | usage: / 8 | description: Run eco commands -------------------------------------------------------------------------------- /Episode_22/PacketListener/PacketListener.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Episode_22/PacketListener/src/me/tsccoding/packets/PacketMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.packets; 2 | 3 | import io.netty.channel.*; 4 | import net.minecraft.server.v1_12_R1.PacketPlayOutBed; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.player.PlayerJoinEvent; 12 | import org.bukkit.event.player.PlayerQuitEvent; 13 | import org.bukkit.plugin.java.JavaPlugin; 14 | 15 | public class PacketMain extends JavaPlugin implements Listener { 16 | 17 | @Override 18 | public void onEnable() { 19 | Bukkit.getPluginManager().registerEvents(this, this); 20 | } 21 | 22 | @EventHandler 23 | public void onjoin(PlayerJoinEvent event){ 24 | injectPlayer(event.getPlayer()); 25 | } 26 | 27 | @EventHandler 28 | public void onleave(PlayerQuitEvent event){ 29 | removePlayer(event.getPlayer()); 30 | } 31 | private void removePlayer(Player player) { 32 | Channel channel = ((CraftPlayer) player).getHandle().playerConnection.networkManager.channel; 33 | channel.eventLoop().submit(() -> { 34 | channel.pipeline().remove(player.getName()); 35 | return null; 36 | }); 37 | } 38 | 39 | private void injectPlayer(Player player) { 40 | ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler() { 41 | 42 | @Override 43 | public void channelRead(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception { 44 | //Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "PACKET READ: " + ChatColor.RED + packet.toString()); 45 | super.channelRead(channelHandlerContext, packet); 46 | } 47 | 48 | @Override 49 | public void write(ChannelHandlerContext channelHandlerContext, Object packet, ChannelPromise channelPromise) throws Exception { 50 | //Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "PACKET WRITE: " + ChatColor.GREEN + packet.toString()); 51 | 52 | 53 | if(packet instanceof PacketPlayOutBed){ 54 | PacketPlayOutBed packetPlayOutBed = (PacketPlayOutBed) packet; 55 | Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "PACKET BLOCKED: " + ChatColor.GREEN + packetPlayOutBed.toString()); 56 | return; 57 | } 58 | super.write(channelHandlerContext, packet, channelPromise); 59 | } 60 | 61 | 62 | }; 63 | 64 | ChannelPipeline pipeline = ((CraftPlayer) player).getHandle().playerConnection.networkManager.channel.pipeline(); 65 | pipeline.addBefore("packet_handler", player.getName(), channelDuplexHandler); 66 | 67 | } 68 | } -------------------------------------------------------------------------------- /Episode_22/PacketListener/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: PacketListener 2 | author: TheSourceCode 3 | version: 1.0 4 | main: me.tsccoding.packets.PacketMain 5 | description: Packets -------------------------------------------------------------------------------- /Episode_23/TutorialMetrics/SourceTutorialMetrics.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Episode_23/TutorialMetrics/src/me/tsctutorial/metrics/SourceTutorialMetrics.java: -------------------------------------------------------------------------------- 1 | package me.tsctutorial.metrics; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.plugin.java.JavaPlugin; 5 | 6 | public class SourceTutorialMetrics extends JavaPlugin { 7 | @Override 8 | public void onEnable() { 9 | Metrics metrics = new Metrics(this); 10 | metrics.addCustomChart(new Metrics.SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size())); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Episode_23/TutorialMetrics/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: SourceTutorialMetrics 2 | version: 1.0 3 | main: me.tsctutorial.metrics.SourceTutorialMetrics 4 | -------------------------------------------------------------------------------- /Episode_24/TabList/PreTutorial.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Episode_24/TabList/src/me/tsccoding/pretutorial/PreTutorial.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import net.minecraft.server.v1_12_R1.ChatComponentText; 4 | import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerListHeaderFooter; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.event.EventHandler; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.player.PlayerJoinEvent; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | import org.bukkit.scheduler.BukkitRunnable; 13 | 14 | import java.lang.reflect.Field; 15 | 16 | public class PreTutorial extends JavaPlugin implements Listener { 17 | 18 | private boolean titlechanged = false; 19 | 20 | @Override 21 | public void onEnable() { 22 | //this.getServer().getPluginManager().registerEvents(this, this); 23 | PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); 24 | new BukkitRunnable() { 25 | 26 | @Override 27 | public void run() { 28 | try { 29 | Field a = packet.getClass().getDeclaredField("a"); 30 | a.setAccessible(true); 31 | Field b = packet.getClass().getDeclaredField("b"); 32 | b.setAccessible(true); 33 | 34 | Object header1 = new ChatComponentText("§bSourceCode\n§3Welcome to our server!"); 35 | Object header2 = new ChatComponentText("§aSourceCode\n§3Welcome to our server!"); 36 | 37 | Object footer = new ChatComponentText("§bPlayers Online: §f" + Bukkit.getServer().getOnlinePlayers().size()); 38 | if (titlechanged) { 39 | a.set(packet, header2); 40 | titlechanged = false; 41 | 42 | } else { 43 | a.set(packet, header1); 44 | titlechanged = true; 45 | } 46 | b.set(packet, footer); 47 | 48 | if (Bukkit.getOnlinePlayers().size() == 0) return; 49 | for (Player player : Bukkit.getOnlinePlayers()) { 50 | ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); 51 | } 52 | 53 | } catch (NoSuchFieldException | IllegalAccessException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | }.runTaskTimer(this, 0, 20); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /Episode_24/TabList/src/me/tsccoding/pretutorial/TestInterface.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | public interface TestInterface { 4 | } 5 | -------------------------------------------------------------------------------- /Episode_24/TabList/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: PreTutorial 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.pretutorial.PreTutorial 5 | description: TNT TAG 6 | 7 | commands: 8 | pre: 9 | usage: / 10 | description: Issues the main command -------------------------------------------------------------------------------- /Episode_25/Animated_Scoreboard(No Flicker)/src/me/tsccoding/pretutorial/PreTutorial.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.player.PlayerJoinEvent; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | import org.bukkit.scheduler.BukkitRunnable; 9 | import org.bukkit.scoreboard.*; 10 | 11 | public class PreTutorial extends JavaPlugin implements Listener { 12 | 13 | @Override 14 | public void onEnable() { 15 | this.getServer().getPluginManager().registerEvents(this, this); 16 | } 17 | 18 | @EventHandler 19 | public void joinServer(PlayerJoinEvent event) { 20 | Player player = event.getPlayer(); 21 | ScoreboardManager scoreboardManager = this.getServer().getScoreboardManager(); 22 | Scoreboard scoreboard = scoreboardManager.getNewScoreboard(); 23 | Objective objective = scoreboard.registerNewObjective("Test", "Dummy"); 24 | objective.setDisplaySlot(DisplaySlot.SIDEBAR); 25 | Team health = scoreboard.registerNewTeam("health"); 26 | health.addEntry("Health: §b"); 27 | health.setSuffix(""); 28 | health.setPrefix(""); 29 | objective.getScore("Health: §b").setScore(0); 30 | String title = "SOURCECADE"; 31 | char[] split = title.toCharArray(); 32 | 33 | new BukkitRunnable() { 34 | int counter = 0; 35 | String finaltitle = ""; 36 | 37 | @Override 38 | public void run() { 39 | if (counter < split.length) { 40 | String letter = String.valueOf(split[counter]); 41 | counter += 1; 42 | String space = ""; 43 | for (int i = 0; i < split.length - counter; i++) { 44 | space += " "; 45 | } 46 | 47 | finaltitle += letter; 48 | objective.setDisplayName(finaltitle); 49 | health.setSuffix(counter + ""); 50 | }else{ 51 | String space = ""; 52 | finaltitle = ""; 53 | for (int i = 0; i < split.length - counter; i++) { 54 | space += " "; 55 | } 56 | objective.setDisplayName(space); 57 | counter = 0; 58 | } 59 | } 60 | }.runTaskTimer(this, 0, 10); 61 | 62 | player.setScoreboard(scoreboard); 63 | } 64 | } -------------------------------------------------------------------------------- /Episode_25/Animated_Scoreboard(No Flicker)/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: PreTutorial 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.pretutorial.PreTutorial 5 | description: TNT TAG 6 | 7 | commands: 8 | pre: 9 | usage: / 10 | description: Issues the main command -------------------------------------------------------------------------------- /Episode_26/Load_Schematics/schematic.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import com.sk89q.worldedit.CuboidClipboard; 4 | import com.sk89q.worldedit.EditSession; 5 | import com.sk89q.worldedit.EditSessionFactory; 6 | import com.sk89q.worldedit.MaxChangedBlocksException; 7 | import com.sk89q.worldedit.Vector; 8 | import com.sk89q.worldedit.WorldEdit; 9 | import com.sk89q.worldedit.bukkit.BukkitWorld; 10 | import com.sk89q.worldedit.bukkit.WorldEditPlugin; 11 | import com.sk89q.worldedit.schematic.MCEditSchematicFormat; 12 | import com.sk89q.worldedit.schematic.SchematicFormat; 13 | import com.sk89q.worldedit.world.DataException; 14 | import java.io.File; 15 | import java.io.IOException; 16 | import org.bukkit.Bukkit; 17 | import org.bukkit.ChatColor; 18 | import org.bukkit.Location; 19 | import org.bukkit.Material; 20 | import org.bukkit.Server; 21 | import org.bukkit.entity.Player; 22 | import org.bukkit.event.EventHandler; 23 | import org.bukkit.event.Listener; 24 | import org.bukkit.event.player.PlayerInteractEvent; 25 | import org.bukkit.inventory.ItemStack; 26 | import org.bukkit.inventory.PlayerInventory; 27 | import org.bukkit.plugin.PluginManager; 28 | import org.bukkit.plugin.java.JavaPlugin; 29 | 30 | public class PreTutorial 31 | extends JavaPlugin 32 | implements Listener 33 | { 34 | public void onEnable() 35 | { 36 | getServer().getPluginManager().registerEvents(this, this); 37 | } 38 | 39 | @EventHandler 40 | public void interact(PlayerInteractEvent event) 41 | { 42 | Player player = event.getPlayer(); 43 | if (player.getInventory().getItemInMainHand().getType().equals(Material.STICK)) 44 | { 45 | loadSchematic(player); 46 | player.sendMessage(ChatColor.GREEN + "Schematic has been loaded."); 47 | } 48 | } 49 | 50 | private void loadSchematic(Player player) 51 | { 52 | Location location = player.getLocation(); 53 | WorldEditPlugin worldEditPlugin = (WorldEditPlugin)Bukkit.getPluginManager().getPlugin("WorldEdit"); 54 | File schematic = new File(getDataFolder() + File.separator + "/schematics/house.schematic"); 55 | EditSession session = worldEditPlugin.getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(location.getWorld()), 10000); 56 | try 57 | { 58 | CuboidClipboard clipboard = MCEditSchematicFormat.getFormat(schematic).load(schematic); 59 | clipboard.rotate2D(90); 60 | clipboard.paste(session, new Vector(location.getX(), location.getY(), location.getZ()), false); 61 | } 62 | catch (MaxChangedBlocksException|DataException|IOException e) 63 | { 64 | e.printStackTrace(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Episode_27/Player_Leveling/PreTutorial.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Episode_27/Player_Leveling/PreTutorial1.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Episode_27/Player_Leveling/src/config.yml: -------------------------------------------------------------------------------- 1 | PlayerLevels: 2 | Levels: 3 | 1: 4 | xp: 500 5 | item: coal 6 | amount: 15 -------------------------------------------------------------------------------- /Episode_27/Player_Leveling/src/me/tsccoding/pretutorial/PlayerLevelManager.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | public class PlayerLevelManager { 4 | 5 | private int level; 6 | private int xp; 7 | 8 | public PlayerLevelManager(int level, int xp) { 9 | this.level = level; 10 | this.xp = xp; 11 | } 12 | 13 | public int getLevel() { 14 | return level; 15 | } 16 | 17 | public void setLevel(int level) { 18 | this.level = level; 19 | } 20 | 21 | public int getXp() { 22 | return xp; 23 | } 24 | 25 | public void setXp(int xp) { 26 | this.xp = xp; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Episode_27/Player_Leveling/src/me/tsccoding/pretutorial/PreTutorial.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.block.BlockBreakEvent; 9 | import org.bukkit.event.player.PlayerJoinEvent; 10 | import org.bukkit.event.player.PlayerQuitEvent; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | import org.bukkit.scoreboard.DisplaySlot; 13 | import org.bukkit.scoreboard.Objective; 14 | import org.bukkit.scoreboard.Score; 15 | import org.bukkit.scoreboard.Scoreboard; 16 | 17 | import java.util.HashMap; 18 | import java.util.UUID; 19 | 20 | public class PreTutorial extends JavaPlugin implements Listener { 21 | 22 | private HashMap levelManagerHashMap; 23 | 24 | @Override 25 | public void onEnable() { 26 | this.levelManagerHashMap = new HashMap<>(); 27 | this.getServer().getPluginManager().registerEvents(this, this); 28 | this.getConfig().options().copyDefaults(true); 29 | this.saveConfig(); 30 | } 31 | 32 | @Override 33 | public void onDisable() { 34 | this.levelManagerHashMap.clear(); 35 | } 36 | 37 | @EventHandler 38 | public void join(PlayerJoinEvent event) { 39 | Player player = event.getPlayer(); 40 | event.setJoinMessage(""); 41 | 42 | if (!player.hasPlayedBefore()) { 43 | player.sendMessage("§bWelcome, your level is §a0"); 44 | 45 | this.levelManagerHashMap.put(player.getUniqueId(), new PlayerLevelManager(0, 0)); 46 | this.getConfig().set("PlayerLevels." + player.getUniqueId() + ".level", 0); 47 | this.getConfig().set("PlayerLevels." + player.getUniqueId() + ".xp", 0); 48 | this.saveConfig(); 49 | 50 | this.setscore(player, 0, 0); 51 | } else { 52 | int level = this.getConfig().getInt("PlayerLevels." + player.getUniqueId() + ".level"); 53 | int xp = this.getConfig().getInt("PlayerLevels." + player.getUniqueId() + ".xp"); 54 | levelManagerHashMap.put(player.getUniqueId(), new PlayerLevelManager(level, xp)); 55 | setscore(player, level, xp); 56 | } 57 | } 58 | 59 | @EventHandler 60 | public void quit(PlayerQuitEvent event) { 61 | Player player = event.getPlayer(); 62 | PlayerLevelManager playerLevelManager = this.levelManagerHashMap.get(player.getUniqueId()); 63 | 64 | if (this.levelManagerHashMap.containsKey(player.getUniqueId())) { 65 | this.getConfig().set("PlayerLevels." + player.getUniqueId() + ".level", playerLevelManager.getLevel()); 66 | this.getConfig().set("PlayerLevels." + player.getUniqueId() + ".xp", playerLevelManager.getXp()); 67 | this.saveConfig(); 68 | this.levelManagerHashMap.remove(player.getUniqueId()); 69 | } 70 | } 71 | 72 | @EventHandler 73 | public void blockbreak(BlockBreakEvent event) { 74 | Player player = event.getPlayer(); 75 | PlayerLevelManager playerLevelManager = this.levelManagerHashMap.get(player.getUniqueId()); 76 | Block block = event.getBlock(); 77 | 78 | if (block.getType() == Material.STONE) { 79 | playerLevelManager.setXp(playerLevelManager.getXp() + 100); 80 | player.sendMessage("§a+100 §bExperience"); 81 | xpcheck(player, playerLevelManager); 82 | setscore(player, playerLevelManager.getLevel(), playerLevelManager.getXp()); 83 | 84 | } 85 | } 86 | 87 | private void xpcheck(Player player, PlayerLevelManager playerLevelManager) { 88 | int xpneeded = this.getConfig().getInt("Levels.1.xp"); 89 | int xp = playerLevelManager.getXp(); 90 | 91 | if (xp >=xpneeded ) { 92 | player.sendMessage("§6Leveled UP!"); 93 | playerLevelManager.setLevel(1); 94 | } 95 | } 96 | 97 | private void setscore(Player player, int level, int xp) { 98 | Scoreboard scoreboard = this.getServer().getScoreboardManager().getNewScoreboard(); 99 | Objective objective = scoreboard.registerNewObjective("test", "dummy"); 100 | 101 | objective.setDisplayName("§cPlayer Level"); 102 | objective.setDisplaySlot(DisplaySlot.SIDEBAR); 103 | 104 | Score lvl = objective.getScore("Level: §a" + level); 105 | lvl.setScore(1); 106 | Score exp = objective.getScore("XP: §a" + xp); 107 | exp.setScore(0); 108 | 109 | player.setScoreboard(scoreboard); 110 | } 111 | 112 | 113 | } -------------------------------------------------------------------------------- /Episode_27/Player_Leveling/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: PreTutorial 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.pretutorial.PreTutorial 5 | description: TNT TAG 6 | 7 | commands: 8 | pre: 9 | usage: / 10 | description: Issues the main command -------------------------------------------------------------------------------- /Episode_28/Updater/src/config.yml: -------------------------------------------------------------------------------- 1 | PlayerLevels: 2 | Levels: 3 | 1: 4 | xp: 500 5 | item: coal 6 | amount: 15 -------------------------------------------------------------------------------- /Episode_28/Updater/src/me/tsccoding/pretutorial/Updater.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import org.bukkit.ChatColor; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.plugin.java.JavaPlugin; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.IOException; 9 | import java.io.InputStreamReader; 10 | import java.net.HttpURLConnection; 11 | import java.net.URL; 12 | 13 | public class Updater extends JavaPlugin implements Listener { 14 | 15 | private String key = "key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource="; 16 | 17 | @Override 18 | public void onEnable() { 19 | versionChecker(); 20 | } 21 | 22 | private void versionChecker() { 23 | try { 24 | HttpURLConnection connection = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection(); 25 | connection.setDoOutput(true); 26 | connection.setRequestMethod("POST"); 27 | connection.getOutputStream().write((key + 34743).getBytes("UTF-8")); 28 | String version = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine(); 29 | if (!version.equals("1.4")) { 30 | this.getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "You do not have the most updated version of BetterBags"); 31 | } else { 32 | this.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "BetterBags is fully updated"); 33 | } 34 | } catch (IOException e) { 35 | this.getServer().getConsoleSender().sendMessage(ChatColor.RED + "ERROR: Could not make connection to SpigotMC.org"); 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Episode_28/Updater/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: PreTutorial 2 | author: dabuseck 3 | version: 1.0 4 | main: me.tsccoding.pretutorial.PreTutorial 5 | description: TNT TAG 6 | 7 | commands: 8 | pre: 9 | usage: / 10 | description: Issues the main command -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/GoogleAuth.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | google_auth 8 | tutorial 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | com.warrenstrange 14 | googleauth 15 | 1.1.2 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/src/main/java/me/tutorial/google/GoogleMain.java: -------------------------------------------------------------------------------- 1 | package me.tutorial.google; 2 | 3 | import com.warrenstrange.googleauth.GoogleAuthenticator; 4 | import com.warrenstrange.googleauth.GoogleAuthenticatorKey; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.EventHandler; 7 | import org.bukkit.event.Listener; 8 | import org.bukkit.event.block.BlockBreakEvent; 9 | import org.bukkit.event.block.BlockPlaceEvent; 10 | import org.bukkit.event.player.AsyncPlayerChatEvent; 11 | import org.bukkit.event.player.PlayerJoinEvent; 12 | import org.bukkit.event.player.PlayerMoveEvent; 13 | import org.bukkit.plugin.java.JavaPlugin; 14 | 15 | import java.rmi.activation.ActivationSystem; 16 | import java.util.ArrayList; 17 | import java.util.UUID; 18 | 19 | public class GoogleMain extends JavaPlugin implements Listener { 20 | private ArrayList authlocked; 21 | 22 | @Override 23 | public void onEnable() { 24 | this.getServer().getPluginManager().registerEvents(this, this); 25 | authlocked = new ArrayList(); 26 | 27 | this.getConfig().options().copyDefaults(true); 28 | this.saveConfig(); 29 | } 30 | 31 | 32 | @EventHandler 33 | public void onJoin(PlayerJoinEvent event) { 34 | Player player = event.getPlayer(); 35 | 36 | if (!this.getConfig().contains("authcodes." + player.getUniqueId())) { 37 | GoogleAuthenticator gAuth = new GoogleAuthenticator(); 38 | GoogleAuthenticatorKey key = gAuth.createCredentials(); 39 | 40 | player.sendMessage("§7Your §bGoogle Auth Code §7is §a" + key.getKey()); 41 | player.sendMessage("§7You must enter this code in the Google Authenticator App before leaving the server."); 42 | 43 | this.getConfig().set("authcodes." + player.getUniqueId(), key.getKey()); 44 | this.saveConfig(); 45 | } else { 46 | authlocked.add(player.getUniqueId()); 47 | player.sendMessage("§cPlease open the Google Authenticator App and provide the six digit code."); 48 | } 49 | } 50 | 51 | private boolean playerInputCode(Player player, int code) { 52 | String secretkey = this.getConfig().getString("authcodes." + player.getUniqueId()); 53 | 54 | GoogleAuthenticator gAuth = new GoogleAuthenticator(); 55 | boolean codeisvalid = gAuth.authorize(secretkey, code); 56 | 57 | 58 | if (codeisvalid) { 59 | authlocked.remove(player.getUniqueId()); 60 | return codeisvalid; 61 | } 62 | 63 | return codeisvalid; 64 | } 65 | 66 | 67 | @EventHandler 68 | public void chat(AsyncPlayerChatEvent event) { 69 | Player player = event.getPlayer(); 70 | String message = event.getMessage(); 71 | 72 | if (authlocked.contains(player.getUniqueId())) { 73 | try { 74 | Integer code = Integer.parseInt(message); 75 | if (playerInputCode(player, code)) { 76 | authlocked.remove(player.getUniqueId()); 77 | player.sendMessage("§a*Access Granted* §bWelcome to the server!"); 78 | } else { 79 | player.sendMessage("§cIncorrect or expired code ** A code will only contain numbers **"); 80 | 81 | } 82 | } catch (Exception e) { 83 | player.sendMessage("§cIncorrect or expired code ** A code will only contain numbers **"); 84 | } 85 | event.setCancelled(true); 86 | } 87 | } 88 | 89 | @EventHandler 90 | public void move(PlayerMoveEvent event) { 91 | Player player = event.getPlayer(); 92 | if (authlocked.contains(player.getUniqueId())) { 93 | event.setCancelled(true); 94 | } 95 | } 96 | 97 | @EventHandler 98 | public void blockbreak(BlockBreakEvent event) { 99 | Player player = event.getPlayer(); 100 | if (authlocked.contains(player.getUniqueId())) { 101 | event.setCancelled(true); 102 | } 103 | } 104 | 105 | @EventHandler 106 | public void blockplace(BlockPlaceEvent event) { 107 | Player player = event.getPlayer(); 108 | if (authlocked.contains(player.getUniqueId())) { 109 | event.setCancelled(true); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | authcodes: -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: GoogleAuth 2 | version: 1.0 3 | main: me.tutorial.google.GoogleMain -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/target/classes/config.yml: -------------------------------------------------------------------------------- 1 | authcodes: -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/target/classes/me/tutorial/google/GoogleMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_29/GoogleAuth/target/classes/me/tutorial/google/GoogleMain.class -------------------------------------------------------------------------------- /Episode_29/GoogleAuth/target/classes/plugin.yml: -------------------------------------------------------------------------------- 1 | name: GoogleAuth 2 | version: 1.0 3 | main: me.tutorial.google.GoogleMain -------------------------------------------------------------------------------- /Episode_30/Sorry.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_30/Sorry.exe -------------------------------------------------------------------------------- /Episode_31/KitUpgrades/Commands.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import org.bukkit.command.Command; 4 | import org.bukkit.command.CommandExecutor; 5 | import org.bukkit.command.CommandSender; 6 | import org.bukkit.entity.Player; 7 | 8 | public class Commands implements CommandExecutor { 9 | private PreTutorial plugin = PreTutorial.getInstance(); 10 | 11 | public void onEnableMethods(){ 12 | plugin.getCommand("upgrade").setExecutor(this); 13 | } 14 | @Override 15 | public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { 16 | if(command.getName().equalsIgnoreCase("upgrade")){ 17 | if(sender instanceof Player){ 18 | Player player = (Player) sender; 19 | plugin.kits.createInventory(player); 20 | } 21 | } 22 | return true; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Episode_31/KitUpgrades/KitUpgrader.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | public class KitUpgrader { 4 | private int damagelevel; 5 | private int xp; 6 | 7 | public KitUpgrader(int damagelevel, int xp) { 8 | this.damagelevel = damagelevel; 9 | 10 | this.xp = xp; 11 | } 12 | 13 | public int getDamagelevel() { 14 | return damagelevel; 15 | } 16 | 17 | public void setDamagelevel(int damagelevel) { 18 | this.damagelevel = damagelevel; 19 | } 20 | 21 | 22 | public int getXp() { 23 | return xp; 24 | } 25 | 26 | public void setXp(int xp) { 27 | this.xp = xp; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Episode_31/KitUpgrades/Kits.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.ChatColor; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.inventory.Inventory; 7 | import org.bukkit.inventory.ItemFlag; 8 | import org.bukkit.inventory.ItemStack; 9 | import org.bukkit.Material; 10 | import org.bukkit.inventory.meta.ItemMeta; 11 | 12 | import java.util.ArrayList; 13 | 14 | public class Kits { 15 | private PreTutorial plugin = PreTutorial.getInstance(); 16 | public Inventory kitupgrade; 17 | public ItemStack damageupgrade; 18 | 19 | public void createInventory(Player player) { 20 | 21 | kitupgrade = Bukkit.createInventory(null, 9, "Kit Upgrades"); 22 | 23 | //DAMAGE ITEM 24 | damageupgrade = new ItemStack(Material.IRON_SWORD); 25 | ItemMeta meta = damageupgrade.getItemMeta(); 26 | 27 | meta.setDisplayName(ChatColor.RED + "Damage Upgrade"); 28 | 29 | ArrayList lore = new ArrayList<>(); 30 | 31 | lore.add(ChatColor.GRAY + "Each upgrade will increase"); 32 | lore.add(ChatColor.GRAY + "your damage by 2 hit points"); 33 | lore.add(""); 34 | checkLevel(damageupgrade, player, lore); 35 | 36 | meta.setLore(lore); 37 | meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); 38 | damageupgrade.setItemMeta(meta); 39 | 40 | kitupgrade.setItem(4, damageupgrade); 41 | 42 | player.openInventory(kitupgrade); 43 | } 44 | 45 | private void checkLevel(ItemStack itemStack, Player player, ArrayList lore) { 46 | KitUpgrader kitUpgrader = plugin.upgrades.get(player.getUniqueId()); 47 | 48 | if (itemStack.equals(damageupgrade)) { 49 | lore.add(ChatColor.WHITE + "Current Level: " + ChatColor.GOLD + kitUpgrader.getDamagelevel()); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Episode_31/KitUpgrades/PreTutorial.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.pretutorial; 2 | 3 | import org.bukkit.ChatColor; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 8 | import org.bukkit.event.inventory.InventoryClickEvent; 9 | import org.bukkit.event.player.PlayerJoinEvent; 10 | import org.bukkit.inventory.ItemStack; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | 13 | import java.util.HashMap; 14 | import java.util.UUID; 15 | 16 | public class PreTutorial extends JavaPlugin implements Listener { 17 | private static PreTutorial instance; 18 | public HashMap upgrades; 19 | public Commands commands; 20 | public Kits kits; 21 | 22 | @Override 23 | public void onEnable() { 24 | instance = this; 25 | commands = new Commands(); 26 | kits = new Kits(); 27 | upgrades = new HashMap<>(); 28 | 29 | commands.onEnableMethods(); 30 | this.getServer().getPluginManager().registerEvents(this, this); 31 | } 32 | 33 | @EventHandler 34 | public void join(PlayerJoinEvent event) { 35 | Player player = event.getPlayer(); 36 | upgrades.put(player.getUniqueId(), new KitUpgrader(0, 100)); 37 | } 38 | 39 | @EventHandler 40 | public void damageEvent(EntityDamageByEntityEvent event) { 41 | if (event.getDamager() instanceof Player) { 42 | Player player = (Player) event.getDamager(); 43 | KitUpgrader kitUpgrader = upgrades.get(player.getUniqueId()); 44 | 45 | event.setDamage(event.getDamage() + (kitUpgrader.getDamagelevel() * 2)); 46 | player.sendMessage(kitUpgrader.getDamagelevel() * 2 + " Damage done."); 47 | } 48 | } 49 | 50 | @EventHandler 51 | public void invenClick(InventoryClickEvent event) { 52 | ItemStack clicked = event.getCurrentItem(); 53 | if (event.getWhoClicked() instanceof Player) { 54 | Player player = (Player) event.getWhoClicked(); 55 | 56 | KitUpgrader kitUpgrader = upgrades.get(player.getUniqueId()); 57 | 58 | if (event.getInventory().equals(kits.kitupgrade)) { 59 | event.setCancelled(true); 60 | if (clicked == null | !clicked.hasItemMeta()) return; 61 | 62 | if (clicked.getItemMeta().getDisplayName().equals(kits.damageupgrade.getItemMeta().getDisplayName())) { 63 | int dmglevel = kitUpgrader.getDamagelevel(); 64 | int xp = kitUpgrader.getXp(); 65 | 66 | if (dmglevel == 0) { 67 | kitUpgrader.setDamagelevel(1); 68 | player.sendMessage(ChatColor.GOLD + "Your damage has been increased"); 69 | player.sendMessage(ChatColor.GREEN + "Costing: " + ChatColor.YELLOW + 20 + "XP"); 70 | kitUpgrader.setXp(kitUpgrader.getXp() - 20); 71 | kits.createInventory(player); 72 | return; 73 | } 74 | 75 | if (xp >= 20 * dmglevel) { 76 | kitUpgrader.setDamagelevel(dmglevel + 1); 77 | player.sendMessage(ChatColor.GOLD + "Your damage has been increased"); 78 | player.sendMessage(ChatColor.GREEN + "Costing: " + ChatColor.YELLOW + (20 * dmglevel) + "XP"); 79 | kitUpgrader.setXp(kitUpgrader.getXp() - (20 * dmglevel)); 80 | kits.createInventory(player); 81 | } else { 82 | player.sendMessage(ChatColor.RED + "You do not have enough XP"); 83 | player.closeInventory(); 84 | } 85 | } 86 | } 87 | } 88 | } 89 | 90 | public static PreTutorial getInstance() { 91 | return instance; 92 | } 93 | 94 | 95 | } -------------------------------------------------------------------------------- /Episode_32/MongoDB/MongoDB.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Episode_32/MongoDB/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.tsc-coding 8 | MongoDB 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | org.mongodb 26 | mongodb-driver 27 | 3.4.3 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Episode_32/MongoDB/src/main/java/me/tsccoding/mongodb/MongoMain.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.mongodb; 2 | 3 | import com.mongodb.MongoClient; 4 | import com.mongodb.MongoClientURI; 5 | import com.mongodb.client.MongoCollection; 6 | import com.mongodb.client.MongoDatabase; 7 | import org.bson.Document; 8 | import org.bukkit.ChatColor; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.player.PlayerJoinEvent; 13 | import org.bukkit.plugin.java.JavaPlugin; 14 | 15 | import java.util.HashMap; 16 | import java.util.UUID; 17 | 18 | public class MongoMain extends JavaPlugin implements Listener { 19 | private MongoCollection collection; 20 | 21 | private HashMap playerDataHashMap; 22 | 23 | @Override 24 | public void onEnable() { 25 | this.playerDataHashMap = new HashMap<>(); 26 | this.getServer().getPluginManager().registerEvents(this, this); 27 | 28 | String uri = "mongodb://Admin:admin@mongodb-shard-00-00-altt9.mongodb.net:27017,mongodb-shard-00-01-altt9.mongodb.net:27017,mongodb-shard-00-02-altt9.mongodb.net:27017/admin?replicaSet=MongoDB-shard-0&ssl=true"; 29 | MongoClientURI clientURI = new MongoClientURI(uri); 30 | MongoClient mongoClient = new MongoClient(clientURI); 31 | 32 | MongoDatabase mongoDatabase = mongoClient.getDatabase("MongoDB"); 33 | collection = mongoDatabase.getCollection("Minecraft"); 34 | 35 | this.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "[MONGODB] Database Connected"); 36 | } 37 | 38 | @EventHandler 39 | public void join(PlayerJoinEvent event) { 40 | Player player = event.getPlayer(); 41 | Document playerdoc = new Document("UUID", player.getUniqueId().toString()); 42 | Document found = (Document) collection.find(playerdoc).first(); 43 | if (found == null){ 44 | playerdoc.append("GOLD", 100); 45 | playerdoc.append("MAGIC", 400); 46 | collection.insertOne(playerdoc); 47 | playerDataHashMap.put(player.getUniqueId(), new PlayerData(player.getUniqueId().toString(),100,400)); 48 | this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "Player created in Database"); 49 | }else{ 50 | int gold = found.getInteger("GOLD"); 51 | int magic = found.getInteger("MAGIC"); 52 | playerDataHashMap.put(player.getUniqueId(), new PlayerData(player.getUniqueId().toString(),gold,magic)); 53 | this.getServer().getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + "Player found in Database"); 54 | 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Episode_32/MongoDB/src/main/java/me/tsccoding/mongodb/PlayerData.java: -------------------------------------------------------------------------------- 1 | package me.tsccoding.mongodb; 2 | 3 | public class PlayerData { 4 | 5 | private String uuid; 6 | private int gold; 7 | private int magic; 8 | 9 | public PlayerData(String uuid, int gold, int magic) { 10 | this.uuid = uuid; 11 | this.gold = gold; 12 | this.magic = magic; 13 | } 14 | 15 | public String getUuid() { 16 | return uuid; 17 | } 18 | 19 | public void setUuid(String uuid) { 20 | this.uuid = uuid; 21 | } 22 | 23 | public int getGold() { 24 | return gold; 25 | } 26 | 27 | public void setGold(int gold) { 28 | this.gold = gold; 29 | } 30 | 31 | public int getMagic() { 32 | return magic; 33 | } 34 | 35 | public void setMagic(int magic) { 36 | this.magic = magic; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Episode_32/MongoDB/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MongoDB_Plugin 2 | version: 1.0 3 | main: me.tsccoding.mongodb.MongoMain -------------------------------------------------------------------------------- /Episode_32/MongoDB/target/classes/me/tsccoding/mongodb/MongoMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_32/MongoDB/target/classes/me/tsccoding/mongodb/MongoMain.class -------------------------------------------------------------------------------- /Episode_32/MongoDB/target/classes/me/tsccoding/mongodb/PlayerData.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-SourceCode/Advanced_Bukkit_Coding/a02448d8cd5a8701d8eb58e4f4784a6d86b030eb/Episode_32/MongoDB/target/classes/me/tsccoding/mongodb/PlayerData.class -------------------------------------------------------------------------------- /Episode_32/MongoDB/target/classes/plugin.yml: -------------------------------------------------------------------------------- 1 | name: MongoDB_Plugin 2 | version: 1.0 3 | main: me.tsccoding.mongodb.MongoMain -------------------------------------------------------------------------------- /Episode_33/Exploding_Pigman_Summoner/src/com/alonsoaliaga/tscplugin/C01.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.ChatColor; 4 | import org.bukkit.Location; 5 | import org.bukkit.Material; 6 | import org.bukkit.entity.EntityType; 7 | import org.bukkit.entity.Pig; 8 | import org.bukkit.entity.PigZombie; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.block.BlockBreakEvent; 13 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 14 | import org.bukkit.inventory.ItemStack; 15 | import org.bukkit.metadata.FixedMetadataValue; 16 | import org.bukkit.scheduler.BukkitRunnable; 17 | 18 | public class C01 implements Listener { 19 | private Main plugin; 20 | public C01(Main main){ 21 | this.plugin = main; 22 | } 23 | @EventHandler 24 | public void onBreakBlock(BlockBreakEvent e){ 25 | if(e.getBlock().getType().equals(Material.SPONGE)){ 26 | Pig pig = (Pig)e.getBlock().getWorld().spawnEntity(e.getBlock().getLocation().add(0.5,0,0.5), EntityType.PIG); 27 | pig.setCustomName(ChatColor.translateAlternateColorCodes('&',"&f&lHit me!")); 28 | pig.setCustomNameVisible(true); 29 | pig.setMetadata("Angry",new FixedMetadataValue(plugin,"angry")); 30 | } 31 | } 32 | @EventHandler 33 | public void onDamageEntity(EntityDamageByEntityEvent e){ 34 | if(e.getEntity() instanceof Pig && e.getDamager() instanceof Player){ 35 | if(e.getEntity().hasMetadata("Angry")){ 36 | Location location = e.getEntity().getLocation(); 37 | e.getEntity().remove(); 38 | location.getWorld().strikeLightning(location); 39 | PigZombie pigZombie = (PigZombie)location.getWorld().spawnEntity(location, EntityType.PIG_ZOMBIE); 40 | pigZombie.getEquipment().setHelmet(new ItemStack(Material.DIAMOND_HELMET)); 41 | pigZombie.getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD)); 42 | pigZombie.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS)); 43 | startMinionSpawn(pigZombie,(Player)e.getDamager()); 44 | } 45 | } 46 | if(e.getDamager() instanceof PigZombie && e.getEntity() instanceof Player){ 47 | if(e.getDamager().hasMetadata("ExplodingZombie")){ 48 | e.getDamager().getWorld().createExplosion(e.getDamager().getLocation(),3,true); 49 | } 50 | } 51 | } 52 | 53 | private void startMinionSpawn(PigZombie pigZombie, Player damager) { 54 | new BukkitRunnable() { 55 | @Override 56 | public void run() { 57 | if(pigZombie.isDead()){ 58 | cancel(); 59 | return; 60 | } 61 | PigZombie babyZombie = (PigZombie)pigZombie.getLocation().getWorld().spawnEntity(pigZombie.getLocation(), EntityType.PIG_ZOMBIE); 62 | babyZombie.setAngry(true); 63 | babyZombie.setBaby(true); 64 | babyZombie.getEquipment().setHelmet(new ItemStack(Material.TNT)); 65 | babyZombie.getEquipment().setItemInHand(new ItemStack(Material.WOOD_SWORD)); 66 | babyZombie.setMetadata("ExplodingZombie",new FixedMetadataValue(plugin,"explodingzombie")); 67 | babyZombie.setTarget(damager); 68 | } 69 | }.runTaskTimer(plugin,100,100); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Episode_33/Exploding_Pigman_Summoner/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.command.ConsoleCommandSender; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.plugin.java.JavaPlugin; 7 | 8 | public class Main extends JavaPlugin implements Listener { 9 | public ConsoleCommandSender console; 10 | @Override 11 | public void onEnable() { 12 | console = Bukkit.getServer().getConsoleSender(); 13 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 14 | getServer().getPluginManager().registerEvents(new C01(this),this); 15 | } 16 | @Override 17 | public void onDisable() { 18 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Episode_33/Exploding_Pigman_Summoner/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: How to spawn a Exploding Pigman Summoner -------------------------------------------------------------------------------- /Episode_34/Boss_Skeleton/src/com/alonsoaliaga/tscplugin/C02.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.Sound; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.entity.Skeleton; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.event.block.BlockBreakEvent; 10 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 11 | import org.bukkit.inventory.ItemStack; 12 | import org.bukkit.metadata.FixedMetadataValue; 13 | import org.bukkit.potion.PotionEffect; 14 | import org.bukkit.potion.PotionEffectType; 15 | import org.bukkit.util.Vector; 16 | 17 | import java.util.concurrent.ThreadLocalRandom; 18 | 19 | public class C02 implements Listener { 20 | private Main plugin; 21 | public C02(Main main){ 22 | this.plugin = main; 23 | } 24 | @EventHandler 25 | public void onBreakBlock(BlockBreakEvent e){ 26 | if(e.getBlock().getType()== Material.SPONGE){ 27 | e.setCancelled(true); 28 | e.getBlock().setType(Material.AIR); 29 | Skeleton skeleton = e.getBlock().getWorld().spawn(e.getBlock().getLocation().add(0.5,0,0.5),Skeleton.class); 30 | skeleton.setCustomName("§8§lSkeleton Boss"); 31 | skeleton.setCustomNameVisible(true); 32 | skeleton.getEquipment().setItemInHand(new ItemStack(Material.DIAMOND_SWORD)); 33 | skeleton.getEquipment().setHelmet(new ItemStack(Material.DIAMOND_HELMET)); 34 | skeleton.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE)); 35 | skeleton.getEquipment().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS)); 36 | skeleton.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS)); 37 | skeleton.setMetadata("SkeletonKing",new FixedMetadataValue(plugin,"skeletonking")); 38 | } 39 | } 40 | @EventHandler 41 | public void onDamage(EntityDamageByEntityEvent e){ 42 | if(e.getEntity() instanceof Skeleton && e.getDamager() instanceof Player){ 43 | if(e.getEntity().hasMetadata("SkeletonKing")){ 44 | int random = ThreadLocalRandom.current().nextInt(10); 45 | if(random<5){ //0 1 2 3 4 46 | e.setCancelled(true); 47 | Player player = (Player)e.getDamager(); 48 | player.playSound(player.getLocation(), Sound.valueOf("ANVIL_LAND"),10,10); 49 | player.sendMessage("§c§lYour attack was blocked!"); 50 | } 51 | } 52 | } 53 | if(e.getDamager() instanceof Skeleton && e.getEntity() instanceof Player){ 54 | if(e.getDamager().hasMetadata("SkeletonKing")){ 55 | int random = ThreadLocalRandom.current().nextInt(10); 56 | if(random<5){ 57 | e.setCancelled(true); 58 | Player player = (Player)e.getEntity(); 59 | player.setVelocity(new Vector(0,2,0)); 60 | player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,60,2)); 61 | player.sendMessage("§4§lYou were punched into the air!"); 62 | } 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Episode_34/Boss_Skeleton/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.command.ConsoleCommandSender; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.plugin.java.JavaPlugin; 7 | 8 | public class Main extends JavaPlugin implements Listener { 9 | public ConsoleCommandSender console; 10 | @Override 11 | public void onEnable() { 12 | console = Bukkit.getServer().getConsoleSender(); 13 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 14 | getServer().getPluginManager().registerEvents(new CO2(this),this); 15 | } 16 | @Override 17 | public void onDisable() { 18 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 19 | } 20 | } -------------------------------------------------------------------------------- /Episode_34/Boss_Skeleton/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: How to spawn a Blocker Skeleton King -------------------------------------------------------------------------------- /Episode_35/How_To_Use_ProtocolLib/src/com/alonsoaliaga/tscplugin/C03.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import com.comphenix.protocol.PacketType; 4 | import com.comphenix.protocol.ProtocolLibrary; 5 | import com.comphenix.protocol.ProtocolManager; 6 | import com.comphenix.protocol.events.PacketContainer; 7 | import com.comphenix.protocol.wrappers.BlockPosition; 8 | import com.comphenix.protocol.wrappers.WrappedChatComponent; 9 | import org.bukkit.Location; 10 | import org.bukkit.Material; 11 | import org.bukkit.entity.Player; 12 | import org.bukkit.event.EventHandler; 13 | import org.bukkit.event.Listener; 14 | import org.bukkit.event.block.Action; 15 | import org.bukkit.event.player.PlayerInteractEvent; 16 | import org.bukkit.event.player.PlayerMoveEvent; 17 | 18 | import java.lang.reflect.InvocationTargetException; 19 | 20 | public class C03 implements Listener { 21 | private Main plugin; 22 | public C03(Main main){ 23 | this.plugin = main; 24 | } 25 | @EventHandler 26 | public void onMove(PlayerMoveEvent e){ 27 | Player player = e.getPlayer(); 28 | ProtocolManager pm = ProtocolLibrary.getProtocolManager(); 29 | PacketContainer packet = pm.createPacket(PacketType.Play.Server.ANIMATION); 30 | packet.getModifier().writeDefaults(); 31 | packet.getIntegers().write(0,player.getEntityId()).write(1,0); 32 | try { 33 | pm.sendServerPacket(player,packet); 34 | } catch (InvocationTargetException e1) { 35 | e1.printStackTrace(); 36 | } 37 | } 38 | @EventHandler 39 | public void onClick(PlayerInteractEvent e){ 40 | if(e.getAction() != Action.RIGHT_CLICK_BLOCK)return; 41 | Player player = e.getPlayer(); 42 | if(e.getClickedBlock().getType() == Material.WALL_SIGN){ 43 | Location loc = e.getClickedBlock().getLocation(); 44 | ProtocolManager pm = ProtocolLibrary.getProtocolManager(); 45 | PacketContainer packet = pm.createPacket(PacketType.Play.Server.UPDATE_SIGN); 46 | packet.getModifier().writeDefaults(); 47 | packet.getBlockPositionModifier().write(0,new BlockPosition(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ())); 48 | packet.getChatComponentArrays().write(0,new WrappedChatComponent[]{ 49 | WrappedChatComponent.fromText("§3§lTheSourceCode"), 50 | WrappedChatComponent.fromText("§l"+player.getName()), 51 | WrappedChatComponent.fromText("§8Suscribe!"), 52 | WrappedChatComponent.fromText("§4Suscribe!") 53 | }); 54 | try { 55 | pm.sendServerPacket(player,packet); 56 | } catch (InvocationTargetException e1) { 57 | e1.printStackTrace(); 58 | } 59 | }else if(e.getClickedBlock().getType() == Material.SIGN_POST){ 60 | Location loc = e.getClickedBlock().getLocation(); 61 | ProtocolManager pm = ProtocolLibrary.getProtocolManager(); 62 | PacketContainer packet = pm.createPacket(PacketType.Play.Server.EXPLOSION); 63 | packet.getModifier().writeDefaults(); 64 | packet.getDoubles().write(0,loc.getX()).write(1,loc.getY()).write(2,loc.getZ()); 65 | packet.getFloat().write(0,(float)3); 66 | player.getWorld().getPlayers().forEach(online->{ 67 | try { 68 | pm.sendServerPacket(online,packet); 69 | } catch (InvocationTargetException e1) { 70 | e1.printStackTrace(); 71 | } 72 | }); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /Episode_35/How_To_Use_ProtocolLib/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import com.comphenix.protocol.ProtocolManager; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.command.ConsoleCommandSender; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | 9 | public class Main extends JavaPlugin implements Listener { 10 | public ConsoleCommandSender console; 11 | public ProtocolManager protocolManager; 12 | @Override 13 | public void onEnable() { 14 | console = Bukkit.getServer().getConsoleSender(); 15 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 16 | getServer().getPluginManager().registerEvents(new CO3(this),this); 17 | } 18 | @Override 19 | public void onDisable() { 20 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 21 | } 22 | } -------------------------------------------------------------------------------- /Episode_35/How_To_Use_ProtocolLib/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: How to use ProtocolLib 6 | depend: 7 | - ProtocolLib -------------------------------------------------------------------------------- /Episode_36/How_To_Use_ProtocolLib_2/src/com/alonsoaliaga/tscplugin/C04.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import com.comphenix.protocol.PacketType; 4 | import com.comphenix.protocol.ProtocolLibrary; 5 | import com.comphenix.protocol.ProtocolManager; 6 | import com.comphenix.protocol.events.PacketContainer; 7 | import com.comphenix.protocol.wrappers.EnumWrappers; 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.Location; 10 | import org.bukkit.Material; 11 | import org.bukkit.event.EventHandler; 12 | import org.bukkit.event.Listener; 13 | import org.bukkit.event.block.BlockBreakEvent; 14 | import org.bukkit.scheduler.BukkitRunnable; 15 | 16 | import java.awt.*; 17 | import java.lang.reflect.InvocationTargetException; 18 | import java.util.concurrent.ThreadLocalRandom; 19 | 20 | public class C04 implements Listener { 21 | private Main plugin; 22 | public C04(Main main) { 23 | this.plugin = main; 24 | } 25 | @EventHandler 26 | public void onBreak(BlockBreakEvent e){ 27 | if(e.getBlock().getType()== Material.TNT){ 28 | Location loc = e.getPlayer().getLocation(); 29 | ProtocolManager pm = ProtocolLibrary.getProtocolManager(); 30 | PacketContainer packet = pm.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT); 31 | packet.getModifier().writeDefaults(); 32 | packet.getStrings().write(0,"mob.enderdragon.end"); 33 | packet.getIntegers().write(0,loc.getBlockX()*8).write(1,loc.getBlockY()*8).write(2,loc.getBlockZ()*8).write(3,10); 34 | packet.getFloat().write(0, (float)1); 35 | try { 36 | pm.sendServerPacket(e.getPlayer(),packet); 37 | } catch (InvocationTargetException e1) { 38 | e1.printStackTrace(); 39 | } 40 | }else if(e.getBlock().getType()==Material.SPONGE){ 41 | ProtocolManager pm = ProtocolLibrary.getProtocolManager(); 42 | double radius = 0.5; 43 | new BukkitRunnable() { 44 | double time = 0; 45 | @Override 46 | public void run() { 47 | if(e.getPlayer().isSneaking() || !e.getPlayer().isOnline()){ 48 | cancel(); 49 | return; 50 | } 51 | Location loc = e.getPlayer().getLocation(); 52 | double x = radius*Math.sin(time); 53 | double z = radius*Math.cos(time); 54 | PacketContainer packet = pm.createPacket(PacketType.Play.Server.WORLD_PARTICLES); 55 | packet.getModifier().writeDefaults(); 56 | packet.getParticles().write(0, EnumWrappers.Particle.HEART); 57 | packet.getFloat().write(0, (float)(loc.getX()+x)).write(1, (float)(loc.getY()+2)).write(2, (float)(loc.getZ()+z)); 58 | Bukkit.getOnlinePlayers().forEach(online->{ 59 | try { 60 | pm.sendServerPacket(online,packet); 61 | } catch (InvocationTargetException e1) { 62 | e1.printStackTrace(); 63 | } 64 | }); 65 | time+=0.1; 66 | } 67 | }.runTaskTimer(plugin,20,1); 68 | }else if(e.getBlock().getType()==Material.GLOWSTONE){ 69 | ProtocolManager pm = ProtocolLibrary.getProtocolManager(); 70 | new BukkitRunnable() { 71 | @Override 72 | public void run() { 73 | if(e.getPlayer().isSneaking()|| !e.getPlayer().isOnline()){ 74 | cancel(); 75 | return; 76 | } 77 | Color color = new Color(ThreadLocalRandom.current().nextInt(255), 78 | ThreadLocalRandom.current().nextInt(255), 79 | ThreadLocalRandom.current().nextInt(255)); 80 | Location loc = e.getPlayer().getLocation(); 81 | PacketContainer packet = pm.createPacket(PacketType.Play.Server.WORLD_PARTICLES); 82 | packet.getModifier().writeDefaults(); 83 | packet.getParticles().write(0, EnumWrappers.Particle.REDSTONE); 84 | packet.getFloat().write(0, (float) loc.getX()).write(1, (float) loc.getY()).write(2, (float) loc.getZ()) 85 | .write(3, (float)(color.getRed()/255)).write(4, (float) color.getGreen()).write(5, (float) color.getBlue()) 86 | .write(6,1F); 87 | try { 88 | pm.sendServerPacket(e.getPlayer(),packet); 89 | } catch (InvocationTargetException e1) { 90 | e1.printStackTrace(); 91 | } 92 | } 93 | }.runTaskTimer(plugin,20,1); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Episode_36/How_To_Use_ProtocolLib_2/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import com.comphenix.protocol.ProtocolManager; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.command.ConsoleCommandSender; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | 9 | public class Main extends JavaPlugin implements Listener { 10 | public ConsoleCommandSender console; 11 | public ProtocolManager protocolManager; 12 | @Override 13 | public void onEnable() { 14 | console = Bukkit.getServer().getConsoleSender(); 15 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 16 | getServer().getPluginManager().registerEvents(new CO4(this),this); 17 | } 18 | @Override 19 | public void onDisable() { 20 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 21 | } 22 | } -------------------------------------------------------------------------------- /Episode_36/How_To_Use_ProtocolLib_2/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: How to use ProtocolLib Part 2 6 | depend: 7 | - ProtocolLib -------------------------------------------------------------------------------- /Episode_37/How_to_integrate_discord/src/com/alonsoaliaga/tscplugin/C05.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import net.dv8tion.jda.core.AccountType; 4 | import net.dv8tion.jda.core.JDA; 5 | import net.dv8tion.jda.core.JDABuilder; 6 | import net.dv8tion.jda.core.entities.TextChannel; 7 | import net.dv8tion.jda.core.entities.User; 8 | import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; 9 | import net.dv8tion.jda.core.hooks.ListenerAdapter; 10 | import org.bukkit.Bukkit; 11 | import org.bukkit.event.EventHandler; 12 | import org.bukkit.event.Listener; 13 | import org.bukkit.event.player.AsyncPlayerChatEvent; 14 | 15 | import javax.security.auth.login.LoginException; 16 | 17 | public class C05 extends ListenerAdapter implements Listener { 18 | public Main plugin; 19 | public JDA jda; 20 | public C05(Main main) { 21 | this.plugin = main; 22 | startBot(); 23 | plugin.getServer().getPluginManager().registerEvents(this,plugin); 24 | jda.addEventListener(this); 25 | } 26 | private void startBot() { 27 | try { 28 | jda = new JDABuilder(AccountType.BOT).setToken(plugin.getConfig().getString("Bot.Token")).buildBlocking(); 29 | } catch (LoginException | InterruptedException e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | @EventHandler 34 | public void chatEvent(AsyncPlayerChatEvent e){ 35 | String message = e.getMessage(); 36 | TextChannel textChannel = jda.getTextChannelsByName("general-tsc",true).get(0); 37 | textChannel.sendMessage("**"+e.getPlayer().getName()+":** "+message).queue(); 38 | } 39 | 40 | @Override 41 | public void onGuildMessageReceived(GuildMessageReceivedEvent event) { 42 | if(event.getAuthor().isBot() || event.getAuthor().isFake() || event.isWebhookMessage())return; 43 | String message = event.getMessage().getContentRaw(); 44 | User user = event.getAuthor(); 45 | Bukkit.broadcastMessage("§9§l"+user.getName()+"#"+user.getDiscriminator()+": §e"+message); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Episode_37/How_to_integrate_discord/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import com.comphenix.protocol.ProtocolManager; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.command.ConsoleCommandSender; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | 9 | public class Main extends JavaPlugin implements Listener { 10 | public ConsoleCommandSender console; 11 | public ProtocolManager protocolManager; 12 | @Override 13 | public void onEnable() { 14 | console = Bukkit.getServer().getConsoleSender(); 15 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 16 | new CO5(this); 17 | } 18 | @Override 19 | public void onDisable() { 20 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 21 | } 22 | } -------------------------------------------------------------------------------- /Episode_37/How_to_integrate_discord/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: How to integrate Discord 6 | depend: 7 | - AlonsoJDA -------------------------------------------------------------------------------- /Episode_38/Discord_Minecraft_Verification_Sytem/src/com/alonsoaliaga/tscplugin/C06.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import com.alonsoaliaga.tscplugin.Trash.Token; 4 | import net.dv8tion.jda.core.AccountType; 5 | import net.dv8tion.jda.core.JDA; 6 | import net.dv8tion.jda.core.JDABuilder; 7 | import net.dv8tion.jda.core.entities.Guild; 8 | import net.dv8tion.jda.core.entities.Member; 9 | import net.dv8tion.jda.core.entities.Role; 10 | import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; 11 | import net.dv8tion.jda.core.hooks.ListenerAdapter; 12 | import org.bukkit.Bukkit; 13 | import org.bukkit.command.Command; 14 | import org.bukkit.command.CommandExecutor; 15 | import org.bukkit.command.CommandSender; 16 | import org.bukkit.entity.Player; 17 | import org.bukkit.event.EventHandler; 18 | import org.bukkit.event.Listener; 19 | import org.bukkit.event.player.PlayerJoinEvent; 20 | import org.bukkit.event.player.PlayerQuitEvent; 21 | 22 | import javax.security.auth.login.LoginException; 23 | import java.io.IOException; 24 | import java.util.*; 25 | 26 | public class C06 extends ListenerAdapter implements CommandExecutor, Listener { 27 | public Main plugin; 28 | public HashMapuuidCodeMap; 29 | public HashMapuuidIdMap; 30 | public Listverifiedmembers; 31 | public Guild guild; 32 | JDA jda; 33 | public C06(Main main) { 34 | this.plugin = main; 35 | startBot(); 36 | uuidCodeMap = new HashMap<>(); 37 | uuidIdMap = new HashMap<>(); 38 | verifiedmembers = new ArrayList<>(); 39 | jda.addEventListener(this); 40 | plugin.getServer().getPluginManager().registerEvents(this,plugin); 41 | plugin.getCommand("verify").setExecutor(this); 42 | Bukkit.getScheduler().runTaskLater(plugin,()->guild = jda.getGuilds().get(0),100L); 43 | } 44 | private void startBot() { 45 | try { 46 | jda = new JDABuilder(AccountType.BOT).setToken(Token.token).build(); 47 | } catch (LoginException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | @Override 52 | public void onGuildMessageReceived(GuildMessageReceivedEvent event) { 53 | if(event.getAuthor().isBot()||event.getAuthor().isFake()||event.isWebhookMessage())return; 54 | String[] args = event.getMessage().getContentRaw().split(" "); //!link args args args 55 | if(args[0].equalsIgnoreCase("!link")){ //!link AlonsoAliaga 56 | if(event.getMember().getRoles().stream().filter(role -> role.getName().equals("Verified")).findAny().orElse(null) != null){ 57 | event.getChannel().sendMessage(":x: **|** Error! "+event.getAuthor().getAsMention()+", you are already verified!").queue(); 58 | return; 59 | } 60 | if(uuidIdMap.values().contains(event.getAuthor().getId())){ 61 | event.getChannel().sendMessage(":x: **|** Error! "+event.getAuthor().getAsMention()+", you already have a code generated!").queue(); 62 | return; 63 | } 64 | if(args.length!=2){ 65 | event.getChannel().sendMessage(":x: **|** Error! You need to specify a player!").queue(); 66 | return; 67 | } 68 | Player target = Bukkit.getPlayer(args[1]); 69 | if(target==null){ 70 | event.getChannel().sendMessage(":x: **|** Error! The player is not online!").queue(); 71 | return; 72 | } 73 | String randomcode = new Random().nextInt(800000)+200000+"AA"; //6581446AA 74 | uuidCodeMap.put(target.getUniqueId(),randomcode); 75 | uuidIdMap.put(target.getUniqueId(),event.getAuthor().getId()); 76 | event.getAuthor().openPrivateChannel().complete().sendMessage("Hey! Your verification has been generated!\n" + 77 | "Use this command in game: ``/verify "+randomcode+"``").queue(); 78 | } 79 | } 80 | @EventHandler 81 | public void onJoin(PlayerJoinEvent e){ 82 | if(plugin.playerData.contains("Data."+e.getPlayer().getUniqueId().toString())){ 83 | verifiedmembers.add(e.getPlayer().getUniqueId()); 84 | } 85 | } 86 | @EventHandler //This is to remove the player from all lists and maps when he leaves the server. 87 | public void onQuit(PlayerQuitEvent e){ 88 | verifiedmembers.remove(e.getPlayer().getUniqueId()); 89 | uuidCodeMap.remove(e.getPlayer().getUniqueId()); 90 | uuidIdMap.remove(e.getPlayer().getUniqueId()); 91 | } 92 | @Override 93 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { // /verify randomcodeAA 94 | if(!(sender instanceof Player)){ 95 | sender.sendMessage("§cOnly players can execute this command!"); 96 | return true; 97 | } 98 | Player player = (Player) sender; 99 | if(plugin.playerData.contains("Data."+player.getUniqueId().toString())){ 100 | player.sendMessage("§cSorry! You are already verified!"); 101 | return true; 102 | } 103 | if(!uuidCodeMap.containsKey(player.getUniqueId())){ 104 | player.sendMessage("§cNot pending verification process!"); 105 | return true; 106 | } 107 | if(args.length!=1){ 108 | player.sendMessage("§cUsage: /verify [code]"); 109 | return true; 110 | } 111 | String actualcode = uuidCodeMap.get(player.getUniqueId()); 112 | if(!actualcode.equals(args[0])){ 113 | player.sendMessage("§cCode is not valid! Check again!"); 114 | return true; 115 | } 116 | String discordid = uuidIdMap.get(player.getUniqueId()); 117 | Member target = guild.getMemberById(discordid); 118 | if(target==null){ 119 | uuidCodeMap.remove(player.getUniqueId()); 120 | uuidIdMap.remove(player.getUniqueId()); 121 | player.sendMessage("§cError! It seems that you left our Discord server!"); 122 | return true; 123 | } 124 | plugin.playerData.set("Data."+player.getUniqueId().toString(),discordid); 125 | try { 126 | plugin.playerData.save(plugin.data); 127 | } catch (IOException e) { 128 | e.printStackTrace(); 129 | } 130 | uuidCodeMap.remove(player.getUniqueId()); 131 | uuidIdMap.remove(player.getUniqueId()); 132 | verifiedmembers.add(player.getUniqueId()); 133 | Role verifiedrole = guild.getRolesByName("Verified",false).get(0); 134 | guild.getController().addSingleRoleToMember(target,verifiedrole).queue(); 135 | target.getUser().openPrivateChannel().complete().sendMessage(":white_check_mark: **|** Verification successfully, you have linked your account with Mc account: "+player.getName()).queue(); 136 | player.sendMessage("§aYou have been verified correctly! You linked your account with member: "+target.getUser().getName()+"#"+target.getUser().getDiscriminator()); 137 | return true; 138 | } 139 | } -------------------------------------------------------------------------------- /Episode_38/Discord_Minecraft_Verification_Sytem/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.command.ConsoleCommandSender; 5 | import org.bukkit.configuration.InvalidConfigurationException; 6 | import org.bukkit.configuration.file.FileConfiguration; 7 | import org.bukkit.configuration.file.YamlConfiguration; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.plugin.java.JavaPlugin; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | 14 | public class Main extends JavaPlugin implements Listener { 15 | public ConsoleCommandSender console; 16 | public FileConfiguration playerData; 17 | public File data; 18 | private C06 c06; 19 | @Override 20 | public void onEnable() { 21 | console = Bukkit.getServer().getConsoleSender(); 22 | createConfig(); 23 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 24 | c06 = new C06(this); 25 | } 26 | private void createConfig() { //Simple way to create/copy a yml file from jar file. 27 | data = new File(getDataFolder() + File.separator + "data.yml"); 28 | if (!data.exists()) { 29 | console.sendMessage(org.bukkit.ChatColor.LIGHT_PURPLE + "[TSCPlugin] Creating file data.yml"); 30 | this.saveResource("data.yml", false); 31 | } 32 | playerData = new YamlConfiguration(); 33 | try { 34 | playerData.load(data); 35 | } catch (IOException | InvalidConfigurationException e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | @Override 40 | public void onDisable() { //Disconnects the bot when the plugin reloads or server is turned off. 41 | c06.jda.shutdownNow(); 42 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 43 | } 44 | } -------------------------------------------------------------------------------- /Episode_38/Discord_Minecraft_Verification_Sytem/src/data.yml: -------------------------------------------------------------------------------- 1 | #EMPTY -------------------------------------------------------------------------------- /Episode_38/Discord_Minecraft_Verification_Sytem/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: Tsc videos 6 | depend: 7 | - AlonsoJDA 8 | commands: 9 | verify: 10 | usage: /verify 11 | description: Command to verify -------------------------------------------------------------------------------- /Episode_39/Minecraft_Discord_Role_Sync/src/com/alonsoaliaga/tscplugin/C06.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import com.alonsoaliaga.tscplugin.Trash.Token; 4 | import net.dv8tion.jda.core.AccountType; 5 | import net.dv8tion.jda.core.JDA; 6 | import net.dv8tion.jda.core.JDABuilder; 7 | import net.dv8tion.jda.core.entities.Guild; 8 | import net.dv8tion.jda.core.entities.Member; 9 | import net.dv8tion.jda.core.entities.Role; 10 | import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; 11 | import net.dv8tion.jda.core.hooks.ListenerAdapter; 12 | import org.bukkit.Bukkit; 13 | import org.bukkit.command.Command; 14 | import org.bukkit.command.CommandExecutor; 15 | import org.bukkit.command.CommandSender; 16 | import org.bukkit.entity.Player; 17 | import org.bukkit.event.EventHandler; 18 | import org.bukkit.event.Listener; 19 | import org.bukkit.event.player.PlayerJoinEvent; 20 | import org.bukkit.event.player.PlayerQuitEvent; 21 | 22 | import javax.security.auth.login.LoginException; 23 | import java.io.IOException; 24 | import java.util.*; 25 | 26 | public class C06 extends ListenerAdapter implements CommandExecutor, Listener { 27 | private Main plugin; 28 | public HashMapuuidCodeMap; 29 | public HashMapuuidIdMap; 30 | public Listverifiedmembers; 31 | public Guild guild; 32 | public JDA jda; 33 | public C06(Main main) { 34 | this.plugin = main; 35 | startBot(); 36 | uuidCodeMap = new HashMap<>(); 37 | uuidIdMap = new HashMap<>(); 38 | verifiedmembers = new ArrayList<>(); 39 | jda.addEventListener(this); 40 | plugin.getServer().getPluginManager().registerEvents(this,plugin); 41 | plugin.getCommand("verify").setExecutor(this); 42 | Bukkit.getScheduler().runTaskLater(plugin,()->guild = jda.getGuilds().get(0),20L); 43 | } 44 | private void startBot() { 45 | try { 46 | jda = new JDABuilder(AccountType.BOT).setToken(Token.token).build(); 47 | } catch (LoginException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | @Override 52 | public void onGuildMessageReceived(GuildMessageReceivedEvent event) { 53 | if(event.getAuthor().isBot()||event.getAuthor().isFake()||event.isWebhookMessage())return; 54 | String[] args = event.getMessage().getContentRaw().split(" "); //!link args args args 55 | if(args[0].equalsIgnoreCase("!link")){ //!link AlonsoAliaga 56 | if(event.getMember().getRoles().stream().filter(role -> role.getName().equals("Verified")).findAny().orElse(null) != null){ 57 | event.getChannel().sendMessage(":x: **|** Error! "+event.getAuthor().getAsMention()+", you are already verified!").queue(); 58 | return; 59 | } 60 | if(uuidIdMap.values().contains(event.getAuthor().getId())){ 61 | event.getChannel().sendMessage(":x: **|** Error! "+event.getAuthor().getAsMention()+", you already have a code generated!").queue(); 62 | return; 63 | } 64 | if(args.length!=2){ 65 | event.getChannel().sendMessage(":x: **|** Error! You need to specify a player!").queue(); 66 | return; 67 | } 68 | Player target = Bukkit.getPlayer(args[1]); 69 | if(target==null){ 70 | event.getChannel().sendMessage(":x: **|** Error! The player is not online!").queue(); 71 | return; 72 | } 73 | String randomcode = new Random().nextInt(800000)+200000+"AA"; //6581446AA 74 | uuidCodeMap.put(target.getUniqueId(),randomcode); 75 | uuidIdMap.put(target.getUniqueId(),event.getAuthor().getId()); 76 | event.getAuthor().openPrivateChannel().complete().sendMessage("Hey! Your verification has been generated!\n" + 77 | "Use this command in game: ``/verify "+randomcode+"``").queue(); 78 | } 79 | } 80 | @EventHandler 81 | public void onJoin(PlayerJoinEvent e){ 82 | if(plugin.playerData.contains("Data."+e.getPlayer().getUniqueId().toString())){ 83 | verifiedmembers.add(e.getPlayer().getUniqueId()); 84 | } 85 | } 86 | @EventHandler //This is to remove the player from all lists and maps when he leaves the server. 87 | public void onQuit(PlayerQuitEvent e){ 88 | //verifiedmembers.remove(e.getPlayer().getUniqueId()); 89 | uuidCodeMap.remove(e.getPlayer().getUniqueId()); 90 | uuidIdMap.remove(e.getPlayer().getUniqueId()); 91 | } 92 | @Override 93 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { // /verify randomcodeAA 94 | if(!(sender instanceof Player)){ 95 | sender.sendMessage("§cOnly players can execute this command!"); 96 | return true; 97 | } 98 | Player player = (Player) sender; 99 | if(plugin.playerData.contains("Data."+player.getUniqueId().toString())){ 100 | player.sendMessage("§cSorry! You are already verified!"); 101 | return true; 102 | } 103 | if(!uuidCodeMap.containsKey(player.getUniqueId())){ 104 | player.sendMessage("§cNot pending verification process!"); 105 | return true; 106 | } 107 | if(args.length!=1){ 108 | player.sendMessage("§cUsage: /verify [code]"); 109 | return true; 110 | } 111 | String actualcode = uuidCodeMap.get(player.getUniqueId()); 112 | if(!actualcode.equals(args[0])){ 113 | player.sendMessage("§cCode is not valid! Check again!"); 114 | return true; 115 | } 116 | String discordid = uuidIdMap.get(player.getUniqueId()); 117 | Member target = guild.getMemberById(discordid); 118 | if(target==null){ 119 | uuidCodeMap.remove(player.getUniqueId()); 120 | uuidIdMap.remove(player.getUniqueId()); 121 | player.sendMessage("§cError! It seems that you left our Discord server!"); 122 | return true; 123 | } 124 | plugin.playerData.set("Data."+player.getUniqueId().toString(),discordid); 125 | try { 126 | plugin.playerData.save(plugin.data); 127 | } catch (IOException e) { 128 | e.printStackTrace(); 129 | } 130 | uuidCodeMap.remove(player.getUniqueId()); 131 | uuidIdMap.remove(player.getUniqueId()); 132 | verifiedmembers.add(player.getUniqueId()); 133 | Role verifiedrole = guild.getRolesByName("Verified",false).get(0); 134 | guild.getController().addSingleRoleToMember(target,verifiedrole).queue(); 135 | target.getUser().openPrivateChannel().complete().sendMessage(":white_check_mark: **|** Verification successfully, you have linked your account with Mc account: "+player.getName()).queue(); 136 | player.sendMessage("§aYou have been verified correctly! You linked your account with member: "+target.getUser().getName()+"#"+target.getUser().getDiscriminator()); 137 | return true; 138 | } 139 | } -------------------------------------------------------------------------------- /Episode_39/Minecraft_Discord_Role_Sync/src/com/alonsoaliaga/tscplugin/C07.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import net.dv8tion.jda.core.entities.Member; 4 | import net.dv8tion.jda.core.entities.Role; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.event.player.PlayerQuitEvent; 10 | 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | 15 | public class C07 implements Listener { 16 | private Main plugin; 17 | private HashMap permissionRoleMap; 18 | public C07(Main main) { 19 | this.plugin = main; 20 | permissionRoleMap = new HashMap<>(); 21 | Bukkit.getScheduler().runTaskLater(plugin, this::loadRoles,40L); 22 | Bukkit.getServer().getPluginManager().registerEvents(this,plugin); 23 | } 24 | private void loadRoles() { 25 | plugin.getConfig().getConfigurationSection("Role-sync").getKeys(false).forEach(s -> { 26 | String rolename = plugin.getConfig().getString("Role-sync."+s+".Name"); 27 | if(plugin.c06.guild.getRolesByName(rolename,false).size()>0){ 28 | plugin.console.sendMessage("§aRole "+rolename+" has been loaded!"); 29 | String permission = plugin.getConfig().getString("Role-sync."+s+".Permission"); 30 | Role role = plugin.c06.guild.getRolesByName(rolename,false).get(0); 31 | permissionRoleMap.put(permission,role); 32 | } 33 | }); 34 | } 35 | @EventHandler 36 | public void onQuit(PlayerQuitEvent e){ 37 | Player player = e.getPlayer(); 38 | if(plugin.c06.verifiedmembers.contains(player.getUniqueId())){ 39 | plugin.c06.verifiedmembers.remove(player.getUniqueId()); 40 | String discordid = plugin.playerData.getString("Data."+player.getUniqueId().toString()); 41 | Member member = plugin.c06.guild.getMemberById(discordid); 42 | if(member==null)return; 43 | List rolestoadd = new ArrayList<>(); 44 | List rolestoremove = new ArrayList<>(); 45 | List memberroles = member.getRoles(); 46 | permissionRoleMap.forEach((permission,role)->{ 47 | if(player.hasPermission(permission)){ 48 | if(!memberroles.contains(role))rolestoadd.add(role); 49 | }else{ 50 | if(memberroles.contains(role))rolestoremove.add(role); 51 | } 52 | }); 53 | if(!rolestoadd.isEmpty()){ 54 | plugin.c06.guild.getController().addRolesToMember(member,rolestoadd).queue(); 55 | } 56 | if(!rolestoremove.isEmpty()){ 57 | Bukkit.getScheduler().runTaskLater(plugin,()->plugin.c06.guild.getController().removeRolesFromMember(member,rolestoremove).queue(),20L); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Episode_39/Minecraft_Discord_Role_Sync/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.command.ConsoleCommandSender; 5 | import org.bukkit.configuration.InvalidConfigurationException; 6 | import org.bukkit.configuration.file.FileConfiguration; 7 | import org.bukkit.configuration.file.YamlConfiguration; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.plugin.java.JavaPlugin; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | 14 | public class Main extends JavaPlugin implements Listener { 15 | public ConsoleCommandSender console; 16 | public FileConfiguration playerData; 17 | public File data; 18 | public C06 c06; 19 | public C07 c07; 20 | @Override 21 | public void onEnable() { 22 | console = Bukkit.getServer().getConsoleSender(); 23 | createConfig(); 24 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 25 | c06 = new C06(this); 26 | c07 = new C07(this); 27 | } 28 | private void createConfig() { 29 | saveDefaultConfig(); 30 | data = new File(getDataFolder() + File.separator + "data.yml"); 31 | if (!data.exists()) { 32 | console.sendMessage(org.bukkit.ChatColor.LIGHT_PURPLE + "[TSCPlugin] Creating file data.yml"); 33 | this.saveResource("data.yml", false); 34 | } 35 | playerData = new YamlConfiguration(); 36 | try { 37 | playerData.load(data); 38 | } catch (IOException | InvalidConfigurationException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | @Override 43 | public void onDisable() { //Disconnects the bot when the plugin reloads or server is turned off. 44 | c06.jda.shutdownNow(); 45 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 46 | } 47 | } -------------------------------------------------------------------------------- /Episode_39/Minecraft_Discord_Role_Sync/src/config.yml: -------------------------------------------------------------------------------- 1 | #Episode 39 2 | Role-sync: 3 | vip: 4 | Permission: "alonsotscplugin.vip" 5 | Name: "VIP" 6 | vip+: 7 | Permission: "alonsotscplugin.vip+" 8 | Name: "VIP+" 9 | mvp: 10 | Permission: "alonsotscplugin.mvp" 11 | Name: "MVP" 12 | mvp+: 13 | Permission: "alonsotscplugin.mvp+" 14 | Name: "MVP+" 15 | guard: 16 | Permission: "alonsotscplugin.guard" 17 | Name: "Guard" -------------------------------------------------------------------------------- /Episode_39/Minecraft_Discord_Role_Sync/src/data.yml: -------------------------------------------------------------------------------- 1 | #EMPTY -------------------------------------------------------------------------------- /Episode_39/Minecraft_Discord_Role_Sync/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: Tsc videos 6 | depend: 7 | - AlonsoJDA 8 | commands: 9 | verify: 10 | usage: /verify 11 | description: Command to verify -------------------------------------------------------------------------------- /Episode_40/Using_LibDisguise/src/com/alonsoaliaga/tscplugin/C08.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import me.libraryaddict.disguise.DisguiseAPI; 4 | import me.libraryaddict.disguise.disguisetypes.DisguiseType; 5 | import me.libraryaddict.disguise.disguisetypes.MiscDisguise; 6 | import me.libraryaddict.disguise.disguisetypes.MobDisguise; 7 | import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; 8 | import org.bukkit.Material; 9 | import org.bukkit.command.Command; 10 | import org.bukkit.command.CommandExecutor; 11 | import org.bukkit.command.CommandSender; 12 | import org.bukkit.entity.EntityType; 13 | import org.bukkit.entity.Player; 14 | 15 | public class C08 implements CommandExecutor { 16 | private Main plugin; 17 | public C08(Main instance) { 18 | plugin = instance; 19 | plugin.getCommand("adisguise").setExecutor(this); 20 | } 21 | 22 | @Override 23 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { 24 | if(!(sender instanceof Player)){ 25 | sender.sendMessage("§cConsole cannot execute this command!"); 26 | return true; 27 | } 28 | Player player = (Player) sender; // adisguise player/mob/block OBSIDIAN, CREEPER, "AlonsoAliaga" 29 | if(args.length<2){ 30 | player.sendMessage("§cUsage: /adisguise [type] [name]"); 31 | return true; 32 | } 33 | if(args[0].equalsIgnoreCase("player")){ 34 | String name = args[1]; 35 | DisguiseAPI.disguiseToAll(player,new PlayerDisguise(name).setViewSelfDisguise(false)); 36 | player.sendMessage("§aYou disguised as '"+name+"'"); 37 | }else if(args[0].equalsIgnoreCase("mob")){ 38 | String entityname = args[1].toUpperCase(); 39 | try{ 40 | EntityType entityType = EntityType.valueOf(entityname); 41 | DisguiseAPI.disguiseToAll(player, new MobDisguise(DisguiseType.getType(entityType)).setViewSelfDisguise(false)); 42 | player.sendMessage("§aYou disguised as '"+entityType.name()+"'"); 43 | }catch (IllegalArgumentException e){ 44 | player.sendMessage("&cThat's not a valid entity type!"); 45 | return true; 46 | } 47 | }else if(args[0].equalsIgnoreCase("block")){ 48 | String materialname = args[1].toUpperCase(); 49 | try { 50 | Material material = Material.valueOf(materialname); 51 | DisguiseAPI.disguiseToAll(player, new MiscDisguise(DisguiseType.FALLING_BLOCK,material.getId()).setViewSelfDisguise(false)); 52 | player.sendMessage("§aYou disguised as '"+material.name()+"'"); 53 | }catch (IllegalArgumentException e){ 54 | player.sendMessage("§cThat's not a valid material!"); 55 | return true; 56 | } 57 | }else{ 58 | player.sendMessage("§cUsage: /adisguise [player/mob/block] [name]"); 59 | } 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Episode_40/Using_LibDisguise/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.command.ConsoleCommandSender; 5 | import org.bukkit.plugin.java.JavaPlugin; 6 | 7 | public class Main extends JavaPlugin { 8 | public ConsoleCommandSender console; 9 | public C08 c08; 10 | @Override 11 | public void onEnable() { 12 | console = Bukkit.getServer().getConsoleSender(); 13 | createConfig(); 14 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 15 | c08 = new C08(this); 16 | } 17 | private void createConfig() { 18 | saveDefaultConfig(); 19 | } 20 | @Override 21 | public void onDisable() { 22 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 23 | } 24 | } -------------------------------------------------------------------------------- /Episode_40/Using_LibDisguise/src/config.yml: -------------------------------------------------------------------------------- 1 | #Episode 40 -------------------------------------------------------------------------------- /Episode_40/Using_LibDisguise/src/data.yml: -------------------------------------------------------------------------------- 1 | #EMPTY -------------------------------------------------------------------------------- /Episode_40/Using_LibDisguise/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: Tsc videos 6 | commands: 7 | adisguise: 8 | usage: /adisguise 9 | description: Command to disguise -------------------------------------------------------------------------------- /Episode_41/PlaceholderAPI/src/com/alonsoaliaga/tscplugin/C09.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import me.clip.placeholderapi.PlaceholderAPI; 4 | import me.clip.placeholderapi.PlaceholderHook; 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.Material; 7 | import org.bukkit.OfflinePlayer; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.block.BlockBreakEvent; 12 | import org.bukkit.event.player.PlayerJoinEvent; 13 | import org.bukkit.inventory.ItemStack; 14 | import org.bukkit.inventory.meta.ItemMeta; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | import java.util.Random; 19 | import java.util.stream.Collectors; 20 | 21 | public class C09 implements Listener { 22 | private Main plugin; 23 | public C09(Main plugin){ 24 | this.plugin = plugin; 25 | registerPlaceholders(); 26 | plugin.getServer().getPluginManager().registerEvents(this,plugin); 27 | } 28 | 29 | private void registerPlaceholders() { 30 | PlaceholderAPI.registerPlaceholderHook("tscplugin", new PlaceholderHook() { 31 | @Override 32 | public String onRequest(OfflinePlayer p, String params) { 33 | if(p!=null && p.isOnline()){ 34 | return onPlaceholderRequest(p.getPlayer(),params); 35 | } 36 | return null; 37 | } 38 | 39 | @Override 40 | public String onPlaceholderRequest(Player p, String params) { 41 | if(p==null){ 42 | return null; 43 | } 44 | // %tscplugin_PARAMS% 45 | if(params.equalsIgnoreCase("creator")){ 46 | return "AlonsoAliaga"; 47 | } 48 | if(params.equalsIgnoreCase("isflying")){ 49 | return p.isFlying()?"Yes":"No"; 50 | } 51 | if(params.equalsIgnoreCase("randomuser")){ 52 | List users = Arrays.asList("AlonsoTwo","TheSourceCode","Peter","Revelation","The_SwaggerHD"); 53 | return users.get(new Random().nextInt(users.size())); 54 | } 55 | return null; 56 | } 57 | }); 58 | } 59 | 60 | @EventHandler 61 | public void onJoin(PlayerJoinEvent e){ 62 | Player p = e.getPlayer(); 63 | String newmessage = PlaceholderAPI.setPlaceholders(p,"&6¡%vault_prefix% %player_name% &6has joined the server!"); 64 | e.setJoinMessage(ChatColor.translateAlternateColorCodes('&',newmessage)); 65 | } 66 | @EventHandler 67 | public void onBreak(BlockBreakEvent e){ 68 | Player p = e.getPlayer(); 69 | ItemStack itemStack = p.getInventory().getItemInHand(); 70 | if(itemStack!=null && itemStack.getType()== Material.DIAMOND_PICKAXE){ 71 | ItemMeta itemMeta = itemStack.getItemMeta(); 72 | itemMeta.setDisplayName("§3§lTheSourceCode Pickaxe"); 73 | List lore = Arrays.asList("&7This pickaxe was forged by gods!"," &2&l&m---------------------&r ", 74 | "&7Random user: &e%tscplugin_randomuser%","&7Is flying: &c%tscplugin_isflying%", 75 | "&7Broken blocks: &6%statistic_mine_block%","&7Broken diamond ores: &b%statistic_mine_block_DIAMOND_ORE%"); 76 | itemMeta.setLore(colorize(PlaceholderAPI.setPlaceholders(p,lore))); 77 | itemStack.setItemMeta(itemMeta); 78 | } 79 | } 80 | 81 | private List colorize(List list) { 82 | return list.stream().map(line->ChatColor.translateAlternateColorCodes('&',line)).collect(Collectors.toList()); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Episode_41/PlaceholderAPI/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.command.ConsoleCommandSender; 5 | import org.bukkit.plugin.java.JavaPlugin; 6 | 7 | public class Main extends JavaPlugin { 8 | public ConsoleCommandSender console; 9 | public C09 c09; 10 | @Override 11 | public void onEnable() { 12 | console = Bukkit.getServer().getConsoleSender(); 13 | createConfig(); 14 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 15 | c09 = new C09(this); 16 | } 17 | private void createConfig() { 18 | saveDefaultConfig(); 19 | } 20 | @Override 21 | public void onDisable() { 22 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 23 | } 24 | } -------------------------------------------------------------------------------- /Episode_41/PlaceholderAPI/src/config.yml: -------------------------------------------------------------------------------- 1 | #Episode 39 -------------------------------------------------------------------------------- /Episode_41/PlaceholderAPI/src/data.yml: -------------------------------------------------------------------------------- 1 | #EMPTY -------------------------------------------------------------------------------- /Episode_41/PlaceholderAPI/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: Tsc videos 6 | depend: 7 | - PlaceholderAPI -------------------------------------------------------------------------------- /Episode_42/Making_Lucky_Blocks/src/com/alonsoaliaga/tscplugin/C10.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.Material; 5 | import org.bukkit.Sound; 6 | import org.bukkit.entity.Bat; 7 | import org.bukkit.entity.Witch; 8 | import org.bukkit.entity.Wolf; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.event.block.BlockBreakEvent; 12 | import org.bukkit.inventory.ItemStack; 13 | 14 | import java.util.Random; 15 | 16 | public class C10 implements Listener { 17 | private Main plugin; 18 | public C10(Main plugin){ 19 | this.plugin = plugin; 20 | plugin.getServer().getPluginManager().registerEvents(this,plugin); 21 | } 22 | @EventHandler 23 | public void onBreak(BlockBreakEvent e){ 24 | if(e.getBlock().getType() != Material.SPONGE)return; 25 | Location location = e.getBlock().getLocation().add(0.5,0,0.5); 26 | e.setCancelled(true); 27 | e.getBlock().setType(Material.AIR); 28 | int randomnumber = new Random().nextInt(3); //0 1 2 29 | switch (randomnumber){ 30 | case 0:{ 31 | Witch witch = location.getWorld().spawn(location, Witch.class); 32 | Bat bat = location.getWorld().spawn(location, Bat.class); 33 | location.getWorld().spawn(location, Bat.class); 34 | location.getWorld().spawn(location, Bat.class); 35 | location.getWorld().spawn(location, Bat.class); 36 | location.getWorld().spawn(location, Bat.class); 37 | bat.setPassenger(witch); 38 | break; 39 | } 40 | case 1:{ 41 | location.getWorld().spawn(location, Wolf.class); 42 | location.getWorld().dropItemNaturally(location,new ItemStack(Material.BONE,7)); 43 | e.getPlayer().playSound(location, Sound.valueOf("WOLF_GROWL"),5,1); 44 | break; 45 | } 46 | case 2:{ 47 | location.getWorld().createExplosion(location,2,true); 48 | break; 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Episode_42/Making_Lucky_Blocks/src/com/alonsoaliaga/tscplugin/Main.java: -------------------------------------------------------------------------------- 1 | package com.alonsoaliaga.tscplugin; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.command.ConsoleCommandSender; 5 | import org.bukkit.plugin.java.JavaPlugin; 6 | 7 | public class Main extends JavaPlugin { 8 | public ConsoleCommandSender console; 9 | @Override 10 | public void onEnable() { 11 | console = Bukkit.getServer().getConsoleSender(); 12 | createConfig(); 13 | console.sendMessage("[TSCPlugin] Plugin enabled!"); 14 | new C10(this); 15 | } 16 | private void createConfig() { 17 | saveDefaultConfig(); 18 | } 19 | @Override 20 | public void onDisable() { 21 | console.sendMessage("[TSCPlugin] Plugin disabled!"); 22 | } 23 | } -------------------------------------------------------------------------------- /Episode_42/Making_Lucky_Blocks/src/config.yml: -------------------------------------------------------------------------------- 1 | #Episode 39 -------------------------------------------------------------------------------- /Episode_42/Making_Lucky_Blocks/src/data.yml: -------------------------------------------------------------------------------- 1 | #EMPTY -------------------------------------------------------------------------------- /Episode_42/Making_Lucky_Blocks/src/plugin.yml: -------------------------------------------------------------------------------- 1 | name: TSCTutorial 2 | author: AlonsoAliaga 3 | version: 1.0 4 | main: com.alonsoaliaga.tscplugin.Main 5 | description: Tsc videos -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Advanced_Bukkit 2 | This will be the repository for the advanced bukkit coding series 3 | 4 | Based on past comments that have been made I have decided to create a new and seperate plugin and upload everything from the project folder. 5 | 6 | If you are having issues just always head to the "src" folder, in their you can see the code! 7 | 8 | [Stop by on YouTube to watch the series!](https://www.youtube.com/playlist?list=PLdnyVeMcpY79SNiA3tCvgTQh0xDzyOSZ5) 9 | --------------------------------------------------------------------------------