mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-03 18:47:43 +01:00
Fix typos in config
Add option to add command cooldown to every player that joins the server Add option to limit the backpack to certain game-modes
This commit is contained in:
parent
cea7476511
commit
b28a19b7d7
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>MinePacks</artifactId>
|
||||
<version>1.16.4.1</version>
|
||||
<version>1.16.4.2-SNAPSHOT</version>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>
|
||||
@ -50,7 +50,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>Bukkit_Bungee_PluginLib</artifactId>
|
||||
<artifactId>PluginLib</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -4,26 +4,30 @@
|
||||
# Language to use, will load the file: /plugins/Minepacks/lang/<your language setting>.yml
|
||||
Language: en
|
||||
# How outdated language files should be treated. Overwrite/Update
|
||||
# Overwrite = old language file will be replaced with new, use this only if you use the language files suplyed from the plugin
|
||||
# Overwrite = old language file will be replaced with new, use this only if you use the language files supplied from the plugin
|
||||
# Update = the old language file will be updated with the new english messages, all your changes to the file will survive the update
|
||||
LanguageUpdateMode: Overwrite
|
||||
|
||||
# Title to be showen for the opened inventory for everyone except the owner of the backpack. Can contain {OwnerName} (which will be replaced with the players name).
|
||||
# Title to be shown for the opened inventory for everyone except the owner of the backpack. Can contain {OwnerName} (which will be replaced with the players name).
|
||||
BackpackTitleOther: "&b{OwnerName}'s Backpack"
|
||||
# The title of the inventory for the owner of the backpack.
|
||||
BackpackTitle: "&bBackpack"
|
||||
# Defines how long a player have to wait till he can reopen his backpack.
|
||||
# Time is in seconds. Values < 1 disable the cooldown.
|
||||
command_cooldown: -1
|
||||
# Defines if the content of the backpack get droped on the death of a player.
|
||||
# The cooldown will be applied to every player joining the server. Values < 1 disable the join cooldown.
|
||||
command_cooldown_after_join: -1
|
||||
# Defines if the content of the backpack get dropped on the death of a player.
|
||||
# If enabled, it can be disabled for individual players with the "backpack.KeepOnDeath" permission.
|
||||
drop_on_death: true
|
||||
# Defines if the message that the backpack has been closed should be shown
|
||||
show_close_message: false
|
||||
# Defines the max amount of colums for a backpack
|
||||
# Defines the max amount of columns for a backpack
|
||||
max_size: 6
|
||||
# Defines in which game-modes a player can access his backpack
|
||||
allowed_game_modes: [ "SURVIVAL" ]
|
||||
|
||||
# Controlls for the auto pickup on full inventory function
|
||||
# Controls for the auto pickup on full inventory function
|
||||
full_inventory:
|
||||
# If items should be collected to the backpack if the players inventory is full
|
||||
collect_items: false
|
||||
@ -37,16 +41,16 @@ full_inventory:
|
||||
Database:
|
||||
# Database type. MySQL, SQLite or Files
|
||||
Type: SQLite
|
||||
# Turn off if you want to use player ids created from an other plugin. When using shared tables please check the tables sellection
|
||||
# Turn off if you want to use player ids created from an other plugin. When using shared tables please check the tables selection
|
||||
UpdatePlayer: true
|
||||
# Auto database cleanup settings
|
||||
AutoCleanup:
|
||||
# Defines the max amount of days backpacks will be stored. -1 to disable auto cleanup
|
||||
MaxInactiveDays: -1
|
||||
# If you would like to use UUIDs, it is recomendet not to change this setting unless you know what you are doing!
|
||||
# If you would like to use UUIDs, it is recommended not to change this setting unless you know what you are doing!
|
||||
# true: Only to use if your server is running in online mode and your minecraft version is 1.7.5 or newer
|
||||
# false: In offline mode or for minecraft version below 1.7.5
|
||||
# Should be configured automaticaly based on your minecraft version and online mode settings
|
||||
# Should be configured automatically based on your minecraft version and online mode settings
|
||||
# If you are using BungeeCord please set this setting based on your BungeeCord's online mode!!!
|
||||
UseUUIDs: true
|
||||
# Defines the storage format for UUIDs for compatibility with other plugins (shared tables)
|
||||
@ -60,19 +64,19 @@ Database:
|
||||
User: minecraft
|
||||
Password: minecraft
|
||||
#The max amount of connections to the database the connection pool will open
|
||||
MaxConnections: 4
|
||||
MaxConnections: 2
|
||||
# Tables settings for shared tables when using MySQL - Advanced MySQL Settings
|
||||
# Use these settings only if you know what you are doing!!!!
|
||||
# Do only change this settings if you know what you are doing and have some basic MySQL knowlage!!!
|
||||
# Changing settings down here after you have used this plugin may result in data inconsitency!!!
|
||||
# Do only change this settings if you know what you are doing and have some basic MySQL knowledge!!!
|
||||
# Changing settings down here after you have used this plugin may result in data inconsistency!!!
|
||||
Tables:
|
||||
# Table names
|
||||
# Don't change the players table if you have backpacks stored in your database already! Player id's might wont match anymore resulting data inconsitency.
|
||||
# Don't change the players table if you have backpacks stored in your database already! Player id's might wont match anymore resulting data inconsistency.
|
||||
User: backpack_players
|
||||
Backpack: backpacks
|
||||
# Field settings for the tables
|
||||
# Do not change them after the tables have been generated!
|
||||
# If you like to change them after the tables have been generated alter the tables manualy or delete them (the system then will regenerate them).
|
||||
# If you like to change them after the tables have been generated alter the tables manually or delete them (the system then will regenerate them).
|
||||
Fields:
|
||||
User:
|
||||
Player_ID: player_id
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: ${project.name}
|
||||
author: GeorgH93
|
||||
website: http://dev.bukkit.org/bukkit-plugins/minepacks/
|
||||
main: at.pcgamingfreaks.MinePacks.MinePacks
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
description: ${project.description}
|
||||
version: ${project.version}
|
||||
commands:
|
||||
@ -80,4 +80,7 @@ permissions:
|
||||
default: op
|
||||
backpack.noCooldown:
|
||||
description: Allows to bypass the cooldown to open the backpack.
|
||||
default: op
|
||||
backpack.ignoreGameMode:
|
||||
description: Allows to bypass the game-mode restriction.
|
||||
default: op
|
@ -21,8 +21,12 @@
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
public class Config extends Configuration
|
||||
@ -164,9 +168,50 @@ public boolean getAutoUpdate()
|
||||
return config.getBoolean("auto-update", true);
|
||||
}
|
||||
|
||||
public int getCommandCooldown()
|
||||
public long getCommandCooldown()
|
||||
{
|
||||
return config.getInt("command_cooldown", -1) * 1000;
|
||||
return config.getInt("command_cooldown", -1) * 1000L;
|
||||
}
|
||||
|
||||
public long getCommandCooldownAfterJoin()
|
||||
{
|
||||
return config.getInt("command_cooldown_after_join", -1) * 1000L;
|
||||
}
|
||||
|
||||
public Collection<GameMode> getAllowedGameModes()
|
||||
{
|
||||
Collection<GameMode> gameModes = new HashSet<>();
|
||||
for(String string : config.getStringList("allowed_game_modes", new LinkedList<String>()))
|
||||
{
|
||||
GameMode gm = null;
|
||||
try
|
||||
{
|
||||
//noinspection deprecation
|
||||
gm = GameMode.getByValue(Integer.valueOf(string));
|
||||
}
|
||||
catch(NumberFormatException ignored) {}
|
||||
if(gm == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
gm = GameMode.valueOf(string.toUpperCase());
|
||||
}
|
||||
catch(IllegalArgumentException ignored)
|
||||
{
|
||||
logger.warning("Unknown game-mode '" + string + "'");
|
||||
}
|
||||
}
|
||||
if(gm != null)
|
||||
{
|
||||
gameModes.add(gm);
|
||||
}
|
||||
}
|
||||
if(gameModes.size() < 1)
|
||||
{
|
||||
logger.info("No game-mode allowed, allowing " + GameMode.SURVIVAL.name());
|
||||
gameModes.add(GameMode.SURVIVAL);
|
||||
}
|
||||
return gameModes;
|
||||
}
|
||||
|
||||
public boolean getShowCloseMessage()
|
||||
|
@ -21,7 +21,6 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
@ -56,10 +55,11 @@ public Files(MinePacks mp)
|
||||
private void CheckFiles()
|
||||
{
|
||||
File[] allFiles = saveFolder.listFiles(new BackpackFileFilter());
|
||||
if(allFiles == null) return;
|
||||
int len;
|
||||
for (File file : allFiles)
|
||||
{
|
||||
if(maxAge > 0 && (new Date()).getTime() - file.lastModified() > maxAge) // Check if the file is older then x days
|
||||
if(maxAge > 0 && System.currentTimeMillis() - file.lastModified() > maxAge) // Check if the file is older then x days
|
||||
{
|
||||
file.delete(); // Delete old files
|
||||
continue; // We don't have to check if the file name is correct cause we have the deleted the file
|
||||
|
@ -20,6 +20,7 @@
|
||||
import at.pcgamingfreaks.MinePacks.Database.Database;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -32,8 +33,8 @@
|
||||
public class EventListener implements Listener
|
||||
{
|
||||
private MinePacks plugin;
|
||||
private boolean drop_on_death, showCloseMessageOwn, showCloseMessageOther;
|
||||
|
||||
private boolean drop_on_death, showCloseMessageOwn, showCloseMessageOther, onJoinCooldown;
|
||||
private long joinCooldown;
|
||||
private String message_OwnBPClose, message_PlayerBPClose;
|
||||
|
||||
public EventListener(MinePacks mp)
|
||||
@ -44,6 +45,8 @@ public EventListener(MinePacks mp)
|
||||
message_PlayerBPClose = plugin.lang.getTranslated("Ingame.PlayerBackPackClose");
|
||||
showCloseMessageOther = message_PlayerBPClose != null && plugin.config.getShowCloseMessage();
|
||||
showCloseMessageOwn = message_OwnBPClose != null && plugin.config.getShowCloseMessage();
|
||||
joinCooldown = plugin.config.getCommandCooldownAfterJoin();
|
||||
onJoinCooldown = joinCooldown > 0;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -111,7 +114,7 @@ public void onClose(InventoryCloseEvent event)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getInventory() != null && event.getInventory().getHolder() instanceof Backpack && event.getWhoClicked() instanceof Player)
|
||||
@ -128,10 +131,14 @@ public void onClick(InventoryClickEvent event)
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerLoginEvent(PlayerJoinEvent event)
|
||||
{
|
||||
plugin.DB.updatePlayerAndLoadBackpack(event.getPlayer());
|
||||
if(onJoinCooldown)
|
||||
{
|
||||
plugin.cooldowns.put(event.getPlayer(), joinCooldown);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -17,33 +17,35 @@
|
||||
|
||||
package at.pcgamingfreaks.MinePacks;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import at.pcgamingfreaks.MinePacks.Database.Database;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class OnCommand implements CommandExecutor
|
||||
{
|
||||
private MinePacks plugin;
|
||||
|
||||
public String Message_NotFromConsole, Message_NoPermission, Message_BackpackCleaned, Message_Cooldown;
|
||||
|
||||
public int cooldown;
|
||||
private final MinePacks plugin;
|
||||
private final String messageNotFromConsole, messageNoPermission, messageBackpackCleaned, messageCooldown, messageWrongGameMode;
|
||||
private final long cooldown;
|
||||
private final Collection<GameMode> gameModes;
|
||||
|
||||
public OnCommand(MinePacks mp)
|
||||
{
|
||||
plugin = mp;
|
||||
Message_NotFromConsole = plugin.lang.getTranslated("Console.NotFromConsole");
|
||||
Message_NoPermission = ChatColor.RED + plugin.lang.getTranslated("Ingame.NoPermission");
|
||||
Message_BackpackCleaned = ChatColor.DARK_GREEN + plugin.lang.getTranslated("Ingame.BackpackCleaned");
|
||||
Message_Cooldown = ChatColor.DARK_GREEN + plugin.lang.getTranslated("Ingame.Cooldown");
|
||||
messageNotFromConsole = plugin.lang.getTranslated("Console.NotFromConsole");
|
||||
messageNoPermission = ChatColor.RED + plugin.lang.getTranslated("Ingame.NoPermission");
|
||||
messageBackpackCleaned = ChatColor.DARK_GREEN + plugin.lang.getTranslated("Ingame.BackpackCleaned");
|
||||
messageCooldown = ChatColor.DARK_GREEN + plugin.lang.getTranslated("Ingame.Cooldown");
|
||||
messageWrongGameMode = ChatColor.RED + plugin.lang.getTranslated("Ingame.WrongGameMode");
|
||||
cooldown = plugin.config.getCommandCooldown();
|
||||
gameModes = plugin.config.getAllowedGameModes();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -57,7 +59,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(Message_NotFromConsole);
|
||||
sender.sendMessage(messageNotFromConsole);
|
||||
return true;
|
||||
}
|
||||
if(args.length == 0)
|
||||
@ -65,23 +67,30 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
|
||||
// Open player backpack
|
||||
if(player.hasPermission("backpack"))
|
||||
{
|
||||
if(cooldown > 0 && !player.hasPermission("backpack.noCooldown"))
|
||||
if(gameModes.contains(player.getGameMode()) || player.hasPermission("backpack.ignoreGameMode"))
|
||||
{
|
||||
if(plugin.cooldowns.containsKey(player))
|
||||
if(cooldown > 0 && !player.hasPermission("backpack.noCooldown"))
|
||||
{
|
||||
if(((new Date()).getTime() - plugin.cooldowns.get(player)) < cooldown)
|
||||
if(plugin.cooldowns.containsKey(player))
|
||||
{
|
||||
sender.sendMessage(Message_Cooldown);
|
||||
return true;
|
||||
if((System.currentTimeMillis() - plugin.cooldowns.get(player)) < cooldown)
|
||||
{
|
||||
sender.sendMessage(messageCooldown);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
plugin.cooldowns.put(player, System.currentTimeMillis());
|
||||
}
|
||||
plugin.cooldowns.put(player, (new Date()).getTime());
|
||||
plugin.openBackpack(player, player, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(messageWrongGameMode);
|
||||
}
|
||||
plugin.openBackpack(player, player, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(Message_NoPermission);
|
||||
player.sendMessage(messageNoPermission);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -111,7 +120,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(Message_NoPermission);
|
||||
player.sendMessage(messageNoPermission);
|
||||
}
|
||||
break;
|
||||
case "empty": // Removes all items from the backpack
|
||||
@ -129,7 +138,7 @@ public void onResult(Backpack backpack)
|
||||
{
|
||||
backpack.getInventory().clear();
|
||||
backpack.save();
|
||||
player.sendMessage(Message_BackpackCleaned);
|
||||
player.sendMessage(messageBackpackCleaned);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -146,7 +155,7 @@ public void onFail()
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(Message_NoPermission);
|
||||
player.sendMessage(messageNoPermission);
|
||||
}
|
||||
break;
|
||||
default: // Shows the backpack of an other player
|
||||
@ -156,7 +165,7 @@ public void onFail()
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(Message_NoPermission);
|
||||
player.sendMessage(messageNoPermission);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user