Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed bin/me/itsatacoshop247/DailyBonus/DailyBonus.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added dist/DailyBonus.jar
Binary file not shown.
32 changes: 32 additions & 0 deletions dist/README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================

When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).

To run the project from the command line, go to the dist folder and
type the following:

java -jar "DailyBonus.jar"

To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.

Notes:

* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.
Binary file added dist/lib/Vault.jar
Binary file not shown.
Binary file added dist/lib/bukkit-1.4.6-R0.4-20130105.234759-4.jar
Binary file not shown.
40 changes: 40 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Main:
Number of Tiers: 3
Item Give Delay (In Seconds): 0
Global Message: "&9[DailyBonus] &6!playername just got a bonus of !amount !type for logging in today!"
Global Message is Enabled: true
Tier:
1:
Economy Amount: 5
Message: "&6You were given &4!amount !type &6for joining today!"
Items:
- 5;5-1
- 357;1
Commands:
2:
Economy Amount: 10
Message: "&6You were given &4!amount !type &6for joining today!"
Items:
- 265;2
- 364;5
Commands:
- give !player 5 10
3:
Economy Amount: 20
Message: "&6You were given &4!amount !type &6for joining today!"
Items:
- 266;5
- 22;10;5
- 372;1
- 5;10;5-1
Commands:
- god !player
- give !player 4 10
Notes:
- Tiers are defined with the highest number being the highest Tier. Hence why Tier 3 give a larger amount by default than 1 or 2 do.
- To make a new Tier, copy and past one of the current Tiers below, and simply change the number to the next highest. Also make sure to change the Number of Tiers in the main.
- An amount of Economy Amount= 20;5 would give a random amount between 15 and 25. 5 in either direction.
- You can delete the Items= list to give no items, or make it one line of 0;0 to also give no items.
- In the item lists, the order is Item Id;Amount;Randomness*dash*Data Num.
- So 5;10;5*dash*1 would give Anywhere from 5 to 15 dark-wood planks. (10 to start, then randomly 0 to 5 more or less) (*dash*1 become a data of 1, the darkwood)
- Please use the Ticket system on bukkitDev for all issues with the plugin!
184 changes: 152 additions & 32 deletions src/me/itsatacoshop247/DailyBonus/DailyBonus.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
//random amounts

