mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-15 23:20:44 +00:00
Merge branch 'namecolors' into mc/1.20
# Conflicts: # settings.gradle.kts
This commit is contained in:
163
plugins/namecolors-paper/.gitignore
vendored
Normal file
163
plugins/namecolors-paper/.gitignore
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/java,linux,macos,windows,intellij
|
||||
|
||||
/target/
|
||||
.classpath
|
||||
.settings/**
|
||||
.project
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
.gradle
|
||||
build
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### Java ###
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
|
||||
# End of https://www.gitignore.io/api/java,linux,macos,windows,intellij
|
||||
29
plugins/namecolors-paper/LICENSE
Normal file
29
plugins/namecolors-paper/LICENSE
Normal file
@@ -0,0 +1,29 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2018, CivClassic
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
4
plugins/namecolors-paper/README.md
Normal file
4
plugins/namecolors-paper/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# NameColors
|
||||
Allow players to change their name color
|
||||
|
||||
Depends on Paper, CivModeCore, CivChat2, and Namelayer. Works with TAB custom tablist to display player names in the server tablist as well.
|
||||
18
plugins/namecolors-paper/build.gradle.kts
Normal file
18
plugins/namecolors-paper/build.gradle.kts
Normal file
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
maven("https://repo.kryptonmc.org/releases")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
|
||||
|
||||
compileOnly(project(":plugins:civmodcore-paper"))
|
||||
compileOnly(project(":plugins:namelayer-paper"))
|
||||
compileOnly(project(":plugins:civchat2-paper"))
|
||||
compileOnly("me.neznamy:tab-api:3.0.2")
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.biggestnerd.namecolors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import vg.civcraft.mc.civmodcore.inventory.gui.Clickable;
|
||||
import vg.civcraft.mc.civmodcore.inventory.gui.IClickable;
|
||||
import vg.civcraft.mc.civmodcore.inventory.gui.MultiPageView;
|
||||
import vg.civcraft.mc.civmodcore.inventory.items.ItemUtils;
|
||||
import vg.civcraft.mc.civmodcore.players.settings.PlayerSetting;
|
||||
import vg.civcraft.mc.civmodcore.players.settings.gui.MenuSection;
|
||||
|
||||
public class NameColorSetting extends PlayerSetting<ChatColor> {
|
||||
|
||||
private static Map<ChatColor, Material> colorToGui = new EnumMap<>(ChatColor.class);
|
||||
private static final String RAINBOW_PERMISSION = "namecolor.rainbow";
|
||||
private static final String COLOR_PERMISSION = "namecolor.use";
|
||||
|
||||
public static final ChatColor RAINBOW_COLOR = ChatColor.STRIKETHROUGH;
|
||||
|
||||
static {
|
||||
colorToGui.put(ChatColor.DARK_RED, Material.RED_WOOL);
|
||||
colorToGui.put(ChatColor.DARK_GREEN, Material.GREEN_WOOL);
|
||||
colorToGui.put(ChatColor.BLUE, Material.BLUE_WOOL);
|
||||
colorToGui.put(ChatColor.DARK_PURPLE, Material.PURPLE_WOOL);
|
||||
colorToGui.put(ChatColor.DARK_AQUA, Material.CYAN_WOOL);
|
||||
colorToGui.put(ChatColor.GRAY, Material.LIGHT_GRAY_WOOL);
|
||||
colorToGui.put(ChatColor.DARK_GRAY, Material.GRAY_WOOL);
|
||||
colorToGui.put(ChatColor.GREEN, Material.LIME_WOOL);
|
||||
colorToGui.put(ChatColor.YELLOW, Material.YELLOW_WOOL);
|
||||
colorToGui.put(ChatColor.AQUA, Material.LIGHT_BLUE_WOOL);
|
||||
colorToGui.put(ChatColor.GOLD, Material.YELLOW_GLAZED_TERRACOTTA);
|
||||
colorToGui.put(ChatColor.LIGHT_PURPLE, Material.MAGENTA_WOOL);
|
||||
colorToGui.put(ChatColor.RESET, Material.WHITE_WOOL);
|
||||
}
|
||||
|
||||
public NameColorSetting(JavaPlugin owningPlugin) {
|
||||
super(owningPlugin, ChatColor.RESET, "Name color", "namecolors.choser", new ItemStack(Material.RED_WOOL),
|
||||
"Lets you chose the color of your name", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor deserialize(String serial) {
|
||||
return ChatColor.valueOf(serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getGuiRepresentation(UUID player) {
|
||||
ChatColor color = getValue(player);
|
||||
ItemStack item;
|
||||
if (color == RAINBOW_COLOR) {
|
||||
item = new ItemStack(Material.YELLOW_STAINED_GLASS);
|
||||
} else {
|
||||
if (color != null) {
|
||||
item = new ItemStack(colorToGui.get(color));
|
||||
} else {
|
||||
item = new ItemStack(Material.WHITE_WOOL);
|
||||
}
|
||||
}
|
||||
applyInfoToItemStack(item, player);
|
||||
Player play = Bukkit.getPlayer(player);
|
||||
if (play != null && !play.hasPermission(COLOR_PERMISSION) && !play.hasPermission(RAINBOW_PERMISSION)) {
|
||||
ItemUtils.addLore(item, ChatColor.RED + "You do not have permission to do this");
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMenuClick(Player player, MenuSection menu) {
|
||||
List<IClickable> clicks = new ArrayList<>();
|
||||
if (player.hasPermission(COLOR_PERMISSION)) {
|
||||
|
||||
for (Entry<ChatColor, Material> entry : colorToGui.entrySet()) {
|
||||
ItemStack is = new ItemStack(entry.getValue());
|
||||
ItemUtils.setDisplayName(is,
|
||||
"Change to color of your name to " + entry.getKey() + entry.getKey().name());
|
||||
clicks.add(new Clickable(is) {
|
||||
|
||||
@Override
|
||||
public void clicked(Player p) {
|
||||
player.sendMessage(
|
||||
"The color of your name was changed to " + entry.getKey() + entry.getKey().name());
|
||||
setValue(player, entry.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (player.hasPermission(RAINBOW_PERMISSION)) {
|
||||
ItemStack is = new ItemStack(Material.YELLOW_STAINED_GLASS);
|
||||
ItemUtils.setDisplayName(is, "Change to color of your name to " + NameColors.rainbowify("rainbow"));
|
||||
clicks.add(new Clickable(is) {
|
||||
|
||||
@Override
|
||||
public void clicked(Player p) {
|
||||
player.sendMessage("The color of your name was changed to " + NameColors.rainbowify("rainbow"));
|
||||
setValue(player, RAINBOW_COLOR);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (clicks.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + "You do not have permission to change the color of your name");
|
||||
return;
|
||||
}
|
||||
MultiPageView view = new MultiPageView(player, clicks, "Select a name color", true);
|
||||
ItemStack returnStack = new ItemStack(Material.BOOK);
|
||||
ItemUtils.setDisplayName(returnStack, "Return to previous menu");
|
||||
view.setMenuSlot(new Clickable(returnStack) {
|
||||
|
||||
@Override
|
||||
public void clicked(Player p) {
|
||||
menu.showScreen(player);
|
||||
}
|
||||
}, 0);
|
||||
view.showScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(String input) {
|
||||
try {
|
||||
ChatColor color = ChatColor.valueOf(input);
|
||||
return color == RAINBOW_COLOR || colorToGui.containsKey(color);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(ChatColor value) {
|
||||
return value.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(UUID player, ChatColor value) {
|
||||
super.setValue(player, value);
|
||||
Player play = Bukkit.getPlayer(player);
|
||||
if (play != null) {
|
||||
NameColors.getInstance().updatePlayerName(play, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toText(ChatColor value) {
|
||||
return value.name();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.biggestnerd.namecolors;
|
||||
|
||||
|
||||
|
||||
import me.neznamy.tab.api.TabAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import vg.civcraft.mc.civchat2.CivChat2;
|
||||
import vg.civcraft.mc.civmodcore.ACivMod;
|
||||
import vg.civcraft.mc.civmodcore.players.settings.PlayerSettingAPI;
|
||||
|
||||
public class NameColors extends ACivMod implements Listener {
|
||||
|
||||
private static NameColors instance;
|
||||
|
||||
private static final ChatColor[] rainbow = { ChatColor.RED, ChatColor.GOLD, ChatColor.YELLOW, ChatColor.GREEN,
|
||||
ChatColor.DARK_AQUA, ChatColor.AQUA, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE };
|
||||
|
||||
public static NameColors getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static String rainbowify(String text) {
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
char[] letters = text.toCharArray();
|
||||
for (int i = 0; i < letters.length; i++) {
|
||||
nameBuilder.append(rainbow[i % rainbow.length]).append(letters[i]);
|
||||
}
|
||||
return nameBuilder.toString();
|
||||
}
|
||||
|
||||
private NameColorSetting setting;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
super.onEnable();
|
||||
setting = new NameColorSetting(this);
|
||||
PlayerSettingAPI.registerSetting(setting, PlayerSettingAPI.getMainMenu());
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
updatePlayerName(event.getPlayer(), setting.getValue(event.getPlayer()));
|
||||
}
|
||||
|
||||
public void updatePlayerName(Player player, ChatColor color) {
|
||||
if (color == null || color == ChatColor.RESET) {
|
||||
CivChat2.getInstance().getCivChat2Manager().removeCustomName(player.getUniqueId());
|
||||
if(getServer().getPluginManager().isPluginEnabled("TAB")) {
|
||||
//TAB is enabled, so lets reset the player name.
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> TabAPI.getInstance().getTablistFormatManager().resetName(TabAPI.getInstance()
|
||||
.getPlayer(player.getUniqueId())), 20l );
|
||||
}
|
||||
} else {
|
||||
if (color == NameColorSetting.RAINBOW_COLOR) {
|
||||
CivChat2.getInstance().getCivChat2Manager().setCustomName(player.getUniqueId(),
|
||||
rainbowify(player.getName()) + ChatColor.RESET);
|
||||
if(getServer().getPluginManager().isPluginEnabled("TAB")) {
|
||||
//TAB enabled, so now we need to re-apply this name as a "custom name"
|
||||
//Side note: we do this temporarily so players if they lose their permission don't keep their colored name in TAB.
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> TabAPI.getInstance().getTablistFormatManager().setName(TabAPI.getInstance()
|
||||
.getPlayer(player.getUniqueId()), rainbowify(player.getName())), 20);
|
||||
}
|
||||
return;
|
||||
}
|
||||
CivChat2.getInstance().getCivChat2Manager().setCustomName(player.getUniqueId(),
|
||||
color + player.getName() + ChatColor.RESET);
|
||||
//Same deal as for rainbow
|
||||
if(getServer().getPluginManager().isPluginEnabled("TAB")) {
|
||||
//We delay just in-case TAB hasn't loaded the player into memory yet.
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> TabAPI.getInstance().getTablistFormatManager().setName(TabAPI.getInstance()
|
||||
.getPlayer(player.getUniqueId()),color + player.getName() + ChatColor.RESET), 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
plugins/namecolors-paper/src/main/resources/plugin.yml
Normal file
20
plugins/namecolors-paper/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
name: NameColors
|
||||
main: com.biggestnerd.namecolors.NameColors
|
||||
version: ${version}
|
||||
authors: [biggestnerd, Maxopoly]
|
||||
depend: [CivModCore, CivChat2]
|
||||
softdepend:
|
||||
- TAB
|
||||
api-version: 1.17
|
||||
commands:
|
||||
namecolor:
|
||||
description: "Give your name a nice color!"
|
||||
usage: "Usage /namecolor"
|
||||
permission: namecolor.use
|
||||
permissions:
|
||||
namecolor.use:
|
||||
description: Allows you to change the color of your name
|
||||
default: op
|
||||
namecolor.rainbow:
|
||||
description: Lets you get a rainbow name
|
||||
default: op
|
||||
@@ -27,3 +27,4 @@ include(":plugins:civduties-paper")
|
||||
include(":plugins:essenceglue-paper")
|
||||
include(":plugins:hiddenore-paper")
|
||||
include(":plugins:kirabukkitgateway-paper")
|
||||
include(":plugins:namecolors-paper")
|
||||
|
||||
Reference in New Issue
Block a user