fix tossmob not working, toggle stuff

- fix tossmob not working, sorta revamp it (#259)
- make tossmob and a few other config things toggleable with /toggle (note mp44 and landmines still don't work, i'll probably try and fix those too)
- replace if else statements with switch and catch (yandere dev code type beat)
This commit is contained in:
speedxx 2020-08-06 16:05:17 -04:00
parent 880b78e528
commit 642725252b
3 changed files with 329 additions and 244 deletions

View File

@ -21,101 +21,120 @@ public class Command_toggle extends FreedomCommand
{ {
if (args.length == 0) if (args.length == 0)
{ {
msg("Available toggles: "); msg("Available toggles: \n"
msg("- waterplace"); + "- waterplace\n"
msg("- fireplace"); + "- fireplace\n"
msg("- lavaplace"); + "- lavaplace\n"
msg("- fluidspread"); + "- fluidspread\n"
msg("- lavadmg"); + "- lavadmg\n"
msg("- firespread"); + "- firespread\n"
msg("- frostwalk"); + "- frostwalk\n"
msg("- firework"); + "- firework\n"
msg("- prelog"); + "- prelog\n"
msg("- lockdown"); + "- lockdown\n"
msg("- petprotect"); + "- petprotect\n"
msg("- entitywipe"); + "- entitywipe\n"
msg("- nonuke [range] [count]"); + "- nonuke [range] [count]\n"
msg("- explosives [radius]"); + "- explosives [radius]\n"
msg("- unsafeenchs"); + "- unsafeenchs\n"
msg("- bells"); + "- bells\n"
msg("- armorstands"); + "- armorstands\n"
msg("- structureblocks"); + "- structureblocks\n"
msg("- jigsaws"); + "- jigsaws\n"
msg("- grindstones"); + "- grindstones\n"
msg("- jukeboxes"); + "- jukeboxes\n"
msg("- spawners"); + "- spawners\n"
msg("- 4chan"); + "- 4chan\n"
msg("- beehives"); + "- beehives\n"
msg("- respawnanchors"); + "- respawnanchors\n"
msg("- autotp"); + "- autotp\n"
msg("- autoclear"); + "- autoclear\n"
+ "- minecarts\n"
+ "- landmines\n"
+ "- mp44\n"
+ "- tossmob");
return false; return false;
} }
if (args[0].equalsIgnoreCase("waterplace")) switch (args[0].toLowerCase())
{
case "waterplace":
{ {
toggle("Water placement is", ConfigEntry.ALLOW_WATER_PLACE); toggle("Water placement is", ConfigEntry.ALLOW_WATER_PLACE);
return true; break;
} }
else if (args[0].equalsIgnoreCase("frostwalk"))
case "frostwalk":
{ {
toggle("Frost walker enchantment is", ConfigEntry.ALLOW_FROSTWALKER); toggle("Frost walker enchantment is", ConfigEntry.ALLOW_FROSTWALKER);
return true; break;
} }
else if (args[0].equalsIgnoreCase("fireplace"))
case "fireplace":
{ {
toggle("Fire placement is", ConfigEntry.ALLOW_FIRE_PLACE); toggle("Fire placement is", ConfigEntry.ALLOW_FIRE_PLACE);
return true; break;
} }
else if (args[0].equalsIgnoreCase("lavaplace"))
case "lavaplace":
{ {
toggle("Lava placement is", ConfigEntry.ALLOW_LAVA_PLACE); toggle("Lava placement is", ConfigEntry.ALLOW_LAVA_PLACE);
return true; break;
} }
else if (args[0].equalsIgnoreCase("fluidspread"))
case "fluidspread":
{ {
toggle("Fluid spread is", ConfigEntry.ALLOW_FLUID_SPREAD); toggle("Fluid spread is", ConfigEntry.ALLOW_FLUID_SPREAD);
return true; break;
} }
else if (args[0].equalsIgnoreCase("lavadmg"))
case "lavadmg":
{ {
toggle("Lava damage is", ConfigEntry.ALLOW_LAVA_DAMAGE); toggle("Lava damage is", ConfigEntry.ALLOW_LAVA_DAMAGE);
return true; break;
} }
else if (args[0].equalsIgnoreCase("firespread"))
case "firespread":
{ {
toggle("Fire spread is", ConfigEntry.ALLOW_FIRE_SPREAD); toggle("Fire spread is", ConfigEntry.ALLOW_FIRE_SPREAD);
plugin.gr.setGameRule(GameRuleHandler.GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()); plugin.gr.setGameRule(GameRuleHandler.GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean());
return true; break;
} }
else if (args[0].equalsIgnoreCase("prelog"))
case "prelog":
{ {
toggle("Command prelogging is", ConfigEntry.ENABLE_PREPROCESS_LOG); toggle("Command prelogging is", ConfigEntry.ENABLE_PREPROCESS_LOG);
return true; break;
} }
else if (args[0].equalsIgnoreCase("lockdown"))
case "lockdown":
{ {
boolean active = !plugin.lp.isLockdownEnabled(); boolean active = !plugin.lp.isLockdownEnabled();
plugin.lp.setLockdownEnabled(active); plugin.lp.setLockdownEnabled(active);
FUtil.adminAction(sender.getName(), (active ? "A" : "De-a") + "ctivating server lockdown", true); FUtil.adminAction(sender.getName(), (active ? "A" : "De-a") + "ctivating server lockdown", true);
return true; break;
} }
else if (args[0].equalsIgnoreCase("petprotect"))
case "petprotect":
{ {
toggle("Tamed pet protection is", ConfigEntry.ENABLE_PET_PROTECT); toggle("Tamed pet protection is", ConfigEntry.ENABLE_PET_PROTECT);
return true; break;
} }
else if (args[0].equalsIgnoreCase("entitywipe"))
case "entitywipe":
{ {
toggle("Automatic entity wiping is", ConfigEntry.AUTO_ENTITY_WIPE); toggle("Automatic entity wiping is", ConfigEntry.AUTO_ENTITY_WIPE);
return true; break;
} }
else if (args[0].equalsIgnoreCase("firework"))
case "firework":
{ {
toggle("Firework explosion is", ConfigEntry.ALLOW_FIREWORK_EXPLOSION); toggle("Firework explosion is", ConfigEntry.ALLOW_FIREWORK_EXPLOSION);
return true; break;
} }
else if (args[0].equalsIgnoreCase("nonuke"))
case "nonuke":
{ {
if (args.length >= 2) if (args.length >= 2)
{ {
@ -125,8 +144,11 @@ public class Command_toggle extends FreedomCommand
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
msg("The input provided is not a valid integer.");
return true;
} }
} }
if (args.length >= 3) if (args.length >= 3)
{ {
try try
@ -135,17 +157,22 @@ public class Command_toggle extends FreedomCommand
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
msg("The input provided is not a valid integer.");
return true;
} }
} }
toggle("Nuke monitor is", ConfigEntry.NUKE_MONITOR_ENABLED); toggle("Nuke monitor is", ConfigEntry.NUKE_MONITOR_ENABLED);
if (ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean()) if (ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean())
{ {
msg("Anti-freecam range is set to " + ConfigEntry.NUKE_MONITOR_RANGE.getDouble() + " blocks."); msg("Anti-freecam range is set to " + ConfigEntry.NUKE_MONITOR_RANGE.getDouble() + " blocks.");
msg("Block throttle rate is set to " + ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger() + " blocks destroyed per 5 seconds."); msg("Block throttle rate is set to " + ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger() + " blocks destroyed per 5 seconds.");
} }
return true; break;
} }
else if (args[0].equalsIgnoreCase("explosives"))
case "explosives":
{ {
if (args.length == 2) if (args.length == 2)
{ {
@ -159,82 +186,119 @@ public class Command_toggle extends FreedomCommand
return true; return true;
} }
} }
toggle("Explosions are", ConfigEntry.ALLOW_EXPLOSIONS); toggle("Explosions are", ConfigEntry.ALLOW_EXPLOSIONS);
if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) if (ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{ {
msg("Radius set to " + ConfigEntry.EXPLOSIVE_RADIUS.getDouble()); msg("Radius set to " + ConfigEntry.EXPLOSIVE_RADIUS.getDouble());
} }
return true; break;
} }
else if (args[0].equalsIgnoreCase("unsafeenchs"))
case "unsafeenchs":
{ {
toggle("Invalid enchantments are", ConfigEntry.ALLOW_UNSAFE_ENCHANTMENTS); toggle("Unsafe enchantments are", ConfigEntry.ALLOW_UNSAFE_ENCHANTMENTS);
return true; break;
} }
else if (args[0].equalsIgnoreCase("bells"))
case "bells":
{ {
toggle("The ringing of bells is", ConfigEntry.ALLOW_BELLS); toggle("The ringing of bells is", ConfigEntry.ALLOW_BELLS);
return true; break;
} }
else if (args[0].equalsIgnoreCase("armorstands"))
case "armorstands":
{ {
toggle("The placement of armor stands is", ConfigEntry.ALLOW_ARMOR_STANDS); toggle("The placement of armor stands is", ConfigEntry.ALLOW_ARMOR_STANDS);
return true; break;
} }
else if (args[0].equalsIgnoreCase("structureblocks"))
case "structureblocks":
{ {
toggle("Structure blocks are", ConfigEntry.ALLOW_STRUCTURE_BLOCKS); toggle("Structure blocks are", ConfigEntry.ALLOW_STRUCTURE_BLOCKS);
return true; break;
} }
else if (args[0].equalsIgnoreCase("jigsaws"))
case "jigsaws":
{ {
toggle("Jigsaws are", ConfigEntry.ALLOW_JIGSAWS); toggle("Jigsaws are", ConfigEntry.ALLOW_JIGSAWS);
return true; break;
} }
else if (args[0].equalsIgnoreCase("grindstones"))
case "grindstones":
{ {
toggle("Grindstones are", ConfigEntry.ALLOW_GRINDSTONES); toggle("Grindstones are", ConfigEntry.ALLOW_GRINDSTONES);
return true; break;
} }
else if (args[0].equalsIgnoreCase("jukeboxes"))
case "jukeboxes":
{ {
toggle("Jukeboxes are", ConfigEntry.ALLOW_JUKEBOXES); toggle("Jukeboxes are", ConfigEntry.ALLOW_JUKEBOXES);
return true; break;
} }
else if (args[0].equalsIgnoreCase("spawners"))
case "spawners":
{ {
toggle("Spawners are", ConfigEntry.ALLOW_SPAWNERS); toggle("Spawners are", ConfigEntry.ALLOW_SPAWNERS);
return true; break;
} }
else if (args[0].equalsIgnoreCase("4chan"))
case "4chan":
{ {
toggle("4chan mode is", ConfigEntry.FOURCHAN_ENABLED); toggle("4chan mode is", ConfigEntry.FOURCHAN_ENABLED);
return true; break;
} }
else if (args[0].equalsIgnoreCase("beehives"))
case "beehives":
{ {
toggle("Beehives are", ConfigEntry.ALLOW_BEEHIVES); toggle("Beehives are", ConfigEntry.ALLOW_BEEHIVES);
return true; break;
} }
else if (args[0].equalsIgnoreCase("respawnanchors"))
case "respawnanchors":
{ {
toggle("Respawn anchors are", ConfigEntry.ALLOW_RESPAWN_ANCHORS); toggle("Respawn anchors are", ConfigEntry.ALLOW_RESPAWN_ANCHORS);
return true; break;
} }
else if (args[0].equalsIgnoreCase("autotp"))
case "autotp":
{ {
toggle("Teleportation on join is", ConfigEntry.AUTO_TP); toggle("Teleportation on join is", ConfigEntry.AUTO_TP);
return true; break;
} }
else if (args[0].equalsIgnoreCase("autoclear"))
case "autoclear":
{ {
toggle("Clearing inventories on join is", ConfigEntry.AUTO_CLEAR); toggle("Clearing inventories on join is", ConfigEntry.AUTO_CLEAR);
return true; break;
} }
else
case "minecarts":
{ {
return false; toggle("Minecarts are", ConfigEntry.ALLOW_MINECARTS);
break;
} }
case "landmines":
{
toggle("Landmines are", ConfigEntry.LANDMINES_ENABLED);
break;
}
case "mp44":
{
toggle("MP44 is", ConfigEntry.MP44_ENABLED);
break;
}
case "tossmob":
{
toggle("Tossmob is", ConfigEntry.TOSSMOB_ENABLED);
break;
}
}
return true;
} }
private void toggle(final String name, final ConfigEntry entry) private void toggle(final String name, final ConfigEntry entry)
@ -245,16 +309,19 @@ public class Command_toggle extends FreedomCommand
@Override @Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{ {
if (!plugin.al.isAdmin(sender))
{
return Collections.emptyList();
}
if (args.length == 1) if (args.length == 1)
{ {
return Arrays.asList( return Arrays.asList(
"waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk", "waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk",
"firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives", "unsafeenchs", "firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives", "unsafeenchs",
"bells", "armorstands", "structureblocks", "jigsaws", "grindstones", "jukeboxes", "spawners", "4chan", "beehives", "bells", "armorstands", "structureblocks", "jigsaws", "grindstones", "jukeboxes", "spawners", "4chan", "beehives",
"respawnanchors", "autotp", "autoclear"); "respawnanchors", "autotp", "autoclear", "minecarts", "mp44", "landmines", "tossmob");
} }
return Collections.emptyList(); return Collections.emptyList();
} }
} }