//meta data on items
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import net.milkbowl.vault.economy.Economy;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
Expand All @@ -29,14 +34,14 @@ public class DailyBonus extends JavaPlugin
{
public static Economy econ = null;

public List<Player> playerList = new ArrayList<Player>();
public HashSet<String> playerList = new HashSet<String>();

public HashMap<Player, Integer> numEarly = new HashMap<Player, Integer>();
public HashMap<String, Integer> numEarly = new HashMap<String, Integer>();

File configFile;
File playersFile;
FileConfiguration config;
FileConfiguration players;

public Logger log = Logger.getLogger("Minecraft");

public void onDisable()
{
Expand All @@ -46,8 +51,29 @@ public void onDisable()
{
for(int x = 0; x < players.length; x++)
{
this.players.set(("Players." + players[x].getName() + ".Last"), System.currentTimeMillis());
this.savePlayers();
File file = new File(this.getDataFolder().getAbsolutePath()+"/players/"+players[x].getName()+".yml");
FileConfiguration pfile = new YamlConfiguration();
try {
pfile.load(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

pfile.set(("Time.Last"), System.currentTimeMillis());

try {
pfile.save(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Expand All @@ -59,7 +85,6 @@ public void onEnable()
setupEconomy();

this.configFile = new File(getDataFolder(), "config.yml");
this.playersFile = new File(getDataFolder(), "players.yml");
try
{
firstRun();
Expand All @@ -69,10 +94,10 @@ public void onEnable()
e.printStackTrace();
}
this.config = new YamlConfiguration();
this.players = new YamlConfiguration();
loadYamls();
config.options().copyDefaults(true);
players.options().copyDefaults(true);

this.updateConfig();
}

@EventHandler
Expand All @@ -83,29 +108,137 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
{
if(args[0].equalsIgnoreCase("Reload"))
{
this.savePlayers();
this.loadYamls();
sender.sendMessage(ChatColor.GOLD + "DailyBonus has been reloaded.");
return true;
if(!sender.hasPermission("dailybonus.reload"))
{
sender.sendMessage(ChatColor.WHITE + "You don't have dailybonus.reload permissions!");
}
else
{
Player[] players = this.getServer().getOnlinePlayers();
if(players.length > 0)
{
for(int x = 0; x < players.length; x++)
{
File file = new File(this.getDataFolder().getAbsolutePath()+"/players/"+players[x].getName()+".yml");
FileConfiguration pfile = new YamlConfiguration();
try {
pfile.load(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

pfile.set(("Time.Last"), System.currentTimeMillis());

try {
pfile.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}

this.loadYamls();
sender.sendMessage(ChatColor.GOLD + "DailyBonus has been reloaded.");
return true;
}
}
}
else
{
sender.sendMessage(ChatColor.YELLOW + this.getName() + " by " + this.getDescription().getAuthors() +". Version " + this.getDescription().getVersion() + ".");
sender.sendMessage("Use '" + ChatColor.YELLOW + "/DailyBonus reload" + ChatColor.WHITE + "' to reload the plugin.");
return true;
}
}
return false;
}

private void firstRun() throws Exception
private void updateConfig()
{
if (!this.playersFile.exists())
HashMap<String, String> items = new HashMap<String, String>();

items = loadConfigurables(items);

int num = 0;
for(Map.Entry<String, String> item : items.entrySet())
{
if(this.config.get(item.getKey()) == null)
{
if(item.getValue().equalsIgnoreCase("LIST"))
{
List<String> list = Arrays.asList("LIST ITEMS GO HERE");
this.config.addDefault(item.getKey(), list);
}
else if(item.getValue().equalsIgnoreCase("true"))
{
this.config.addDefault(item.getKey(), true);
}
else if(item.getValue().equalsIgnoreCase("false"))
{
this.config.addDefault(item.getKey(), false);
}
else if(isInteger(item.getValue()))
{
this.config.addDefault(item.getKey(), Integer.parseInt(item.getValue()));
}
else
{
this.config.addDefault(item.getKey(), item.getValue());
}
num++;
}
}
if(num > 0)
{
this.playersFile.getParentFile().mkdirs();
copy(getResource("players.yml"), this.playersFile);
this.configFile.delete();
this.log.info("[DailyBonus] " + num + " missing items added to config file.");
}
this.saveConfig();
}

public boolean isInteger(String input)
{
try
{
Integer.parseInt(input);
return true;
}
catch(Exception e)
{
return false;
}
}

private HashMap<String, String> loadConfigurables(HashMap<String, String> items)
{
//1.0
items.put("Main.Number of Tiers", "1");
items.put("Main.Item Give Delay (In Seconds)", "0");
items.put("Main.Global Message", "&9[DailyBonus] &6!playername just got abonus of !amount !type for logging in today!");
items.put("Main.Global Message is Enabled", "true");

return items;
}

private void firstRun() throws Exception
{
if (!this.configFile.exists())
{
this.configFile.getParentFile().mkdirs();
copy(getResource("config.yml"), this.configFile);
}

File file = new File(this.getDataFolder().getAbsolutePath()+"/players");
if(!file.exists())
{
file.mkdir();
}
}

private void copy(InputStream in, File file)
Expand Down Expand Up @@ -133,7 +266,6 @@ public void loadYamls()
try
{
this.config.load(this.configFile);
this.players.load(this.playersFile);
}
catch (Exception e)
{
Expand All @@ -153,18 +285,6 @@ public void saveConfig()
}
}

public void savePlayers()
{
try
{
this.players.save(this.playersFile);
}
catch (IOException e)
{
e.printStackTrace();
}
}

private boolean setupEconomy()
{
if (getServer().getPluginManager().getPlugin("Vault") == null)
Expand Down
Loading