From a87c3b56b5327e351d512b5467d61e0b4c049986 Mon Sep 17 00:00:00 2001 From: Dakota Frost <37204445+icicl@users.noreply.github.com> Date: Tue, 31 May 2022 22:13:59 -0700 Subject: [PATCH] Add conscript and prolong cmds. Enchants on starting tools. Milk bucket event. --- src/BingoCommandExecutor.java | 81 +++++++++++++++++++++++++++++++---- src/BingoInventoryHelper.java | 13 ++++++ src/BingoPlayer.java | 26 +++++------ src/CHANGELOG | 11 ++++- src/GameDaemon.java | 4 ++ src/GameHelper.java | 5 ++- src/GameState.java | 7 +++ src/TODO | 25 ++++++++--- src/TabAgent.java | 11 ++++- src/TabCompletionManager.java | 10 +++++ src/config.yml | 52 +++++++++++----------- src/plugin.yml | 2 +- 12 files changed, 188 insertions(+), 59 deletions(-) diff --git a/src/BingoCommandExecutor.java b/src/BingoCommandExecutor.java index 4275c3e..1b4ef65 100644 --- a/src/BingoCommandExecutor.java +++ b/src/BingoCommandExecutor.java @@ -129,15 +129,54 @@ public boolean onCommand( if (plugin.game != null) { if (plugin.game.get_player(player) != null) { player.sendMessage( - "You are already a participant in the current bingo game." + "You are already a participant in the current bingo game." ); return true; } plugin.game.join(player); } else { player.sendMessage( - "No instance of bingo. Ask an admin to create one with §a/bingo new§f." + "No instance of bingo. Ask an admin to create one with §a/bingo new§f." + ); + } + return true; + } + if (args[0].equalsIgnoreCase("conscript")) { + if (args.length == 1) { + sender.sendMessage("/bingo conscript [player]. to add all online players, use the wildcard *"); + return true; + } + if (plugin.game == null) { + sender.sendMessage( + "No instance of bingo. Ask an admin to create one with §a/bingo new§f." ); + return true; + } + for (int i = 1; i < args.length; i++) { + if (args[i].equals("*")) { + for (Player bp : Bukkit.getOnlinePlayers()) { + if (plugin.game.get_player(bp) != null) { + sender.sendMessage( + bp.getDisplayName() + " is already a participant in the current bingo game." + ); + } else { + plugin.game.join(bp); + } + } + return true; + } + player = Bukkit.getPlayer(args[i]); + if (player == null) { + sender.sendMessage("Player " + args[i] + " was not found online."); + } else { + if (plugin.game.get_player(player) != null) { + sender.sendMessage( + args[i] + " is already a participant in the current bingo game." + ); + } else { + plugin.game.join(player); + } + } } return true; } @@ -306,14 +345,28 @@ public boolean onCommand( player.teleport( new Location( player.getWorld(), - (double) px, + (double) px + 0.5, (double) top_block.getLocation().getBlockY() + 1, - (double) pz + (double) pz + 0.5//todo ) ); player.sendMessage("Teleported you to the surface."); return true; } + if (args[0].equalsIgnoreCase("prolong")) { + if (args.length != 2) { + sender.sendMessage( + "Usage: /bingo prolong [timeInSeconds]" + ); + return true; + } + if (plugin.game == null) { + sender.sendMessage("No instance of bingo. Ask an admin to create one with §a/bingo new§f."); + return true; + } + plugin.game.prolong(Integer.parseInt(args[1])); + return true; + } if (args[0].equalsIgnoreCase("about")){ sender.sendMessage("Bingo v§c"+plugin.getDescription().getVersion()+"§f by §aicicl§f."); return true; @@ -328,10 +381,22 @@ public boolean onCommand( " creates a new bingo game, and allows players to join it." ); sender.sendMessage( - pref + - "/bingo join" + - suff + - " joins the current bingo game, if it exists and has not yet finished." + pref + + "/bingo join" + + suff + + " joins the current bingo game, if it exists and has not yet finished." + ); + sender.sendMessage( + pref + + "/bingo conscript [player]" + + suff + + " adds [player] to the current bingo game, if it exists and has not yet finished." + ); + sender.sendMessage( + pref + + "/bingo prolong [timeInSeconds]" + + suff + + " extends the duration of the current bingo game." ); sender.sendMessage( pref + diff --git a/src/BingoInventoryHelper.java b/src/BingoInventoryHelper.java index 09ed632..c9acd2e 100644 --- a/src/BingoInventoryHelper.java +++ b/src/BingoInventoryHelper.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.FurnaceInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.event.player.PlayerBucketFillEvent; public class BingoInventoryHelper implements Listener { @@ -126,6 +127,18 @@ public void invEvent6(PlayerSwapHandItemsEvent e) { } } + @EventHandler + public void onBucket(PlayerBucketFillEvent e) { + if (plugin.game == null || plugin.game.in_progress == false) { + return; + } + Player player = e.getPlayer(); + BingoPlayer bplayer = this.plugin.game.get_player(player); + if (bplayer.goals_remaining.contains(e.getItemStack().getType())) { + find_goal(bplayer, e.getItemStack().getType()); + } + } + public void find_goal(BingoPlayer bplayer, Material mat) { bplayer.find(mat); for (BingoPlayer bp : plugin.game.players) { diff --git a/src/BingoPlayer.java b/src/BingoPlayer.java index e643b29..22f784a 100644 --- a/src/BingoPlayer.java +++ b/src/BingoPlayer.java @@ -1,6 +1,8 @@ import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.Sound; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -69,11 +71,18 @@ public void respawn() { ItemStack tool; ItemMeta meta; PlayerInventory pinv=this.player.getInventory(); - for (String item:this.plugin.getConfig().getStringList("initial-items-unbreakable")){ + for (String item:this.plugin.getConfig().getConfigurationSection("initial-items-unbreakable").getKeys(false)){ tool=new ItemStack(Material.getMaterial(item.toUpperCase())); meta=tool.getItemMeta(); meta.setUnbreakable(true); tool.setItemMeta(meta); + if (this.plugin.getConfig().getConfigurationSection("initial-items-unbreakable." + item) != null) { + int level = this.plugin.getConfig().getInt("initial-items-unbreakable." + item + ".level"); + String enchant = this.plugin.getConfig().getString("initial-items-unbreakable." + item + ".enchant"); + if (Enchantment.getByKey(NamespacedKey.fromString(enchant)) != null) { + tool.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.fromString(enchant)), level); + } + } if (tool==null){ this.plugin.log(item+" not recognized as valid material."); } else { @@ -88,21 +97,6 @@ public void respawn() { pinv.addItem(tool); } } -/* tool=new ItemStack(Material.IRON_PICKAXE); - ItemMeta meta=tool.getItemMeta(); - meta.setUnbreakable(true); - tool.setItemMeta(meta); - pinv.addItem(tool); - tool=new ItemStack(Material.IRON_AXE); - tool.getItemMeta().setUnbreakable(true); - pinv.addItem(tool); - tool=new ItemStack(Material.IRON_SHOVEL); - tool.getItemMeta().setUnbreakable(true); - pinv.addItem(tool); - this.player.getInventory().addItem(new ItemStack(Material.GOLDEN_CARROT, 64));*/ - //this.player.getInventory().addItem(new ItemStack(Material.FURNACE,64)); - //this.player.getInventory().addItem(new ItemStack(Material.COAL,64)); - //this.player.getInventory().addItem(new ItemStack(Material.RAW_IRON,64)); if (this.map != null) { this.player.getInventory().setItemInOffHand(this.map); } diff --git a/src/CHANGELOG b/src/CHANGELOG index 2d93ba2..7c2ef46 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -1,6 +1,15 @@ +1.1.5 + Add /bingo conscript command, to allow for adding people who forget they have to join. + Add /bingo prolong to increase the duration of thegame mid-play + Fixed bug where milking a cow did not trigger the item collection detection function. + Added ability to put enchantments on tools, and put looting 3 on the axe and fortune 3 on the pick in the default config. +1.1.4 + Add reminder when 5:00 and 1:00 remain. Optimize loading time when making new game. + Changed /bingo card to run even if a player has a map to help with bug where when + a player is killed and their map taken by another player, the respawning player will have the killer's card. 1.1.3 Fix bug where players would remain near spawn when isolatePlayers flag was set. - Fix bug where goals would non change until plugin was restarted. + Fix bug where goals would not change until plugin was restarted. 1.1.2 When clearInventories is set to true, achievements are also cleared. 1.1.1 diff --git a/src/GameDaemon.java b/src/GameDaemon.java index 2220f95..47ed93b 100644 --- a/src/GameDaemon.java +++ b/src/GameDaemon.java @@ -63,4 +63,8 @@ public void start(int time) { this.timer = time; this.score_counter = SCORE_COUNTER + 1; } + + public void prolong(int time) { + this.timer += time; + } } diff --git a/src/GameHelper.java b/src/GameHelper.java index ff7e5d9..a94b392 100644 --- a/src/GameHelper.java +++ b/src/GameHelper.java @@ -21,14 +21,14 @@ public void give_map(BingoPlayer bplayer) { ); return; } - if ( +/* if ( bplayer.getMap() != null && bplayer.getMap().equals(bplayer.player.getInventory().getItemInOffHand()) ) { bplayer.player.sendMessage("You already have your card. Forcing inventory update."); bplayer.player.updateInventory(); return; - } + }*/ ItemStack item = new ItemStack(Material.FILLED_MAP); MapView view = Bukkit.createMap(Bukkit.getWorlds().get(0)); view.getRenderers().forEach(view::removeRenderer); @@ -37,6 +37,7 @@ public void give_map(BingoPlayer bplayer) { view.setLocked(false); MapMeta meta = (MapMeta) item.getItemMeta(); meta.setMapView(view); + meta.setDisplayName("§a" + bplayer.player.getName() + "'s bingo card§f"); item.setItemMeta(meta); PlayerInventory inventory = bplayer.player.getInventory(); inventory.setItemInOffHand(item); diff --git a/src/GameState.java b/src/GameState.java index 0487c0d..09364db 100644 --- a/src/GameState.java +++ b/src/GameState.java @@ -341,6 +341,13 @@ public void end() { plugin.game = null; } + public void prolong(int seconds) { + plugin.daemon.prolong(seconds); + for (BingoPlayer bp : players) { + bp.player.sendMessage("Game duration prolonged by " + seconds); + } + } + public void record() { } diff --git a/src/TODO b/src/TODO index e4a6b08..49837d3 100644 --- a/src/TODO +++ b/src/TODO @@ -1,13 +1,28 @@ Support Earlier Games -- should work, just need to downgrade api and test -bug with health in tab not updating on respawn +bug with health in tab not updating on respawn only for self player -read map image bitmaps from file instead of in class categories for armor/tools, and sea temple? -admin only for /bingo new? +admin only for /bingo new if ongoing game? -milk bucket +check integer args for times + +on /top preserve pitch and yaw +"run it back" button + +/bingo kick +/bingo roster + +keepinv freeze day/night option -put players in same biome? \ No newline at end of file +put players in same biome? + +teams? + +totem, but if used has penalty + +/bingo all [time] + +rejoin, start with blocks diff --git a/src/TabAgent.java b/src/TabAgent.java index 50f6758..4c0ae7d 100644 --- a/src/TabAgent.java +++ b/src/TabAgent.java @@ -1,4 +1,5 @@ import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -7,6 +8,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; public class TabAgent implements Listener { @@ -48,11 +50,16 @@ public void onJoinServer(PlayerJoinEvent e) { @EventHandler public void onRespawn(PlayerRespawnEvent e) { - updatePlayer(e.getPlayer(), 20); if (plugin.game != null && plugin.game.get_player(e.getPlayer()) != null) { e.setRespawnLocation(plugin.game.get_player(e.getPlayer()).getSpawn()); plugin.game.get_player(e.getPlayer()).respawn(); } + updatePlayer(e.getPlayer(), 20); + } + + @EventHandler + public void onWorldTransition(PlayerChangedWorldEvent e) { + updatePlayer(e.getPlayer()); } public void updatePlayer(Player player) { @@ -79,7 +86,7 @@ public void updatePlayer(Player player) { "§a" + player.getName() + " " + - health_str + + health_str + " " + ((player.getWorld().getEnvironment() == World.Environment.NORMAL) ? "§f" : ((player.getWorld().getEnvironment() == World.Environment.NETHER) ? "§4" : "§a")) + "☀" + plugin.game.get_player_score(player) ); } diff --git a/src/TabCompletionManager.java b/src/TabCompletionManager.java index e1cd81b..ffd99eb 100644 --- a/src/TabCompletionManager.java +++ b/src/TabCompletionManager.java @@ -1,5 +1,7 @@ import java.util.ArrayList; import java.util.List; + +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -14,6 +16,7 @@ public TabCompletionManager(Main plugin) { this.plugin = plugin; root_args.add("new"); root_args.add("join"); + root_args.add("conscript"); root_args.add("start"); root_args.add("card"); root_args.add("top"); @@ -89,6 +92,13 @@ public List onTabComplete( list.add("false"); return list; } + if (args[0].equalsIgnoreCase("conscript")) { + for (Player player : Bukkit.getOnlinePlayers()) { + list.add(player.getDisplayName()); + } + list.add("*"); + return list; + } } return list; } diff --git a/src/config.yml b/src/config.yml index d4b58fc..5476d40 100644 --- a/src/config.yml +++ b/src/config.yml @@ -8,15 +8,19 @@ reward-decrease-amount: 1 # by how many points the rewards are decreased bingo-set-score-to-zero: false # whether other player will no longer gain points on finding items in your bingo bingo-bonus-static: 0 # how many bonus points a bingo will award, regardless of how many points you received for said bingo's items bingo-bonus-multiplier: 1.0 # how much items in a bingo are multiplied by, will round score increase to int. this is the BONUS, so a value of 0 means - # that no dynamic bonus will be given for bingos, and a value of 2 means that all the items in a bingo will award triple points. +# that no dynamic bonus will be given for bingos, and a value of 2 means that all the items in a bingo will award triple points. initial-items-unbreakable: # players will be given these items at the start of the game, and every time they respawn. - - iron_pickaxe - - iron_axe - - iron_shovel + iron_pickaxe: + enchant: minecraft:fortune + level: 3 + iron_axe: + enchant: minecraft:looting + level: 3 + iron_shovel: + enchant: none initial-items: # players will also be given the specified amount of these items at the start of the game, and when they respawn. golden_carrot: 64 - blocks: red_: weight: [10,0] @@ -67,7 +71,7 @@ blocks: yellow_terracotta: [10,0] yellow_wool: [10,0] lime: - weight: [10,0] + weight: [2,40] lime_banner: [0,0] lime_bed: [0,0] lime_candle: [0,0] @@ -83,7 +87,7 @@ blocks: lime_terracotta: [10,0] lime_wool: [10,0] green: - weight: [10,0] + weight: [0,50] green_banner: [0,0] green_bed: [0,0] green_candle: [0,0] @@ -115,7 +119,7 @@ blocks: light_blue_terracotta: [10,0] light_blue_wool: [10,0] cyan: - weight: [10,0] + weight: [0,50] cyan_banner: [0,0] cyan_bed: [0,0] cyan_candle: [0,0] @@ -275,7 +279,7 @@ blocks: black_terracotta: [10,0] black_wool: [10,0] acacia: - weight: [5,25] + weight: [4,30] acacia_boat: [10,0] acacia_button: [0,0] acacia_door: [10,0] @@ -309,7 +313,7 @@ blocks: birch_trapdoor: [10,0] birch_wood: [0,0] dark_oak: - weight: [5,25] + weight: [4,30] dark_oak_boat: [10,0] dark_oak_button: [0,0] dark_oak_door: [10,0] @@ -360,7 +364,7 @@ blocks: oak_trapdoor: [10,0] oak_wood: [0,0] spruce: - weight: [5,25] + weight: [6,20] spruce_boat: [10,0] spruce_button: [0,0] spruce_door: [10,0] @@ -408,12 +412,12 @@ blocks: flower: weight: [10,0] red_tulip: [10,0] - orange_tulip: [4,0] - blue_orchid: [6,0] - pink_tulip: [4,0] - allium: [4,0] - white_tulip: [4,0] - blue_ice: [0,0] + orange_tulip: [10,0] + blue_orchid: [10,0] + pink_tulip: [10,0] + allium: [10,0] + white_tulip: [10,0] + blue_ice: [0,0] brown_mushroom: [10,0] brown_mushroom_block: [0,0] activator_rail: [10,0] @@ -431,7 +435,7 @@ blocks: azalea_leaves: [0,0] azure_bluet: [10,0] baked_potato: [2,40] - bamboo: [0,50] + bamboo: [4,30] bamboo_sapling: [0,0] barrel: [10,0] basalt: [0,50] @@ -475,7 +479,7 @@ blocks: bubble_coral_fan: [0,0] bucket: [10,0] budding_amethyst: [0,0] - cactus: [10,0] + cactus: [3,35] cake: [0,50] calcite: [10,0] campfire: [10,0] @@ -533,7 +537,7 @@ blocks: composter: [10,0] conduit: [0,0] contents: [0,0] - cooked_rabbit: [10,0] + cooked_rabbit: [2,40] cookie: [0,50] copper_block: [10,0] copper_ingot: [10,0] @@ -792,7 +796,7 @@ blocks: mossy_stone_brick_wall: [0,0] mossy_stone_bricks: [0,50] mushroom_stem: [0,0] - mushroom_stew: [10,0] + mushroom_stew: [3,35] mutton: [10,0] mycelium: [0,0] nautilus_shell: [0,0] @@ -923,9 +927,9 @@ blocks: quartz_pillar: [0,50] quartz_slab: [0,0] quartz_stairs: [0,0] - rabbit: [5,25] - rabbit_hide: [5,25] - rabbit_stew: [0,30] + rabbit: [2,40] + rabbit_hide: [2,40] + rabbit_stew: [2,40] rail: [10,0] raw_copper: [10,0] raw_copper_block: [10,0] diff --git a/src/plugin.yml b/src/plugin.yml index ed25bca..4e39c5a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: Bingo # the name of the plugin. -version: 1.1.2 # the version of the plugin. +version: 1.1.5 # the version of the plugin. main: Main # the main class of the plugin. author: icicl api-version: 1.13