View File

@ -1,9 +1,12 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -27,12 +30,17 @@ public class Command_tossmob extends FreedomCommand
return true; return true;
} }
if (args.length == 0)
{
return false;
}
FPlayer playerData = plugin.pl.getPlayer(playerSender); FPlayer playerData = plugin.pl.getPlayer(playerSender);
EntityType type = null; EntityType type = null;
if (args.length >= 1) if (args.length >= 1)
{ {
if ("off".equals(args[0])) if (args[0].equalsIgnoreCase("off"))
{ {
playerData.disableMobThrower(); playerData.disableMobThrower();
msg("MobThrower is disabled.", ChatColor.GREEN); msg("MobThrower is disabled.", ChatColor.GREEN);
@ -41,32 +49,29 @@ public class Command_tossmob extends FreedomCommand
if (args[0].equalsIgnoreCase("list")) if (args[0].equalsIgnoreCase("list"))
{ {
StringBuilder sb = new StringBuilder(); msg("Supported mobs: " + getAllMobNames(), ChatColor.GREEN);
for (EntityType loop : EntityType.values())
{
if (loop.isAlive())
{
sb.append(" ").append(DepreciationAggregator.getName_EntityType(loop));
}
}
msg("Supported mobs: " + sb.toString().trim(), ChatColor.GREEN);
return true; return true;
} }
for (EntityType loopType : EntityType.values()) for (EntityType loop : EntityType.values())
{ {
if (DepreciationAggregator.getName_EntityType(loopType).toLowerCase().equalsIgnoreCase(args[0])) if (loop != null && loop.name().equalsIgnoreCase(args[0]))
{ {
type = loopType; type = loop;
break; break;
} }
} }
if (type == null) if (type == null)
{ {
msg(args[0] + " is not a supported mob type. Using a pig instead.", ChatColor.RED); msg("Unknown entity type: " + args[0], ChatColor.RED);
msg("By the way, you can type /tossmob list to see all possible mobs.", ChatColor.RED); return true;
type = EntityType.PIG; }
if (!Groups.MOB_TYPES.contains(type))
{
msg(FUtil.formatName(type.name()) + " is an entity, however it is not a mob.", ChatColor.RED);
return true;
} }
} }
@ -77,8 +82,10 @@ public class Command_tossmob extends FreedomCommand
{ {
speed = Double.parseDouble(args[1]); speed = Double.parseDouble(args[1]);
} }
catch (NumberFormatException nfex) catch (NumberFormatException ex)
{ {
msg("The input provided is not a valid integer.");
return true;
} }
} }
@ -92,12 +99,20 @@ public class Command_tossmob extends FreedomCommand
} }
playerData.enableMobThrower(type, speed); playerData.enableMobThrower(type, speed);
msg("MobThrower is enabled. Creature: " + type + " - Speed: " + speed + ".", ChatColor.GREEN); msg("MobThrower is enabled. Mob: " + type + " - Speed: " + speed + ".", ChatColor.GREEN);
msg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN); msg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
msg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN); msg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.BONE, 1)); playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.BONE, 1));
return true; return true;
} }
public static List<String> getAllMobNames()
{
List<String> names = new ArrayList<>();
for (EntityType entityType : Groups.MOB_TYPES)
{
names.add(entityType.name());
}
return names;
}
} }

