Don't hardcode join titles

This commit is contained in:
mathiascode 2019-12-01 01:04:08 +02:00
parent ddd6fa76f4
commit 3a3b450921
6 changed files with 62 additions and 26 deletions

View file

@ -650,6 +650,8 @@ public class Main extends JavaPlugin {
this.nonSolidBlockList.addAll(nonSolidDoubleBlockList);
this.nonSolidBlockList.addAll(nonSolidSingularBlockList);
this.nonSolidBlockList.addAll(nonSolidWallMountedBlockList);
saveResource("config.yml", false);
}
public void onEnable() {

View file

@ -1,5 +1,7 @@
package pw.kaboom.extras;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -7,6 +9,9 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -17,19 +22,25 @@ class CommandPrefix implements CommandExecutor {
sender.sendMessage("Command has to be run by a player");
} else {
final Player player = (Player) sender;
final JavaPlugin plugin = JavaPlugin.getPlugin(Main.class);
final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml");
final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile);
try {
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <prefix|off>");
} else if (args[0].equalsIgnoreCase("off")) {
plugin.getConfig().set(player.getUniqueId().toString(), null);
plugin.saveConfig();
prefixConfig.set(player.getUniqueId().toString(), null);
prefixConfig.save(configFile);
player.sendMessage("You no longer have a tag");
} else {
plugin.getConfig().set(player.getUniqueId().toString(), String.join(" ", args));
plugin.saveConfig();
prefixConfig.set(player.getUniqueId().toString(), String.join(" ", args));
prefixConfig.save(configFile);
player.sendMessage("You now have the tag: " + ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
}
} catch (Exception exception) {
player.sendMessage("Something went wrong while saving the prefix. Please check console.");
exception.printStackTrace();
}
}
return true;
}

View file

@ -5,12 +5,13 @@ import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Nameable;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.CommandBlock;
import org.bukkit.block.ShulkerBox;
import org.bukkit.block.data.Levelled;
@ -73,13 +74,21 @@ class BlockPhysics implements Listener {
@EventHandler
void onBlockPhysics(BlockPhysicsEvent event) {
final Material material = event.getChangedType();
final BlockState blockState = event.getSourceBlock().getState();
final BlockState blockStateSource = event.getSourceBlock().getState();
/*if (event.getSourceBlock().getBlockData().getAsString().length() > 3019) {
event.getSourceBlock().setType(Material.AIR);
} else if (event.getBlock().getBlockData().getAsString().length() > 3019) {
event.getBlock().setType(Material.AIR);
}*/
if (material == Material.FARMLAND) {
event.setCancelled(true);
} else if (event.getSourceBlock().getState() instanceof CommandBlock) {
event.getSourceBlock().getState().update();
} else if (event.getBlock().getState() instanceof CommandBlock) {
event.getBlock().getState().update();
} else if (blockState instanceof CommandBlock) {
blockState.update();
} else if (blockStateSource instanceof CommandBlock) {
blockStateSource.update();
} else if (event.getBlock().isLiquid()) {
final Block block = event.getBlock();
final World world = block.getWorld();

View file

@ -1,9 +1,13 @@
package pw.kaboom.extras;
import java.io.File;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -33,10 +37,13 @@ class PlayerChat implements Listener {
return;
}
if (JavaPlugin.getPlugin(Main.class).getConfig().getString(player.getUniqueId().toString()) != null) {
final File configFile = new File(JavaPlugin.getPlugin(Main.class).getDataFolder(), "prefixes.yml");
final FileConfiguration prefixConfig = YamlConfiguration.loadConfiguration(configFile);
if (prefixConfig.getString(player.getUniqueId().toString()) != null) {
final String prefix = ChatColor.translateAlternateColorCodes(
'&',
JavaPlugin.getPlugin(Main.class).getConfig().getString(player.getUniqueId().toString())
prefixConfig.getString(player.getUniqueId().toString())
);
event.setFormat(prefix + ChatColor.RESET + " " + player.getDisplayName().toString() + ChatColor.RESET + ": " + ChatColor.RESET + "%2$s");

View file

@ -62,6 +62,8 @@ class PlayerConnection implements Listener {
@EventHandler
void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
final String title = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinTitle");
final String subtitle = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinSubtitle");
final int fadeIn = 10;
final int stay = 160;
final int fadeOut = 5;
@ -87,14 +89,17 @@ class PlayerConnection implements Listener {
}
}
if (title != null ||
subtitle != null) {
player.sendTitle(
ChatColor.GRAY + "Welcome to Kaboom!",
"Free OP • Anarchy • Creative",
title,
subtitle,
fadeIn,
stay,
fadeOut
);
}
}
@EventHandler
void onPlayerKick(PlayerKickEvent event) {

View file

@ -0,0 +1,2 @@
playerJoinTitle: "§7Welcome to Kaboom!"
playerJoinSubtitle: "Free OP • Anarchy • Creative"