View File

@ -104,6 +104,7 @@ public class ItemFun extends FreedomService
Player player = event.getPlayer(); Player player = event.getPlayer();
Entity entity = event.getRightClicked(); Entity entity = event.getRightClicked();
FPlayer fPlayer = plugin.pl.getPlayer(player);
if (player.getInventory().getItemInMainHand().getType().equals(Material.POTATO) || entity.getType().equals(EntityType.PLAYER)) if (player.getInventory().getItemInMainHand().getType().equals(Material.POTATO) || entity.getType().equals(EntityType.PLAYER))
{ {
@ -117,12 +118,32 @@ public class ItemFun extends FreedomService
player.sendMessage("Stacked " + entity.getName()); player.sendMessage("Stacked " + entity.getName());
} }
} }
if (player.getInventory().getItemInMainHand().getType().equals(Material.BONE) || entity.getType().equals(EntityType.PLAYER))
{
if (!fPlayer.mobThrowerEnabled())
{
return;
}
Location playerLoc = player.getLocation();
Vector direction = playerLoc.getDirection().normalize();
LivingEntity livingEntity = (LivingEntity)event.getRightClicked();
EntityType entityType = livingEntity.getType();
if (!(entityType == fPlayer.mobThrowerCreature()))
{
return;
}
livingEntity.setVelocity(direction.multiply(fPlayer.mobThrowerSpeed()));
fPlayer.enqueueMob(livingEntity);
}
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamage(EntityDamageByEntityEvent event) public void onEntityDamage(EntityDamageByEntityEvent event)
{ {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof Player || !(event.getDamager() instanceof Player)) if (entity instanceof Player || !(event.getDamager() instanceof Player))
@ -160,24 +181,6 @@ public class ItemFun extends FreedomService
switch (event.getMaterial()) switch (event.getMaterial())
{ {
case BONE:
{
if (!fPlayer.mobThrowerEnabled())
{
break;
}
Location player_pos = player.getLocation();
Vector direction = player_pos.getDirection().normalize();
LivingEntity rezzed_mob = (LivingEntity)player.getWorld().spawnEntity(player_pos.add(direction.multiply(2.0)), fPlayer.mobThrowerCreature());
rezzed_mob.setVelocity(direction.multiply(fPlayer.mobThrowerSpeed()));
fPlayer.enqueueMob(rezzed_mob);
event.setCancelled(true);
break;
}
case GUNPOWDER: case GUNPOWDER:
{ {
if (!fPlayer.isMP44Armed()) if (!fPlayer.isMP44Armed())